From patchwork Fri Jan 24 15:16:40 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13949588 Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.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 988C715855C; Fri, 24 Jan 2025 15:17:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737731828; cv=none; b=ox+tjWctlgOsJhjdvAueO1NSsmqo4uARzRMIYGyUfemPBtu2GFLhXZmzqiUnxfA2ZW2vCBKw7doip1e4RDOvdDTudsC2OnSIdmzMEP1HyI1O4lTAj72e3+DR4AyITcSaes0elBz0y7Fa6URiwq+zGw7JTImU1JSu3/WiM3uDibA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737731828; c=relaxed/simple; bh=ENMcuvIsrdXzGn7P4VLTgINjgrDPhJIrowbcEwJHEo0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=U006X6+hEiUd4RQyWLIGIFbZ3J1q4q/wAJBnds3XHJkg0BSpDVtceX4FXiu9U43kabJVvCJChNNt4sci/R7BK+DYqOYSbuCytICuJkCASJsu8RZtovH6RRIxpd0e8lwK45x2TsBoomeB3BHPqQVooHIw53dT/XJW9EfrgdolDSg= 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.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-ej1-f43.google.com with SMTP id a640c23a62f3a-aaef00ab172so370870366b.3; Fri, 24 Jan 2025 07:17:05 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737731823; x=1738336623; 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=ol560JIslRN34pYLB85RMI+8P1oXDamnShUUezaavwE=; b=f8jiDJvd0FOtpiQ6105PAEU3OLnvD9bV6AfNFU78tjoycXogsF47P+dqJAcfNuepRa YfKhyOLNsCKdaZd6640yGSX2+rYPHXCj+3veWKTGVhNP1fvRdTA7KCSZ0GLCm+FWqzUY RdRu27KRWUyqn8MbAeOOyNpWnFAfqjqHjPsSgmCi2mLQLb3HORCI/IX++GekJ8t1k3ew Er1XwiF6egfVouXECXifoHbCZDLUUuYm/YCPS7mYnNnmPILn5i6lOyWuahtie53BrKyZ 5KHz/lp+Qa2A1nDD0R6NueS25IwaSKS+B1IIbreqIxsGEj3Me9ze7V8CIX2ebUI34JQH yMkA== X-Forwarded-Encrypted: i=1; AJvYcCUgheSh4oSUoB0VK4Shb2bJwwr72pH6zBEvpyoux0renNGPjwpf56+7x6wPnf0i7mmQUBE/4kJSd+0=@vger.kernel.org, AJvYcCUtEUue4ViM2rb4O8gyuLKbe0BRSFxR0NJAjj11XEVWFN4qNWSy9OhcNJCuTCnEyPp10zJ8dWj5PGbLQwwi@vger.kernel.org, AJvYcCVkyTBNuOLZDwl1scVgoymvtf50w1ISu8umKjzdceg30U9pv16/oMJQ1pglcZObr9ovASdw+yXO2lIIqGaBsZK0@vger.kernel.org X-Gm-Message-State: AOJu0YxOmsCNrzt4YDfidCZTiSYOQfwFJQMv/v6SfVR2zkJTCBDJQKZl Td5HqPPH7/9oza1vkv0KYPog280xEx3o7BwsVWBCJwVruv/nhSWMMjhlzQ== X-Gm-Gg: ASbGncuptW8SwlBENI5sHLcTHs/sBMWQobQ76BH2a4LdALOGeelf6UoMxBdcMf2MojI 7aj1d2EKRPKAJ6ubhNhaCz8iQRygMVI94BLqDLo2a65/XxADgrY0k3uRWOuYDWKL+smosJycXkG Nrt1LQrwO4/7sqNpMZB04aHDj96memJmLRCJhRlE1DLZIia5LDgOQQ/7vuLIiibweyaOQrqxyvX ymjYJp8TIKogbzBHZ2tCE1TB9Jv/eIDyPmWS4HF7jYyu7xWKp1jgXBdU4I5VIytgfkdErMnN//N bMusSxo= X-Google-Smtp-Source: AGHT+IFYcvq+4BZS/Q+jN4NHKzsrtIDVvOLEvozHFTBHU6IaarhtSUN51Fg/eibXdmI6KV5WjA6WSg== X-Received: by 2002:a05:6402:84c:b0:5d0:d818:559d with SMTP id 4fb4d7f45d1cf-5db7d2f5e2amr76281354a12.11.1737731823233; Fri, 24 Jan 2025 07:17:03 -0800 (PST) Received: from localhost ([2a03:2880:30ff:74::]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab6760fbce4sm140758066b.127.2025.01.24.07.17.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 07:17:02 -0800 (PST) From: Breno Leitao Date: Fri, 24 Jan 2025 07:16:40 -0800 Subject: [PATCH RFC net-next v3 1/8] netconsole: consolidate send buffers into netconsole_target struct Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250124-netcon_cpu-v3-1-12a0d286ba1d@debian.org> References: <20250124-netcon_cpu-v3-0-12a0d286ba1d@debian.org> In-Reply-To: <20250124-netcon_cpu-v3-0-12a0d286ba1d@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, rdunlap@infradead.org, Breno Leitao , kernel-team@meta.com X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=4492; i=leitao@debian.org; h=from:subject:message-id; bh=ENMcuvIsrdXzGn7P4VLTgINjgrDPhJIrowbcEwJHEo0=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBnk67qig4CR5eQggAxvsdzT1pNLm7U0rBSCynFB vH3i3F/armJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCZ5Ou6gAKCRA1o5Of/Hh3 bWd4D/9SoNAX/fMQrR7Xx3v+5bh+uYdApQWUvPnBHfLTvFzSP6DPCjToWM0hRHiLcTLUgYXSL56 xJv9Dd8a/mdj+CPsT5H5Vgt2iMBqXuqA2On617sv9Sq6kljcGudw+ar2jC3zAsbBUvqqQqQgCZu S8KtdKsozMIrCcSC1o1nrnhjZpCVqnlHRg1Rcxe3WitwiYQPKyuUPBcdetj8gtT9y5zArT1wC05 wB9gHCiCxcL1q8JGoYe2JUYsSrjsnc2ZqH6HeTrNMaAzYTSWICUwjyabg2qir++JXeTMANbCeew wLZQSTPdiHkYERmhgDajOxPCIGl4+PVIUY9/Rym4B3prhHMpypRjyqIlkJCgVbgCMe59mT71eRa jsaaQ5dTJ1ijiZsUSk6I9EGYRxk6Y9lUz8QHtWNlCE21UjfCWsntjwvtP7x74NsjnD2tJDaOVZi TtS/tXQrOb7LZKpZoLC6U4ethwJIzAxSVTcJ9pdI7D/iEPLmUxg4gVZPlp2YaqN1JH7+au7wyU8 w8ySPAeZTZHUpLVZWZLF06RcHRtQ72ZUxr2S6pm1+JHbtsx3LQ7gwmDvmYVoupAeVFgS3TchzF/ TyfjJtsoB0Aq0HWpaoImmf8y0gPVGUxWKBixroo5LQbwArsO+bWLlR75n4n8zA5VMeinGHpVQBY jJiZNt+pEbbiNhw== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D Move the static buffers from send_msg_no_fragmentation() and send_msg_fragmented() into the netconsole_target structure. This simplifies the code by: - Eliminating redundant static buffers - Centralizing buffer management in the target structure - Reducing memory usage by 1KB (one buffer instead of two) The buffer in netconsole_target is protected by target_list_lock, maintaining the same synchronization semantics as the original code. Suggested-by: Jakub Kicinski Signed-off-by: Breno Leitao --- drivers/net/netconsole.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index 86ab4a42769a49eebe5dd6f01dafafc6c86ec54f..1a78704681184673f5c1ba8ae665e46751384293 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -137,6 +137,8 @@ struct netconsole_target { bool extended; bool release; struct netpoll np; + /* protected by target_list_lock */ + char buf[MAX_PRINT_CHUNK]; }; #ifdef CONFIG_NETCONSOLE_DYNAMIC @@ -1117,7 +1119,6 @@ static void send_msg_no_fragmentation(struct netconsole_target *nt, int msg_len, int release_len) { - static char buf[MAX_PRINT_CHUNK]; /* protected by target_list_lock */ const char *userdata = NULL; const char *release; @@ -1128,18 +1129,18 @@ static void send_msg_no_fragmentation(struct netconsole_target *nt, if (release_len) { release = init_utsname()->release; - scnprintf(buf, MAX_PRINT_CHUNK, "%s,%s", release, msg); + scnprintf(nt->buf, MAX_PRINT_CHUNK, "%s,%s", release, msg); msg_len += release_len; } else { - memcpy(buf, msg, msg_len); + memcpy(nt->buf, msg, msg_len); } if (userdata) - msg_len += scnprintf(&buf[msg_len], + msg_len += scnprintf(&nt->buf[msg_len], MAX_PRINT_CHUNK - msg_len, "%s", userdata); - send_udp(nt, buf, msg_len); + send_udp(nt, nt->buf, msg_len); } static void append_release(char *buf) @@ -1150,7 +1151,7 @@ static void append_release(char *buf) scnprintf(buf, MAX_PRINT_CHUNK, "%s,", release); } -static void send_fragmented_body(struct netconsole_target *nt, char *buf, +static void send_fragmented_body(struct netconsole_target *nt, const char *msgbody, int header_len, int msgbody_len) { @@ -1181,7 +1182,7 @@ static void send_fragmented_body(struct netconsole_target *nt, char *buf, int this_offset = 0; int this_chunk = 0; - this_header += scnprintf(buf + this_header, + this_header += scnprintf(nt->buf + this_header, MAX_PRINT_CHUNK - this_header, ",ncfrag=%d/%d;", offset, body_len); @@ -1192,7 +1193,8 @@ static void send_fragmented_body(struct netconsole_target *nt, char *buf, MAX_PRINT_CHUNK - this_header); if (WARN_ON_ONCE(this_chunk <= 0)) return; - memcpy(buf + this_header, msgbody + offset, this_chunk); + memcpy(nt->buf + this_header, msgbody + offset, + this_chunk); this_offset += this_chunk; } @@ -1226,13 +1228,13 @@ static void send_fragmented_body(struct netconsole_target *nt, char *buf, */ return; - memcpy(buf + this_header + this_offset, + memcpy(nt->buf + this_header + this_offset, userdata + sent_userdata, this_chunk); this_offset += this_chunk; } - send_udp(nt, buf, this_header + this_offset); + send_udp(nt, nt->buf, this_header + this_offset); offset += this_offset; } } @@ -1242,7 +1244,6 @@ static void send_msg_fragmented(struct netconsole_target *nt, int msg_len, int release_len) { - static char buf[MAX_PRINT_CHUNK]; /* protected by target_list_lock */ int header_len, msgbody_len; const char *msgbody; @@ -1260,16 +1261,16 @@ static void send_msg_fragmented(struct netconsole_target *nt, * "ncfrag=/" */ if (release_len) - append_release(buf); + append_release(nt->buf); /* Copy the header into the buffer */ - memcpy(buf + release_len, msg, header_len); + memcpy(nt->buf + release_len, msg, header_len); header_len += release_len; /* for now on, the header will be persisted, and the msgbody * will be replaced */ - send_fragmented_body(nt, buf, msgbody, header_len, msgbody_len); + send_fragmented_body(nt, msgbody, header_len, msgbody_len); } /** From patchwork Fri Jan 24 15:16:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13949589 Received: from mail-ed1-f53.google.com (mail-ed1-f53.google.com [209.85.208.53]) (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 75B20158DD0; Fri, 24 Jan 2025 15:17:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737731829; cv=none; b=PHwmTCoPoS0Vh7O3powAMiJm7obtSL1BwanmOTqKfwv/ms2LCIVxih1SIHMQmCuHTpZidEDtibrA6HliPi9VZnIREtnCXRQoBf3twBJK5FeZ99JkdCGE3Ryz8Cbz3WMxOwx0h8jgCYqHtwB0g3PpkSplc+dkyPQlNNnkWEDLa2M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737731829; c=relaxed/simple; bh=Ao8Bs78JWxllxyF30dJaAHCQnMH5vPji5urPY0Ka0W8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=G6xQUxj6YD7/34Fsw500ssuPkbICU+Mx6l64QkMpkZLgltdd+bLjDFIofSA05aBSagSCWYNBgnbCTuFybhHtyxDY4Z9puMyZV7nrGj8iOCwQLawaLPTqkuV3rj75seTKsJhrmHS6bkvJDFhjvl7ka4UlD5ZXv2r9L1z4OMqURoE= 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.53 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-f53.google.com with SMTP id 4fb4d7f45d1cf-5dc149e14fcso2615897a12.2; Fri, 24 Jan 2025 07:17:07 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737731825; x=1738336625; 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=3Q9FA5+y3TSH0h6S+zIICHxD3JLDLno9rduHb4UMqf0=; b=hBJhqHs0j7t2jFN6B/3++sCKM5TajvU303Ee3k3L8aNUM3HqtltZ43vpntc11blv5y qzIn+rj8MpMBmf8Dnve0Jqu5UBNN+Ep6nlIp29Fs2emalb6K1/y4yVRC8pCLyGMVXHS1 SfZf5eEDGCGIzSIsvOhTPe3u6D2rCg8VuAnDWwC1gxFLNDfkvlq2+ngQOAqxK9k6gn5E IODh5Mvti+EjH1C4+QUEWKZYIedg7t3Yrctm5sz4S61qYblH6dzXzcMD7jvNsvajmESs uxrvFSqQzUCC6ycJisR1E0q1ivtJPWZEDcX0dIZwuCQ3W6g0EehUtHvC1Ym59KbjBa7/ qeiw== X-Forwarded-Encrypted: i=1; AJvYcCUq7PHSNfU9wpx/VHp18QdglpvyzQj2ephEGmj67cUtYE+AJobJuYdqCOlFmCCEGfB/qDD2TMebLO6ERhLo@vger.kernel.org, AJvYcCVp9/KUxWrsHt2rIoR3Mayyl54802VFHbFdpgN4mrlFXuwk2+qdy08LXEli3XJnT8r7iX8SbuN/qfdGME08GrOO@vger.kernel.org, AJvYcCXRuK2MssxOUgZWGx76mzp5Og/HuF8Wf0t6tzBOOobQclRJYbj7+tVN8U5aufhh4yqgdTNkB7s9W+U=@vger.kernel.org X-Gm-Message-State: AOJu0YyR4SxGMLs74tyqhAMrX8a8NB5Rpwhy5JuIeYO4nDguC8TMAbGQ 1B1pUFB78UNON38vGPP+HtjppaIT09pffCBDF+i+jFWLixSOqlrgzaqtfg== X-Gm-Gg: ASbGncvkM6Y4RCzrCWxGXvT6LIjxpAvoqmos2kjfOeC6Hz+H6IuZeGjy7sBDvVaTJ8k DY6PvekDkA2tKdydtvBjVCSkurfr8TtQeLmExwg1lsOnZCOlPT/s4hNH53f+lgKG0W+fIJLyy8C Y6HN2GwwDSacRv83JGtvPKNgMfah/vDTyEyV2QzfWK4xLfQ3ZgS7NLc2YHEZMhOj4btAToguO6J du9fJSkMOm9ycNyXyXu83EMe4iPHACgzMRUjmhl13yTHQzZiKnmEMVDmVXyP4bYPn3XNCt5 X-Google-Smtp-Source: AGHT+IE7lfd6ufDq6KEasiaxTyo2iyPX7uokoc5vrLMqpxurzW91F3yIHafzjcKEZ0VRjFY3rl9yFg== X-Received: by 2002:a50:9346:0:b0:5db:d9ac:b302 with SMTP id 4fb4d7f45d1cf-5dbd9acb39dmr13142408a12.32.1737731825099; Fri, 24 Jan 2025 07:17:05 -0800 (PST) Received: from localhost ([2a03:2880:30ff:71::]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5dc18638e5asm1306413a12.34.2025.01.24.07.17.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 07:17:04 -0800 (PST) From: Breno Leitao Date: Fri, 24 Jan 2025 07:16:41 -0800 Subject: [PATCH RFC net-next v3 2/8] netconsole: Rename userdata to extradata Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250124-netcon_cpu-v3-2-12a0d286ba1d@debian.org> References: <20250124-netcon_cpu-v3-0-12a0d286ba1d@debian.org> In-Reply-To: <20250124-netcon_cpu-v3-0-12a0d286ba1d@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, rdunlap@infradead.org, Breno Leitao , kernel-team@meta.com X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=10543; i=leitao@debian.org; h=from:subject:message-id; bh=Ao8Bs78JWxllxyF30dJaAHCQnMH5vPji5urPY0Ka0W8=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBnk67qXBmoHzqGCGTV2/I/ITdvFfR/2ePnXlROy 8ZW4TKJsJ+JAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCZ5Ou6gAKCRA1o5Of/Hh3 be8FEACv146PdRzT9mbtAvM78UjmRn7AkzwdqfF312qPijIdjbxhygkuIk7Mc31kI+V0tQemBSx 9m8yKH8ZBWtMEEjHjpEGr/H+pQ2aBAIhSE192mk6IP2pTLvwQ6wPzVH75PO6kTu0xlbc3Ijjk/0 tMU+10bKaWnYIwdGd5GbZ1Q0idiW9BoK3nVd0FXtNmmLxicuRhl1Mwy8abP6nxM2ip0h29LwaWi vSk2LnyHYVWYLEzZh05jQ+cs0fzZqQJcWpwbJ8BYvrdOhWnj+KJOUPMzD7hs8S4S07VcsLh6mnG iAV5TlX57bFTxRNI+LwV+EhJAtFmS8YHSqe/+frPe3uw03kFZZi9CC63TTnCcM8X88xj9Hc45Vh 33CQ/tTgNRxKdsg0JV7j7PTo+yh7KleFPf3p5b52iJ3Pbhy11GrShO5INuFFhyk7W4ePq+Mtpzf 1LWbR0owKURHLu/H2cZVusBEaWVxtbIzRSqLmSvsIiQ9lyxcFRx73Wfq5ldkeA1uWQ2lBBrkbmK fxphbdPzEp3PI+V5IjDqhVFx8/pW7mTLD+EMUycl+T4uYza/3bF/ZQu7VDnJlcQiOBqn5CzLJPp 3iIOK4I2wMwFyp2rIROJcC6VQ96AucifrMklGcYPO0fT7u5QuybXblDjmttRC4AGSOKnVAU3MGh k05H17jyBNcvQRg== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D 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 | 87 ++++++++++++++++++++++++------------------------ 1 file changed, 44 insertions(+), 43 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index 1a78704681184673f5c1ba8ae665e46751384293..6c67840e583a295e4f357bd19be0dd0ae3b76627 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; @@ -689,7 +689,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) @@ -726,13 +726,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++; @@ -740,19 +740,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, @@ -763,7 +763,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); @@ -812,13 +812,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); @@ -1119,11 +1119,11 @@ static void send_msg_no_fragmentation(struct netconsole_target *nt, int msg_len, int release_len) { - 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) { @@ -1135,10 +1135,10 @@ static void send_msg_no_fragmentation(struct netconsole_target *nt, memcpy(nt->buf, msg, msg_len); } - if (userdata) + if (extradata) msg_len += scnprintf(&nt->buf[msg_len], MAX_PRINT_CHUNK - msg_len, - "%s", userdata); + "%s", extradata); send_udp(nt, nt->buf, msg_len); } @@ -1155,24 +1155,25 @@ static void send_fragmented_body(struct netconsole_target *nt, const char *msgbody, int header_len, int msgbody_len) { - const char *userdata = NULL; + int sent_extradata, preceding_bytes; + 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. */ @@ -1200,36 +1201,36 @@ static void send_fragmented_body(struct netconsole_target *nt, /* 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; + sent_extradata = (offset + this_offset) - msgbody_len; /* offset of bytes used in current buf */ - int preceding_bytes = this_chunk + this_header; + 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(nt->buf + this_header + this_offset, - userdata + sent_userdata, + extradata + sent_extradata, this_chunk); this_offset += this_chunk; } @@ -1286,17 +1287,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 Fri Jan 24 15:16:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13949590 Received: from mail-ej1-f46.google.com (mail-ej1-f46.google.com [209.85.218.46]) (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 08A1015EFA0; Fri, 24 Jan 2025 15:17:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737731830; cv=none; b=gYW/lSGg9ZAFfWUvDKktvVGbs/laM3tCMYifZIRjFP4d59Rd8nQm/S3u2Gq34Kcnca1sieaVytBj7LBEe9DiO2fryqU/+b3+uO+yFQXavbF5v40XT0OdtBwEdkbGdpHiV4it2YnoM8Nhu7pQdnMHNBk5WrHtlCKT5mVfHu4Y4O0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737731830; c=relaxed/simple; bh=GCi+43WWf19lNSy6J7d4ZBO0U3IT+kcIa4GMZvO7Xv8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=WnR5GRITUQjmwRkqCjWZgKqvaxysuZN6QzANv9FK49bp1IC3qg1KC6IjIpZV0cwhDLTx99vWZtLDwln6cVDDWGodU84h4/EGpjhrjtStTwamfxMo4hNQ/gjQqLRb5EiQvV12SnKMEzqB4QFm/b5nT33PSl5Wx0EyQYIEmWkFk3Q= 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.46 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-f46.google.com with SMTP id a640c23a62f3a-aa689a37dd4so452507866b.3; Fri, 24 Jan 2025 07:17:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737731827; x=1738336627; 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=r6A2gXWuEaFoL/mi3Lklti59AWgaQA5akjMekqzi2GQ=; b=osyzJhaKddmr0J4le1HX9SjxN5b63Wd7qPJlTFjekBBPKzcTm2Da3KMVKQADb+iUPH QB7tzYkp0PNAHDdRcTIbG/+lgTGIKJqzzcxRpqmPAqG7ARO3cgt8o2Dv+g6oS4Ko/Led F991pYJbq4w2tWSTq/ZqVEAoOsV+YoR39CFMKKEP52nmeIB7C+Q9CzlO9SlXLZJfYf4M PMLubgVNj0zjPHyZ7t4RQHNiL5t06hoTwKOWhOjf+lFEr8jndjKEEzUL1CQo1LFft4kN Z7sVkoJyu5HZzPKIVvvGIPe58ZIs+okIccLWez7DXg7LzU5JhdaaeTHWyy7/Z3lrbK4h aRGA== X-Forwarded-Encrypted: i=1; AJvYcCU5z9ZO6ohQ+QQWHtCBEF5yrYg0rRNvgqbty9AQYoMKGMWqtWIENTIEjzcLR5lxwdrDtO0IZBNBNmk=@vger.kernel.org, AJvYcCUEcJOgTcX3tq4tn+tW/q3sS29zL30U4ugEEI56/Nbio009YChmwaUMKDdwpXKeAF6K9Bu8K4tAjGBKoyhf@vger.kernel.org, AJvYcCVHA5perv50TYTZfUfrZ17HU0MYgCw5rDiidn1SzDU48asxhSFG2iToPPBkok4Y82RXBaGC7oVCZhcWpvC6aJt/@vger.kernel.org X-Gm-Message-State: AOJu0YzH3e1yj5JhV84i3e3AElTd9MH/SE5+y/ZO5EfDtKdthNTMW649 srXKXLaC2u6eq5Sxxy+XNTp16wFu+qhG5hpxiFSfwLIYWODZuvMyt8s5Aw== X-Gm-Gg: ASbGncutweEkzdcEFOPWkaaEqLh7oAlh/9TUlNl893FUFY+1zNeQHYxQcz3+mkW8aNC f/c1HpZM2B71BRebidMbS1CfMyYdIRlaUEVBXH/skxVqT7JNyecElS4YINPWAlApgJt0H7Q8cHd Oe5lheZzKMqtkjXkNYYrqwEGk9vKsSaGzrBUIk1TtLSTH6GMhoXfAuokxV5IcZi8op11q1VIeoe l/OoWyq3sjSXP/m9KxGqYpeufnRdR5z6vLLvH/yALwXwQjb0Kqv++5HRywc4rHvvnx37RI= X-Google-Smtp-Source: AGHT+IFn3tWJ/ADXrd3oO717cFG70u92LZ8ynhOWopFdUS0IWNtbdCmzZFH+CxPOkXVvmDJ5zi5zaA== X-Received: by 2002:a17:907:2ce3:b0:aa6:8d51:8fdb with SMTP id a640c23a62f3a-ab38b240a67mr2605110666b.19.1737731826761; Fri, 24 Jan 2025 07:17:06 -0800 (PST) Received: from localhost ([2a03:2880:30ff:9::]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab6760fbd51sm141531766b.151.2025.01.24.07.17.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 07:17:06 -0800 (PST) From: Breno Leitao Date: Fri, 24 Jan 2025 07:16:42 -0800 Subject: [PATCH RFC net-next v3 3/8] netconsole: Helper to count number of used entries Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250124-netcon_cpu-v3-3-12a0d286ba1d@debian.org> References: <20250124-netcon_cpu-v3-0-12a0d286ba1d@debian.org> In-Reply-To: <20250124-netcon_cpu-v3-0-12a0d286ba1d@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, rdunlap@infradead.org, Breno Leitao , kernel-team@meta.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=GCi+43WWf19lNSy6J7d4ZBO0U3IT+kcIa4GMZvO7Xv8=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBnk67qdmMAXEMstMwVd49qG2/cV073AZXA2RWd/ eCzDQN9jTmJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCZ5Ou6gAKCRA1o5Of/Hh3 bWQUD/9ueTW9DbIz0lvGKCfF2zE8DD716Ww7ztp7PiuNusOZ6F7Akj2xFJWxO7XSHJ3SYizpG8B 3oyhd5xTcQjYJrGFPn14+y7m08sbkUTsKSZ/JwBrCbQ3BMDIk/aGhUFHZm6pWctnj2emnbVST/L P/wt9mcoEAyLINlb1rlS4B/jJYhs43gPfkTYZ1gcz+KOkJskrnejknGk8Fz1PAx6H0NLVkWj5Lp FjsyNhrEuVGTLE/yqKg+jZnP93soWBuX6deAYx3f+zgCCd7467pb6Rs4pqFdy4f9wtw4gCc7F49 Bo5nBdKo294tIHDGB00rl6TPhFsqU38BplErDBboBKc92C1B2BG53/uVfkj32hAMjMAbNmefkC4 x44xvOBOsULeQr5ZGxvlraBG9gbHKIRrmkLTMb5LvIXaEneif1Ok6getx8hMQev56kD0RhCXg8N UG2LKwWFMjAkkbAu5NudG/4yBVMD75pE04ur06oFPu0q1rJWi6vDnX1LcS+vkyC1vzQGUi8WLoz zek0Wz42c43Z9B/J36TRBlNsqmU6cUFwfjOWQmEqoAPabiI3H2AQAsc+z1XMbETXpZMBCpNYw7Q ju9wnj1IO7GquLSoFvXL1S9FOJE+0cQsr/Y+NMmN9Ha8uyI83THpTDyhwj8OiLe0krU4yrKn5h5 nlIUsCYZw2nm3dw== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D 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 6c67840e583a295e4f357bd19be0dd0ae3b76627..1c197da806962a751a3da8794def6a97cff5f701 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -661,6 +661,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) { @@ -810,15 +820,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 Fri Jan 24 15:16:43 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13949591 Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) (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 6CD9C1991A8; Fri, 24 Jan 2025 15:17:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737731833; cv=none; b=opSrCPXqisMl9MIw4WGJYPjU7zKd496HmlhDShgfPBR3hwJBm4h7wexgSzHShSaRM47Vlqz2zL+vGCWiLoXjZBT2zR2pVSpKN/cfuzXB6JIdzQu5Odmj0FHyKbhpQTr507EyhkgBXfJ4hUsSs0uVdvrXPbD6saCr92VnWXvE4eM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737731833; c=relaxed/simple; bh=VvYhMqUAo0V8kDZW6fMOYa/jXGpxQtZ/+oVgd6D3HQo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=AUSeYXWmS3w7iBoYRkgfwBoyQnga2L9qJNTkKKLnFd7Lsz3PZJNqLSecx+736TINGfzVyuuP20YbeMW1vOr1z0pcL09Bsn2mJ0lErszevjwSyijr6hysmt/zyY8qoPlPQBVKQs8tb6YYTeWuxXNMC+uoT+UgB/wcENzbHUE0mb4= 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.51 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-f51.google.com with SMTP id a640c23a62f3a-aaef00ab172so370884466b.3; Fri, 24 Jan 2025 07:17:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737731829; x=1738336629; 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=A9uBJBavnRRbXIEPgvkqqS5e1E1VX0ZLnO/5iP3vrGQ=; b=vIC41ywEOsrCw2QRiPLcfIDL9Hby4AnKfgPuBFdkY3NCIvEeR1Ld0Irb34YxFmH5yb 8noTdih5Luv/ZCwx27yjLjV8q3e8KrPu7Nu2+wlEnHnz5oFcEvR3ysdxF3ostEgaybco qlEptvms6YkVpaLqBCehmIMm2s1ORRQxXuD18iV0KQSLBLROsFfFAMO4g++WEsqg1LdW 7bhpu+JkzqZF0loFz6lsKbLEdTYKkQHh2nowz3FVlx+4AgzklUNaGgPuIsRsr8UWwjOh K+w5HAYCjAZMAOBS841nk/Xljf2Jxbudk3SqI037gb+vhJMih0PY7pHb07FFutqPQwpy zk4Q== X-Forwarded-Encrypted: i=1; AJvYcCUWUSTmq9vUanUYnHFcM+/glTbI6OsZfpWsb07iWn0uYUwgF5K+s093ZCA53IBU7P3EdgPRv1iahlu+QEqL@vger.kernel.org, AJvYcCUfwTmc5wMx+LyoZ19WHOtQIt54EsEOU/F4fnxKVSpUmousZwyxrkg7Zm8nzQptjYpUkXz7q5RNaP9uq6SJDI7Y@vger.kernel.org, AJvYcCWpAkq2Qpv/4KQYdA4K+NlfxiVZmoHIauVNj9sJyDCpLiBArL1irS1ksVLaXOcPXxldWlyuXmIy5ME=@vger.kernel.org X-Gm-Message-State: AOJu0Yz0QUvHY2CsDni8T5y54JeGz113kK8AC4kQI8H4hpDuvRHX6gcg HsWlEU8gWWldsFoe0C5ilJzth0Uw/aGvDmuHtRtPyxqat67ekHvo3SYy6A== X-Gm-Gg: ASbGncuNIFUUfX9FZ4dWok9NFXrfyVyH1q2D427uzR2BboY3ED/LUU/zTgKu3hQjjgQ mjHwJ6V22LIREXgdTpHYQWmcBZZYeqNZNAJVftx311vjC8gDzUu2OoEiAVxJEidkY+qXyXdhtRX 3PwXx2+8HFVelBR2sKwP5ANmsArezQDbCSewa5Mmrvg5Lq23DZVu9tApLVpshFRVjHxT/phsAIK Pu1y/lrTL26mfKrjwuVg49sB8acExys4sy8tn4chIUpcE5Dejl6FKc+/zsyW0m2hHrGFyks3/Mh TTcTVA== X-Google-Smtp-Source: AGHT+IEtcR7IbsNgiEZoxO8P72iS4HBHIFewAeqmpjE95N0eZ9X9crJzrzP+IyCJm8KJY/SMqxlI4g== X-Received: by 2002:a05:6402:4313:b0:5db:f5e9:6760 with SMTP id 4fb4d7f45d1cf-5dbf5e96a10mr25922157a12.2.1737731829217; Fri, 24 Jan 2025 07:17:09 -0800 (PST) Received: from localhost ([2a03:2880:30ff:5::]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5dc1862a17fsm1274712a12.32.2025.01.24.07.17.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 07:17:07 -0800 (PST) From: Breno Leitao Date: Fri, 24 Jan 2025 07:16:43 -0800 Subject: [PATCH RFC net-next v3 4/8] netconsole: Introduce configfs helpers for sysdata features Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250124-netcon_cpu-v3-4-12a0d286ba1d@debian.org> References: <20250124-netcon_cpu-v3-0-12a0d286ba1d@debian.org> In-Reply-To: <20250124-netcon_cpu-v3-0-12a0d286ba1d@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, rdunlap@infradead.org, Breno Leitao , kernel-team@meta.com X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=4808; i=leitao@debian.org; h=from:subject:message-id; bh=VvYhMqUAo0V8kDZW6fMOYa/jXGpxQtZ/+oVgd6D3HQo=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBnk67rBC45BX5/8jV+gS22yCwvBKhXPUEbbUuWg qf77RGudMeJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCZ5Ou6wAKCRA1o5Of/Hh3 bR0LD/4pg0J9MtjO2Qsu392AGhrbPGLkcj9ixQYU+4XWAksjxUBgY4Fg5ZbiX1TW3qgY4ccJkO6 lhB18cMsoYHLw1UrK1nRCP+IXDydppUxwx7cYHY+L/+g3c8a1CJUDChB6bhmY8HPEczwtdTOwcn QK/fJfwtwPkW7W07/p5u3QJzFlpOHO4VQ2o4HO33uEZqZ2igUf56CuxGUlSLBWwJMKIhEycy9u9 yHHhR/+udTfPs5a+HOp2UETKSF+DQuqP2VyP93xkOQloDMxqQDXnlNjvT8CwYnhsEO3e7Sj+RLZ nVYKotdD1dk/8gRqeTIwrYb+OMrSfPqb1cbF6WIZPL+5BjFzDW3qj0B45kMm92neX78ef6OqOTy x7VtSWQ9TTUIoT0D0pH7k64jl+Tbbovke4wJbP7oQ2t0c7LmQ7d/rIE6UFV0UUApxlQZbCNefaH zQTRNiQVMWjyd4XAohGODuV1ht+AVaqbNvZQQILT3hPEyIBc+4JZrDR36xZt3JSzaillCIRodG0 vciUIVSZMFACesBCB88OnkS71CNBaIJNzId/dgjC8S0yVH5/QaCJ3nhwp3RvncQBMqmRXHdySAN FMnb9qzONPo6MFBFoTef8lhw7UWwdNZHD5uLYh63E+OrOjuHxqgNqHEtCIYsvxxkJxvNL0oXDWZ CZbcz6kfFojCdqQ== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D This patch introduces a bitfield to store sysdata features in the netconsole_target struct. It also adds configfs helpers to enable or disable the CPU_NR feature, which populates the CPU number in sysdata. The patch provides the necessary infrastructure to set or unset the CPU_NR feature, but does not modify the message itself. Signed-off-by: Breno Leitao --- drivers/net/netconsole.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index 1c197da806962a751a3da8794def6a97cff5f701..4cefa43555aada25769b705dd8c8c89964f51a52 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,7 @@ 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_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). @@ -131,6 +141,8 @@ struct netconsole_target { struct config_group userdata_group; char extradata_complete[MAX_EXTRADATA_ENTRY_LEN * MAX_EXTRADATA_ITEMS]; size_t userdata_length; + /* bit-wise with sysdata_feature bits */ + u32 sysdata_fields; #endif struct netconsole_target_stats stats; bool enabled; @@ -398,6 +410,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. @@ -792,7 +817,62 @@ 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->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, @@ -852,6 +932,7 @@ static void userdatum_drop(struct config_group *group, struct config_item *item) } static struct configfs_attribute *userdata_attrs[] = { + &sysdata_attr_cpu_nr, NULL, }; From patchwork Fri Jan 24 15:16:44 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13949592 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (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 0F4D31A9B43; Fri, 24 Jan 2025 15:17:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737731834; cv=none; b=SiSEcly5JpfI8e7V8rscgCi01is6Cm6/bTGQcGyX6WZZ3q91l1rqkptJ9t2XLEL/5wujVeWpjU21EPbUo5UgmpYpVYnh4TsaiJomMbsTbV/xjp3BSoKChuxHKg5XwvfyjIn6LE/NaO0U5yAA3AIZX74MByVniutKKdUnLjURVqY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737731834; c=relaxed/simple; bh=90ofQRjddhIwjY7B3NdBo3IIRS/bucBdlhjUgF+NetU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Mfh0gaEsME5CZT35m4y7kqAUEmLCayLbxkoPFndDlfSuVvHCMGsFHjt0o6KSjg2Z3M08jw3My2QtTWreT/un6xf4gm0IBWaqo4dUJiVy5wizcK7/T6QEmsKcx17RtlpiiYN6Xh0BoDf1JMp7d9ll4Zet5He/Q0jPaokSsQl3EdA= 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.128.41 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-wm1-f41.google.com with SMTP id 5b1f17b1804b1-436341f575fso23742855e9.1; Fri, 24 Jan 2025 07:17:12 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737731831; x=1738336631; 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=0R5eAfrpk5/TXaX9HTiFe76PxOptLYOl1qhyiQmRyhk=; b=VfwggWEazoY3kBBiFlRexoLrCBW6vsFGCRzk4XH+yPmJVWZer/1vHuXXAYUsNyOktE 2ajwZo7X8SMCuuHJZqwmwPRNfYdjCWMR122aPa9hR2h0FYpXAG90FSMkwl/2PPaItYdk t4fKy5ulRnDeX/UtThjGr5MSMYS61B25bvGlJvm8x3d83bd2KirOucVyZeOrDmN0EUKo O3aoyl8R6JgIdZzqwSNU9aQlWJEEyg9B5BlQ76Zn7MNdHgKqOYAiw4ThW60l6JS+5VrP qLc2D/r+JayNIPdASCZwkIXJKTcTcOUH8jZbfCOWXc7B3/Htc7ZyACYvmQ9YE2I8wUvP aKLg== X-Forwarded-Encrypted: i=1; AJvYcCWIeqUFQ2D+chxXKfD2dkLq7c5UBoDPSuychkpDlr0mIBkQPer1jrCCTVHHV7HxJuRki/UcSWxy/YbO3IEl@vger.kernel.org, AJvYcCWeUKmOqXSxpQUhLBq19UAZ6RlsPrZZasxdbrMuxRcYuP5OTrH8TVCx4KYJwtMfcof6A8NSH3Z7RUIH6FOIOE58@vger.kernel.org, AJvYcCX8EzwsL9NTMnEg3hjtmVloHDOnyHdO8BlEbiOr0GTGBwcL+Otpymwmko2HMXPUmo0mNOG0/72V6T8=@vger.kernel.org X-Gm-Message-State: AOJu0YxRswVzaswOY81yl0aIzF7DgMfoVJhBhe0pyPQZyE+2zOfyNzmq hhNynTH4jwP3PZJJt3qKTW0s5KBZCcp0qYLj42oM8oNU9HioNlE+xCM5rg== X-Gm-Gg: ASbGncu1gA/CYTnJIv6gCcu1UsgDyyt4YNdm1RUz+nY/sz77l7CqxA1Lr3ohe6X6h05 L9gKY72qPmZ5xUkavCJ6JIFMN09sqxtxprPMfyKKuEApFHEOyDW/C4AZ540Qmn99y2hR4o+/9tF A4kO+CRWuVS8IZwmHW2S+BnulD+8tY+VWkBGVNrMIunrJdh4nPorhXOUUESmisR4ThB/fsgP54n atF6pK8iLefZawwpK542jDhXUHnrjSMKJ8hEp2gJAjHaBeuhs7dsPCHM8w5bOqaC8Kp7q3B X-Google-Smtp-Source: AGHT+IGbwuU0YUTK5ski45/DPq5R/feN+h1iQPzoO7KXr6SpIOhTmlD9nMcHyJDhlejriWK7Mujlcw== X-Received: by 2002:a05:600c:468d:b0:431:542d:2599 with SMTP id 5b1f17b1804b1-4389143b715mr277099595e9.22.1737731830891; Fri, 24 Jan 2025 07:17:10 -0800 (PST) Received: from localhost ([2a03:2880:30ff:74::]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab675e13694sm143592466b.24.2025.01.24.07.17.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 07:17:10 -0800 (PST) From: Breno Leitao Date: Fri, 24 Jan 2025 07:16:44 -0800 Subject: [PATCH RFC net-next v3 5/8] netconsole: Include sysdata in extradata entry count Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250124-netcon_cpu-v3-5-12a0d286ba1d@debian.org> References: <20250124-netcon_cpu-v3-0-12a0d286ba1d@debian.org> In-Reply-To: <20250124-netcon_cpu-v3-0-12a0d286ba1d@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, rdunlap@infradead.org, Breno Leitao , kernel-team@meta.com X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1317; i=leitao@debian.org; h=from:subject:message-id; bh=90ofQRjddhIwjY7B3NdBo3IIRS/bucBdlhjUgF+NetU=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBnk67rWYcX6SWsGuYFG8q6jneB281uW+NNRGcYr Uw3FzJniseJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCZ5Ou6wAKCRA1o5Of/Hh3 bdZ2EACler/RBhAu5PNHtKud9KcWiGqhyUQT4SVa+YxhctC7UU8e+GDDwuCwaiG7YDSCMeN6IVK Lmn1tz/AKUUqTcmufHtBpn4a5Uej0TrAIZNTt1k69TMsPDkhERZx7loY0TaF5Y58Vq8ZICBfkec 3SFUZzh5NfNcUjAIJ9Y389Q0vhYUjxeeiAPnYmkqES3k7vJKGm7cMsAbu9CLNk3Na0CaLvJ5mo7 wXcMuYvhwJ21kyxvgz2QUBGajAhGrl69hLjDoLU3uqdRoCCtcgZoIK7wD2zrK24K/Z1WA/jLvda wWWBUeLNE8BhEog4qCRw9hiBjV8+rlX24dlD3Z8OUiqi2fjB2WFZ/sinoGf2GkxxXQmp5afc8wK Bz5C0wl9J1tLgGYHhTM5Rxlzs0KUMlR1rdpbC7ThnM0mDxjL/pG10q5bH2yf8rktCuFS4NL0qOo wbDOT4v9QDGP9i/Lg/47aPG44pLV1vnPC0UfN8I6iyV0OTXEjIlaJrJHVCSpkqr91g+M73UbUMR z/GZZ6bADwv0cpzyKWndsZyKu8FqOMCSJWd+tV/L+KdORU1zJtP90YDiikPr1ToxhHtx+bxBJ1x BkumSaaMe64mRHb6c9eR2ICTw2RuprvVpBGJyF6qfBtFTiCJReaDT1xn1JoqdguindOXafiHWoF O+0XIxVbAnbxLvQ== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D Modify count_extradata_entries() to include sysdata fields when calculating the total number of extradata entries. This change ensures that the sysdata feature, specifically the CPU number field, is correctly counted against the MAX_EXTRADATA_ITEMS limit. The modification adds a simple check for the CPU_NR flag in the sysdata_fields, incrementing the entry count accordingly. Signed-off-by: Breno Leitao --- drivers/net/netconsole.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index 4cefa43555aada25769b705dd8c8c89964f51a52..2f1aecdf2a47f246e75061d09b9ca524a82ec994 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -693,7 +693,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, From patchwork Fri Jan 24 15:16:45 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13949593 Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.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 ECE131C54B1; Fri, 24 Jan 2025 15:17:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737731836; cv=none; b=cOAf2wzfiHUR/PZpylJ3+7TL1vvv8M3IgaswzdAstcHS80/CP3CjbI/JKUr6uYU5qyW3xlU72UlSXFIb2lns3YMM2XgcmD56YQ8YIJguCjFo2767HRptlVvM4k8Pfs/ym3s/ze4vlFu1W7v/ngr4d3TOKcB8KWVdRk6yWWMJEb4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737731836; c=relaxed/simple; bh=k3Texaptxd22qXRsu+lfUttY8c8569tjrYrumyuXOQQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=LRAAcskZWpRQ6E/vXsp6AzJqZQCNoZDIGy6Wbxu/oPhN9QLdHEAzYL6iXCnG55iAmDLCY4IYeGmO8P+/hMyCYWOjX9WJJUmHePHT5VHc6M/j2UjsAnVAR8xSne9KfRH77i32BEunFaBuNBUpbvpYUkGjui5al2qRpGqJRcMx+CU= 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.221.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-wr1-f48.google.com with SMTP id ffacd0b85a97d-38a88ba968aso2172480f8f.3; Fri, 24 Jan 2025 07:17:14 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737731833; x=1738336633; 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=OLbfgzlUkX2+ckF9tJQz6U58wXcO4TEKMtUAALJyc1s=; b=TDKwDyxuf7ezXq5QJTWiaP35JQ9Zf/ybWWMNJhFTH6+04Vh2vJVfDtJmKsTKPgM3iS L6FNMnl7L+2vgMNAioywUR6UmxF3Ot4p8jHDjxCH4NfOADvhyVeUM/36jfFDh5YHsGhZ FjRmnVKUOGJ8UDeXHuZ2SKx7RccApBpNeyItWVug9gvvjmW2ILBglPCrP4xgw7/1OiBi TDDanzq8tA6I5ao1CjyOkADzI73hsxe0jam0xsoLytb4OzAfcPbYyldwhNx0eNaCKMf4 gc0ll5+UFaAOGtgamf7kitgvGd+FV5eKzx48/Dah0AXvzfgRlQHKfqJLJJuqVR9kNquI aCnA== X-Forwarded-Encrypted: i=1; AJvYcCWDAQ6JyOB9pDH7FU51QmFlOq4crnIoR+MEBFIkBAIOZn/gyWVAiCZhWqwNlaG6x8E8jNR2T2MnUgRE5eTx@vger.kernel.org, AJvYcCWSzJnwtGT9IcXtr1C2iRDrgpBpGECYx8NvQ9VjfoX8xPimcjfGDgcNBjJobjJJ+qzWybX6DAdTw6o=@vger.kernel.org, AJvYcCXp5YwTPOcFpwucDjNGIetMYSbf5BlouH1yw3/VdnGH6RhnsPlf8QcP7U+3MS+nJJz9GuXVEG3yA7pqEMOsU6rY@vger.kernel.org X-Gm-Message-State: AOJu0YxmOBE0ja0y9WyrZKuR7W/E/L48ycjtLHHvC2ORBVl2/LRCwcAv SUN7BNyLOn3SIAHed6tp5PNM2+8FGwr/a4v8rbIslqAB1l2PpnMzPgo+Zg== X-Gm-Gg: ASbGnct+3MZUKv6RlsApP6g2Ibo4oi7rcoDZypIk9I9UdxJgN0fe1sAlR337W+mGgwM 7GQZ2+WdyU/HQEP15kTNmZtIBD1f8hsAvFzg5hvYzhXiMWSW/mapeXL0TIDU4oftbMV2skOck2g lqhVl8kgS89QYby3UuawV6WpW8IlZMtiEAqKRkcgZVfoRFZZnVnnh44mkyg7ESnz0OQLAk97TaZ b66laJbTXvdtUkJJ4Ai66FZTdEYGPzzdjeUsFwDOtPLCuDuQAvfpKPuzbPUHFFmT1LMVfo= X-Google-Smtp-Source: AGHT+IHQeHLYO/ldVpqwDP81gBGqP3wI9099dRFqEk0Tt6sgnCe4046i/kqKcqXf01nR74DXkisUTQ== X-Received: by 2002:a05:6000:1acc:b0:382:4ab4:b3e5 with SMTP id ffacd0b85a97d-38bf55bbddemr29154234f8f.0.1737731832649; Fri, 24 Jan 2025 07:17:12 -0800 (PST) Received: from localhost ([2a03:2880:30ff:8::]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab682f55facsm21014166b.63.2025.01.24.07.17.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 07:17:11 -0800 (PST) From: Breno Leitao Date: Fri, 24 Jan 2025 07:16:45 -0800 Subject: [PATCH RFC net-next v3 6/8] netconsole: add support for sysdata and CPU population Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250124-netcon_cpu-v3-6-12a0d286ba1d@debian.org> References: <20250124-netcon_cpu-v3-0-12a0d286ba1d@debian.org> In-Reply-To: <20250124-netcon_cpu-v3-0-12a0d286ba1d@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, rdunlap@infradead.org, Breno Leitao , kernel-team@meta.com X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=4587; i=leitao@debian.org; h=from:subject:message-id; bh=k3Texaptxd22qXRsu+lfUttY8c8569tjrYrumyuXOQQ=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBnk67rRmy+WsXHjKvs4jNjI4xrad3pzdyWXhl2I 4in48AGdLmJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCZ5Ou6wAKCRA1o5Of/Hh3 bX7KEACFJW2po0YvttLAEY3ZeIgm6BcUjCjS/QYL4bcWCveTbPIDgLMZC9TnSKptJPF56oFSr0+ BwGm4OIScH0j7QBThdzQjC/5FbCaI4IGEVqb6eRITrKMbSjCuyaUf2el2BAvDWq7NBLfxnTiiK5 FZuwoiTwkrivC0tCnNsQBkNLfgBXmNvOocQHRrPbQ6kUDgf5lmdvIbnhiqCMrkpd05PDFjHNPkU GwdoiahHK98veeRZg8yOgMUrGzJy++pXEZw3spkW4nOZUd/Rz6/T9E6Hhhc8f0NfRMNjpJuFkLT 59J8rPB53z3Xh6Y4j7qnxi64rXlR0Bux65yGF8KoHhWW1+c4UkmTlHaZrZlsQNf5PJlX4tAOEc/ ZaExxu/zPBAm0IoAZ++5lCCDniFOIkmmtdLLAFImOOtBUAMU3MXecFXjnLAzGOJIzhqcqoYJAV8 3DWRJaLuK4JrHntekgmvw9Pz+bWTnQGeC5HwG7ZehS7GVhl+LCDZpRSt8eTzo2MdmfkilsuGJOM U+JLt/mh4YbaGLJrwKgIEYOgs9FcdM0APVL6D5zq97pDLnE6BC0jgRebS01yHBGd15PqWWemxHa EjQRNKuuVwRV4hWLIQaU3E5Wxb8Kv1SW5Pn81eSXLxxosneaybVgUYAXj4FTO/5/J59n0/OyLRc p/g1W4odKabeBYw== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D 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 | 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, From patchwork Fri Jan 24 15:16:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13949594 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 5AABE1D47AD; Fri, 24 Jan 2025 15:17:17 +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=1737731839; cv=none; b=puLxY93d/onoPv46qHilC0jYVQikfxewxHZxqSekE4L90Jlc/DoBa9GkbK6NBD8d58Z4VCduWuL0wf3Gx8iCrShddGODfaUPU0bJ6oByYWBTWHo/PWb34WB6ouA7zO0qVfw1PexYTMt5iQP4zoKXbz6IgXPVPvrLMcZtG38EbQQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737731839; c=relaxed/simple; bh=HH5Vd0/wTISa/RdkFDoACDqmczgi5UrCPOZJhomUhsM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=IDpY/SyjpY+cNA+aBn7LE3HlO9x82JIYuEw2meWpuI1ViYLl14do9h7VWUqwnXAPErFPrhzTVeiVRAELvVkHuQlHlShdhR0cDy0MLKLtn/LVCkJA9+WqTnI4Iq1Lm250nFEuHZXxhJy9CfDzALXHDqOkKuwMU1Y+o1xqBOo4SEw= 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-aaecf50578eso515604266b.2; Fri, 24 Jan 2025 07:17:16 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737731835; x=1738336635; 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=CUUSxXMA9/ZzLm1CQhpRCwYqH4rW6urRrefck5UrJQA=; b=YYI1gnruIlP+QjKcxy3xf1DAju1RsDDWSklOeDFnfKrXiGwtm3uyoj+j2iAfgM155m Lu2rrEEJ7yPIx9LQ6uid6As1xwdgCU8COT8TzgrA7OaX8pNs4cqmiSLrjY7koj+1WYxX F7OJ0uSCqy2VXESNclrrjmlMFRsGftJv4u4eJk79eY61+Yow/U+mG7clBYyamd4oGacv ZU+PODXFd5Q7RQirzc/dvA/oSUNOaSGD1IGHP1QmKy7JwFvFypvzVaHO/UFuK0F89agf UQzlhLDo0I/aOCm26N/L3Y2+Ltyoup320JIYpun+EGuzh2kd69RehOIR8CJft6ofMuvc 2Wlg== X-Forwarded-Encrypted: i=1; AJvYcCU9ch6++QHcrpRxtw/CNXV0rkv5+jOVC5CNCG4cqvPh+kafR7zEUDzfAjOI5yJVJhbSHYA/64dxbKE=@vger.kernel.org, AJvYcCVyrdjd2xk8czDV+lurhzFbIY7ER9JtK9vMp6loBTRAgs/2guJnJz3W0NfKIgxqafnw7MIvdY1K/tTJONUR@vger.kernel.org, AJvYcCWl1DxCu6+8lL4aUPgTLun03iXwy+v2smaM/cUYdqqLOfBLbTDsdFHibC6jdtzV42GpWBAgoROv/ACIXsh8zzAA@vger.kernel.org X-Gm-Message-State: AOJu0YwHjqXaDqYo6s0evEZarrLR04Yl3Y3xR1EwnQ/9yp8as9e7k3jl 4GyJETIyWnM/7VGNy1sp7KRcKnh68+GxVkfSUMWo6OVF3wILrvT0G/Ur0Q== X-Gm-Gg: ASbGncsvOLWXYenfCZ2qUVcuVBWpdJK7oaGAUU42rJF7SmqXVDdLhK76AEZt5Ew2yV/ SkiD5I8R8tTYM6iwJ/vLHaHWqs1ZvZWJAAU9LN3CIkttVFULKUsFlOM8WWt58LoRySAWApTzhol oFU6OU+szhZiMcVKQJYB+MFSkVtT16G35Hn1JxsJW99FeT9xkHWDPQRJtrZJ+oaRTYpv8whaw95 1+QOLOkepXkZTEH7Ywxofns4errVzLoz0/86yDAEb0VXM5+OgBfsgj+Av4INXbjZBE1lkE= X-Google-Smtp-Source: AGHT+IFGFoPwj1Glit3wkHQ6H5kjHsv5c8LH2I8PtFlvsWCzeaqQat6JElK5Vy/QdrNnZBLS3qcXPQ== X-Received: by 2002:a17:907:72c1:b0:ab3:61e8:aa16 with SMTP id a640c23a62f3a-ab38b38134amr3150937766b.43.1737731835017; Fri, 24 Jan 2025 07:17:15 -0800 (PST) Received: from localhost ([2a03:2880:30ff:4::]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab676113267sm141210666b.161.2025.01.24.07.17.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 07:17:13 -0800 (PST) From: Breno Leitao Date: Fri, 24 Jan 2025 07:16:46 -0800 Subject: [PATCH RFC net-next v3 7/8] netconsole: selftest: test for sysdata CPU Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250124-netcon_cpu-v3-7-12a0d286ba1d@debian.org> References: <20250124-netcon_cpu-v3-0-12a0d286ba1d@debian.org> In-Reply-To: <20250124-netcon_cpu-v3-0-12a0d286ba1d@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, rdunlap@infradead.org, Breno Leitao , kernel-team@meta.com X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=7648; i=leitao@debian.org; h=from:subject:message-id; bh=HH5Vd0/wTISa/RdkFDoACDqmczgi5UrCPOZJhomUhsM=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBnk67rYbAxwiKtY4ZSi/QPKuPp9o32dMfk81pwy 5TwgoNbh7yJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCZ5Ou6wAKCRA1o5Of/Hh3 bVDeD/43MFQZD+CnoUq6kLpIPZmWmDsCIG45p6kol3FaYoi3q8DosLP2kHpzg2YaZDuUQ/PqsZf b/9YzXkp8REAZ42zLIM6tO2xpEfj2oZxVosF/NlQMXfskFfqH5lyfZNW+TpGRdwroYcM9S48Yqd 3Y79IPtN5XRsrj1/rIpc86BSF7GJmzWc8od7k2zPDjIurplICJ7VcmVCBcnrzRKH4CKmGcsSp0V klTRuKeqOjYJVelHZH9y8+zxFd43mD/hV4Xo5n63JtXIAL2kdRt95RnEpzfZcuegmPeTKgpvY9y wesD6F/bIqBygycUb8WHVNcS3nMARnKOzGUapG7LvM28USPapBDc9f6XUjSDfe4b5ted0YzB0Gx zFub3I3K8idggpqZa2+9ZHh3e9W2Wt5fmlMCemptw9qSmIDhwI28j/ua1vtmLnnHoEw6AtT680Y YPC2bqvAfEWB615ft6P3FMt6AszKmxRLJhekbRubceG3ToL+E0n2j9cBtYC9Syj8U/dwya4FU1V tz/vddtui1hRBWGH80ZdQG3sMsjElHmJlf1WSlvmPGSFjguppvz3/mLQ2YPjZ7omuzjCHE8VIwa k9sfsG7Zu8wTgPiulN/8TRQ2fJr5A0gB95L0MalmKnSNVid/8xgQSNOqJRKs4g34l5C+fyy7hFd wkONcIMS9K86atQ== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D 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 | 167 +++++++++++++++++++++ 3 files changed, 185 insertions(+) diff --git a/tools/testing/selftests/drivers/net/Makefile b/tools/testing/selftests/drivers/net/Makefile index 137470bdee0c7fd2517bd1baafc12d575de4b4ac..6c5e6159d8913e7bfd6bd835f0a9bd9e9d83518b 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..f50ccae6c0c090d6574defe5e02d7eda5f3d7188 --- /dev/null +++ b/tools/testing/selftests/drivers/net/netcons_sysdata.sh @@ -0,0 +1,167 @@ +#!/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 Fri Jan 24 15:16:47 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13949595 Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.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 D44B0156879; Fri, 24 Jan 2025 15:17:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737731842; cv=none; b=pJ0gEld900vuDKmwU7+F6XGgdMobBrklG+Va6gdY/W6fvPrwNHGUMtKutHBvmoKzZr/FipkI2qKHIWIG6FR8zLsWtJmlQijMbWXoJWMGZbPfXlWajmSqj/di4paMrqs0eDlDD3AKdMFtbqyO3oCUBHObdMIM4I0KmcDfXdFhtDA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737731842; c=relaxed/simple; bh=2pUaLVwLHOwxMYDPKEmqQLY0Bgk29Kn0tTJ8gIKafis=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Pv93pW+lDRH+vLdKloQ18JjgUj18MBDRU4GGL0rOUCXp01e460e7VsPEB18l4liqJ9f8Bjx/JUyBxri1Lv6OhZ8PoLF2urWflOtp9pAZIcT6SRFFCuII4CvORkJAICAoP758FemUntqeeKmSXPkVRsGbxhP7wzSVEvRZLQgV4UM= 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.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-ej1-f54.google.com with SMTP id a640c23a62f3a-aa69107179cso460980566b.0; Fri, 24 Jan 2025 07:17:18 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737731837; x=1738336637; 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=8PPqcIXQzYEFsqNlbLKuHZEq4XrZtJwQTMEp1c3me10=; b=giu6h2pfOU6wUEeART5mACIbA/Xb1MjYr97EgN/YPp2yhzf1XjP+WPf65Dmat+bUDR U9hd5gUSnjhIJQxFjXjLdgJYpTNvyY3yDzgFJT/my4N1WmnShjiC7ESw3G9wTFn6a9HX 7qvJjK0DqqGUDrIZigPAUKR/CqoHUraNsrXm4hB/3Z2N6EDk4RFSfy8eT1hDb50WfBX3 7n5Iy/D8hfY7T9eGvMMXkX89yOecjeQNxKalk0RJvBZyLdFKAxzYmxxyYcI6ODX/Tp4X EwFe2X8B8LxpZJJjjdeb14bCgQLZdB7G95MwX7mCysb9pRJs/SUAQFNNXzqvp1k+cSK0 hwTA== X-Forwarded-Encrypted: i=1; AJvYcCUWkpxwLm5N8dpG1AfYhI1Q9bVaXWjMwxzdHgI28T2koiMnGqrnYgUe6KBQ0PfEsi9ZW5tdNMI6jjXQb9yj@vger.kernel.org, AJvYcCUYyQV1G+pUxtNiZz/7lr3fcKeR3d7V/l3wdrAOIZjbUxZ4izLrcp0FRHnCbZapM9Xca0IfINCLQbcd6iaaIoem@vger.kernel.org, AJvYcCUhlhqP/Jyd4ZoMwEtQUX7CFXgwd9ZHeUGKEuTq2gX70KzFveRoKpWaglJSVZQ6jqm4ilBKX4dn0FE=@vger.kernel.org X-Gm-Message-State: AOJu0YwGblGp0mPwF3vMs671reID2HxmK+GregDZo9CFWWkK5bXE9+cw dgQ95ZPdldHoYiklQbW8rn8QP238xFQRI3iFsjqFYc00ANyq+B+Yi1ejMw== X-Gm-Gg: ASbGncsRkOdLv3790b4S2Lq10zrd1Wdr/kM+bFHn2wYJed1I0L0OvqwUFvrOdx4zRsS aIK4nF90zR96kV8uJ7MpIhRM2jxeiIUYK52vHS2Wo6vyp3HhG/fn1PGHW6OpPYReEd1oEHsZgB3 4HK0ALwQ1kUcfUkKWh1SPBBy5vhkXFGns9HEc0LgQ9PeImtqoC5AglKGJbdK4qEQkXRrhgyo6Bc oQmT2w+CTLDEeCBtf4t1GzUydPSRODJGtZN46QURuWR3nOd6xm8IlwS1w5hQnFJptqQm5o= X-Google-Smtp-Source: AGHT+IHmMArBUhVtg/1WJ0WUAhLRWzfR+vlFz0bqngO0k9VoWPbYyjW3luib/bc7xGTkRb7/Ph1S8Q== X-Received: by 2002:a17:906:1788:b0:ab3:47cc:a7dd with SMTP id a640c23a62f3a-ab38b15d31dmr2428769466b.25.1737731836596; Fri, 24 Jan 2025 07:17:16 -0800 (PST) Received: from localhost ([2a03:2880:30ff:7::]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab675e8a72csm143089866b.79.2025.01.24.07.17.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 07:17:15 -0800 (PST) From: Breno Leitao Date: Fri, 24 Jan 2025 07:16:47 -0800 Subject: [PATCH RFC net-next v3 8/8] netconsole: docs: Add documentation for CPU number auto-population Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250124-netcon_cpu-v3-8-12a0d286ba1d@debian.org> References: <20250124-netcon_cpu-v3-0-12a0d286ba1d@debian.org> In-Reply-To: <20250124-netcon_cpu-v3-0-12a0d286ba1d@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, rdunlap@infradead.org, Breno Leitao , kernel-team@meta.com X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3164; i=leitao@debian.org; h=from:subject:message-id; bh=2pUaLVwLHOwxMYDPKEmqQLY0Bgk29Kn0tTJ8gIKafis=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBnk67rzqpaFBm/uAykxQpqzIDmyYNpJQXNmvQwJ trRp/RdZ3mJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCZ5Ou6wAKCRA1o5Of/Hh3 bZbKD/94RwRqeg+0IfuSnuirUkVEZlJNvpAGF3RTwwEneET8cc+ZnBDYQeMq1Q5M+RoICwHg4r/ XjRIg/B1NhXjEobrvkQz6ewWBO1jutkMN43d+ZRzv9czSs5/lSpdvyzFnx14hQ78bq5ZCZVdsOr Tj6BXrPJOG45I1VHRVO2or8ysG3c+VlPH2Fie5Y+eGzFsGEJymIDx6g1nTtgiW3OZMJ5CUidwJl YFdTkk4oaiRDbOi9ZLMJnBZdxfHOdeiGZHoGdDlYQgNbI/H86vtK4zeefqO0UNMJHO4NVVYuJrl fbEK7EYTB4qsm8xK5Q1gddvm+ebxC1oowvtf+ZW727ajc0B19oFYTXyopoDmtNr6KdapRdGOQgT 8ElwRxAPTjI6Ft7hUT2sKcymUdwzRHF4dr9OJzfbDXwLJcSUIeWG0WIjFIuIP3SGrofY7+C3u4P YE+Qxm1xVJbSgiBeGLd92oHlcLlGLYNnaWSZ11Iiirxzeb/688yQTVMy0Go6GG10hXaMywbzFus ppWBGvhkpR5WfnEQnkQNa/aSP9v9OhEPL4r58yPCnRIUzJrcd5bz+W2y+VcpO1HpX7layA3Ca5h IiD6+tfnJ0JfrOdQJqqInR8w900kdB4fAU3XSz3c3kTspjnPDycVrZQ3ZO3mLS6NwwW992TUENu i34h2scdJYJBqdw== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D 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..84803c59968a3237012fab821f432eb531aba45c 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 +populates 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: =================