From nobody Thu Oct 2 10:57:10 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 B1DFD32898A for ; Wed, 17 Sep 2025 12:52:16 +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=1758113539; cv=none; b=CUOWDjLqMENTY6JFZdEmbQwjRkGfVBv8oRW1GI0zlKuwqgzuc+BFatgI8zNuN1p1vi7+0w//QQvxncLyiA6u0tnbH81yJlQqjuTkRpveiCY7YZoeyOKYUVo/jThYKZIFNDa8tHLEy8HVuAngs1W7kxNW64+Eg6NPRmWOXXXuiBY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758113539; c=relaxed/simple; bh=0qblMs7pvAvukMaqH1XZzSc/HsAgRmJmnlAnkCtcl+M=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=RQwj0HGoKXlnIbgN8iJ3jBDQw+vo60G4+hIp2Zpa+d2iIKz/HyZ4RZYFhSYvVfVYyRPiUXjRIgGfDy/11EUid2tp5lx3WF1RZ0pPXlqAz7GoR+HgUB2J9jIKA6R0VLnm63RqDJ4Fc6UZ7EKfBmoYawFu4Jp4QFOvEtAz/bTmPvI= 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-62f1987d4b2so7984685a12.2 for ; Wed, 17 Sep 2025 05:52:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758113535; x=1758718335; 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=uXueQ8KQd6pmMRNKDrH1WYGpwKFoBqWRPS4sLEKgzg17KGJmFIkVQnfcj5ghbjXR8t n33Yb1XOimWR9ao/+HBNXHfONN0Q8dXN44yZDKXnWfxuJfktzpyySO9LZ6jw8CR0JbVA 3O2q51X3Fz7VUkKv1M86Zo1rrGqw3Rg7N1/008vFwMQrqIiBrqE2aBhU3mUNgYCRP9XH 5UB27aWU+Y0w50ydN+kuxc54JDm0dL3F8AYw9/B8pclBVokKdJ2xHBZH9MR98qVuAOKW SGysDfVPWhtD4p4xg1ztrqk4eJTpkqFs3w2BwiLkGUCiN+PH1hQgP3uh6QPDy0ASnQ4U LldA== X-Gm-Message-State: AOJu0YxbL54XiDaeMf/BbjzBZy112eAma8iQHicfMZjpK+2mgVil2aQJ MCxSOgPEawdvj00hTghf4Qty8lp50s+hJxgUubGEPuPx+y8U9F0eLO2y X-Gm-Gg: ASbGncu/xKsh7SkbpZzZEo9fvT5wjvOX3sI9qrFcnSwV5lr6wr89KmzMYM8uuCMAoaY 35aB9kiWtb8SZY3tNnD61R7c0Vqm6uxdvhbfyZmZzKTGYi7NATX+ReWeIwWt6t1X9dadARBu5ae 8BTVuHQzSvg7asBbTCQRvKmp7Ow+5614vzsXlzUilZdL7VoCPpkUo4avWQNsUKm74nOMtvHKy22 wzWa64ykjInY4pQwWyDMKwEIWwRw3hAUk48KRV0E4iS63oFSUySoKrFawMNJYLbAUCA0LDYh2so 2ErEl8gQZRx53fQ5MkcMqlysAHUhUT3iBM9iCqHiVl9W1PNOGwFrdmMEVoYqxv/6VC9NcnDu+Hb WkiwgIwhvXHjB4w== X-Google-Smtp-Source: AGHT+IGcKNDtBC4IjzRF3C/1A9WDY4PVAXhCw25GqLowT2AP0xhnCrLG2vPouzAemnf5ULAz3hkDMA== X-Received: by 2002:a17:907:9444:b0:afe:b311:a274 with SMTP id a640c23a62f3a-b1bc106eff5mr256536266b.46.1758113534737; Wed, 17 Sep 2025 05:52:14 -0700 (PDT) Received: from localhost ([2a03:2880:30ff:41::]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b1c11d45587sm114087366b.12.2025.09.17.05.52.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Sep 2025 05:52:14 -0700 (PDT) From: Breno Leitao Date: Wed, 17 Sep 2025 05:51:42 -0700 Subject: [PATCH net v4 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: <20250917-netconsole_torture-v4-1-0a5b3b8f81ce@debian.org> References: <20250917-netconsole_torture-v4-0-0a5b3b8f81ce@debian.org> In-Reply-To: <20250917-netconsole_torture-v4-0-0a5b3b8f81ce@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/8eHdtAcsmYgBoyq77ikqYfP1RsaQ1IywqQvoCiFOi9x4LHFf3b bZdGzWOyqiJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaMqu+wAKCRA1o5Of/Hh3 bSuvEACZOgjHa9YCJXRrUCYSe7rbbAYJhxe8eWRbe/mAXDcoBW+xpoh1HUdkdE1BAw7KwCch3f7 Cvf/tCZ1PG9v+NXgAL8A1R9jwarbT2vNayZo3f9ynePau6EOLiptAvpyqr/RoNvmoF7GvF4ELz9 wLx8oNvpTzgSNv6K2o3SEGxewOQweLFfIo+9BOHlJvlXvtm6J4f0MaMcgHiGz77YxM3BYKfNlIj 8RY0q/NZCmalRYOMAvonH0AJkLXJvwGKVEH/k1rgFTK7PEE9ayZV4sfcjBE74CUOAjQWam4FFIg 2mDTwda3SsxX6zzrNx5FPuQmMYhFCWDHqPwTm8dqatgr3VYnOCOrNRHmICT+S6g7W2CSOdveycJ ttTlVgfnzb5nskzsZCipFeIx3K133loOfy2StaLgIcGcx6XM4vE4vH43DF1Wj+uzzJiLm/E3wzp sMjRFKKqgwBxYZizTWVnwRWcax3N7iMHLyA4e7wkwX68w8EEnqzUKpBdVNcFYaALDTo4eR1LvDj klGCoybhLWEBaAlEwohhAInLBwj/lJeg7lln5Y3DkWaU8z8DPCBcvc0i3y18oSW4L/rii7zaa+b Nhd262M16Gx8Xt1rG4YQB0qi3HzB0GrqDifWCYwgFIaSYRaXi8ilp1/xfkZmrx9IvLnSojLcDbU 2eehCEHIH6FtR0g== 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 10:57:10 2025 Received: from mail-ed1-f41.google.com (mail-ed1-f41.google.com [209.85.208.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2B9D532BBE2 for ; Wed, 17 Sep 2025 12:52:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758113541; cv=none; b=eD1+yz/d/qugTsXG2+KgoZXqcYvjgyvgCZc7ZwmFyQ9QSRSJLMfWxqwrX15Kb3Q5Lyt9EvOyb7VAxJ3gCmRSqUJe3GYxtObjrEn4kSJWGN3fK0hJKylSZXOhPs4iq3Be/s0X/cB0oHYB++mN8urgHghRpL1d5TneOuvCKOx9n6w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758113541; c=relaxed/simple; bh=g8Rymja0V72nq6OnDIyWQadzgQlOQaCKBNDvE6hktyo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=lFCRWf2dhBLKrYsHzE7vFEKBzB5Yn0UwaYWia7NNCxFCRxpajssKQTLxxJK9o8o8kjQQn7t+f39EgoasKltlEtyHDqeMg2SHb+bRYcG+GguSSkKdktkpCKp7IDeygl9PzlWTlqUAQDtHkH+nLf09uWz8MleIBrEWuBztnNcnnBE= 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.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-f41.google.com with SMTP id 4fb4d7f45d1cf-62105d21297so12818432a12.0 for ; Wed, 17 Sep 2025 05:52:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758113536; x=1758718336; 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=nO//K4iJyg1Z6SU6OM3VaV2ZpqUTwV+vLikutwPsANwnJZuwWR0unIv+yg+yhypmfP 5fcBdH23LC91Dp8wrM+cyHapBClS4rYla1eJlC87QOSLa4ulhaqsc5FUl6wDXjZ4csGh t5Zar+xs3vvYIXj5zrDxE25DbLWLEjj/grB/WIb0Ew47htWA2MXwA0XKCwodgM0AAPXL X+9PIhdxoePpzUdLtIKemuszctnsrAnkqotHs2g6LgHV7fa35TrD1h2tHdURRj9OfswB CqMe2V5wg/TvxP+7Md7/YSeHMFzEEf+fl4kGUNqrh0jgMNDJo5WacVxzWYheuKYMH0/N XAwA== X-Gm-Message-State: AOJu0YxyoEIqnJ9N3CdTjJYyy0+MmbVWp4C7eOCDOLz7QPevrQioXkw4 SIAzU2cpi/6HIGmYnKdn5uBdFtrM5AtB4VE7EJFWt5UUpD8/cTaOVpRn X-Gm-Gg: ASbGncuIqfv8SoDpoh+evfr0PGpYd0w3P4hFW2R+9jaQC0TZ6BJHev4dIpKlotYsD50 P9zKb9axvfpYXXMLwYC2uzbcmydUPdT9Pih93AgzR0URWFA/J7+3gFfGIA7nXN2W1e8/EA6PH5/ pzYTSQ3ESvn9IkPhAASKw8S1iNjNvoU4giIN17a6Jp4prk9P1O8dXPA1hQjJYkKkWuGx9DhSKMX oDSaSgIqpBVjjalt7qKGpJy3h2a5JK4JE60QybZ6fcj+6itqeEM1259Yso0+RYAU331DtIJqsjA 0F5+aYnTFkvhHu10OsBSEKKO67owHxmJstqZc1dWYvB83dKW4BWJCMv39P4J6CoOiCFiA+LBEAd TPV22WquTCq4f X-Google-Smtp-Source: AGHT+IHhku+j1T36cuiJ0d0xS73leySID7J8LR0tE9XWMEffbke5MNL3JEXPU6e9cXah2ZqkPOnqwg== X-Received: by 2002:a05:6402:440b:b0:62f:4040:bf70 with SMTP id 4fb4d7f45d1cf-62f844623abmr2323884a12.24.1758113536187; Wed, 17 Sep 2025 05:52:16 -0700 (PDT) Received: from localhost ([2a03:2880:30ff:7::]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-62ec33ae181sm13708626a12.22.2025.09.17.05.52.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Sep 2025 05:52:15 -0700 (PDT) From: Breno Leitao Date: Wed, 17 Sep 2025 05:51:43 -0700 Subject: [PATCH net v4 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: <20250917-netconsole_torture-v4-2-0a5b3b8f81ce@debian.org> References: <20250917-netconsole_torture-v4-0-0a5b3b8f81ce@debian.org> In-Reply-To: <20250917-netconsole_torture-v4-0-0a5b3b8f81ce@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/8eHdtAcsmYgBoyq77IMhtUQqCc1NMy3UCs+bE/0aGxgsG0YiA8 DmMgqxfUzOJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaMqu+wAKCRA1o5Of/Hh3 bRoYEACuWR2zXSe2VYyFo8PEEJn1uxZuK7cjyF2DM6sRI2XkJ9D2Q3fkIJwoh3eyBqL/1JBFxfB dmC0MO3m/91VTRaZlsz/0V4wtxbZa4jIp1H5KqUJzyYJM3i8V6Nfl7P4y2mT0OZl5uljSS4nS4K iC1/fK0DFD8CAuCITL/t5CVb1cLNRgCvDtD7r+zqi5KbS8LedlR1a3YfrEWc+xFXPmsWs07H+6p kf7/Du8ZyUNSxdJVmi6jCEpFBFi+8fEwQZZvgaDjuinbCgyFcpVpWvgxkWZ9a0yTgvd/PzINR31 T6U8Ohqb3iAr6kMNg3DhY21ilX4kr9DP0e5H4n18Swg4zHNEz546ZG0U8Aecv5vnjrs6PzFcwNg 0TfRSuPok/492DnJlhjR9O8NO8k5RQEion/wMJLkB33bY4Ea86TNfEGRqlld7K4LS1RKlt2E61v yDLP3iKGake9vzG9FDVUR3MzW+MiWlv6UmqJ5ysUv9bV0tGqTnDsusSVRn+7mJltwDjuI6ApIzu ZLGAgtEI1rCmxVpABdLerok/V7c/7Gy2y9pryuhG3Vwtf9PxtieNB7Kb0DZRfaKNcLmuk55enF4 S9PDa0/5Rg8HXEXMUigcm/HrJOPPoQvMMDYOUoEhxpYeeIGSGKQ/RNMmikDPVLnCl1z204whjuV K/ONcQy8cr40z+g== 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 10:57:10 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 DA96B32BC1E for ; Wed, 17 Sep 2025 12:52:19 +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=1758113541; cv=none; b=WwmNsyxgDHd7tUZaL+cUuxo4a7M7nmX8L9VcMIy47MObUHApui0X9W/KoKYbhxG4EYn+HLPAHDHYKH5sjPAhHa6F8ah2hA8tEKrRMm8ucs+4cp1nUAnfcaU0bS+kmx/ywRaW5bZ7u9O5/M7cF1KDlsaHnb/lvsoVRSSq62r7vnU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758113541; c=relaxed/simple; bh=r5EfBfSKIMrv477f7G+oCA4XbIivs+K5Gn+BWOKD4pM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Z5qhWdHXdOz5Fw1lJxp15uKxqvHUQ0Ho4ggaNMgr9vIYVNNaodfjP5MfynFNJsdrAt1Ci6/te8DTKSA8nR8hnv3p/peP/9t9IFaGJJ/vm8RVr0yruT/JOl1rhzSwwP6wg4Kr5pmnDhZJh2vPD509gGacUBhkBSApPOmpNLXy/og= 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-61cc281171cso11206209a12.0 for ; Wed, 17 Sep 2025 05:52:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758113538; x=1758718338; 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=B8g7UcBIXs26hAWNvuNbRdwnLJkrypreUCJrwcNAvpI=; b=l3/tJCM6hraWlIwlk0zgdntq5YFsT4psVU9r9wQqLxFExZ6mBsHxApRy/Im7AAU40w BlE/B/5q+hjkrl1OItKBMTe7XJBkb4XxHo5Il5aw7GWrnn9d8lfsowI4MSE9Q/X9Xd1X zD2t3HUVPJM8K874uFq6OCvO1eLHkVbe4Gp8AQ+82u+LbJjNba5b9h5zOhsSDO1z9Mwf RWnALYz4CteS9LblEr3BTl4JMo8PipaskuBtWQHJxAmPzTI+g/dayxGzwrTwhvrlXd9O f47ZoAxcPW9WZtqBJ4a2SA9kLiCmzng0C/vGNYPpHmvk0bLzLdhgm9FLdXd6wy4z3kfB aMUA== X-Gm-Message-State: AOJu0YykziP+PrQ1lmArzKbRw+lex/LB3VNS6lD0mJFkjZisQveHrJys JUYBVgYJmQuTtMPXP4/E58MAufuzLZMHSLlZPRjPsEWxE2zAdXIHVSDn2PlruA== X-Gm-Gg: ASbGncukIQX7dDm4zzAMZKUD25KSkbkuaHzHWS4HgmVtVDIQcnK/TVYF4cbDN1wyv9F w5kR3Bn1q4gB99+hjTxd8BoHGEiVwMz+dHVPfD+2ss+Hl1S4SH7p6asXa9t0CIh0yv8+YBSw80L 6xwsOoYKXY8dfeUOj04wG33YqynvcqiQSzftXWYFQ78dV2JGgKAIe88rzuogTaY+qD/zpZs8KWe R1DXssKKl19d7XjzqASe6FfFw8SuAv0NQiYh2ybgnleIVxNIeFfRKb9u8eOdtlOqm4axdbDPhTI Feq8zJk3yXdnL0uvkmw4kEQoWjEm3hp/qlJBmUSywsNQMQQqCToDQG5SOBcUvdioqsnvlzLRcJp lfSost+gzswZD X-Google-Smtp-Source: AGHT+IHTSbPsp4F3Yju33mS4p9sEo3aXea3qOqf9CdOqp53LQeo/NydDmk2umI6b6gKsykQWoXn1Nw== X-Received: by 2002:a17:907:3fa1:b0:b04:20c0:b1f9 with SMTP id a640c23a62f3a-b1bbecaf490mr245783766b.52.1758113537973; Wed, 17 Sep 2025 05:52:17 -0700 (PDT) Received: from localhost ([2a03:2880:30ff:6::]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b07c337e785sm1195125766b.25.2025.09.17.05.52.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Sep 2025 05:52:17 -0700 (PDT) From: Breno Leitao Date: Wed, 17 Sep 2025 05:51:44 -0700 Subject: [PATCH net v4 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: <20250917-netconsole_torture-v4-3-0a5b3b8f81ce@debian.org> References: <20250917-netconsole_torture-v4-0-0a5b3b8f81ce@debian.org> In-Reply-To: <20250917-netconsole_torture-v4-0-0a5b3b8f81ce@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=5258; i=leitao@debian.org; h=from:subject:message-id; bh=r5EfBfSKIMrv477f7G+oCA4XbIivs+K5Gn+BWOKD4pM=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBoyq77yytWubbprz0ljy6yMvY3u1Cr+N6g6vDUL juUk2QrHWiJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaMqu+wAKCRA1o5Of/Hh3 bQeQD/0XSQ6iM2BOau/ThxHm56EFKGBJAMD7gvCazvvxLXmj/QJxMhHzzLJZ8kLQ6GM3KxONl6N iJcghZXRSMF34SiSa1r4XNpULmWvHKDj+TGLoDh+QjkqZ1bWSB2E7jTEnELaw6XWMJXnkO8sDsK +B5iPZhufDcEKRdcoJV3P10F2I61iKsoKbxobK4k1KBDt07OgUgjEQCYXI6SGK9R0nVnpcv+Z5c ywv+XVUAltzV2QBA1RBI7SpZcMRALayE4bP0Hqftl4SiEWuc09APzr5CpRuAfySF9Ap87VSyNgw kQbm/yVQ1anmmPVSZRj3ZcKKoP/eaFcENwoe4f+2NlWkYJOcYBN34PZdpbWvpn3EZHo41Jo+9Xe McsBhL+J/Cc2MnGG/+qsDQ+54vSpeWDQVXZ+Js9xdtZ9F3jeTF80a09bdctbzJc61lYvZn4M7h2 Ng/oEcWhGRfMDM33GYrsQGQJsTKXOyqMWO6dH5yxccuzWqXQN1zoVyns7KZ9JXG7nodiypJ6NEp G+DsSHMYazuqJejEPmNYdfqAfjTvMV/nHDYueevdpN6P1DXYNH8VDGhqnwyGZCVSsHBMfu8gYEh vbLGB72N34hui1elpswHPYiRRVfx9xdjB/zxu0kVDGC1RCKlJM4tRf/IDMQ8NwClFgrKiqIaHHR z3oD82pkCsTZb6A== 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..3608051d475ff --- /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 "${ksft_pass}" --=20 2.47.3 From nobody Thu Oct 2 10:57:10 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 86E3234572E for ; Wed, 17 Sep 2025 12:52:21 +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=1758113543; cv=none; b=X6MGKBl+0nQr/T880gpjtO6GwLfkLrFBCnpPZKtGySNuKIJB1ZH956DuP1AXAt8ISPMDt2noOw7xeiRvCSkQeC8/RiJgGZ+5f2wBiQw8K7TpARx7ZRv2KV3cEbL45Mprr8Q6uOOMNnu0EVcp6ETBTbcHNKMomwN3oTYrw9j54vw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758113543; c=relaxed/simple; bh=xydTUOOwR+kb4BiGLwqzztmAAKwAAbCtW7zc4Xhr3I0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=eiD+fIDu3Qs5Ym5t2F0JrKfwolk+3QJeJlo88MnvXnDA5DgSciY+wzYHw62AJR6NRz/EKrj2PUD/lVeTlAv9cZbmJ+OsDcz9PQbfF5HOfvRw/+AY6eJJUdMQkuf4Fzrykzf+pRvo3nsixcZdRdIufEfG99co0wX8fy2ojuocudM= 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-b0787fa12e2so944899866b.2 for ; Wed, 17 Sep 2025 05:52:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758113540; x=1758718340; 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=0UUKIXVVQhORiL6o2zggCDFLRC+Tn3mg+SUCXQ8RI4c=; b=AfjdoQSg05IqncHgmWhETj8clxHuERbi4RGeNjV2I0WUNExm+ei+JJirGX8r8xpS2J pr3djV0IVMeBO49GCxV0qSxyL22rCIGyqok2gsnRN1MYt6qOdKTqzDswhpEPnD55O2mY psCP2wQvihv0sQsoLzKirH+mCCH8eZhdlhvn3qtFo1nmSTbzYJwtFGVNCqQv3m+dCdc5 VIMYrod2H+WBhIWO8qRdL5r79j4Bv8L0aJQFx+YvDAUQ9io7A3lG2xAHcCow7KS/xzKz exkoP18K3SMWUU9PyQ7/YlbpCLCkNoJTk5unXIeDnliUNVAsGs+N8VnvuTqZUKUoMa8X KnOg== X-Gm-Message-State: AOJu0Yw30jNBO3B5+sfH0PRnVCUi2CeA/E06ADBhc45uhWrNhXX7t6M4 rZAObW2SjeXAHlhdLU/oYuAsdx1b13EvAkbedUrqa7tz8hMgAgMltLMd X-Gm-Gg: ASbGncu1sYxjlk2y03NKECenWT0EXM3aR+J9RNnHl4XUF/RBy/vALqcvQ+BtXKi4q3I eksSv2nr8RYvdisqT7jUdfeBcq0WbeuSJqYB9hBW88TefzlWm4ZOczlZaCZwtmL6J3Gc+8dLnSP rTI0RWBiz3G7oi1RQERafXtHps5HFsxerGSER9jKACWCBiUiZKW4KXhidvMTHF1RNbJbg5MKePL 5Fwrq1XUdUgsKGazgcfyNuuIpEYMRB2nhFvNZiQ49CEA08KOr/zLzR0c1iWDBtiFGJ65ywMhcGQ cQXkv7gTqT8mJTX/ZVuCNQXyDJzIh61nvZnHvO0jayL0dzq5+qOB07DY2Pt2RJqYftQq4ZCeRlR 0bxYNiumqoq1Z X-Google-Smtp-Source: AGHT+IEeSwxR761Zx/HgsbV8wEkAW/gpnsYRMwqUPjR/FKzQf5EVL3B+45+LEkfHmiRphhFyY3eD/w== X-Received: by 2002:a17:907:2dac:b0:b07:c909:ceb0 with SMTP id a640c23a62f3a-b1bb7e35eadmr224042266b.32.1758113539523; Wed, 17 Sep 2025 05:52:19 -0700 (PDT) Received: from localhost ([2a03:2880:30ff:4::]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b07b30da542sm1392489866b.2.2025.09.17.05.52.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Sep 2025 05:52:19 -0700 (PDT) From: Breno Leitao Date: Wed, 17 Sep 2025 05:51:45 -0700 Subject: [PATCH net v4 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: <20250917-netconsole_torture-v4-4-0a5b3b8f81ce@debian.org> References: <20250917-netconsole_torture-v4-0-0a5b3b8f81ce@debian.org> In-Reply-To: <20250917-netconsole_torture-v4-0-0a5b3b8f81ce@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=12638; i=leitao@debian.org; h=from:subject:message-id; bh=xydTUOOwR+kb4BiGLwqzztmAAKwAAbCtW7zc4Xhr3I0=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBoyq77aVAd8MsswrPsiASqaObU0Z6xMqt4s1eiC 2wy9K2MesyJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaMqu+wAKCRA1o5Of/Hh3 bRxaD/9veBRmzdAY/Vi4yjScqEw35Mzthp8KBWv1nA5pa56SK/ADczLTA1EPv7tIpfvRQxU3uyt mWJpMJSXe/gMhu/AEh7WJlD1fIWQR91m56mrBFKe2hUbWvhzHJar1lkOa1WWH7lp7n+fTQURuZ7 0jEiGUPCbgy8shGI9GAUxzcp4afMnccW99PXG9z0LuTo0cVHR6foo7oc9C4e+f/li0Q3wE0e+77 zU8/IE3MqjG1/LY75YElMIcXTI3o9ezpmPibXLthoYBWCdgfYMk80vDGgnnBgjEYqwZNHGcMQeC Fu/dPgn5thHOUOytwc3kYilaCE9W+x0gJAcS3Aig+2YAHxX7eGjLXxnfJP2aQfLUPyZcm7Orywn dSqhnTPkYpDUHR74deJ2QoKU22RyPiI/45/Xrw/RmI0CftQqSlirzfkv7by+Po6qIZUxfkXUMfe g86CO+qIjgKUSVTD4sYOhVpWw9cOAH5DALes8CLtLj5dLocuduUO+MRRE1uuNY2GBDnM+eWHHo6 Ru5zzgiMcYKzZ1FyApUi2z5X+wGJlifDwaaNb7uQ2o6nlzriGycKa8jzn4Ab22NafRmBuojlOFm 7kg9m3AB6lGXrqBfDgxzuKHwu/uVxVV/NM1PZuGlFho5duYRVDqSOqFjB/P4Urus7DdMxoAC21c 5lzPE+TlPFBhaaA== 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, which is already set in tools/testing/selftests/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 + .../selftests/drivers/net/lib/sh/lib_netcons.sh | 167 +++++++++++++++++= ++-- .../selftests/drivers/net/netcons_over_bonding.sh | 76 ++++++++++ 3 files changed, 232 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/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