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
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
© 2016 - 2026 Red Hat, Inc.