From: "Masami Hiramatsu (Google)" <mhiramat@kernel.org>
To: Steven Rostedt <rostedt@goodmis.org>,
Masami Hiramatsu <mhiramat@kernel.org>,
Jonathan Corbet <corbet@lwn.net>,
Naveen N Rao <naveen@kernel.org>,
"David S . Miller" <davem@davemloft.net>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
Shuah Khan <skhan@linuxfoundation.org>,
Randy Dunlap <rdunlap@infradead.org>,
Tiezhu Yang <yangtiezhu@loongson.cn>,
linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org,
linux-doc@vger.kernel.org
Subject: [PATCH 0/3] probes: Use trace_printk() in probe handlers
Date: Mon, 2 Nov 2026 16:10:54 +0900 [thread overview]
Message-ID: <179360345418.115681.193455787480210412.stgit@devnote2> (raw)
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/d179086d-78d8-d0e3-e113-9072cffa55f4@loongson.cn/
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) <mhiramat@kernel.org>
next reply other threads:[~2026-11-02 7:10 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-02 7:10 Masami Hiramatsu (Google) [this message]
2026-11-02 7:11 ` [PATCH 1/3] samples/kprobes: Use trace_printk() in probe handlers Masami Hiramatsu (Google)
2026-11-02 7:11 ` [PATCH 2/3] samples/fprobe: Use trace_printk() and trace_dump_stack() Masami Hiramatsu (Google)
2026-11-02 7:11 ` [PATCH 3/3] docs: trace: Warn against using printk() in probe handlers Masami Hiramatsu (Google)
2026-11-02 17:34 ` [PATCH 0/3] probes: Use trace_printk() " Steven Rostedt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=179360345418.115681.193455787480210412.stgit@devnote2 \
--to=mhiramat@kernel.org \
--cc=corbet@lwn.net \
--cc=davem@davemloft.net \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=naveen@kernel.org \
--cc=rdunlap@infradead.org \
--cc=rostedt@goodmis.org \
--cc=skhan@linuxfoundation.org \
--cc=yangtiezhu@loongson.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox