ARM: 9316/1: hw_breakpoint: fix single-stepping when using bpf_overflow_handler
authorTomislav Novak <tnovak@fb.com>
Tue, 20 Jun 2023 17:54:11 +0000 (18:54 +0100)
committerRussell King (Oracle) <rmk+kernel@armlinux.org.uk>
Mon, 14 Aug 2023 11:16:58 +0000 (12:16 +0100)
commite6b51532d5273eeefba84106daea3d392c602837
treed2ebbb9dbaa8e2afb41620cc03f9324d57b79aec
parent06c2afb862f9da8dc5efa4b6076a0e48c3fbaaa5
ARM: 9316/1: 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.

Link: https://lore.kernel.org/linux-arm-kernel/20220923203644.2731604-1-tnovak@fb.com/
Signed-off-by: Tomislav Novak <tnovak@fb.com>
Tested-by: Samuel Gosselin <sgosselin@google.com> # arm64
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
arch/arm/kernel/hw_breakpoint.c
arch/arm64/kernel/hw_breakpoint.c
include/linux/perf_event.h