Skip to content

RFC kernel/events/uprobes: uprobe_write_opcode() rewrite

David Hildenbrand linux-arm-kernel linux-mm linux-perf-users lkml 1 version New

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest3 patches 0 repliesNew

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3kernel/events/uprobes: pass VMA instead of MM to install_breakpoint()kernel/events/uprobes.c+11 -90 replies
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 replies
3/3kernel/events/uprobes: uprobe_write_opcode() rewritekernel/events/uprobes.c+194 -1480 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH RFC 0/3] kernel/events/uprobes: uprobe_write_opcode() rewrite

Against mm/mm-unstable.

There is interest in supporting uprobes on hugetlb pages [1]. Having uprobe_write_opcode() implement COW-breaking itself is really far from optimal, and having to add hugetlb COW-breaking to implement hugetlb support really does sound wrong.

Further, 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.

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 write fault to break COW to then modify the already-mapped page.

Briefly sanity tested with perf:
[root@localhost ~]# perf probe -x /usr/bin/bash -a main
...
[root@localhost ~]# perf record -e probe_bash:main -aR sleep 10 &
[1] 2196
[root@localhost ~]# bash
[root@localhost ~]# exit
exit
[root@localhost ~]# bash
[root@localhost ~]# exit
exit
[root@localhost ~]# [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.287 MB perf.data (8 samples) ]
...
[root@localhost ~]# perf report --stdio
# To display the perf.data header info, please use --header/--header-only optio> #
#
# Total Lost Samples: 0
#
# Samples: 8 of event 'probe_bash:main'
# Event count (approx.): 8
#

  # Overhead  Command      Shared Object  Symbol  
  # ........  ...........  .............  ........
  #
      75.00%  grepconf.sh  bash           [.] main
      25.00%  bash         bash           [.] main

...

Are there any uprobe tests / benchmarks that are worth running?

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

Cc Andrew Morton <[email protected]>
Cc Guillaume Morin <[email protected]>
Cc Russell King <[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]>

David Hildenbrand (3):
kernel/events/uprobes: pass VMA instead of MM to install_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        | 387 +++++++++++++++++++--------------
 3 files changed, 223 insertions(+), 174 deletions(-)

base-commit: 065d3634d60843b8e338d405b844cc7f2e5e1c66

Signature · 1 line
2.45.1