[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <j764nuipx4nvemd3wlqfyx77lkdf7wgs5z452hlacwglvc2e7n@vsko4bq5xb2f>
Date: Thu, 8 Jan 2026 03:08:16 -0800
From: Breno Leitao <leitao@...ian.org>
To: John Ogness <john.ogness@...utronix.de>, pmladek@...e.com,
mpdesouza@...e.com
Cc: pmladek@...e.com, mpdesouza@...e.com, netdev@...r.kernel.org,
linux-kernel@...r.kernel.org, asantostc@...il.com, efault@....de, gustavold@...il.com,
calvin@...nvd.org, jv@...sburgh.net, kernel-team@...a.com,
Simon Horman <horms@...nel.org>, Andrew Lunn <andrew+netdev@...n.ch>,
"David S. Miller" <davem@...emloft.net>, Eric Dumazet <edumazet@...gle.com>,
Jakub Kicinski <kuba@...nel.org>, Paolo Abeni <pabeni@...hat.com>, rostedt@...dmis.org
Subject: Re: [PATCH net-next 0/2] net: netconsole: convert to NBCON console
infrastructure
On Wed, Jan 07, 2026 at 08:58:39AM -0800, Breno Leitao wrote:
> On Wed, Jan 07, 2026 at 04:56:41PM +0106, John Ogness wrote:
>
> Thanks. Let me prototype this and see how it turns out.
This is what I am thinking about. How bad is it?
(I've also implemented the netconsole part as well, so, if you want to
have a tree, you can find it in
https://github.com/leitao/linux/tree/execution_context)
commit fe79961da6cabe42343185cf1a7308162bf6bad3
Author: Breno Leitao <leitao@...ian.org>
Date: Thu Jan 8 03:00:46 2026 -0800
printk: Add execution context (PID/CPU) to dev_printk_info
Extend struct dev_printk_info to include the task 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@...utronix.de>
Signed-off-by: Breno Leitao <leitao@...ian.org>
diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index ac12eaf11755..e6a9369be202 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 PRINTK_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 fc9f5c5c1b04..c724f59f96e6 100644
--- a/include/linux/console.h
+++ b/include/linux/console.h
@@ -298,12 +298,18 @@ 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
+ * @pid: PID of the task that generated the message
+ * @cpu: CPU on which the message was generated
*/
struct nbcon_write_context {
struct nbcon_context __private ctxt;
char *outbuf;
unsigned int len;
bool unsafe_takeover;
+#ifdef CONFIG_PRINTK_EXECUTION_CTX
+ pid_t pid;
+ int cpu;
+#endif
};
/**
diff --git a/include/linux/dev_printk.h b/include/linux/dev_printk.h
index eb2094e43050..42ee778b29dd 100644
--- a/include/linux/dev_printk.h
+++ b/include/linux/dev_printk.h
@@ -27,6 +27,10 @@ struct device;
struct dev_printk_info {
char subsystem[PRINTK_INFO_SUBSYSTEM_LEN];
char device[PRINTK_INFO_DEVICE_LEN];
+#ifdef CONFIG_PRINTK_EXECUTION_CTX
+ pid_t pid;
+ int cpu;
+#endif
};
#ifdef CONFIG_PRINTK
diff --git a/kernel/printk/internal.h b/kernel/printk/internal.h
index 5f5f626f4279..81e5cd336677 100644
--- a/kernel/printk/internal.h
+++ b/kernel/printk/internal.h
@@ -287,6 +287,10 @@ struct printk_message {
unsigned int outbuf_len;
u64 seq;
unsigned long dropped;
+#ifdef CONFIG_PRINTK_EXECUTION_CTX
+ pid_t pid;
+ int cpu;
+#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 3fa403f9831f..2465fafd7727 100644
--- a/kernel/printk/nbcon.c
+++ b/kernel/printk/nbcon.c
@@ -946,6 +946,18 @@ 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->pid = pmsg->pid;
+ wctxt->cpu = pmsg->cpu;
+}
+#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 +1060,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 1d765ad242b8..ff47b5384f20 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -2213,6 +2213,26 @@ static u16 printk_sprint(char *text, u16 size, int facility,
return text_len;
}
+#ifdef CONFIG_PRINTK_EXECUTION_CTX
+static inline void printk_save_execution_ctx(struct dev_printk_info *dev_info)
+{
+ dev_info->pid = task_pid_nr(current);
+ dev_info->cpu = smp_processor_id();
+}
+
+static inline void pmsg_load_execution_ctx(struct printk_message *pmsg,
+ const struct dev_printk_info *dev_info)
+{
+ pmsg->pid = dev_info->pid;
+ pmsg->cpu = dev_info->cpu;
+}
+#else
+static inline void printk_save_execution_ctx(struct dev_printk_info *dev_info) {}
+
+static inline void pmsg_load_execution_ctx(struct printk_message *pmsg,
+ const struct dev_printk_info *dev_info) {}
+#endif
+
__printf(4, 0)
int vprintk_store(int facility, int level,
const struct dev_printk_info *dev_info,
@@ -2320,6 +2340,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_save_execution_ctx(&r.info->dev_info);
/* A message without a trailing newline can be continued. */
if (!(flags & LOG_NEWLINE))
@@ -3002,6 +3023,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->dev_info);
/*
* Skip records that are not forced to be printed on consoles and that
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index ba36939fda79..197022099dd8 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -35,6 +35,17 @@ config PRINTK_CALLER
no option to enable/disable at the kernel command line parameter or
sysfs interface.
+config PRINTK_EXECUTION_CTX
+ bool
+ depends on PRINTK
+ help
+ This option extends struct dev_printk_info to include extra execution
+ context in pritnk, such as task PID and CPU number from where the
+ message originated. This is useful for correlating device messages
+ with specific execution contexts.
+
+ One of the main user for this config is netconsole.
+
config STACKTRACE_BUILD_ID
bool "Show build ID information in stacktraces"
depends on PRINTK
Powered by blists - more mailing lists