From: Breno Leitao <leitao@debian.org>
To: 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>, Simon Horman <horms@kernel.org>,
Jonathan Corbet <corbet@lwn.net>, Shuah Khan <shuah@kernel.org>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org,
rdunlap@infradead.org, Breno Leitao <leitao@debian.org>,
kernel-team@meta.com
Subject: [PATCH RFC net-next v3 6/8] netconsole: add support for sysdata and CPU population
Date: Fri, 24 Jan 2025 07:16:45 -0800 [thread overview]
Message-ID: <20250124-netcon_cpu-v3-6-12a0d286ba1d@debian.org> (raw)
In-Reply-To: <20250124-netcon_cpu-v3-0-12a0d286ba1d@debian.org>
Add infrastructure to automatically append kernel-generated data (sysdata)
to netconsole messages. As the first use case, implement CPU number
population, which adds the CPU that sent the message.
This change introduces three distinct data types:
- extradata: The complete set of appended data (sysdata + userdata)
- userdata: User-provided key-value pairs from userspace
- sysdata: Kernel-populated data (e.g. cpu=XX)
The implementation adds a new configfs attribute 'cpu_nr' to control CPU
number population per target. When enabled, each message is tagged with
its originating CPU. The sysdata is dynamically updated at message time
and appended after any existing userdata.
The CPU number is formatted as "cpu=XX" and is added to the extradata
buffer, respecting the existing size limits.
Signed-off-by: Breno Leitao <leitao@debian.org>
---
drivers/net/netconsole.c | 53 +++++++++++++++++++++++++++++++++++++++---------
1 file changed, 43 insertions(+), 10 deletions(-)
diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
index 2f1aecdf2a47f246e75061d09b9ca524a82ec994..d3df66de9a352678bff011024922c63ef6f1b0ef 100644
--- a/drivers/net/netconsole.c
+++ b/drivers/net/netconsole.c
@@ -1116,6 +1116,40 @@ static void populate_configfs_item(struct netconsole_target *nt,
init_target_config_group(nt, target_name);
}
+/*
+ * prepare_extradata - append sysdata at extradata_complete in runtime
+ * @nt: target to send message to
+ */
+static int prepare_extradata(struct netconsole_target *nt)
+{
+ int sysdata_len, extradata_len;
+
+ /* userdata was appended when configfs write helper was called
+ * by update_userdata().
+ */
+ extradata_len = nt->userdata_length;
+
+ if (!(nt->sysdata_fields & CPU_NR))
+ goto out;
+
+ /* Append cpu=%d at extradata_complete after userdata str */
+ sysdata_len = scnprintf(&nt->extradata_complete[nt->userdata_length],
+ MAX_EXTRADATA_ENTRY_LEN, " cpu=%u\n",
+ raw_smp_processor_id());
+
+ extradata_len += sysdata_len;
+
+ WARN_ON_ONCE(extradata_len >
+ MAX_EXTRADATA_ENTRY_LEN * MAX_EXTRADATA_ITEMS);
+
+out:
+ return extradata_len;
+}
+#else /* CONFIG_NETCONSOLE_DYNAMIC not set */
+static int prepare_extradata(struct netconsole_target *nt)
+{
+ return 0;
+}
#endif /* CONFIG_NETCONSOLE_DYNAMIC */
/* Handle network interface device notifications */
@@ -1250,16 +1284,14 @@ static void append_release(char *buf)
static void send_fragmented_body(struct netconsole_target *nt,
const char *msgbody, int header_len,
- int msgbody_len)
+ int msgbody_len, int extradata_len)
{
int sent_extradata, preceding_bytes;
const char *extradata = NULL;
int body_len, offset = 0;
- int extradata_len = 0;
#ifdef CONFIG_NETCONSOLE_DYNAMIC
extradata = nt->extradata_complete;
- extradata_len = nt->userdata_length;
#endif
/* body_len represents the number of bytes that will be sent. This is
@@ -1340,7 +1372,8 @@ static void send_fragmented_body(struct netconsole_target *nt,
static void send_msg_fragmented(struct netconsole_target *nt,
const char *msg,
int msg_len,
- int release_len)
+ int release_len,
+ int extradata_len)
{
int header_len, msgbody_len;
const char *msgbody;
@@ -1368,7 +1401,8 @@ static void send_msg_fragmented(struct netconsole_target *nt,
/* for now on, the header will be persisted, and the msgbody
* will be replaced
*/
- send_fragmented_body(nt, msgbody, header_len, msgbody_len);
+ send_fragmented_body(nt, msgbody, header_len, msgbody_len,
+ extradata_len);
}
/**
@@ -1384,12 +1418,10 @@ static void send_msg_fragmented(struct netconsole_target *nt,
static void send_ext_msg_udp(struct netconsole_target *nt, const char *msg,
int msg_len)
{
- int extradata_len = 0;
int release_len = 0;
+ int extradata_len;
-#ifdef CONFIG_NETCONSOLE_DYNAMIC
- extradata_len = nt->userdata_length;
-#endif
+ extradata_len = prepare_extradata(nt);
if (nt->release)
release_len = strlen(init_utsname()->release) + 1;
@@ -1397,7 +1429,8 @@ static void send_ext_msg_udp(struct netconsole_target *nt, const char *msg,
if (msg_len + release_len + extradata_len <= MAX_PRINT_CHUNK)
return send_msg_no_fragmentation(nt, msg, msg_len, release_len);
- return send_msg_fragmented(nt, msg, msg_len, release_len);
+ return send_msg_fragmented(nt, msg, msg_len, release_len,
+ extradata_len);
}
static void write_ext_msg(struct console *con, const char *msg,
--
2.43.5
next prev parent reply other threads:[~2025-01-24 15:17 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-24 15:16 [PATCH RFC net-next v3 0/8] netconsole: Add support for CPU population Breno Leitao
2025-01-24 15:16 ` [PATCH RFC net-next v3 1/8] netconsole: consolidate send buffers into netconsole_target struct Breno Leitao
2025-01-28 16:11 ` Simon Horman
2025-01-30 10:35 ` Simon Horman
2025-01-31 13:11 ` Breno Leitao
2025-01-24 15:16 ` [PATCH RFC net-next v3 2/8] netconsole: Rename userdata to extradata Breno Leitao
2025-01-30 10:36 ` Simon Horman
2025-01-24 15:16 ` [PATCH RFC net-next v3 3/8] netconsole: Helper to count number of used entries Breno Leitao
2025-01-30 10:37 ` Simon Horman
2025-01-24 15:16 ` [PATCH RFC net-next v3 4/8] netconsole: Introduce configfs helpers for sysdata features Breno Leitao
2025-01-28 16:12 ` Simon Horman
2025-01-30 10:37 ` Simon Horman
2025-01-24 15:16 ` [PATCH RFC net-next v3 5/8] netconsole: Include sysdata in extradata entry count Breno Leitao
2025-01-30 10:38 ` Simon Horman
2025-01-24 15:16 ` Breno Leitao [this message]
2025-01-30 10:38 ` [PATCH RFC net-next v3 6/8] netconsole: add support for sysdata and CPU population Simon Horman
2025-01-24 15:16 ` [PATCH RFC net-next v3 7/8] netconsole: selftest: test for sysdata CPU Breno Leitao
2025-01-30 10:38 ` Simon Horman
2025-01-24 15:16 ` [PATCH RFC net-next v3 8/8] netconsole: docs: Add documentation for CPU number auto-population Breno Leitao
2025-01-24 16:15 ` Andrew Lunn
2025-01-27 17:10 ` Breno Leitao
2025-01-24 16:02 ` [PATCH RFC net-next v3 0/8] netconsole: Add support for CPU population Andrew Lunn
2025-01-27 9:52 ` Breno Leitao
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=20250124-netcon_cpu-v3-6-12a0d286ba1d@debian.org \
--to=leitao@debian.org \
--cc=andrew+netdev@lunn.ch \
--cc=corbet@lwn.net \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kernel-team@meta.com \
--cc=kuba@kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=rdunlap@infradead.org \
--cc=shuah@kernel.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;
as well as URLs for NNTP newsgroup(s).