From: Breno Leitao <leitao@debian.org>
To: Breno Leitao <leitao@debian.org>,
Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>,
pmladek@suse.com, john.ogness@linutronix.de
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Steven Rostedt <rostedt@goodmis.org>,
Sergey Senozhatsky <senozhatsky@chromium.org>,
Andrew Morton <akpm@linux-foundation.org>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
asantostc@gmail.com, efault@gmx.de, gustavold@gmail.com,
calvin@wbinvd.org, jv@jvosburgh.net, mpdesouza@suse.com,
kernel-team@meta.com
Subject: [PATCH net-next v5 4/4] netconsole: Use printk context for CPU and task information
Date: Wed, 28 Jan 2026 06:17:40 -0800 [thread overview]
Message-ID: <20260128-nbcon-v5-4-93b4ddbc181a@debian.org> (raw)
In-Reply-To: <20260128-nbcon-v5-0-93b4ddbc181a@debian.org>
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->cpu instead of raw_smp_processor_id().
For taskname, use wctxt->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 | 40 +++++++++++++++++++++++-----------------
1 file changed, 23 insertions(+), 17 deletions(-)
diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
index ec000f477c2a8..0f44ce5ccc0ab 100644
--- a/drivers/net/netconsole.c
+++ b/drivers/net/netconsole.c
@@ -1490,18 +1490,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)
@@ -1522,8 +1524,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;
@@ -1531,9 +1535,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)
@@ -1831,31 +1835,33 @@ 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;
+ int len;
#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);
+ len = wctxt->len + release_len + sysdata_len + userdata_len;
+ if (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);
}
@@ -1900,7 +1906,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
next prev parent reply other threads:[~2026-01-28 14:18 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-28 14:17 [PATCH net-next v5 0/4] net: netconsole: convert to NBCON console infrastructure Breno Leitao
2026-01-28 14:17 ` [PATCH net-next v5 1/4] printk: Add execution context (task name/CPU) to printk_info Breno Leitao
2026-01-28 14:42 ` John Ogness
2026-01-30 9:01 ` Breno Leitao
2026-01-30 9:19 ` Petr Mladek
2026-01-30 9:20 ` John Ogness
2026-01-31 1:32 ` Jakub Kicinski
2026-02-02 11:49 ` Breno Leitao
2026-02-03 0:23 ` Jakub Kicinski
2026-01-28 14:17 ` [PATCH net-next v5 2/4] netconsole: extract message fragmentation into send_msg_udp() Breno Leitao
2026-01-28 14:44 ` John Ogness
2026-01-28 14:17 ` [PATCH net-next v5 3/4] netconsole: convert to NBCON console infrastructure Breno Leitao
2026-01-28 14:49 ` John Ogness
2026-01-29 15:19 ` Petr Mladek
2026-01-28 14:17 ` Breno Leitao [this message]
2026-01-28 15:03 ` [PATCH net-next v5 4/4] netconsole: Use printk context for CPU and task information John Ogness
2026-01-28 16:46 ` Breno Leitao
2026-01-29 15:25 ` Petr Mladek
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=20260128-nbcon-v5-4-93b4ddbc181a@debian.org \
--to=leitao@debian.org \
--cc=akpm@linux-foundation.org \
--cc=andrew+netdev@lunn.ch \
--cc=asantostc@gmail.com \
--cc=calvin@wbinvd.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=efault@gmx.de \
--cc=gregkh@linuxfoundation.org \
--cc=gustavold@gmail.com \
--cc=john.ogness@linutronix.de \
--cc=jv@jvosburgh.net \
--cc=kernel-team@meta.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mpdesouza@suse.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=pmladek@suse.com \
--cc=rostedt@goodmis.org \
--cc=senozhatsky@chromium.org \
/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