From patchwork Thu Feb 6 11:05:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 862766 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 0046A22689C; Thu, 6 Feb 2025 11:06:07 +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=1738839969; cv=none; b=Q+T7PW+lUlEsfBUYW9Wn46BNnErgLlb9kTwxoSX7LzMJQjm7lZQEqaNmiFZcCL2cjeqj814Ktjwgx07Ogfpo4K2zSn/vGzyvxKSPWy/ks5/5/cTuaD4b/vqQoHyIzrzRDPBmdvlDIjj57dtoRWQwvGzrRAeuoDGvoXK7PBgZyiQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738839969; c=relaxed/simple; bh=lTnjo5M9mcX1w/bC55hH7D4u1Aef58AcXKWP+fHpObA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=fOqluIEWuTJHNZb2a8/XCi+lDFgOjn77fh1TMcFVN1h9nh0SmHsBP/vAYKYCgIBh+ssmHx3zMrzjbSpNLJQoq2Y/0arE+tRpc7p2O5B9lmKetCUIjjyZl5Bi7ph45kuJIQayvQSQMCBFRoPRFlitTHfeFWb6/RsicZW02eV6Lws= 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-aaf0f1adef8so159360266b.3; Thu, 06 Feb 2025 03:06:07 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738839966; x=1739444766; 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=REdEcbQPl65CW/hCmXFtnxh/44oJYC9fdWTnOSTALpY=; b=YujFAx22HE/lalpzqFUl0ySTxWypWJ60pTD4gyqIiKM4BbtPK3dBgzLhwsC0BkitZz d9kUlDPWc27aTGPkQ1jPVzx6RPCoPlfYQtxDrLF2N87/5Y/4MoPWyq6ZzZ5JYru2q2uM MTGmLlVCt/lwp7k7wE8ClW4VLeYn09Y4Ldb0z5oRoFbuI4nZ0u9un3CXkFJ1sOROUf8Q 5khb4HRPf3QAEnX0gJlVxsvSfPNU7Gk8DJSvOVmHtV3OKum7qWfFblLhXdjEc7ACHlB6 ZM7oTriZ5B01GaV5WJyKm3aHlmqjj1jOb8DMzHLwjhOHzdobvWVs7e9yoJdNi323g8mY dvfg== X-Forwarded-Encrypted: i=1; AJvYcCUi3WRDNfmAOaFJkXPM41ex2Ym5Snsbhq2q8N5jG53Q6Qk8ILjNSpULjrcWbGLGoZr9Il1u4ahKKqqofrCWbUsc@vger.kernel.org, AJvYcCV3sdAfo07EmnA3siKsinm3Pi/HroFd3Ry6O+1DIGbjPU59mePbmvq75mBQNs3qFeXZkZ7rdP0o9/ioiFPY@vger.kernel.org, AJvYcCVjprekuI+HCTbBjyLrpaamVLTXD/VVv+2BHVrlVodevySJc+oXiUKbjHkZmF+wDjELDzvD/KZJWlQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yz2cTGNL9KKP2OO8WkwZ0Nxy8Z/uwHSqjDzFo3hJoDTbxr8JFGH WpvKWgbNmh+FZAPveFDrnuuI/ROGV55FKwZOho0Kw8M+GNNoDqQx X-Gm-Gg: ASbGncvoln5yBUskCsc/cRtX6hoaUi5Hd+B9ZP3YQFfUorNBSQP0u9pqSnMA/B3VSbm TRPpn5AhM3Pgj7AFbmkRtLQ6OIatu3cIRUPuH/uj0c50GXfK6vRyMTuya7uqVaYjaeCZKn5qjaH VFzJ9/Wx3aqxVfXp4mqiuuoOftw8xVkE+CRcY/cYtOPphcUA/g+ox0M2LhM4odGwpU4MCB8DYRH IZA/poOwdS6GlTdNassdjioEaLCYDlEM2BN6dBYQWsssdvlD2jBDVKuX6fXVrsTgzexdujGA4om f7f40Bo= X-Google-Smtp-Source: AGHT+IEFzu5552xmMut4eBQ8kM3b60OXc28m+jdCkEYJPO9PAppMuzlTkh2nqwHMk+eoNVzhpAoigw== X-Received: by 2002:a17:907:6ea3:b0:aae:fb7c:50df with SMTP id a640c23a62f3a-ab75e34596bmr695893466b.36.1738839966138; Thu, 06 Feb 2025 03:06:06 -0800 (PST) Received: from localhost ([2a03:2880:30ff:71::]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab7736468e7sm82392066b.172.2025.02.06.03.06.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Feb 2025 03:06:05 -0800 (PST) From: Breno Leitao Date: Thu, 06 Feb 2025 03:05:52 -0800 Subject: [PATCH net-next v5 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: <20250206-netcon_cpu-v5-1-859b23cc3826@debian.org> References: <20250206-netcon_cpu-v5-0-859b23cc3826@debian.org> In-Reply-To: <20250206-netcon_cpu-v5-0-859b23cc3826@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=4811; i=leitao@debian.org; h=from:subject:message-id; bh=lTnjo5M9mcX1w/bC55hH7D4u1Aef58AcXKWP+fHpObA=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBnpJeaSHEqxfpJAHBDX/XAsm+QM37Keoj68KRD6 efCzMD0xJGJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCZ6SXmgAKCRA1o5Of/Hh3 bQaHD/9Mik8uaIvAZXqH3Lzr9pYTkgMo9nePIxRDKYKLYt8QCieeE6Ql1BBeOCB51SUsbNXjwS7 fvoMcUa73HfqYe1xbBavt0oG+hAyc4IXb08NRheg5/1h2uI+N75YN2sNWlBp2GumkjGkof4RLKx L5yAEyYfxrnF4+Pj895icG9jrZxgWmOgzC9onZbMbSoAYzCwdkue25v4Vo/hhCRuS16LvjP8vtf j3UdAUq5+zLiiX+BYBRFOTgKV9PSLzLbq2H0aL7U1CMW8vMJTfWR810rKjs6nEgGrOJ/Yo/O6Tz OJUofUqU+G2Lim2q5NXJsuCdjdPScaEUCyt2zqdan/sprHNe0tPIg5tYMUqMxxRLP3NG9Res22S 30puhnoDAi1GkJfpA4+vEd7e4zBqfBnlKaOkXRafUAXTUJNp6GMSCxZED3J4wD+r87aRsKgtjkc Yu9yygv4fK7FEhlRsrKX1rT2Gfd+gmnY144QOQszuOJFEfO3cSysgPXHAxl5P62xXjcNVhBI8UP /7ME1a1lNCOoPER6W196JqTgoC5hvG4FfVreUfYd3zjIJTzhDiLi5cVF+98CeBYyXprsFImL7L7 jCjilz1kKoMAPdy40qD8grfm+SWB4LeAG11Jwb4J9BSvS6Djn62zrGZFCOoWNnYe+N28uSd4HrD 21dqHSK2o/XWBfA== 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 Reviewed-by: Simon Horman --- drivers/net/netconsole.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index 86ab4a42769a49eebe5dd6f01dafafc6c86ec54f..034caaa26563504357f859000678af2037003c25 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -123,6 +123,7 @@ struct netconsole_target_stats { * remote_ip (read-write) * local_mac (read-only) * remote_mac (read-write) + * @buf: The buffer used to send the full msg to the network stack */ struct netconsole_target { struct list_head list; @@ -137,6 +138,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 +1120,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 +1130,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 +1152,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 +1183,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 +1194,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 +1229,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 +1245,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 +1262,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 Thu Feb 6 11:05:54 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 862765 Received: from mail-ed1-f50.google.com (mail-ed1-f50.google.com [209.85.208.50]) (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 305DC2288D7; Thu, 6 Feb 2025 11:06:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738839973; cv=none; b=QED9ZsF6gtvTtl1Z8dPMGbyI3+z+HRLDwsE9krv9rC9E+uQNR/KVvddVLcdqDkfAN/nAoElM7xOuasFSdMd2lgS1/QJ0qniJ9yvpKAjV6sJCSabG59yvVhgWawfwBJXJCf/rDR+HUX1AlDsM5CL6wk1L0STTb7ZRHc8Wym/55w0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738839973; c=relaxed/simple; bh=+niiaHiskkhsTnTEZJ4wU+lHWH66HqehWyev2K0YeO8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ag1VjMY4qeVJufAS5W4Gxv74JD4YQqHy2ZGkcUCsBEdPQxZD62q6PZfOT37H7jVTNSVniZ8M14Hunq+MWjd8Zt1yPMoJHb7HxSgktIXMrg5eiHtv3oU75NhB8hIaAtsdIc9tN+7yT+EfLZiIJoiEq5NmyyFqfmWOTzW/J7PnD1o= 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.50 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-f50.google.com with SMTP id 4fb4d7f45d1cf-5dce4a5d8a0so1378037a12.1; Thu, 06 Feb 2025 03:06:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738839970; x=1739444770; 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=H/paCx3x7C5/fSrkE+t0Z5vy0JRj846fYPbO5BYY5RM=; b=hvt70c849CD/J4D6i4+nVfKxtZlpMfW7AN4NzWo48kMLUAediXnzLXuWaTG0TGdPcE u3YrVm/6WvyMc2546W/7EDmW9s2yOdbqEl6erzkrCIFKGNBQI889DwP0wo3mcLHasYRp C5GbDga7pmUeix80elMCf9piUwI5NXa+V7njqt7RDhBv/axJspYaRa0T+IEPgKZcXvv3 p3ED8aKvEWB6fSSQqUD4l3yg9u0uoMzWi5SDPKvecQk7JjO3CJE0kEjNdmMH2dCU01q6 dIi/MGO/Q6CFWbrmiIZKgynuoAXJT+GLoPfHknMZsdX8a67rYA0X4hPvmpFzWIERi7zs zk2w== X-Forwarded-Encrypted: i=1; AJvYcCUFnhC0jeRZsobGYJ0HA5nqrCzsCq/8NS90ZrfW2NUSOd+mKijzwrgZXRnjYwaUv99I+20lbcisVVgn9qiC@vger.kernel.org, AJvYcCXWteVEGH5Gkv7kr7USAVrGGYH0w3xTWTpr/Dne4ea9BTIv5ecupieBwXFZYLk6A5qFQ7bseJo930wpuA5HCCsn@vger.kernel.org, AJvYcCXqKIW1m9YfL9qz4/P8X5CN0isX3tYqzNL1WIJyIsk/xQnSi5+7+CKfDRG1y+M6CqxrBGk2sOtkM3I=@vger.kernel.org X-Gm-Message-State: AOJu0Yy8je6c7citG6ZQmkB+Skje8RCgs7FhYeAjAbpGANMBwC9w7z4x 9Xgqm2ZRcGPktkOre2bFSIaVzhVbzuS80vewk8u+ZU+WlwshcARq X-Gm-Gg: ASbGncs/NcRap/oq3DNTSoADc16cQykfDva7m3NW2bMyXAmYcTj8oD3IO+4dSAAI71v NXNlhVvqy+LNU9MEdDx+PpUaXWQO64ESKt3TvMV1mse3Yppu6aCKQ19K5yYB4o5xoOiKtpvr0+c MrceEzR5mXGF1y4vqCYgEhZuUEY7iOkAEPe4WDjXGZvJwY5RDFevaITUJzzaPPmEEDdCNLh7ppO H4fMi/WD0QgKAk1lysbSaU2i96lv2NrgAtqqWOeDaF2PAXrwuUV+SwlQIgtWokrU2lY7LGbz7EV UKs= X-Google-Smtp-Source: AGHT+IEB23Ju3E9DJMpJQ7MTISnaIRXQuB9GVRcsqItI9Ob6K6xPb6asE1TwgWbZmQ6kqdi3ciO6Uw== X-Received: by 2002:a05:6402:2812:b0:5d0:bf5e:eb8 with SMTP id 4fb4d7f45d1cf-5dcdb762d40mr14605385a12.23.1738839970108; Thu, 06 Feb 2025 03:06:10 -0800 (PST) Received: from localhost ([2a03:2880:30ff::]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5dcf6c9f93csm693345a12.51.2025.02.06.03.06.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Feb 2025 03:06:08 -0800 (PST) From: Breno Leitao Date: Thu, 06 Feb 2025 03:05:54 -0800 Subject: [PATCH net-next v5 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: <20250206-netcon_cpu-v5-3-859b23cc3826@debian.org> References: <20250206-netcon_cpu-v5-0-859b23cc3826@debian.org> In-Reply-To: <20250206-netcon_cpu-v5-0-859b23cc3826@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=2043; i=leitao@debian.org; h=from:subject:message-id; bh=+niiaHiskkhsTnTEZJ4wU+lHWH66HqehWyev2K0YeO8=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBnpJea/JQi1p4uc8Fv+crwWRCulPgJxkHpLTBfY tzjTiUmvQuJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCZ6SXmgAKCRA1o5Of/Hh3 bcs0D/9MAY7WpEi2yV+6kRBfWRZCF17lxg9vANvh891T6tnI1IBvZUkWGxJv2UwYsz96TbkQdOG Axk/KUmJkuo/wuXQlY6OpMHhMWlURmcpdOlOInmvxD7WS2f/7pBOcrjc2r3UWZE04snAVouAld1 mQpPBsceCnYjXvHsJuQFZFWu4FP4DtZEUD8fImt4Fgunwj9fOQu2HolzJ3AxTMB+pyCEdfgUX/w glWZYsnKaQ9xcbIFOWow/0ImdnkhirGh4NZ4v0BhRPlxtVX1Bs/rlmQRjKIkCXc0jJKWA2XWWq9 miQ8EAnywFvyb6NKgAkZMI3GsUoLMrwG76c7BAasRFgy08mxP6QidfTIGaf56hOXCgy//gUtw3K bWluO7Iafv5sqQyxyIY+AcfGvSc1bplNNcZGXLMQsty9UZoRoAmxO2uJoZzdRIdpCyRvfn0aJqI 67L1mJrzw2qkXCTDBeNmNW6f+qnCxPjj8FuCMBVbXxYdANActgtDkG9Ko5AwE56ziSYQCVzCGOs SGthkYCoI+dB7eGuGtDOG7auzu5oWUmDT8B68kL98q5n2mb4Lt6zcFaqvX8sBRVRI1Ee/TFJVtR mMy16/eUWGdmaNRi38TX23AN5PY5fS1ewKbiTY2ddoIWpd/SYEPwJPu9vGWhqOZ5z/M2lAS0bQj /wM6ykULEwJK3kw== 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 Reviewed-by: Simon Horman --- 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 7f05c7f74c31ce26a7329c784bd99305b7bea0e8..15daaba65c8827bf399f0623cc42d310626cbf68 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -662,6 +662,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) { @@ -811,15 +821,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 Thu Feb 6 11:05:56 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 862764 Received: from mail-ed1-f50.google.com (mail-ed1-f50.google.com [209.85.208.50]) (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 459AC22E3EC; Thu, 6 Feb 2025 11:06:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738839977; cv=none; b=Th3jzp6gOLXyk94blQcXil2YFp1iMnGH+82cdT9qxWk3p1uucw8q0As1SuXh3wYdyHMDscRd+lt0AffrMkM5HvWO7ZkYF0w+ZkDhY1VphhPu10qcq0Vj57xVySo07g8eGzzqcmch3cKAOOBd6Bgq9S4xe9c0h7GrJ+MmBvdZ51M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738839977; c=relaxed/simple; bh=146+Fd7GMEHjIB2x3rHlp8/1LduCZ88lYbm9gyDIpfE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=JxvVMOeq6+IALUnMtISrkls1onsPw4oiZG/9d3IZCsApTyh35UrHuGHsw/ceSEuAGnQpZQRpKXSXXIT2uE8X2qARlu7VKS2bO2fbBoXUNMv7UnMlsLKgPaFXbCoSBZ1K1+81iH2pKygKfFLgo8IcOCFLfD0jTpLMVvob0mJ8Ds8= 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.50 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-f50.google.com with SMTP id 4fb4d7f45d1cf-5dcedee4f7bso1188600a12.0; Thu, 06 Feb 2025 03:06:14 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738839973; x=1739444773; 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=v60yw++ddCI3iUtxUgKCBy+AvjYXItQZQ0qYmmzPQnw=; b=P4i8CDxsbtUCnaF+yiPtG3hBdpsOcjaxkpvRrTzd42I00jNkpmo4Hi4Mx9Yo27IgY0 u2YfOfJvdvOBAkOPwZGZA8Zoj5YvUYapABBLdkHrRXAhoWrGTuqmf2753X9Src1oJMSj fYWFjTq5iSfVvnbzyg1KVP0MsDser62MaW5kxH0Jlh4qNN80GMZSzkHKO/VcsGMwzk9S 0ocDjWdMBJ2PoV9BPMLBm1/No467s9Ci18XrizZmx5fixPwGtJCaWUw4UbbOO02i5oDt toZQVXQmLubCF+kbQRSMjNIvxHVKs0c3G5tVLsIhbeGurC4wFXCDCnyH8fpCE1DHRkdu EB1Q== X-Forwarded-Encrypted: i=1; AJvYcCVWSIwiLYpvHQoe2iq3s7KdSe2q4eoC6R09rqt+AuDN0C0iZoF4FG9X975/gUAQnWdFBZ9QL6JHvzk=@vger.kernel.org, AJvYcCVgeIbarB4ETZZX4YwOcSE5S2LDxA88Uy4ErObOtwLwyAhLujlwPuEJA1/D2tIzTkHxWenxJmhU4wYyeyIYg81g@vger.kernel.org, AJvYcCWABgtDlFmvPgdAoXYDht7JOdR2EY5J909qXJTkqCxvcNdVhfYPHYNeDIBl4tvy2cTSeykN3bjxuao1i+MM@vger.kernel.org X-Gm-Message-State: AOJu0Yw8p2vK0SZ8tRbQ2ncD4Lp3Dw5scXOWKcl8wbhEHZNAkhF7OF5c FLYPD76eLrpaXXzjQSbQwaWKUvv8TkjuEpnnG0XbAD2+P3IPKpkk X-Gm-Gg: ASbGnctJxaLTb3h20ZqXLdj90etI/rI2gdHs7wLR9CFsSWuT2Lqymw7flLVmSjIOc97 40rNvO4qBVao+ES8mM9hGOtIXmx3RzxyWXQE3DUIFE8thOdMoAjr8Pu/ugDSazkoXoNvxx24Ugr eAtDC/kO0UD9fDVpNbxOvlRSJk9ZQc3Ub3Fjic8AMx/7C0R5mmbeNI7cRysozwvJsZLOenxFSTF 9lu/w42fUjQfimwFSRwxCVnVvg4+OELSYkEobn+wY4X9sEe3XA3Xy2iigGSjIlxIjUCgPOmcu8+ OQyfTg== X-Google-Smtp-Source: AGHT+IG+p+1DmFFdJVRkJTROJXqXPU7O8SQKva/DWcOTuD4kF/FInXV/1u4PhkS+FyAj2Vl47BaWEw== X-Received: by 2002:a05:6402:388c:b0:5d9:8877:895a with SMTP id 4fb4d7f45d1cf-5dcdb732cd0mr7584773a12.17.1738839973305; Thu, 06 Feb 2025 03:06:13 -0800 (PST) Received: from localhost ([2a03:2880:30ff:4::]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5dcf1b990b6sm696427a12.48.2025.02.06.03.06.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Feb 2025 03:06:12 -0800 (PST) From: Breno Leitao Date: Thu, 06 Feb 2025 03:05:56 -0800 Subject: [PATCH net-next v5 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: <20250206-netcon_cpu-v5-5-859b23cc3826@debian.org> References: <20250206-netcon_cpu-v5-0-859b23cc3826@debian.org> In-Reply-To: <20250206-netcon_cpu-v5-0-859b23cc3826@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=1363; i=leitao@debian.org; h=from:subject:message-id; bh=146+Fd7GMEHjIB2x3rHlp8/1LduCZ88lYbm9gyDIpfE=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBnpJeanF6eo7+Yu1shhA89YfURblQQdN0terIOc aWg6lvKukCJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCZ6SXmgAKCRA1o5Of/Hh3 bY/SD/0TrSjAMOxvmMn+XwfcZfbi59Hy7YGIfYsbKgPZ1iuBAePpFATHQgBZKlTjxz8KnVfuXaS NtXZG4mK3XStf3Nm1m3wAjd4s8hti4X7WKm51zVr7UYmIPGjnV9eleaqkj0bmirQZPrpGaNSUck oUC38DVhDL0m6uAmGQQxcdAE+Lr5n5GQ9khjDh8/H2VXAjSJsa1FjNNK2E8wF+Ni6uNh2h8+blx DWthQJTqQvmOf8RfEf0Wetk9ZagcdYGRgV1eeJ0ZCsg2TyGbCMo60wk0ark4dsXpmfATHpHRZzw 6jqtmVD7C4RsOMswXMXqO19ryfxokVksbZqsDWSMaWowzLR9tBH1652XEe7PV2LMZphzrJMdWEm Z8HGEQ8UHroaiAszJ00YeCLhFXPP+EP2Y0I2YBzBCfkWm24s60ucx2E5FZk3hD7VT6rC5vDOMrm RhAqw31LPIxS3lcDrl6C1YjD57aQ+eLkqSJnpSIV9WZEmbfUqRj2zGWusteoPhFv9u/Uq6d5gqn bo6oAmlYNEsmIsOsQ/V03Qgi/mCAk9e9ws1tUDb+x21MWGRVWXZuw/lqUR0YctOQfRLEc3759CR AupCNQMPUg0YNE3Pz+f8tYO5Sl5gd2xPMKpRfntR6c+l2F8afyve6eDK6NR52zO4AO5dGsffGZQ vr2Vq9XSO/VPE+w== 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 Reviewed-by: Simon Horman --- 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 710330ae8ee462083dbb4aa889cb0ba0cb5a7475..50739c7dbfb6ad5b1a65ef33325cf4dd6ed02031 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -694,7 +694,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 Thu Feb 6 11:05:58 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 862763 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 91DBD22FDFA; Thu, 6 Feb 2025 11:06:18 +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=1738839981; cv=none; b=lwSs658WsDqVQxfoV33nmQZgBDKiP+XUl7W2nglStXg+5FPY7uhR9bGljm/xrHAZ5LutEg+jviUVIvCuI/oN8GCraP3Vmi7mliHsSSbgKL4SqW9XcJZ41RvLiY4geHVASzbOkId8JiBCVaqYhW9WSBOZoVBDHEexaX87fUr+9Ao= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738839981; c=relaxed/simple; bh=EWk2ay0albPWO0VUzwfvd3FuxFeaTYfwca4yspDY4GM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=uiWEqkx44Puh7K3pIHjCNIESeFyhuhc/sZIhMCSXJXPJm0D0ilAm1RYUlRKO2th6nf7y47K8gsTTYt+10oYkp0W68msrB8DdW/Eua7ZhiqShu2QcCk8nQp6qyyzh0DfcncNQ44GFQAxtuTL/U37A5KkrrdJymZvz4ls+JnJtZRw= 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-ab698eae2d9so144327066b.0; Thu, 06 Feb 2025 03:06:18 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738839977; x=1739444777; 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=+4lbmitZAUWzZsnieUUQwDFzsIag16/ARHCo65YqC7k=; b=LTM16u84GPge0C6kT6Wb7iiPHqPknW0Kj1nXt2LgbZJddcVtrC1qXfJquN4RpNB6Un 3IZv/k4sWNOrFDIOTB/s6kq5qRjyR6NDMUc0pLKO4W4yJyD/NmwtVeMglKZQi0Cbw6Yj vRyDV9Iwa1C6MX2ka5y0jrCc4mUmULkE63fW1/IxITQBVok2HQH5YRsXkojLdVVs0LQt ZtR7n1vBYgP+c7bkKBhWLoXfQCyHfZ5wAd/zPOAU9rMM2Zuim6acayZMY5uRkVzeqKGB Q/rSRUYDPV7hAAJIM7+3twfi3Qmo2DoLbV3ubpUn+LP6HZF79zFp81CAi9b9jVBjDmhc seDg== X-Forwarded-Encrypted: i=1; AJvYcCV+3riChSyYlyPWtW/MadyP9aEG1DewWL0q9XGpKkiDSFwh4PqeQi1pIcG79kDyNY3a/188P94TbFQ=@vger.kernel.org, AJvYcCWqG+v3QZwbU0bmLzakQRV9Mixd9WpZ+/Ur3nGPfeNilg6VpOxC3TFDBpRam5IKvMHIFf35iZQ7DG0zJOGubHoW@vger.kernel.org, AJvYcCWxknod9n4sXgPrwnqXgwQX8Yl6oOhEn3cYS/UWlCVQ4ELQN7G+kJuZPs4spI48fauhWjWfL3uJbDxC8ouX@vger.kernel.org X-Gm-Message-State: AOJu0YwESb/7Wd3SkclsUgPueGZJy6zIwZq2jISHsJTHmjr5koTRwfhX qk56Rx7l254BORxUjczXpYRiEsQ/IvHRR612AvIBxvOPca1ofAFq X-Gm-Gg: ASbGncuzwlRm9RxP3FTYguKcaucQLlbs5AkmSI7nyjb0anUAiwGNCMJUgY5OJfqC6by XBYg84wdVQuWHfwoHEDqQwhIrRALCllqCqhk6QDj9LT/uNFbWpMA4CEPfk6kGpmrii6i4rSVggg S+BrjsF7mkkj6xgl0GuLJcDYDamlJetnIsvhhJhI8LjMbxuxIbPWzHjrsDTZjVQNwNLigNmw/fM 1aipstIGbS9O3uFDzWmFpUYkEEbt4tKwPsKgUbALLDIUURe23BUaycmxZE2QfF8pA1opgnhGNrD kB3/3w== X-Google-Smtp-Source: AGHT+IFGhsz5+7kgfIZDY99QjO8pdL+augGLexBcLQ0bQftg/Zc2Eo5bX11/Iw+zA69dXn7JBR+Ebg== X-Received: by 2002:a17:906:3857:b0:ab7:6c4b:920a with SMTP id a640c23a62f3a-ab76c4b9227mr330324666b.6.1738839976563; Thu, 06 Feb 2025 03:06:16 -0800 (PST) Received: from localhost ([2a03:2880:30ff:5::]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab7732e61d1sm81399466b.119.2025.02.06.03.06.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Feb 2025 03:06:15 -0800 (PST) From: Breno Leitao Date: Thu, 06 Feb 2025 03:05:58 -0800 Subject: [PATCH net-next v5 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: <20250206-netcon_cpu-v5-7-859b23cc3826@debian.org> References: <20250206-netcon_cpu-v5-0-859b23cc3826@debian.org> In-Reply-To: <20250206-netcon_cpu-v5-0-859b23cc3826@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=7712; i=leitao@debian.org; h=from:subject:message-id; bh=EWk2ay0albPWO0VUzwfvd3FuxFeaTYfwca4yspDY4GM=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBnpJeaUSAo4i+K7MhatfW97K0yNTXh5oPZtS0MU RSwHb1lY6uJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCZ6SXmgAKCRA1o5Of/Hh3 bZWCD/983gGwIsnoH3FeBJ82Kf3H5RrV/Vj4ZFTw0pbRHhtq1tGPrtNZOLbYChWPEfuonUCSd96 QjR3CkSwgq+ciyAgky5up8zgXpm4SunxPTvHIsZmZ2jkogV0YgVopca4UF0KGv42Epxaoaykdxg 5GPLBs+J7oO/g97pymmU5tRDCyTplcLhCjTqw0WgsYmVe4IsXJcwfb0fbmd72zrZhdVlq66z5Qs n9MzdrUVs8Uy9vq5gkUQnf3t9Mem6GSc0GHnSnPnZAF5gS+hFQR0KCPsabIDwaayygjrS32NGKa FKBLVZc5xgqEVbLdWGuJk4QOxwkeM9Ntyc9X3k41+qheylVpEjyX0Tuqpvl4LJiXI3+lwppfFkJ eltLXf0brq2Jsr1TbskeyZ8M4tIU0bITHNBsx8XMAYW48OoR/cl1fhSvhY8wY2fnZfdpSTKEES8 KGKZtSlYMf+MBYVIfwgdJI+lX0zEmrQAfGF0y2NssH+c00U+1a8IeRZXf6xZIOPbyDtYQiRnKho ziC7tKqKjn84WGU2fzkwnEP9PLwQoHe5hzbQCtTvz6vNN9RcKKlyzFxf5J2meq1F65gMv0ndksG bWOrjuJMnYRknnm0aFG1KUFBh0IXR3ay/9dAROjRoMedEiiEUpbMo5lZDdeaZD5a4lwJxJS/Dnx +w50GGEpvOCAnqQ== 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 Reviewed-by: Simon Horman --- 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 c7f1c443f2af091aa13f67dd1df9ae05d7a43f40..28b6d47f812dd23dfed89599b6edb020671f8242 100644 --- a/tools/testing/selftests/drivers/net/Makefile +++ b/tools/testing/selftests/drivers/net/Makefile @@ -9,6 +9,7 @@ TEST_PROGS := \ netcons_basic.sh \ netcons_fragmented_msg.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 0c262b123fdd3082c40b2bd899ec626d223226ed..3c96b022954db9e21216950b1c13431c313ed4b5 100644 --- a/tools/testing/selftests/drivers/net/lib/sh/lib_netcons.sh +++ b/tools/testing/selftests/drivers/net/lib/sh/lib_netcons.sh @@ -230,3 +230,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..2b78fd1f5982fee81b379bf9ac6f64a38d915974 --- /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_enabled" ]] + then + echo "Populate CPU configfs path not available in ${NETCONS_PATH}/userdata/cpu_nr_enabled" >&2 + exit "${ksft_skip}" + fi + + echo 1 > "${NETCONS_PATH}/userdata/cpu_nr_enabled" +} + +# Disable the sysdata cpu_nr feature +function unset_cpu_nr() { + echo 0 > "${NETCONS_PATH}/userdata/cpu_nr_enabled" +} + +# 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}"