Skip to content

probes: Use trace_printk() in probe handlers

Masami Hiramatsu (Google) linux-doc linux-trace-kernel lkml 1 version In review

Get series with b4
b4 am 179360345418.115681.193455787480210412.stgit@devnote2

Versions newest first

  1. v1 Latest3 patches 7 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3samples/kprobes: Use trace_printk() in probe handlerssamples/Kconfig samples/kprobes/kprobe_example.c samples/kprobes/kretprobe_example.c+41 -400 replies
2/3samples/fprobe: Use trace_printk() and trace_dump_stack()samples/Kconfig samples/fprobe/fprobe_example.c+11 -400 replies
3/3docs: trace: Warn against using printk() in probe handlersDocumentation/trace/fprobe.rst Documentation/trace/kprobes.rst+14 -20 replies

Reviews trailers per patch

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

Read the v1 thread

Cover letter [PATCH 0/3] probes: Use trace_printk() in probe handlers

Hi,

Here are patches to update the probe sample code to use trace_printk instead of normal printk. Since the fprobe and kprobe/kretprobe handlers can be called from somewhere where console is locked, using printk() is basically unsafe. Only the unoptimized kprobe on x86 is safe because it is ran with NMI context (in this case, the kernel uses printk_deferred() automatically), but optimized kprobe/kretprobe/fprobe are not.

Thus, this series replaces those printk() (pr_*()) with trace_printk() which should be safe to output the result into trace buffer, and use trace_dump_stack() instead of stack_trace_print().

The similar issue had been reported by Tiezhu Yang [1] in 2023, but it was pointed different reason, and not applicable to upstream. I investigated it again.

[1] https://lore.kernel.org/all/[email protected]/

Thank you,
---
base-commit: bc71431221f5ba8bb33918399552636e059c2c45

Masami Hiramatsu (Google) (3):
samples/kprobes: Use trace_printk() in probe handlers samples/fprobe: Use trace_printk() and trace_dump_stack()
docs: trace: Warn against using printk() in probe handlers

 Documentation/trace/fprobe.rst      |    5 +++
 Documentation/trace/kprobes.rst     |   11 +++++-
 samples/Kconfig                     |    4 +-
 samples/fprobe/fprobe_example.c     |   49 +++++--------------------
 samples/kprobes/kprobe_example.c    |   69 ++++++++++++++++++-----------------
 samples/kprobes/kretprobe_example.c |   10 +++--
 6 files changed, 66 insertions(+), 82 deletions(-)

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