Skip to content

kernel/events/uprobes: uprobe_write_opcode() rewrite

David Hildenbrand linux-arm-kernel linux-mm linux-perf-users linux-trace-kernel lkml 3 versions – Applied

Status from this message: [merged mm-stable] kernel-events-uprobes-uprobe_write_opcode-rewrite.patch removed from -mm tree

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest3 patches 4 repliesApplied 3/3
  2. v23 patches 2 repliesSuperseded
  3. v13 patches 11 repliesSuperseded

Changes in v3 from the cover letter

* Fix missing folio_put()

Patches in v3 All 3 applied

#Subject and filesSizeRepliesApplied
1/3kernel/events/uprobes: pass VMA instead of MM to remove_breakpoint()kernel/events/uprobes.c+11 -90 repliesApplied
2/3kernel/events/uprobes: pass VMA to set_swbp(), set_orig_insn() and uprobe_write_opcode()arch/arm/probes/uprobes/core.c include/linux/uprobes.h kernel/events/uprobes.c+22 -210 repliesApplied
3/3kernel/events/uprobes: uprobe_write_opcode() rewritekernel/events/uprobes.c+158 -1542 repliesApplied

Reviews trailers per patch

All 3 patches have a Reviewed-by or Acked-by of their own; the series has one for all of them.

PatchOleg NesterovPeter Zijlstra (Intel)
SeriesA-b
1/3A-b
2/3A-b
3/3A-b

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 v3 0/3] kernel/events/uprobes: uprobe_write_opcode() rewrite

Based on mm/unstable.

Currently, uprobe_write_opcode() implements COW-breaking manually, which is really far from ideal. Further, there is interest in supporting uprobes on hugetlb pages [1], and leaving at least the COW-breaking to the core will make this much easier.

Also, I think the current code doesn't really handle some things properly (see patch #3) when replacing/zapping pages.

Let's rewrite it, to leave COW-breaking to the fault handler, and handle registration/unregistration by temporarily unmapping the anonymous page, modifying it, and mapping it again. We still have to implement zapping of anonymous pages ourselves, unfortunately.

We could look into not performing the temporary unmapping if we can perform the write atomically, which would likely also make adding hugetlb support a lot easier. But, limited (e.g., only PMD/PUD) hugetlb support could be added on top of this with some tweaking.

Note that we now won't have to allocate another anonymous folio when unregistering (which will be beneficial for hugetlb as well), we can simply modify the already-mapped one from the registration (if any). When registering a uprobe, we'll first trigger a ptrace-like write fault to break COW, to then modify the already-mapped page.

Briefly sanity tested with perf probes and with the bpf uprobes selftest.

v2 -> v3:
* Fix missing folio_put()

v1 -> v2:
* "kernel/events/uprobes: uprobe_write_opcode() rewrite" -> hold GUP reference longer so we can see if the page is still mapped when performing the folio_walk
-> Move anon-folio check
-> Reshuffle / cleanup some related things

RFC -> v1:
* Use folio_walk and simplify the logic

Cc Andrew Morton <[email protected]>
Cc Andrii Nakryiko <[email protected]>
Cc Matthew Wilcox <[email protected]>
Cc Russell King <[email protected]>
Cc Masami Hiramatsu <[email protected]>
Cc Oleg Nesterov <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Alexander Shishkin <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Ian Rogers <[email protected]>
Cc Adrian Hunter <[email protected]>
Cc "Liang, Kan" <[email protected]>
Cc Tong Tiangen <[email protected]>

[1] https://lkml.kernel.org/r/[email protected]

David Hildenbrand (3):
kernel/events/uprobes: pass VMA instead of MM to remove_breakpoint() kernel/events/uprobes: pass VMA to set_swbp(), set_orig_insn() and
uprobe_write_opcode()
kernel/events/uprobes: uprobe_write_opcode() rewrite

 arch/arm/probes/uprobes/core.c |   4 +-
 include/linux/uprobes.h        |   6 +-
 kernel/events/uprobes.c        | 357 +++++++++++++++++----------------
 3 files changed, 187 insertions(+), 180 deletions(-)

base-commit: a150906197a12c7b0f3f5efd844443bf98453efa

Signature · 1 line
2.48.1