From nobody Wed Nov 27 06:47:25 2024 Received: from mail-yw1-f172.google.com (mail-yw1-f172.google.com [209.85.128.172]) (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 AD7291C244B; Fri, 11 Oct 2024 18:36:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728671786; cv=none; b=PqbSpU0RJSdEzqUGgQO1GYTrTt20cMjtbSgroqSCWEVMOzxWrP2qRbAlKUBJolUdpBiFwMZYFYEDY9oIHkyS2Fj5y3+Rp70uhK60HxRIZbAGoueKaQo6dDs+kxQP90Bee45Q6u32E1rUXy7Y1EinRjNIXmElfU9lB25I+RABiTc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728671786; c=relaxed/simple; bh=JrF8Zr7us2ct+2L2k4U1kz7UYT/O4VO681fDrN/5LeQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KPQ0+ai+16gTtG0lBH+SbYoxOk7raC7MyYNLFv4c/wlr/4OhrMLIScRj9pUtr6h+zjHBhb3OH+xR0E3bUaHpz8bh40iLBjS0aokgEvDMmcefV92O2Q/TiQPJGZL1q3Zfu61MVoB+qfWpV47sQuPlwobz1DWAFA64/IF+VeFKMNU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Hz73zBM9; arc=none smtp.client-ip=209.85.128.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Hz73zBM9" Received: by mail-yw1-f172.google.com with SMTP id 00721157ae682-6de14e0f050so20129187b3.0; Fri, 11 Oct 2024 11:36:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728671784; x=1729276584; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2whrxblOrdDrylyUOw7dZMpo5t5TWeQsqPQJzAREmOw=; b=Hz73zBM9yDseKIwXP2veavPGia1qbW7VygS6OPjojX8tFspC5XA3M+mgVDrZzZZkCO flJj0Pf2XlRD20kMtgLDdBS8wtn1+AH9TPHpTU+0UZI1ndPoJ7O2KcfXDC9ArWMSGgSX PWDubzk7maaTDtuO5/krvBeyIOBv7jDJbazMgcYvL5A9KDuX6QlKMD9iK2AagWvc+Zdm 2BYTfm9iO7Y9py8uklx+19/OuUiPaJbbDCBMTCOaX+onOKIS1Pm2+/ZkOoCH/feE47fJ sMBnjDgxzB+duXrxTyzyU5/5jF9X2rJ9ehq74UIPzpp0VQLCfhfTE02C3GHSjZtlUOEw /Kmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728671784; x=1729276584; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2whrxblOrdDrylyUOw7dZMpo5t5TWeQsqPQJzAREmOw=; b=tby2bFlQmFlZIwM6O+8jUrOE1mA3OqN8Zv+ChV4+mUho6rKkDFVCFAaRbI6KCNGjCn Df0I0ofKu2E3VIn50pLAuPSN1A+5hBqTLw9AKTmNDhl3WoI2Jpcl+z7rGnVskVduBNvj 8F3jKR9wCr5/oaSSQ3eBgSOro1NBjsFnsC6P304CbU/0K3eueCHrYdLSGgwPpd9Z3ZUn 4Ysdspk5deO9EyA7iOm77hMNh3oUMLIpaVumpy1VcrjK9QYkCY7HXfOtLMrs8iXhIKTb DDU+QDum6C1k/7FRmLKKCdssIbiy853chHLr5msU7MHqMabbGNkZS+w0rYnL6pvjHnCN sNKA== X-Forwarded-Encrypted: i=1; AJvYcCXxOIUMEWv7zHRiftloJ0TC7w0o2p9O1nu7XHZkfghVTqRabybmcgeL4zoWMbs5q/QmmU5SLwiTPWY4IHU=@vger.kernel.org X-Gm-Message-State: AOJu0Yz4t6kdTIWEBd+8NwBKKHhlZ5MIcipxLsTt0GQKZ0u7Ale8KE9C I3vdOicsYXgF1j8eFrVFbUfoQchoV4nGDl7ADtRY6Q/taZcyg0tv X-Google-Smtp-Source: AGHT+IHCDNcCTyov+kFKcENxUDR/OEh5HFEcijllc6MNGfxEbHrHrgz64N7J/Um5XOHOAa3GS5zDlA== X-Received: by 2002:a05:690c:9a8b:b0:6e3:13c6:7fc3 with SMTP id 00721157ae682-6e3644c0efcmr5631067b3.28.1728671783656; Fri, 11 Oct 2024 11:36:23 -0700 (PDT) Received: from localhost (fwdproxy-nha-113.fbsv.net. [2a03:2880:25ff:71::face:b00c]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6e332c27d94sm6949017b3.86.2024.10.11.11.36.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Oct 2024 11:36:23 -0700 (PDT) From: Daniel Zahka To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next 1/2] ethtool: rss: prevent rss ctx deletion when in use Date: Fri, 11 Oct 2024 11:35:47 -0700 Message-ID: <20241011183549.1581021-2-daniel.zahka@gmail.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241011183549.1581021-1-daniel.zahka@gmail.com> References: <20241011183549.1581021-1-daniel.zahka@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" ntuple filters can specify an rss context to use for packet hashing and queue selection. When a filter is referencing an rss context, it should be invalid for that context to be deleted. A list of active ntuple filters and their associated rss contexts can be compiled by querying a device's ethtool_ops.get_rxnfc. This patch checks to see if any ntuple filters are referencing an rss context during context deletion, and prevents the deletion if the requested context is still in use. Signed-off-by: Daniel Zahka --- net/ethtool/common.c | 48 ++++++++++++++++++++++++++++++++++++++++++++ net/ethtool/common.h | 1 + net/ethtool/ioctl.c | 7 +++++++ 3 files changed, 56 insertions(+) diff --git a/net/ethtool/common.c b/net/ethtool/common.c index dd345efa114b..0d62363dbd9d 100644 --- a/net/ethtool/common.c +++ b/net/ethtool/common.c @@ -684,6 +684,54 @@ int ethtool_check_max_channel(struct net_device *dev, return 0; } =20 +int ethtool_check_rss_ctx_busy(struct net_device *dev, u32 rss_context) +{ + const struct ethtool_ops *ops =3D dev->ethtool_ops; + struct ethtool_rxnfc *info; + int rc, i, rule_cnt; + + if (!ops->get_rxnfc) + return 0; + + rule_cnt =3D ethtool_get_rxnfc_rule_count(dev); + if (!rule_cnt) + return 0; + + if (rule_cnt < 0) + return -EINVAL; + + info =3D kvzalloc(struct_size(info, rule_locs, rule_cnt), GFP_KERNEL); + if (!info) + return -ENOMEM; + + info->cmd =3D ETHTOOL_GRXCLSRLALL; + info->rule_cnt =3D rule_cnt; + rc =3D ops->get_rxnfc(dev, info, info->rule_locs); + if (rc) + goto out_free; + + for (i =3D 0; i < rule_cnt; i++) { + struct ethtool_rxnfc rule_info =3D { + .cmd =3D ETHTOOL_GRXCLSRULE, + .fs.location =3D info->rule_locs[i], + }; + + rc =3D ops->get_rxnfc(dev, &rule_info, NULL); + if (rc) + goto out_free; + + if (rule_info.fs.flow_type & FLOW_RSS && + rule_info.rss_context =3D=3D rss_context) { + rc =3D -EBUSY; + goto out_free; + } + } + +out_free: + kvfree(info); + return rc; +} + int ethtool_check_ops(const struct ethtool_ops *ops) { if (WARN_ON(ops->set_coalesce && !ops->supported_coalesce_params)) diff --git a/net/ethtool/common.h b/net/ethtool/common.h index d55d5201b085..4a2de3ce7354 100644 --- a/net/ethtool/common.h +++ b/net/ethtool/common.h @@ -47,6 +47,7 @@ bool convert_legacy_settings_to_link_ksettings( int ethtool_check_max_channel(struct net_device *dev, struct ethtool_channels channels, struct genl_info *info); +int ethtool_check_rss_ctx_busy(struct net_device *dev, u32 rss_context); int __ethtool_get_ts_info(struct net_device *dev, struct kernel_ethtool_ts= _info *info); =20 extern const struct ethtool_phy_ops *ethtool_phy_ops; diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c index 04b34dc6b369..5cc131cdb1bc 100644 --- a/net/ethtool/ioctl.c +++ b/net/ethtool/ioctl.c @@ -1462,6 +1462,13 @@ static noinline_for_stack int ethtool_set_rxfh(struc= t net_device *dev, mutex_lock(&dev->ethtool->rss_lock); locked =3D true; } + + if (rxfh.rss_context && rxfh_dev.rss_delete) { + ret =3D ethtool_check_rss_ctx_busy(dev, rxfh.rss_context); + if (ret) + goto out; + } + if (create) { if (rxfh_dev.rss_delete) { ret =3D -EINVAL; --=20 2.43.5 From nobody Wed Nov 27 06:47:25 2024 Received: from mail-yw1-f182.google.com (mail-yw1-f182.google.com [209.85.128.182]) (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 69FDD1C8FB7; Fri, 11 Oct 2024 18:36:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728671798; cv=none; b=XZxLajIs0JGy9gqsxh+3lQRQUYFmYySrM+R7VlYHTd+qjVweSICzkj0e71fQ9Rlwt6aJFKbpbTtybguJ5SA0X9I90ac9ELmWkv4J/fzshxs5wW8HW3ujjpzq/7uOkYQ8UMYFJiJr824C6hj4c4sA/JCHAZStWo4xViu2oNpV0U8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728671798; c=relaxed/simple; bh=ayPciMWY//VbPSzpp2VbZbk7uWTZGaXOBvAeQgtBwzA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AK9TyZVgjo/RbdnZAOvVU/Sx8YWpbi2dHMfgJtnZSEk+MYOoTw8n7ARpGm1tijSDMeV4m9FL6ynF1D++lEPkovuMrZyI/uO4cwl7WafzEehbwI/0XoHfWnfMtKX9VMKR/tkT1ApUSpl55mW6LAd55Lvc21A3Yu3wpqKK9YAKJxw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=kVt8ugzr; arc=none smtp.client-ip=209.85.128.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kVt8ugzr" Received: by mail-yw1-f182.google.com with SMTP id 00721157ae682-6e2346f164cso20646957b3.3; Fri, 11 Oct 2024 11:36:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728671796; x=1729276596; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=D0I/3yItTQ/jGPmVdy1AuiludxZJFxBg01l9+u4Pb+Q=; b=kVt8ugzrwd7atyJPCNjar/NfIf9ojRW7BIob9BPt3/WPtqBdn+9S2baLwqHWWi1PJQ QMnNefGwqLgGJMIpDn9KSfvnRaBQTngUDKLc411Iw+MzY2yownih37xfMj/+90Bh3ZXR QWCOo1p3pWmvjqPL8tDvg4UEtus6JTll7upcibSg1i/H89ylCU1AYQR4Nur4qPJ9BqgE JwDKUyyNI4m0bVtIFIge21QTtfN/Wa2m3NxktSONNLHGsqBy3iDE7tXoaz/FudNs/gRg GvGVGbtoY6Dmw65/sIGPxJplGUibuZ9VSOSMloj/fHdqzGmICcPaqqdFwK3TCoqau5sr VVvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728671796; x=1729276596; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=D0I/3yItTQ/jGPmVdy1AuiludxZJFxBg01l9+u4Pb+Q=; b=omLotlVWFkd86uhmEnRjOjgnLhSglI7dCg5Ac1aLjvuH7ypyCdiwCWkyNB7X+cnmYO /awhhs70z9EPPEd/1v+GueyLb5unmLCYKyWS+FyaieP8gAowDa/Dw7DMMZFvTzUjMlwV ekOtT//vgPlaf7t3TGqU1Nbv4ri1evb+jffrgzkQ0bLuEUG2L7NZyJZF7Rq/E3hYR8BT 2bSlKiWhd/552stP3x1D949vHSTET0QBPeqj9WjRxDCKPJbECMOJVFHidF071EDC6hZk KMpCmOivWJKn1RB5RtzaK3zJqfeUfE+kHrteP8kpE87oofh+7CSV0NORB4pvn4BTl9H7 +iIA== X-Forwarded-Encrypted: i=1; AJvYcCUbUW0g2u+6llfpq2ipsVcv+0BLBMsWurXDfCb23c5FmtqPcnDt3IREdgNomoqZELmSDUiyzaT5tZ34CqWcvNVh@vger.kernel.org, AJvYcCV80AF13tVvjS73zc/Y3M8+IZrGd3MBcPzAJ8NW+dCpmXvUekYbME5sBJ7xnGGWPh8mUhGKdBbxg4BaQuE=@vger.kernel.org X-Gm-Message-State: AOJu0Yw2EtCHbFqDVXeLsCbqFQRrOjZF3YnRXp7I+vaCSSi1bglOf0DI /qsVwbBXKtI1v8aAMAHgXNnovfuTvkOUB9+B0JffKgfUlIoMGcKz X-Google-Smtp-Source: AGHT+IEkRojL52hJwweCx2O+wUTzR4I5MkaqX2ww+MF8GrcLEe5MjWVwn/h2w/MXIKyB1CbvEhASEQ== X-Received: by 2002:a05:690c:9c05:b0:6e2:2600:ed50 with SMTP id 00721157ae682-6e3479ca9dcmr38458547b3.21.1728671796308; Fri, 11 Oct 2024 11:36:36 -0700 (PDT) Received: from localhost (fwdproxy-nha-112.fbsv.net. [2a03:2880:25ff:70::face:b00c]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6e332b83e8dsm6983997b3.33.2024.10.11.11.36.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Oct 2024 11:36:36 -0700 (PDT) From: Daniel Zahka To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Shuah Khan Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH net-next 2/2] selftests: drv-net: rss_ctx: add rss ctx busy testcase Date: Fri, 11 Oct 2024 11:35:48 -0700 Message-ID: <20241011183549.1581021-3-daniel.zahka@gmail.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241011183549.1581021-1-daniel.zahka@gmail.com> References: <20241011183549.1581021-1-daniel.zahka@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" It should be invalid to delete an rss context while it is being referenced from an ntuple filter. ethtool core should prevent this from happening. This patch adds a testcase to verify this behavior. Signed-off-by: Daniel Zahka --- .../selftests/drivers/net/hw/rss_ctx.py | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/drivers/net/hw/rss_ctx.py b/tools/test= ing/selftests/drivers/net/hw/rss_ctx.py index 9d7adb3cf33b..29995586993c 100755 --- a/tools/testing/selftests/drivers/net/hw/rss_ctx.py +++ b/tools/testing/selftests/drivers/net/hw/rss_ctx.py @@ -6,7 +6,7 @@ import random from lib.py import ksft_run, ksft_pr, ksft_exit, ksft_eq, ksft_ne, ksft_ge= , ksft_lt from lib.py import NetDrvEpEnv from lib.py import EthtoolFamily, NetdevFamily -from lib.py import KsftSkipEx +from lib.py import KsftSkipEx, KsftFailEx from lib.py import rand_port from lib.py import ethtool, ip, defer, GenerateTraffic, CmdExitFailure =20 @@ -606,6 +606,33 @@ def test_rss_context_overlap2(cfg): test_rss_context_overlap(cfg, True) =20 =20 +def test_delete_rss_context_busy(cfg): + """ + Test that deletion returns -EBUSY when an rss context is being used + by an ntuple filter. + """ + + require_ntuple(cfg) + + # create additional rss context + ctx_id =3D ethtool_create(cfg, "-X", "context new") + ctx_deleter =3D defer(ethtool, f"-X {cfg.ifname} context {ctx_id} dele= te") + + # utilize context from ntuple filter + port =3D rand_port() + flow =3D f"flow-type tcp{cfg.addr_ipver} dst-port {port} context {ctx_= id}" + ntuple_id =3D ethtool_create(cfg, "-N", flow) + defer(ethtool, f"-N {cfg.ifname} delete {ntuple_id}") + + # attempt to delete in-use context + try: + ctx_deleter.exec_only() + ctx_deleter.cancel() + raise KsftFailEx(f"deleted context {ctx_id} used by rule {ntuple_i= d}") + except CmdExitFailure: + pass + + def main() -> None: with NetDrvEpEnv(__file__, nsim_test=3DFalse) as cfg: cfg.ethnl =3D EthtoolFamily() @@ -616,7 +643,8 @@ def main() -> None: test_rss_context, test_rss_context4, test_rss_context32, test_rss_context_dump, test_rss_context_queue_reconfigur= e, test_rss_context_overlap, test_rss_context_overlap2, - test_rss_context_out_of_order, test_rss_context4_create_= with_cfg], + test_rss_context_out_of_order, test_rss_context4_create_= with_cfg, + test_delete_rss_context_busy], args=3D(cfg, )) ksft_exit() =20 --=20 2.43.5