From nobody Thu Oct 2 09:17:07 2025 Received: from mail-ed1-f51.google.com (mail-ed1-f51.google.com [209.85.208.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 8E9C128368A for ; Thu, 18 Sep 2025 10:42:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758192140; cv=none; b=gVqNaoY71VJ9LspqbSYIqzvRe2PZYM8mLCe36/lM8ZRXfyOhPP5KqlT03mXalvlbxczolneMRjwnHpzjoy1zWSqGzYGoNrnAIc4Z5TKLJhCWOADqlHIpk4O3PkguhqYj4WIw5BLS+32SnSN5RAthFb/e02pS1ouDgfSvKENRv2Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758192140; c=relaxed/simple; bh=0qblMs7pvAvukMaqH1XZzSc/HsAgRmJmnlAnkCtcl+M=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=G0jUWJRzJIpt+YpT0c/BiEgjzwfD+ma93c4+nyCA45PBPq7JeDWDjG9ZGNRApg+ijNwqIF9MKn9z2nGSUug6uPbChnSSeYCL//WV18A28SJh1D+KpU80jm73rbuzzPXS6Oo/nKAHjnIV9vsgIjCdxZo1cy5H7Mejy7Jx42K4fuQ= 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.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-ed1-f51.google.com with SMTP id 4fb4d7f45d1cf-62ec5f750f7so1339778a12.3 for ; Thu, 18 Sep 2025 03:42:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758192136; x=1758796936; 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=9cRw8y8aLRwmgMXJrfhUT0H+SQQUEvdJ4IqhIR3aLXE=; b=dmJQveDeoWZc7OlTNPEwjBRWwgVPAcwnNuI+aMIqFsWkG9MWx1Pyty35arIeaWJ5Ce u193JoFzXFkqEl3/DjUtFcay6ispilHMmEjyJ+z9ckb2zGiDa8zQ3Y48uW6b8bdmbX+4 x8a6mB1KV+tkcEYvZDkkFLlmyTBWWeOjYCmuB7sFeap/d/Qe4iSKzMEOYGYdX0gZKny8 jGKjOwNDozQvz9VnZZXEKPxsuc1lBGvqR+kv6uU7986rddVCJo3CIPsH6++iDHxazqk6 j01Cz+gtmlEVTUqc+GmwyG+CU5qMVus0aAXRGEO4SJmuA01qobmTTUAWUnwK4WVUhQ/W VZkg== X-Gm-Message-State: AOJu0YxcW7qHASGVz33n7rhhKRehtl9yevkS6rOhhGrV+jsTT5qe4Toj kYC0qtEcfDPNq3J+eG5Gu2k0QIg/EBhH3vUYfmw/nzwXErS/8C/dsULe X-Gm-Gg: ASbGncvi/zQYcQj9bYRunszlk+3pwighBjRwxUKp2ixxNuCya2GwgUnRZVAsX4+9S/j eA5QgKlK5Ueup5R5rOvt4GiDq3nZmWYAF3oCd9Pq6xUf7ORT8x/dbLyDA55+ukK2NJtBdRrw7on wKiyg9hH6tmF389mQ9TuU7H2vi8G7q8S6VANyNE7AGaz3lgsnqqyfbIQWKLtvxLuq9JGbxTCmU1 mk295b3IeeM4UFsnPj1+b+HwZ29kOSzhUQiBMMeNakFdMvuOfM9lLM/OzJI2dBaUxAxhrkaqaMi JUCPQoziLju2itRZpI5NsAxGdMovlJWFrj+2W1xHwXwVH3g2Te/9UFoHqtesmOJPu0qm4R2/X5m XZZP94l9eofh2DChQvBhStoed/rTievE= X-Google-Smtp-Source: AGHT+IEen4VTSshGtU3k73aBIzuXFSnZy2lHMd9isfLbu7lLEngvBaj6Hd/jeZSUE4Vng9OKkRulaQ== X-Received: by 2002:a17:907:3c90:b0:b0a:333:2f97 with SMTP id a640c23a62f3a-b1bb7f2a341mr613829266b.37.1758192135547; Thu, 18 Sep 2025 03:42:15 -0700 (PDT) Received: from localhost ([2a03:2880:30ff:6::]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b1fc5f43884sm173998466b.3.2025.09.18.03.42.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Sep 2025 03:42:14 -0700 (PDT) From: Breno Leitao Date: Thu, 18 Sep 2025 03:42:05 -0700 Subject: [PATCH net v5 1/4] net: netpoll: fix incorrect refcount handling causing incorrect cleanup Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250918-netconsole_torture-v5-1-77e25e0a4eb6@debian.org> References: <20250918-netconsole_torture-v5-0-77e25e0a4eb6@debian.org> In-Reply-To: <20250918-netconsole_torture-v5-0-77e25e0a4eb6@debian.org> To: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Shuah Khan , Simon Horman , david decotigny Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, asantostc@gmail.com, efault@gmx.de, calvin@wbinvd.org, kernel-team@meta.com, calvin@wbinvd.org, jv@jvosburgh.net, Breno Leitao , stable@vger.kernel.org X-Mailer: b4 0.15-dev-dd21f X-Developer-Signature: v=1; a=openpgp-sha256; l=2686; i=leitao@debian.org; h=from:subject:message-id; bh=0qblMs7pvAvukMaqH1XZzSc/HsAgRmJmnlAnkCtcl+M=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBoy+IEkg4upfaClHOYSMpVXOdvghNm1AX/xX9xQ E7C4l8p1CqJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaMviBAAKCRA1o5Of/Hh3 bRDHEACE+pWQpKmGFKBg2obJPsqbG17N51Rjp/3+eJPs1geX03/x0rU7llUqu8zKj48ZxwUn123 oAQXLBUqFqXpzFERQHVZHdKbhELy0bbRxxufyPN+RPkOOjTAvN8Rp2mUYvKqAsFW8aAi+MvyiB5 hXmuxMm8Vd3KHbVSnF5wFj4+jAPinZb/r/qhkUdxF9CsoHED0yZULlHCtqYMo8i37xxqPGXTM/D z2ofBArf0qCgbYSVeuRJJ9tKKr431dXLi0ZSdOm/J5OT5J6JkgU9ilRGSAzijjUTuS7GqJWOOEj emVUvt2yG20XQCfkt7G7pN1ib9OM3vQxrQYXrv+5t2b8br6tqqPOo0irlw7bhBE7SISP0o16YHr 5akPpO0ez5Jhda79rDFEuTDD3KSRrJYEeGats53T8uaM6YoSSYj/AzHWsVIYnz6VkXS1yu5jUR2 VRLg3DLeSnbuFNs/C9Ak6tAJeO0h4usrWhDnpGsS0Qo0LOtVAo3QrUXqm7THxmhYaYwnY3BdLSy eC3uAwOpw7VxKYRAY4Jm0MzsGye/8dpy0Fo2qAJYy7ot70SDVe/ikfZMWaIDmp13nWYK24ilgs/ x8mqmuEFYjktZ0rn8Dl63ok9w5EQMYdlteorbgFDZXPmiLubNZnnjukm6rhQoSUar5paKAVlFV4 qgfg8owAi/QARkg== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D commit efa95b01da18 ("netpoll: fix use after free") incorrectly ignored the refcount and prematurely set dev->npinfo to NULL during netpoll cleanup, leading to improper behavior and memory leaks. Scenario causing lack of proper cleanup: 1) A netpoll is associated with a NIC (e.g., eth0) and netdev->npinfo is allocated, and refcnt =3D 1 - Keep in mind that npinfo is shared among all netpoll instances. In this case, there is just one. 2) Another netpoll is also associated with the same NIC and npinfo->refcnt +=3D 1. - Now dev->npinfo->refcnt =3D 2; - There is just one npinfo associated to the netdev. 3) When the first netpolls goes to clean up: - The first cleanup succeeds and clears np->dev->npinfo, ignoring refcnt. - It basically calls `RCU_INIT_POINTER(np->dev->npinfo, NULL);` - Set dev->npinfo =3D NULL, without proper cleanup - No ->ndo_netpoll_cleanup() is either called 4) Now the second target tries to clean up - The second cleanup fails because np->dev->npinfo is already NULL. * In this case, ops->ndo_netpoll_cleanup() was never called, and the skb pool is not cleaned as well (for the second netpoll instance) - This leaks npinfo and skbpool skbs, which is clearly reported by kmemleak. Revert commit efa95b01da18 ("netpoll: fix use after free") and adds clarifying comments emphasizing that npinfo cleanup should only happen once the refcount reaches zero, ensuring stable and correct netpoll behavior. Cc: # 3.17.x Cc: Jay Vosburgh Fixes: efa95b01da18 ("netpoll: fix use after free") Signed-off-by: Breno Leitao Reviewed-by: Simon Horman --- net/core/netpoll.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/net/core/netpoll.c b/net/core/netpoll.c index 5f65b62346d4e..19676cd379640 100644 --- a/net/core/netpoll.c +++ b/net/core/netpoll.c @@ -815,6 +815,10 @@ static void __netpoll_cleanup(struct netpoll *np) if (!npinfo) return; =20 + /* At this point, there is a single npinfo instance per netdevice, and + * its refcnt tracks how many netpoll structures are linked to it. We + * only perform npinfo cleanup when the refcnt decrements to zero. + */ if (refcount_dec_and_test(&npinfo->refcnt)) { const struct net_device_ops *ops; =20 @@ -824,8 +828,7 @@ static void __netpoll_cleanup(struct netpoll *np) =20 RCU_INIT_POINTER(np->dev->npinfo, NULL); call_rcu(&npinfo->rcu, rcu_cleanup_netpoll_info); - } else - RCU_INIT_POINTER(np->dev->npinfo, NULL); + } =20 skb_pool_flush(np); } --=20 2.47.3 From nobody Thu Oct 2 09:17:07 2025 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 16A8F2E040C for ; Thu, 18 Sep 2025 10:42:18 +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=1758192141; cv=none; b=flk2OU01XMfjRfRseDjQZeoD0E/tRKXzADVOZ2UBfeVfKChJP/7WSz0RwBy3DwvQxVp7xidSTVI+zkvA4GaCHWvMR14/fhmpvCwlPGhbP4oD7RKcJme/ffNQvQiOEk6b+gsaFyYaZhaSgjbrRpUUvzBdArUYliUIQrRjjqwX2rA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758192141; c=relaxed/simple; bh=g8Rymja0V72nq6OnDIyWQadzgQlOQaCKBNDvE6hktyo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=geOl2G0IySXY7nUuZ9P0qXvrhG7OLmT2jmX+fKymo4TfoCB7m2qJ9EAY+Gz7ad5WxdVpCuttP7dBZBwzcS9IF6jI8wnywjMEup+XQh8WYlg4XOCQTJJLTWj7yc7khnv1XJCNN+j2J64lRsw0UrwG/T0yxJ8ceAlNZLNLkiCAzbc= 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-b042cc3954fso154284966b.0 for ; Thu, 18 Sep 2025 03:42:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758192137; x=1758796937; 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=Hnf8G2/o1fozlbYtBL0vduYZr+SYz2Fp67m1oGmqTd0=; b=bVPpqU3mAKh+ApZV4B7TUIvCgGGLdtB0trtTvb8Ryoy8n7BQcRPfk3+xPSzrE1zw24 SLYhB3s7wnSpGdHX5dthUO7MPX6fX/IwhOmjIvgJvqx3dA544vUZTuEUSTtmuoxg4NZv vYD1VGoP3AIoTYe9e3eJp945Op2cAMAXNvJro8SoUwJUwjHsd8PzY8BrzVn77sxSRgJe M2n+QoDy7ko+bTBumb4ExfPF6gEbGJqPZxEBA+tWK+MO65P306+zNl53BsJFdjtopwXx w9Ge7LP78S9VGk3G4Jzdk2rNpCmcXbhaAFaQvputuzp73lIdgmNnLhoUT9uNaZY5kyYA B4tQ== X-Gm-Message-State: AOJu0YyMgLT3T5QP8nD/Ub5smBqdi13BuKf8nF1mEkMPwDYROwmeZHYw 2mbuJa9mZ7S1vcuLYxoA/geZOzKFJtcEQHBJP3xyGopdy4ToAfx4GQjF X-Gm-Gg: ASbGncuHcFWa4yO2jw6zJe2D8HH/sFs/tItf1t6ev6yk1k0Ex4YqGBQSkoX6I39ce+y r/mb9vbUY0kMEK293FK2NlYH1E2CeXksNlm3GBgMQ3cFKvZ0+bQIaAIupmiq2cC5rkGI2U+/HiP kh+NE/qFPT2UHeAsQWn/4eamLe8jMJFvAjkF4QIsRCru7+eFXcCzMx59rFh29ebmEzTva0UzCM1 cUAE6578AgilyFxN0+meSkuRs+TL7pPemVlVYl8RN85iX4sR+dQmkfSzJCb68n6jUZijXft5gBy cs/Y/sR3qPkroxx+sfpd6dvgNQ3PQn82ML9ptJwt9WjPwaUBUFBkOyeQflSDcM8mcCQ9wXcOzO0 nk3MwpglNCqJAqjDi7wpbmzbTJTBXXajQi+5YZaFGOFY= X-Google-Smtp-Source: AGHT+IHZ76Ty7W0omcpdo3n5MkN3sf6Q4OcP/Bdw9ZDtOAwYzRo7981Z0ymOu7nfRAbVU1mgwU++uQ== X-Received: by 2002:a17:907:3f92:b0:b07:c1d1:4b66 with SMTP id a640c23a62f3a-b1bb0a58881mr566493066b.14.1758192136915; Thu, 18 Sep 2025 03:42:16 -0700 (PDT) Received: from localhost ([2a03:2880:30ff:41::]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b1fc5f43879sm173383366b.7.2025.09.18.03.42.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Sep 2025 03:42:16 -0700 (PDT) From: Breno Leitao Date: Thu, 18 Sep 2025 03:42:06 -0700 Subject: [PATCH net v5 2/4] selftest: netcons: refactor target creation Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250918-netconsole_torture-v5-2-77e25e0a4eb6@debian.org> References: <20250918-netconsole_torture-v5-0-77e25e0a4eb6@debian.org> In-Reply-To: <20250918-netconsole_torture-v5-0-77e25e0a4eb6@debian.org> To: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Shuah Khan , Simon Horman , david decotigny Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, asantostc@gmail.com, efault@gmx.de, calvin@wbinvd.org, kernel-team@meta.com, calvin@wbinvd.org, jv@jvosburgh.net, Breno Leitao X-Mailer: b4 0.15-dev-dd21f X-Developer-Signature: v=1; a=openpgp-sha256; l=2478; i=leitao@debian.org; h=from:subject:message-id; bh=g8Rymja0V72nq6OnDIyWQadzgQlOQaCKBNDvE6hktyo=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBoy+IEgwKHhN8NHKFIUq0Vt3srwkf2ttcLoURlY hzNAvymcd6JAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaMviBAAKCRA1o5Of/Hh3 bbMuD/9ibiWGvzvApY+fBVKhaZM0LGqn9Oip3ni+snNHPdKRVDyLJYlTgNXb9V8vR6ip/8XAKKO D5uOPpwPkJyt3WMpHIPyWeQudIgJv/8b4id7rKfTuxsclBKj7N5UI8wjcOa2rrf3Pv6S7UeHN4i kgsfcHQX53pFlNwCxwgBLRYRKcgxiLKAg6fDPpoAMLQOqigGqBYNqMmVEAqygaxf2yEYxlI+17i kK94C+s4mf94LOER7dFm1XOGCXRPMhltb33JaTSWDY4XI2OjEqKYBKYscaEzTLurVY+g0/4YkF6 4YeD1VanH3qOqcDy+we+OVWpAOzNPPQOwZxOZVWKBl0iyaylbvKSKxAizn064Z5kMam4/2RMD+x 5K5jGiawNdojFfxsooK7EFnU/zyuT1GBHWiyCCGRn+cnS4WTP3V763y+z4177HWjd+uLFPvzGbb 3O1rnUR8yWWlz2suewde6z+rlAP/jNqEmtxSbVYcI/1Kx8mzRfbmnfWuDpmMwvYHCFnwLYkbG1a wCaE7EHZorMM8sEvNxQec8y3q4xhA5++EIyTjw6LNLbojYMKhryi5Hg8XVb2P+eqrKvLIXa3PiN AkYP1DT0t3kdEHxxPZ1UYaVYpLlkUbIQcZ/gdcKsHnJglQYyTaHOM7TYxdGQ3Hh4QerpCPsDmxz P3bTQgr+qMJ6wCg== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D Extract the netconsole target creation from create_dynamic_target(), by moving it from create_dynamic_target() into a new helper function. This enables other tests to use the creation of netconsole targets with arbitrary parameters and no sleep. The new helper will be utilized by forthcoming torture-type selftests that require dynamic target management. Signed-off-by: Breno Leitao Reviewed-by: Simon Horman --- .../selftests/drivers/net/lib/sh/lib_netcons.sh | 30 ++++++++++++++----= ---- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/tools/testing/selftests/drivers/net/lib/sh/lib_netcons.sh b/to= ols/testing/selftests/drivers/net/lib/sh/lib_netcons.sh index 8e1085e896472..9b5ef8074440c 100644 --- a/tools/testing/selftests/drivers/net/lib/sh/lib_netcons.sh +++ b/tools/testing/selftests/drivers/net/lib/sh/lib_netcons.sh @@ -113,31 +113,39 @@ function set_network() { configure_ip } =20 -function create_dynamic_target() { - local FORMAT=3D${1:-"extended"} +function _create_dynamic_target() { + local FORMAT=3D"${1:?FORMAT parameter required}" + local NCPATH=3D"${2:?NCPATH parameter required}" =20 DSTMAC=3D$(ip netns exec "${NAMESPACE}" \ ip link show "${DSTIF}" | awk '/ether/ {print $2}') =20 # Create a dynamic target - mkdir "${NETCONS_PATH}" + mkdir "${NCPATH}" =20 - echo "${DSTIP}" > "${NETCONS_PATH}"/remote_ip - echo "${SRCIP}" > "${NETCONS_PATH}"/local_ip - echo "${DSTMAC}" > "${NETCONS_PATH}"/remote_mac - echo "${SRCIF}" > "${NETCONS_PATH}"/dev_name + echo "${DSTIP}" > "${NCPATH}"/remote_ip + echo "${SRCIP}" > "${NCPATH}"/local_ip + echo "${DSTMAC}" > "${NCPATH}"/remote_mac + echo "${SRCIF}" > "${NCPATH}"/dev_name =20 if [ "${FORMAT}" =3D=3D "basic" ] then # Basic target does not support release - echo 0 > "${NETCONS_PATH}"/release - echo 0 > "${NETCONS_PATH}"/extended + echo 0 > "${NCPATH}"/release + echo 0 > "${NCPATH}"/extended elif [ "${FORMAT}" =3D=3D "extended" ] then - echo 1 > "${NETCONS_PATH}"/extended + echo 1 > "${NCPATH}"/extended fi =20 - echo 1 > "${NETCONS_PATH}"/enabled + echo 1 > "${NCPATH}"/enabled + +} + +function create_dynamic_target() { + local FORMAT=3D${1:-"extended"} + local NCPATH=3D${2:-"$NETCONS_PATH"} + _create_dynamic_target "${FORMAT}" "${NCPATH}" =20 # This will make sure that the kernel was able to # load the netconsole driver configuration. The console message --=20 2.47.3 From nobody Thu Oct 2 09:17:07 2025 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 1C86B2FE56B for ; Thu, 18 Sep 2025 10:42:19 +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=1758192142; cv=none; b=a/RbzSGuW+Or7Pamde/ntJCPa0VzRGpdy1FydqgV2Wil7DZHrmcKcytHVG+Eo7OSUNeTFhscJoMO+OY5iCW5XTo6WGDklwFSswR1M3gl5+jhyykK4KjCjadwySByvbvIHOdJ4Izehfq9+6AipZGmFSgDL7m6LChZ8ZaejGr9ndQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758192142; c=relaxed/simple; bh=njsWipcAw6zDiWuPvoBPcLtz4KDuk27UDraQiXEyOh8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Eqm/CkualNNGgJ4Qij++xVnv/FK9h2BGTyuunIukkVuiI9rdQQWsJNuIetQiTp5myzjJBhyNNsggvqGv/wnLDb+HOlVZnA6mf8XvnVPVWe2Z33JsKLZGJtqR9Pa2cO1rGw6PzVJ1sDuLnRaP8yOn6XIRDAY26uM7wrTDbVvPdbk= 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-b04770a25f2so126408666b.2 for ; Thu, 18 Sep 2025 03:42:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758192138; x=1758796938; 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=/XoyvrHtWDXQ1aF+5AGUr+W6S/qx0Hv9FBJ5bml0jjU=; b=O3cefy+t5o6vKtVp2ROeYUmKzsu3eyUGGVTArN8yvEE2aiDDGvozhVBJQqRqPmAty1 YPpBAWO5wfcD1jV0XZprWI3VvblOs3gd1X1GAsT/0vdvpensXs0YUfMh92A982ExgDIB 6nwj3y5fgnOsf1D4JsmJ1LYKQC2FyY2uqiIP9yRi+PrsWDkoLjearvdVgUpijyYOQNHV n+JKPxdTwy6cMhALjjqFUbDJ009EWbw6YwNQfKNolbXTvY/Vc3fhx+TpbNVyhrbfJfZz 4ZDeDvMi64o0hhMDJG1gK+oYxr3JW9RHfKDyE5N6GCH+A5y5Ip7sPdKM45riWn3SE/0Z kC4A== X-Gm-Message-State: AOJu0YyDSJ+VQRNlQ8TsvCHInUWKFooWrXgxTkz5Zy4S0+keCXSklPiJ z+wuuhMbMRmFJV2lZAQprMe9DUzV1S59+PTe7I7FDGYd6gMjHqq00LNm X-Gm-Gg: ASbGncvSNW2Z4OsCAwHGqTjsZGh+leRFnylSy1Vy5mivD7Uo0ZO0peuEwk0gtXYwEcC FxW6maY/wymc5K3UIl9tqxsapsg7SV2gxxkejv1XaeFf6uCD6r6V8N0n2XqAo8WaMnkLZx/mHFm xM5emXbBqFAm2ylsn3Z1lSl1kdKnKxbKXGQXLRoL11/d0R5hfEXieaWzN3cbuvMN3Ztfogsu7b7 WcWcBZNQ4NNA7SYBki9pLh2vRxtkR3h4LIekqm+OQjBgexSotdmRsbtjJS3sfb+S7y9fmOcb0z+ 80/Uzl4DDoD4+bUGFpG4wrX4plWDFkw3pGJw2PANcFnWZhU8Q50cDS95gPiWnsqYYZnxTepaWyn R5XOVGxksPxB7gMvmqC8sbwShqRxTBn0= X-Google-Smtp-Source: AGHT+IE92BVFrQCBsR676S80PJ/8gUcq+eiiRVuAaXrNsNJAA15CFSCVcQfNzvpwZlkxIxTyuZ2zOg== X-Received: by 2002:a17:907:6d11:b0:b04:5cca:9963 with SMTP id a640c23a62f3a-b1bbb0678d1mr596051466b.41.1758192138250; Thu, 18 Sep 2025 03:42:18 -0700 (PDT) Received: from localhost ([2a03:2880:30ff:9::]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b1fd110259fsm168886166b.90.2025.09.18.03.42.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Sep 2025 03:42:17 -0700 (PDT) From: Breno Leitao Date: Thu, 18 Sep 2025 03:42:07 -0700 Subject: [PATCH net v5 3/4] selftest: netcons: create a torture test Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250918-netconsole_torture-v5-3-77e25e0a4eb6@debian.org> References: <20250918-netconsole_torture-v5-0-77e25e0a4eb6@debian.org> In-Reply-To: <20250918-netconsole_torture-v5-0-77e25e0a4eb6@debian.org> To: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Shuah Khan , Simon Horman , david decotigny Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, asantostc@gmail.com, efault@gmx.de, calvin@wbinvd.org, kernel-team@meta.com, calvin@wbinvd.org, jv@jvosburgh.net, Breno Leitao X-Mailer: b4 0.15-dev-dd21f X-Developer-Signature: v=1; a=openpgp-sha256; l=5260; i=leitao@debian.org; h=from:subject:message-id; bh=njsWipcAw6zDiWuPvoBPcLtz4KDuk27UDraQiXEyOh8=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBoy+IEovc49EgP5d4GjkGG1zgN4ovby5/JpB/Gu bWxpeoknFuJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaMviBAAKCRA1o5Of/Hh3 bUcVD/oDDzmOZ/WDmw4umwdzF5PpslmCzGqFdnd/3/MODVV6eTR5YoBX/oi6j5rXsr7S3EWNp/d f3ANYb2uFJGznNnE9XNH65XPMHc/I4qKgB3n3MVsYIMv9lAZtmy+5vlZGMg3/cI2J/+MdwlK3zW FnGCOGZlqy1wad42ip35/RYKTLOD7XjFTMfplQJPskqgegn1NTy6Y9Wm8nBsZfzm3uICHzajxZn M9CjU5XmM0pTYug4g2UlfrMsKbhnK+Zj5MGgJGlS9E8nixYoj+qO50re1lS9iu0VBpjBOkxfXKf 53sePs+4XNcd81g3m37vtkPFCbDVbsUnFlAc8iwKC11Bs5QMiyTB4DHA4IahWP3KSYsAWmJLEJp hYdq+ROdFTpJhSPiJp+jxVFdsp9fHayfLE3j/4iHwdzUsWJOrIpRW8pVSuJVE1gNb+DL9fXH0or 0xrAerAVhVtYYW+skruPndxTCqJuEQoWP/jxmjfkhPmKUFAtCystb/dF1l7nSaR+fp82Lf27JBF nd6Lo8k38F3racYpgnnng+ddgJxqC80Vwuair90h+bwvjRzBy6/PrP8CCwv+z1XQwWVQm1Wv4FM TpLP/I2sBABwftn36Yks4msnf4aXvciaYs9PJAtefaYYC0dWdb3dkU+iBfY/mfa0sGRrmHTocQ1 RMlF9QtzlesOqSQ== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D Create a netconsole test that puts a lot of pressure on the netconsole list manipulation. Do it by creating dynamic targets and deleting targets while messages are being sent. Also put interface down while the messages are being sent, as creating parallel targets. The code launches three background jobs on distinct schedules: * Toggle netcons target every 30 iterations * create and delete random_target every 50 iterations * toggle iface every 70 iterations This creates multiple concurrency sources that interact with netconsole states. This is good practice to simulate stress, and exercise netpoll and netconsole locks. This test already found an issue as reported in [1] Link: https://lore.kernel.org/all/20250901-netpoll_memleak-v1-1-34a181977df= c@debian.org/ [1] Signed-off-by: Breno Leitao Reviewed-by: Andre Carvalho Reviewed-by: Simon Horman --- tools/testing/selftests/drivers/net/Makefile | 1 + .../selftests/drivers/net/netcons_torture.sh | 127 +++++++++++++++++= ++++ 2 files changed, 128 insertions(+) diff --git a/tools/testing/selftests/drivers/net/Makefile b/tools/testing/s= elftests/drivers/net/Makefile index 984ece05f7f92..2b253b1ff4f38 100644 --- a/tools/testing/selftests/drivers/net/Makefile +++ b/tools/testing/selftests/drivers/net/Makefile @@ -17,6 +17,7 @@ TEST_PROGS :=3D \ netcons_fragmented_msg.sh \ netcons_overflow.sh \ netcons_sysdata.sh \ + netcons_torture.sh \ netpoll_basic.py \ ping.py \ queues.py \ diff --git a/tools/testing/selftests/drivers/net/netcons_torture.sh b/tools= /testing/selftests/drivers/net/netcons_torture.sh new file mode 100755 index 0000000000000..723aa2488c19a --- /dev/null +++ b/tools/testing/selftests/drivers/net/netcons_torture.sh @@ -0,0 +1,127 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: GPL-2.0 + +# Repeatedly send kernel messages, toggles netconsole targets on and off, +# creates and deletes targets in parallel, and toggles the source interfac= e to +# simulate stress conditions. +# +# This test aims to verify the robustness of netconsole under dynamic +# configurations and concurrent operations. +# +# The major goal is to run this test with LOCKDEP, Kmemleak and KASAN to m= ake +# sure no issues is reported. +# +# Author: Breno Leitao + +set -euo pipefail + +SCRIPTDIR=3D$(dirname "$(readlink -e "${BASH_SOURCE[0]}")") + +source "${SCRIPTDIR}"/lib/sh/lib_netcons.sh + +# Number of times the main loop run +ITERATIONS=3D${1:-1000} + +# Only test extended format +FORMAT=3D"extended" +# And ipv6 only +IP_VERSION=3D"ipv6" + +# Create, enable and delete some targets. +create_and_delete_random_target() { + COUNT=3D2 + RND_PREFIX=3D$(mktemp -u netcons_rnd_XXXX_) + + if [ -d "${NETCONS_CONFIGFS}/${RND_PREFIX}${COUNT}" ] || \ + [ -d "${NETCONS_CONFIGFS}/${RND_PREFIX}0" ]; then + echo "Function didn't finish yet, skipping it." >&2 + return + fi + + # enable COUNT targets + for i in $(seq ${COUNT}) + do + RND_TARGET=3D"${RND_PREFIX}"${i} + RND_TARGET_PATH=3D"${NETCONS_CONFIGFS}"/"${RND_TARGET}" + + # Basic population so the target can come up + _create_dynamic_target "${FORMAT}" "${RND_TARGET_PATH}" + done + + echo "netconsole selftest: ${COUNT} additional targets were created" > /d= ev/kmsg + # disable them all + for i in $(seq ${COUNT}) + do + RND_TARGET=3D"${RND_PREFIX}"${i} + RND_TARGET_PATH=3D"${NETCONS_CONFIGFS}"/"${RND_TARGET}" + echo 0 > "${RND_TARGET_PATH}"/enabled + rmdir "${RND_TARGET_PATH}" + done +} + +# Disable and enable the target mid-air, while messages +# are being transmitted. +toggle_netcons_target() { + for i in $(seq 2) + do + if [ ! -d "${NETCONS_PATH}" ] + then + break + fi + echo 0 > "${NETCONS_PATH}"/enabled 2> /dev/null || true + # Try to enable a bit harder, given it might fail to enable + # Write to `enabled` might fail depending on the lock, which is + # highly contentious here + for _ in $(seq 5) + do + echo 1 > "${NETCONS_PATH}"/enabled 2> /dev/null || true + done + done +} + +toggle_iface(){ + ip link set "${SRCIF}" down + ip link set "${SRCIF}" up +} + +# 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 +# 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 "${IP_VERSION}" +# Create a dynamic target for netconsole +create_dynamic_target "${FORMAT}" + +for i in $(seq "$ITERATIONS") +do + for _ in $(seq 10) + do + echo "${MSG}: ${TARGET} ${i}" > /dev/kmsg + done + wait + + if (( i % 30 =3D=3D 0 )); then + toggle_netcons_target & + fi + + if (( i % 50 =3D=3D 0 )); then + # create some targets, enable them, send msg and disable + # all in a parallel thread + create_and_delete_random_target & + fi + + if (( i % 70 =3D=3D 0 )); then + toggle_iface & + fi +done +wait + +exit "${EXIT_STATUS}" --=20 2.47.3 From nobody Thu Oct 2 09:17:07 2025 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 BCB8B2FFF84 for ; Thu, 18 Sep 2025 10:42:21 +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=1758192145; cv=none; b=RZhhi2CndhT8iY+sEJktoe/oPSRWrKGGTZYico5hU17qN9urNYRz5j0sChDt48RbOslh6LMeQb5SeZ37BWQGwCrxZ+sZg6Y18OD1PTvZtn0u0NFlkULNC2ynV3hJJFEmN9K8aFd8Uq0+3eOOEmNs/6k6OiADQWLzXPgF2ewYXR4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758192145; c=relaxed/simple; bh=UPOeRaoIL7DJ+4Ij9UByVGp65lQeUNBpRGIjUXmOtj0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=meLhCFNkt+1mvoefD+1eSq0m1tKes3PrBERq9XhzXwxzT88ncTcoCI1Sds6d3WYrdAWKMLqtNdZcalGXaJxi0o3btNdjwflaqGd6uiK0IV5qeAddYm4xio/JQl3A8hAol22xB4cwQCoRzklTjeWKn/P3+fn26U4qGKwdOijV/zE= 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-b21539dfc90so76379366b.0 for ; Thu, 18 Sep 2025 03:42:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758192140; x=1758796940; 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=Ttz6uN58LRlh8ViQ+ffTzJzOrsWeWDC1M2e/yz7D5SU=; b=pdt/OLJHxrnqt5m0BEAGdHVBAVcwl4YPnetbqYPsV6XEtPHoVuG6Fjw2JhYEqTFvmd hd3INMuR4O8Kx0I3sDpPDRUFsmEZfRlc9ML10BkAhBR+C6VuZUSDS/ns2+rnwfd7wWFp /XKsCbNpzPESIZDA44/l/df8yAGFD+VEcthSIbQX6D7XcP6/3U45db5DMnguPL4N1Pj1 RlPQpdH+brgA2vCZNT+mGSWfeqIlgYgMFVrIDoNvyMmhdYvu0p+abarI8RbfMWWjLF0i H//DQstsro7T1RfoAiO6z+nsOXIsRxp59oIK265w0j2SYaAhKXbGvRDS/0dqNr408NC8 qz0A== X-Gm-Message-State: AOJu0YxJpPlI+tmCzBy9u11yABaXYroHJB3I6A6F4VRzXlafYsZay43l RcZQLex19lhAx2s97+fwaXdOM5ARhnrS1F5hVGGz1rzyksh+Y5qWpXho X-Gm-Gg: ASbGncuUTb9pGcwv5wAh7So5mQItOzBdaV5DFAPjguQQ2rPaSRA0ktTpaiAotfFObbc wDXMMtlVZipbacuBCiJDVeARl6ioyKO4t5h+0j+LgS22k3kIjxhoAg2d+sGe34rF5uOPMbnoVQM iAnT5gYLo0l9cJrr9NdbQJ8+nakHDCHqze/JQAMRMMLxtNBAgyyV9I3+3CUqVtcbrrHafUzavpz /JM2753Z46iEr+uS767uPZ29jT1RNDbIcD6Rwmrw2jEbzswp3mHHeUAQ2BuJiGPol8kEGW+CT62 KejeyKEXBYMCMzdYjlmi8nO0n53sQX5cGDc9aOYFQQRWQIHnGTIo3Whog0tisaZ/mco3UzCnSo0 GYW+G6VM4LaUv3vbw/hVdU/00CjgKcfyZe8gtRTn0Tc4= X-Google-Smtp-Source: AGHT+IG0HhmnyhYS1NNbtaqgrfBIVw6kopyMhg4xbnlgguj5Ju/znaodoDimA2TlTKgeLAva//um+g== X-Received: by 2002:a17:907:869e:b0:b0f:8f4b:f03a with SMTP id a640c23a62f3a-b1bbdc440d6mr656926166b.61.1758192139676; Thu, 18 Sep 2025 03:42:19 -0700 (PDT) Received: from localhost ([2a03:2880:30ff:7::]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b1fc73ba1e8sm166719066b.31.2025.09.18.03.42.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Sep 2025 03:42:19 -0700 (PDT) From: Breno Leitao Date: Thu, 18 Sep 2025 03:42:08 -0700 Subject: [PATCH net v5 4/4] selftest: netcons: add test for netconsole over bonded interfaces Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250918-netconsole_torture-v5-4-77e25e0a4eb6@debian.org> References: <20250918-netconsole_torture-v5-0-77e25e0a4eb6@debian.org> In-Reply-To: <20250918-netconsole_torture-v5-0-77e25e0a4eb6@debian.org> To: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Shuah Khan , Simon Horman , david decotigny Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, asantostc@gmail.com, efault@gmx.de, calvin@wbinvd.org, kernel-team@meta.com, calvin@wbinvd.org, jv@jvosburgh.net, Breno Leitao X-Mailer: b4 0.15-dev-dd21f X-Developer-Signature: v=1; a=openpgp-sha256; l=13252; i=leitao@debian.org; h=from:subject:message-id; bh=UPOeRaoIL7DJ+4Ij9UByVGp65lQeUNBpRGIjUXmOtj0=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBoy+IEsEVWYECduRegaXJkCmtlUiJiY7u67V9g1 o8unOlNLXOJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaMviBAAKCRA1o5Of/Hh3 baB1D/4ih9cLXHDB7XM7Dc3P8aIvtWeTnOX3BEy8GEOOv+Fb7RGzIArFyncReBMnlfGYvdXlW2s 7epPBsT0XFwAm/AwSrspu+tC9fDBkQXfTo0b0LHVr9s/n3VrlWfX8DE+HwgFo5dLsLcMQfSLc/M xQGPlmMqmCvn1jWFU4NBDwxwC312j6Ve1hJC34zNdAisZKgvffZI85+RU2T9k/Z5SAJ5XxHE9Sf cuGTPTmHhlaCD1LKwVuguBeuy29VC+iEmoIFl93OFrwndp2PTbwXCbhr/CvhF0ENJfIPUJgfIS1 U6vZRMVGU3yr1l1DAEpz0QOw+xU8GuRXjKZ/vgJMDbhnEkKkr6noouDHSbsr1gWReSRjFmD8JUN WS52grz3izy2G6L4fGjvcdEbmYj0A9yJd3Un/jLum2Pfnp/sGOiOBmTXEKuOcxG1FkoOXsFSP/I PqgGmM+RABJqjiy+vtr5I6Lm2ha42NuNeh552UCLcyjx+QAQ2QLwzkbdn4z5lehXAfYvnXIPd7S t2tqIWMeqxG+WPEaZWWW+zPWnKf9X6zWerxQm8q/SdEqL66mMcyMNmurhunuA6BofVjGfRQ0oyf rcckMS4fqL0bijiGEIS2rC9Nka0GsGUjxy0sgPnjmMRoJeonkb/qQb3c70HcrY4ZtbCHerEGCdf WoILWbQO3zc5nPw== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D This patch adds a selftest that verifies netconsole functionality over bonded network interfaces using netdevsim. It sets up two bonded interfaces acting as transmit (TX) and receive (RX) ends, placed in separate network namespaces. The test sends kernel log messages and verifies that they are properly received on the bonded RX interfaces with both IPv4 and IPv6, and using basic and extended netconsole formats. This patchset aims to test a long-standing netpoll are where netpoll has multiple users. (in this case netconsole and bonding). A similar selftest has been discussed in [1] and [2]. This depends on CONFIG_BONDING, set it, given it is not set in kernel/configs/debug.config. NIPA uses the following command: $ vng -v -b -f kernel/configs/debug.config -f tools/testing/selftests/driv= ers/net/config Link: https://lore.kernel.org/all/20250905-netconsole_torture-v3-0-875c7feb= d316@debian.org/ [1] Link: https://lore.kernel.org/lkml/96b940137a50e5c387687bb4f57de8b0435a653f= .1404857349.git.decot@googlers.com/ [2] Signed-off-by: Breno Leitao --- tools/testing/selftests/drivers/net/Makefile | 1 + tools/testing/selftests/drivers/net/config | 1 + .../selftests/drivers/net/lib/sh/lib_netcons.sh | 167 +++++++++++++++++= ++-- .../selftests/drivers/net/netcons_over_bonding.sh | 76 ++++++++++ 4 files changed, 233 insertions(+), 12 deletions(-) diff --git a/tools/testing/selftests/drivers/net/Makefile b/tools/testing/s= elftests/drivers/net/Makefile index 2b253b1ff4f38..b49730b393bdc 100644 --- a/tools/testing/selftests/drivers/net/Makefile +++ b/tools/testing/selftests/drivers/net/Makefile @@ -15,6 +15,7 @@ TEST_PROGS :=3D \ netcons_basic.sh \ netcons_cmdline.sh \ netcons_fragmented_msg.sh \ + netcons_over_bonding.sh \ netcons_overflow.sh \ netcons_sysdata.sh \ netcons_torture.sh \ diff --git a/tools/testing/selftests/drivers/net/config b/tools/testing/sel= ftests/drivers/net/config index f27172ddee0a1..dfa8d3291ce0e 100644 --- a/tools/testing/selftests/drivers/net/config +++ b/tools/testing/selftests/drivers/net/config @@ -1,6 +1,7 @@ CONFIG_IPV6=3Dy CONFIG_NETDEVSIM=3Dm CONFIG_CONFIGFS_FS=3Dy +CONFIG_BONDING=3Dm CONFIG_NETCONSOLE=3Dm CONFIG_NETCONSOLE_DYNAMIC=3Dy CONFIG_NETCONSOLE_EXTENDED_LOG=3Dy diff --git a/tools/testing/selftests/drivers/net/lib/sh/lib_netcons.sh b/to= ols/testing/selftests/drivers/net/lib/sh/lib_netcons.sh index 9b5ef8074440c..b9436f29ddf29 100644 --- a/tools/testing/selftests/drivers/net/lib/sh/lib_netcons.sh +++ b/tools/testing/selftests/drivers/net/lib/sh/lib_netcons.sh @@ -28,17 +28,24 @@ NETCONS_PATH=3D"${NETCONS_CONFIGFS}"/"${TARGET}" # NAMESPACE will be populated by setup_ns with a random value NAMESPACE=3D"" =20 -# IDs for netdevsim +# IDs for netdevsim. We either use NSIM_DEV_{1,2}_ID for standard test +# or NSIM_BOND_{T,R}X_{1,2} for the bonding tests. Not both at the +# same time. NSIM_DEV_1_ID=3D$((256 + RANDOM % 256)) NSIM_DEV_2_ID=3D$((512 + RANDOM % 256)) +NSIM_BOND_TX_1=3D$((768 + RANDOM % 256)) +NSIM_BOND_TX_2=3D$((1024 + RANDOM % 256)) +NSIM_BOND_RX_1=3D$((1280 + RANDOM % 256)) +NSIM_BOND_RX_2=3D$((1536 + RANDOM % 256)) NSIM_DEV_SYS_NEW=3D"/sys/bus/netdevsim/new_device" +NSIM_DEV_SYS_LINK=3D"/sys/bus/netdevsim/link_device" +NSIM_DEV_SYS_DEL=3D"/sys/bus/netdevsim/del_device" =20 # Used to create and delete namespaces source "${LIBDIR}"/../../../../net/lib.sh =20 # Create netdevsim interfaces create_ifaces() { - echo "$NSIM_DEV_2_ID" > "$NSIM_DEV_SYS_NEW" echo "$NSIM_DEV_1_ID" > "$NSIM_DEV_SYS_NEW" udevadm settle 2> /dev/null || true @@ -54,7 +61,6 @@ create_ifaces() { } =20 link_ifaces() { - local NSIM_DEV_SYS_LINK=3D"/sys/bus/netdevsim/link_device" local SRCIF_IFIDX=3D$(cat /sys/class/net/"$SRCIF"/ifindex) local DSTIF_IFIDX=3D$(cat /sys/class/net/"$DSTIF"/ifindex) =20 @@ -96,18 +102,60 @@ function select_ipv4_or_ipv6() fi } =20 +# Create 4 netdevsim interfaces. Two of them will be bound to TX bonding i= face +# and the other two will be bond to the RX interface (on the other namespa= ce) +function create_ifaces_bond() { + echo "$NSIM_BOND_TX_1" > "$NSIM_DEV_SYS_NEW" + echo "$NSIM_BOND_TX_2" > "$NSIM_DEV_SYS_NEW" + echo "$NSIM_BOND_RX_1" > "$NSIM_DEV_SYS_NEW" + echo "$NSIM_BOND_RX_2" > "$NSIM_DEV_SYS_NEW" + udevadm settle 2> /dev/null || true + + local BOND_TX1=3D/sys/bus/netdevsim/devices/netdevsim"$NSIM_BOND_TX_1" + local BOND_TX2=3D/sys/bus/netdevsim/devices/netdevsim"$NSIM_BOND_TX_2" + local BOND_RX1=3D/sys/bus/netdevsim/devices/netdevsim"$NSIM_BOND_RX_1" + local BOND_RX2=3D/sys/bus/netdevsim/devices/netdevsim"$NSIM_BOND_RX_2" + + # TX + BOND_TX1_IF=3D$(find "$BOND_TX1"/net -maxdepth 1 -type d ! \ + -path "$BOND_TX1"/net -exec basename {} \; | grep -v net) + BOND_TX2_IF=3D$(find "$BOND_TX2"/net -maxdepth 1 -type d ! \ + -path "$BOND_TX2"/net -exec basename {} \; | grep -v net) + + # RX + BOND_RX1_IF=3D$(find "$BOND_RX1"/net -maxdepth 1 -type d ! \ + -path "$BOND_RX1"/net -exec basename {} \; | grep -v net) + BOND_RX2_IF=3D$(find "$BOND_RX2"/net -maxdepth 1 -type d ! \ + -path "$BOND_RX2"/net -exec basename {} \; | grep -v net) +} + function set_network() { local IP_VERSION=3D${1:-"ipv4"} + local MODE=3D${2:-"standard"} =20 # setup_ns function is coming from lib.sh setup_ns NAMESPACE =20 - # Create both interfaces, and assign the destination to a different - # namespace - create_ifaces + if [[ "${MODE}" =3D=3D "bonding" ]] + then + # Create two interfaces for RX and two for TX + create_ifaces_bond + # Link netlink ifaces + link_ifaces_bond + # Bind the TX ifaces into BONDTX_IF and the receive ifaces + # into BONDRX_IF + setup_bonding_ifaces + else + # Create both interfaces, and assign the destination to + # a different namespace + create_ifaces =20 - # Link both interfaces back to back - link_ifaces + # Link both interfaces back to back + link_ifaces + fi + # Here after SRCIF and DSTIF are configured to either + # regular interfaces or bonding interfaces, and will be treated + # the same. =20 select_ipv4_or_ipv6 "${IP_VERSION}" configure_ip @@ -180,8 +228,6 @@ function disable_release_append() { } =20 function do_cleanup() { - local NSIM_DEV_SYS_DEL=3D"/sys/bus/netdevsim/del_device" - # Delete netdevsim devices echo "$NSIM_DEV_2_ID" > "$NSIM_DEV_SYS_DEL" echo "$NSIM_DEV_1_ID" > "$NSIM_DEV_SYS_DEL" @@ -193,14 +239,18 @@ function do_cleanup() { echo "${DEFAULT_PRINTK_VALUES}" > /proc/sys/kernel/printk } =20 -function cleanup() { +function cleanup_netcons() { # delete netconsole dynamic reconfiguration - echo 0 > "${NETCONS_PATH}"/enabled + # do not fail if the target is already disabled + echo 0 > "${NETCONS_PATH}"/enabled || true # Remove all the keys that got created during the selftest find "${NETCONS_PATH}/userdata/" -mindepth 1 -type d -delete # Remove the configfs entry rmdir "${NETCONS_PATH}" +} =20 +function cleanup() { + cleanup_netcons do_cleanup } =20 @@ -377,3 +427,96 @@ function wait_for_port() { # more frequently on IPv6 sleep 1 } + +# netdevsim link BOND_TX to BOND_RX interfaces +function link_ifaces_bond() { + local BOND_TX1_IFIDX + local BOND_TX2_IFIDX + local BOND_RX1_IFIDX + local BOND_RX2_IFIDX + + BOND_TX1_IFIDX=3D$(cat /sys/class/net/"$BOND_TX1_IF"/ifindex) + BOND_TX2_IFIDX=3D$(cat /sys/class/net/"$BOND_TX2_IF"/ifindex) + BOND_RX1_IFIDX=3D$(cat /sys/class/net/"$BOND_RX1_IF"/ifindex) + BOND_RX2_IFIDX=3D$(cat /sys/class/net/"$BOND_RX2_IF"/ifindex) + + exec {NAMESPACE_FD} "$NSIM_DEV_SYS_LINK" + echo "${INITNS_FD}:$BOND_TX2_IFIDX $NAMESPACE_FD:$BOND_RX2_IFIDX" \ + > "$NSIM_DEV_SYS_LINK" +} + +# Create "bond_tx_XX" and "bond_rx_XX" interfaces, and set DSTIF and SRCIF= with +# the bonding interfaces +function setup_bonding_ifaces() { + local RAND=3D$(( RANDOM % 100 )) + BONDTX_IF=3D"bond_tx_$RAND" + BONDRX_IF=3D"bond_rx_$RAND" + + if ! ip link add "${BONDTX_IF}" type bond mode balance-rr + then + echo "Failed to create bond TX interface. Is CONFIG_BONDING set?" >&2 + # only clean nsim ifaces and namespace. Nothing else has been + # initialized + cleanup_bond_nsim + trap - EXIT + exit "${ksft_skip}" + fi + ip link set "${BOND_TX1_IF}" master "${BONDTX_IF}" + ip link set "${BOND_TX2_IF}" master "${BONDTX_IF}" + ip link set "${BONDTX_IF}" up + + # now create the RX bonding iface + ip netns exec "${NAMESPACE}" \ + ip link add "${BONDRX_IF}" type bond mode balance-rr + ip netns exec "${NAMESPACE}" \ + ip link set "${BOND_RX1_IF}" master "${BONDRX_IF}" + ip netns exec "${NAMESPACE}" \ + ip link set "${BOND_RX2_IF}" master "${BONDRX_IF}" + ip netns exec "${NAMESPACE}" \ + ip link set "${BONDRX_IF}" up + + # from here after, SRCIF is bond interface + SRCIF=3D"${BONDTX_IF}" + DSTIF=3D"${BONDRX_IF}" +} + +# Clean up netdevsim ifaces created for bonding test +function cleanup_bond_nsim() { + echo "$NSIM_BOND_TX_1" > "$NSIM_DEV_SYS_DEL" + echo "$NSIM_BOND_TX_2" > "$NSIM_DEV_SYS_DEL" + echo "$NSIM_BOND_RX_1" > "$NSIM_DEV_SYS_DEL" + echo "$NSIM_BOND_RX_2" > "$NSIM_DEV_SYS_DEL" + cleanup_all_ns +} + +# Full cleanup +function cleanup_bond() { + cleanup_netcons + + # Delete TX ifaces + ip link set "${BONDTX_IF}" down || true + ip link set "${BOND_TX1_IF}" down || true + ip link set "${BOND_TX2_IF}" down || true + ip link delete "${BONDTX_IF}" type bond || true + + # Delete RX ifaces + ip netns exec "${NAMESPACE}" \ + ip link set "${BONDRX_IF}" down || true + ip netns exec "${NAMESPACE}" \ + ip link set "${BOND_RX1_IF}" down || true + ip netns exec "${NAMESPACE}" \ + ip link set "${BOND_RX2_IF}" down || true + ip netns exec "${NAMESPACE}" \ + ip link delete "${BONDRX_IF}" type bond || true + + cleanup_bond_nsim +} diff --git a/tools/testing/selftests/drivers/net/netcons_over_bonding.sh b/= tools/testing/selftests/drivers/net/netcons_over_bonding.sh new file mode 100755 index 0000000000000..10f2183a16edb --- /dev/null +++ b/tools/testing/selftests/drivers/net/netcons_over_bonding.sh @@ -0,0 +1,76 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: GPL-2.0 +# This test verifies netconsole functionality over a bonded network setup. +# +# Four interfaces are created using netdevsim; two of them are bonded to s= erve +# as the netconsole's transmit interface. The remaining two interfaces are +# similarly bonded and assigned to a separate network namespace, which act= s as +# the receive interface, where socat monitors for incoming messages. +# +# A netconsole message is then sent to ensure it is properly received acro= ss +# this configuration. +# +# The test's objective is to exercise netpoll usage when managed simultane= ously +# by multiple subsystems (netconsole and bonding). +# +# Author: Breno Leitao + +set -euo pipefail + +SCRIPTDIR=3D$(dirname "$(readlink -e "${BASH_SOURCE[0]}")") + +source "${SCRIPTDIR}"/lib/sh/lib_netcons.sh + +modprobe netdevsim 2> /dev/null || true +modprobe netconsole 2> /dev/null || true +modprobe bonding 2> /dev/null || true + +# The content of kmsg will be save to the following file +OUTPUT_FILE=3D"/tmp/${TARGET}" + +# Check for basic system dependency and exit if not found +check_for_dependencies +# 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_bond EXIT + +# Run the test twice, with different format modes +for FORMAT in "basic" "extended" +do + for IP_VERSION in "ipv6" "ipv4" + do + # Run the test twice, with different format modes + echo "Running netcons over bonding ifaces: ${FORMAT} (${IP_VERSION})" + + # Create one namespace and two interfaces + set_network "${IP_VERSION}" "bonding" + # Create a dynamic target for netconsole + create_dynamic_target "${FORMAT}" + # Only set userdata for extended format + if [ "$FORMAT" =3D=3D "extended" ] + then + # Set userdata "key" with the "value" value + set_user_data + fi + # Listed for netconsole port inside the namespace and + # destination interface + listen_port_and_save_to "${OUTPUT_FILE}" "${IP_VERSION}" & + # Wait for socat to start and listen to the port. + wait_for_port "${NAMESPACE}" "${PORT}" "${IP_VERSION}" + # Send the message + echo "${MSG}: ${TARGET}" > /dev/kmsg + # Wait until socat saves the file to disk + busywait "${BUSYWAIT_TIMEOUT}" test -s "${OUTPUT_FILE}" + # Make sure the message was received in the dst part + # and exit + validate_result "${OUTPUT_FILE}" "${FORMAT}" + # kill socat in case it is still running + pkill_socat + cleanup_bond + echo "bonding: ${FORMAT} : ${IP_VERSION} : Test passed" >&2 + done +done + +trap - EXIT +exit "${EXIT_STATUS}" --=20 2.47.3