mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Petr Mladek <pmladek@suse.com>
To: Breno Leitao <leitao@debian.org>
Cc: Jakub Kicinski <kuba@kernel.org>,
	horms@kernel.org, efault@gmx.de, john.ogness@linutronix.de,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Paolo Abeni <pabeni@redhat.com>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	calvin@wbinvd.org, asml.silence@gmail.com, kernel-team@meta.com,
	gustavold@gmail.com, asantostc@gmail.com
Subject: Re: [PATCH RFC net-next 2/2] netconsole: add CONFIG_NETCONSOLE_NBCON for nbcon support
Date: Mon, 24 Nov 2025 14:55:02 +0100	[thread overview]
Message-ID: <aSRjtgmr9xKOX1Ek@pathway.suse.cz> (raw)
In-Reply-To: <20251121-nbcon-v1-2-503d17b2b4af@debian.org>

On Fri 2025-11-21 03:26:08, Breno Leitao wrote:
> Add optional support for the nbcon infrastructure to netconsole via a new
> CONFIG_NETCONSOLE_NBCON compile-time option.
> 
> The nbcon infrastructure provides a lock-free, priority-based console
> system that supports atomic printing from any context including NMI,
> with safe handover mechanisms between different priority levels. This
> makes it particularly suitable for crash-safe kernel logging.
> 
> When disabled (default), netconsole uses the legacy console callbacks,
> maintaining full backward compatibility.
> 
> PS: .write_atomic and .write_thread uses the same callback, given that
> there is no safe .write_atomic, so .write_atomic is called as the last
> resource. This is what CON_NBCON_ATOMIC_UNSAFE is telling nbcon.

Makes sense. CON_NBCON_ATOMIC_UNSAFE also explains why target_list_lock
need not be synchronized with nbcon context locking [*]. The _unsafe_
.write_atomic() callback might be called only by the final
nbcon_atomic_flush_unsafe() when even the nbcon context
synchronization can be ignored.

[*] For example, see how port->lock is synchronized with the nbcon
    context by uart_port_lock() wrapper.

> --- a/drivers/net/Kconfig
> +++ b/drivers/net/Kconfig
> @@ -369,6 +369,20 @@ config NETCONSOLE_PREPEND_RELEASE
>  	  message.  See <file:Documentation/networking/netconsole.rst> for
>  	  details.
>  
> +config NETCONSOLE_NBCON
> +	bool "Use nbcon infrastructure (EXPERIMENTAL)"
> +	depends on NETCONSOLE
> +	default n
> +	help
> +	  Enable nbcon support for netconsole. This uses the new lock-free

Strictly speaking, it is not lock-free. The main feature is that it is
threaded so that it does not block the printk() caller.

Nbcon consoles also support synchronous flushing in emergecy situations.
But it does not work with netconsoles because they do not support
atomic operations. They are flushed only by the final desperate flush
in panic() when all locks are ignored.

> +	  console infrastructure which supports threaded and atomic printing.
> +	  Given that netconsole does not support atomic operations, the current
> +	  implementation focuses on threaded callbacks, unless the host is
> +	  crashing, then it uses an unsafe atomic callbacks. This feature is
> +	  available for both extended and non-extended consoles.
> +
> +	  If unsure, say N to use the legacy console infrastructure.
> +
>  config NETPOLL
>  	def_bool NETCONSOLE
>  
> diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
> index f4b1706fb081..2943f00b83f6 100644
> --- a/drivers/net/netconsole.c
> +++ b/drivers/net/netconsole.c
> @@ -1724,6 +1724,57 @@ static void send_ext_msg_udp(struct netconsole_target *nt, const char *msg,
>  				   extradata_len);
>  }
>  
> +#ifdef CONFIG_NETCONSOLE_NBCON
> +static void netcon_write_nbcon(struct console *con,
> +			       struct nbcon_write_context *wctxt,
> +			       bool extended)
> +{
> +	struct netconsole_target *nt;
> +
> +	lockdep_assert_held(&target_list_lock);
> +
> +	list_for_each_entry(nt, &target_list, list) {
> +		if (nt->extended != extended || !nt->enabled ||
> +		    !netif_running(nt->np.dev))
> +			continue;
> +
> +		if (!nbcon_enter_unsafe(wctxt))
> +			continue;
> +
> +		if (extended)
> +			send_ext_msg_udp(nt, wctxt->outbuf, wctxt->len);
> +		else
> +			write_msg_target(nt, wctxt->outbuf, wctxt->len);

If you accepted the rename in the 1st patch then this would be ;-)

		if (extended)
			send_ext_msg_udp(nt, wctxt->outbuf, wctxt->len);
		else
			send_msg_udp(nt, wctxt->outbuf, wctxt->len);

> +
> +		nbcon_exit_unsafe(wctxt);
> +	}
> +}

Otherwise, it looks good from my POV.

Best Regards,
Petr

      reply	other threads:[~2025-11-24 13:55 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-21 11:26 [PATCH RFC net-next 0/2] netconsole: NBCON Infrastructure Support Breno Leitao
2025-11-21 11:26 ` [PATCH RFC net-next 1/2] netconsole: extract message fragmentation into write_msg_target() Breno Leitao
2025-11-24 13:08   ` Petr Mladek
2025-11-21 11:26 ` [PATCH RFC net-next 2/2] netconsole: add CONFIG_NETCONSOLE_NBCON for nbcon support Breno Leitao
2025-11-24 13:55   ` Petr Mladek [this message]

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=aSRjtgmr9xKOX1Ek@pathway.suse.cz \
    --to=pmladek@suse.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=asantostc@gmail.com \
    --cc=asml.silence@gmail.com \
    --cc=calvin@wbinvd.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=efault@gmx.de \
    --cc=gustavold@gmail.com \
    --cc=horms@kernel.org \
    --cc=john.ogness@linutronix.de \
    --cc=kernel-team@meta.com \
    --cc=kuba@kernel.org \
    --cc=leitao@debian.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /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

all inboxes | Powered by JetHome®