Subject: Re: [PATCH net-next 0/2] net: netconsole: convert to NBCON console infrastructure

From: Petr Mladek <[email-masked]>
Date: Fri, 16 Jan 2026 16:53:48 +0100

On Fri 2026-01-16 16:51:49, Petr Mladek wrote:
> On Mon 2026-01-12 04:44:42, Breno Leitao wrote:
> > On Mon, Jan 12, 2026 at 02:55:06AM -0800, Breno Leitao wrote:
> > 
> >     printk: Add execution context (task name/CPU) to printk_info
> >     
> > 
> > --- a/kernel/printk/printk_ringbuffer.h
> > +++ b/kernel/printk/printk_ringbuffer.h
> > @@ -23,6 +24,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
> > +	char	msg_comm[TASK_COMM_LEN]; /* name of the task that generated the message */
> > +	int	msg_cpu;	/* CPU where the message was generated */
> 
> I would allow to store the caller_id complement so that we
> always store both cpu and pid.
> 
> Also I would remove the "msg_" prefix. It is not bad. But it is
> inconsistent with the existing "caller_" prefix. And the meaning
> should be obvious because it is stored in struct printk_info...
> 
> Otherwise, it looks good to me.
> 
> I tried to update your patch with the above proposal to see how
> it looks and I got:

The change seems to work. I have tested it with the following patch:

>From 1966dc35bb19eb3fc13ca41257203819c36cd21b Mon Sep 17 00:00:00 2001
From: Petr Mladek <[email-masked]>
Date: Fri, 16 Jan 2026 16:38:16 +0100
Subject: [PATCH 2/2] printk: Test extended execution context

Compile with

CONFIG_NETCONSOLE=y
CONFIG_NETCONSOLE_EXTENDED_LOG=y
CONFIG_CONSOLE_HAS_EXECUTION_CTX=y
CONFIG_PRINTK_EXECUTION_CTX=y

Then the extended console format should show also:

     ,cpu=XXX,pid=YYY,comm=ZZZ

For example:

[...]
6,776,2595848,-,caller=T167,cpu=3,pid=167,comm=scsi_eh_4;ata5: SATA link down (SStatus 0 SControl 300)
6,777,2623478,-,caller=T1,cpu=11,pid=1,comm=swapper/0;sched_clock: Marking stable (2420002924, 202869031)->(2789319400, -166447445)
6,778,2626663,-,caller=T159,cpu=2,pid=159,comm=scsi_eh_0;ata1: SATA link down (SStatus 0 SControl 300)
6,779,2671763,-,caller=T1,cpu=7,pid=1,comm=swapper/0;registered taskstats version 1
6,780,2672803,-,caller=T163,cpu=3,pid=163,comm=scsi_eh_2;ata3: SATA link down (SStatus 0 SControl 300)
[...]
4,1210,238099642,-,caller=C11,cpu=11,pid=0,comm=swapper/11; common_startup_64+0x13e/0x141
4,1211,238099651,-,caller=C11,cpu=11,pid=0,comm=swapper/11; </TASK>
4,1212,238099652,-,caller=C7,cpu=7,pid=0,comm=swapper/7;NMI backtrace for cpu 7
4,1213,238099655,-,caller=C7,cpu=7,pid=0,comm=swapper/7;CPU: 7 UID: 0 PID: 0 Comm: swapper/7 Not tainted 6.19.0-rc5-default+ #475 PREEMPT(full)  9097c5ae70fd66490486e279e5273a94d14cd453
[...]

Signed-off-by: Petr Mladek <[email-masked]>
---
 kernel/printk/printk.c | 84 ++++++++++++++++++++++++------------------
 1 file changed, 48 insertions(+), 36 deletions(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index bc09fb6e33d1..ac8eccb1d2fc 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -630,6 +630,40 @@ static int check_syslog_permissions(int type, int source)
 	return security_syslog(type);
 }
 
+#define caller_id_mask 0x80000000
+
+static inline u32 printk_caller_id(void)
+{
+	return in_task() ? task_pid_nr(current) :
+		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
+
 static void append_char(char **pp, char *e, char c)
 {
 	if (*pp < e)
@@ -641,6 +675,7 @@ static ssize_t info_print_ext_header(char *buf, size_t size,
 {
 	u64 ts_usec = info->ts_nsec;
 	char caller[20];
+	char ext_caller[100];
 #ifdef CONFIG_PRINTK_CALLER
 	u32 id = info->caller_id;
 
@@ -650,11 +685,22 @@ static ssize_t info_print_ext_header(char *buf, size_t size,
 	caller[0] = '\0';
 #endif
 
+#ifdef CONFIG_PRINTK_EXECUTION_CTX
+	snprintf(ext_caller, sizeof(ext_caller),
+		 ",cpu=%u,pid=%u,comm=%s",
+		 printk_info_get_cpu(info),
+		 printk_info_get_pid(info),
+		 info->comm);
+#else
+	ext_caller[0] = '\0';
+#endif
+
 	do_div(ts_usec, 1000);
 
-	return scnprintf(buf, size, "%u,%llu,%llu,%c%s;",
+	return scnprintf(buf, size, "%u,%llu,%llu,%c%s%s;",
 			 (info->facility << 3) | info->level, info->seq,
-			 ts_usec, info->flags & LOG_CONT ? 'c' : '-', caller);
+			 ts_usec, info->flags & LOG_CONT ? 'c' : '-',
+			 caller, ext_caller);
 }
 
 static ssize_t msg_add_ext_text(char *buf, size_t size,
@@ -2131,40 +2177,6 @@ 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) :
-		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.
  *
-- 
2.52.0