Netdev List
 help / color / mirror / Atom feed
From: Petr Mladek <pmladek@suse.com>
To: Breno Leitao <leitao@debian.org>
Cc: Gustavo Luiz Duarte <gustavold@gmail.com>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	John Ogness <john.ogness@linutronix.de>,
	Sam Crossley <samuelcrossley@gmail.com>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	kernel-team@meta.com
Subject: Re: [PATCH net-next v2] netconsole: register one console per target
Date: Wed, 18 Nov 2026 16:59:32 +0100	[thread overview]
Message-ID: <av3LZA_ZemI7ov0q@pathway.suse.cz> (raw)
In-Reply-To: <20261110-netcons_one_console_per_target-v2-1-bebf45b2733f@debian.org>

On Tue 2026-11-10 05:10:01, Breno Leitao wrote:
> netconsole registers a single console (or two in case someone wants
> basic and extended at the same time), independent of the number of
> targets.
> 
> This was not ideal, but, there was no reason to change.
> 
> Now that we want to replay some messages [1], we cannot do it per
> target, but, per console [2].
> 
> Embed a struct console in netconsole_target, so, each target has its own
> console, named `netcons_<target name>`. struct console holds 15
> characters, so longer names are truncated, and two targets can end up
> with the same console name.
> 
> No ->match() callback is added: netconsole consoles set CON_ENABLED and
> register without a console= match. console=netcon0 no longer refers to
> netconsole.
> 
> Unregistering a console waits for an SRCU grace period and for its
> printer thread to stop, which the netdev notifier should not do
> under RTNL. A target stopped by an interface event keeps its console
> instead, and the write callback skips the target as it does today.
> Writing to its enabled attribute drops that console.
> 
> The console is replaced when the target is enabled again or resumes.
> The user may have switched the format in between, and printk has to
> format the records the way the target sends them. A target whose
> console fails to register is disabled, as it would not print
> anything.
> 
> Today, a target switched to the other format while deactivated resumes
> silently if no console of that format is registered.
> 
> target_list_lock remains the device_lock of all the consoles. A target
> is enabled before its console is registered, so only disabling it and
> interface events race with the write callback, and both change the
> state under that lock. The printer threads of the targets serialize on
> it, like the two shared consoles do today.
> 
> /proc/consoles now lists one entry per enabled target, and per target
> stopped by an interface event, for example:
> 
> 	netcons_foo0         -W- (E  N   )
> 
> This makes the mental model easier to understand, and also simplifies
> the code.
> 
> --- a/drivers/net/netconsole.c
> +++ b/drivers/net/netconsole.c
> @@ -1134,19 +1112,6 @@ static ssize_t enabled_store(struct config_item *item,
>  			goto out_unlock;
>  		}
>  
> -		if (nt->extended && !console_is_registered(&netconsole_ext)) {
> -			netconsole_ext.flags |= CON_ENABLED;
> -			register_console(&netconsole_ext);
> -		}
> -
> -		/* User might be enabling the basic format target for the very
> -		 * first time, make sure the console is registered.
> -		 */
> -		if (!nt->extended && !console_is_registered(&netconsole)) {
> -			netconsole.flags |= CON_ENABLED;
> -			register_console(&netconsole);
> -		}

What is the expected behavior when people repeatedly disable/enable
the console, please?

register_console() always initializes con->nbcon_seq, see
get_init_console_seq(). A solution might be to keep the current value
when con->nbcon_seq or con->seq is not zero.

Alternative solution would be to add a flag CON_PAUSED which would be
used to temporary disable the console without unregistering. It might
be handled similar way as CON_SUSPENDED. The point is to make
is_console_usable() return false when the console should stop
emitting the messages.

Note that we could not use CON_ENABLE because it already has another
semantic.

> -
>  		/*
>  		 * Skip netconsole_parser_cmdline() -- all the attributes are
>  		 * already configured via configfs. Just print them out.
> @@ -1167,6 +1132,9 @@ static ssize_t enabled_store(struct config_item *item,
>  			goto out_unlock;
>  		}
>  
> +		ret = netconsole_register_console(nt, 0);
> +		if (ret)
> +			goto out_unlock;
>  		pr_info("network logging started\n");
>  	} else {	/* false */
>  		/* We need to disable the netconsole before cleaning it up
> @@ -1182,10 +1150,7 @@ static ssize_t enabled_store(struct config_item *item,

The code does this here:

		nt->state = STATE_DISABLED;

>  		list_move(&nt->list, &target_cleanup_list);
>  		spin_unlock_irqrestore(&target_list_lock, flags);
>  		mutex_unlock(&target_cleanup_list_lock);
> -		/* Unregister consoles, whose the last target of that type got
> -		 * disabled.
> -		 */
> -		unregister_netcons_consoles();
> +		netconsole_unregister_console(nt);

Why do we disable the traget before unregistering, please?
I ask because it might cause loosing messages, see below.

>  	}
>  
>  	ret = count;
> @@ -2615,53 +2585,40 @@ static void send_msg_udp(struct netconsole_target *nt, const char *msg,
>  }
>  
>  /**
> - * netconsole_write - Generic function to send a msg to all targets
> + * netconsole_write - Send a msg to the target of a console
> + * @con: console of the target
>   * @wctxt: nbcon write context
> - * @extended: "true" for extended console mode
>   *
> - * Given an nbcon write context, send the message to the netconsole targets
> + * Given an nbcon write context, send the message to the netconsole target
>   */
> -static void netconsole_write(struct nbcon_write_context *wctxt, bool extended)
> +static void netconsole_write(struct console *con,
> +			     struct nbcon_write_context *wctxt)
>  {
>  	struct netconsole_target *nt;
>  
> +	nt = container_of(con, struct netconsole_target, console);
> +
>  	if (oops_only && !netconsole_kernel_dying())
>  		return;
>  
> -	list_for_each_entry(nt, &target_list, list) {
> -		if (nt->extended != extended || nt->state != STATE_ENABLED ||
> -		    !netif_running(nt->np.dev))
> -			continue;
> -
> -		if (netconsole_ratelimited(nt))
> -			continue;
> -
> -		/* If nbcon_enter_unsafe() fails, just return given netconsole
> -		 * lost the ownership, and iterating over the targets will not
> -		 * be able to re-acquire.
> -		 */
> -		if (!nbcon_enter_unsafe(wctxt))
> -			return;
> +	if (nt->state != STATE_ENABLED || !netif_running(nt->np.dev))
> +		return;

This is where the messages can get lost. The write() callback does not
pass any error value. As a result, nbcon_emit_next_record() bumps
con->nbcon_seq even when the message was not emitted.

A better solution would be to unregister or disable the console
so that the write() callback is not longer called in the 1st place.
The current con->nbcon_seq could be preserved and used again when
the console is resumed/enabled again.

>  
> -		if (extended)
> -			send_ext_msg_udp(nt, wctxt);
> -		else
> -			send_msg_udp(nt, wctxt->outbuf, wctxt->len);
> +	if (netconsole_ratelimited(nt))
> +		return;
>  
> -		nbcon_exit_unsafe(wctxt);
> -	}
> -}
> +	/* If nbcon_enter_unsafe() fails, just return given netconsole
> +	 * lost the ownership.
> +	 */
> +	if (!nbcon_enter_unsafe(wctxt))
> +		return;
>  
> -static void netconsole_write_ext(struct console *con __always_unused,
> -				 struct nbcon_write_context *wctxt)
> -{
> -	netconsole_write(wctxt, true);
> -}
> +	if (nt->extended)
> +		send_ext_msg_udp(nt, wctxt);
> +	else
> +		send_msg_udp(nt, wctxt->outbuf, wctxt->len);
>  
> -static void netconsole_write_basic(struct console *con __always_unused,
> -				   struct nbcon_write_context *wctxt)
> -{
> -	netconsole_write(wctxt, false);
> +	nbcon_exit_unsafe(wctxt);
>  }
>  
>  static void netconsole_device_lock(struct console *con __always_unused,

Otherwise, the patch looks reasonable from the printk POV.

Note that I haven't tested it. And I am not sure how many scenarios
are possible. It seems that the netconsole user interface is really
rich ;-)

Best Regards,
Petr

      parent reply	other threads:[~2026-11-18 15:59 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-10 13:10 [PATCH net-next v2] netconsole: register one console per target Breno Leitao
2026-11-12  1:40 ` patchwork-bot+netdevbpf
2026-11-18 15:59 ` 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=av3LZA_ZemI7ov0q@pathway.suse.cz \
    --to=pmladek@suse.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=gustavold@gmail.com \
    --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 \
    --cc=samuelcrossley@gmail.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