From nobody Wed Dec 17 17:42:40 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 B8E333074A6 for ; Fri, 7 Nov 2025 14:04:06 +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=1762524249; cv=none; b=RLrjstKw/vum8oNvjzCj/P+DTx4Uomo8+Yis0VYuWiMD6L1Hao5lEPbgW8P6WFjduhFXcg24TgA1nX+c7NCmrtAz6iKXT5R1Ey7hsQR+KL6Wg3TELMWQ3dCmlaSs2UmP4GVAVAIhv0BNMnCwG5Twdn/ryX/qIiO0rqKWffIZzKc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762524249; c=relaxed/simple; bh=PBufnVhc0vYw6K1yqEtQER08QOskv29ELpqGFdftBe8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=sMngzZLK/TYxzpYPaQOXTzkcrxY6u4QQ6LGikSIxN6Sha7PfdFiuMdIfEGY9eNfwrbSdSlBmWQy4XHHslOyqe3iH3k3QpjSX8dsVpeoodcdiNkrPj1mytzejIMuAP0K0GBG4dgDkk4wkHC9+gWGMvidkv8nVfHwEroJ0b8gjoe8= 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-640c6577120so1613492a12.1 for ; Fri, 07 Nov 2025 06:04:06 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762524245; x=1763129045; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=GjGKFyPmmnOORJmfJYb79vkMgO3eaKsfbWlFTGwHffE=; b=kwo614kbNlQY9Bq26/saegPeEGRlu7YjIHTOchi2EV4dkHM8XOkhv0O+G8ul9DUg3A HwBwcMPD4HFebGk04c83M6w5yVobaEKZyVsxpGbhTU06TGhxcIcIH8jkMWmJIUXh4s4R ZvXrL5cCSk7wFg2NrdN6vYi9hI0KeK1/GIZ8jXM1NG4iX2DUgY5T+B8XySJOQlCjVO8v sT/6Q/9dzoN0OPg+/297/GOwTl7PZcsRWwoe8W1urt3vLOKFL2B/vFIKw0/h4zj/tA4o s5ly3o0afkC5J9ymIR83pnqofzQzBisieaYAh6913Ro0FwKp9RLuXTqD6NHi98cYl8q/ BmbA== X-Gm-Message-State: AOJu0Yy0QxZl4zIF5Upj5cr/mcpoFR3H3wyDezjKdrpHlLJxnnOvSkM7 8H6YB2cJ7y5MYzzptvLhnIn2AJ+x8tE3RPieRrg0LfrRHuzav+J8rrG/ X-Gm-Gg: ASbGnctGq8+k6HbG8WCTsXl7/vGOWUWa6vD9XLxTMp0pfZFtIKFlq3uBOvudqp1bryg +5/hVOK0Jir3rfqACbTj8maJnRMi0kI2L9wbFxtx0ZzLmHTCYSV5xQXHsnLPVeyUO2vReS8fbmS K8g3MtFcIpd98u1jtiw6DAd5yqG9j8VpNDYKPKy1Du32hyG83t2MUnqbPx1An+pIJCgdXfKKodl vu9ZGlONMEAZAVFuj8z8DauMarPZ/p/Cy6hxtSnPJ//vCH+5r7GGlaXU3IA9ocYdwhcNS7Urgaw yz6WDwtgPr1Z+ffxm4rl6Cx+ZDgdZdsHzQ/o9AZ2hoThYaZKCN2cwK4fXiagmUMOGOYKNgnRniF 8zkej0mQSKjanRdDFgQbcsN6NCAkHMUwdVVDDYtYuxlGPemVdbC/IQOtY3pe7+er7sndE6p7/ND SLPg== X-Google-Smtp-Source: AGHT+IF0zw7XdYz7vcM3phUQMOrnFBlIHOTr9IuGmwv7KNhzEHTNvBcJ4yY+AVdmmb4MZwhkXftiaQ== X-Received: by 2002:a05:6402:5112:b0:641:3d64:b120 with SMTP id 4fb4d7f45d1cf-6413ef4f894mr3089941a12.18.1762524244877; Fri, 07 Nov 2025 06:04:04 -0800 (PST) Received: from localhost ([2a03:2880:30ff:74::]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-6411f8578ecsm4116404a12.19.2025.11.07.06.04.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Nov 2025 06:04:04 -0800 (PST) From: Breno Leitao Date: Fri, 07 Nov 2025 06:03:37 -0800 Subject: [PATCH net v10 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: <20251107-netconsole_torture-v10-1-749227b55f63@debian.org> References: <20251107-netconsole_torture-v10-0-749227b55f63@debian.org> In-Reply-To: <20251107-netconsole_torture-v10-0-749227b55f63@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=PBufnVhc0vYw6K1yqEtQER08QOskv29ELpqGFdftBe8=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBpDfxR66IUfHQOCEO81HXwPeIzUPA08Bi6dPx8P jKinLB5IwuJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaQ38UQAKCRA1o5Of/Hh3 beYAD/9T9FlKvwfyunjOenx5s8BJf0h0BhplLEhAaLaDNUiZlHWNi3TX43tzuhundshN7VfbxQM pVqbepfqQhbcRuZ+XIP5kk6ZM2tRJxzMST8l2TZip0e5AvlAuhvEPtF4/yD3ikKTvhyYcJY3XMU xRXrHoOdhAaoEKdzqGlz+tjSzod5Do02jr1PfX9KQOVWuOr4xHSI/3JBYnvl9iwQUb9iSBtUOP6 KBnn7c2jPPdhRaG8iarM4BwxSzmeX6L9gfuFPabSZOAsBzIdgiLYkaEb/UaoI9LQoh2kp7JYXcd CQN5157iVL56GTLSBydY9lJZiukoq42Znc/w59iSNMXXrJepry2kbjM13pIrEduoNytvnxvOurO 5mlSpAg44u5ShzovNmNt2NC+L7bZtBYfa3Vug7iYBvzC2649s/sP6yeBXG2dR+wchkHFlY5nrF6 X+AIjNFD09oi0+ykEjjCSJ7OwzNPs3yUJpMXNs972QqQ+uvu7dS2fZF76XoIBVKaT9ohH7JNukH dIKVdHQZ5x2fjNP4Kvx0I0EwEo8WBMkUA7tyPZmx3ye29ceT6rRxvWs2nTpYDW4NZpT55qQZF1v tHozXJes+Akv8AiM4tBsXkbL6RlVxJv2K6Nac8ZOgevHz+gKAEHIfx85IHkydMVoMMjxHxMsZ7j 0vyXgao7lsr9QdA== 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 c85f740065fc6..331764845e8fa 100644 --- a/net/core/netpoll.c +++ b/net/core/netpoll.c @@ -811,6 +811,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 @@ -820,8 +824,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:42:40 2025 Received: from mail-ej1-f46.google.com (mail-ej1-f46.google.com [209.85.218.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5BF6632721B for ; Fri, 7 Nov 2025 14:04:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762524251; cv=none; b=HQhmTVIOXA/MhN4NuWQS23gjcw3flKrtMOQ5gVjEcFzpu3LtjlszLUYgxOXYB8KG7EjxE79uz32dmkl0QW3L2suoogEN7tsqNpFrozqZlJ6Pn4fPN+vJmQF0dWjADB7lzXLNbcIHAmPOIa3Ye/twioM4G06Nl7/GOLKBrY3ynUI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762524251; c=relaxed/simple; bh=g8Rymja0V72nq6OnDIyWQadzgQlOQaCKBNDvE6hktyo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=sSZjuGv0xQZQnaDXD7zm8xhhNgIvqA3yJJQ6qTZV7L9p8kACkgEcIL2Q+66dQCNxFbpkceiGls+rdrLJVh2ThNvkMDyYgDHRNx38AX0Xab4KJw7f2grrnN+xUqeAs2MCqEclczHkQ4j9TmE0cQQwFHpyFKrO7iZYBXXLBlipLDs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f46.google.com with SMTP id a640c23a62f3a-b6d402422c2so145548966b.2 for ; Fri, 07 Nov 2025 06:04:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762524247; x=1763129047; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=Hnf8G2/o1fozlbYtBL0vduYZr+SYz2Fp67m1oGmqTd0=; b=Xhuf7UfR+ljD0sH/XalcQUaJVFvSJ65idKOc26OCG2nSSdh9W3qpCeJ5mfY3qUO1vX txK63APqJwM0wjkmTEpPJKJ9Pf37OK2kOBk2OVF8PX1XJazZPaZjPn1lkVxJHqgx9XZ+ VqRwtC65n2DTAPzwVx8eoq17aUzzw7mgFZX4FC95SDuR7PTk3UAxAVOD7Z4n/iopBWAD U7EJpll1d9Wzmr9ZxTUoN0leGfo+atFebaWdONInYKBk2zPud8ddg2rKZ52VI0X895s9 KKNYkuGjWynVLU8wC2oqrDhsNbVzGwCl6O9a1I/EPzsAUaOgasXGTNv5G4tABm1Wk6GY OK4A== X-Gm-Message-State: AOJu0YzT8iIay3FkaBd7to+l2iJgzxK8OeHzocMnvkOmnGAd/ykHpfiA eTKASMD/gCWPma05tYd46BEcNhKzj1FRDc6mHbXagrlFuoLmRRw1zyts X-Gm-Gg: ASbGncuka9lELNQdPeLAFa4RfnyDixJnLKeSgaMISN6BQtWiEC1EBI9zOcHSaV/TdON 7xn3lKKnNEf9EsADdUCkyXYpCDc2UZrzmezB6a+7gLDFnH0ZDx/J/sc2j8NnQMxpME+2U1XLbrO kcESf0E+KdBDHbw9/XdlstV2ES/DyIuBQf7ZmmylDzTeGc7e57qPwtCaRgzRV9XHUMgj6RVyBem atVnHNk8fxBQmAIxA1J454AHGsdfRCgoZGZtoys69fVCQZghrv/E2aoYwbzfnRy+7bh91XlhtTa 583aSQkbYJCfgQISfvLSDiKG2ucH/By4aOFKo5aogi+pG695XjYvcr165ZC06/SlasScKm7+3kV MlwzwMMD8YxUUtVweeUan4td6ha9fIl4sBfnLhqUo43fTMjyzGzM6yxgDC0nO8to9BjZhr4Z0jt OR7w== X-Google-Smtp-Source: AGHT+IEnA4n1oxvAuSZNuAYTNl4X2XL9nFJEKYukQiqovNv4tfPvYkpSeP2M+nuQbeHb6r6bCT8z9A== X-Received: by 2002:a17:907:6ea5:b0:b72:60d9:32b0 with SMTP id a640c23a62f3a-b72c08ebc4fmr370881866b.3.1762524246382; Fri, 07 Nov 2025 06:04:06 -0800 (PST) Received: from localhost ([2a03:2880:30ff:73::]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b72bfa11271sm250694466b.66.2025.11.07.06.04.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Nov 2025 06:04:05 -0800 (PST) From: Breno Leitao Date: Fri, 07 Nov 2025 06:03:38 -0800 Subject: [PATCH net v10 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: <20251107-netconsole_torture-v10-2-749227b55f63@debian.org> References: <20251107-netconsole_torture-v10-0-749227b55f63@debian.org> In-Reply-To: <20251107-netconsole_torture-v10-0-749227b55f63@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/8eHdtAcsmYgBpDfxR3LFcagYoQMxeE/hGFckSp2YiaItTI6fZZ WyOjHlh5E2JAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaQ38UQAKCRA1o5Of/Hh3 bbgiD/oCTfTa9SezvgQamYx3/71IqxBEFN7xAq//c6G/xegLPcC/Y42hzoXD31o6kw8GZ0BPvkE 15dkvjCNmtZOyV65fIMM4py2qpkq3JkFLrsIyLObUWyVrYrS8ST09aTTnUpxzontmX02p5imi10 +Zr4HIRDS/LDec7SDfUSGEojFyiOXnUBjfX2gxSj1T7w40zZjHwEmaJWL5tBSru0NaLEi7n/7NO NFA7dfOr8RGydsida0v4kTClq1SkozT2ILBXYosANpILDFdtUcbBMc9XdvTStojsQCKtegFtexS PQT1MEqozoF1000nl85hrLBSW3uwzubMRGDXW8RPF5UYzFEcHGvlg5SFs5h07DejgBRg2ecpvYt dnNUxB2eYy5lDCpVnPHd+z0t1e6BPrmP9yuM2oH03j0A23IbuXPRA8+yvsu+E7rJ5k20014hVMz NNOg0KFkBBdCNGPPde/W8d0XQ2VMLs98+8vn6lbfnwMG97FPnNYse4fkMLpZZCj/ws2iwkwgXHL 17h03ykkIz/1QT82HcX3NDMjsXU1Uw8spiqo7yLVtCUOF3dh1Wea1tcVzmgGHTl3jtiokgNGfkB t3Yf15n/C8SJspCfqG95kKROX4TCIK3ZJCUxXXDmWliG0XS0FW3NzlVOOrYf7E0NwxzAhvm+qx/ Qt+EHbHzAhtQyxA== 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:42:40 2025 Received: from mail-ej1-f53.google.com (mail-ej1-f53.google.com [209.85.218.53]) (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 EBBEA328613 for ; Fri, 7 Nov 2025 14:04:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762524252; cv=none; b=VtHaUgULVxPiQQrAsj4dysPM58Koos1SC6/sLB4yafhNj3Buj7p9WEX8T/D0gv5tBxZXiwxVMTacaO9sYRH6OzZqYk+gcHnZJeEfxtIkT246O85h93sE5PcPXEm50POtmJ5dfHzUHZcugBhB13hfoafyBvH0IW/pW1dHE0rXmWk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762524252; c=relaxed/simple; bh=XQp4YoJOgWYJBS+lAreScEfDBZBcema28xQn9VyrhM8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TSBoxhX0gUtUWWfJGrmU0UMJHp7a1SX64r7+vOTzQlv0Jjgp25WAJw1cAY6H+56CO5Q7aa0qR7qMefnuBkT7DJxokrMiiVV5PrjfBLxBUPYyBtKQd79DFTmwRqsbpeWbyNLsNfbj4hk6MEDCzcuyoiXx+70EImSCmEulKjhD/MU= 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.53 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-f53.google.com with SMTP id a640c23a62f3a-b7277324054so105439766b.0 for ; Fri, 07 Nov 2025 06:04:09 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762524248; x=1763129048; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=48WWGgV3/OQmNtRAgDmereIyjTW6e2ku3y8EB8DFBcI=; b=wROUfqVkVEcGq3vMMFtNvwynQYj6Ny5npYHRqmIQOxi4xqPEXrgslLXDTyyQd3KO1E E4dyOcpNeiveQuY+HFMzzVxuqWIiAY0CZyti0cETFUXBd/d/2uqFZHDIHW/kB0Fbrzvf U+JesUZyMqOiKvE73cKU9+mI2aHRff+BqTFgX+uQUWnsDh1mgZt5Cu/KzxFR5EMpbNy+ 7h/afJY8Zza26+ZOm7RDD5LxO6IdvKbx0LcF29cuD0RHsWi1qt7PzmZDU9GvfSlqoRs0 ZMlea+xo8zn5D0QBxgpcW8gT+2Zsv2XTIlE+ttRZWdYfkh7GV9jv/0xAQvRxLJdDIFyJ YOAQ== X-Gm-Message-State: AOJu0YzVdp9dpSQkac3ohJHIAp8pSKMCWMg1B/VZOFVb4kfBJyooAGYe zdoS1O3j3fdaxJJBvUJvI/No1CQd7h53m/lyAgOcyyqJxU5aDzaQttTi X-Gm-Gg: ASbGncvmCdVpQ/t018fseP2L6w64PiHQaXrQF37DCtJRPp4HfvokquccLM/7qugu8cu p0NpXmaN1ni1RD56EIRR/fG5xv1c4cUk2wxsJQo18bfc8k+KgS0d7JAJ0qvtXJUXoLViGSayZu5 zs03dkMw0EE3y53TtnvroAqTweQWf01M2sB9lD8/JAFxtSS+tH0xLw5bNtx+NUG+z/5FjdRU4a7 vXdcyoAOq7ceOkmZ8NIzxUxkVbiyWh/SuCdIgdcqYYuMNO0Kj4Pepn4JXN0asjgPi7SJhInK62B k3lLjiNC8wT6tqCQWm7Y2HyJ2G9zTaSGq1PLAgLv8Q3ALMD3g2DcT7pCYS3GimFKhNmeTDaqo0m I+HidcNjq+sy5ZCQ7E7YCqS2lVPEta7HoIpExIRG/1GKZOjUi/3DC66io/HLZHfxo5A== X-Google-Smtp-Source: AGHT+IHsxl2XPAlFemI24OJUBp3fWjsJgLD0KhUvnrbrT+u5Rl9gEHfRv/SUFSF97pVI+pc2Kd8NmQ== X-Received: by 2002:a17:907:7f8b:b0:b6d:67b0:ca0b with SMTP id a640c23a62f3a-b72c0dcb646mr312514066b.61.1762524247809; Fri, 07 Nov 2025 06:04:07 -0800 (PST) Received: from localhost ([2a03:2880:30ff:8::]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-6411f862bd0sm4354131a12.26.2025.11.07.06.04.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Nov 2025 06:04:07 -0800 (PST) From: Breno Leitao Date: Fri, 07 Nov 2025 06:03:39 -0800 Subject: [PATCH net v10 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: <20251107-netconsole_torture-v10-3-749227b55f63@debian.org> References: <20251107-netconsole_torture-v10-0-749227b55f63@debian.org> In-Reply-To: <20251107-netconsole_torture-v10-0-749227b55f63@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=5328; i=leitao@debian.org; h=from:subject:message-id; bh=XQp4YoJOgWYJBS+lAreScEfDBZBcema28xQn9VyrhM8=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBpDfxRs0hwlyPprZCy7+HJz29rlUnUJTxAFFQNi /Z8x94vzfaJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaQ38UQAKCRA1o5Of/Hh3 beFwD/93H/5JZ90OGK7FAb7LO8jQ5l5TjjZmj91h748Q+8zPGszefi/KlWCesQ4vSBGJ0YP6Xbe z/AXyk4N6z3LUM6kxXuWUgEZ8gnsb5VuVAK+qMnBzhTjKdTZ3IuRSd4vIZNhDf99pmOAY+dv8/s KHump/2qH/HsFgDFtsH+xGwUDYrOHJ/2Zk04MBnuSXZpl8HbDJd2mBiasrjfZ1fU6eHdD+OZhk+ ypykIZRZgJvLSE8nHJMLC2Abxvq3eZHCoqg7wEDWcX2c8J6s+GiEgF1Y/ob6KmEk0QRkZVXvOjH 2BbtvdK142leANniiHxHCPtxFS5NMJa2Tg7lLR716S5WLaUy5eAzvoFXZ0GZ0I9CfVXROzTbyP5 evCXNHFGimHDDVJnYJsS5n9lNqN92Gnc11IEjJXQ8faVGn/rd94hqb70TQCKn3GvXw+US4m3Wm4 ZWTN4Fale4u4FEgno56YX6FjONuC1x1dDcN43bcz1XGnnIw++NWcEnIOWhU4drRCCQgvllBC4Mw LJdAAAd0VvhjAIWUkYu72WLtZnlzgMMBAgzzGJRYOI0BsdV4HORBeGUFheISB5ZWmHZqOEBc994 /u6sZi36kt1eWcqEbpxU7ctyDIA3dCowVYukU6bt5skEHCJrBMJw7PoQ/yd+AdUtzdYNfd79Upn TM3XfaLkgWTnU1Q== 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 | 130 +++++++++++++++++= ++++ 2 files changed, 131 insertions(+) diff --git a/tools/testing/selftests/drivers/net/Makefile b/tools/testing/s= elftests/drivers/net/Makefile index 6e41635bd55a4..71ee69e524d77 100644 --- a/tools/testing/selftests/drivers/net/Makefile +++ b/tools/testing/selftests/drivers/net/Makefile @@ -18,6 +18,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..2ce9ee3719d1a --- /dev/null +++ b/tools/testing/selftests/drivers/net/netcons_torture.sh @@ -0,0 +1,130 @@ +#!/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:-150} + +# 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}" + if [[ $(cat "${RND_TARGET_PATH}/enabled") -eq 1 ]] + then + echo 0 > "${RND_TARGET_PATH}"/enabled + fi + 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:42:40 2025 Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.45]) (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 DE901328B6F for ; Fri, 7 Nov 2025 14:04:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762524254; cv=none; b=mMweC3mbNKPfKmpP8by/1ExghCLDWRUJoFNTlmsupueMDuI0wUdrOOusXSZOZaIE9oc49h/7bV5br9X9KVCghpFpoGGZ7+6x7iRztl3rK4hNH29Rt303+WIGUrvzHNydYSNXWyKOfHFsgpU0gwzNpv+bpnoQOTXyogVV2jU6+Rg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762524254; c=relaxed/simple; bh=ppaiO2Vs9XmORt4JYnm3iemeeYLzNd4bUeRDRmB7wM4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=I6+AuY0gsWiDspdWwiQrbreASoTTXDIwK4qtiWECCvi9afXkHsrinfry4i6gMFamEFbvvZuiqU7jMMX8vUHNftT8utS9lFmXsbM7StoFWCVZtIIF2pKDmRa2ezEffJxsIhP2MuMajkJv+njyyk/dfG2obZNr4BDjpmPnx8di0vw= 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.45 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-f45.google.com with SMTP id a640c23a62f3a-b7200568b13so141202866b.1 for ; Fri, 07 Nov 2025 06:04:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762524250; x=1763129050; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=52JMUM1NA5qpPdeke3vKvkZnbklvpx7bMGO4OFGhD3Y=; b=TrSe9HWdWw5xmHUVdvBjoLo5pX7qy2WVOAC0Er5Ix8Na0JakwmhCciqTzbBjC/tQcs ahmAbylm/s3Cpi+znZfnaxU2axvjrCnTHNmeU57d/MMbavqnwGemQgi/AvjKE6F8Zu1P l7pVNTrKqGf5cvw6slzstBPw0Em7+PP+fk5CMAwYzpO3fA8SjOwyEuuq5xb5k7lfHEbq FTdIaNB6QIwEuN5UQF5T9UpT5smgbSE5dI6MG6uTVyuVlbgM6qmQBL4zBPkDn7yvMOSo IMFkKHip8vMgmdKCjszWznMGXqFJDDl1xH1wtTdoBUTiCFyJAXD+M8SS40Wh59Gt5fw2 omVQ== X-Gm-Message-State: AOJu0YwY6GFDJT1iIS0MUes/8anyEcdk9qm9wKpEFX+iq5IpLbxwaZSb M+mPznKgp0JJiFuQzH672s4b59GN7NKWBhFZAhCh5lTKY1MDSjT0aItG X-Gm-Gg: ASbGncvvrueSRIu4xmeimm9I3aNq4i2gS33Vz4E3hoWncVz/Juo/HK2mGIzCRBPEAN7 Pt6FM9kpVqBupZgtZFApvJQUMkpqsG22O4aHaKB3BR+4y1RniVweztTrOubHgdJldokl0MDycqh EnnZMWd8mbbNAeSe4CfNYT1sfE444ntFFS9NU7ASBcF8Uiwgus1qPDWKyUVi24mZNrMUllvfNbh lCaRFHUojS3VVWuOXUNYIGf13PQwzxM7UewwD0DiMNWgL60HUdxPkljaH8j9BCPLlpIN1FcOj19 Rf5S49NTPHtMXg6NUeRYrjq5hxSPzcbolpKwR0IlfMyYIP7saLlwpFdnHvI2aW8KBrAszY6OGRA NvHbirZQjNh4zAGT6Ride2Dk085ce8AtYIrWF1FDrs3s812mM/hZLxFGzg0A8Z7Y= X-Google-Smtp-Source: AGHT+IG3wKM86n9BZU4n1wsKqdRiu106DCX4fnn/hh7aH2pH57GSnN0utmPt7Y+edi9BbCwgU4k9NQ== X-Received: by 2002:a17:907:2d91:b0:b72:7c52:8e9b with SMTP id a640c23a62f3a-b72c078a0d3mr377454066b.15.1762524249496; Fri, 07 Nov 2025 06:04:09 -0800 (PST) Received: from localhost ([2a03:2880:30ff::]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b72bf40768fsm248211266b.23.2025.11.07.06.04.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Nov 2025 06:04:09 -0800 (PST) From: Breno Leitao Date: Fri, 07 Nov 2025 06:03:40 -0800 Subject: [PATCH net v10 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: <20251107-netconsole_torture-v10-4-749227b55f63@debian.org> References: <20251107-netconsole_torture-v10-0-749227b55f63@debian.org> In-Reply-To: <20251107-netconsole_torture-v10-0-749227b55f63@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=19483; i=leitao@debian.org; h=from:subject:message-id; bh=ppaiO2Vs9XmORt4JYnm3iemeeYLzNd4bUeRDRmB7wM4=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBpDfxStD/rXgevHfANqJqc2pIizKRK9L2vkZGdZ tvaXP/jBdCJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaQ38UgAKCRA1o5Of/Hh3 bTtoD/oCfoF5PwxMtqhTAYFsKRycbwYvah3vN8E58Ei9jY/fTrEZfscladRDcwch9h4sZRISLbF 4R/Mu7B42hNFhvO2GnO4qh89DTR4ur+3H5qCQeoic/JhZM6TCiEYHNbFCyXjzj7CC4NTCUG/YPe ywde1Wvn9O7seUJmPib8ycQKAJwDWb1DA8BYRZAqiJ6GcIEEZL3Y1VEm4vUYXkZ5YTP2r0c439N kociMn+qKw2tQBoZus0DhDm1+KSEf9yf3bn5ozti+RIGyt22DVQoJoEtirvvtAZAin+bP7vCQjj YXadTEcbzoejTtc3+1W3Bda7cU42VePsvNHpuJ2C457g1/FsKRsfp+DqrsOWW+cVgxeW/3Khk2h /IhBWBuA6nFJi/Z4HkqLtnt6tJERdOROrk4pIvNGIjULoCxY1YuRBh8Caw4Ka2SsqsXSEB1gwGC +FoDpbyLhM8Wy+BFW7WdyYhhHNq+8grEDhofBCCephIhJeoAUzxNpU+5zoLDJib1935CD1qajhJ SiluOJWkdyrgsV0l1HowuAjMCdqEcW6in1WaY2ZUWXikxklEUYnqOyo+xEJwiMUlUWEqkvNFYgs x+mdAgicD+76miAwgK/+HzdVzf0UEtuK9pMrJFovTeVrcJJsXZB5pbT7f4N8Hj/HpVCrY1wahrH iqFmMDg4oHOeTEQ== 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 Reviewed-by: Simon Horman --- .../testing/selftests/drivers/net/bonding/Makefile | 2 + tools/testing/selftests/drivers/net/bonding/config | 4 + .../drivers/net/bonding/netcons_over_bonding.sh | 361 +++++++++++++++++= ++++ .../selftests/drivers/net/lib/sh/lib_netcons.sh | 54 ++- 4 files changed, 414 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/drivers/net/bonding/Makefile b/tools/t= esting/selftests/drivers/net/bonding/Makefile index 402d4ee84f2e8..6c5c60adb5e85 100644 --- a/tools/testing/selftests/drivers/net/bonding/Makefile +++ b/tools/testing/selftests/drivers/net/bonding/Makefile @@ -14,6 +14,7 @@ TEST_PROGS :=3D \ dev_addr_lists.sh \ mode-1-recovery-updelay.sh \ mode-2-recovery-updelay.sh \ + netcons_over_bonding.sh \ # end of TEST_PROGS =20 TEST_FILES :=3D \ @@ -24,6 +25,7 @@ TEST_FILES :=3D \ =20 TEST_INCLUDES :=3D \ ../../../net/lib.sh \ + ../lib/sh/lib_netcons.sh \ ../../../net/forwarding/lib.sh \ # end of TEST_INCLUDES =20 diff --git a/tools/testing/selftests/drivers/net/bonding/config b/tools/tes= ting/selftests/drivers/net/bonding/config index 6bb290abd48bf..9914943762234 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_INET_ESP=3Dy CONFIG_INET_ESP_OFFLOAD=3Dy @@ -9,6 +10,9 @@ CONFIG_MACVLAN=3Dy CONFIG_NET_ACT_GACT=3Dy CONFIG_NET_CLS_FLOWER=3Dy CONFIG_NET_CLS_MATCHALL=3Dm +CONFIG_NETCONSOLE=3Dm +CONFIG_NETCONSOLE_DYNAMIC=3Dy +CONFIG_NETCONSOLE_EXTENDED_LOG=3Dy CONFIG_NETDEVSIM=3Dm CONFIG_NET_SCH_INGRESS=3Dy CONFIG_NLMON=3Dy 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..477cc9379500a --- /dev/null +++ b/tools/testing/selftests/drivers/net/bonding/netcons_over_bonding.sh @@ -0,0 +1,361 @@ +#!/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 +# cannot 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 +modprobe veth 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" +VETH0=3D"veth"$(( RANDOM % 256)) +VETH1=3D"veth"$((256 + RANDOM % 256)) +TXNS=3D"" +RXNS=3D"" + +# 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" + + # Setup TX + if ! ip -n "${TXNS}" 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 + + # create_netdevsim() got the interface up, but it needs to be down + # before being enslaved. + ip -n "${TXNS}" \ + link set "${BOND_TX1_SLAVE_IF}" down + ip -n "${TXNS}" \ + link set "${BOND_TX2_SLAVE_IF}" down + ip -n "${TXNS}" \ + link set "${BOND_TX1_SLAVE_IF}" master "${BOND_TX_MAIN_IF}" + ip -n "${TXNS}" \ + link set "${BOND_TX2_SLAVE_IF}" master "${BOND_TX_MAIN_IF}" + ip -n "${TXNS}" \ + link set "${BOND_TX_MAIN_IF}" up + + # Setup RX + ip -n "${RXNS}" \ + link add "${BOND_RX_MAIN_IF}" type bond mode balance-rr + ip -n "${RXNS}" \ + link set "${BOND_RX1_SLAVE_IF}" down + ip -n "${RXNS}" \ + link set "${BOND_RX2_SLAVE_IF}" down + ip -n "${RXNS}" \ + link set "${BOND_RX1_SLAVE_IF}" master "${BOND_RX_MAIN_IF}" + ip -n "${RXNS}" \ + link set "${BOND_RX2_SLAVE_IF}" master "${BOND_RX_MAIN_IF}" + ip -n "${RXNS}" \ + link set "${BOND_RX_MAIN_IF}" up + + export DSTIF=3D"${BOND_RX_MAIN_IF}" + export SRCIF=3D"${BOND_TX_MAIN_IF}" +} + +# 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() { + BOND_TX1_SLAVE_IF=3D$(create_netdevsim "${NSIM_BOND_TX_1}" "${TXNS}") + BOND_TX2_SLAVE_IF=3D$(create_netdevsim "${NSIM_BOND_TX_2}" "${TXNS}") + BOND_RX1_SLAVE_IF=3D$(create_netdevsim "${NSIM_BOND_RX_1}" "${RXNS}") + BOND_RX2_SLAVE_IF=3D$(create_netdevsim "${NSIM_BOND_RX_2}" "${RXNS}") +} + +# 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 + local TXNS_FD + local RXNS_FD + + BOND_TX1_SLAVE_IFIDX=3D$(ip netns exec "${TXNS}" \ + cat /sys/class/net/"$BOND_TX1_SLAVE_IF"/ifindex) + BOND_TX2_SLAVE_IFIDX=3D$(ip netns exec "${TXNS}" \ + cat /sys/class/net/"$BOND_TX2_SLAVE_IF"/ifindex) + BOND_RX1_SLAVE_IFIDX=3D$(ip netns exec "${RXNS}" \ + cat /sys/class/net/"$BOND_RX1_SLAVE_IF"/ifindex) + BOND_RX2_SLAVE_IFIDX=3D$(ip netns exec "${RXNS}" \ + cat /sys/class/net/"$BOND_RX2_SLAVE_IF"/ifindex) + + exec {TXNS_FD} "$NSIM_DEV_SYS_LINK" + echo "${TXNS_FD}:$BOND_TX2_SLAVE_IFIDX $RXNS_FD:$BOND_RX2_SLAVE_IFIDX" \ + > "$NSIM_DEV_SYS_LINK" + + exec {TXNS_FD}<&- + exec {RXNS_FD}<&- +} + +function create_all_ifaces() { + # setup_ns function is coming from lib.sh + setup_ns TXNS RXNS + export NAMESPACE=3D"${RXNS}" + + # 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}" + + ip -n "${RXNS}" addr add "${DSTIP}"/24 dev "${DSTIF}" + ip -n "${RXNS}" link set "${DSTIF}" up + + ip -n "${TXNS}" addr add "${SRCIP}"/24 dev "${SRCIF}" + ip -n "${TXNS}" link set "${SRCIF}" up +} + +function test_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 + enable_netcons_ns 2> /dev/null + 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 test_delete_bond_and_reenable_target() { + ip -n "${TXNS}" \ + 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 + enable_netcons_ns + + 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 test_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 "${RXNS}" "${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 test_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 (test_delete_bond_and_reenable_target) + ip -n "${TXNS}" \ + 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 -n "${TXNS}" \ + link set "${BOND_TX1_SLAVE_IF}" down + ip -n "${TXNS}" \ + link set "${BOND_TX1_SLAVE_IF}" master "${BOND_TX_MAIN_IF}" + ip -n "${TXNS}" \ + 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 test_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 + enable_netcons_ns + + # 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 -n "${TXNS}" \ + 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 +} + +function test_enslave_iff_disabled_netpoll_iface { + local ret + + # Create two interfaces. veth interfaces it known to have + # IFF_DISABLE_NETPOLL set + if ! ip link add "${VETH0}" type veth peer name "${VETH1}" + then + echo "Failed to create veth TX interface. Is CONFIG_VETH set?" >&2 + exit "${ksft_skip}" + fi + set +e + # This will print RTNETLINK answers: Device or resource busy + ip link set "${VETH0}" master "${BOND_TX_MAIN_IF}" 2> /dev/null + ret=3D$? + set -e + if [[ $ret -eq 0 ]] + then + echo "test failed: veth interface could not be enslaved" + exit "${ksft_fail}" + fi +} + +# Given that netconsole picks the current net namespace, we need to enable= it +# from inside the TXNS namespace +function enable_netcons_ns() { + ip netns exec "${TXNS}" sh -c \ + "mount -t configfs configfs /sys/kernel/config && echo 1 > $NETCONS_PATH= /enabled" +} + +#################### +# 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 + +# Configure the ips as BOND_RX1_SLAVE_IF and BOND_TX1_SLAVE_IF +configure_ifaces_ips "${IP_VERSION}" + +_create_dynamic_target "${FORMAT}" "${NETCONS_PATH}" +enable_netcons_ns +set_user_data + +# Test #1 : Create an bonding interface and attach netpoll into +# the bonding interface. Netconsole/netpoll should work on +# the bonding interface. +test_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 +test_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 +test_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 +test_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 +test_enslave_iface_to_bond +echo "test #5: Enslaving an interface to bond+netpoll. Test passed." >&2 + +# Test #6: Enslave a IFF_DISABLE_NETPOLL sub-interface to a bonding interf= ace +# At this stage, BOND_TX_MAIN_IF has both sub interface and netconsole is +# enabled. This test will try to enslave an a veth (IFF_DISABLE_NETPOLL) i= nterface +# and it should fail, with netpoll: veth0 doesn't support polling +test_enslave_iff_disabled_netpoll_iface +echo "test #6: Enslaving IFF_DISABLE_NETPOLL ifaces to bond iface is not s= upported. 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..87f89fd92f8c1 100644 --- a/tools/testing/selftests/drivers/net/lib/sh/lib_netcons.sh +++ b/tools/testing/selftests/drivers/net/lib/sh/lib_netcons.sh @@ -11,9 +11,11 @@ set -euo pipefail LIBDIR=3D$(dirname "$(readlink -e "${BASH_SOURCE[0]}")") =20 SRCIF=3D"" # to be populated later +SRCIP=3D"" # to be populated later SRCIP4=3D"192.0.2.1" SRCIP6=3D"fc00::1" DSTIF=3D"" # to be populated later +DSTIP=3D"" # to be populated later DSTIP4=3D"192.0.2.2" DSTIP6=3D"fc00::2" =20 @@ -28,17 +30,23 @@ 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" =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 @@ -137,9 +145,6 @@ function _create_dynamic_target() { then echo 1 > "${NCPATH}"/extended fi - - echo 1 > "${NCPATH}"/enabled - } =20 function create_dynamic_target() { @@ -147,6 +152,8 @@ function create_dynamic_target() { local NCPATH=3D${2:-"$NETCONS_PATH"} _create_dynamic_target "${FORMAT}" "${NCPATH}" =20 + echo 1 > "${NCPATH}"/enabled + # This will make sure that the kernel was able to # load the netconsole driver configuration. The console message # gets more organized/sequential as well. @@ -193,14 +200,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 +396,24 @@ function wait_for_port() { # more frequently on IPv6 sleep 1 } + +# Clean up netdevsim ifaces created for bonding test +function cleanup_bond_nsim() { + ip -n "${TXNS}" \ + link delete "${BOND_TX_MAIN_IF}" type bond || true + ip -n "${RXNS}" \ + link delete "${BOND_RX_MAIN_IF}" type bond || true + + cleanup_netdevsim "$NSIM_BOND_TX_1" + cleanup_netdevsim "$NSIM_BOND_TX_2" + cleanup_netdevsim "$NSIM_BOND_RX_1" + cleanup_netdevsim "$NSIM_BOND_RX_2" +} + +# cleanup tests that use bonding interfaces +function cleanup_bond() { + cleanup_netcons + cleanup_bond_nsim + cleanup_all_ns + ip link delete "${VETH0}" || true +} --=20 2.47.3