From patchwork Wed Jan 15 13:35:18 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13940453 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f43.google.com (mail-ed1-f43.google.com [209.85.208.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 83C172419F5; Wed, 15 Jan 2025 13:35:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736948139; cv=none; b=f5/auFki2car/Gq7M/NG0bLBEOBCdsT/aGBZ3o5Jh4sZf3V3w57uB8m4jRD0H4x7i8feLRdO7yCnFfbFKWwGMgOWeuYNAlk9KX11X11WvKgAVpttM/0CezkpVyr33qWe0FOshUeHorMoj2kAfWG1r1kmuGgXxpT5luDJnXvryHk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736948139; c=relaxed/simple; bh=I44r0ohDanmuyGUNmsb93UKVYeAjH4Ix9dgCMmolnZA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=aLxwsiefkgTAl6/Wbq+TbCjeUaNWcDG+8soPYSShk2k8g04i9xQTAupqaZrPpXmnApOFKIIDceBhBCUyfAgVCn7kfVtJSBrr736mrsxg3RaaX2mzVE7n2yw8e09tIGXCAGiPlhLmDqCIyt/fie5r/nL7RtixWSYZ8G7viQcBuWA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.208.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-f43.google.com with SMTP id 4fb4d7f45d1cf-5d3d0205bd5so10247855a12.3; Wed, 15 Jan 2025 05:35:37 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736948136; x=1737552936; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=df2IhOg8gjz9sUPxNfKqvMxzOJiOqxvGrLLj83bUoYA=; b=hLv3AFBX8ZVqbIlicnKbuUKUZeudhardmH9m5JK2G48NS9ACqjzq9Jb44cGHAEFmGG lMWhS071vPWTEct9fN9N3JFXC/M3aAoKnbPyEPC1cuouEIycGbXfprh2baHDHhPi2Gfp c7iJvi60jxArCPHcFD61rYPk8Vqe5z+6deh+DLqerjdx585tPV2yRUOtpSfI78RAeZr+ JU6lB+mea+EiH+LwBnkocrPaFOaKDtWqM1sH6ssfcoA84vBdlwna9Isk2Hr1u0RjwZA+ T6aOGZfw4JojmKE3mbDdk5NX+b9QXhXvrwEUW7IpCjZveeCqH6KEAmhWjOieNYaTxW5x tVzQ== X-Forwarded-Encrypted: i=1; AJvYcCV+8mwTy9nxE4ZUmQg9EXXxLlNB5ItuAq1/BCQpeGC1ryzHliqi0zq80ZSeXzGNjDzpAMFWMcr9tWMyasARwq/2@vger.kernel.org, AJvYcCWQpgral8UBDvNghmQyEqxqG7xnfVQ/CHAZJAduu7PZHFpDiG1Zvm6AMXK4xZ0RmsQ0kAHlia68sNOGns8g@vger.kernel.org, AJvYcCWjjTogMtORp7XEQzuCGGHOaEpn7BNCk+XT0RMY97SOEWc6rKWOcKJs289TCZ1qke3+uZEXgJFKkhs=@vger.kernel.org X-Gm-Message-State: AOJu0YwEmsKY1G1RAmy3PDCCHNIWy244HeYYTqoKoj6zuiqgEnTLJHs2 k0p28SkcJ5AB5/hbG3Ivqxe7foF5+2wvQUD6aF/okVGQk42OumUK3LMfoA== X-Gm-Gg: ASbGncs+DIrAZ7zGa6C+gVggdBoa6AwGr1YLkQcG+n2Or3ajrYxOPraIzRN015OvhQZ 35ih5e71w4ezQWff/ydTh9Boj2BIvRvgIAcBVv/LUyK/d+TL1AabNmIaNSWLjGK7DSJYfaKClSz Rh3K1m1Y3sh7NR29oFduztGn+UCPGiYQVw0ZnGZuIJQU/7FX9+EJs2AnHkN9F5Q9Ku90hUOFZ8D aSLS8JZCAJnhJco5Eb8hiBwXTB0L27EKzgJLScIh/w8UEw= X-Google-Smtp-Source: AGHT+IH+jzZB+6H7tb2ufIL0iv9VO3Ke5GHd3vthkaBLWfZZiuwGOj0yB6/tLGzksHnYgKgAypln0A== X-Received: by 2002:a05:6402:51d0:b0:5d2:7346:3ecb with SMTP id 4fb4d7f45d1cf-5d972e08366mr27860822a12.12.1736948135564; Wed, 15 Jan 2025 05:35:35 -0800 (PST) Received: from localhost ([2a03:2880:30ff:1::]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d99046d7e3sm7183701a12.60.2025.01.15.05.35.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jan 2025 05:35:34 -0800 (PST) From: Breno Leitao Date: Wed, 15 Jan 2025 05:35:18 -0800 Subject: [PATCH net-next v2 1/5] netconsole: Rename userdata to extradata Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250115-netcon_cpu-v2-1-95971b44dc56@debian.org> References: <20250115-netcon_cpu-v2-0-95971b44dc56@debian.org> In-Reply-To: <20250115-netcon_cpu-v2-0-95971b44dc56@debian.org> To: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Jonathan Corbet , Shuah Khan Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, Breno Leitao , kernel-team@meta.com, max@kutsevol.com, thepacketgeek@gmail.com X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=10512; i=leitao@debian.org; h=from:subject:message-id; bh=I44r0ohDanmuyGUNmsb93UKVYeAjH4Ix9dgCMmolnZA=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBnh7mjB5DwkkBvfj6RL/Z/OSwlrlFr9WV/+JG6t PyDuzkSsnqJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCZ4e5owAKCRA1o5Of/Hh3 bYqND/472GKbeKPvYgOZBGTzDezqgW2rctj19Zm5Ii0h2NlBEszHZue1/TtDEjZ/2yPIZ7h1tO5 6vz4NkmN3vXRjDaZH/69FLVuatnWnoUrfSlwUtwiMwTwom5+SMngoK5qVZKpUnYDyruE2NY33sL lMwDHqtft4fos5PHEIVetAJJO94pvvHPQVllUaTkJ4Mj5quHyxN4AUT0eHECX8rd+09mEoq1eSX wt577hGMVMoOfK6nldzjeghgsCx5Gpxlw8ElXNxWkcuDMOZiqRWVol2eMGVFdI8jwqm5yl/fuWd lYYtuA7KW4Jfbqb+bvKAZxJeJFVNqLBA1OQAXdSoyQB52J2ISopeIbVJC3Yc42PPq0wZUXw18r6 XAI/6b0PQIZ+6GNa/qeDQ39qeHdE0oxI/dbbs4xOjFsMrjQdyrQRK4tfhdXd4DCyAvqhiktiQtk UxkjLmGXlPZVIx3FR9lKukmWmQgFAnT1ZcY0Yn1QetZQ2q3L9GHoQwph1eX2OFEaHpEbQw8DB2z 7fLoD1coFKFdV2CJd6elbo7EQyAzoNvgxbAbg4RGVf5antS7sJgOumW63g1eAjM6ghYtczQYW8t YQfGZ9zS4hYld4wcSQPYugKgrVdOIoIhy2JumPdXNK81+GoxRZxR8vYU7VRZzS0lOv2wXaJBK/S xKFL8+2bDe7ELYg== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D X-Patchwork-Delegate: kuba@kernel.org Rename "userdata" to "extradata" since this structure will hold both user and system data in future patches. Keep "userdata" term only for data that comes from userspace (configfs), while "extradata" encompasses both userdata and future kerneldata. These are the rules of the design 1. extradata_complete will hold userdata and sysdata (coming) 2. sysdata will come after userdata_length 3. extradata_complete[userdata_length] string will be replaced at every message 5. userdata is replaced when configfs changes (update_userdata()) 6. sysdata is replaced at every message Example: extradata_complete = "userkey=uservalue cpu=42" userdata_length = 17 sysdata_length = 7 (space (" ") is part of sysdata) Since sysdata is still not available, you will see the following in the send functions: extradata_len = nt->userdata_length; The upcoming patches will, which will add support for sysdata, will change it to: extradata_len = nt->userdata_length + sysdata_len; Signed-off-by: Breno Leitao --- drivers/net/netconsole.c | 84 ++++++++++++++++++++++++------------------------ 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index 86ab4a42769a49eebe5dd6f01dafafc6c86ec54f..5ef069e8277efa87d6f00d08277dcfe97a858cf9 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -45,12 +45,12 @@ MODULE_DESCRIPTION("Console driver for network interfaces"); MODULE_LICENSE("GPL"); #define MAX_PARAM_LENGTH 256 -#define MAX_USERDATA_ENTRY_LENGTH 256 -#define MAX_USERDATA_VALUE_LENGTH 200 +#define MAX_EXTRADATA_ENTRY_LEN 256 +#define MAX_EXTRADATA_VALUE_LEN 200 /* The number 3 comes from userdata entry format characters (' ', '=', '\n') */ -#define MAX_USERDATA_NAME_LENGTH (MAX_USERDATA_ENTRY_LENGTH - \ - MAX_USERDATA_VALUE_LENGTH - 3) -#define MAX_USERDATA_ITEMS 16 +#define MAX_EXTRADATA_NAME_LEN (MAX_EXTRADATA_ENTRY_LEN - \ + MAX_EXTRADATA_VALUE_LEN - 3) +#define MAX_EXTRADATA_ITEMS 16 #define MAX_PRINT_CHUNK 1000 static char config[MAX_PARAM_LENGTH]; @@ -102,8 +102,8 @@ struct netconsole_target_stats { * @list: Links this target into the target_list. * @group: Links us into the configfs subsystem hierarchy. * @userdata_group: Links to the userdata configfs hierarchy - * @userdata_complete: Cached, formatted string of append - * @userdata_length: String length of userdata_complete + * @extradata_complete: Cached, formatted string of append + * @userdata_length: String length of usedata in extradata_complete. * @stats: Packet send stats for the target. Used for debugging. * @enabled: On / off knob to enable / disable target. * Visible from userspace (read-write). @@ -129,7 +129,7 @@ struct netconsole_target { #ifdef CONFIG_NETCONSOLE_DYNAMIC struct config_group group; struct config_group userdata_group; - char userdata_complete[MAX_USERDATA_ENTRY_LENGTH * MAX_USERDATA_ITEMS]; + char extradata_complete[MAX_EXTRADATA_ENTRY_LEN * MAX_EXTRADATA_ITEMS]; size_t userdata_length; #endif struct netconsole_target_stats stats; @@ -687,7 +687,7 @@ static ssize_t remote_mac_store(struct config_item *item, const char *buf, struct userdatum { struct config_item item; - char value[MAX_USERDATA_VALUE_LENGTH]; + char value[MAX_EXTRADATA_VALUE_LEN]; }; static struct userdatum *to_userdatum(struct config_item *item) @@ -724,13 +724,13 @@ static void update_userdata(struct netconsole_target *nt) /* Clear the current string in case the last userdatum was deleted */ nt->userdata_length = 0; - nt->userdata_complete[0] = 0; + nt->extradata_complete[0] = 0; list_for_each(entry, &nt->userdata_group.cg_children) { struct userdatum *udm_item; struct config_item *item; - if (WARN_ON_ONCE(child_count >= MAX_USERDATA_ITEMS)) + if (WARN_ON_ONCE(child_count >= MAX_EXTRADATA_ITEMS)) break; child_count++; @@ -738,19 +738,19 @@ static void update_userdata(struct netconsole_target *nt) udm_item = to_userdatum(item); /* Skip userdata with no value set */ - if (strnlen(udm_item->value, MAX_USERDATA_VALUE_LENGTH) == 0) + if (strnlen(udm_item->value, MAX_EXTRADATA_VALUE_LEN) == 0) continue; - /* This doesn't overflow userdata_complete since it will write - * one entry length (1/MAX_USERDATA_ITEMS long), entry count is + /* This doesn't overflow extradata_complete since it will write + * one entry length (1/MAX_EXTRADATA_ITEMS long), entry count is * checked to not exceed MAX items with child_count above */ - complete_idx += scnprintf(&nt->userdata_complete[complete_idx], - MAX_USERDATA_ENTRY_LENGTH, " %s=%s\n", + complete_idx += scnprintf(&nt->extradata_complete[complete_idx], + MAX_EXTRADATA_ENTRY_LEN, " %s=%s\n", item->ci_name, udm_item->value); } - nt->userdata_length = strnlen(nt->userdata_complete, - sizeof(nt->userdata_complete)); + nt->userdata_length = strnlen(nt->extradata_complete, + sizeof(nt->extradata_complete)); } static ssize_t userdatum_value_store(struct config_item *item, const char *buf, @@ -761,7 +761,7 @@ static ssize_t userdatum_value_store(struct config_item *item, const char *buf, struct userdata *ud; ssize_t ret; - if (count > MAX_USERDATA_VALUE_LENGTH) + if (count > MAX_EXTRADATA_VALUE_LEN) return -EMSGSIZE; mutex_lock(&dynamic_netconsole_mutex); @@ -810,13 +810,13 @@ static struct config_item *userdatum_make_item(struct config_group *group, struct userdata *ud; size_t child_count; - if (strlen(name) > MAX_USERDATA_NAME_LENGTH) + if (strlen(name) > MAX_EXTRADATA_NAME_LEN) return ERR_PTR(-ENAMETOOLONG); ud = to_userdata(&group->cg_item); nt = userdata_to_target(ud); child_count = list_count_nodes(&nt->userdata_group.cg_children); - if (child_count >= MAX_USERDATA_ITEMS) + if (child_count >= MAX_EXTRADATA_ITEMS) return ERR_PTR(-ENOSPC); udm = kzalloc(sizeof(*udm), GFP_KERNEL); @@ -1118,11 +1118,11 @@ static void send_msg_no_fragmentation(struct netconsole_target *nt, int release_len) { static char buf[MAX_PRINT_CHUNK]; /* protected by target_list_lock */ - const char *userdata = NULL; + const char *extradata = NULL; const char *release; #ifdef CONFIG_NETCONSOLE_DYNAMIC - userdata = nt->userdata_complete; + extradata = nt->extradata_complete; #endif if (release_len) { @@ -1134,10 +1134,10 @@ static void send_msg_no_fragmentation(struct netconsole_target *nt, memcpy(buf, msg, msg_len); } - if (userdata) + if (extradata) msg_len += scnprintf(&buf[msg_len], MAX_PRINT_CHUNK - msg_len, - "%s", userdata); + "%s", extradata); send_udp(nt, buf, msg_len); } @@ -1154,24 +1154,24 @@ static void send_fragmented_body(struct netconsole_target *nt, char *buf, const char *msgbody, int header_len, int msgbody_len) { - const char *userdata = NULL; + const char *extradata = NULL; int body_len, offset = 0; - int userdata_len = 0; + int extradata_len = 0; #ifdef CONFIG_NETCONSOLE_DYNAMIC - userdata = nt->userdata_complete; - userdata_len = nt->userdata_length; + extradata = nt->extradata_complete; + extradata_len = nt->userdata_length; #endif /* body_len represents the number of bytes that will be sent. This is * bigger than MAX_PRINT_CHUNK, thus, it will be split in multiple * packets */ - body_len = msgbody_len + userdata_len; + body_len = msgbody_len + extradata_len; /* In each iteration of the while loop below, we send a packet * containing the header and a portion of the body. The body is - * composed of two parts: msgbody and userdata. We keep track of how + * composed of two parts: msgbody and extradata. We keep track of how * many bytes have been sent so far using the offset variable, which * ranges from 0 to the total length of the body. */ @@ -1198,36 +1198,36 @@ static void send_fragmented_body(struct netconsole_target *nt, char *buf, /* msgbody was finally written, either in the previous * messages and/or in the current buf. Time to write - * the userdata. + * the extradata. */ msgbody_written |= offset + this_offset >= msgbody_len; - /* Msg body is fully written and there is pending userdata to - * write, append userdata in this chunk + /* Msg body is fully written and there is pending extradata to + * write, append extradata in this chunk */ if (msgbody_written && offset + this_offset < body_len) { /* Track how much user data was already sent. First * time here, sent_userdata is zero */ - int sent_userdata = (offset + this_offset) - msgbody_len; + int sent_extradata = (offset + this_offset) - msgbody_len; /* offset of bytes used in current buf */ int preceding_bytes = this_chunk + this_header; - if (WARN_ON_ONCE(sent_userdata < 0)) + if (WARN_ON_ONCE(sent_extradata < 0)) return; - this_chunk = min(userdata_len - sent_userdata, + this_chunk = min(extradata_len - sent_extradata, MAX_PRINT_CHUNK - preceding_bytes); if (WARN_ON_ONCE(this_chunk < 0)) /* this_chunk could be zero if all the previous * message used all the buffer. This is not a - * problem, userdata will be sent in the next + * problem, extradata will be sent in the next * iteration */ return; memcpy(buf + this_header + this_offset, - userdata + sent_userdata, + extradata + sent_extradata, this_chunk); this_offset += this_chunk; } @@ -1285,17 +1285,17 @@ 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 userdata_len = 0; + int extradata_len = 0; int release_len = 0; #ifdef CONFIG_NETCONSOLE_DYNAMIC - userdata_len = nt->userdata_length; + extradata_len = nt->userdata_length; #endif if (nt->release) release_len = strlen(init_utsname()->release) + 1; - if (msg_len + release_len + userdata_len <= MAX_PRINT_CHUNK) + 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); From patchwork Wed Jan 15 13:35:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13940454 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f47.google.com (mail-ed1-f47.google.com [209.85.208.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3FA57242250; Wed, 15 Jan 2025 13:35:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736948141; cv=none; b=FAraTJvpBbJ51E69zX/r+mtSdwCdRQo0yPN4TJWrteQy3sSNnsTkHMh9HyPRJVQ3gvLJ5T11AjsQXR405aTmWMZSH9HR1bWCgSpWMAN0fplNrf6MCgZjVTFGHoDe1+Opn5hojlTH0M5TafUd8phF+WyrlkdyygfVWG/J6JYRh+s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736948141; c=relaxed/simple; bh=+5zPit+6w4Q87PebYLLQqICHMl8W7vM3JOE4biu2VRY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=rXKu8/NVgNX0iu0ErBrTqVBl/zq/9tb1HHXjyEF9IXztavphxN3rCiVXv5Z1LkaRhrDavSumOT3lgsUrdLPg4JNW6lhY1I9F3j8k1eW5SESnQZWyYXrZSaDmmTGPPfg+h+OtSGYMBUDm2oZYj2QXdWjvYOFN1YXZwyr08Fu349I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.208.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-f47.google.com with SMTP id 4fb4d7f45d1cf-5da135d3162so912675a12.3; Wed, 15 Jan 2025 05:35:38 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736948137; x=1737552937; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ec7/MpEi/atSJrAfxhBY2CBnYVqA9MsTtmzPCtszyDs=; b=b7rrZJWBjygi8FLdDMuuw0xm3JgetqvX5P2rMHi5l4mBcImpOl/Xnp1+Le8vMYPChs n9r3LLUbPfVJDyW2/z7ho3sj3/5ww19qtoF8i76gw1z4Hr/QWm6ZMz1RB9d/zxh4M2OL xgANfsuCQMkYAFkR3KUlj8tRDjDYB84JjijSMx6U9XzvGBm/kWTYvfgJicZwXhc+jefy awhZ+RT7Xkn31N4NY1vCQG4g4A/RDvwsGL7ig1w5tvhTGcRpW+NxOabk45PWFzLEt95e drrMl7HtmWgnXIBfZ4yheFJC7izFMG7M37K/tqMTvbhBcXUZNKWR50WmSNBbFrRTpBMz Cm3Q== X-Forwarded-Encrypted: i=1; AJvYcCUKntCjvsBYSvigdZuUjd5kg7s3k+3KLNBOo66i8jv/5EsKIRjhEen3uk5qF1NdCmE025oXGrj9Yeqi4HEBeJ6R@vger.kernel.org, AJvYcCUmDzX1FbSZeaDpf9fAHi0MRDcnSF7GxzJaUaK9ZtZLx5dSBH8CSts40x/bLh2iyhG4ZKriN5OzUKdp5jo1@vger.kernel.org, AJvYcCXrclpNq6eV/KUq/JBjeKdvR2GoVYL7do65o/Vzeg0HCQQvv9ZEDWBZymE8OcYQvkKZLRplYObwXXc=@vger.kernel.org X-Gm-Message-State: AOJu0Yxia6Bi53oq4JxtNfurH22ZsrY82IBlAr+fADi8FvmkpyB5l56U E8U2YXnZHAkcoc+plAKFvpFt52Yj0cFFj6Rnzcve2DcAv3+MPEXm X-Gm-Gg: ASbGncvPEAlQuKid4O6XxMGu2ndHig7R4s+LjvKCI5ckd/yGaKb217qUN2vLua9Mvp2 G2IDmtrSQCc6og+//FK4nyCuqc0LbnHI5yB3KJU0xUNKRhWJkMmIefNzWEhvDH5CccBcQd/I3Rf ZyUcqZ5Zhmdh+YMGMjUMTDYeeoHO4oBOBYgpX4ZIBuPaUMWjZB5qTFDkmrMrsBdfODAoe3ZrTOg +pLNvfo5stsaR63J+Ipx7Q0I9on9fW+5Dr+Df/L3wpkAeU= X-Google-Smtp-Source: AGHT+IH09HBaE5F9R+1j7gXj0uFhR8rhyxsE5IJFKPryqtPDjj7EmdMPOhto+lldRrb+zhknk2Yo9A== X-Received: by 2002:a17:906:d555:b0:aa6:7b34:c1a8 with SMTP id a640c23a62f3a-ab2ab70a5a8mr2744648966b.55.1736948137238; Wed, 15 Jan 2025 05:35:37 -0800 (PST) Received: from localhost ([2a03:2880:30ff:3::]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab2c906200dsm756580566b.40.2025.01.15.05.35.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jan 2025 05:35:36 -0800 (PST) From: Breno Leitao Date: Wed, 15 Jan 2025 05:35:19 -0800 Subject: [PATCH net-next v2 2/5] netconsole: Helper to count number of used entries Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250115-netcon_cpu-v2-2-95971b44dc56@debian.org> References: <20250115-netcon_cpu-v2-0-95971b44dc56@debian.org> In-Reply-To: <20250115-netcon_cpu-v2-0-95971b44dc56@debian.org> To: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Jonathan Corbet , Shuah Khan Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, Breno Leitao , kernel-team@meta.com, max@kutsevol.com, thepacketgeek@gmail.com X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1997; i=leitao@debian.org; h=from:subject:message-id; bh=+5zPit+6w4Q87PebYLLQqICHMl8W7vM3JOE4biu2VRY=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBnh7mjq51PJL8Ycf9UXn9bXWsFHJY2bHIhz8/j6 yD2bPtiDH+JAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCZ4e5owAKCRA1o5Of/Hh3 bWkuD/sEih3WhwQkHz5ZBfOd+xWT6WuuCHltCtJPb69SIob1kvyXGrh3WRYEUruuP1BzvglbWws OPX+xu2mG3AS+LzWQ9O7thr7/MMUilEKfMCfMe/v2u69awx+wdNNDKpJVg8iigcH7vJuF6bskOC yjuLvNQk54JiWQ2IRNKAbfQPXRiNkR9abgzWvTW8P7V4G2KeZ/4uHYuJtihJSLBDScZbHvsdhKC uFc2hAkgczwPGSf7GqIve+4vL0Z1b8e44fXUDlRz42BHwO7ua7klFPE1yO+uU1Iy23/45JRRxPW FHe4cUDrgg3Mq7VDac3dxKjSnlIx3/Xi+4bkCu8djGIqcD1+w/tEePh6xV53pk8gqVR9fA1hOmG GIrN8BwOjCa9StFMUF+DlTX67zcCgOyTruvzPUFAct5N52BoQg5/db3AFQUo4A7WI164WblqedS 8AbWCSpFXJmXmlxkEbWzaS0Q1x35j686AUlJMF4y8GhzNWW9GU+QfcZtDvSPSv9ToOweJflJWJZ vWeCH+oCT6ygA3zEahgTmEyFproaXvqqeixhQLIuW/8ri71eG7wxxHsXI0gus6LI4qjKNs3dEAB m3HXfVw2skRe3nRH1QFZvLbC9rgbGaps/SUzre0M6PiWBS36v3Qxk7mykzLqVHLVkJUnGEqBh+f r4UA61CyiU8hsOA== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D X-Patchwork-Delegate: kuba@kernel.org Add a helper function nr_extradata_entries() to count the number of used extradata entries in a netconsole target. This refactors the duplicate code for counting entries into a single function, which will be reused by upcoming CPU sysdata changes. The helper uses list_count_nodes() to count the number of children in the userdata group configfs hierarchy. Signed-off-by: Breno Leitao --- drivers/net/netconsole.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index 5ef069e8277efa87d6f00d08277dcfe97a858cf9..108ec4f836b62860832c601768546c0ecbdb1153 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -659,6 +659,16 @@ static ssize_t remote_ip_store(struct config_item *item, const char *buf, return ret; } +/* Count number of entries we have in extradata. + * This is important because the extradata_complete only supports + * MAX_EXTRADATA_ITEMS entries. Before enabling any new {user,sys}data + * feature, number of entries needs to checked for available space. + */ +static size_t count_extradata_entries(struct netconsole_target *nt) +{ + return list_count_nodes(&nt->userdata_group.cg_children); +} + static ssize_t remote_mac_store(struct config_item *item, const char *buf, size_t count) { @@ -808,15 +818,13 @@ static struct config_item *userdatum_make_item(struct config_group *group, struct netconsole_target *nt; struct userdatum *udm; struct userdata *ud; - size_t child_count; if (strlen(name) > MAX_EXTRADATA_NAME_LEN) return ERR_PTR(-ENAMETOOLONG); ud = to_userdata(&group->cg_item); nt = userdata_to_target(ud); - child_count = list_count_nodes(&nt->userdata_group.cg_children); - if (child_count >= MAX_EXTRADATA_ITEMS) + if (count_extradata_entries(nt) >= MAX_EXTRADATA_ITEMS) return ERR_PTR(-ENOSPC); udm = kzalloc(sizeof(*udm), GFP_KERNEL); From patchwork Wed Jan 15 13:35:20 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13940455 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ej1-f48.google.com (mail-ej1-f48.google.com [209.85.218.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C127C243845; Wed, 15 Jan 2025 13:35:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736948143; cv=none; b=DrLHXtJ7iaIS7urW08W890nbGFpxZHJZeb60GGIo/ctctJ/vj/ILr8vrj1z4Occ/YAqh5+N5j465GN2+ddbmSoZt16Ho3Lfg7rpVVH44Nknc/dlwoiMK495bnzmSSoYrUow9DYX0KG9TVVpFPIHQp+Lq27xuRW6J2xw5ow/liW0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736948143; c=relaxed/simple; bh=zGKQnOePCXNnK2ujFJnG9eBNvBf38hWpuFyKGZ6MIqY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=WcGAthzXJNEv3Wk2ALt7Rsjf4+Veu2/9eHJe+WDBNtLx575mW7dhPwFSLlH+aq3v+7E8aRP0msSoP320Mcwoc+IX9Yy68xvityTk+d7JfCIjKMBcbmxLKkKU7OiDDgCcMO8kgKWuIA/8FMzjWR//1+2LQAnm33yzuprJws2vOfI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f48.google.com with SMTP id a640c23a62f3a-aaf6b1a5f2bso176284266b.1; Wed, 15 Jan 2025 05:35:40 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736948139; x=1737552939; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=N+TRFdUSlvt3nSzhQ5Uy/fXS/5eMuJmBJc92CYoce4k=; b=JaC2LaUZ6pgbVWJ2j5weA+Pke6hUAzhnz4XQSAKpI4GmXQSoMQoBDRXG5vP1f6/UjZ k72+RgeqhCyUifZgeg32rp9bw8YxptvYFcShoEhp3KTpI7KKrANpQG+EI3DUMV77EetV Yo3gZ3PN6EuNPNmSySNn4SLs7/oQ4ALNPT6rqqqKRRKN83wDr3wtxrzuE3I5jJVIojYF dNzUxYQaIH8QgHmCpFoiUC8OfHcMkYJpw8A6pqFvWpmESfrNku4qpQM5BzJPjzlz8sq3 qLdxGGeAFwFlfJoVhZT7GN2L0sGcY5giVMKMjMbYjggaaOUhsk4c++9WjS6HJ6jcDH6g 3lnw== X-Forwarded-Encrypted: i=1; AJvYcCUWji81Mn6Ul+gNKxH373yOZp5/JobLpZns149J1MsNrsktlY4CgIfZKagx8nBCm6RshqJOfrP1vN4uBZ7i@vger.kernel.org, AJvYcCVkKrRYE+V5maaIOq17Z17IGNKIGH+zgjG16AdCdFFdrzlgMQ+wR35IJZUOn2Aurpxnhd4Laf1R+XjNVm5AVLVg@vger.kernel.org, AJvYcCXwcfQ6QTFktFeJshus+Pi3uQxgQ0v/Obe4OAy4n3aSmn0kxSbYeUKMGBiNbKCj+jYtxYOonp7ftR0=@vger.kernel.org X-Gm-Message-State: AOJu0YwVtbhS+NgxB31hCNzDnTI+O3l7JGbz9ZwJP8qziGic4HxpY+6U OiwR2yXcb0V1/PvYzXLa7K4JowCAftOk6lL1Fqt1dfeQKTFHN/pzwEa4SQ== X-Gm-Gg: ASbGncuGKvN9Gsp11Go3q4bahxlUO3t0fpBNM+j9uXud/kKeGTYfyqKoqz0tW/LkHZ+ 0gayFEoBz1AZNIXe9OXKBC+d/R8Tpjkgevoz6tKEDbcymnb3H0xFtKzaGhMAW0VP6sK3EVSXZzG Hg+UQYohx0EgO/4GseXMDYGuuYx2qmUoO9A2t+CTTCszWZGVscfRm2F6zum+jfupCt4Be2WA4JO Gc2fKEQH8EbyPKf49VTsbSH2j6pCdZIPtgk9/zn9hEFyLo= X-Google-Smtp-Source: AGHT+IGervku6gALvYqjlFtTDOMMJ3EL5hGs4iGmf8CmlSrkSwlNt97sYb+GEdPUk5c+zg56oqeD6Q== X-Received: by 2002:a17:907:7282:b0:a9a:6c41:50a8 with SMTP id a640c23a62f3a-ab2c3c79cf5mr2294578966b.17.1736948138826; Wed, 15 Jan 2025 05:35:38 -0800 (PST) Received: from localhost ([2a03:2880:30ff:9::]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab2c906200dsm756582666b.40.2025.01.15.05.35.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jan 2025 05:35:38 -0800 (PST) From: Breno Leitao Date: Wed, 15 Jan 2025 05:35:20 -0800 Subject: [PATCH net-next v2 3/5] netconsole: add support for sysdata and CPU population Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250115-netcon_cpu-v2-3-95971b44dc56@debian.org> References: <20250115-netcon_cpu-v2-0-95971b44dc56@debian.org> In-Reply-To: <20250115-netcon_cpu-v2-0-95971b44dc56@debian.org> To: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Jonathan Corbet , Shuah Khan Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, Breno Leitao , kernel-team@meta.com, max@kutsevol.com, thepacketgeek@gmail.com X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=7758; i=leitao@debian.org; h=from:subject:message-id; bh=zGKQnOePCXNnK2ujFJnG9eBNvBf38hWpuFyKGZ6MIqY=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBnh7mjKcrs721+URaAHjhCOYEErnoTQN/9CMR1Z CIMWWGb116JAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCZ4e5owAKCRA1o5Of/Hh3 bW83D/93fIxXz5O5vE0EkqwHKgMlp0mMD6NoSAulr9H9juei42e3nM4yyhECsJpNAzwAkrvet/u F7r3bKmARuwtPaUGRtRXL40bolOK1SVjM5ouWsxT8/U4JrvQk7PZh6LYFcCz8uxZuhMFM7ayHFW DaLf5YU5Qb4CXooo5jUlSj2VTwJgcSUbm1yxL1jhAcJ56BvgE00eL/rwck4fsdm5drRceTbcBQX dj90OS5KFrCGygx6XIqUq+mBx/tMzXCGK0zNMEdhC7X+zLBMTfklu81o0lffoNgZGCVS+ODOpUw PXO6RZjHa6TNEjUd1d2WR8e1OwUXdmItXJK0Cd6zh7/tdJ10wzy8PoLpjd9/f8afI3D0PMTbRjQ xnK4iokOQXSqc1jQdQF/IKKjvDxMTpArr4JOT0pnD4RsiZq8g5CYKnraLZfcSG9XU2FNJGYFLbN nAaAGVr9O48chyNctROhzQvkITyTfmtwj+38m+AbfH5CygGqio8dzms7MfysIZ3jZAJQXyBweIN zquUCPF0H67F+PDAN8Dw0KoMbaQkHNdGWU+jBQ4HA/mT6r9qYq4AfnyC0XYbaDmp0J77mxYqMHw Y15jsvUq9EOSPY0kpl28FjBzwrAfGWa6pT707ZvZZtcpL9RXXtLtAiUPW/IWTCmGYEpYjfme7jF K7KWx0g3gUMHqOQ== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D X-Patchwork-Delegate: kuba@kernel.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 --- drivers/net/netconsole.c | 131 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 128 insertions(+), 3 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index 108ec4f836b62860832c601768546c0ecbdb1153..d89b4ef23965ac0a25090d0a1e461de4e56c5fa7 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -97,6 +97,15 @@ struct netconsole_target_stats { struct u64_stats_sync syncp; }; +/* Features enabled in sysdata. Contrary to userdata, this data is populated by + * the kernel. The fields are designed as bitwise flags, allowing multiple + * features to be set in sysdata_fields. + */ +enum sysdata_feature { + /* Populate the CPU that sends the message */ + CPU_NR = BIT(0), +}; + /** * struct netconsole_target - Represents a configured netconsole target. * @list: Links this target into the target_list. @@ -104,6 +113,8 @@ struct netconsole_target_stats { * @userdata_group: Links to the userdata configfs hierarchy * @extradata_complete: Cached, formatted string of append * @userdata_length: String length of usedata in extradata_complete. + * @sysdata_length: String length of sysdata in extradata_complete. + * @sysdata_fields: Sysdata features enabled. * @stats: Packet send stats for the target. Used for debugging. * @enabled: On / off knob to enable / disable target. * Visible from userspace (read-write). @@ -130,7 +141,9 @@ struct netconsole_target { struct config_group group; struct config_group userdata_group; char extradata_complete[MAX_EXTRADATA_ENTRY_LEN * MAX_EXTRADATA_ITEMS]; - size_t userdata_length; + size_t userdata_length; /* updated at update_userdata() */ + size_t sysdata_length; /* updated at every message */ + u32 sysdata_fields; /* bit-wise with sysdata_feature bits */ #endif struct netconsole_target_stats stats; bool enabled; @@ -396,6 +409,19 @@ static ssize_t transmit_errors_show(struct config_item *item, char *buf) return sysfs_emit(buf, "%llu\n", xmit_drop_count + enomem_count); } +/* configfs helper to display if cpu_nr sysdata feature is enabled */ +static ssize_t sysdata_cpu_nr_show(struct config_item *item, char *buf) +{ + struct netconsole_target *nt = to_target(item->ci_parent); + bool cpu_nr_enabled; + + mutex_lock(&dynamic_netconsole_mutex); + cpu_nr_enabled = nt->sysdata_fields & CPU_NR; + mutex_unlock(&dynamic_netconsole_mutex); + + return sysfs_emit(buf, "%d\n", cpu_nr_enabled); +} + /* * This one is special -- targets created through the configfs interface * are not enabled (and the corresponding netpoll activated) by default. @@ -666,7 +692,15 @@ static ssize_t remote_ip_store(struct config_item *item, const char *buf, */ static size_t count_extradata_entries(struct netconsole_target *nt) { - return list_count_nodes(&nt->userdata_group.cg_children); + size_t entries; + + /* Userdata entries */ + entries = list_count_nodes(&nt->userdata_group.cg_children); + /* Plus sysdata entries */ + if (nt->sysdata_fields & CPU_NR) + entries += 1; + + return entries; } static ssize_t remote_mac_store(struct config_item *item, const char *buf, @@ -790,7 +824,67 @@ static ssize_t userdatum_value_store(struct config_item *item, const char *buf, return ret; } +/* disable_sysdata_feature - Disable sysdata feature and clean sysdata + * @nt: target that is diabling the feature + * @feature: feature being disabled + */ +static void disable_sysdata_feature(struct netconsole_target *nt, + enum sysdata_feature feature) +{ + nt->sysdata_fields &= ~feature; + nt->sysdata_length = 0; + /* extradata_complete might have sysdata appended after + * userdata. Clean everything, and it will be re-appened + * when a new message is sent. + */ + nt->extradata_complete[nt->userdata_length] = 0; +} + +/* configfs helper to sysdata cpu_nr feature */ +static ssize_t sysdata_cpu_nr_store(struct config_item *item, const char *buf, + size_t count) +{ + struct netconsole_target *nt = to_target(item->ci_parent); + bool cpu_nr_enabled, curr; + ssize_t ret; + + ret = kstrtobool(buf, &cpu_nr_enabled); + if (ret) + return ret; + + mutex_lock(&dynamic_netconsole_mutex); + curr = nt->sysdata_fields & CPU_NR; + if (cpu_nr_enabled == curr) + /* no change requested */ + goto unlock_ok; + + if (cpu_nr_enabled && + count_extradata_entries(nt) >= MAX_EXTRADATA_ITEMS) { + /* user wants the new feature, but there is no space in the + * buffer. + */ + ret = -ENOSPC; + goto unlock; + } + + if (cpu_nr_enabled) + nt->sysdata_fields |= CPU_NR; + else + /* This is special because extradata_complete might have + * remaining data from previous sysdata, and it needs to be + * cleaned. + */ + disable_sysdata_feature(nt, CPU_NR); + +unlock_ok: + ret = strnlen(buf, count); +unlock: + mutex_unlock(&dynamic_netconsole_mutex); + return ret; +} + CONFIGFS_ATTR(userdatum_, value); +CONFIGFS_ATTR(sysdata_, cpu_nr); static struct configfs_attribute *userdatum_attrs[] = { &userdatum_attr_value, @@ -850,6 +944,7 @@ static void userdatum_drop(struct config_group *group, struct config_item *item) } static struct configfs_attribute *userdata_attrs[] = { + &sysdata_attr_cpu_nr, NULL, }; @@ -1025,6 +1120,35 @@ static void populate_configfs_item(struct netconsole_target *nt, init_target_config_group(nt, target_name); } +/* + * append_runtime_sysdata - append sysdata at extradata_complete in runtime + * @nt: target to send message to + */ +static void append_runtime_sysdata(struct netconsole_target *nt) +{ + size_t userdata_len = nt->userdata_length; + size_t sysdata_len; + + if (!(nt->sysdata_fields & CPU_NR)) + return; + + /* Append cpu=%d at extradata_complete after userdata str */ + sysdata_len = scnprintf(&nt->extradata_complete[userdata_len], + MAX_EXTRADATA_ENTRY_LEN, " cpu=%u\n", + raw_smp_processor_id()); + + WARN_ON_ONCE(userdata_len + sysdata_len > + MAX_EXTRADATA_ENTRY_LEN * MAX_EXTRADATA_ITEMS); + + /* nt->sysdata_length will be used later to decide if the message + * needs to be fragmented. + * userdata_len cannot be used for it, once next sysdata append should + * start from the same userdata_len location, and only overwrite old + * sysdata. + */ + nt->sysdata_length = sysdata_len; +} + #endif /* CONFIG_NETCONSOLE_DYNAMIC */ /* Handle network interface device notifications */ @@ -1297,7 +1421,8 @@ static void send_ext_msg_udp(struct netconsole_target *nt, const char *msg, int release_len = 0; #ifdef CONFIG_NETCONSOLE_DYNAMIC - extradata_len = nt->userdata_length; + append_runtime_sysdata(nt); + extradata_len = nt->userdata_length + nt->sysdata_length; #endif if (nt->release) From patchwork Wed Jan 15 13:35:21 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13940456 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ej1-f44.google.com (mail-ej1-f44.google.com [209.85.218.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 43178243873; Wed, 15 Jan 2025 13:35:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736948145; cv=none; b=GI7YD2SfRpoSKq2L8fAanCZzYVzhAJwbg/s1nMwI7QsrZnXfoHs3TKmn0bg3GGkb979ksE22qlI9CFQzm7X+QlUsf3qn8FOKmHXsYKi4f6fAzTrUBHviYbV8uDLkJnL/3G/fOOva12dLGm7sRoNnENiocZqTyOfL1j3yxtjmp68= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736948145; c=relaxed/simple; bh=b+K5dYQ+pmuYTcPApzLrUA47uxeMEoTKA+hWTz6q5n8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=JOzdw22Ep3nBwkkyhqLelIPqIjrKo+hqO/03HKHRqyQicblsKvvZclg1irYFWehrF/sZzbIZrhxSEd7kfApfhDEwfagtIV5kpcy4RZXqd8M4WMHNOJrbcZXFkhfPpxiV1WJ1s7vKMqCz+QMg0Ej8SDE1s8QaxdVm1WG9yFE0TqY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f44.google.com with SMTP id a640c23a62f3a-aa684b6d9c7so1191266966b.2; Wed, 15 Jan 2025 05:35:42 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736948141; x=1737552941; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BIJ/Ae1RdlG6JrQhyaZytF06+/sw79PkUaiZw46sYlk=; b=sVlJZvE5a4R02Tese0hpQ3Rv23siz/pT/uX/coczVaz++4aoYQMaS2WkYtsT8/DAVJ UUrifSPxwnBTBOdNpijH08Z0LuNa6KhTaXmobYl6sfv7uvP2f/etHrN340Us7zP8cb0K 7oc/2TnsOyNFFElt2OlrIK04I6ZsAiSZAkL/yCz41Pz9fxNZWmN+S08dYp0+Wb2n19Uv xvq5wizdE07216pIeEQXW3l/6Bb11A/ehBAoTM96tYEy5kvzBfp/JwERJlSG4F04usI3 j9BV21jlrkD7oE1oszCnzqnj1M6gsgxMZ7R7WbvtdnMgnIuWk5hVOG8zgSHEV2RqJ5Bj siwQ== X-Forwarded-Encrypted: i=1; AJvYcCVccA7dvWmjQo/WvuuSAbnDOB/UqufL1DgPUcDWWBP98Y71geNRENQnF9GqUL+DeCbjTWMRkmypkpU=@vger.kernel.org, AJvYcCXKCtqDNcDREvHGhHO+EmpqqotD7jaTMQtmrjS4fdkh1Aar45xmDnbR0gLwXlbdYGGb3q9s7/+zymtGWsIJE2vV@vger.kernel.org, AJvYcCXL6DMsnEkn9izPAKKVfcNxyF/JQsm7KuumEa8FY3i8sqM5PIRg6CItGwMHQ7iK+9fX8azuBQW2j3VZ0gvV@vger.kernel.org X-Gm-Message-State: AOJu0Yw/je0JWaVr/lG5F+r15JYONecd/4QFzb1b5p7+uxZL4E655Ho1 EiRZFOG/1kbRTF/rXaRKzV3wm5hl5RSfrmHqc2vHnrGttXzQRhuC X-Gm-Gg: ASbGncuQaQ0m9k25QlMm21TCEtkZtcQ6qGDLX7bfYQ0lrITe7yVISSsyLwXggE3KFFf tXvChk2QJgQ/dMOJ9kkWCkdthDNrUIlH8ocBlR+mzGkNclRJxGYZlsQCZ3BhfWx4REExMXSfPfY if4s6lxzmSrd6cf1L6y6yEW4+Mh7mOccy4QY2SqabqgmMkEIkqfvGztkvxgWEX42MhSB7OrLS5D eQKKr7ZU9K+R8vivTw0MxPBT2MmnuwIHq8kGhpjNLES/ag= X-Google-Smtp-Source: AGHT+IHWmX149OPZFUzxJH6FjINlXXn+Ovct4wtUyrUWJzuv/vvc+rFWkA/j1NMhQhUZC43NJjmX8w== X-Received: by 2002:a17:907:36c8:b0:aa6:9fad:3c1d with SMTP id a640c23a62f3a-ab2abc6f5b9mr3058244766b.39.1736948140456; Wed, 15 Jan 2025 05:35:40 -0800 (PST) Received: from localhost ([2a03:2880:30ff:4::]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab2c90dace5sm768149366b.60.2025.01.15.05.35.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jan 2025 05:35:39 -0800 (PST) From: Breno Leitao Date: Wed, 15 Jan 2025 05:35:21 -0800 Subject: [PATCH net-next v2 4/5] netconsole: selftest: test for sysdata CPU Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250115-netcon_cpu-v2-4-95971b44dc56@debian.org> References: <20250115-netcon_cpu-v2-0-95971b44dc56@debian.org> In-Reply-To: <20250115-netcon_cpu-v2-0-95971b44dc56@debian.org> To: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Jonathan Corbet , Shuah Khan Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, Breno Leitao , kernel-team@meta.com, max@kutsevol.com, thepacketgeek@gmail.com X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=7643; i=leitao@debian.org; h=from:subject:message-id; bh=b+K5dYQ+pmuYTcPApzLrUA47uxeMEoTKA+hWTz6q5n8=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBnh7mj1jUj3LrDhaMO/QWuT2Ms/91J4Z0Yo0oe8 HLuqWvWbhKJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCZ4e5owAKCRA1o5Of/Hh3 bejTD/4vRK7FTsBBocrdm/L09gZ+qFHED4+cR6MxsO5oCHk7ygYhCrNJv/DRlgDOWn0SMdhBJSV 3PaR8CWMSs1TqHmVsk6OI63cb1vNUKO4aJ2PMBkVfhCtFnv/MrgaU6DiFMSY1EN/y1bewJEuAuM V/pR5pymc73CxynpsovXpC5/ZI/Oj8sbokScdN1kzWaAB3yT8peo+O30EoBSYTHsIsqa9IQmPYg BYUQijAruRsUZSEryhZ6fzkORSCgLwOybPHyDnH2R9/X3D6kPKbWy6pmykIgBmhT3naAmST8OCI NImX01TPKexKmvPOdH7CPhsVlePdNxGSTrNTQyb+r5Q54fJhHkbtUj8YVld+gWAl+9nPiM1p9n0 Yu62rS2wnGnUFsmqi8JCYFBPgf0CIOeR1AvP7UXQQAHmWuQnpsitW63xY6wQFdokQeRgBN2Os7P 1nTgADOfGsTiEW3gSMVpCsdCAWZ2trEgG97psefL0rVStuP+u57Y5BbocX51Td1UBy/t10oa37D sOgtvz5VhgPgL906ihmIeOQuytLnrwaHY5HFoV0a1Kq4RZzxnsxulT2gPpQK637zBnms2K+peAO rJRN7pdFSYS9Ivl2WwkwBAAq4AA4LLMEYu07EjvR62Qn1tYgQsaijHeFrWoEoqze8Awa66tXqUa VgwdA5aLpP0UFNg== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D X-Patchwork-Delegate: kuba@kernel.org Add a new selftest to verify that the netconsole module correctly handles CPU runtime data in sysdata. The test validates three scenarios: 1. Basic CPU sysdata functionality - verifies that cpu=X is appended to messages 2. CPU sysdata with userdata - ensures CPU data works alongside userdata 3. Disabled CPU sysdata - confirms no CPU data is included when disabled The test uses taskset to control which CPU sends messages and verifies the reported CPU matches the one used. This helps ensure that netconsole accurately tracks and reports the originating CPU of messages. Signed-off-by: Breno Leitao --- tools/testing/selftests/drivers/net/Makefile | 1 + .../selftests/drivers/net/lib/sh/lib_netcons.sh | 17 +++ .../selftests/drivers/net/netcons_sysdata.sh | 166 +++++++++++++++++++++ 3 files changed, 184 insertions(+) diff --git a/tools/testing/selftests/drivers/net/Makefile b/tools/testing/selftests/drivers/net/Makefile index 469179c18935ffcc12b979ccdc9f84e9d4082b90..1ff5dd076340433ce29bb175b95ba4c6683c2846 100644 --- a/tools/testing/selftests/drivers/net/Makefile +++ b/tools/testing/selftests/drivers/net/Makefile @@ -8,6 +8,7 @@ TEST_INCLUDES := $(wildcard lib/py/*.py) \ TEST_PROGS := \ netcons_basic.sh \ netcons_overflow.sh \ + netcons_sysdata.sh \ ping.py \ queues.py \ stats.py \ diff --git a/tools/testing/selftests/drivers/net/lib/sh/lib_netcons.sh b/tools/testing/selftests/drivers/net/lib/sh/lib_netcons.sh index 3acaba41ac7b21aa2fd8457ed640a5ac8a41bc12..d319d177ce5ed7a1b196e68bffe549d57011fb15 100644 --- a/tools/testing/selftests/drivers/net/lib/sh/lib_netcons.sh +++ b/tools/testing/selftests/drivers/net/lib/sh/lib_netcons.sh @@ -223,3 +223,20 @@ function check_for_dependencies() { exit "${ksft_skip}" fi } + +function check_for_taskset() { + if ! which taskset > /dev/null ; then + echo "SKIP: taskset(1) is not available" >&2 + exit "${ksft_skip}" + fi +} + +# This is necessary if running multiple tests in a row +function pkill_socat() { + PROCESS_NAME="socat UDP-LISTEN:6666,fork ${OUTPUT_FILE}" + # socat runs under timeout(1), kill it if it is still alive + # do not fail if socat doesn't exist anymore + set +e + pkill -f "${PROCESS_NAME}" + set -e +} diff --git a/tools/testing/selftests/drivers/net/netcons_sysdata.sh b/tools/testing/selftests/drivers/net/netcons_sysdata.sh new file mode 100755 index 0000000000000000000000000000000000000000..b569efc07361780c85d64c7ca89c1b4b188945bc --- /dev/null +++ b/tools/testing/selftests/drivers/net/netcons_sysdata.sh @@ -0,0 +1,166 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: GPL-2.0 + +# A test that makes sure that sysdata runtime CPU data is properly set +# when a message is sent. +# +# There are 3 different tests, every time sent using a random CPU. +# - Test #1 +# * Only enable cpu_nr sysdata feature. +# - Test #2 +# * Keep cpu_nr sysdata feature enable and enable userdata. +# - Test #3 +# * keep userdata enabled, and disable sysdata cpu_nr feature. +# +# Author: Breno Leitao + +set -euo pipefail + +SCRIPTDIR=$(dirname "$(readlink -e "${BASH_SOURCE[0]}")") + +source "${SCRIPTDIR}"/lib/sh/lib_netcons.sh + +# Enable the sysdata cpu_nr feature +function set_cpu_nr() { + if [[ ! -f "${NETCONS_PATH}/userdata/cpu_nr" ]] + then + echo "Populate CPU configfs path not available in ${NETCONS_PATH}/userdata/cpu_nr" >&2 + exit "${ksft_skip}" + fi + + echo 1 > "${NETCONS_PATH}/userdata/cpu_nr" +} + +# Disable the sysdata cpu_nr feature +function unset_cpu_nr() { + echo 0 > "${NETCONS_PATH}/userdata/cpu_nr" +} + +# Test if MSG content and `cpu=${CPU}` exists in OUTPUT_FILE +function validate_sysdata_cpu_exists() { + # OUTPUT_FILE will contain something like: + # 6.11.1-0_fbk0_rc13_509_g30d75cea12f7,13,1822,115075213798,-;netconsole selftest: netcons_gtJHM + # userdatakey=userdatavalue + # cpu=X + + if [ ! -f "$OUTPUT_FILE" ]; then + echo "FAIL: File was not generated." >&2 + exit "${ksft_fail}" + fi + + if ! grep -q "${MSG}" "${OUTPUT_FILE}"; then + echo "FAIL: ${MSG} not found in ${OUTPUT_FILE}" >&2 + cat "${OUTPUT_FILE}" >&2 + exit "${ksft_fail}" + fi + + # Check if cpu=XX exists in the file and matches the one used + # in taskset(1) + if ! grep -q "cpu=${CPU}\+" "${OUTPUT_FILE}"; then + echo "FAIL: 'cpu=${CPU}' not found in ${OUTPUT_FILE}" >&2 + cat "${OUTPUT_FILE}" >&2 + exit "${ksft_fail}" + fi + + rm "${OUTPUT_FILE}" + pkill_socat +} + +# Test if MSG content exists in OUTPUT_FILE but no `cpu=` string +function validate_sysdata_no_cpu() { + if [ ! -f "$OUTPUT_FILE" ]; then + echo "FAIL: File was not generated." >&2 + exit "${ksft_fail}" + fi + + if ! grep -q "${MSG}" "${OUTPUT_FILE}"; then + echo "FAIL: ${MSG} not found in ${OUTPUT_FILE}" >&2 + cat "${OUTPUT_FILE}" >&2 + exit "${ksft_fail}" + fi + + if grep -q "cpu=" "${OUTPUT_FILE}"; then + echo "FAIL: 'cpu= found in ${OUTPUT_FILE}" >&2 + cat "${OUTPUT_FILE}" >&2 + exit "${ksft_fail}" + fi + + rm "${OUTPUT_FILE}" +} + +# Start socat, send the message and wait for the file to show up in the file +# system +function runtest { + # Listen for netconsole port inside the namespace and destination interface + listen_port_and_save_to "${OUTPUT_FILE}" & + # Wait for socat to start and listen to the port. + wait_local_port_listen "${NAMESPACE}" "${PORT}" udp + # Send the message + taskset -c "${CPU}" echo "${MSG}: ${TARGET}" > /dev/kmsg + # Wait until socat saves the file to disk + busywait "${BUSYWAIT_TIMEOUT}" test -s "${OUTPUT_FILE}" +} + +# ========== # +# Start here # +# ========== # + +modprobe netdevsim 2> /dev/null || true +modprobe netconsole 2> /dev/null || true + +# Check for basic system dependency and exit if not found +check_for_dependencies +# This test also depends on taskset(1). Check for it before starting the test +check_for_taskset + +# Set current loglevel to KERN_INFO(6), and default to KERN_NOTICE(5) +echo "6 5" > /proc/sys/kernel/printk +# Remove the namespace, interfaces and netconsole target on exit +trap cleanup EXIT +# Create one namespace and two interfaces +set_network +# Create a dynamic target for netconsole +create_dynamic_target + +#==================================================== +# TEST #1 +# Send message from a random CPU +#==================================================== +# Random CPU in the system +CPU=$((RANDOM % $(nproc))) +OUTPUT_FILE="/tmp/${TARGET}_1" +MSG="Test #1 from CPU${CPU}" +# Enable the auto population of cpu_nr +set_cpu_nr +runtest +# Make sure the message was received in the dst part +# and exit +validate_sysdata_cpu_exists + +#==================================================== +# TEST #2 +# This test now adds userdata together with sysdata +# =================================================== +# Get a new random CPU +CPU=$((RANDOM % $(nproc))) +OUTPUT_FILE="/tmp/${TARGET}_2" +MSG="Test #2 from CPU${CPU}" +set_user_data +runtest +validate_sysdata_cpu_exists + +# =================================================== +# TEST #3 +# Unset cpu_nr, so, no CPU should be appended. +# userdata is still set +# =================================================== +CPU=$((RANDOM % $(nproc))) +OUTPUT_FILE="/tmp/${TARGET}_3" +MSG="Test #3 from CPU${CPU}" +# Enable the auto population of cpu_nr +unset_cpu_nr +runtest +# At this time, cpu= shouldn't be present in the msg +validate_sysdata_no_cpu + +exit "${ksft_pass}" From patchwork Wed Jan 15 13:35:22 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13940457 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f54.google.com (mail-ed1-f54.google.com [209.85.208.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 093F02442C9; Wed, 15 Jan 2025 13:35:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736948147; cv=none; b=L3OdYjtYXBtvbJyd6pyycWsTGMwp0HCEbG1gzcl/3KYKBSEeh6+odsxBH3Cx9r64HOjSnTJ9wsmLq8QSdQi1UKwDn12RmCeoz4OISpkJgpSjx5qzhxJ3lST23M0xllSvqXdhJGamYQAylYz+fcnU5WaHLdAHIhXLBUBezTcsD6E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736948147; c=relaxed/simple; bh=0oHhKbeC5HsGd9axRgZ+a+1v3+X8oAJistl2Zqr0Tnw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Q0hzLzwzQZ1kxAC2/bXEKTvOV7M2IwEoSwCUjRiTyiTupLudUk9xFR+IqlURaT5NmsTYdTNCKBCmpxmymxk5xP4jxMqaHJEOVzajQp7SNPh0lBXDMAvnakeBlHDU6ku5yxm0rnOIA9Rsy/o5w4MSRftffER+RPecGjGI9vL4PVk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.208.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-f54.google.com with SMTP id 4fb4d7f45d1cf-5d4e2aa7ea9so13357353a12.2; Wed, 15 Jan 2025 05:35:43 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736948142; x=1737552942; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hxJoZ54lWmY7y03qGdohZy+9vBhB4XRFoa82rjM9rKk=; b=ebdrYflHbzu+ZScAYAs0y/tXwH+WHjpz3Pxp00Hy2mr2CCZctE8rw1O7aqnTTwpjU0 e8Ykda+iE1vpRPyIQJgmDSWbC2tpzo+ZwBdnwAOWOw1q9TAW6PVM0A3CUulnhgNT1ohE 89WIpTFbLqWNI5eRhjPahzlVRSy5b5xWAKbCxj7wcZRzJuO9B7dRxq+VfeoUnmHo/p2d ZK/pU/+cHkHYheNMe5DlsCGLYU5j7nQiN+COVVh2BTahjy+fI1T/F5fQ5DWvgE2Vn/lg /3diNFpzkkM2K3FARw05ixKYVWsUBCCEJ/esyh7ynuOH96iQoZRHDf99zwdDQx7dKc1P da0Q== X-Forwarded-Encrypted: i=1; AJvYcCVV3FBzlShXTb9I//HNFe0oRQ+tPJbLUOYe0u/uHK0/KVgyo4txsPlXJ5oFEtoc8OWBb2DSGhZgKBM5mWk3ApU9@vger.kernel.org, AJvYcCW4QOJ0UIlLBqZwPyHeFfwSRTuzah8C9wxT19WDPToXX8E6I0rMpAHNHK+kMQ26/cHHciD9YHrLQgmug7va@vger.kernel.org, AJvYcCWvLC0CSJcbg0ZjwU7VjhZLTuTzdY8b2ChTh+GUZRWn524KjiDfrM8YVRhGbUTYFhZ4XhEduIo4lBw=@vger.kernel.org X-Gm-Message-State: AOJu0YyFzthCOsOIOW5hH+vG5F7J0q7UfmfJ3qCFjZVaLUQshc4gITf3 UZIV3B3Vk0inbGpARhqbRiAf8wtv3hdpUWim5JHClQE3kUeGfUVT X-Gm-Gg: ASbGncuY2Vggy1iCRTf9KwOyC0JF8HIPUB9oLvPDNWqty1yDxUU8jl0adh4kgOkHjrb QxsSoN8nuztTDugVI6OH5RoXfljcUZElqB3ixlNBHkpZdEp8FLHLbXskA8pLtwephfikXDzR7bZ bTXk1LjWSnCZ0HPxKMzrK32sBFSyNPY6K/jWl1nk38MEKR1slOTFtB9uY0mBaGRBll5Xx4fucr5 MzEM28gmwxPEZa7SxbjuUk6OSRpO2/wRym0wbof2p7/osTc X-Google-Smtp-Source: AGHT+IHkbMdfObs31g/uxBDWJkg3DCJ8vK/UdUPgmYZzzc/BSJGQRpU0xtCIkd0BMW5M3kic6vM1VA== X-Received: by 2002:a17:907:3f9b:b0:aac:1e96:e7cf with SMTP id a640c23a62f3a-ab2ab6c6720mr2639494066b.20.1736948142064; Wed, 15 Jan 2025 05:35:42 -0800 (PST) Received: from localhost ([2a03:2880:30ff:73::]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab33d6254ffsm194073066b.6.2025.01.15.05.35.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jan 2025 05:35:41 -0800 (PST) From: Breno Leitao Date: Wed, 15 Jan 2025 05:35:22 -0800 Subject: [PATCH net-next v2 5/5] netconsole: docs: Add documentation for CPU number auto-population Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250115-netcon_cpu-v2-5-95971b44dc56@debian.org> References: <20250115-netcon_cpu-v2-0-95971b44dc56@debian.org> In-Reply-To: <20250115-netcon_cpu-v2-0-95971b44dc56@debian.org> To: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Jonathan Corbet , Shuah Khan Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, Breno Leitao , kernel-team@meta.com, max@kutsevol.com, thepacketgeek@gmail.com X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3163; i=leitao@debian.org; h=from:subject:message-id; bh=0oHhKbeC5HsGd9axRgZ+a+1v3+X8oAJistl2Zqr0Tnw=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBnh7mjnDag4eJcR1nVn8Jbgr8LMjboW0P5wsfwy aSp+YMMyCuJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCZ4e5owAKCRA1o5Of/Hh3 bczFD/0QNg2h1j+sLpHXLQ4IvAtAtrNtBi612SGfuWrHIHVGzFejxKTwJghwqGDUg2VjqNypy8a nBHMPr3olE7nzhdTWcdUGxdsXi3nyjOPkK5f7k5XoUPK3LGdQPppgGb6/OhE1+nyzVcktSuFNSE vbKeGIAfJOEQObqtXvShf7f4H7Ry2Jzljq5fOG1WCibK+NfnGu0zPdE9qXG5Hr4ulneBOxR0nQY 4mWbfWlafW5qKtcgI2LxJMpduLabYOPWrTrsAOYQUo4chcxj5Q1/u9kTKjfMzUZ/AjKkGeikZgH Mlqg/w/s75M4iTrNg72IRk4WLSay6PSzHeiWBiwGQ8WYxd+SNKHaA+sn2C9D0JXBYa/Z56ovOrM tv5m19brudoy2npvbV/lOnzVvXsxocst5TVqrn8+6oybRivekRuMB6y/B7Ydzrenbae6FG3CX0g HITfZIsfXYxtf7N8BOFr2AyrY5aknnlfviIJpFajV9emQRzxGSCdhgDGj3LYuciii8ung4AHlB4 jTQts/+BcS6o7ikQeVv5PldMxL41Njod4yp9RDF5KKORx000vyLTiFpcIqYIJwoGRJxnpyeX6WM 1J8MmbVZSIUBj1aEp0P/OIg7ecg/ezOtYpnfNcZe4dYh7pouHrl1De4RgTAOoznQedXcOSv1yRW a/diSrNDPrmytSQ== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D X-Patchwork-Delegate: kuba@kernel.org Update the netconsole documentation to explain the new feature that allows automatic population of the CPU number. The key changes include introducing a new section titled "CPU number auto population in userdata", explaining how to enable the CPU number auto-population feature by writing to the "populate_cpu_nr" file in the netconsole configfs hierarchy. This documentation update ensures users are aware of the new CPU number auto-population functionality and how to leverage it for better demultiplexing and visibility of parallel netconsole output. Signed-off-by: Breno Leitao --- Documentation/networking/netconsole.rst | 45 +++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/Documentation/networking/netconsole.rst b/Documentation/networking/netconsole.rst index 94c4680fdf3e7e1a0020d11b44547acfd68072a5..bc9ccebdae7adadd7c57aef20a726536d7ab3173 100644 --- a/Documentation/networking/netconsole.rst +++ b/Documentation/networking/netconsole.rst @@ -17,6 +17,8 @@ Release prepend support by Breno Leitao , Jul 7 2023 Userdata append support by Matthew Wood , Jan 22 2024 +Sysdata append support by Breno Leitao , Jan 15 2025 + Please send bug reports to Matt Mackall Satyam Sharma , and Cong Wang @@ -238,6 +240,49 @@ Delete `userdata` entries with `rmdir`:: It is recommended to not write user data values with newlines. +CPU number auto population in userdata +-------------------------------------- + +Inside the netconsole configfs hierarchy, there is a file called +`cpu_nr` under the `userdata` directory. This file is used to enable or disable +the automatic CPU number population feature. This feature automatically +populate the CPU number that is sending the message. + +To enable the CPU number auto-population:: + + echo 1 > /sys/kernel/config/netconsole/target1/userdata/cpu_nr + +When this option is enabled, the netconsole messages will include an additional +line in the userdata field with the format `cpu=`. This allows the +receiver of the netconsole messages to easily differentiate and demultiplex +messages originating from different CPUs, which is particularly useful when +dealing with parallel log output. + +Example:: + + echo "This is a message" > /dev/kmsg + 12,607,22085407756,-;This is a message + cpu=42 + +In this example, the message was sent by CPU 42. + +.. note:: + + If the user has set a conflicting `cpu` key in the userdata dictionary, + both keys will be reported, with the kernel-populated entry appearing after + the user one. For example:: + + # User-defined CPU entry + mkdir -p /sys/kernel/config/netconsole/target1/userdata/cpu + echo "1" > /sys/kernel/config/netconsole/target1/userdata/cpu/value + + Output might look like:: + + 12,607,22085407756,-;This is a message + cpu=1 + cpu=42 # kernel-populated value + + Extended console: =================