Skip to content

RFC arm64: Make the kprobes debug exception path noinstr

Hongyan Xia linux-arm-kernel linux-mm linux-trace-kernel lkml llvm 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest9 patches 20 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/9arm64/entry: Bound certain debug exception paths in instrumentation windowsarch/arm64/kernel/entry-common.c+17 -22 replies
2/9arm64/entry: Make debug_exception_enter/exit() noinstrarch/arm64/kernel/entry-common.c+15 -91 reply
3/9arm64/debug-monitors: Make do_el1_brk64()/do_el1_softstep() noinstrarch/arm64/kernel/debug-monitors.c+41 -332 replies
4/9arm64/kprobes: Make the single-step machinery noinstrarch/arm64/kernel/probes/kprobes.c+24 -153 replies
5/9arm64/kprobes: Invoke pre/post handlers inside instrumentationarch/arm64/include/asm/kprobes.h arch/arm64/kernel/probes/kprobes.c+21 -102 replies
6/9arm64/kprobes: Make kprobe_fault_handler() noinstrarch/arm64/kernel/probes/kprobes.c+1 -12 replies
7/9arm64/kprobes: Drop the KPROBE_HIT_SS reentry special casearch/arm64/include/asm/kprobes.h arch/arm64/kernel/probes/kprobes.c+1 -260 replies
8/9arm64/kprobes: Drop the XOL single-step fault PC checkarch/arm64/kernel/probes/kprobes.c+0 -121 reply
9/9arm64/debug: Mark debug exception helpers __always_inlinearch/arm64/include/asm/esr.h arch/arm64/include/asm/percpu.h arch/arm64/include/asm/preempt.h +3 more+11 -117 replies

Reviews trailers per patch

1 of 9 patches has a Reviewed-by or Acked-by.

PatchMasami Hiramatsu (Google)
1/9
2/9
3/9
4/9
5/9
6/9
7/9
8/9
9/9A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [RFC PATCH 0/9] arm64: Make the kprobes debug exception path noinstr

From: Hongyan Xia <[email protected]>

Commit 879a6754d3d1 ("arm64: kprobes: Only handle faults originating from XOL slot") and 23f851ac0078 ("arm64: kprobes: Allow reentering kprobes while single-stepping") band-aided two corner cases in the arm64 kprobe path: Unrelated page faults inside Kprobe and nested Kprobe SS handling. Although the two patches were taken, Will asked whether we should keep patching things like this each time we find a corner case, and whether making Kprobe noinstr is the correct answer [1].

This series attempts to do exactly that: Making the Kprobe path noinstr. The kprobe handlers become noinstr end to end, and everything that is inherently instrumentable is confined to instrumentation_begin/end() windows, similar to the x86 side. After this series, the two corner-cases mentioned above are also gone, hence the revert in 7/9 and 8/9. Some of the instrumentation_begin/end() sections are suggested by AI, so they may need careful review.

Note that arm64 has no objtool to validate noinstr, so I wrote a small script finding bl/blr and validated that their calls are confined within noinstr. This is exactly what found the Clang outline compile problem that motivated patch 9/9.

One question is whether other BRK paths get the same treatment. Currently they stay instrumentable inside a big window.

[1] https://lore.kernel.org/all/alpuL10h7-OK2hFb@willie-the-truck/

Hongyan Xia (9):
arm64/entry: Bound certain debug exception paths in instrumentation
windows
arm64/entry: Make debug_exception_enter/exit() noinstr arm64/debug-monitors: Make do_el1_brk64()/do_el1_softstep() noinstr arm64/kprobes: Make the single-step machinery noinstr arm64/kprobes: Invoke pre/post handlers inside instrumentation arm64/kprobes: Make kprobe_fault_handler() noinstr arm64/kprobes: Drop the KPROBE_HIT_SS reentry special case arm64/kprobes: Drop the XOL single-step fault PC check arm64/debug: Mark debug exception helpers __always_inline

 arch/arm64/include/asm/esr.h       |  2 +-
 arch/arm64/include/asm/kprobes.h   | 15 +----
 arch/arm64/include/asm/percpu.h    |  2 +-
 arch/arm64/include/asm/preempt.h   |  4 +-
 arch/arm64/include/asm/ptrace.h    |  4 +-
 arch/arm64/kernel/debug-monitors.c | 76 ++++++++++++-----------
 arch/arm64/kernel/entry-common.c   | 43 +++++++++----
 arch/arm64/kernel/probes/kprobes.c | 96 ++++++++++++++----------------
 include/linux/kprobes.h            |  8 +--
 9 files changed, 131 insertions(+), 119 deletions(-)
Signature · 1 line
2.47.3