public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next v2 0/5] net: netconsole: convert to NBCON console infrastructure
@ 2026-01-20 16:23 Breno Leitao
  2026-01-20 16:23 ` [PATCH net-next v2 1/5] printk: Add execution context (task name/CPU) to printk_info Breno Leitao
                   ` (4 more replies)
  0 siblings, 5 replies; 11+ messages in thread
From: Breno Leitao @ 2026-01-20 16:23 UTC (permalink / raw)
  To: Breno Leitao, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, pmladek, john.ogness
  Cc: Greg Kroah-Hartman, Steven Rostedt, Sergey Senozhatsky,
	Andrew Morton, netdev, linux-kernel, asantostc, efault, gustavold,
	calvin, jv, mpdesouza, kernel-team, Simon Horman

This series adds support for the nbcon (new buffer console) infrastructure
to netconsole, enabling lock-free, priority-based console operations that
are safer in crash scenarios.

The implementation is introduced in three steps:

0) Extend printk to expose CPU and taskname (task->comm) where the
   printk originated from. (Thanks John and Petr for the support in
   getting this done)
1) Refactor the message fragmentation logic into a reusable helper function
2) Extend nbcon support to non-extended (basic) consoles using the same
   infrastructure.

The initial discussion about it appeared a while ago in [1], in order to
solve Mike's HARDIRQ-safe -> HARDIRQ-unsafe lock order warning, and the root
cause is that some hosts were calling IRQ unsafe locks from inside console
lock.

At that time, we didn't have the CON_NBCON_ATOMIC_UNSAFE yet. John
kindly implemented CON_NBCON_ATOMIC_UNSAFE in 187de7c212e5 ("printk:
nbcon: Allow unsafe write_atomic() for panic"), and now we can
implement netconsole on top of nbcon.

Important to note that netconsole continues to call netpoll and the
network TX helpers with interrupt disable, given the TX are called with
target_list_lock.

Netdev maintainers, Petr suggested that this patchset goes through netdev[2]

Link: https://lore.kernel.org/all/b2qps3uywhmjaym4mht2wpxul4yqtuuayeoq4iv4k3zf5wdgh3@tocu6c7mj4lt/ [1]
Link: https://lore.kernel.org/all/aW9D5M0o9_8hdVvt@pathway.suse.cz/ [2]

Signed-off-by: Breno Leitao <leitao@debian.org>

---
Changes in v2:
- Return if not able to nbcon_enter_unsafe() instead of retrying on
  a different target (Marcos)
- Add printk that supports context information, which will be used later
  by netconsole sysdata. (John, Petr)
- An extra patch to bring symmetry to send_msg_udp()
- Link to v1: https://patch.msgid.link/20251222-nbcon-v1-0-65b43c098708@debian.org

Changes in V1 from RFC:
  * Removed the extra CONFIG for NBCON, given we don't want to support
    both console. Move to nbcon as the only console framework supported
  * Incorporated the changes from Petr.
  * Some renames to make the code more consistent.
  * RFC Link: https://lore.kernel.org/all/20251121-nbcon-v1-0-503d17b2b4af@debian.org/

---
Breno Leitao (5):
      printk: Add execution context (task name/CPU) to printk_info
      netconsole: extract message fragmentation into send_msg_udp()
      netconsole: convert to NBCON console infrastructure
      netconsole: Use printk context for CPU and task information
      netconsole: pass wctxt to send_msg_udp() for consistency

 drivers/net/Kconfig               |   1 +
 drivers/net/netconsole.c          | 147 +++++++++++++++++++++++---------------
 include/linux/console.h           |   8 +++
 kernel/printk/internal.h          |   8 +++
 kernel/printk/nbcon.c             |  15 ++++
 kernel/printk/printk.c            |  52 +++++++++++++-
 kernel/printk/printk_ringbuffer.h |   4 ++
 lib/Kconfig.debug                 |  20 ++++++
 8 files changed, 197 insertions(+), 58 deletions(-)
---
base-commit: 956f569c90ab507559342d289f4c923adfbf06f5
change-id: 20251117-nbcon-f24477ca9f3e

Best regards,
--  
Breno Leitao <leitao@debian.org>


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH net-next v2 1/5] printk: Add execution context (task name/CPU) to printk_info
  2026-01-20 16:23 [PATCH net-next v2 0/5] net: netconsole: convert to NBCON console infrastructure Breno Leitao
@ 2026-01-20 16:23 ` Breno Leitao
  2026-01-21 11:41   ` Breno Leitao
  2026-01-20 16:23 ` [PATCH net-next v2 2/5] netconsole: extract message fragmentation into send_msg_udp() Breno Leitao
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 11+ messages in thread
From: Breno Leitao @ 2026-01-20 16:23 UTC (permalink / raw)
  To: Breno Leitao, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, pmladek, john.ogness
  Cc: Greg Kroah-Hartman, Steven Rostedt, Sergey Senozhatsky,
	Andrew Morton, netdev, linux-kernel, asantostc, efault, gustavold,
	calvin, jv, mpdesouza, kernel-team

Extend struct printk_info to include the task name, pid, and CPU
number where printk messages originate. This information is captured
at vprintk_store() time and propagated through printk_message to
nbcon_write_context, making it available to nbcon console drivers.

This is useful for consoles like netconsole that want to include
execution context in their output, allowing correlation of messages
with specific tasks and CPUs regardless of where the console driver
actually runs.

The feature is controlled by CONFIG_PRINTK_EXECUTION_CTX, which is
automatically selected by CONFIG_NETCONSOLE_DYNAMIC. When disabled,
the helper functions compile to no-ops with no overhead.

Suggested-by: John Ogness <john.ogness@linutronix.de>
Signed-off-by: Breno Leitao <leitao@debian.org>
Signed-off-by: Petr Mladek <pmladek@suse.com>
---
 drivers/net/Kconfig               |  1 +
 include/linux/console.h           |  8 ++++++
 kernel/printk/internal.h          |  8 ++++++
 kernel/printk/nbcon.c             | 15 +++++++++++
 kernel/printk/printk.c            | 52 ++++++++++++++++++++++++++++++++++++++-
 kernel/printk/printk_ringbuffer.h |  4 +++
 lib/Kconfig.debug                 | 20 +++++++++++++++
 7 files changed, 107 insertions(+), 1 deletion(-)

diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index ac12eaf11755d..12e47cb27ffa5 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -341,6 +341,7 @@ config NETCONSOLE_DYNAMIC
 	bool "Dynamic reconfiguration of logging targets"
 	depends on NETCONSOLE && SYSFS && CONFIGFS_FS && \
 			!(NETCONSOLE=y && CONFIGFS_FS=m)
+	select CONSOLE_HAS_EXECUTION_CTX
 	help
 	  This option enables the ability to dynamically reconfigure target
 	  parameters (interface, IP addresses, port numbers, MAC addresses)
diff --git a/include/linux/console.h b/include/linux/console.h
index fc9f5c5c1b04c..cc5dc3bf58b60 100644
--- a/include/linux/console.h
+++ b/include/linux/console.h
@@ -298,12 +298,20 @@ struct nbcon_context {
  * @outbuf:		Pointer to the text buffer for output
  * @len:		Length to write
  * @unsafe_takeover:	If a hostile takeover in an unsafe state has occurred
+ * @cpu:		CPU on which the message was generated
+ * @pid:		PID of the task that generated the message
+ * @comm:		Name of the task that generated the message
  */
 struct nbcon_write_context {
 	struct nbcon_context	__private ctxt;
 	char			*outbuf;
 	unsigned int		len;
 	bool			unsafe_takeover;
+#ifdef CONFIG_PRINTK_EXECUTION_CTX
+	int			cpu;
+	pid_t			pid;
+	char			comm[TASK_COMM_LEN];
+#endif
 };
 
 /**
diff --git a/kernel/printk/internal.h b/kernel/printk/internal.h
index 5f5f626f42794..5fdea56827564 100644
--- a/kernel/printk/internal.h
+++ b/kernel/printk/internal.h
@@ -281,12 +281,20 @@ struct printk_buffers {
  *		nothing to output and this record should be skipped.
  * @seq:	The sequence number of the record used for @pbufs->outbuf.
  * @dropped:	The number of dropped records from reading @seq.
+ * @cpu:	CPU on which the message was generated.
+ * @pid:	PID of the task that generated the message
+ * @comm:	Name of the task that generated the message.
  */
 struct printk_message {
 	struct printk_buffers	*pbufs;
 	unsigned int		outbuf_len;
 	u64			seq;
 	unsigned long		dropped;
+#ifdef CONFIG_PRINTK_EXECUTION_CTX
+	int			cpu;
+	pid_t			pid;
+	char			comm[TASK_COMM_LEN];
+#endif
 };
 
 bool printk_get_next_message(struct printk_message *pmsg, u64 seq,
diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c
index 3fa403f9831f0..c2b3c4d2146e3 100644
--- a/kernel/printk/nbcon.c
+++ b/kernel/printk/nbcon.c
@@ -946,6 +946,19 @@ void nbcon_reacquire_nobuf(struct nbcon_write_context *wctxt)
 }
 EXPORT_SYMBOL_GPL(nbcon_reacquire_nobuf);
 
+#ifdef CONFIG_PRINTK_EXECUTION_CTX
+static inline void wctxt_load_execution_ctx(struct nbcon_write_context *wctxt,
+					    struct printk_message *pmsg)
+{
+	wctxt->cpu = pmsg->cpu;
+	wctxt->pid = pmsg->pid;
+	memcpy(wctxt->comm, pmsg->comm, TASK_COMM_LEN);
+}
+#else
+static inline void wctxt_load_execution_ctx(struct nbcon_write_context *wctxt,
+					    struct printk_message *pmsg) {}
+#endif
+
 /**
  * nbcon_emit_next_record - Emit a record in the acquired context
  * @wctxt:	The write context that will be handed to the write function
@@ -1048,6 +1061,8 @@ static bool nbcon_emit_next_record(struct nbcon_write_context *wctxt, bool use_a
 	/* Initialize the write context for driver callbacks. */
 	nbcon_write_context_set_buf(wctxt, &pmsg.pbufs->outbuf[0], pmsg.outbuf_len);
 
+	wctxt_load_execution_ctx(wctxt, &pmsg);
+
 	if (use_atomic)
 		con->write_atomic(con, wctxt);
 	else
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 1d765ad242b82..8885e8e7753fe 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -2131,11 +2131,38 @@ static inline void printk_delay(int level)
 	}
 }
 
+#define CALLER_ID_MASK 0x80000000
+
 static inline u32 printk_caller_id(void)
 {
 	return in_task() ? task_pid_nr(current) :
-		0x80000000 + smp_processor_id();
+		CALLER_ID_MASK + smp_processor_id();
+}
+
+#ifdef CONFIG_PRINTK_EXECUTION_CTX
+/* Store the opposite info than caller_id. */
+static inline u32 printk_caller_id2(void)
+{
+	return !in_task() ? task_pid_nr(current) :
+		CALLER_ID_MASK + smp_processor_id();
+}
+
+static inline pid_t printk_info_get_pid(const struct printk_info *info)
+{
+	u32 caller_id = info->caller_id;
+	u32 caller_id2 = info->caller_id2;
+
+	return caller_id & CALLER_ID_MASK ? caller_id2 : caller_id;
+}
+
+static inline int printk_info_get_cpu(const struct printk_info *info)
+{
+	u32 caller_id = info->caller_id;
+	u32 caller_id2 = info->caller_id2;
+
+	return (caller_id & CALLER_ID_MASK ? caller_id : caller_id2) & ~CALLER_ID_MASK;
 }
+#endif
 
 /**
  * printk_parse_prefix - Parse level and control flags.
@@ -2213,6 +2240,27 @@ static u16 printk_sprint(char *text, u16 size, int facility,
 	return text_len;
 }
 
+#ifdef CONFIG_PRINTK_EXECUTION_CTX
+static inline void printk_store_execution_ctx(struct printk_info *info)
+{
+	info->caller_id2 = printk_caller_id2();
+	get_task_comm(info->comm, current);
+}
+
+static inline void pmsg_load_execution_ctx(struct printk_message *pmsg,
+					   const struct printk_info *info)
+{
+	pmsg->cpu = printk_info_get_cpu(info);
+	pmsg->pid = printk_info_get_pid(info);
+	memcpy(pmsg->comm, info->comm, TASK_COMM_LEN);
+}
+#else
+static inline void printk_store_execution_ctx(struct printk_info *info) {}
+
+static inline void pmsg_load_execution_ctx(struct printk_message *pmsg,
+					   const struct printk_info *info) {}
+#endif
+
 __printf(4, 0)
 int vprintk_store(int facility, int level,
 		  const struct dev_printk_info *dev_info,
@@ -2320,6 +2368,7 @@ int vprintk_store(int facility, int level,
 	r.info->caller_id = caller_id;
 	if (dev_info)
 		memcpy(&r.info->dev_info, dev_info, sizeof(r.info->dev_info));
+	printk_store_execution_ctx(r.info);
 
 	/* A message without a trailing newline can be continued. */
 	if (!(flags & LOG_NEWLINE))
@@ -3002,6 +3051,7 @@ bool printk_get_next_message(struct printk_message *pmsg, u64 seq,
 	pmsg->seq = r.info->seq;
 	pmsg->dropped = r.info->seq - seq;
 	force_con = r.info->flags & LOG_FORCE_CON;
+	pmsg_load_execution_ctx(pmsg, r.info);
 
 	/*
 	 * Skip records that are not forced to be printed on consoles and that
diff --git a/kernel/printk/printk_ringbuffer.h b/kernel/printk/printk_ringbuffer.h
index 4ef81349d9fbe..bf5b23a0bf54e 100644
--- a/kernel/printk/printk_ringbuffer.h
+++ b/kernel/printk/printk_ringbuffer.h
@@ -23,6 +23,10 @@ struct printk_info {
 	u8	flags:5;	/* internal record flags */
 	u8	level:3;	/* syslog level */
 	u32	caller_id;	/* thread id or processor id */
+#ifdef CONFIG_PRINTK_EXECUTION_CTX
+	u32	caller_id2;	/* caller_id complement */
+	char	comm[TASK_COMM_LEN]; /* name of the task that generated the message */
+#endif
 
 	struct dev_printk_info	dev_info;
 };
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index ba36939fda79b..57f91ee10b8e6 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -35,6 +35,26 @@ config PRINTK_CALLER
 	  no option to enable/disable at the kernel command line parameter or
 	  sysfs interface.
 
+config CONSOLE_HAS_EXECUTION_CTX
+	bool
+	help
+	  Selected by console drivers that support execution context
+	  (task name/CPU) in their output. This enables PRINTK_EXECUTION_CTX
+	  to provide the necessary infrastructure.
+
+config PRINTK_EXECUTION_CTX
+	bool "Include execution context (task/CPU) in printk messages"
+	depends on PRINTK && CONSOLE_HAS_EXECUTION_CTX
+	default CONSOLE_HAS_EXECUTION_CTX
+	help
+	  This option extends struct printk_info to include extra execution
+	  context in printk, such as task name and CPU number from where the
+	  message originated. This is useful for correlating printk messages
+	  with specific execution contexts.
+
+	  This is automatically enabled when a console driver that supports
+	  execution context is selected.
+
 config STACKTRACE_BUILD_ID
 	bool "Show build ID information in stacktraces"
 	depends on PRINTK

-- 
2.47.3


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH net-next v2 2/5] netconsole: extract message fragmentation into send_msg_udp()
  2026-01-20 16:23 [PATCH net-next v2 0/5] net: netconsole: convert to NBCON console infrastructure Breno Leitao
  2026-01-20 16:23 ` [PATCH net-next v2 1/5] printk: Add execution context (task name/CPU) to printk_info Breno Leitao
@ 2026-01-20 16:23 ` Breno Leitao
  2026-01-20 16:23 ` [PATCH net-next v2 3/5] netconsole: convert to NBCON console infrastructure Breno Leitao
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 11+ messages in thread
From: Breno Leitao @ 2026-01-20 16:23 UTC (permalink / raw)
  To: Breno Leitao, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, pmladek, john.ogness
  Cc: Greg Kroah-Hartman, Steven Rostedt, Sergey Senozhatsky,
	Andrew Morton, netdev, linux-kernel, asantostc, efault, gustavold,
	calvin, jv, mpdesouza, kernel-team, Simon Horman

Extract the message fragmentation logic from write_msg() into a
dedicated send_msg_udp() function. This improves code readability
and prepares for future enhancements.

The new send_msg_udp() function handles splitting messages that
exceed MAX_PRINT_CHUNK into smaller fragments and sending them
sequentially. This function is placed before send_ext_msg_udp()
to maintain a logical ordering of related functions.

No functional changes - this is purely a refactoring commit.

Reviewed-by: Petr Mladek <pmladek@suse.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Signed-off-by: Breno Leitao <leitao@debian.org>
---
 drivers/net/netconsole.c | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
index 9cb4dfc242f5f..dc3bd7c9b0498 100644
--- a/drivers/net/netconsole.c
+++ b/drivers/net/netconsole.c
@@ -1725,12 +1725,24 @@ static void write_ext_msg(struct console *con, const char *msg,
 	spin_unlock_irqrestore(&target_list_lock, flags);
 }
 
+static void send_msg_udp(struct netconsole_target *nt, const char *msg,
+			 unsigned int len)
+{
+	const char *tmp = msg;
+	int frag, left = len;
+
+	while (left > 0) {
+		frag = min(left, MAX_PRINT_CHUNK);
+		send_udp(nt, tmp, frag);
+		tmp += frag;
+		left -= frag;
+	}
+}
+
 static void write_msg(struct console *con, const char *msg, unsigned int len)
 {
-	int frag, left;
 	unsigned long flags;
 	struct netconsole_target *nt;
-	const char *tmp;
 
 	if (oops_only && !oops_in_progress)
 		return;
@@ -1747,13 +1759,7 @@ static void write_msg(struct console *con, const char *msg, unsigned int len)
 			 * at least one target if we die inside here, instead
 			 * of unnecessarily keeping all targets in lock-step.
 			 */
-			tmp = msg;
-			for (left = len; left;) {
-				frag = min(left, MAX_PRINT_CHUNK);
-				send_udp(nt, tmp, frag);
-				tmp += frag;
-				left -= frag;
-			}
+			send_msg_udp(nt, msg, len);
 		}
 	}
 	spin_unlock_irqrestore(&target_list_lock, flags);

-- 
2.47.3


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH net-next v2 3/5] netconsole: convert to NBCON console infrastructure
  2026-01-20 16:23 [PATCH net-next v2 0/5] net: netconsole: convert to NBCON console infrastructure Breno Leitao
  2026-01-20 16:23 ` [PATCH net-next v2 1/5] printk: Add execution context (task name/CPU) to printk_info Breno Leitao
  2026-01-20 16:23 ` [PATCH net-next v2 2/5] netconsole: extract message fragmentation into send_msg_udp() Breno Leitao
@ 2026-01-20 16:23 ` Breno Leitao
  2026-01-22 21:09   ` Simon Horman
  2026-01-20 16:23 ` [PATCH net-next v2 4/5] netconsole: Use printk context for CPU and task information Breno Leitao
  2026-01-20 16:23 ` [PATCH net-next v2 5/5] netconsole: pass wctxt to send_msg_udp() for consistency Breno Leitao
  4 siblings, 1 reply; 11+ messages in thread
From: Breno Leitao @ 2026-01-20 16:23 UTC (permalink / raw)
  To: Breno Leitao, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, pmladek, john.ogness
  Cc: Greg Kroah-Hartman, Steven Rostedt, Sergey Senozhatsky,
	Andrew Morton, netdev, linux-kernel, asantostc, efault, gustavold,
	calvin, jv, mpdesouza, kernel-team

Convert netconsole from the legacy console API to the NBCON framework.
NBCON provides threaded printing which unblocks printk()s and flushes in
a thread, decoupling network TX from printk() when netconsole is
in use.

Since netconsole relies on the network stack which cannot safely operate
from all atomic contexts, mark both consoles with
CON_NBCON_ATOMIC_UNSAFE. (See discussion in [1])

CON_NBCON_ATOMIC_UNSAFE restricts write_atomic() usage to emergency
scenarios (panic) where regular messages are sent in threaded mode.

Implementation changes:
- Unify write_ext_msg() and write_msg() into netconsole_write()
- Add device_lock/device_unlock callbacks to manage target_list_lock
- Use nbcon_enter_unsafe()/nbcon_exit_unsafe() around network
  operations.
  - If nbcon_enter_unsafe() fails, just return given netconsole lost
    the ownership of the console.
- Set write_thread and write_atomic callbacks (both use same function)

Link: https://lore.kernel.org/all/b2qps3uywhmjaym4mht2wpxul4yqtuuayeoq4iv4k3zf5wdgh3@tocu6c7mj4lt/ [1]
Signed-off-by: Breno Leitao <leitao@debian.org>
---
 drivers/net/netconsole.c | 97 ++++++++++++++++++++++++++++++------------------
 1 file changed, 60 insertions(+), 37 deletions(-)

diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
index dc3bd7c9b0498..c5d7e97fe2a78 100644
--- a/drivers/net/netconsole.c
+++ b/drivers/net/netconsole.c
@@ -1709,22 +1709,6 @@ static void send_ext_msg_udp(struct netconsole_target *nt, const char *msg,
 				   sysdata_len);
 }
 
-static void write_ext_msg(struct console *con, const char *msg,
-			  unsigned int len)
-{
-	struct netconsole_target *nt;
-	unsigned long flags;
-
-	if ((oops_only && !oops_in_progress) || list_empty(&target_list))
-		return;
-
-	spin_lock_irqsave(&target_list_lock, flags);
-	list_for_each_entry(nt, &target_list, list)
-		if (nt->extended && nt->enabled && netif_running(nt->np.dev))
-			send_ext_msg_udp(nt, msg, len);
-	spin_unlock_irqrestore(&target_list_lock, flags);
-}
-
 static void send_msg_udp(struct netconsole_target *nt, const char *msg,
 			 unsigned int len)
 {
@@ -1739,29 +1723,62 @@ static void send_msg_udp(struct netconsole_target *nt, const char *msg,
 	}
 }
 
-static void write_msg(struct console *con, const char *msg, unsigned int len)
+/**
+ * netconsole_write - Generic function to send a msg to all targets
+ * @wctxt: nbcon write context
+ * @extended: "true" for extended console mode
+ *
+ * Given an nbcon write context, send the message to the netconsole targets
+ */
+static void netconsole_write(struct nbcon_write_context *wctxt, bool extended)
 {
-	unsigned long flags;
 	struct netconsole_target *nt;
 
 	if (oops_only && !oops_in_progress)
 		return;
-	/* Avoid taking lock and disabling interrupts unnecessarily */
-	if (list_empty(&target_list))
-		return;
 
-	spin_lock_irqsave(&target_list_lock, flags);
 	list_for_each_entry(nt, &target_list, list) {
-		if (!nt->extended && nt->enabled && netif_running(nt->np.dev)) {
-			/*
-			 * We nest this inside the for-each-target loop above
-			 * so that we're able to get as much logging out to
-			 * at least one target if we die inside here, instead
-			 * of unnecessarily keeping all targets in lock-step.
-			 */
-			send_msg_udp(nt, msg, len);
-		}
+		if (nt->extended != extended || !nt->enabled ||
+		    !netif_running(nt->np.dev))
+			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 (extended)
+			send_ext_msg_udp(nt, wctxt->outbuf, wctxt->len);
+		else
+			send_msg_udp(nt, wctxt->outbuf, wctxt->len);
+
+		nbcon_exit_unsafe(wctxt);
 	}
+}
+
+static void netconsole_write_ext(struct console *con __always_unused,
+				 struct nbcon_write_context *wctxt)
+{
+	netconsole_write(wctxt, true);
+}
+
+static void netconsole_write_basic(struct console *con __always_unused,
+				   struct nbcon_write_context *wctxt)
+{
+	netconsole_write(wctxt, false);
+}
+
+static void netconsole_device_lock(struct console *con __always_unused,
+				   unsigned long *flags)
+{
+	spin_lock_irqsave(&target_list_lock, *flags);
+}
+
+static void netconsole_device_unlock(struct console *con __always_unused,
+				     unsigned long flags)
+{
 	spin_unlock_irqrestore(&target_list_lock, flags);
 }
 
@@ -1924,15 +1941,21 @@ static void free_param_target(struct netconsole_target *nt)
 }
 
 static struct console netconsole_ext = {
-	.name	= "netcon_ext",
-	.flags	= CON_ENABLED | CON_EXTENDED,
-	.write	= write_ext_msg,
+	.name = "netcon_ext",
+	.flags = CON_ENABLED | CON_EXTENDED | CON_NBCON | CON_NBCON_ATOMIC_UNSAFE,
+	.write_thread = netconsole_write_ext,
+	.write_atomic = netconsole_write_ext,
+	.device_lock = netconsole_device_lock,
+	.device_unlock = netconsole_device_unlock,
 };
 
 static struct console netconsole = {
-	.name	= "netcon",
-	.flags	= CON_ENABLED,
-	.write	= write_msg,
+	.name = "netcon",
+	.flags = CON_ENABLED | CON_NBCON | CON_NBCON_ATOMIC_UNSAFE,
+	.write_thread = netconsole_write_basic,
+	.write_atomic = netconsole_write_basic,
+	.device_lock = netconsole_device_lock,
+	.device_unlock = netconsole_device_unlock,
 };
 
 static int __init init_netconsole(void)

-- 
2.47.3


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH net-next v2 4/5] netconsole: Use printk context for CPU and task information
  2026-01-20 16:23 [PATCH net-next v2 0/5] net: netconsole: convert to NBCON console infrastructure Breno Leitao
                   ` (2 preceding siblings ...)
  2026-01-20 16:23 ` [PATCH net-next v2 3/5] netconsole: convert to NBCON console infrastructure Breno Leitao
@ 2026-01-20 16:23 ` Breno Leitao
  2026-01-21  5:40   ` kernel test robot
  2026-01-20 16:23 ` [PATCH net-next v2 5/5] netconsole: pass wctxt to send_msg_udp() for consistency Breno Leitao
  4 siblings, 1 reply; 11+ messages in thread
From: Breno Leitao @ 2026-01-20 16:23 UTC (permalink / raw)
  To: Breno Leitao, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, pmladek, john.ogness
  Cc: Greg Kroah-Hartman, Steven Rostedt, Sergey Senozhatsky,
	Andrew Morton, netdev, linux-kernel, asantostc, efault, gustavold,
	calvin, jv, mpdesouza, kernel-team

Use the CPU and task name captured at printk() time from
nbcon_write_context instead of querying the current execution context.
This provides accurate information about where the message originated,
rather than where netconsole happens to be running.

For CPU, use wctxt->msg_cpu instead of raw_smp_processor_id().

For taskname, use wctxt->msg_comm directly which contains the task
name captured at printk time.

This change ensures netconsole outputs reflect the actual context that
generated the log message, which is especially important when the
console driver runs asynchronously in a dedicated thread.

Signed-off-by: Breno Leitao <leitao@debian.org>
---
 drivers/net/netconsole.c | 38 +++++++++++++++++++++-----------------
 1 file changed, 21 insertions(+), 17 deletions(-)

diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
index c5d7e97fe2a78..d89ff01bc9658 100644
--- a/drivers/net/netconsole.c
+++ b/drivers/net/netconsole.c
@@ -1357,18 +1357,20 @@ static void populate_configfs_item(struct netconsole_target *nt,
 	init_target_config_group(nt, target_name);
 }
 
-static int sysdata_append_cpu_nr(struct netconsole_target *nt, int offset)
+static int sysdata_append_cpu_nr(struct netconsole_target *nt, int offset,
+				 struct nbcon_write_context *wctxt)
 {
 	return scnprintf(&nt->sysdata[offset],
 			 MAX_EXTRADATA_ENTRY_LEN, " cpu=%u\n",
-			 raw_smp_processor_id());
+			 wctxt->cpu);
 }
 
-static int sysdata_append_taskname(struct netconsole_target *nt, int offset)
+static int sysdata_append_taskname(struct netconsole_target *nt, int offset,
+				   struct nbcon_write_context *wctxt)
 {
 	return scnprintf(&nt->sysdata[offset],
 			 MAX_EXTRADATA_ENTRY_LEN, " taskname=%s\n",
-			 current->comm);
+			 wctxt->comm);
 }
 
 static int sysdata_append_release(struct netconsole_target *nt, int offset)
@@ -1389,8 +1391,10 @@ static int sysdata_append_msgid(struct netconsole_target *nt, int offset)
 /*
  * prepare_sysdata - append sysdata in runtime
  * @nt: target to send message to
+ * @wctxt: nbcon write context containing message metadata
  */
-static int prepare_sysdata(struct netconsole_target *nt)
+static int prepare_sysdata(struct netconsole_target *nt,
+			   struct nbcon_write_context *wctxt)
 {
 	int sysdata_len = 0;
 
@@ -1398,9 +1402,9 @@ static int prepare_sysdata(struct netconsole_target *nt)
 		goto out;
 
 	if (nt->sysdata_fields & SYSDATA_CPU_NR)
-		sysdata_len += sysdata_append_cpu_nr(nt, sysdata_len);
+		sysdata_len += sysdata_append_cpu_nr(nt, sysdata_len, wctxt);
 	if (nt->sysdata_fields & SYSDATA_TASKNAME)
-		sysdata_len += sysdata_append_taskname(nt, sysdata_len);
+		sysdata_len += sysdata_append_taskname(nt, sysdata_len, wctxt);
 	if (nt->sysdata_fields & SYSDATA_RELEASE)
 		sysdata_len += sysdata_append_release(nt, sysdata_len);
 	if (nt->sysdata_fields & SYSDATA_MSGID)
@@ -1681,31 +1685,31 @@ static void send_msg_fragmented(struct netconsole_target *nt,
 /**
  * send_ext_msg_udp - send extended log message to target
  * @nt: target to send message to
- * @msg: extended log message to send
- * @msg_len: length of message
+ * @wctxt: nbcon write context containing message and metadata
  *
- * Transfer extended log @msg to @nt.  If @msg is longer than
+ * Transfer extended log message to @nt.  If message is longer than
  * MAX_PRINT_CHUNK, it'll be split and transmitted in multiple chunks with
  * ncfrag header field added to identify them.
  */
-static void send_ext_msg_udp(struct netconsole_target *nt, const char *msg,
-			     int msg_len)
+static void send_ext_msg_udp(struct netconsole_target *nt,
+			     struct nbcon_write_context *wctxt)
 {
 	int userdata_len = 0;
 	int release_len = 0;
 	int sysdata_len = 0;
 
 #ifdef CONFIG_NETCONSOLE_DYNAMIC
-	sysdata_len = prepare_sysdata(nt);
+	sysdata_len = prepare_sysdata(nt, wctxt);
 	userdata_len = nt->userdata_length;
 #endif
 	if (nt->release)
 		release_len = strlen(init_utsname()->release) + 1;
 
-	if (msg_len + release_len + sysdata_len + userdata_len <= MAX_PRINT_CHUNK)
-		return send_msg_no_fragmentation(nt, msg, msg_len, release_len);
+	if (wctxt->len + release_len + sysdata_len + userdata_len <= MAX_PRINT_CHUNK)
+		return send_msg_no_fragmentation(nt, wctxt->outbuf,
+						 wctxt->len, release_len);
 
-	return send_msg_fragmented(nt, msg, msg_len, release_len,
+	return send_msg_fragmented(nt, wctxt->outbuf, wctxt->len, release_len,
 				   sysdata_len);
 }
 
@@ -1750,7 +1754,7 @@ static void netconsole_write(struct nbcon_write_context *wctxt, bool extended)
 			return;
 
 		if (extended)
-			send_ext_msg_udp(nt, wctxt->outbuf, wctxt->len);
+			send_ext_msg_udp(nt, wctxt);
 		else
 			send_msg_udp(nt, wctxt->outbuf, wctxt->len);
 

-- 
2.47.3


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH net-next v2 5/5] netconsole: pass wctxt to send_msg_udp() for consistency
  2026-01-20 16:23 [PATCH net-next v2 0/5] net: netconsole: convert to NBCON console infrastructure Breno Leitao
                   ` (3 preceding siblings ...)
  2026-01-20 16:23 ` [PATCH net-next v2 4/5] netconsole: Use printk context for CPU and task information Breno Leitao
@ 2026-01-20 16:23 ` Breno Leitao
  4 siblings, 0 replies; 11+ messages in thread
From: Breno Leitao @ 2026-01-20 16:23 UTC (permalink / raw)
  To: Breno Leitao, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, pmladek, john.ogness
  Cc: Greg Kroah-Hartman, Steven Rostedt, Sergey Senozhatsky,
	Andrew Morton, netdev, linux-kernel, asantostc, efault, gustavold,
	calvin, jv, mpdesouza, kernel-team

Refactor send_msg_udp() to take a struct nbcon_write_context pointer
instead of separate msg and len parameters. This makes its signature
consistent with send_ext_msg_udp() and prepares the function for
future use of execution context information from wctxt.

No functional change.

Signed-off-by: Breno Leitao <leitao@debian.org>
---
 drivers/net/netconsole.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
index d89ff01bc9658..ab547a0da5e0d 100644
--- a/drivers/net/netconsole.c
+++ b/drivers/net/netconsole.c
@@ -1713,16 +1713,16 @@ static void send_ext_msg_udp(struct netconsole_target *nt,
 				   sysdata_len);
 }
 
-static void send_msg_udp(struct netconsole_target *nt, const char *msg,
-			 unsigned int len)
+static void send_msg_udp(struct netconsole_target *nt,
+			 struct nbcon_write_context *wctxt)
 {
-	const char *tmp = msg;
-	int frag, left = len;
+	const char *msg = wctxt->outbuf;
+	int frag, left = wctxt->len;
 
 	while (left > 0) {
 		frag = min(left, MAX_PRINT_CHUNK);
-		send_udp(nt, tmp, frag);
-		tmp += frag;
+		send_udp(nt, msg, frag);
+		msg += frag;
 		left -= frag;
 	}
 }
@@ -1756,7 +1756,7 @@ static void netconsole_write(struct nbcon_write_context *wctxt, bool extended)
 		if (extended)
 			send_ext_msg_udp(nt, wctxt);
 		else
-			send_msg_udp(nt, wctxt->outbuf, wctxt->len);
+			send_msg_udp(nt, wctxt);
 
 		nbcon_exit_unsafe(wctxt);
 	}

-- 
2.47.3


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH net-next v2 4/5] netconsole: Use printk context for CPU and task information
  2026-01-20 16:23 ` [PATCH net-next v2 4/5] netconsole: Use printk context for CPU and task information Breno Leitao
@ 2026-01-21  5:40   ` kernel test robot
  0 siblings, 0 replies; 11+ messages in thread
From: kernel test robot @ 2026-01-21  5:40 UTC (permalink / raw)
  To: Breno Leitao, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, pmladek, john.ogness
  Cc: oe-kbuild-all, netdev, Greg Kroah-Hartman, Steven Rostedt,
	Sergey Senozhatsky, Andrew Morton, Linux Memory Management List,
	linux-kernel, asantostc, efault, gustavold, calvin, jv, mpdesouza,
	kernel-team

Hi Breno,

kernel test robot noticed the following build errors:

[auto build test ERROR on 956f569c90ab507559342d289f4c923adfbf06f5]

url:    https://github.com/intel-lab-lkp/linux/commits/Breno-Leitao/printk-Add-execution-context-task-name-CPU-to-printk_info/20260121-033457
base:   956f569c90ab507559342d289f4c923adfbf06f5
patch link:    https://lore.kernel.org/r/20260120-nbcon-v2-4-b61f960587a8%40debian.org
patch subject: [PATCH net-next v2 4/5] netconsole: Use printk context for CPU and task information
config: csky-randconfig-r134-20260121 (https://download.01.org/0day-ci/archive/20260121/202601211304.r9ecHy9L-lkp@intel.com/config)
compiler: csky-linux-gcc (GCC) 13.4.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260121/202601211304.r9ecHy9L-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202601211304.r9ecHy9L-lkp@intel.com/

All error/warnings (new ones prefixed by >>):

   drivers/net/netconsole.c: In function 'sysdata_append_cpu_nr':
>> drivers/net/netconsole.c:1365:31: error: 'struct nbcon_write_context' has no member named 'cpu'
    1365 |                          wctxt->cpu);
         |                               ^~
   drivers/net/netconsole.c: In function 'sysdata_append_taskname':
>> drivers/net/netconsole.c:1373:31: error: 'struct nbcon_write_context' has no member named 'comm'
    1373 |                          wctxt->comm);
         |                               ^~
   drivers/net/netconsole.c: In function 'sysdata_append_cpu_nr':
>> drivers/net/netconsole.c:1366:1: warning: control reaches end of non-void function [-Wreturn-type]
    1366 | }
         | ^
   drivers/net/netconsole.c: In function 'sysdata_append_taskname':
   drivers/net/netconsole.c:1374:1: warning: control reaches end of non-void function [-Wreturn-type]
    1374 | }
         | ^


vim +1365 drivers/net/netconsole.c

  1359	
  1360	static int sysdata_append_cpu_nr(struct netconsole_target *nt, int offset,
  1361					 struct nbcon_write_context *wctxt)
  1362	{
  1363		return scnprintf(&nt->sysdata[offset],
  1364				 MAX_EXTRADATA_ENTRY_LEN, " cpu=%u\n",
> 1365				 wctxt->cpu);
> 1366	}
  1367	
  1368	static int sysdata_append_taskname(struct netconsole_target *nt, int offset,
  1369					   struct nbcon_write_context *wctxt)
  1370	{
  1371		return scnprintf(&nt->sysdata[offset],
  1372				 MAX_EXTRADATA_ENTRY_LEN, " taskname=%s\n",
> 1373				 wctxt->comm);
  1374	}
  1375	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH net-next v2 1/5] printk: Add execution context (task name/CPU) to printk_info
  2026-01-20 16:23 ` [PATCH net-next v2 1/5] printk: Add execution context (task name/CPU) to printk_info Breno Leitao
@ 2026-01-21 11:41   ` Breno Leitao
  0 siblings, 0 replies; 11+ messages in thread
From: Breno Leitao @ 2026-01-21 11:41 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, pmladek, john.ogness
  Cc: Greg Kroah-Hartman, Steven Rostedt, Sergey Senozhatsky,
	Andrew Morton, netdev, linux-kernel, asantostc, efault, gustavold,
	calvin, jv, mpdesouza, kernel-team

On Tue, Jan 20, 2026 at 08:23:47AM -0800, Breno Leitao wrote:
> Extend struct printk_info to include the task name, pid, and CPU
> number where printk messages originate. This information is captured
> at vprintk_store() time and propagated through printk_message to
> nbcon_write_context, making it available to nbcon console drivers.
> 
> This is useful for consoles like netconsole that want to include
> execution context in their output, allowing correlation of messages
> with specific tasks and CPUs regardless of where the console driver
> actually runs.
> 
> The feature is controlled by CONFIG_PRINTK_EXECUTION_CTX, which is
> automatically selected by CONFIG_NETCONSOLE_DYNAMIC. When disabled,
> the helper functions compile to no-ops with no overhead.
> 
> Suggested-by: John Ogness <john.ogness@linutronix.de>
> Signed-off-by: Breno Leitao <leitao@debian.org>
> Signed-off-by: Petr Mladek <pmladek@suse.com>
> ---
>  drivers/net/Kconfig               |  1 +
>  include/linux/console.h           |  8 ++++++
>  kernel/printk/internal.h          |  8 ++++++
>  kernel/printk/nbcon.c             | 15 +++++++++++
>  kernel/printk/printk.c            | 52 ++++++++++++++++++++++++++++++++++++++-
>  kernel/printk/printk_ringbuffer.h |  4 +++
>  lib/Kconfig.debug                 | 20 +++++++++++++++
>  7 files changed, 107 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
> index ac12eaf11755d..12e47cb27ffa5 100644
> --- a/drivers/net/Kconfig
> +++ b/drivers/net/Kconfig
> @@ -341,6 +341,7 @@ config NETCONSOLE_DYNAMIC
>  	bool "Dynamic reconfiguration of logging targets"
>  	depends on NETCONSOLE && SYSFS && CONFIGFS_FS && \
>  			!(NETCONSOLE=y && CONFIGFS_FS=m)
> +	select CONSOLE_HAS_EXECUTION_CTX

This is wrong as detected by Kernel test robot.

	https://lore.kernel.org/all/202601211304.r9ecHy9L-lkp@intel.com/

On csky, CONSOLE_HAS_EXECUTION_CTX is set, but not
CONFIG_PRINTK_EXECUTION_CTX

	https://download.01.org/0day-ci/archive/20260121/202601211304.r9ecHy9L-lkp@intel.com/config

The execution context fields were not available, while
NETCONSOLE_DYNAMIC, causing a compilation error.

It needs to be:

+ select PRINTK_EXECUTION_CTX

--
pw-bot: cr

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH net-next v2 3/5] netconsole: convert to NBCON console infrastructure
  2026-01-20 16:23 ` [PATCH net-next v2 3/5] netconsole: convert to NBCON console infrastructure Breno Leitao
@ 2026-01-22 21:09   ` Simon Horman
  2026-01-23 10:48     ` Breno Leitao
  0 siblings, 1 reply; 11+ messages in thread
From: Simon Horman @ 2026-01-22 21:09 UTC (permalink / raw)
  To: Breno Leitao
  Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, pmladek, john.ogness, Greg Kroah-Hartman,
	Steven Rostedt, Sergey Senozhatsky, Andrew Morton, netdev,
	linux-kernel, asantostc, efault, gustavold, calvin, jv, mpdesouza,
	kernel-team

On Tue, Jan 20, 2026 at 08:23:49AM -0800, Breno Leitao wrote:
> Convert netconsole from the legacy console API to the NBCON framework.
> NBCON provides threaded printing which unblocks printk()s and flushes in
> a thread, decoupling network TX from printk() when netconsole is
> in use.
> 
> Since netconsole relies on the network stack which cannot safely operate
> from all atomic contexts, mark both consoles with
> CON_NBCON_ATOMIC_UNSAFE. (See discussion in [1])
> 
> CON_NBCON_ATOMIC_UNSAFE restricts write_atomic() usage to emergency
> scenarios (panic) where regular messages are sent in threaded mode.
> 
> Implementation changes:
> - Unify write_ext_msg() and write_msg() into netconsole_write()
> - Add device_lock/device_unlock callbacks to manage target_list_lock
> - Use nbcon_enter_unsafe()/nbcon_exit_unsafe() around network
>   operations.
>   - If nbcon_enter_unsafe() fails, just return given netconsole lost
>     the ownership of the console.
> - Set write_thread and write_atomic callbacks (both use same function)
> 
> Link: https://lore.kernel.org/all/b2qps3uywhmjaym4mht2wpxul4yqtuuayeoq4iv4k3zf5wdgh3@tocu6c7mj4lt/ [1]
> Signed-off-by: Breno Leitao <leitao@debian.org>
> ---
>  drivers/net/netconsole.c | 97 ++++++++++++++++++++++++++++++------------------
>  1 file changed, 60 insertions(+), 37 deletions(-)
> 
> diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c

...

> +static void netconsole_device_lock(struct console *con __always_unused,
> +				   unsigned long *flags)
> +{
> +	spin_lock_irqsave(&target_list_lock, *flags);
> +}
> +
> +static void netconsole_device_unlock(struct console *con __always_unused,
> +				     unsigned long flags)
> +{
>  	spin_unlock_irqrestore(&target_list_lock, flags);
>  }
>  

Hi Breno,

I'm wondering if we could consider the following annotations,
as "suggested" by Sparse[1].

diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
index c5d7e97fe2a7..79e39a6c5343 100644
--- a/drivers/net/netconsole.c
+++ b/drivers/net/netconsole.c
@@ -1772,12 +1772,14 @@ static void netconsole_write_basic(struct console *con __always_unused,
 
 static void netconsole_device_lock(struct console *con __always_unused,
 				   unsigned long *flags)
+__acquires(&target_list_lock)
 {
 	spin_lock_irqsave(&target_list_lock, *flags);
 }
 
 static void netconsole_device_unlock(struct console *con __always_unused,
 				     unsigned long flags)
+__releases(&target_list_lock)
 {
 	spin_unlock_irqrestore(&target_list_lock, flags);
 }

[1] This particular commit of Sparse, from Al Viro's tree:
    https://git.kernel.org/pub/scm/linux/kernel/git/viro/sparse.git/commit/?id=2634e39bf02697a18fece057208150362c985992
    Which addresses this mess:
    https://lore.kernel.org/all/bf5b9a62-a120-421e-908d-1404c42e0b60@kernel.org/

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH net-next v2 3/5] netconsole: convert to NBCON console infrastructure
  2026-01-22 21:09   ` Simon Horman
@ 2026-01-23 10:48     ` Breno Leitao
  2026-01-23 18:04       ` Simon Horman
  0 siblings, 1 reply; 11+ messages in thread
From: Breno Leitao @ 2026-01-23 10:48 UTC (permalink / raw)
  To: Simon Horman
  Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, pmladek, john.ogness, Greg Kroah-Hartman,
	Steven Rostedt, Sergey Senozhatsky, Andrew Morton, netdev,
	linux-kernel, asantostc, efault, gustavold, calvin, jv, mpdesouza,
	kernel-team

Hello Simon!

On Thu, Jan 22, 2026 at 09:09:34PM +0000, Simon Horman wrote:
> On Tue, Jan 20, 2026 at 08:23:49AM -0800, Breno Leitao wrote:
> > Convert netconsole from the legacy console API to the NBCON framework.
> > NBCON provides threaded printing which unblocks printk()s and flushes in
> > a thread, decoupling network TX from printk() when netconsole is
> > in use.
> > 
> > Since netconsole relies on the network stack which cannot safely operate
> > from all atomic contexts, mark both consoles with
> > CON_NBCON_ATOMIC_UNSAFE. (See discussion in [1])
> > 
> > CON_NBCON_ATOMIC_UNSAFE restricts write_atomic() usage to emergency
> > scenarios (panic) where regular messages are sent in threaded mode.
> > 
> > Implementation changes:
> > - Unify write_ext_msg() and write_msg() into netconsole_write()
> > - Add device_lock/device_unlock callbacks to manage target_list_lock
> > - Use nbcon_enter_unsafe()/nbcon_exit_unsafe() around network
> >   operations.
> >   - If nbcon_enter_unsafe() fails, just return given netconsole lost
> >     the ownership of the console.
> > - Set write_thread and write_atomic callbacks (both use same function)
> > 
> > Link: https://lore.kernel.org/all/b2qps3uywhmjaym4mht2wpxul4yqtuuayeoq4iv4k3zf5wdgh3@tocu6c7mj4lt/ [1]
> > Signed-off-by: Breno Leitao <leitao@debian.org>
> > ---
> >  drivers/net/netconsole.c | 97 ++++++++++++++++++++++++++++++------------------
> >  1 file changed, 60 insertions(+), 37 deletions(-)
> > 
> > diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
> 
> ...
> 
> > +static void netconsole_device_lock(struct console *con __always_unused,
> > +				   unsigned long *flags)
> > +{
> > +	spin_lock_irqsave(&target_list_lock, *flags);
> > +}
> > +
> > +static void netconsole_device_unlock(struct console *con __always_unused,
> > +				     unsigned long flags)
> > +{
> >  	spin_unlock_irqrestore(&target_list_lock, flags);
> >  }
> >  
> 
> Hi Breno,
> 
> I'm wondering if we could consider the following annotations,
> as "suggested" by Sparse[1].

This is great. I hadn't realized that Al Viro's sparse tree includes this
additional check, which is really useful.

Are you using Al Viro's branch rather than the sparse mainline?

(I'm asking to see if I should also follow master and do the same, in
true padawan fashion)


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH net-next v2 3/5] netconsole: convert to NBCON console infrastructure
  2026-01-23 10:48     ` Breno Leitao
@ 2026-01-23 18:04       ` Simon Horman
  0 siblings, 0 replies; 11+ messages in thread
From: Simon Horman @ 2026-01-23 18:04 UTC (permalink / raw)
  To: Breno Leitao
  Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, pmladek, john.ogness, Greg Kroah-Hartman,
	Steven Rostedt, Sergey Senozhatsky, Andrew Morton, netdev,
	linux-kernel, asantostc, efault, gustavold, calvin, jv, mpdesouza,
	kernel-team

On Fri, Jan 23, 2026 at 02:48:47AM -0800, Breno Leitao wrote:
> Hello Simon!
> 
> On Thu, Jan 22, 2026 at 09:09:34PM +0000, Simon Horman wrote:
> > On Tue, Jan 20, 2026 at 08:23:49AM -0800, Breno Leitao wrote:
> > > Convert netconsole from the legacy console API to the NBCON framework.
> > > NBCON provides threaded printing which unblocks printk()s and flushes in
> > > a thread, decoupling network TX from printk() when netconsole is
> > > in use.
> > > 
> > > Since netconsole relies on the network stack which cannot safely operate
> > > from all atomic contexts, mark both consoles with
> > > CON_NBCON_ATOMIC_UNSAFE. (See discussion in [1])
> > > 
> > > CON_NBCON_ATOMIC_UNSAFE restricts write_atomic() usage to emergency
> > > scenarios (panic) where regular messages are sent in threaded mode.
> > > 
> > > Implementation changes:
> > > - Unify write_ext_msg() and write_msg() into netconsole_write()
> > > - Add device_lock/device_unlock callbacks to manage target_list_lock
> > > - Use nbcon_enter_unsafe()/nbcon_exit_unsafe() around network
> > >   operations.
> > >   - If nbcon_enter_unsafe() fails, just return given netconsole lost
> > >     the ownership of the console.
> > > - Set write_thread and write_atomic callbacks (both use same function)
> > > 
> > > Link: https://lore.kernel.org/all/b2qps3uywhmjaym4mht2wpxul4yqtuuayeoq4iv4k3zf5wdgh3@tocu6c7mj4lt/ [1]
> > > Signed-off-by: Breno Leitao <leitao@debian.org>
> > > ---
> > >  drivers/net/netconsole.c | 97 ++++++++++++++++++++++++++++++------------------
> > >  1 file changed, 60 insertions(+), 37 deletions(-)
> > > 
> > > diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
> > 
> > ...
> > 
> > > +static void netconsole_device_lock(struct console *con __always_unused,
> > > +				   unsigned long *flags)
> > > +{
> > > +	spin_lock_irqsave(&target_list_lock, *flags);
> > > +}
> > > +
> > > +static void netconsole_device_unlock(struct console *con __always_unused,
> > > +				     unsigned long flags)
> > > +{
> > >  	spin_unlock_irqrestore(&target_list_lock, flags);
> > >  }
> > >  
> > 
> > Hi Breno,
> > 
> > I'm wondering if we could consider the following annotations,
> > as "suggested" by Sparse[1].
> 
> This is great. I hadn't realized that Al Viro's sparse tree includes this
> additional check, which is really useful.
> 
> Are you using Al Viro's branch rather than the sparse mainline?
> 
> (I'm asking to see if I should also follow master and do the same, in
> true padawan fashion)

Well, I think it would be best if mainline was fixed.
(Although I am yet to do anything towards making that happen.)

But to answer your question, yes, I am using Al's tree.
Since a few days ago when I tracked down that it allows
Sparse to once work significantly more robustly on the
current Kernel tree.

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2026-01-23 18:04 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-20 16:23 [PATCH net-next v2 0/5] net: netconsole: convert to NBCON console infrastructure Breno Leitao
2026-01-20 16:23 ` [PATCH net-next v2 1/5] printk: Add execution context (task name/CPU) to printk_info Breno Leitao
2026-01-21 11:41   ` Breno Leitao
2026-01-20 16:23 ` [PATCH net-next v2 2/5] netconsole: extract message fragmentation into send_msg_udp() Breno Leitao
2026-01-20 16:23 ` [PATCH net-next v2 3/5] netconsole: convert to NBCON console infrastructure Breno Leitao
2026-01-22 21:09   ` Simon Horman
2026-01-23 10:48     ` Breno Leitao
2026-01-23 18:04       ` Simon Horman
2026-01-20 16:23 ` [PATCH net-next v2 4/5] netconsole: Use printk context for CPU and task information Breno Leitao
2026-01-21  5:40   ` kernel test robot
2026-01-20 16:23 ` [PATCH net-next v2 5/5] netconsole: pass wctxt to send_msg_udp() for consistency Breno Leitao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox