hw_breakpoint: fix single-stepping when using bpf_overflow_handler
authorTomislav Novak <tnovak@meta.com>
Mon, 5 Jun 2023 19:19:23 +0000 (12:19 -0700)
committerWill Deacon <will@kernel.org>
Fri, 18 Aug 2023 16:04:09 +0000 (17:04 +0100)
commitd11a69873d9a7435fe6a48531e165ab80a8b1221
tree496449640d13575a9a703f6161042ac9990b5a61
parentf4e2bd91ddf5e8543cbe7ad80b3fba3d2dc63fa3
hw_breakpoint: fix single-stepping when using bpf_overflow_handler

Arm platforms use is_default_overflow_handler() to determine if the
hw_breakpoint code should single-step over the breakpoint trigger or
let the custom handler deal with it.

Since bpf_overflow_handler() currently isn't recognized as a default
handler, attaching a BPF program to a PERF_TYPE_BREAKPOINT event causes
it to keep firing (the instruction triggering the data abort exception
is never skipped). For example:

  # bpftrace -e 'watchpoint:0x10000:4:w { print("hit") }' -c ./test
  Attaching 1 probe...
  hit
  hit
  [...]
  ^C

(./test performs a single 4-byte store to 0x10000)

This patch replaces the check with uses_default_overflow_handler(),
which accounts for the bpf_overflow_handler() case by also testing
if one of the perf_event_output functions gets invoked indirectly,
via orig_default_handler.

Signed-off-by: Tomislav Novak <tnovak@meta.com>
Tested-by: Samuel Gosselin <sgosselin@google.com> # arm64
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/linux-arm-kernel/20220923203644.2731604-1-tnovak@fb.com/
Link: https://lore.kernel.org/r/20230605191923.1219974-1-tnovak@meta.com
Signed-off-by: Will Deacon <will@kernel.org>
arch/arm/kernel/hw_breakpoint.c
arch/arm64/kernel/hw_breakpoint.c
include/linux/perf_event.h