Lines Matching +full:local +full:- +full:bd +full:- +full:address
1 // SPDX-License-Identifier: GPL-2.0-or-later
14 * HW_breakpoint: a unified kernel/user-space hardware breakpoint facility,
42 /* Per cpu debug address registers values */
46 * Stores the breakpoints currently in use on each breakpoint address
90 * We seek a free debug address register and use it for this
93 * Atomic: we hold the counter->ctx->lock and we only handle variables
94 * and registers local to this cpu.
114 return -EBUSY; in arch_install_hw_breakpoint()
116 set_debugreg(info->address, i); in arch_install_hw_breakpoint()
117 __this_cpu_write(cpu_debugreg[i], info->address); in arch_install_hw_breakpoint()
120 *dr7 |= encode_dr7(i, info->len, info->type); in arch_install_hw_breakpoint()
129 if (info->mask) in arch_install_hw_breakpoint()
130 amd_set_dr_addr_mask(info->mask, i); in arch_install_hw_breakpoint()
138 * First we search the debug address register it uses and then we disable
141 * Atomic: we hold the counter->ctx->lock and we only handle variables
142 * and registers local to this cpu.
165 dr7 &= ~__encode_dr7(i, info->len, info->type); in arch_uninstall_hw_breakpoint()
168 if (info->mask) in arch_uninstall_hw_breakpoint()
194 return -EINVAL; in arch_bp_generic_len()
207 return -EINVAL; in arch_bp_generic_fields()
219 return -EINVAL; in arch_bp_generic_fields()
225 return -EINVAL; in arch_bp_generic_fields()
232 * Check for virtual address in kernel space.
239 va = hw->address; in arch_check_bp_in_kernelspace()
240 len = arch_bp_generic_len(hw->len); in arch_check_bp_in_kernelspace()
244 * We don't need to worry about va + len - 1 overflowing: in arch_check_bp_in_kernelspace()
247 return (va >= TASK_SIZE_MAX) || ((va + len - 1) >= TASK_SIZE_MAX); in arch_check_bp_in_kernelspace()
273 * When FSGSBASE is enabled, paranoid_entry() fetches the per-CPU in within_cpu_entry()
313 * will read per-cpu cpu_dr7 before clear dr7 register. in within_cpu_entry()
329 bp_end = attr->bp_addr + attr->bp_len - 1; in arch_build_bp_info()
330 if (bp_end < attr->bp_addr) in arch_build_bp_info()
331 return -EINVAL; in arch_build_bp_info()
339 if (within_cpu_entry(attr->bp_addr, bp_end)) in arch_build_bp_info()
340 return -EINVAL; in arch_build_bp_info()
342 hw->address = attr->bp_addr; in arch_build_bp_info()
343 hw->mask = 0; in arch_build_bp_info()
346 switch (attr->bp_type) { in arch_build_bp_info()
348 hw->type = X86_BREAKPOINT_WRITE; in arch_build_bp_info()
351 hw->type = X86_BREAKPOINT_RW; in arch_build_bp_info()
356 * acceptable for kprobes. On non-kprobes kernels, we don't in arch_build_bp_info()
359 if (attr->bp_addr >= TASK_SIZE_MAX) { in arch_build_bp_info()
360 if (within_kprobe_blacklist(attr->bp_addr)) in arch_build_bp_info()
361 return -EINVAL; in arch_build_bp_info()
364 hw->type = X86_BREAKPOINT_EXECUTE; in arch_build_bp_info()
370 if (attr->bp_len == sizeof(long)) { in arch_build_bp_info()
371 hw->len = X86_BREAKPOINT_LEN_X; in arch_build_bp_info()
376 return -EINVAL; in arch_build_bp_info()
380 switch (attr->bp_len) { in arch_build_bp_info()
382 hw->len = X86_BREAKPOINT_LEN_1; in arch_build_bp_info()
385 hw->len = X86_BREAKPOINT_LEN_2; in arch_build_bp_info()
388 hw->len = X86_BREAKPOINT_LEN_4; in arch_build_bp_info()
392 hw->len = X86_BREAKPOINT_LEN_8; in arch_build_bp_info()
397 if (!is_power_of_2(attr->bp_len)) in arch_build_bp_info()
398 return -EINVAL; in arch_build_bp_info()
399 if (attr->bp_addr & (attr->bp_len - 1)) in arch_build_bp_info()
400 return -EINVAL; in arch_build_bp_info()
403 return -EOPNOTSUPP; in arch_build_bp_info()
407 * user vs kernel detection because bp_len - 1 can't in arch_build_bp_info()
409 * breakpoints, then we'll have to check for kprobe-blacklisted in arch_build_bp_info()
412 hw->mask = attr->bp_len - 1; in arch_build_bp_info()
413 hw->len = X86_BREAKPOINT_LEN_1; in arch_build_bp_info()
420 * Validate the arch-specific HW Breakpoint register settings
434 switch (hw->len) { in hw_breakpoint_arch_parse()
437 if (hw->mask) in hw_breakpoint_arch_parse()
438 align = hw->mask; in hw_breakpoint_arch_parse()
453 return -EINVAL; in hw_breakpoint_arch_parse()
457 * Check that the low-order bits of the address are appropriate in hw_breakpoint_arch_parse()
460 if (hw->address & align) in hw_breakpoint_arch_parse()
461 return -EINVAL; in hw_breakpoint_arch_parse()
472 struct thread_struct *t = &tsk->thread; in flush_ptrace_hw_breakpoint()
475 unregister_hw_breakpoint(t->ptrace_bps[i]); in flush_ptrace_hw_breakpoint()
476 t->ptrace_bps[i] = NULL; in flush_ptrace_hw_breakpoint()
479 t->virtual_dr6 = 0; in flush_ptrace_hw_breakpoint()
480 t->ptrace_dr7 = 0; in flush_ptrace_hw_breakpoint()
500 * i) When the causative address is from user-space and the exception
504 * as BD, BS or BT) indicating that more than one debug condition is
518 /* The DR6 value is pointed by args->err */ in hw_breakpoint_handler()
519 dr6_p = (unsigned long *)ERR_PTR(args->err); in hw_breakpoint_handler()
535 bpx = bp->hw.info.type == X86_BREAKPOINT_EXECUTE; in hw_breakpoint_handler()
555 perf_bp_event(bp, args->regs); in hw_breakpoint_handler()
562 args->regs->flags |= X86_EFLAGS_RF; in hw_breakpoint_handler()
566 * Further processing in do_debug() is needed for a) user-space in hw_breakpoint_handler()
570 if ((current->thread.virtual_dr6 & DR_TRAP_BITS) || in hw_breakpoint_handler()