Skip to content

RFC Mark Kprobe debug exception paths 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. v2 RFC Latest4 patches 5 repliesIn review

Changes in v2 from the cover letter

- Remove instrumentation_{begin/end}() markers as they do nothing
- Fold __always_inline into the patches that actually need them
- Remove the debug exception path changes unrelated to Kprobe. This series is only about Kprobe for now
- Drop the kprobe_page_fault() patch for now. It's a question whether we even need it at all. Will send a patch for it separately.

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/4arm64/entry: Make debug_exception_enter/exit() noinstrarch/arm64/include/asm/preempt.h arch/arm64/kernel/entry-common.c+6 -111 reply
2/4arm64/debug: Make the Kprobe functions noinstrarch/arm64/include/asm/esr.h arch/arm64/include/asm/kprobes.h arch/arm64/kernel/debug-monitors.c +1 more+9 -141 reply
3/4arm64/kprobes: Make the entire Kprobe noinstrarch/arm64/include/asm/percpu.h arch/arm64/include/asm/ptrace.h arch/arm64/kernel/probes/kprobes.c +1 more+22 -220 replies
4/4Revert "arm64: kprobes: Allow reentering kprobes while single-stepping"arch/arm64/include/asm/kprobes.h arch/arm64/kernel/probes/kprobes.c+1 -280 replies

Reviews trailers per patch

2 of 4 patches have a Reviewed-by or Acked-by.

PatchMasami Hiramatsu (Google)
1/4R-b
2/4R-b
3/4
4/4

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

Read the v2 thread

Cover letter [RFC PATCH v2 0/4] Mark Kprobe debug exception paths 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: Nested 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. Apart from marking functions noinstr, we also force-inline some static inline helper functions because certain compilers still outline them, breaking noinstr.

Note that arm64 has no objtool so at the moment noinstr is more of a contract that must be followed, instead of actually enforcing control flow. Instrumentation can still happen if someone with root privileges does something stupid, but now it is regarded as a bug rather than a legitimate use case that the kernel needs to cover.

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

Changed in v2:
- Remove instrumentation_{begin/end}() markers as they do nothing
- Fold __always_inline into the patches that actually need them
- Remove the debug exception path changes unrelated to Kprobe. This series is only about Kprobe for now
- Drop the kprobe_page_fault() patch for now. It's a question whether we even need it at all. Will send a patch for it separately.

Hongyan Xia (4):
arm64/entry: Make debug_exception_enter/exit() noinstr arm64/debug: Make the Kprobe functions noinstr arm64/kprobes: Make the entire Kprobe noinstr Revert "arm64: kprobes: Allow reentering kprobes while
single-stepping"

 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 |  6 +--
 arch/arm64/kernel/entry-common.c   | 13 ++-----
 arch/arm64/kernel/probes/kprobes.c | 59 ++++++++++--------------------
 include/linux/kprobes.h            |  8 ++--
 9 files changed, 38 insertions(+), 75 deletions(-)
Signature · 1 line
2.47.3