From nobody Wed Dec 17 17:40:45 2025 Received: from mail-ed1-f43.google.com (mail-ed1-f43.google.com [209.85.208.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3ED8E27A919 for ; Fri, 3 Oct 2025 11:57:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759492644; cv=none; b=g7BUo/BhN7O1sxYx7yhJpSgXQYQ5sF/rSt7rNQqLmg9dBsdMHpdpOBw/D1XKBkkftObwfEPlW9i2E18QRlPiYYYwRrw9QIx9Nv7CPY1RmGZvGVBag9FtmTK+ETtcFESdEGspEj4GFPNUy/mgyJ0ph15yQDMjvOIHNAEyPIXWVI4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759492644; c=relaxed/simple; bh=+RzgxlXhvAjihAWHcJSiVhsrURV2de8MPdHHcOWTs/g=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Qpd+uZfFF+gkt1IJupolDK5xBmIl/0mQe7k1AGmyxsCPD2u4Y67LI/UvGmwRcZTwFpQhYC5hiw/mXmODWn9NXyDbgcK3tEgp9loprL0+sutT91qWS1v8ARThmXAyn6ICd6iY89Pg5gsN15t8v8zcMUZtf+F+pf6XVpCFSLVRRK4= 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.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-f43.google.com with SMTP id 4fb4d7f45d1cf-61feb87fe26so3234316a12.1 for ; Fri, 03 Oct 2025 04:57:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759492640; x=1760097440; 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=wnyKnLculZ/3rlZ7WNi7OX+cm7Si9QBwXmjKwiYq8Peeiuy5EqGzkv3MYE3obkNRCu DO95SytSBbI1N4x4JdRSWMUS97HSbn9BqSGTEoAW/DexvTWPfoGknikPIEGpGj87SVpL LMLL1kg/bXgjVgRitnYztABxOkK/8NJbV5XJ5oTQN444WTgDKJScsX8MLM3p5tBIgVlJ GsEbgcWKLHNN09eBjQjXhH+2pJ5NT9tMQp4ZiIFz7ZJowdYdx0oCH4YJqirIVpOToy9Y RJ2pOnEyvSOwapM3MKh6aD5oqmd/9cAm5rKiIkfDzJmM7alz9TDw4qnRTIIm7oWg/eD6 7AkQ== X-Gm-Message-State: AOJu0YzdcFACVLUjqZtwmJPyb2NCmypRpsdiFHJZ+dYFab7KP7Vos6Sa kPuQP/R52GriGHQV5S5JzUgF4twKWI794O17KLtaE45soFLhIflyIiVp X-Gm-Gg: ASbGncspizlv6coqn2GkjR+DNK0X1PmppjVM8Qy3C2Bew890bM7DG0zPiXd9deCNwYT RVXiD28HOkFCPHC17GApBvOtZx8qgC9l+VyOldfJf5XQcwPSpCrwJe1PlKxefZpgm7oVPidY20N 4XcIri21PUsGlwS0zTzCepm80zBbxO/UrntXmWKwMhbkI9S4qFPUUdagofNXxx57MQeNnWKubSv H21aA93vmd1uWXRSEvmIoK9kqLIBnIHX/R9yZDMtcqxPVwKh9t0a7Qu0p0N3zde3FwN8gf8CaD7 J+Yi/wc+R26bs/tRWiMTXGVGSXpzRuOrYVMU/3JxGYg82dyGu9QSf/x26juOw+OcQiO2YDjamWF nQqxF0smKzxA0QIvh+fdmI4lBgANMOFAY4+P73AxpmU2lbUeqrmysJzI6kuo= X-Google-Smtp-Source: AGHT+IFpV/823baDEnkWXtsZgJSHpqM6pPT3docQw0LYhsvgAr/IMB0l5Cup8boOngZWnvghRP3wEA== X-Received: by 2002:a05:6402:3585:b0:638:689:dee6 with SMTP id 4fb4d7f45d1cf-639348e6e8amr2796933a12.8.1759492640334; Fri, 03 Oct 2025 04:57:20 -0700 (PDT) Received: from localhost ([2a03:2880:30ff:74::]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-63788112bbdsm3866461a12.41.2025.10.03.04.57.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Oct 2025 04:57:19 -0700 (PDT) From: Breno Leitao Date: Fri, 03 Oct 2025 04:57:12 -0700 Subject: [PATCH net v7 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: <20251003-netconsole_torture-v7-1-aa92fcce62a9@debian.org> References: <20251003-netconsole_torture-v7-0-aa92fcce62a9@debian.org> In-Reply-To: <20251003-netconsole_torture-v7-0-aa92fcce62a9@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/8eHdtAcsmYgBo37odYpsGtZhECiITMdqo2bef9kXbNLlvzWt0x +wCDxTkUSKJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaN+6HQAKCRA1o5Of/Hh3 bdgOD/90PhNiCa0N3WZOW/7jGtNYrv0KINyhkhZpziG0lqMOooyDWLfAnC7GZQ8blbA/k4TVdIw RKAScM2pqkO0f48vBRrpkp+9wwxZeoAlMLBJziTp728hFfXmPrYxJpmUT17z/MLg9yxE9YQHr9t JG4V3ldShZR2RSZbbhFR9umA5gERU/yyk+1Vtv2F+7kQglhr0F98RiYkEEqGkKDZ/UUTXGEEiE8 u9nHKMfqCt8AcVHfoqgjI/PCcaBqqGBS1L8mVLXydW7hpEXvLTg9uKkGRcTF/njLEjXnoWYRSRq pMIMBVDG6SGMM06viMtX+Dak03BLE+vE04Y7nddcd6YYDDzXnnce14xRq5bXpkV2yDG4MvENurX qFubY6S+ChXUtS99c7retQ3oL1OVwAJ9gO73KYKlifFp9DbFBzPJmPGhjXosEzytwnVSkY7ts5/ en1rQWqRVbBKYExWUqlCVBnJVJgx0tyh1FmlG5usw80CpGiJZZQUFHt0C/OWR7vdVZHL+P0gQ77 pncLW7GJlQumUBPtundGviRV9ai/ahvsFfxlu0YXu+bSeCE9Y7s1v7pOk4nfMhck6gOWJfrZsbE XciLMbijeyAmbMFVQT3f+O/4KVwArgyV0gtO2OeYO/0O5ZV9+qQw0GFjZDKgEnCHdCHG6oZShDa 0bQ2VxuiYLF6B6A== 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 Wed Dec 17 17:40:45 2025 Received: from mail-ed1-f44.google.com (mail-ed1-f44.google.com [209.85.208.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AE7A627281D for ; Fri, 3 Oct 2025 11:57:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759492645; cv=none; b=TulcXogfnIdECd5tdH+zikefud5z+qcbNxObboLBx9oUgkahsMo3T7gmKlQTz8kVToslzp0R2XGxu7+8nsY5huOgpaiCte87uIJD5DW8Cms+jIO4M6Epu2hTKsBviK9GbjdxigJdQgDnX89aDYhr/Y7rstI2tPkI9pqK1WDJis8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759492645; c=relaxed/simple; bh=g8Rymja0V72nq6OnDIyWQadzgQlOQaCKBNDvE6hktyo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=XX70W+Z6kvpaUgmybrgMYmunHsOa8FPwrW1ilB81uO1WYZ8bPhVkwVUQinmAGv69rhaXbgDJYxs37d8FB6SPKufkQW/kwdwehBeuQA+bjAG8r/eDAlSo9T1kayoJOrLnDnqcFW2LJWSubY4zsD8PH7o00+LhpBbCIi3E6Yax0lM= 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.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-f44.google.com with SMTP id 4fb4d7f45d1cf-637dbabdb32so4055303a12.2 for ; Fri, 03 Oct 2025 04:57:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759492642; x=1760097442; 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=LNsgxA4Ln4LIxh5HN7oDJCZplx1tJUW0xaSTvKGaakGi6E879FNzYPzkvcBflyiMWf 0Pal74tvU6wk+SEw1T+mtzOgyJadYmqdCK4DxvFd9RWMAkAX/oBt1QjH9craeVUpZUjT hOw4rtadMMkeTn64/c7xjANVEivlrt57LPNNbh9YnWoxwOIchvvzVKK64zo0he1P+7A4 ZuZYqP2C25ExeB6pB+RArhUC4kBNxtOFZYwJJedtfPoNQho7DnW1pRPsvDCPjO+LlATh 8awLtxgihXca4fYBiNfNpPLqvpyVJybCIZ5jyor5PjtQE3Hhxw2LSlLUS1ZlTIMod90M 3lnA== X-Gm-Message-State: AOJu0YxYhzJO0wkjjAPxP5mvZQUzxl5NW5XBSEe7N5QL8GFax2ee/m4R XoX04z76ZUkJ5KdK1k+G7jdQMwLVZW5Etv0gSdCtz4hmz2R6deoL7mCe X-Gm-Gg: ASbGncszu8jPo/1o6qylZuGSLr4obNiVAzMZuWGkKaTwiasy/DyDVPcNqdMfNT7vq4U QuNP1YFm/wvaRS9dYutgioucj6vrtAr2SINwydAlrKMydGPEcz961iNUik78FLjlGJ3boIz180R 9txy7nIeJ7B13ZLnQE2GZM2g/nPy7o9ee4Z5roMNObVcbXFiERCZ+O+odKwQL6mBYZ0QhqllqCB Q+QaII1FZiyW7RWBjY5tBJzKksoAXTHfzvtbzw6ShKKSzKAyv/gfqtu+9KXSNDo2f0GN5uOrxVU 0IeNGU6OFELD8P04WvDOXvi+qFfcBYTZ/AUd0IQhQ8TYSbNfPHfSqelB6FciDK9IGO1xUh5qkfb 70f6n+XdJC0eKiIcC3hAd105BAjcpU8mde2DrvQ== X-Google-Smtp-Source: AGHT+IFe+e7BtR6KHk8+3xXfcyL5nJihXhgLVyegD/fHJ6X33+sQ2DypzZV2awvTjaBOoEGaQZ2YyQ== X-Received: by 2002:a05:6402:50d2:b0:629:e50c:b058 with SMTP id 4fb4d7f45d1cf-63939c2348cmr2890100a12.28.1759492641821; Fri, 03 Oct 2025 04:57:21 -0700 (PDT) Received: from localhost ([2a03:2880:30ff:43::]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-637880ffdf7sm3960903a12.28.2025.10.03.04.57.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Oct 2025 04:57:21 -0700 (PDT) From: Breno Leitao Date: Fri, 03 Oct 2025 04:57:13 -0700 Subject: [PATCH net v7 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: <20251003-netconsole_torture-v7-2-aa92fcce62a9@debian.org> References: <20251003-netconsole_torture-v7-0-aa92fcce62a9@debian.org> In-Reply-To: <20251003-netconsole_torture-v7-0-aa92fcce62a9@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/8eHdtAcsmYgBo37odeOah+/XaoNPfaLxvw310AnBgjuhJMREou LmSJh7sbpuJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaN+6HQAKCRA1o5Of/Hh3 bXXTD/4iax2NkJa3PtFgrzOYfMIn1p+/F4yEva2mj0mIH4fP/l1GaLlFdOlBq0m+5IyRyLF1TJr xsorqbc1PD39f6UfY4IfibeXbeewQeCH+Rdx5ml/2l51tHYaMEYF7Mzyh+Nr9mc1MMHPGHIijzq MgY8dE0n/hTLqRgz0o9PgLqDYGJ6XHpV/uvFLX4AcnmqQSOta0cMuOCzPIHyfaXTRwm/Yln1yix S8EtnIzERcooSYCWaym7aDo7u/+4NM/kBVl0Bua74lxwJTydcW09rNhliTngSXkAq+7IMSPXGQe iImck6h8EdsZlreu9EVxoNiA5bsxNDkBbdCOoAvdCOH5LDSYL9TU8C3QSitYd9Uln4KIn11tpNL dQ/RbZJKDjcmEvopW0mdedsSubukCi345gVmZ53zF4k0oylGTmotV9jq3WgqjNT3ZLE+7lWtyYU 547e8YqsZbOvhxfRft6UPbrLOJ2dE74YzDitOgETUnuDFuodcneXSpIrXUA/xSkrDxq5YZvi13P CbtYQPZ4lyB39jsL8aaItXzlNLRj6TKMQerlw+N+pC6BZZatdaVKWcJDd1jOk3Dc3VR3UyJZoZh b5MsEkFdfmDpufKQ3zgXdYt/Z9tbS/frNcGGDyI52nVKNJRlIPGXHeUNWP9a2BixrBmONqqkbTW sRU8hz1A0jg1z1A== 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 Wed Dec 17 17:40:45 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 087C32BE029 for ; Fri, 3 Oct 2025 11:57:24 +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=1759492647; cv=none; b=IgfmTww/dMvedVETkeKjrbrvx5rb7KoJkW7thvqdeY+IHZqHIT+yhyROQLjIwzck0/arZe3Yyw+xc5mjtijwrk0ITjOss9gItV3RHXzZ0mBdNi+kiuBIcENSeD6u7+XPx2/QsnRadRJ0JuMv5Mo/09kPs5Ufy1coOOiS6WElwpk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759492647; c=relaxed/simple; bh=Tjpm4RbfWtGDoFiEsISXBux5s1C88ndSM58FldqBqTI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=gBhi/wJiEWi91QbDWYtD3sjWc6t5ccgmf03kXL3fg5uh3sMUhLw0xri0epIlB761dDnQ/BHGYa4sopp3ytO61gJoLuybmOIFMU+lBbQhtcojoWc6Ynq+ueZxH2zf9zeHmLjSkG+zABz3EOsAqq57TgrPBr6wuL7deOWBPEDrJ70= 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-62fbc90e6f6so4247140a12.3 for ; Fri, 03 Oct 2025 04:57:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759492643; x=1760097443; 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=ri3Yk+R6v8p6/dp1Jjzw7TUVEJw3doRpqntYPTJquY8=; b=Vu3iIw/Lln8TuyGnVbmMQ/G8PotFUCyZj2l5C1Tlb1Nqpbb7eEOTPt1a/PnahGSV8A V0P1051duzr3fgYFKppY4BdzMkiQpuyqlvsDhwDIBZsT5geD3y0X3VXZ6BujYDup2lxE LBWvTDY4uH8T0t+jfGL8zLpTLHAk1g2q6yNknlv5AH8bBftQjFigmV2O1viEvayJ1LY5 3pU1xMIam+F5A/Sjg2OF2mgtc7I4hI0fp5J8mQvy4h3QvmhTG8K4RZr67Y+JVVqWIX4B XtJj5TNO87PGfLnuy+hYGRM5SZ1pYBWKrX1n2R4Evc0/ajEy/OIwxkYIFCiaqdSuY2p3 muNA== X-Gm-Message-State: AOJu0Yz91Zoy1HjAIhrk6HU7UQ97nWUnqOrehYzXbC8MHZzPvUfK/pOp WtQet4iRovwhDzM37iGdpK7KnKitam2QzC1g41IJQDD0aumK+rWIr5gt X-Gm-Gg: ASbGncs7DusUMl5BhSAMXbbDEhFBzZs1UU/Hcxa/kJhrz2yn3LUift+YMLrkhqumk/9 gU4XERDmnOK3E5aeXLjgFU0fa5Nl/DMtXZ9dq3bzjXRKRQgj1/EGLkkIDhKmpqPV28Lva6raAdN lwmJxxQmWrXdWdXSLWB+y3IUBAQRAwCKWh7o/43xxEA60vD02ci8R39Gpl819wbQeq1NM0sjkp2 rt+ER6vQMmlHRW670Fn/UAI0rXvHK1WHzsxKTgBD0Q8L/1cqzJYoRhgiXu90RJy1FQgyig5z7WE V0SR7fuYKdrtfOT09vObevqb+7bhdGbkfMjYEyvloxiKuhZMQevjSrZ9xpD7Ckax9KQinififl9 WOYjzS+hAVMBEBzq5wUXmcDANXU1w0tiqMRBulQMPmogsv5g= X-Google-Smtp-Source: AGHT+IFPwQoR8OAqkG5wJPF+4KyBxmm8XJ44xrE4QX6QJmlVGotYuu3HNJEc1Bf0kTZdBb8NjCQaQA== X-Received: by 2002:a05:6402:42d6:b0:62f:5992:a64a with SMTP id 4fb4d7f45d1cf-639348f1287mr2981993a12.13.1759492643181; Fri, 03 Oct 2025 04:57:23 -0700 (PDT) Received: from localhost ([2a03:2880:30ff:8::]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-6376b3ab692sm3874370a12.6.2025.10.03.04.57.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Oct 2025 04:57:22 -0700 (PDT) From: Breno Leitao Date: Fri, 03 Oct 2025 04:57:14 -0700 Subject: [PATCH net v7 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: <20251003-netconsole_torture-v7-3-aa92fcce62a9@debian.org> References: <20251003-netconsole_torture-v7-0-aa92fcce62a9@debian.org> In-Reply-To: <20251003-netconsole_torture-v7-0-aa92fcce62a9@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=5257; i=leitao@debian.org; h=from:subject:message-id; bh=Tjpm4RbfWtGDoFiEsISXBux5s1C88ndSM58FldqBqTI=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBo37odUXbco8T+ETf3vOsgWdqUwlUx2LqDw1q0n NrsS5yuAA6JAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaN+6HQAKCRA1o5Of/Hh3 bRphD/98YZPmVSRfmgy0ZGV09XSGNtfSnzYZLVFTO4FtDRxioNNVxuA1Re7xRcySx6yX7p64MeP LNTdL+8B7yyooTi5f9gMhHL/28XfpEKSnzyaItMtwiYK/YaniYRUwgYrkhvj1zcNO62AejPD+FK UM7ucDQza5anv/0xDkl2hrU84MnAnUKiOSJh6Gdz+jJh64bPCmR0FDoIQF8/s5YmukpLMjgfdmB mx681HApdqg6oTWctnQtjsgc6m/fhnDc2ExmbkX2PNhClgc+uOHLpcYJ0jmlkNDB/AqHuAOTPQK wCfNPFc/TDLvS/muFwDCZfuTsVhTnBDkg3ixfevOzi1XZZYULIlSTwW8PRWq/yYvsiRKcotbYcC Fiz0pqFYmsmG/oxarBD6ypkpgHM4VRlZvsjxj7BYZQsH4eJiE+DOWwc9ABJsSHNv0ZBt2WnqMZc FO037C2yZHp43YMZbMFMsybbeKOj3wZ9spHbHKRjrxgTkl2HXovt6jVzfH0qyuTvaKP8KMbSjNY /f/Hz+cTfxb8lJLqybu0goRaMzTm2/A3dvMAsJR0N1Iw71kIq1Nogu//dzqWPs8agQAumlvaec/ zJNACZiEQzX7YEIBqsXHzhGuENsS4Ro4fE1MiUnQVv1T+tX9zzoPtbMe5w2GJMaeF7QQ7lFcx9G xpIMUWKKueL5jcA== 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 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 Wed Dec 17 17:40:45 2025 Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 963662EBB8C for ; Fri, 3 Oct 2025 11:57:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759492649; cv=none; b=VMrZ5scHp6Es9dFqjCEoB7bpXmTh+8bAYXYPEO2E+OEjC1atSu6aZR0jrVCF1k4gnrtnLGZA49cTqPBZRQxDJzTWlMammaCofMX4sypEDMiuj48Q9wvxANsOQkNGZR0O+042Qjl3ws1WMcQ6XaJkA1lv6la9dUn/H+ie+jHQO8c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759492649; c=relaxed/simple; bh=kXeBQWfw7Jx9MLKkvNQFw5Up3TwBcRtANKYYjl7PaDQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=iOmEHTJ1hHs6TVlu22FOQwfdz9F4Z4gzCLKAIdbBOKe3u5IxkXJFB6U6zELdietQttqTrm9nuG8RtyanJpCwFHi+t16SB3fh3tismHJwBHzEsChcXaD9U7r2xdJC+ePTOyGVdwkrftq7GPowjyrsuZlgKQ4xpo0vtIwH6SkBqRk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f54.google.com with SMTP id a640c23a62f3a-b00a9989633so5888866b.0 for ; Fri, 03 Oct 2025 04:57:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759492645; x=1760097445; 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=IPqSdPRLL+/ic1c9CZoAayBqLN290Dj7ejr0ufn8Chk=; b=GcNNfHOJ/eDxghvTHLIGJY1hPADJ/X4vfgiH3bkxwZEVB6jrIPgH0gT+swDTnrwtmM BEQKSE13E6NUiPErNUzt59jeLNODAyeAVBeW7qQAOZrQ8q4hHoftSSeLjl0xSIYDLxJu jUCUlAAjGd4gePhGCCa4BnKwdwf5WY/fj4+1xbITDUFEXsbViEO3WxOf6FdDO+1UGXlt XrWi/DZ0Ki3SkH9+ezGHrHP6ggUGMOParqah189IlkrH1+c4lX1jxL06XIpWdk74w2GF fUbRXE9VrlldjlseImJppUoEBY2FBVZ218Lr/Uz8SxS9W8DDMEcj3HFX4LUcKE9w/dhX Vs5Q== X-Gm-Message-State: AOJu0YxVNg0lpZJSFFCe1Uh5dH97mAg7YDYGkPVMIPFN72cdu9ViNELz qUB8TPjReN98p0a+k4HtyijO1uifTpEa2SCEPCLbA5Ls8DcJzTgRGszd X-Gm-Gg: ASbGncuuQ6Js4WQOfzLs1gaB3ag+H5bhHgMayEywhC9yKcikiohq+lJiCPnc83+viA3 Jo2rAkl9NKDQqZlbx1Segcn4ZZ+GgpX8RehTur6B4u+w7MXHjJWksMzgS4HLAAGz8aHfGlmBXN/ +4r3okqcwgEFdGzGWANTVYMGolsSMVJEvsHgDVHpXa8lVWZ8KAWnH6wzHLtgxt6nr+hhCn8MXBY sSmreHXTRaZx++WN+b8Rrcx+GQNYdkRdGOeYmNlGOK884ksMUcoUKrnpVCRdJ1kug/dBN8vT+xU TUUajNYsWExGn5sy7Td885eSgq+OGr/YQJGoyAH9dpDEHDZXpmkVw5Ujk36n0aqV2cxMgEgo4Z1 2GEIB6GRJe0Lalea9zhHQ+HEs9eq77lUh471WLg== X-Google-Smtp-Source: AGHT+IEyuR/64V9ixQilwXTYbXG/GDiP+3k/Iw7RqoIRh1FIAzjeg7kAxEjGsvd5EOpIcCbGc7gjAw== X-Received: by 2002:a17:906:d54c:b0:b3a:8070:e269 with SMTP id a640c23a62f3a-b49c19754a9mr427262166b.14.1759492644628; Fri, 03 Oct 2025 04:57:24 -0700 (PDT) Received: from localhost ([2a03:2880:30ff:73::]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b486970a4bdsm423720466b.49.2025.10.03.04.57.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Oct 2025 04:57:24 -0700 (PDT) From: Breno Leitao Date: Fri, 03 Oct 2025 04:57:15 -0700 Subject: [PATCH net v7 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: <20251003-netconsole_torture-v7-4-aa92fcce62a9@debian.org> References: <20251003-netconsole_torture-v7-0-aa92fcce62a9@debian.org> In-Reply-To: <20251003-netconsole_torture-v7-0-aa92fcce62a9@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=18767; i=leitao@debian.org; h=from:subject:message-id; bh=kXeBQWfw7Jx9MLKkvNQFw5Up3TwBcRtANKYYjl7PaDQ=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBo37odPod2tQAgud2H6XoIlLTFNe7lRUSvPkw8a CgiFTQVWPKJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaN+6HQAKCRA1o5Of/Hh3 bbJQD/9XRjVFqMt0jubU0zJx7fgZFCwhDPUn3Zd1oB/lfIieLKI+dgqdnmG5HtaNAlABVaLLR4b 1ob2DMogh+HjD+KS9Za3EvgvtTsYLjjbNZhrcy8Op1blxVqdDN0ZGUubkNXAMloWooARX+gjWvt G5Q2eLrWcvLFuq9ZsrWVlCToQGPMuyufyfCIJASTomkdXjgbTlfMydjJtw8ybpXle3XWl00xykI J+IyDEG6E24O13sHIYA4ZQ+pd0uOYVzx9XBoCcQKJlPOXCwY11IL80Dp6oXE/V6zHxLCY0lERHC tE6XJ089AzLOZiqH6B6IQ9uEsLcufD6eCvPLnxwH328aUqZM+ZqQZf3W565cAq314luOnhp+SH0 ZocmZ39cmMxvRs+Xinej4ki181Y4XA/eNAdQiojjJoy1srP3GbZJ/V2RvR4XqkaQuTuk1ZI93s2 WowEPjLaL0FYTL9oOIQNSbQhEnUtdBU6qLFDqfYOsWUy7KTBcnpbybkGoSrRefWTzdJ8JcpXLqi zwQLTyIw1u4v9oirdmsd639DGCv2+WXtUwmYN/Bs/bW1aqAH8HddNOR5xWSSo7kai5vO1pE+eau 5XVJKKs3hjw49IuU5tmx7DT/EBx8AYpPoaDf8SJrhDMnqcX0ptzTyC8ebYTYgiIkv9akGXbnG88 sHNCP+r5z3sh2ZA== 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 --- .../testing/selftests/drivers/net/bonding/Makefile | 2 + tools/testing/selftests/drivers/net/bonding/config | 4 + .../drivers/net/bonding/netcons_over_bonding.sh | 221 +++++++++++++++++= ++++ .../selftests/drivers/net/lib/sh/lib_netcons.sh | 158 ++++++++++++++- 4 files changed, 378 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..30e4f357b47e9 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,104 @@ 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