Linux Documentation
 help / color / mirror / Atom feed
From: Petr Mladek <pmladek@suse.com>
To: "Masami Hiramatsu (Google)" <mhiramat@kernel.org>
Cc: John Ogness <john.ogness@linutronix.de>,
	Steven Rostedt <rostedt@goodmis.org>,
	Jonathan Corbet <corbet@lwn.net>,
	Naveen N Rao <naveen@kernel.org>,
	"David S . Miller" <davem@davemloft.net>,
	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: Re: [PATCH 0/3] probes: Use trace_printk() in probe handlers
Date: Tue, 3 Nov 2026 12:11:47 +0100	[thread overview]
Message-ID: <aunBcxXXNhXDd-U5@pathway.suse.cz> (raw)
In-Reply-To: <undine-1793671566795563056-fb7169cffcc7ac3c@undined.local>

On Tue 2026-11-03 11:06:06, Masami Hiramatsu (Google) wrote:
> On Mon, 02 Nov 2026 23:07:41 +0106, John Ogness <john.ogness@linutronix.de> wrote:
> > [ Cc'ing Petr Mladek ]
> > 
> > On 2026-11-02, Steven Rostedt <rostedt@goodmis.org> wrote:
> > > [ Cc'ing John Ogness ]
> > 
> > Thanks.
> > 
> > >
> > > On Mon,  2 Nov 2026 16:10:54 +0900
> > > "Masami Hiramatsu (Google)" <mhiramat@kernel.org> wrote:
> > >> 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.
> > >
> > > I don't think printk() is unsafe in these situations anymore.
> > 
> > Since we still support legacy consoles, it is true that printk() is not
> > safe in these contexts when a legacy console is registered.
> > 
> > However, the printk_deferred() variant _is_ safe from any context. Once
> > we convert the legacy consoles (including boot consoles) to nbcon,
> > printk_deferred() can become printk() and still be safe from any
> > context.
> 
> Got it. But since printk_deferred() is not exposed to modules,
> these sample modules can not use it. (printk_deferred_enter/exit()
> are also not exposed.)

We could export it if it would be useful for kprobes...

> > It is misfortunate to add documentation saying printk() is not safe,
> > since the problem is converting the remaining legacy consoles. But we
> > can cleanup all such documentation later once the legacy consoles are
> > gone.
> 
> So, until it is done, this series is valid. Please let me know it.
> After that version, I can revert these.

I do not have strong opinion here.

It just looks to me that using trace_printk() everywhere is an
overkill. It is true that printk() is not safe when probing some
locations, e.g. where a console is locked. But these are locations
where you could not use printk() even in the probed code.

I believe that trace_printk() has a similar problem. You could
not use it inside the code used by trace_printk() because
it might cause an unbound recursion.

I agree that the scope of the code used by trace_printk() is
smaller than the code used by console drivers. Also it is better
located. And maybe, the recursion can be even detected and handled.

But still, the point is that even trace_printk() is not a 100%
safe cure. So, maybe, instead of proposing trace_printk() everywhere,
it might be enough to propose it only for probing the printk/console
related code. Well, I know that it involves also some less obvious
areas, for example, irq_work, some timer and scheduler code.

That said, I do not want to block this patchset. It is solving
some real problems...

Best Regards,
Petr

  reply	other threads:[~2026-11-03 11:11 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-02  7:10 [PATCH 0/3] probes: Use trace_printk() in probe handlers Masami Hiramatsu (Google)
2026-11-02  7:11 ` [PATCH 1/3] samples/kprobes: " 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
2026-11-02 22:01   ` John Ogness
2026-11-03  2:06     ` Masami Hiramatsu (Google)
2026-11-03 11:11       ` Petr Mladek [this message]
2026-11-03 14:09         ` 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=aunBcxXXNhXDd-U5@pathway.suse.cz \
    --to=pmladek@suse.com \
    --cc=corbet@lwn.net \
    --cc=davem@davemloft.net \
    --cc=john.ogness@linutronix.de \
    --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=mhiramat@kernel.org \
    --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