From nobody Sun Feb 8 14:59:35 2026 Received: from mail-ed1-f54.google.com (mail-ed1-f54.google.com [209.85.208.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DBE721A08DB for ; Thu, 2 Oct 2025 15:26:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759418802; cv=none; b=XYH9LYQMkc1mO8+LC2haSzYNgLSQ8Ivnvq6nevbQi/3wyS3wNE7O/EkSJwCMz+iB9yZ29SDzn5kTLXkSb3r4d66mOSlyKBSKs9MmIsvdc1z5nRpGxmoDwAEuWvFTRWtAasUe0tWU6Efnu0Q5A8CAJWy3EqhQ7KSUaXqdQb6ORkM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759418802; c=relaxed/simple; bh=+RzgxlXhvAjihAWHcJSiVhsrURV2de8MPdHHcOWTs/g=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=fPd3Y+JUJyffkiry3sxZCywFZ90U2lH+FV5KPtjMYxnBNyYQ4R5pweuXtAS1PcfBgD79etZdWH3hyIPGU3COoTO8wK3k0339UkUFb9hscWMH0FrD4DxbWz6Jh09jNEdaZHmY4Cuv0Ow/uyihX6ihGtTcYHZqqH68bOfpeiJYPKY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.208.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-f54.google.com with SMTP id 4fb4d7f45d1cf-637dbabdb32so2036803a12.2 for ; Thu, 02 Oct 2025 08:26:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759418799; x=1760023599; 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=1CR8vj1NdfmaZYiunLULz9OPZOynQvbneaWGWn09HLE=; b=dFUdYnzetZX68pjqV9GWPow/qkQ+SixUksyXv7svXawMj4XfHJeYW5gPV0P4szKzOm OtZ/rhAOC/4WnJJYyDxbeJ5ALMi/hjWF7VuWC2j8zOCmAfb8/uKs7opnseeZlv24z66I xZKNzBuz/IdS0cmXHO8HVMeli+iSkdlljY7xJZ+s4NUx3k/wr3Yj7/W60arxjQsdCHSy +yuaTeN1+bDTy/lWQpfBDNeKqOR+osfZI0QX5Uojrx1yHfnodKH+Qwe1N04TNgoZgfem G/omWQK2vZjq5v5LJGURmStOdraFOmoidb4Z6HuA/ZdpYM97hdOv31/3ZyAsleBHd+Fx UPsQ== X-Gm-Message-State: AOJu0YxmgLIdHL+cZ38BQm41WQEqucUa7Yo1sMxsXW86z89EI3Ucp8+K N7aN6Hhl8uew9rJestvgY2TLtmXB364nTq7buikc194QlabNnaV7zCLU X-Gm-Gg: ASbGncvxI7WUuSfRIbE76ZfenS0QLOoGHsg8HkSyGXk1lD/xSTEVHP0kZFrcsE5YKO3 F0rgDTW8UzwBBxEsV5rgKGMeDIzmTjTkbRaJuMVeu6uGpfF3tCvGUfyIxWg+Hc3/PB1WBCjVDH/ BBMcz9/5EVTg3w7wRQMAPnqZZGAl0JMo/Ll9EBz59QvqOZr+nMO+EVt34gK/hZBmlgxDRmd/ZVa d7pFm66Xcb4t22XEsgb5O1CHnDOfbNUVIJAOjGB0smwP6u1gkpF3pWlq12hEGbYeupk+QY448pl /K6LjGQp06eNjLd0229a0WOmmWuvv7mc/r+5UsZf0n2HTF3+O8qJXT1mF/P4L2X+UCOzEU6oJ/q 0icADmm6ShT977F17cuDZNcizixAg+JioA1jf X-Google-Smtp-Source: AGHT+IGQezPxxiQ+1Z3VIlbAcwk+ye5bVV2z7QZN3w4RqsN7m5DXUIPTwn71y7T68heiqIIoL/CKuw== X-Received: by 2002:a05:6402:2793:b0:638:66b1:e5b3 with SMTP id 4fb4d7f45d1cf-63866b1e788mr564378a12.9.1759418799104; Thu, 02 Oct 2025 08:26:39 -0700 (PDT) Received: from localhost ([2a03:2880:30ff:1::]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-63788110530sm2065860a12.38.2025.10.02.08.26.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Oct 2025 08:26:38 -0700 (PDT) From: Breno Leitao Date: Thu, 02 Oct 2025 08:26:25 -0700 Subject: [PATCH net v6 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: <20251002-netconsole_torture-v6-1-543bf52f6b46@debian.org> References: <20251002-netconsole_torture-v6-0-543bf52f6b46@debian.org> In-Reply-To: <20251002-netconsole_torture-v6-0-543bf52f6b46@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=+RzgxlXhvAjihAWHcJSiVhsrURV2de8MPdHHcOWTs/g=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBo3pmsL95LlY0VMP3W1luaxEiZHoPub6VfwaOQ4 YbUFtc3yImJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaN6ZrAAKCRA1o5Of/Hh3 baV0D/4r9TaEEvP77fTxZxdf0o0lCYQADBftm/XrTNtv1i0HqMi+xC9/hc+w1My4OpLHKGUashN 5yl2EVbjC8lP7AnP8Y1TRX8JvAERoE8qlj+PxeqRUDFKQZUSdrVIyo3hZoHpJ8xsfZCFsdd2MsA vV8REz1OkI1fGPJp3/8t5DEn+wSeNAsej2T34BMarJvJf5Az1PmObDgqdlyxO/17LfU3ps3iNc/ Fns/L4fNn5TJlTAUS6OAqUgrw12vgApt283suPX5nvM2QIq3xm1Kq95HLrBRp4GNZwRYoSJd4Mx VC5f5Cr528QhBH+t5y9z7GcSBN991R8ejK7tZ8CWBSDj/82pCTdGlx+M6zBwAztheaqlIYVrTKL nCKxFFSN+OpA9LSD+Vh+5JLazleDzRw1U5IIpSR9jqEiHFoUJAFymWfYoKLM7ZHsZi2iA6ptskk dYDUhe6pDjna7MqvlJMuYZy+JV+bSNiyqMxyi3uDkXjFHdNYxpj8UBtQ5mtNVO7nzCJu05+jTS5 cckHZJTyCqZKtmORZz+InyXov1PRHlx/mzyZDfH9snHjuzB6NzVtOXp7nXLJkSnGbN+gYwbjyjC Q3evFzvFqHJ9F8vHhoWTeAdHXkM66w4C2l7Mt7Fa7MpGtEvnUCDQdJ9uQ7QuKYk19FMsKgTB2Z5 e9+sDOF7uivC4hQ== 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 60a05d3b7c249..f4a0023428265 100644 --- a/net/core/netpoll.c +++ b/net/core/netpoll.c @@ -814,6 +814,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 @@ -823,8 +827,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 Sun Feb 8 14:59:35 2026 Received: from mail-ed1-f52.google.com (mail-ed1-f52.google.com [209.85.208.52]) (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 432B51A9FB5 for ; Thu, 2 Oct 2025 15:26:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759418804; cv=none; b=UG44DJFBr6Nm+zhQ2n8UUCvfhb2vUs2m0MLnQ2ac0t3t3OKwFT6kWSf8h2VbNhmegnTDxVq0XcnUdCURiaQ2/s3sQqRlbQPDID/dS6M/Z24z+D4UA07qVqmPHasBREPzIcHJ9w5LF2lTNiCVvwJz0OXYfnC7pYgrgc6VXDn/Mqk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759418804; c=relaxed/simple; bh=Z86lLnI5Tm3fzb69918VDPeWt3usJ2k/s66dsD2rV1E=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=tMwziS+9Y0+GzWO32qwikzjT9pg1/tePEagng/nofdtT6w6i2DW1Oxry4gQFrWcKbq2hvw1v7/b4c/BE5a3mDyCwrkuLdZBc67ou6Zy7JOJq965xlwF9XcOMfjAk/RhSYqxPH/YnwWmDZbnAQ61aW2xuAqzThlZKRCVW0gFmj84= 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.52 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-f52.google.com with SMTP id 4fb4d7f45d1cf-628f29d68ecso2674339a12.3 for ; Thu, 02 Oct 2025 08:26:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759418801; x=1760023601; 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=fV7gueGwrkVggKjpKT46wk+Vba2utbQt9f8Z8d2dnHs=; b=htAoYs6BDGfjOH0WBQ+/Ae/cBri9SkKpnGzXd0v/hWzHXQRoEWPw4IP8UwaS2Yd3EL wa4bRfvZZ0V9Yu+RkrimqZmzI2SdK2zNYBx8OPk8s42CV2t6ZxBIqeUIhmvkwPfBNNCa BFBy9GpW4gjvk4OHoAUF/A6wdqItzolCuSn1FnkV5pO5XYzEyAt+ahvFhAvvUovcGAE+ ZZW45gd2FUpZGSmw0xcBc9f+uDEkGo0MI4+yDo4jAF3NmiCnAN8/pHHfjJFCctx/Rhso a1RxaqkVbl9fIlkTphvenvcqMSOXH0kaFwDgMVAS8wRinMhWb+lx/0XhK0ry1F1WKgMV CjPg== X-Gm-Message-State: AOJu0Yx3nL9yjm6XC0zvwJ0SQrhq+tIXHxFLQXSSRe2afBN++4L72KzZ uojDT68T0p41Kysrjgt2QBTlNfNbtEMG/pLvNN0TeG0JB8iD9huLDzpO X-Gm-Gg: ASbGncvGu9bA3dexRSYawvn2gi76nw3ub0OUzxPbrY0ZIzjxAtFBQw9BXG1uU1My8W0 0YwDafYOPs4bmRV8inIhGhzxkC3CY5X0xEPhrj1bDzUyeKD/1wjMt9B8Pqz0/vfpgW+lLJCSSsh efg2t9CskKoHjCMJdngqM5e7bVtKt+khsS/KVYxs6YUvPtOQ7IQuKzdxdJS6mzauszaQIszh9OL vSK3w8GSYxhL3tyROuWlVPKGjkuqvSVRjcJ9IeSxwSgcDCwlvIXbVB2IPFkaApB/O1NjZncIr5l rT87H35TATAiRvhW3t3MZ8VlZK2squ4DEZFLc5UNkKwBMMXJMR5p7R8LqLMURD0mrr0hsRb+zSf l0w+Ak2s6DiPJvAPJd+DJ6U+OUknWpThkknASCA== X-Google-Smtp-Source: AGHT+IHu4WE80t/90uYDNyDhdDM+IRvgxuoF7rHrcmkwwOikdOlCR5zfrTQPjaAV6zMrz5FIvlZlJA== X-Received: by 2002:a17:907:728e:b0:b3d:73e1:d809 with SMTP id a640c23a62f3a-b46ea414aefmr989484766b.48.1759418800558; Thu, 02 Oct 2025 08:26:40 -0700 (PDT) Received: from localhost ([2a03:2880:30ff:73::]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b4869c4e613sm217854966b.81.2025.10.02.08.26.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Oct 2025 08:26:40 -0700 (PDT) From: Breno Leitao Date: Thu, 02 Oct 2025 08:26:26 -0700 Subject: [PATCH net v6 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: <20251002-netconsole_torture-v6-2-543bf52f6b46@debian.org> References: <20251002-netconsole_torture-v6-0-543bf52f6b46@debian.org> In-Reply-To: <20251002-netconsole_torture-v6-0-543bf52f6b46@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=2493; i=leitao@debian.org; h=from:subject:message-id; bh=Z86lLnI5Tm3fzb69918VDPeWt3usJ2k/s66dsD2rV1E=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBo3pmspZB8YD2VU7zArjltNHoR3Lv5JL4ulcLK/ 0QwucYTe+CJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaN6ZrAAKCRA1o5Of/Hh3 bQu3EACLUz67wGRPN9BfvCvd4welZkaPX5R64wU0e0JPLIx8IybZT4DThQgjZo+SHbCPnOyyPev ci4ZZlxLvQY4DX3zszY5Hj9mgzp87uLLiP3U76hnN8sKyVemm4b/JOmIxlYBkHmRzBozg/3BIdf M/zs9uXms2MrN5+lkmoN9+d6hyA/fmULTbHc2nH3ZRI2VJsembz116cS2ncRS1Df00uSRZrvt0d XCrlOLp/Rj3oUD8wDWzBE6ou7D8RLTS5TKLlZh+GxiRiBnUk4ycTfVu7tenhr/16hseDacUDnr8 +eyro2kmx3Ipi5gdesBRat4P7xzhiIuIkNYvNPUc0bnUiD75e2XSdBOk9kNofP4i1oisZcU8pMX QaQVX0mVWr4URMEkJTgOSU6it8h2vsVmQCZgKdnJAHZ5s293JNNuzjGHXuLsmvg5mJDRP/lp2jQ rmSrW4caPmcJpPSFFTBkkKF/1dFHCfBx5gX3Z/9Dvv/xdGJx/kB1CBLG+JfQybzTuKzZom7g2xV UjxMbgw9yk/XNOKu+02TMxwBhdZeQwEgf5xefelb5sMfUAE/0dQUUE6SoL+LgDLxZuAfkGerS7i +xnCrjc34r35cViwnYkLXkMwz7VhF82gBaoTm+n6I8zi+pakdwjeBX+lACJc+LFmVMxMP3DNmci 1+VcNwkEQj2XmLw== 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 --- tools/testing/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 Sun Feb 8 14:59:35 2026 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 3B7351D88D0 for ; Thu, 2 Oct 2025 15:26:43 +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=1759418806; cv=none; b=N7yZAzNDh17s7vR47Qvwk6cNfDTKL/ao5Bt/BIwK3Kz7ZJnS2amLtbWuliQgkHO0KfDUNt5WrJRBGaUfj+Qkgn17MoP9FkIqxneSqPPEQbdBDiej6e0S0Jtn1CewxSfBRhMK1zhMXbArgKxdpzl8k1FCqEGf1FHebMHljq+MsYQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759418806; c=relaxed/simple; bh=wCTCXuF1yxmEp/u/Sr4POeQXqdQsOxIg5TvZ/SJ3ls0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=K6MBfQwGlBhYIBKyw/q2OkrBhHH1arJIFdqNdwGRPlayCf+W0gjI1YcsFju3rF5vYp/4LDiIvVAk5Q0TvOeXheb0dTD7aam4FHHE6Ako1AwPbpUdFxByWAVpG7X1BsIW87ED2p/Jy18Qeco9FnUo5wnO9mwXBapZwVzF6OSiwOM= 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-b3ee18913c0so212953566b.3 for ; Thu, 02 Oct 2025 08:26:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759418802; x=1760023602; 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=GXgombtdf1pG/9E0pDd7PwlfJe24y1WoCU+6S182X6w=; b=KvhHgJN/C/KGIqYJI/u+nv8JeaEUfucxF4w8RENy1QlIiwLrpR0YvEXYr2bvvkgIAb u5ksEAZyGfUP0b9IRwNz/pdtaVFlHVSOyz16EUzdLx8TsviieM674iCJvSkG62BOHbYk GifAZKhqcSoDi3IEobHppM54BVTMTtuKNXts9HYdHnFzN5xMeh3qeplt0FFLNmFTgION C3FSBO6PO7Xm9kKE2LiF9Xq9NFr8y0u1DFx4FkL7YYiRtxnCB2+PAfLQxGkx7n9ljkDd XVTClpMZ7x6Wnm/o83T47jz6j30/guyOOuXYrMvVs4GIk9mExjGCgPOa3u/LkmelY3Hq hdwA== X-Gm-Message-State: AOJu0YxkAaSaNh9SjURuQuA1VZai1DK3gw4f7j4JoEbcP0RIyIS6LdRR ql1P+QMhEu3ukQ2QG3Birjnz9zA1kMg/cgyWXXNN+qKs3dpq+R7RDKxS X-Gm-Gg: ASbGncuGn8bYu81sf3r276Zca7zSr4SrYi5CpMlwETdWLz0aBvpg3FvgIc9IVweFybq 2gzhkfsn6h+VdaN4GihDPcZIM/kqtIptlV8bXasNMXtwc0iZFyfy82wuH65bSSibFxPTprA3oG6 sIau6r2yeNcBslSY/r4R7k2wsECwjsvJrW3mWylV+y/eMZ0Ag7zIO2M5HzK379MG9oMD5B01e+8 xMS5PiF4G2f3XIDbHsNAjRIq0uRb6jTxipeEjRpvGuMAeCYOxScma2/J6DnN0cSmtyXMpFaBFZ/ LDFPyty474VzAPpOovrYPq2QDmVPoTJmW1fW4PERcsJhD4ctw6aF2Iw8WTX+FFjK6qo0a2dZfCD ks7PK8BGfREUqQ1YhX5hvgb83JfpGU1U/eMG+2Gs6uSSGXyc= X-Google-Smtp-Source: AGHT+IGwJ7GX2udijpZY8tC506RtKUpv5oAxJ0Wta3SK+EKAIFSchsaTuH5oq1K3c4XJNvkVHHckCQ== X-Received: by 2002:a17:906:6a1e:b0:b46:1db9:cb76 with SMTP id a640c23a62f3a-b46e6031e32mr947212166b.39.1759418802114; Thu, 02 Oct 2025 08:26:42 -0700 (PDT) Received: from localhost ([2a03:2880:30ff:7::]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b486606dc84sm222645366b.45.2025.10.02.08.26.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Oct 2025 08:26:41 -0700 (PDT) From: Breno Leitao Date: Thu, 02 Oct 2025 08:26:27 -0700 Subject: [PATCH net v6 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: <20251002-netconsole_torture-v6-3-543bf52f6b46@debian.org> References: <20251002-netconsole_torture-v6-0-543bf52f6b46@debian.org> In-Reply-To: <20251002-netconsole_torture-v6-0-543bf52f6b46@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=5371; i=leitao@debian.org; h=from:subject:message-id; bh=wCTCXuF1yxmEp/u/Sr4POeQXqdQsOxIg5TvZ/SJ3ls0=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBo3pmsmmMGNKcgEnavHC2jMEtdvF8yeZdoGp4aZ 3JHNKKmj6SJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaN6ZrAAKCRA1o5Of/Hh3 bd4lD/9+O4IHa2bZy6+3RktskQcbeHj09CYSlsackDR0zeECGyMpFB9wUmmDQMJW0foPBqCXB5F PrsVB83q1YgEsLu4mfivqXDYoBuYHVAImibFrRzwkWuLaAPNJnE/cN7niP885NMl6Ydrjrn5ySM FEx3yPsG1f6td68+Qzy9nKvNQmL/ImM6/ndzpvXuknJqYb3XWGa+8QpuZzOxemQYj0XFUoOO7rI h+tILR8p55nF+3AAilLeMBJfipr+WqGklE6+WbbvPzP4WlHlJypCZeuJBusi/gEbwwXmv4THtlx 0/CjRNY3ufwtPFg0k+JfR+agGr7Pnfqlimayzxh92fMKp3DgU034derwx4K0edlAXc2vb+uh5Kq AKVQI352huzOxTrMHMaczB9zQkV4czj+BUYLOn8NUyj75HC/UL8FgPLqRGXCQGW0z4AZKp205/M ptqPctj1EEYeHoo7njjgUC5liEhdCvZ+FfWXiWdkjPjbq60Eu6PKS6Kho5jaYC7SPo7T9TV2+QX TarXwGH5FIfbck8Vca1C9DYEitV1IKf70mBxFXSzwQn1MBnahxE5WJTXWBT4I5axFynAZpapC3U SlXCzgalhj+34nNzXjy7wahhcOlSTGioynvN2TMsd7YY710BXiJEahoL6MejHXyq8K6/CmrN1k0 n5ldAGaPgN8Bq0Q== 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 + tools/testing/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 bd3af9a34e2f2..42b3fb049f868 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 \ psp.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 Sun Feb 8 14:59:35 2026 Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) (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 9154C1C84BD for ; Thu, 2 Oct 2025 15:26:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759418808; cv=none; b=O7GM5Gmqk3aoeKs11rzgvqfvsvnWB1IrE+S1B1cp5oGIhxsa60K2lt9If1H94ULtHt2dh99NXARdysxE+g9O+hGDXVXu1UeVFn8+2mlljXTDe4kC0wOYT3uunEplIetFTVHZ9f5gtbwYFiKWR8j2n5VZpSHG6p7i2Ebmt3179jc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759418808; c=relaxed/simple; bh=+Wr2JHLDAdqSQOdJXgdj0aLxFpj+xU56ZnNePILVH1g=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=lI9X6M8BK3+yxmfrxU6LzHrUk5PNA95Q5xkU0SH5iJEoZb0jObFGx+KYq2ax1Xk02CDUfmLtlBUhnW5JcaC7s1eiJ1H2LsQE3NUt2H9OlV7+E9TAem58zPVYZ1GLTEclJtDF3VTHXG4rYXgxlGslSWOvSByEVpTEsCC2r6ZzuYM= 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.52 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-f52.google.com with SMTP id a640c23a62f3a-afcb7ae31caso211035566b.3 for ; Thu, 02 Oct 2025 08:26:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759418804; x=1760023604; 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=aQtdUQWucLO0DCJsaLkokI5pGITgscy1HOM+9oBHcHM=; b=aXq1QPrcZdHFzB52XC07kcHUzFGtVgFXQVBuSrYK6BC4uwSThWj9cAJblWAU7WU137 IXQjB9Veafb5mo6rHAvCUSe0pqHKzix3Se3yETOOe2ff+pv68ucMULl7PFzl7qyODSg/ QPA2+4EkXl622cxvaTHg2lJtzC7MsJRbf0Z1uvbRcAxeRMMHFpFLC+d/fAooWG+ha/Nc tVXy4z5ytlGnb2kffl2c97vJZXD/HHBBTIb79xmyu+RDKEkXsXn8VHC1fwoNWvtQ6/di pVXxUzhi6XRhwAeLt2rvdyvOo6feRkdYef6KeHqEiw6RmvA35ioqHFDpdpnxn5seul7W DtEQ== X-Gm-Message-State: AOJu0YzUiX7T4jF/CL5fQaIzlMRrpeAN/wwrCnXSZ2upkNgo4JWgYrdq 4hBPudFT2FYMUMpKVb0VHIXfnAegwVs9BCMrTmqIYY02t0IJevOEXs5F X-Gm-Gg: ASbGnct6TJdC7clasv/Uu0zmqUIUkTjJr+aUo6Nhw9z7Yl3g4bI2whevFcdcyUxMbc8 jrOq5ksnaTX1bPJQEkvX/KH59apsXKbj4oa5ZvhBtvYlZmIDqHn1hYEYmxrh+hPgLCYXL2CXYr9 3FPdAEaA0SqJvUAPfDbvfYSLZoFwh5ROPwppaKdZ5QidBa0FFwTg/6L0gdR/6vDsJ+ZgiREuyvp ZvbufbI4DzBswLbd2DuHBxxzs4BwZ9yTZfQX/z4HiOJvL71PyAXSiO7FYj88mezQ4LBOGRxZVjP YWX4wJ2dLObrDxkWy2gfgXK++9zhe2BrHnlDQ4imzjXQvC9T/RHySfACfY9CADSzuIegcph9/KD Nr+Wci3EPSlyEyYYdLhFZLw2PdC/694kLtNXezSqIoL+xTNs= X-Google-Smtp-Source: AGHT+IEVmG9H+TlJ1ZzoqVnIhnhEwG6cD6EP4xCjqOwLody3wdin4IVdMCnuils1S0EyiXJS2OJ2Eg== X-Received: by 2002:a17:907:25c5:b0:b41:e675:95cd with SMTP id a640c23a62f3a-b46e4b8ec0emr979506866b.13.1759418803742; Thu, 02 Oct 2025 08:26:43 -0700 (PDT) Received: from localhost ([2a03:2880:30ff:2::]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b486a177c62sm225916966b.91.2025.10.02.08.26.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Oct 2025 08:26:43 -0700 (PDT) From: Breno Leitao Date: Thu, 02 Oct 2025 08:26:28 -0700 Subject: [PATCH net v6 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: <20251002-netconsole_torture-v6-4-543bf52f6b46@debian.org> References: <20251002-netconsole_torture-v6-0-543bf52f6b46@debian.org> In-Reply-To: <20251002-netconsole_torture-v6-0-543bf52f6b46@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=19187; i=leitao@debian.org; h=from:subject:message-id; bh=+Wr2JHLDAdqSQOdJXgdj0aLxFpj+xU56ZnNePILVH1g=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBo3pms4sv0tUm7YcpAzRFBCnxXgjt/XLTfthy1L bxhTPol5r+JAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaN6ZrAAKCRA1o5Of/Hh3 bTNPEACLkAFfwMW7+cSaYlK3bNE2soxKgazao3s/SN9ltyvy/514w1eEqnL5gHE981+nYOGt9Tn dJdDglbCcRLkNZ88reiUl/Ev9NJVmezdmriWES46PM24mDYz9NpicyGje8YgshHH/1ZO3pXAtP6 ifM610uJ236Jzskvx7CUUmfyRoSkr+SMar74qBhPt/v9vzj0GXhiizYqtRiXjKiFEdVfY8/u+VZ T7N7oc4u5dQCG8ge8GMWu/1UEYF7hrz/9QGNDGqmTfp3vQASJGR7kClH/1oOAAiieytLWEnb61P 4+CV4EzESQh75VUskqFIdQcshMrhBa9rlHxpIJimQ0RDKSNeMC+RFxdjSVSHX7e01GWQ+SUtmSX s6rWFKQOCROSzQXlVlMWyiHa2YxtdFVcwBi0Q+qGBETM/A3FUJMYKj9GiSQMNRbNx2AntyxmxX/ ulm9wSFBip0iIGziBhNk772mdu35KT9glxtV9r/K8AsgaS/pccaIk6RspqbAfGjZW2KiTYai75r PxzxBN2c8S8gpbgijgB2FPWC4Cb3XcGwNvnpTV0wdnh0GxivsbWNNoqbEUUsOBca5nxn9eujBNL 1tqm1pt08ZEET0fyy0FF1NmAGoDsqrmLxUOpTyWkLW5YRZmbwnZs5ifFXNC9nUi9DPMUxbsL9Oy oGmmYp/6tRD6dsg== 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 subsystem where netpoll has multiple users. (in this case netconsole and bonding). A similar selftest has been discussed in [1] and [2]. This test also tries to enable bonding and netpoll in different order, just to guarantee that all the possibilities are exercised. 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/bonding/Makefile | 2 = ++ tools/testing/selftests/drivers/net/bonding/config | 4 = ++++ tools/testing/selftests/drivers/net/bonding/netcons_over_bonding.sh | 221 = +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++= +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++= +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ tools/testing/selftests/drivers/net/lib/sh/lib_netcons.sh | 159 = +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++= ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-= ------ 4 files changed, 379 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/drivers/net/bonding/Makefile b/tools/t= esting/selftests/drivers/net/bonding/Makefile index 2f095cf67d9a0..691e0bef4244c 100644 --- a/tools/testing/selftests/drivers/net/bonding/Makefile +++ b/tools/testing/selftests/drivers/net/bonding/Makefile @@ -8,6 +8,7 @@ TEST_PROGS :=3D \ dev_addr_lists.sh \ mode-1-recovery-updelay.sh \ mode-2-recovery-updelay.sh \ + netcons_over_bonding.sh \ bond_options.sh \ bond-eth-type-change.sh \ bond_macvlan_ipvlan.sh \ @@ -21,6 +22,7 @@ TEST_FILES :=3D \ bond_topo_3d1c.sh =20 TEST_INCLUDES :=3D \ + ../lib/sh/lib_netcons.sh \ ../../../net/forwarding/lib.sh \ ../../../net/lib.sh =20 diff --git a/tools/testing/selftests/drivers/net/bonding/config b/tools/tes= ting/selftests/drivers/net/bonding/config index e5b7a8db4dfa3..5adc77d3808e1 100644 --- a/tools/testing/selftests/drivers/net/bonding/config +++ b/tools/testing/selftests/drivers/net/bonding/config @@ -1,5 +1,6 @@ CONFIG_BONDING=3Dy CONFIG_BRIDGE=3Dy +CONFIG_CONFIGFS_FS=3Dy CONFIG_DUMMY=3Dy CONFIG_IPV6=3Dy CONFIG_MACVLAN=3Dy @@ -8,6 +9,9 @@ CONFIG_NET_ACT_GACT=3Dy CONFIG_NET_CLS_FLOWER=3Dy CONFIG_NET_CLS_MATCHALL=3Dm CONFIG_NET_SCH_INGRESS=3Dy +CONFIG_NETCONSOLE=3Dm +CONFIG_NETCONSOLE_DYNAMIC=3Dy +CONFIG_NETCONSOLE_EXTENDED_LOG=3Dy CONFIG_NLMON=3Dy CONFIG_VETH=3Dy CONFIG_VLAN_8021Q=3Dm diff --git a/tools/testing/selftests/drivers/net/bonding/netcons_over_bondi= ng.sh b/tools/testing/selftests/drivers/net/bonding/netcons_over_bonding.sh new file mode 100755 index 0000000000000..c550c906bf021 --- /dev/null +++ b/tools/testing/selftests/drivers/net/bonding/netcons_over_bonding.sh @@ -0,0 +1,221 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: GPL-2.0 +# +# This selftest exercises trying to have multiple netpoll users at the same +# time. +# +# This selftest has multiple smalls test inside, and the goal is to +# get interfaces with bonding and netconsole in different orders in order +# to catch any possible issue. +# +# The main test composes of four interfaces being created using netdevsim;= two +# of them are bonded to serve as the netconsole's transmit interface. The +# remaining two interfaces are similarly bonded and assigned to a separate +# network namespace, which acts as the receive interface, where socat moni= tors +# for incoming messages. +# +# A netconsole message is then sent to ensure it is properly received acro= ss +# this configuration. +# +# Later, run a few other tests, to make sure that bonding and netconsole c= annot +# coexist. +# +# 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 + +FORMAT=3D"extended" +IP_VERSION=3D"ipv4" + +function create_all_ifaces() { + # setup_ns function is coming from lib.sh + setup_ns NAMESPACE + + # Create two interfaces for RX and two for TX + create_ifaces_bond + # Link netlink ifaces + link_ifaces_bond +} + +# configure DSTIF and SRCIF IPs +function configure_ifaces_ips() { + local IP_VERSION=3D${1:-"ipv4"} + select_ipv4_or_ipv6 "${IP_VERSION}" + configure_ip +} + +function enable_netpoll_on_enslaved_iface() { + echo 0 > "${NETCONS_PATH}"/enabled + + # At this stage, BOND_TX1_SLAVE_IF is enslaved to BOND_TX_MAIN_IF, and + # linked to BOND_RX1_SLAVE_IF inside the namespace. + echo "${BOND_TX1_SLAVE_IF}" > "${NETCONS_PATH}"/dev_name + + # This should fail with the following message in dmesg: + # netpoll: netconsole: ethX is a slave device, aborting + set +e + echo 1 > "${NETCONS_PATH}"/enabled + set -e + + if [[ $(cat "${NETCONS_PATH}"/enabled) -eq 1 ]] + then + echo "test failed: Bonding and netpoll cannot co-exists." >&2 + exit "${ksft_fail}" + fi +} + +function delete_bond_and_reenable_target() { + ip link delete "${BOND_TX_MAIN_IF}" type bond + + # BOND_TX1_SLAVE_IF is not attached to a bond interface anymore + # netpoll can be plugged in there + echo "${BOND_TX1_SLAVE_IF}" > "${NETCONS_PATH}"/dev_name + + # this should work, since the interface is not enslaved + echo 1 > "${NETCONS_PATH}"/enabled + + if [[ $(cat "${NETCONS_PATH}"/enabled) -eq 0 ]] + then + echo "test failed: Unable to start netpoll on an unbond iface." >&2 + exit "${ksft_fail}" + fi +} + +# Send a netconsole message to the netconsole target +function send_netcons_msg_through_bond_iface() { + # Listen 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 +} + +# BOND_TX1_SLAVE_IF has netconsole enabled on it, bind it to BOND_TX_MAIN_= IF. +# Given BOND_TX_MAIN_IF was deleted, recreate it first +function enslave_netcons_enabled_iface { + # netconsole got disabled while the interface was down + if [[ $(cat "${NETCONS_PATH}"/enabled) -eq 0 ]] + then + echo "test failed: netconsole expected to be enabled against BOND_TX1_SL= AVE_IF" >&2 + exit "${ksft_fail}" + fi + + # recreate the bonding iface. it got deleted by previous + # test (delete_bond_and_reenable_target) + ip link add "${BOND_TX_MAIN_IF}" type bond mode balance-rr + + # sub-interface need to be down before attaching to bonding + # This will also disable netconsole. + ip link set "${BOND_TX1_SLAVE_IF}" down + ip link set "${BOND_TX1_SLAVE_IF}" master "${BOND_TX_MAIN_IF}" + ip link set "${BOND_TX_MAIN_IF}" up + + # netconsole got disabled while the interface was down + if [[ $(cat "${NETCONS_PATH}"/enabled) -eq 1 ]] + then + echo "test failed: Device is part of a bond iface, cannot have netcons e= nabled" >&2 + exit "${ksft_fail}" + fi +} + +# Get netconsole enabled on a bonding interface and attach a second +# sub-interface. +function enslave_iface_to_bond { + # BOND_TX_MAIN_IF has only BOND_TX1_SLAVE_IF right now + echo "${BOND_TX_MAIN_IF}" > "${NETCONS_PATH}"/dev_name + echo 1 > "${NETCONS_PATH}"/enabled + + # netcons is attached to bond0 and BOND_TX1_SLAVE_IF is + # part of BOND_TX_MAIN_IF. Attach BOND_TX2_SLAVE_IF to BOND_TX_MAIN_IF. + ip link set "${BOND_TX2_SLAVE_IF}" master "${BOND_TX_MAIN_IF}" + if [[ $(cat "${NETCONS_PATH}"/enabled) -eq 0 ]] + then + echo "test failed: Netconsole should be enabled on bonding interface. Fa= iled" >&2 + exit "${ksft_fail}" + fi +} + +#################### +# Tests start here # +#################### + +# Create regular interfaces using netdevsim and link them +create_all_ifaces + +# Setup the bonding interfaces +# BOND_RX_MAIN_IF has BOND_RX{1,2}_SLAVE_IF +# BOND_TX_MAIN_IF has BOND_TX{1,2}_SLAVE_IF +setup_bonding_ifaces + +# First test send a msg through bonding +export DSTIF=3D"${BOND_RX_MAIN_IF}" +export SRCIF=3D"${BOND_TX_MAIN_IF}" + +# Configure the ips as BOND_RX1_SLAVE_IF and BOND_TX1_SLAVE_IF +configure_ifaces_ips "${IP_VERSION}" +create_dynamic_target "${FORMAT}" +set_user_data + +# Test #1 : Create an bonding interface and attach netpoll into +# the bonding interface. Netconsole/netpoll should work on +# the bonding interface. +send_netcons_msg_through_bond_iface +echo "test #1: netpoll on bonding interface worked. Test passed" >&2 + +# Test #2: Attach netpoll to an enslaved interface +# Try to attach netpoll to an enslaved sub-interface (while still being pa= rt of +# a bonding interface), which shouldn't be allowed +enable_netpoll_on_enslaved_iface +echo "test #2: netpoll correctly rejected enslaved interface (expected beh= avior). Test passed." >&2 + +# Test #3: Unplug the sub-interface from bond and enable netconsole +# Detach the interface from a bonding interface and attach netpoll again +delete_bond_and_reenable_target +echo "test #3: Able to attach to an unbound interface. Test passed." >&2 + +# Test #4: Enslave a sub-interface that had netconsole enabled +# Try to enslave an interface that has netconsole/netpoll enabled. +# Previous test has netconsole enabled in BOND_TX1_SLAVE_IF, try to enslav= e it +enslave_netcons_enabled_iface +echo "test #4: Enslaving an interface with netpoll attached. Test passed."= >&2 + +# Test #5: Enslave a sub-interface to a bonding interface +# Enslave an interface to a bond interface that has netpoll attached +# At this stage, BOND_TX_MAIN_IF is created and BOND_TX1_SLAVE_IF is part = of +# it. Netconsole is currently disabled +enslave_iface_to_bond +echo "test #5: Enslaving an interface to bond+netpoll. Test passed." >&2 + +cleanup_bond +trap - EXIT +exit "${EXIT_STATUS}" 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..73f7505726a77 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,6 +102,33 @@ 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_SLAVE_IF=3D$(find "$BOND_TX1"/net -maxdepth 1 -type d ! \ + -path "$BOND_TX1"/net -exec basename {} \; | grep -v net) + BOND_TX2_SLAVE_IF=3D$(find "$BOND_TX2"/net -maxdepth 1 -type d ! \ + -path "$BOND_TX2"/net -exec basename {} \; | grep -v net) + + # RX + BOND_RX1_SLAVE_IF=3D$(find "$BOND_RX1"/net -maxdepth 1 -type d ! \ + -path "$BOND_RX1"/net -exec basename {} \; | grep -v net) + BOND_RX2_SLAVE_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"} =20 @@ -180,8 +213,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 +224,26 @@ 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 + if [[ ! -d "${NETCONS_PATH}" ]] + then + # in some cases this is called before netcons path is created + return + fi + if [[ $(cat "${NETCONS_PATH}"/enabled) !=3D 0 ]] + then + echo 0 > "${NETCONS_PATH}"/enabled || true + fi # 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 +420,105 @@ 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_SLAVE_IFIDX + # local BOND_TX2_SLAVE_IFIDX + # local BOND_RX1_SLAVE_IFIDX + # local BOND_RX2_SLAVE_IFIDX + + BOND_TX1_SLAVE_IFIDX=3D$(cat /sys/class/net/"$BOND_TX1_SLAVE_IF"/ifindex) + BOND_TX2_SLAVE_IFIDX=3D$(cat /sys/class/net/"$BOND_TX2_SLAVE_IF"/ifindex) + BOND_RX1_SLAVE_IFIDX=3D$(cat /sys/class/net/"$BOND_RX1_SLAVE_IF"/ifindex) + BOND_RX2_SLAVE_IFIDX=3D$(cat /sys/class/net/"$BOND_RX2_SLAVE_IF"/ifindex) + + exec {NAMESPACE_FD} "$NSIM_DEV_SYS_LINK" + echo "${INITNS_FD}:$BOND_TX2_SLAVE_IFIDX $NAMESPACE_FD:$BOND_RX2_SLAVE_IF= IDX" \ + > "$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 )) + BOND_TX_MAIN_IF=3D"bond_tx_$RAND" + BOND_RX_MAIN_IF=3D"bond_rx_$RAND" + + if ! ip link add "${BOND_TX_MAIN_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_SLAVE_IF}" down + ip link set "${BOND_TX2_SLAVE_IF}" down + + ip link set "${BOND_TX1_SLAVE_IF}" master "${BOND_TX_MAIN_IF}" + ip link set "${BOND_TX2_SLAVE_IF}" master "${BOND_TX_MAIN_IF}" + ip link set "${BOND_TX_MAIN_IF}" up + + # now create the RX bonding iface + ip netns exec "${NAMESPACE}" \ + ip link add "${BOND_RX_MAIN_IF}" type bond mode balance-rr + ip netns exec "${NAMESPACE}" \ + ip link set "${BOND_RX1_SLAVE_IF}" down + ip netns exec "${NAMESPACE}" \ + ip link set "${BOND_RX2_SLAVE_IF}" down + + ip netns exec "${NAMESPACE}" \ + ip link set "${BOND_RX1_SLAVE_IF}" master "${BOND_RX_MAIN_IF}" + ip netns exec "${NAMESPACE}" \ + ip link set "${BOND_RX2_SLAVE_IF}" master "${BOND_RX_MAIN_IF}" + ip netns exec "${NAMESPACE}" \ + ip link set "${BOND_RX_MAIN_IF}" up + ip netns exec "${NAMESPACE}" \ + ip link set "${BOND_RX1_SLAVE_IF}" up + ip netns exec "${NAMESPACE}" \ + ip link set "${BOND_RX2_SLAVE_IF}" up + +} + +# 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 +} + +# cleanup tests that use bonding interfaces +function cleanup_bond() { + cleanup_netcons + + # Delete TX ifaces + ip link set "${BOND_TX_MAIN_IF}" down 2> /dev/null || true + ip link set "${BOND_TX1_SLAVE_IF}" down || true + ip link set "${BOND_TX2_SLAVE_IF}" down || true + ip link delete "${BOND_TX_MAIN_IF}" type bond 2> /dev/null || true + + # Delete RX ifaces + ip netns exec "${NAMESPACE}" \ + ip link set "${BOND_RX_MAIN_IF}" down || true + ip netns exec "${NAMESPACE}" \ + ip link set "${BOND_RX1_SLAVE_IF}" down || true + ip netns exec "${NAMESPACE}" \ + ip link set "${BOND_RX2_SLAVE_IF}" down || true + ip netns exec "${NAMESPACE}" \ + ip link delete "${BOND_RX_MAIN_IF}" type bond || true + + cleanup_bond_nsim +} --=20 2.47.3