Skip to content

kprobes: rethook: x86: Replace kretprobe trampoline with rethook

Masami Hiramatsu bpf kernel-janitors lkml 3 versions – Applied

Status from this message: This series was applied to bpf/bpf.git (master)

Get series with b4
b4 am 164826160914.2455864.505359679001055158.stgit@devnote2

Versions newest first · linked by author and title

  1. v3 Latest4 patches 0 repliesApplied 4/4
  2. v24 patches 6 repliesSuperseded
  3. v12 patches 6 repliesSuperseded

Patches in v3 All 4 applied

#Subject and filesSizeRepliesApplied
1/4kprobes: Use rethook for kretprobe if possiblearch/Kconfig include/linux/kprobes.h kernel/Makefile +2 more+163 -250 repliesApplied
2/4x86,rethook,kprobes: Replace kretprobe with rethook on x86arch/x86/Kconfig arch/x86/include/asm/unwind.h arch/x86/kernel/Makefile +4 more+144 -1230 repliesApplied
3/4x86,rethook: Fix arch_rethook_trampoline() to generate a complete pt_regsarch/x86/kernel/rethook.c+13 -110 repliesApplied
4/4x86,kprobes: Fix optprobe trampoline to generate complete pt_regsarch/x86/kernel/kprobes/opt.c+16 -90 repliesApplied

Reviews trailers per patch

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

PatchJiri OlsaMasami Hiramatsu
1/4
2/4T-b
3/4R-b
4/4

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

Read the v3 thread

Cover letter [PATCH bpf-next v3 0/4] kprobes: rethook: x86: Replace kretprobe trampoline with rethook

Hi,

Here are the 3rd version for generic kretprobe and kretprobe on x86 for replacing the kretprobe trampoline with rethook. The previous version is here[1]

[1] https://lore.kernel.org/all/164821817332.2373735.12048266953420821089.stgit@devnote2/T/#u

This version fixed typo and build issues for bpf-next and CONFIG_RETHOOK=y error. I also add temporary mitigation lines for ANNOTATE_NOENDBR macro issue for bpf-next tree [2/4].

#ifndef ANNOTATE_NOENDBR
#define ANNOTATE_NOENDBR
#endif

This will be removed after merging kernel IBT series.

Background:

This rethook came from Jiri's request of multiple kprobe for bpf[2]. He tried to solve an issue that starting bpf with multiple kprobe will take a long time because bpf-kprobe will wait for RCU grace period for sync rcu events.

Jiri wanted to attach a single bpf handler to multiple kprobes and he tried to introduce multiple-probe interface to kprobe. So I asked him to use ftrace and kretprobe-like hook if it is only for the function entry and exit, instead of adding ad-hoc interface to kprobes.
For this purpose, I introduced the fprobe (kprobe like interface for ftrace) with the rethook (this is a generic return hook feature for fprobe exit handler)[3].

[2] https://lore.kernel.org/all/[email protected]/T/#u
[3] https://lore.kernel.org/all/164191321766.806991.7930388561276940676.stgit@devnote2/T/#u

The rethook is basically same as the kretprobe trampoline. I just made it decoupled from kprobes. Eventually, the all arch dependent kretprobe trampolines will be replaced with the rethook trampoline instead of cloning and set HAVE_RETHOOK=y.
When I port the rethook for all arch which supports kretprobe, the legacy kretprobe specific code (which is for CONFIG_KRETPROBE_ON_RETHOOK=n) will be removed eventually.

Thank you,

---

Masami Hiramatsu (3):
kprobes: Use rethook for kretprobe if possible x86,rethook,kprobes: Replace kretprobe with rethook on x86 x86,kprobes: Fix optprobe trampoline to generate complete pt_regs

Peter Zijlstra (1):
x86,rethook: Fix arch_rethook_trampoline() to generate a complete pt_regs

 arch/Kconfig                     |    8 ++
 arch/x86/Kconfig                 |    1 
 arch/x86/include/asm/unwind.h    |   23 +++----
 arch/x86/kernel/Makefile         |    1 
 arch/x86/kernel/kprobes/common.h |    1 
 arch/x86/kernel/kprobes/core.c   |  106 --------------------------------
 arch/x86/kernel/kprobes/opt.c    |   25 +++++--
 arch/x86/kernel/rethook.c        |  127 ++++++++++++++++++++++++++++++++++++++
 arch/x86/kernel/unwind_orc.c     |   10 +--
 include/linux/kprobes.h          |   51 +++++++++++++++
 kernel/Makefile                  |    1 
 kernel/kprobes.c                 |  124 +++++++++++++++++++++++++++++++------
 kernel/trace/trace_kprobe.c      |    4 +
 13 files changed, 325 insertions(+), 157 deletions(-)
 create mode 100644 arch/x86/kernel/rethook.c

--
Masami Hiramatsu (Linaro) <[email protected]>