Linux Documentation
 help / color / mirror / Atom feed
From: Petr Mladek <pmladek@suse.com>
To: Breno Leitao <leitao@debian.org>
Cc: John Ogness <john.ogness@linutronix.de>,
	chris@chrisdown.name, Sam Crossley <samuelcrossley@gmail.com>,
	Thomas Gleixner <tglx@kernel.org>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>,
	Jonathan Corbet <corbet@lwn.net>, Paolo Abeni <pabeni@redhat.com>,
	Randy Dunlap <rdunlap@infradead.org>,
	Sergey Senozhatsky <senozhatsky@chromium.org>,
	Shuah Khan <skhan@linuxfoundation.org>,
	Simon Horman <horms@kernel.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
	linux-doc@vger.kernel.org
Subject: Re: [PATCH RFC 0/2] netconsole: allow replaying the printk buffer on demand
Date: Tue, 27 Oct 2026 18:45:24 +0100	[thread overview]
Message-ID: <auDjNKi336lstU7j@pathway.suse.cz> (raw)
In-Reply-To: <auDETo3ot3enCEv_@gmail.com>

On Tue 2026-10-27 08:54:12, Breno Leitao wrote:
> On Tue, Oct 27, 2026 at 02:47:22PM +0100, Petr Mladek wrote:
> > On Mon 2026-10-26 10:49:32, Breno Leitao wrote:
> > > A bit of context on the use case from our side.
> > > 
> > > In an ideal world netconsole is enabled from early boot through the
> > > kernel command line, but in some case this is impossible
> > > (linux as bootloaders - ipxe/sd-stubs/etc).
> > > 
> > > The other way to setup netconsole is to create a new target at runtime
> > > through configfs. Netconsole then only sends messages from the time the
> > > target is enabled.
> > > 
> > > For this second case, I would like to replay the whole kernel log on
> > > netconsole, such as previous messages. Something might have happened
> > > before the target was enabled, and we want visibility into that.
> > 
> > Just to be sure that I understand it correctly. 
> > 
> > Is the netconsole registered before it gets functional, please?
> 
> Correct. The console is registered at module load time, in
> init_netconsole(), before any target is created.
> 
> In other words, a single console is registered at module load, and the
> netconsole targets are then handled under that same console.

I see.

> > Is it possible to detect that the netconsole is not yet functional
> > and when it could start working?
> >
> > I ask because there is the flag CON_PRINTBUFFER which should cause
> > re-playing all messages on the console during registration.
> > 
> > A solution might be to delay the console registration until
> > the netwok target is really working.
> 
> Yes, we can register the console when the target is enabled. However, I
> think the user will need to choose whether the console is registered
> with CON_PRINTBUFFER or not, since in some cases they only want messages
> from the moment the target is enabled.

It is more complicated then. IMHO, this patchset does not work
as expected. The 1st patch does:

--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -3494,13 +3494,14 @@ void console_unblank(void)
 }
 
 /*
- * Rewind all consoles to the oldest available record.
+ * Rewind a console, or all consoles if @target is NULL, to the oldest
+ * available record.
  *
  * IMPORTANT: The function is safe only when called under
  *            console_lock(). It is not enforced because
  *            it is used as a best effort in panic().
  */
-static void __console_rewind_all(void)
+static void __console_rewind(struct console *target)
 {
 	struct console *c;
 	short flags;
@@ -3511,6 +3512,9 @@ static void __console_rewind_all(void)
 
 	cookie = console_srcu_read_lock();
 	for_each_console_srcu(c) {
+		if (target && c != target)
+			continue;
+
 		flags = console_srcu_read_flags(c);
 
 		if (flags & CON_NBCON) {

Note that the filtering is done by struct console *target.
And it resets con->nbcon_seq for this structure.

But the "target" in netconsole_write() is struct netconsole_target *nt.

By other words, the messages will be replayed on all netconsole
targets associated with the given struct console. But you want
to replay it only on a particular netconsole_target.

> So we would probably need one console per netconsole target?

This might be the right solution. But it would require some
support in the register_console() and maybe in
__add_preferred_console() machinery.

The console registration code is a historical mess.
I am trying to clean this up a bit, see
https://lore.kernel.org/all/20260929120546.328616-1-pmladek@suse.com/
But it just a beginning. The code will be hairy even with this patchset.

The following problems come to my mind:

  1. The information about preferred consoles is stored into
     a static array console_cmdline[MAX_CMDLINECONSOLES].
     It is currently limited to 8 entries. I am not sure
     how much netconsole targets people use.

     We might need to create one entry for each netconsole
     target.

     Alternative solution might be to implement con->match()
     callback which would be able to share a single
     console_cmdline entry for all netconsole targets.

     Note that the ->match() callback was added to match
     real console driver with a boot console driver.
     But it should be usable to match a netconsole target
     as well.


  2. AFAIK, all console drivers are currently using a statically
     defined struct console. But we might need to allocate
     one for each netconsole target dynamically. It might
     require revisiting/adding a code for handling the
     lifetime of the structure.

     But it should be doable.


> > Another solution might be to temporary block/disable the console
> > until it gets operational. We already have console_suspend()/resume()
> > API. But we might need something new to distinguish it from
> > the system suspend/resume handling.
> 
> In that case, what happens to the console while it is suspended?

The suspended console gets stalled and the related con->nbcon_seq
stays where it is. The pending messages are flushed when the console
gets resumed.


> > > That said, the "per-console counter" might work as well, since it would
> > > start as 0, thus, we know that netconsole target would be behind, and
> > > try to replay? (not sure how yet)
> > 
> > This is what the console_try_replay_all() does. The only difference
> > is that it resets the counter to the oldest available message,
> > see __console_rewind_all(). It is just a small optimization
> > when the ring buffer is already full and the oldest messages
> > are gone.
> 
> Right, but that would apply to all consoles, while in our case we only
> want to replay the log on a specific console (netconsole).

As explained above. It is even more complicated because there
might be more netconsole_target pointers for the single
struct console netconsole.

I suggest to investigate the way with the custom ->match()
callback and dynamically allocated per-netconsole target
struct console. It would allow to have per-netconsole-target
con->nbcon_seq counter and keep the netconsole target details
in netconsole code.

You might want to wait for John's opinion before you spend
to much time on this. It is possible that I miss some
obvious problem.

Best Regards,
Petr

PS: Feel free to ask for more details. Just note that there is a public
    holiday here tomorrow. I will not be able to react before Thursday.

  reply	other threads:[~2026-10-27 17:45 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-24 23:06 [PATCH RFC 0/2] netconsole: allow replaying the printk buffer on demand Sam Crossley
2026-10-24 23:06 ` [PATCH RFC 1/2] printk: add per-console replay helper Sam Crossley
2026-10-24 23:06 ` [PATCH RFC 2/2] netconsole: add configfs trigger to replay printk buffer Sam Crossley
2026-10-26  9:34 ` [PATCH RFC 0/2] netconsole: allow replaying the printk buffer on demand John Ogness
2026-10-26 11:44   ` Breno Leitao
2026-10-26 13:09     ` John Ogness
2026-10-26 14:58       ` Petr Mladek
2026-10-26 16:33         ` John Ogness
2026-10-26 17:49           ` Breno Leitao
2026-10-27 13:47             ` Petr Mladek
2026-10-27 15:54               ` Breno Leitao
2026-10-27 17:45                 ` Petr Mladek [this message]
2026-10-27 12:58           ` Petr Mladek
2026-10-26 14:39     ` Chris Down
2026-10-26 15:32       ` Breno Leitao

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=auDjNKi336lstU7j@pathway.suse.cz \
    --to=pmladek@suse.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=chris@chrisdown.name \
    --cc=corbet@lwn.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=john.ogness@linutronix.de \
    --cc=kuba@kernel.org \
    --cc=leitao@debian.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=rdunlap@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=samuelcrossley@gmail.com \
    --cc=senozhatsky@chromium.org \
    --cc=skhan@linuxfoundation.org \
    --cc=tglx@kernel.org \
    /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