xref: /openbmc/linux/arch/powerpc/kernel/hw_breakpoint.c (revision b57aeab811db07295f646808b1b17c312d17f57d)
11a59d1b8SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
25aae8a53SK.Prasad /*
35aae8a53SK.Prasad  * HW_breakpoint: a unified kernel/user-space hardware breakpoint facility,
45aae8a53SK.Prasad  * using the CPU's debug registers. Derived from
55aae8a53SK.Prasad  * "arch/x86/kernel/hw_breakpoint.c"
65aae8a53SK.Prasad  *
75aae8a53SK.Prasad  * Copyright 2010 IBM Corporation
85aae8a53SK.Prasad  * Author: K.Prasad <prasad@linux.vnet.ibm.com>
95aae8a53SK.Prasad  */
105aae8a53SK.Prasad 
115aae8a53SK.Prasad #include <linux/hw_breakpoint.h>
125aae8a53SK.Prasad #include <linux/notifier.h>
135aae8a53SK.Prasad #include <linux/kprobes.h>
145aae8a53SK.Prasad #include <linux/percpu.h>
155aae8a53SK.Prasad #include <linux/kernel.h>
165aae8a53SK.Prasad #include <linux/sched.h>
175aae8a53SK.Prasad #include <linux/smp.h>
18c1fe190cSMichael Neuling #include <linux/debugfs.h>
19c1fe190cSMichael Neuling #include <linux/init.h>
205aae8a53SK.Prasad 
215aae8a53SK.Prasad #include <asm/hw_breakpoint.h>
225aae8a53SK.Prasad #include <asm/processor.h>
235aae8a53SK.Prasad #include <asm/sstep.h>
2485ce9a5dSMichael Neuling #include <asm/debug.h>
25c1fe190cSMichael Neuling #include <asm/debugfs.h>
26c1fe190cSMichael Neuling #include <asm/hvcall.h>
277c0f6ba6SLinus Torvalds #include <linux/uaccess.h>
285aae8a53SK.Prasad 
295aae8a53SK.Prasad /*
305aae8a53SK.Prasad  * Stores the breakpoints currently in use on each breakpoint address
315aae8a53SK.Prasad  * register for every cpu
325aae8a53SK.Prasad  */
335aae8a53SK.Prasad static DEFINE_PER_CPU(struct perf_event *, bp_per_reg);
345aae8a53SK.Prasad 
355aae8a53SK.Prasad /*
36d09ec738SPaul Mackerras  * Returns total number of data or instruction breakpoints available.
37d09ec738SPaul Mackerras  */
38d09ec738SPaul Mackerras int hw_breakpoint_slots(int type)
39d09ec738SPaul Mackerras {
40d09ec738SPaul Mackerras 	if (type == TYPE_DATA)
41d09ec738SPaul Mackerras 		return HBP_NUM;
42d09ec738SPaul Mackerras 	return 0;		/* no instruction breakpoints available */
43d09ec738SPaul Mackerras }
44d09ec738SPaul Mackerras 
45d09ec738SPaul Mackerras /*
465aae8a53SK.Prasad  * Install a perf counter breakpoint.
475aae8a53SK.Prasad  *
485aae8a53SK.Prasad  * We seek a free debug address register and use it for this
495aae8a53SK.Prasad  * breakpoint.
505aae8a53SK.Prasad  *
515aae8a53SK.Prasad  * Atomic: we hold the counter->ctx->lock and we only handle variables
525aae8a53SK.Prasad  * and registers local to this cpu.
535aae8a53SK.Prasad  */
545aae8a53SK.Prasad int arch_install_hw_breakpoint(struct perf_event *bp)
555aae8a53SK.Prasad {
565aae8a53SK.Prasad 	struct arch_hw_breakpoint *info = counter_arch_bp(bp);
5769111bacSChristoph Lameter 	struct perf_event **slot = this_cpu_ptr(&bp_per_reg);
585aae8a53SK.Prasad 
595aae8a53SK.Prasad 	*slot = bp;
605aae8a53SK.Prasad 
615aae8a53SK.Prasad 	/*
625aae8a53SK.Prasad 	 * Do not install DABR values if the instruction must be single-stepped.
635aae8a53SK.Prasad 	 * If so, DABR will be populated in single_step_dabr_instruction().
645aae8a53SK.Prasad 	 */
655aae8a53SK.Prasad 	if (current->thread.last_hit_ubp != bp)
6621f58507SPaul Gortmaker 		__set_breakpoint(info);
675aae8a53SK.Prasad 
685aae8a53SK.Prasad 	return 0;
695aae8a53SK.Prasad }
705aae8a53SK.Prasad 
715aae8a53SK.Prasad /*
725aae8a53SK.Prasad  * Uninstall the breakpoint contained in the given counter.
735aae8a53SK.Prasad  *
745aae8a53SK.Prasad  * First we search the debug address register it uses and then we disable
755aae8a53SK.Prasad  * it.
765aae8a53SK.Prasad  *
775aae8a53SK.Prasad  * Atomic: we hold the counter->ctx->lock and we only handle variables
785aae8a53SK.Prasad  * and registers local to this cpu.
795aae8a53SK.Prasad  */
805aae8a53SK.Prasad void arch_uninstall_hw_breakpoint(struct perf_event *bp)
815aae8a53SK.Prasad {
8269111bacSChristoph Lameter 	struct perf_event **slot = this_cpu_ptr(&bp_per_reg);
835aae8a53SK.Prasad 
845aae8a53SK.Prasad 	if (*slot != bp) {
855aae8a53SK.Prasad 		WARN_ONCE(1, "Can't find the breakpoint");
865aae8a53SK.Prasad 		return;
875aae8a53SK.Prasad 	}
885aae8a53SK.Prasad 
895aae8a53SK.Prasad 	*slot = NULL;
909422de3eSMichael Neuling 	hw_breakpoint_disable();
915aae8a53SK.Prasad }
925aae8a53SK.Prasad 
935aae8a53SK.Prasad /*
945aae8a53SK.Prasad  * Perform cleanup of arch-specific counters during unregistration
955aae8a53SK.Prasad  * of the perf-event
965aae8a53SK.Prasad  */
975aae8a53SK.Prasad void arch_unregister_hw_breakpoint(struct perf_event *bp)
985aae8a53SK.Prasad {
995aae8a53SK.Prasad 	/*
1005aae8a53SK.Prasad 	 * If the breakpoint is unregistered between a hw_breakpoint_handler()
1015aae8a53SK.Prasad 	 * and the single_step_dabr_instruction(), then cleanup the breakpoint
1025aae8a53SK.Prasad 	 * restoration variables to prevent dangling pointers.
103fb822e60SRavi Bangoria 	 * FIXME, this should not be using bp->ctx at all! Sayeth peterz.
1045aae8a53SK.Prasad 	 */
105fb822e60SRavi Bangoria 	if (bp->ctx && bp->ctx->task && bp->ctx->task != ((void *)-1L))
1065aae8a53SK.Prasad 		bp->ctx->task->thread.last_hit_ubp = NULL;
1075aae8a53SK.Prasad }
1085aae8a53SK.Prasad 
1095aae8a53SK.Prasad /*
1105aae8a53SK.Prasad  * Check for virtual address in kernel space.
1115aae8a53SK.Prasad  */
1128e983ff9SFrederic Weisbecker int arch_check_bp_in_kernelspace(struct arch_hw_breakpoint *hw)
1135aae8a53SK.Prasad {
1148e983ff9SFrederic Weisbecker 	return is_kernel_addr(hw->address);
1155aae8a53SK.Prasad }
1165aae8a53SK.Prasad 
1175aae8a53SK.Prasad int arch_bp_generic_fields(int type, int *gen_bp_type)
1185aae8a53SK.Prasad {
1199422de3eSMichael Neuling 	*gen_bp_type = 0;
1209422de3eSMichael Neuling 	if (type & HW_BRK_TYPE_READ)
1219422de3eSMichael Neuling 		*gen_bp_type |= HW_BREAKPOINT_R;
1229422de3eSMichael Neuling 	if (type & HW_BRK_TYPE_WRITE)
1239422de3eSMichael Neuling 		*gen_bp_type |= HW_BREAKPOINT_W;
1249422de3eSMichael Neuling 	if (*gen_bp_type == 0)
1255aae8a53SK.Prasad 		return -EINVAL;
1265aae8a53SK.Prasad 	return 0;
1275aae8a53SK.Prasad }
1285aae8a53SK.Prasad 
1295aae8a53SK.Prasad /*
130*b57aeab8SRavi Bangoria  * Watchpoint match range is always doubleword(8 bytes) aligned on
131*b57aeab8SRavi Bangoria  * powerpc. If the given range is crossing doubleword boundary, we
132*b57aeab8SRavi Bangoria  * need to increase the length such that next doubleword also get
133*b57aeab8SRavi Bangoria  * covered. Ex,
134*b57aeab8SRavi Bangoria  *
135*b57aeab8SRavi Bangoria  *          address   len = 6 bytes
136*b57aeab8SRavi Bangoria  *                |=========.
137*b57aeab8SRavi Bangoria  *   |------------v--|------v--------|
138*b57aeab8SRavi Bangoria  *   | | | | | | | | | | | | | | | | |
139*b57aeab8SRavi Bangoria  *   |---------------|---------------|
140*b57aeab8SRavi Bangoria  *    <---8 bytes--->
141*b57aeab8SRavi Bangoria  *
142*b57aeab8SRavi Bangoria  * In this case, we should configure hw as:
143*b57aeab8SRavi Bangoria  *   start_addr = address & ~HW_BREAKPOINT_ALIGN
144*b57aeab8SRavi Bangoria  *   len = 16 bytes
145*b57aeab8SRavi Bangoria  *
146*b57aeab8SRavi Bangoria  * @start_addr and @end_addr are inclusive.
147*b57aeab8SRavi Bangoria  */
148*b57aeab8SRavi Bangoria static int hw_breakpoint_validate_len(struct arch_hw_breakpoint *hw)
149*b57aeab8SRavi Bangoria {
150*b57aeab8SRavi Bangoria 	u16 max_len = DABR_MAX_LEN;
151*b57aeab8SRavi Bangoria 	u16 hw_len;
152*b57aeab8SRavi Bangoria 	unsigned long start_addr, end_addr;
153*b57aeab8SRavi Bangoria 
154*b57aeab8SRavi Bangoria 	start_addr = hw->address & ~HW_BREAKPOINT_ALIGN;
155*b57aeab8SRavi Bangoria 	end_addr = (hw->address + hw->len - 1) | HW_BREAKPOINT_ALIGN;
156*b57aeab8SRavi Bangoria 	hw_len = end_addr - start_addr + 1;
157*b57aeab8SRavi Bangoria 
158*b57aeab8SRavi Bangoria 	if (dawr_enabled()) {
159*b57aeab8SRavi Bangoria 		max_len = DAWR_MAX_LEN;
160*b57aeab8SRavi Bangoria 		/* DAWR region can't cross 512 bytes boundary */
161*b57aeab8SRavi Bangoria 		if ((start_addr >> 9) != (end_addr >> 9))
162*b57aeab8SRavi Bangoria 			return -EINVAL;
163*b57aeab8SRavi Bangoria 	}
164*b57aeab8SRavi Bangoria 
165*b57aeab8SRavi Bangoria 	if (hw_len > max_len)
166*b57aeab8SRavi Bangoria 		return -EINVAL;
167*b57aeab8SRavi Bangoria 
168*b57aeab8SRavi Bangoria 	hw->hw_len = hw_len;
169*b57aeab8SRavi Bangoria 	return 0;
170*b57aeab8SRavi Bangoria }
171*b57aeab8SRavi Bangoria 
172*b57aeab8SRavi Bangoria /*
1735aae8a53SK.Prasad  * Validate the arch-specific HW Breakpoint register settings
1745aae8a53SK.Prasad  */
1755d5176baSFrederic Weisbecker int hw_breakpoint_arch_parse(struct perf_event *bp,
1765d5176baSFrederic Weisbecker 			     const struct perf_event_attr *attr,
1775d5176baSFrederic Weisbecker 			     struct arch_hw_breakpoint *hw)
1785aae8a53SK.Prasad {
179*b57aeab8SRavi Bangoria 	int ret = -EINVAL;
1805aae8a53SK.Prasad 
181*b57aeab8SRavi Bangoria 	if (!bp || !attr->bp_len)
1825aae8a53SK.Prasad 		return ret;
1835aae8a53SK.Prasad 
1845d5176baSFrederic Weisbecker 	hw->type = HW_BRK_TYPE_TRANSLATE;
1855d5176baSFrederic Weisbecker 	if (attr->bp_type & HW_BREAKPOINT_R)
1865d5176baSFrederic Weisbecker 		hw->type |= HW_BRK_TYPE_READ;
1875d5176baSFrederic Weisbecker 	if (attr->bp_type & HW_BREAKPOINT_W)
1885d5176baSFrederic Weisbecker 		hw->type |= HW_BRK_TYPE_WRITE;
1895d5176baSFrederic Weisbecker 	if (hw->type == HW_BRK_TYPE_TRANSLATE)
1909422de3eSMichael Neuling 		/* must set alteast read or write */
1915aae8a53SK.Prasad 		return ret;
1925d5176baSFrederic Weisbecker 	if (!attr->exclude_user)
1935d5176baSFrederic Weisbecker 		hw->type |= HW_BRK_TYPE_USER;
1945d5176baSFrederic Weisbecker 	if (!attr->exclude_kernel)
1955d5176baSFrederic Weisbecker 		hw->type |= HW_BRK_TYPE_KERNEL;
1965d5176baSFrederic Weisbecker 	if (!attr->exclude_hv)
1975d5176baSFrederic Weisbecker 		hw->type |= HW_BRK_TYPE_HYP;
1985d5176baSFrederic Weisbecker 	hw->address = attr->bp_addr;
1995d5176baSFrederic Weisbecker 	hw->len = attr->bp_len;
2005aae8a53SK.Prasad 
20185ce9a5dSMichael Neuling 	if (!ppc_breakpoint_available())
20285ce9a5dSMichael Neuling 		return -ENODEV;
203*b57aeab8SRavi Bangoria 
204*b57aeab8SRavi Bangoria 	return hw_breakpoint_validate_len(hw);
2055aae8a53SK.Prasad }
2065aae8a53SK.Prasad 
2075aae8a53SK.Prasad /*
20806532a67SK.Prasad  * Restores the breakpoint on the debug registers.
20906532a67SK.Prasad  * Invoke this function if it is known that the execution context is
21006532a67SK.Prasad  * about to change to cause loss of MSR_SE settings.
21106532a67SK.Prasad  */
21206532a67SK.Prasad void thread_change_pc(struct task_struct *tsk, struct pt_regs *regs)
21306532a67SK.Prasad {
21406532a67SK.Prasad 	struct arch_hw_breakpoint *info;
21506532a67SK.Prasad 
21606532a67SK.Prasad 	if (likely(!tsk->thread.last_hit_ubp))
21706532a67SK.Prasad 		return;
21806532a67SK.Prasad 
21906532a67SK.Prasad 	info = counter_arch_bp(tsk->thread.last_hit_ubp);
22006532a67SK.Prasad 	regs->msr &= ~MSR_SE;
22121f58507SPaul Gortmaker 	__set_breakpoint(info);
22206532a67SK.Prasad 	tsk->thread.last_hit_ubp = NULL;
22306532a67SK.Prasad }
22406532a67SK.Prasad 
225bc01bdf6SRavi Bangoria static bool is_larx_stcx_instr(struct pt_regs *regs, unsigned int instr)
226bc01bdf6SRavi Bangoria {
227bc01bdf6SRavi Bangoria 	int ret, type;
228bc01bdf6SRavi Bangoria 	struct instruction_op op;
229bc01bdf6SRavi Bangoria 
230bc01bdf6SRavi Bangoria 	ret = analyse_instr(&op, regs, instr);
231bc01bdf6SRavi Bangoria 	type = GETTYPE(op.type);
232bc01bdf6SRavi Bangoria 	return (!ret && (type == LARX || type == STCX));
233bc01bdf6SRavi Bangoria }
234bc01bdf6SRavi Bangoria 
23506532a67SK.Prasad /*
2365aae8a53SK.Prasad  * Handle debug exception notifications.
2375aae8a53SK.Prasad  */
238658d029dSChristophe Leroy static bool stepping_handler(struct pt_regs *regs, struct perf_event *bp,
239658d029dSChristophe Leroy 			     unsigned long addr)
240658d029dSChristophe Leroy {
241bc01bdf6SRavi Bangoria 	unsigned int instr = 0;
242bc01bdf6SRavi Bangoria 
243bc01bdf6SRavi Bangoria 	if (__get_user_inatomic(instr, (unsigned int *)regs->nip))
244bc01bdf6SRavi Bangoria 		goto fail;
245bc01bdf6SRavi Bangoria 
246bc01bdf6SRavi Bangoria 	if (is_larx_stcx_instr(regs, instr)) {
247bc01bdf6SRavi Bangoria 		printk_ratelimited("Breakpoint hit on instruction that can't be emulated."
248bc01bdf6SRavi Bangoria 				   " Breakpoint at 0x%lx will be disabled.\n", addr);
249bc01bdf6SRavi Bangoria 		goto disable;
250bc01bdf6SRavi Bangoria 	}
251658d029dSChristophe Leroy 
252658d029dSChristophe Leroy 	/* Do not emulate user-space instructions, instead single-step them */
253658d029dSChristophe Leroy 	if (user_mode(regs)) {
254658d029dSChristophe Leroy 		current->thread.last_hit_ubp = bp;
255658d029dSChristophe Leroy 		regs->msr |= MSR_SE;
256658d029dSChristophe Leroy 		return false;
257658d029dSChristophe Leroy 	}
258658d029dSChristophe Leroy 
259bc01bdf6SRavi Bangoria 	if (!emulate_step(regs, instr))
260bc01bdf6SRavi Bangoria 		goto fail;
261658d029dSChristophe Leroy 
262bc01bdf6SRavi Bangoria 	return true;
263bc01bdf6SRavi Bangoria 
264bc01bdf6SRavi Bangoria fail:
265658d029dSChristophe Leroy 	/*
266bc01bdf6SRavi Bangoria 	 * We've failed in reliably handling the hw-breakpoint. Unregister
267bc01bdf6SRavi Bangoria 	 * it and throw a warning message to let the user know about it.
268658d029dSChristophe Leroy 	 */
269658d029dSChristophe Leroy 	WARN(1, "Unable to handle hardware breakpoint. Breakpoint at "
270658d029dSChristophe Leroy 		"0x%lx will be disabled.", addr);
271bc01bdf6SRavi Bangoria 
272bc01bdf6SRavi Bangoria disable:
273658d029dSChristophe Leroy 	perf_event_disable_inatomic(bp);
274658d029dSChristophe Leroy 	return false;
275658d029dSChristophe Leroy }
276658d029dSChristophe Leroy 
27703465f89SNicholas Piggin int hw_breakpoint_handler(struct die_args *args)
2785aae8a53SK.Prasad {
2795aae8a53SK.Prasad 	int rc = NOTIFY_STOP;
2805aae8a53SK.Prasad 	struct perf_event *bp;
2815aae8a53SK.Prasad 	struct pt_regs *regs = args->regs;
2824ad8622dSChristophe Leroy 	struct arch_hw_breakpoint *info;
283e3e94084SK.Prasad 	unsigned long dar = regs->dar;
2845aae8a53SK.Prasad 
2855aae8a53SK.Prasad 	/* Disable breakpoints during exception handling */
2869422de3eSMichael Neuling 	hw_breakpoint_disable();
287574cb248SPaul Mackerras 
2885aae8a53SK.Prasad 	/*
2895aae8a53SK.Prasad 	 * The counter may be concurrently released but that can only
2905aae8a53SK.Prasad 	 * occur from a call_rcu() path. We can then safely fetch
2915aae8a53SK.Prasad 	 * the breakpoint, use its callback, touch its counter
2925aae8a53SK.Prasad 	 * while we are in an rcu_read_lock() path.
2935aae8a53SK.Prasad 	 */
2945aae8a53SK.Prasad 	rcu_read_lock();
2955aae8a53SK.Prasad 
29669111bacSChristoph Lameter 	bp = __this_cpu_read(bp_per_reg);
297c21a493aSRavi Bangoria 	if (!bp) {
298c21a493aSRavi Bangoria 		rc = NOTIFY_DONE;
2995aae8a53SK.Prasad 		goto out;
300c21a493aSRavi Bangoria 	}
3015aae8a53SK.Prasad 	info = counter_arch_bp(bp);
3025aae8a53SK.Prasad 
3035aae8a53SK.Prasad 	/*
3045aae8a53SK.Prasad 	 * Return early after invoking user-callback function without restoring
3055aae8a53SK.Prasad 	 * DABR if the breakpoint is from ptrace which always operates in
3065aae8a53SK.Prasad 	 * one-shot mode. The ptrace-ed process will receive the SIGTRAP signal
3075aae8a53SK.Prasad 	 * generated in do_dabr().
3085aae8a53SK.Prasad 	 */
309574cb248SPaul Mackerras 	if (bp->overflow_handler == ptrace_triggered) {
3105aae8a53SK.Prasad 		perf_bp_event(bp, regs);
3115aae8a53SK.Prasad 		rc = NOTIFY_DONE;
3125aae8a53SK.Prasad 		goto out;
3135aae8a53SK.Prasad 	}
3145aae8a53SK.Prasad 
315e3e94084SK.Prasad 	/*
316e3e94084SK.Prasad 	 * Verify if dar lies within the address range occupied by the symbol
317574cb248SPaul Mackerras 	 * being watched to filter extraneous exceptions.  If it doesn't,
318574cb248SPaul Mackerras 	 * we still need to single-step the instruction, but we don't
319574cb248SPaul Mackerras 	 * generate an event.
320e3e94084SK.Prasad 	 */
321540e07c6SMichael Neuling 	info->type &= ~HW_BRK_TYPE_EXTRANEOUS_IRQ;
3229422de3eSMichael Neuling 	if (!((bp->attr.bp_addr <= dar) &&
3239422de3eSMichael Neuling 	      (dar - bp->attr.bp_addr < bp->attr.bp_len)))
3249422de3eSMichael Neuling 		info->type |= HW_BRK_TYPE_EXTRANEOUS_IRQ;
325e3e94084SK.Prasad 
326658d029dSChristophe Leroy 	if (!IS_ENABLED(CONFIG_PPC_8xx) && !stepping_handler(regs, bp, info->address))
3275aae8a53SK.Prasad 		goto out;
3285aae8a53SK.Prasad 
3295aae8a53SK.Prasad 	/*
3305aae8a53SK.Prasad 	 * As a policy, the callback is invoked in a 'trigger-after-execute'
3315aae8a53SK.Prasad 	 * fashion
3325aae8a53SK.Prasad 	 */
3339422de3eSMichael Neuling 	if (!(info->type & HW_BRK_TYPE_EXTRANEOUS_IRQ))
3345aae8a53SK.Prasad 		perf_bp_event(bp, regs);
3355aae8a53SK.Prasad 
33621f58507SPaul Gortmaker 	__set_breakpoint(info);
3375aae8a53SK.Prasad out:
3385aae8a53SK.Prasad 	rcu_read_unlock();
3395aae8a53SK.Prasad 	return rc;
3405aae8a53SK.Prasad }
34103465f89SNicholas Piggin NOKPROBE_SYMBOL(hw_breakpoint_handler);
3425aae8a53SK.Prasad 
3435aae8a53SK.Prasad /*
3445aae8a53SK.Prasad  * Handle single-step exceptions following a DABR hit.
3455aae8a53SK.Prasad  */
34603465f89SNicholas Piggin static int single_step_dabr_instruction(struct die_args *args)
3475aae8a53SK.Prasad {
3485aae8a53SK.Prasad 	struct pt_regs *regs = args->regs;
3495aae8a53SK.Prasad 	struct perf_event *bp = NULL;
3503f4693eeSMichael Neuling 	struct arch_hw_breakpoint *info;
3515aae8a53SK.Prasad 
3525aae8a53SK.Prasad 	bp = current->thread.last_hit_ubp;
3535aae8a53SK.Prasad 	/*
3545aae8a53SK.Prasad 	 * Check if we are single-stepping as a result of a
3555aae8a53SK.Prasad 	 * previous HW Breakpoint exception
3565aae8a53SK.Prasad 	 */
3575aae8a53SK.Prasad 	if (!bp)
3585aae8a53SK.Prasad 		return NOTIFY_DONE;
3595aae8a53SK.Prasad 
3603f4693eeSMichael Neuling 	info = counter_arch_bp(bp);
3615aae8a53SK.Prasad 
3625aae8a53SK.Prasad 	/*
3635aae8a53SK.Prasad 	 * We shall invoke the user-defined callback function in the single
3645aae8a53SK.Prasad 	 * stepping handler to confirm to 'trigger-after-execute' semantics
3655aae8a53SK.Prasad 	 */
3669422de3eSMichael Neuling 	if (!(info->type & HW_BRK_TYPE_EXTRANEOUS_IRQ))
3675aae8a53SK.Prasad 		perf_bp_event(bp, regs);
3685aae8a53SK.Prasad 
36921f58507SPaul Gortmaker 	__set_breakpoint(info);
3705aae8a53SK.Prasad 	current->thread.last_hit_ubp = NULL;
37176b0f133SPaul Mackerras 
37276b0f133SPaul Mackerras 	/*
37376b0f133SPaul Mackerras 	 * If the process was being single-stepped by ptrace, let the
37476b0f133SPaul Mackerras 	 * other single-step actions occur (e.g. generate SIGTRAP).
37576b0f133SPaul Mackerras 	 */
37676b0f133SPaul Mackerras 	if (test_thread_flag(TIF_SINGLESTEP))
37776b0f133SPaul Mackerras 		return NOTIFY_DONE;
37876b0f133SPaul Mackerras 
3795aae8a53SK.Prasad 	return NOTIFY_STOP;
3805aae8a53SK.Prasad }
38103465f89SNicholas Piggin NOKPROBE_SYMBOL(single_step_dabr_instruction);
3825aae8a53SK.Prasad 
3835aae8a53SK.Prasad /*
3845aae8a53SK.Prasad  * Handle debug exception notifications.
3855aae8a53SK.Prasad  */
38603465f89SNicholas Piggin int hw_breakpoint_exceptions_notify(
3875aae8a53SK.Prasad 		struct notifier_block *unused, unsigned long val, void *data)
3885aae8a53SK.Prasad {
3895aae8a53SK.Prasad 	int ret = NOTIFY_DONE;
3905aae8a53SK.Prasad 
3915aae8a53SK.Prasad 	switch (val) {
3925aae8a53SK.Prasad 	case DIE_DABR_MATCH:
3935aae8a53SK.Prasad 		ret = hw_breakpoint_handler(data);
3945aae8a53SK.Prasad 		break;
3955aae8a53SK.Prasad 	case DIE_SSTEP:
3965aae8a53SK.Prasad 		ret = single_step_dabr_instruction(data);
3975aae8a53SK.Prasad 		break;
3985aae8a53SK.Prasad 	}
3995aae8a53SK.Prasad 
4005aae8a53SK.Prasad 	return ret;
4015aae8a53SK.Prasad }
40203465f89SNicholas Piggin NOKPROBE_SYMBOL(hw_breakpoint_exceptions_notify);
4035aae8a53SK.Prasad 
4045aae8a53SK.Prasad /*
4055aae8a53SK.Prasad  * Release the user breakpoints used by ptrace
4065aae8a53SK.Prasad  */
4075aae8a53SK.Prasad void flush_ptrace_hw_breakpoint(struct task_struct *tsk)
4085aae8a53SK.Prasad {
4095aae8a53SK.Prasad 	struct thread_struct *t = &tsk->thread;
4105aae8a53SK.Prasad 
4115aae8a53SK.Prasad 	unregister_hw_breakpoint(t->ptrace_bps[0]);
4125aae8a53SK.Prasad 	t->ptrace_bps[0] = NULL;
4135aae8a53SK.Prasad }
4145aae8a53SK.Prasad 
4155aae8a53SK.Prasad void hw_breakpoint_pmu_read(struct perf_event *bp)
4165aae8a53SK.Prasad {
4175aae8a53SK.Prasad 	/* TODO */
4185aae8a53SK.Prasad }
419