K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 1 | /* |
| 2 | * HW_breakpoint: a unified kernel/user-space hardware breakpoint facility, |
| 3 | * using the CPU's debug registers. Derived from |
| 4 | * "arch/x86/kernel/hw_breakpoint.c" |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 19 | * |
| 20 | * Copyright 2010 IBM Corporation |
| 21 | * Author: K.Prasad <prasad@linux.vnet.ibm.com> |
| 22 | * |
| 23 | */ |
| 24 | |
| 25 | #include <linux/hw_breakpoint.h> |
| 26 | #include <linux/notifier.h> |
| 27 | #include <linux/kprobes.h> |
| 28 | #include <linux/percpu.h> |
| 29 | #include <linux/kernel.h> |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 30 | #include <linux/sched.h> |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 31 | #include <linux/smp.h> |
| 32 | |
| 33 | #include <asm/hw_breakpoint.h> |
| 34 | #include <asm/processor.h> |
| 35 | #include <asm/sstep.h> |
Michael Neuling | 85ce9a5 | 2018-03-27 15:37:18 +1100 | [diff] [blame^] | 36 | #include <asm/debug.h> |
Linus Torvalds | 7c0f6ba | 2016-12-24 11:46:01 -0800 | [diff] [blame] | 37 | #include <linux/uaccess.h> |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 38 | |
| 39 | /* |
| 40 | * Stores the breakpoints currently in use on each breakpoint address |
| 41 | * register for every cpu |
| 42 | */ |
| 43 | static DEFINE_PER_CPU(struct perf_event *, bp_per_reg); |
| 44 | |
| 45 | /* |
Paul Mackerras | d09ec73 | 2010-06-29 12:50:32 +1000 | [diff] [blame] | 46 | * Returns total number of data or instruction breakpoints available. |
| 47 | */ |
| 48 | int hw_breakpoint_slots(int type) |
| 49 | { |
| 50 | if (type == TYPE_DATA) |
| 51 | return HBP_NUM; |
| 52 | return 0; /* no instruction breakpoints available */ |
| 53 | } |
| 54 | |
| 55 | /* |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 56 | * Install a perf counter breakpoint. |
| 57 | * |
| 58 | * We seek a free debug address register and use it for this |
| 59 | * breakpoint. |
| 60 | * |
| 61 | * Atomic: we hold the counter->ctx->lock and we only handle variables |
| 62 | * and registers local to this cpu. |
| 63 | */ |
| 64 | int arch_install_hw_breakpoint(struct perf_event *bp) |
| 65 | { |
| 66 | struct arch_hw_breakpoint *info = counter_arch_bp(bp); |
Christoph Lameter | 69111ba | 2014-10-21 15:23:25 -0500 | [diff] [blame] | 67 | struct perf_event **slot = this_cpu_ptr(&bp_per_reg); |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 68 | |
| 69 | *slot = bp; |
| 70 | |
| 71 | /* |
| 72 | * Do not install DABR values if the instruction must be single-stepped. |
| 73 | * If so, DABR will be populated in single_step_dabr_instruction(). |
| 74 | */ |
| 75 | if (current->thread.last_hit_ubp != bp) |
Paul Gortmaker | 21f5850 | 2014-04-29 15:25:17 -0400 | [diff] [blame] | 76 | __set_breakpoint(info); |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 77 | |
| 78 | return 0; |
| 79 | } |
| 80 | |
| 81 | /* |
| 82 | * Uninstall the breakpoint contained in the given counter. |
| 83 | * |
| 84 | * First we search the debug address register it uses and then we disable |
| 85 | * it. |
| 86 | * |
| 87 | * Atomic: we hold the counter->ctx->lock and we only handle variables |
| 88 | * and registers local to this cpu. |
| 89 | */ |
| 90 | void arch_uninstall_hw_breakpoint(struct perf_event *bp) |
| 91 | { |
Christoph Lameter | 69111ba | 2014-10-21 15:23:25 -0500 | [diff] [blame] | 92 | struct perf_event **slot = this_cpu_ptr(&bp_per_reg); |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 93 | |
| 94 | if (*slot != bp) { |
| 95 | WARN_ONCE(1, "Can't find the breakpoint"); |
| 96 | return; |
| 97 | } |
| 98 | |
| 99 | *slot = NULL; |
Michael Neuling | 9422de3 | 2012-12-20 14:06:44 +0000 | [diff] [blame] | 100 | hw_breakpoint_disable(); |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | /* |
| 104 | * Perform cleanup of arch-specific counters during unregistration |
| 105 | * of the perf-event |
| 106 | */ |
| 107 | void arch_unregister_hw_breakpoint(struct perf_event *bp) |
| 108 | { |
| 109 | /* |
| 110 | * If the breakpoint is unregistered between a hw_breakpoint_handler() |
| 111 | * and the single_step_dabr_instruction(), then cleanup the breakpoint |
| 112 | * restoration variables to prevent dangling pointers. |
Ravi Bangoria | fb822e6 | 2016-03-02 15:25:17 +0530 | [diff] [blame] | 113 | * FIXME, this should not be using bp->ctx at all! Sayeth peterz. |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 114 | */ |
Ravi Bangoria | fb822e6 | 2016-03-02 15:25:17 +0530 | [diff] [blame] | 115 | if (bp->ctx && bp->ctx->task && bp->ctx->task != ((void *)-1L)) |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 116 | bp->ctx->task->thread.last_hit_ubp = NULL; |
| 117 | } |
| 118 | |
| 119 | /* |
| 120 | * Check for virtual address in kernel space. |
| 121 | */ |
| 122 | int arch_check_bp_in_kernelspace(struct perf_event *bp) |
| 123 | { |
| 124 | struct arch_hw_breakpoint *info = counter_arch_bp(bp); |
| 125 | |
| 126 | return is_kernel_addr(info->address); |
| 127 | } |
| 128 | |
| 129 | int arch_bp_generic_fields(int type, int *gen_bp_type) |
| 130 | { |
Michael Neuling | 9422de3 | 2012-12-20 14:06:44 +0000 | [diff] [blame] | 131 | *gen_bp_type = 0; |
| 132 | if (type & HW_BRK_TYPE_READ) |
| 133 | *gen_bp_type |= HW_BREAKPOINT_R; |
| 134 | if (type & HW_BRK_TYPE_WRITE) |
| 135 | *gen_bp_type |= HW_BREAKPOINT_W; |
| 136 | if (*gen_bp_type == 0) |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 137 | return -EINVAL; |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 138 | return 0; |
| 139 | } |
| 140 | |
| 141 | /* |
| 142 | * Validate the arch-specific HW Breakpoint register settings |
| 143 | */ |
| 144 | int arch_validate_hwbkpt_settings(struct perf_event *bp) |
| 145 | { |
Michael Neuling | 4ae7ebe | 2013-01-24 15:02:59 +0000 | [diff] [blame] | 146 | int ret = -EINVAL, length_max; |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 147 | struct arch_hw_breakpoint *info = counter_arch_bp(bp); |
| 148 | |
| 149 | if (!bp) |
| 150 | return ret; |
| 151 | |
Michael Neuling | 9422de3 | 2012-12-20 14:06:44 +0000 | [diff] [blame] | 152 | info->type = HW_BRK_TYPE_TRANSLATE; |
| 153 | if (bp->attr.bp_type & HW_BREAKPOINT_R) |
| 154 | info->type |= HW_BRK_TYPE_READ; |
| 155 | if (bp->attr.bp_type & HW_BREAKPOINT_W) |
| 156 | info->type |= HW_BRK_TYPE_WRITE; |
| 157 | if (info->type == HW_BRK_TYPE_TRANSLATE) |
| 158 | /* must set alteast read or write */ |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 159 | return ret; |
Michael Neuling | 9422de3 | 2012-12-20 14:06:44 +0000 | [diff] [blame] | 160 | if (!(bp->attr.exclude_user)) |
| 161 | info->type |= HW_BRK_TYPE_USER; |
| 162 | if (!(bp->attr.exclude_kernel)) |
| 163 | info->type |= HW_BRK_TYPE_KERNEL; |
| 164 | if (!(bp->attr.exclude_hv)) |
| 165 | info->type |= HW_BRK_TYPE_HYP; |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 166 | info->address = bp->attr.bp_addr; |
| 167 | info->len = bp->attr.bp_len; |
| 168 | |
| 169 | /* |
| 170 | * Since breakpoint length can be a maximum of HW_BREAKPOINT_LEN(8) |
| 171 | * and breakpoint addresses are aligned to nearest double-word |
| 172 | * HW_BREAKPOINT_ALIGN by rounding off to the lower address, the |
| 173 | * 'symbolsize' should satisfy the check below. |
| 174 | */ |
Michael Neuling | 85ce9a5 | 2018-03-27 15:37:18 +1100 | [diff] [blame^] | 175 | if (!ppc_breakpoint_available()) |
| 176 | return -ENODEV; |
Michael Neuling | 4ae7ebe | 2013-01-24 15:02:59 +0000 | [diff] [blame] | 177 | length_max = 8; /* DABR */ |
| 178 | if (cpu_has_feature(CPU_FTR_DAWR)) { |
| 179 | length_max = 512 ; /* 64 doublewords */ |
| 180 | /* DAWR region can't cross 512 boundary */ |
| 181 | if ((bp->attr.bp_addr >> 10) != |
Michael Neuling | e2a800b | 2013-07-01 14:19:50 +1000 | [diff] [blame] | 182 | ((bp->attr.bp_addr + bp->attr.bp_len - 1) >> 10)) |
Michael Neuling | 4ae7ebe | 2013-01-24 15:02:59 +0000 | [diff] [blame] | 183 | return -EINVAL; |
| 184 | } |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 185 | if (info->len > |
Michael Neuling | 4ae7ebe | 2013-01-24 15:02:59 +0000 | [diff] [blame] | 186 | (length_max - (info->address & HW_BREAKPOINT_ALIGN))) |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 187 | return -EINVAL; |
| 188 | return 0; |
| 189 | } |
| 190 | |
| 191 | /* |
K.Prasad | 06532a6 | 2010-06-15 11:35:41 +0530 | [diff] [blame] | 192 | * Restores the breakpoint on the debug registers. |
| 193 | * Invoke this function if it is known that the execution context is |
| 194 | * about to change to cause loss of MSR_SE settings. |
| 195 | */ |
| 196 | void thread_change_pc(struct task_struct *tsk, struct pt_regs *regs) |
| 197 | { |
| 198 | struct arch_hw_breakpoint *info; |
| 199 | |
| 200 | if (likely(!tsk->thread.last_hit_ubp)) |
| 201 | return; |
| 202 | |
| 203 | info = counter_arch_bp(tsk->thread.last_hit_ubp); |
| 204 | regs->msr &= ~MSR_SE; |
Paul Gortmaker | 21f5850 | 2014-04-29 15:25:17 -0400 | [diff] [blame] | 205 | __set_breakpoint(info); |
K.Prasad | 06532a6 | 2010-06-15 11:35:41 +0530 | [diff] [blame] | 206 | tsk->thread.last_hit_ubp = NULL; |
| 207 | } |
| 208 | |
| 209 | /* |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 210 | * Handle debug exception notifications. |
| 211 | */ |
Nicholas Piggin | 03465f8 | 2016-09-16 20:48:08 +1000 | [diff] [blame] | 212 | int hw_breakpoint_handler(struct die_args *args) |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 213 | { |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 214 | int rc = NOTIFY_STOP; |
| 215 | struct perf_event *bp; |
| 216 | struct pt_regs *regs = args->regs; |
Christophe Leroy | 4ad8622 | 2016-11-29 09:52:15 +0100 | [diff] [blame] | 217 | #ifndef CONFIG_PPC_8xx |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 218 | int stepped = 1; |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 219 | unsigned int instr; |
Christophe Leroy | 4ad8622 | 2016-11-29 09:52:15 +0100 | [diff] [blame] | 220 | #endif |
| 221 | struct arch_hw_breakpoint *info; |
K.Prasad | e3e9408 | 2010-06-15 11:36:12 +0530 | [diff] [blame] | 222 | unsigned long dar = regs->dar; |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 223 | |
| 224 | /* Disable breakpoints during exception handling */ |
Michael Neuling | 9422de3 | 2012-12-20 14:06:44 +0000 | [diff] [blame] | 225 | hw_breakpoint_disable(); |
Paul Mackerras | 574cb24 | 2010-06-23 15:42:43 +1000 | [diff] [blame] | 226 | |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 227 | /* |
| 228 | * The counter may be concurrently released but that can only |
| 229 | * occur from a call_rcu() path. We can then safely fetch |
| 230 | * the breakpoint, use its callback, touch its counter |
| 231 | * while we are in an rcu_read_lock() path. |
| 232 | */ |
| 233 | rcu_read_lock(); |
| 234 | |
Christoph Lameter | 69111ba | 2014-10-21 15:23:25 -0500 | [diff] [blame] | 235 | bp = __this_cpu_read(bp_per_reg); |
Ravi Bangoria | c21a493 | 2016-11-22 14:55:59 +0530 | [diff] [blame] | 236 | if (!bp) { |
| 237 | rc = NOTIFY_DONE; |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 238 | goto out; |
Ravi Bangoria | c21a493 | 2016-11-22 14:55:59 +0530 | [diff] [blame] | 239 | } |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 240 | info = counter_arch_bp(bp); |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 241 | |
| 242 | /* |
| 243 | * Return early after invoking user-callback function without restoring |
| 244 | * DABR if the breakpoint is from ptrace which always operates in |
| 245 | * one-shot mode. The ptrace-ed process will receive the SIGTRAP signal |
| 246 | * generated in do_dabr(). |
| 247 | */ |
Paul Mackerras | 574cb24 | 2010-06-23 15:42:43 +1000 | [diff] [blame] | 248 | if (bp->overflow_handler == ptrace_triggered) { |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 249 | perf_bp_event(bp, regs); |
| 250 | rc = NOTIFY_DONE; |
| 251 | goto out; |
| 252 | } |
| 253 | |
K.Prasad | e3e9408 | 2010-06-15 11:36:12 +0530 | [diff] [blame] | 254 | /* |
| 255 | * Verify if dar lies within the address range occupied by the symbol |
Paul Mackerras | 574cb24 | 2010-06-23 15:42:43 +1000 | [diff] [blame] | 256 | * being watched to filter extraneous exceptions. If it doesn't, |
| 257 | * we still need to single-step the instruction, but we don't |
| 258 | * generate an event. |
K.Prasad | e3e9408 | 2010-06-15 11:36:12 +0530 | [diff] [blame] | 259 | */ |
Michael Neuling | 540e07c | 2013-06-24 15:47:23 +1000 | [diff] [blame] | 260 | info->type &= ~HW_BRK_TYPE_EXTRANEOUS_IRQ; |
Michael Neuling | 9422de3 | 2012-12-20 14:06:44 +0000 | [diff] [blame] | 261 | if (!((bp->attr.bp_addr <= dar) && |
| 262 | (dar - bp->attr.bp_addr < bp->attr.bp_len))) |
| 263 | info->type |= HW_BRK_TYPE_EXTRANEOUS_IRQ; |
K.Prasad | e3e9408 | 2010-06-15 11:36:12 +0530 | [diff] [blame] | 264 | |
Christophe Leroy | 4ad8622 | 2016-11-29 09:52:15 +0100 | [diff] [blame] | 265 | #ifndef CONFIG_PPC_8xx |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 266 | /* Do not emulate user-space instructions, instead single-step them */ |
| 267 | if (user_mode(regs)) { |
Michael Neuling | 6d9c00c | 2012-08-22 20:30:43 +0000 | [diff] [blame] | 268 | current->thread.last_hit_ubp = bp; |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 269 | regs->msr |= MSR_SE; |
| 270 | goto out; |
| 271 | } |
| 272 | |
| 273 | stepped = 0; |
| 274 | instr = 0; |
| 275 | if (!__get_user_inatomic(instr, (unsigned int *) regs->nip)) |
| 276 | stepped = emulate_step(regs, instr); |
| 277 | |
| 278 | /* |
| 279 | * emulate_step() could not execute it. We've failed in reliably |
| 280 | * handling the hw-breakpoint. Unregister it and throw a warning |
| 281 | * message to let the user know about it. |
| 282 | */ |
| 283 | if (!stepped) { |
| 284 | WARN(1, "Unable to handle hardware breakpoint. Breakpoint at " |
| 285 | "0x%lx will be disabled.", info->address); |
Jiri Olsa | 5aab90c | 2016-10-26 11:48:24 +0200 | [diff] [blame] | 286 | perf_event_disable_inatomic(bp); |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 287 | goto out; |
| 288 | } |
Christophe Leroy | 4ad8622 | 2016-11-29 09:52:15 +0100 | [diff] [blame] | 289 | #endif |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 290 | /* |
| 291 | * As a policy, the callback is invoked in a 'trigger-after-execute' |
| 292 | * fashion |
| 293 | */ |
Michael Neuling | 9422de3 | 2012-12-20 14:06:44 +0000 | [diff] [blame] | 294 | if (!(info->type & HW_BRK_TYPE_EXTRANEOUS_IRQ)) |
K.Prasad | e3e9408 | 2010-06-15 11:36:12 +0530 | [diff] [blame] | 295 | perf_bp_event(bp, regs); |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 296 | |
Paul Gortmaker | 21f5850 | 2014-04-29 15:25:17 -0400 | [diff] [blame] | 297 | __set_breakpoint(info); |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 298 | out: |
| 299 | rcu_read_unlock(); |
| 300 | return rc; |
| 301 | } |
Nicholas Piggin | 03465f8 | 2016-09-16 20:48:08 +1000 | [diff] [blame] | 302 | NOKPROBE_SYMBOL(hw_breakpoint_handler); |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 303 | |
| 304 | /* |
| 305 | * Handle single-step exceptions following a DABR hit. |
| 306 | */ |
Nicholas Piggin | 03465f8 | 2016-09-16 20:48:08 +1000 | [diff] [blame] | 307 | static int single_step_dabr_instruction(struct die_args *args) |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 308 | { |
| 309 | struct pt_regs *regs = args->regs; |
| 310 | struct perf_event *bp = NULL; |
Michael Neuling | 3f4693e | 2012-09-05 19:17:48 +0000 | [diff] [blame] | 311 | struct arch_hw_breakpoint *info; |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 312 | |
| 313 | bp = current->thread.last_hit_ubp; |
| 314 | /* |
| 315 | * Check if we are single-stepping as a result of a |
| 316 | * previous HW Breakpoint exception |
| 317 | */ |
| 318 | if (!bp) |
| 319 | return NOTIFY_DONE; |
| 320 | |
Michael Neuling | 3f4693e | 2012-09-05 19:17:48 +0000 | [diff] [blame] | 321 | info = counter_arch_bp(bp); |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 322 | |
| 323 | /* |
| 324 | * We shall invoke the user-defined callback function in the single |
| 325 | * stepping handler to confirm to 'trigger-after-execute' semantics |
| 326 | */ |
Michael Neuling | 9422de3 | 2012-12-20 14:06:44 +0000 | [diff] [blame] | 327 | if (!(info->type & HW_BRK_TYPE_EXTRANEOUS_IRQ)) |
K.Prasad | e3e9408 | 2010-06-15 11:36:12 +0530 | [diff] [blame] | 328 | perf_bp_event(bp, regs); |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 329 | |
Paul Gortmaker | 21f5850 | 2014-04-29 15:25:17 -0400 | [diff] [blame] | 330 | __set_breakpoint(info); |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 331 | current->thread.last_hit_ubp = NULL; |
Paul Mackerras | 76b0f13 | 2010-06-23 15:46:55 +1000 | [diff] [blame] | 332 | |
| 333 | /* |
| 334 | * If the process was being single-stepped by ptrace, let the |
| 335 | * other single-step actions occur (e.g. generate SIGTRAP). |
| 336 | */ |
| 337 | if (test_thread_flag(TIF_SINGLESTEP)) |
| 338 | return NOTIFY_DONE; |
| 339 | |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 340 | return NOTIFY_STOP; |
| 341 | } |
Nicholas Piggin | 03465f8 | 2016-09-16 20:48:08 +1000 | [diff] [blame] | 342 | NOKPROBE_SYMBOL(single_step_dabr_instruction); |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 343 | |
| 344 | /* |
| 345 | * Handle debug exception notifications. |
| 346 | */ |
Nicholas Piggin | 03465f8 | 2016-09-16 20:48:08 +1000 | [diff] [blame] | 347 | int hw_breakpoint_exceptions_notify( |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 348 | struct notifier_block *unused, unsigned long val, void *data) |
| 349 | { |
| 350 | int ret = NOTIFY_DONE; |
| 351 | |
| 352 | switch (val) { |
| 353 | case DIE_DABR_MATCH: |
| 354 | ret = hw_breakpoint_handler(data); |
| 355 | break; |
| 356 | case DIE_SSTEP: |
| 357 | ret = single_step_dabr_instruction(data); |
| 358 | break; |
| 359 | } |
| 360 | |
| 361 | return ret; |
| 362 | } |
Nicholas Piggin | 03465f8 | 2016-09-16 20:48:08 +1000 | [diff] [blame] | 363 | NOKPROBE_SYMBOL(hw_breakpoint_exceptions_notify); |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 364 | |
| 365 | /* |
| 366 | * Release the user breakpoints used by ptrace |
| 367 | */ |
| 368 | void flush_ptrace_hw_breakpoint(struct task_struct *tsk) |
| 369 | { |
| 370 | struct thread_struct *t = &tsk->thread; |
| 371 | |
| 372 | unregister_hw_breakpoint(t->ptrace_bps[0]); |
| 373 | t->ptrace_bps[0] = NULL; |
| 374 | } |
| 375 | |
| 376 | void hw_breakpoint_pmu_read(struct perf_event *bp) |
| 377 | { |
| 378 | /* TODO */ |
| 379 | } |