public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next v2 0/3] ethtool: Dynamic RSS context indirection table resizing
@ 2026-03-04 13:18 Björn Töpel
  2026-03-04 13:18 ` [PATCH net-next v2 1/3] ethtool: Add RSS indirection table resize helpers Björn Töpel
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Björn Töpel @ 2026-03-04 13:18 UTC (permalink / raw)
  To: Michael Chan, Pavan Chebbi, Andrew Lunn, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman,
	linux-kernel, netdev, linux-kselftest
  Cc: Björn Töpel, Willem de Bruijn

Hi!

Some NICs (e.g. bnxt) change their RSS indirection table size based on
the queue count, because the hardware table is a shared resource. The
ethtool core locks ctx->indir_size at context creation, so drivers
have to reject channel changes when RSS contexts exist.

This series adds resize helpers and wires them up in bnxt.

Patch 1 adds core helpers:
  ethtool_rxfh_can_resize() - read-only validation
  ethtool_rxfh_resize() - fold/unfold a raw table in place
  ethtool_rxfh_ctxs_can_resize() - validate all non-default contexts
  ethtool_rxfh_ctxs_resize() - resize all non-default contexts,
    with locking and RSS_NTF notifications

Patch 2 uses them in bnxt_set_channels(). Validation runs before
bnxt_close_nic(); actual resize is deferred until after. RSS table
size only changes on P5 chips with older firmware.

Patch 3 adds HW tests in rss_drv.py (devices without dynamic table
sizing are skipped):
  resize_periodic - fold/unfold with a non-default [3,2,1,0]xN
    pattern, verifying exact content preservation (main + ctx)
  resize_nonperiodic_reject - non-periodic table blocks channel
    reduction, with an extra periodic context to exercise
    multi-context validation (main + ctx)
  resize_nonperiodic_no_corruption - failed resize leaves table
    contents and channel count unchanged (main + ctx)

Running the tests:

  # On real hardware
  sudo NETIF=eth0 ./rss_drv.py

Changes v1 -> v2:

 - Dropped netdevsim support and netdevsim selftest (Jakub)
 - Split ethtool_rxfh_contexts_resize_all() into separate validate
   (ethtool_rxfh_ctxs_can_resize) and apply (ethtool_rxfh_ctxs_resize)
   so drivers can validate before closing the device (Jakub)
 - Shortened helper names (Jakub)
 - Replaced scoped_guard(mutex) with explicit mutex_lock/unlock
   (Jakub)
 - Removed defensive zero-size check, bare expressions instead of != 0
   comparisons, ! instead of == 0 (Jakub)
 - In bnxt, moved bnxt_check_rings() before RSS validation and
   deferred actual resize to after bnxt_close_nic() (Jakub, Michael)
 - Added comment that RSS table size only changes on P5 chips with
   older firmware (Michael)
 - Use non-default [3,2,1,0]xN pattern set via netlink to distinguish
   correct fold from driver resetting to defaults (Jakub)
 - Check exact indirection table pattern, not just set(indir) (Jakub)
 - Use ksft_raises() instead of try/except/else (Jakub)
 - Removed queue_count=8 from NetDrvEnv (Jakub)
 - Added ksft_variants to resize_nonperiodic_reject for ctx coverage
 - Added extra periodic context in reject test for multi-context
   validation coverage
 - Added resize_nonperiodic_no_corruption test

Open items:

 - No user-controlled minimum table size yet. The plan is to record
   the user-provided indirection table length in the context (e.g.
   ctx->user_indir_size) and use it as a floor when folding: reject if
   new_size < user_indir_size. This way the user's original table size
   serves as an implicit minimum, preventing the driver from shrinking
   below what the user intended. Left for a follow-up.


Björn Töpel (3):
  ethtool: Add RSS indirection table resize helpers
  bnxt_en: Resize RSS contexts on channel count change
  selftests: rss_drv: Add RSS indirection table resize tests

 .../net/ethernet/broadcom/bnxt/bnxt_ethtool.c |  36 +++-
 include/linux/ethtool.h                       |   4 +
 net/ethtool/common.c                          | 146 ++++++++++++++++
 .../selftests/drivers/net/hw/rss_drv.py       | 163 +++++++++++++++++-
 4 files changed, 338 insertions(+), 11 deletions(-)


base-commit: ed0abfe93fd135dac223e87a3c945017b1fa8bfc
-- 
2.53.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH net-next v2 1/3] ethtool: Add RSS indirection table resize helpers
  2026-03-04 13:18 [PATCH net-next v2 0/3] ethtool: Dynamic RSS context indirection table resizing Björn Töpel
@ 2026-03-04 13:18 ` Björn Töpel
  2026-03-04 13:18 ` [PATCH net-next v2 2/3] bnxt_en: Resize RSS contexts on channel count change Björn Töpel
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Björn Töpel @ 2026-03-04 13:18 UTC (permalink / raw)
  To: Michael Chan, Pavan Chebbi, Andrew Lunn, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman,
	linux-kernel, netdev, linux-kselftest
  Cc: Björn Töpel, Willem de Bruijn

The core locks ctx->indir_size when an RSS context is created. Some
NICs (e.g. bnxt) change their indirection table size based on the
channel count, because the hardware table is a shared resource. This
forces drivers to reject channel changes when RSS contexts exist.

Add helpers to resize indirection tables:

ethtool_rxfh_can_resize() checks whether a table can be resized
without modifying it.

ethtool_rxfh_resize() resizes a raw u32 table in place. Folding
(shrink) requires the table to be periodic at the new size;
non-periodic tables are rejected. Unfolding (grow) replicates the
existing pattern. Sizes must be multiples of each other.

ethtool_rxfh_ctxs_can_resize() validates all non-default RSS contexts
can be resized. ethtool_rxfh_ctxs_resize() applies the resize and
sends ETHTOOL_MSG_RSS_NTF per resized context after releasing
rss_lock.

No reallocation is needed because ethtool_rxfh_ctx_alloc() reserves
space for rxfh_indir_space entries, and key_off is based on that
maximum.

Signed-off-by: Björn Töpel <bjorn@kernel.org>
---
 include/linux/ethtool.h |   4 ++
 net/ethtool/common.c    | 146 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 150 insertions(+)

diff --git a/include/linux/ethtool.h b/include/linux/ethtool.h
index 798abec67a1b..57f480444607 100644
--- a/include/linux/ethtool.h
+++ b/include/linux/ethtool.h
@@ -214,6 +214,10 @@ static inline u8 *ethtool_rxfh_context_key(struct ethtool_rxfh_context *ctx)
 }
 
 void ethtool_rxfh_context_lost(struct net_device *dev, u32 context_id);
+int ethtool_rxfh_can_resize(const u32 *tbl, u32 old_size, u32 new_size);
+int ethtool_rxfh_resize(u32 *tbl, u32 old_size, u32 new_size);
+int ethtool_rxfh_ctxs_can_resize(struct net_device *dev, u32 new_indir_size);
+void ethtool_rxfh_ctxs_resize(struct net_device *dev, u32 new_indir_size);
 
 struct link_mode_info {
 	int	speed;
diff --git a/net/ethtool/common.c b/net/ethtool/common.c
index e252cf20c22f..5041b7ebf50a 100644
--- a/net/ethtool/common.c
+++ b/net/ethtool/common.c
@@ -1204,6 +1204,152 @@ void ethtool_rxfh_context_lost(struct net_device *dev, u32 context_id)
 }
 EXPORT_SYMBOL(ethtool_rxfh_context_lost);
 
+static bool rxfh_indir_is_periodic(const u32 *tbl, u32 old_size, u32 new_size)
+{
+	u32 i;
+
+	for (i = new_size; i < old_size; i++)
+		if (tbl[i] != tbl[i % new_size])
+			return false;
+	return true;
+}
+
+/**
+ * ethtool_rxfh_can_resize - Check if an indirection table can be resized
+ * @tbl: indirection table
+ * @old_size: current number of entries in the table
+ * @new_size: desired number of entries
+ *
+ * Validate that @tbl can be resized from @old_size to @new_size without
+ * data loss. Read-only; does not modify the table.
+ *
+ * Return: 0 if resize is possible, -%EINVAL otherwise.
+ */
+int ethtool_rxfh_can_resize(const u32 *tbl, u32 old_size, u32 new_size)
+{
+	if (new_size == old_size)
+		return 0;
+
+	if (new_size < old_size) {
+		if (old_size % new_size)
+			return -EINVAL;
+		if (!rxfh_indir_is_periodic(tbl, old_size, new_size))
+			return -EINVAL;
+		return 0;
+	}
+
+	if (new_size % old_size)
+		return -EINVAL;
+	return 0;
+}
+EXPORT_SYMBOL(ethtool_rxfh_can_resize);
+
+/* Resize without validation; caller must have called can_resize first */
+static void __ethtool_rxfh_resize(u32 *tbl, u32 old_size, u32 new_size)
+{
+	u32 i;
+
+	/* Grow: replicate existing pattern; shrink is a no-op on the data */
+	for (i = old_size; i < new_size; i++)
+		tbl[i] = tbl[i % old_size];
+}
+
+/**
+ * ethtool_rxfh_resize - Fold or unfold an indirection table
+ * @tbl: indirection table (must have room for max(old_size, new_size) entries)
+ * @old_size: current number of entries in the table
+ * @new_size: desired number of entries
+ *
+ * Resize an RSS indirection table in place. When folding (shrinking),
+ * the table must be periodic with period @new_size; otherwise the
+ * operation is rejected. When unfolding (growing), the existing
+ * pattern is replicated. Both directions require the sizes to be
+ * multiples of each other.
+ *
+ * Return: 0 on success, -%EINVAL on failure (no mutation on failure).
+ */
+int ethtool_rxfh_resize(u32 *tbl, u32 old_size, u32 new_size)
+{
+	int ret;
+
+	ret = ethtool_rxfh_can_resize(tbl, old_size, new_size);
+	if (ret)
+		return ret;
+
+	__ethtool_rxfh_resize(tbl, old_size, new_size);
+	return 0;
+}
+EXPORT_SYMBOL(ethtool_rxfh_resize);
+
+/**
+ * ethtool_rxfh_ctxs_can_resize - Validate resize for all RSS contexts
+ * @dev: network device
+ * @new_indir_size: new indirection table size
+ *
+ * Validate that the indirection tables of all non-default RSS contexts
+ * can be resized to @new_indir_size. Read-only; does not modify any
+ * context. Intended to be paired with ethtool_rxfh_ctxs_resize().
+ *
+ * Return: 0 if all contexts can be resized, negative errno on failure.
+ */
+int ethtool_rxfh_ctxs_can_resize(struct net_device *dev,
+				 u32 new_indir_size)
+{
+	struct ethtool_rxfh_context *ctx;
+	unsigned long context;
+	int ret;
+
+	if (!dev->ethtool_ops->rxfh_indir_space ||
+	    new_indir_size > dev->ethtool_ops->rxfh_indir_space)
+		return -EINVAL;
+
+	mutex_lock(&dev->ethtool->rss_lock);
+	xa_for_each(&dev->ethtool->rss_ctx, context, ctx) {
+		u32 *indir = ethtool_rxfh_context_indir(ctx);
+
+		ret = ethtool_rxfh_can_resize(indir, ctx->indir_size,
+					      new_indir_size);
+		if (ret)
+			goto unlock;
+	}
+	ret = 0;
+unlock:
+	mutex_unlock(&dev->ethtool->rss_lock);
+	return ret;
+}
+EXPORT_SYMBOL(ethtool_rxfh_ctxs_can_resize);
+
+/**
+ * ethtool_rxfh_ctxs_resize - Resize all RSS context indirection tables
+ * @dev: network device
+ * @new_indir_size: new indirection table size
+ *
+ * Resize the indirection table of every non-default RSS context to
+ * @new_indir_size. Caller must have validated with
+ * ethtool_rxfh_ctxs_can_resize() first. An %ETHTOOL_MSG_RSS_NTF is
+ * sent for each resized context.
+ *
+ * Notifications are sent outside the RSS lock to avoid holding the
+ * mutex during notification delivery.
+ */
+void ethtool_rxfh_ctxs_resize(struct net_device *dev, u32 new_indir_size)
+{
+	struct ethtool_rxfh_context *ctx;
+	unsigned long context;
+
+	mutex_lock(&dev->ethtool->rss_lock);
+	xa_for_each(&dev->ethtool->rss_ctx, context, ctx) {
+		__ethtool_rxfh_resize(ethtool_rxfh_context_indir(ctx),
+				      ctx->indir_size, new_indir_size);
+		ctx->indir_size = new_indir_size;
+	}
+	mutex_unlock(&dev->ethtool->rss_lock);
+
+	xa_for_each(&dev->ethtool->rss_ctx, context, ctx)
+		ethtool_rss_notify(dev, ETHTOOL_MSG_RSS_NTF, context);
+}
+EXPORT_SYMBOL(ethtool_rxfh_ctxs_resize);
+
 enum ethtool_link_medium ethtool_str_to_medium(const char *str)
 {
 	int i;
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH net-next v2 2/3] bnxt_en: Resize RSS contexts on channel count change
  2026-03-04 13:18 [PATCH net-next v2 0/3] ethtool: Dynamic RSS context indirection table resizing Björn Töpel
  2026-03-04 13:18 ` [PATCH net-next v2 1/3] ethtool: Add RSS indirection table resize helpers Björn Töpel
@ 2026-03-04 13:18 ` Björn Töpel
  2026-03-06  3:05   ` Jakub Kicinski
  2026-03-04 13:18 ` [PATCH net-next v2 3/3] selftests: rss_drv: Add RSS indirection table resize tests Björn Töpel
  2026-03-05  9:25 ` [PATCH net-next v2 0/3] ethtool: Dynamic RSS context indirection table resizing Pavan Chebbi
  3 siblings, 1 reply; 7+ messages in thread
From: Björn Töpel @ 2026-03-04 13:18 UTC (permalink / raw)
  To: Michael Chan, Pavan Chebbi, Andrew Lunn, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman,
	linux-kernel, netdev, linux-kselftest
  Cc: Björn Töpel, Willem de Bruijn

bnxt_set_channels() rejects channel changes that alter the RSS table
size when IFF_RXFH_CONFIGURED is set, because non-default context
sizes were locked at creation.

Replace the rejection with the new resize helpers. All validation runs
before the device is closed; actual resize is deferred until after
bnxt_close_nic():

 1. ethtool_rxfh_can_resize() checks context 0.
 2. ethtool_rxfh_ctxs_can_resize() validates all non-default contexts.
 3. After bnxt_close_nic(), ethtool_rxfh_resize() applies context 0
    changes, and ethtool_rxfh_ctxs_resize() resizes non-default
    contexts.

RSS table size only changes on P5 chips with older firmware; newer
firmware always uses the largest table size.

When context 0 uses defaults (!IFF_RXFH_CONFIGURED), steps 1 and 3 are
skipped; the driver regenerates the table via
bnxt_set_dflt_rss_indir_tbl().

Signed-off-by: Björn Töpel <bjorn@kernel.org>
---
 .../net/ethernet/broadcom/bnxt/bnxt_ethtool.c | 36 +++++++++++++++----
 1 file changed, 29 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c b/drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c
index 26fcd52c8a61..1bb0dd5bb683 100644
--- a/drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c
@@ -942,6 +942,7 @@ static int bnxt_set_channels(struct net_device *dev,
 {
 	struct bnxt *bp = netdev_priv(dev);
 	int req_tx_rings, req_rx_rings, tcs;
+	u32 new_tbl_size = 0, old_tbl_size;
 	bool sh = false;
 	int tx_xdp = 0;
 	int rc = 0;
@@ -977,19 +978,33 @@ static int bnxt_set_channels(struct net_device *dev,
 		tx_xdp = req_rx_rings;
 	}
 
-	if (bnxt_get_nr_rss_ctxs(bp, req_rx_rings) !=
-	    bnxt_get_nr_rss_ctxs(bp, bp->rx_nr_rings) &&
-	    netif_is_rxfh_configured(dev)) {
-		netdev_warn(dev, "RSS table size change required, RSS table entries must be default to proceed\n");
-		return -EINVAL;
-	}
-
 	rc = bnxt_check_rings(bp, req_tx_rings, req_rx_rings, sh, tcs, tx_xdp);
 	if (rc) {
 		netdev_warn(dev, "Unable to allocate the requested rings\n");
 		return rc;
 	}
 
+	/* RSS table size only changes on P5 chips with older firmware;
+	 * newer firmware always uses the largest table size.
+	 */
+	if (bnxt_get_nr_rss_ctxs(bp, req_rx_rings) !=
+	    bnxt_get_nr_rss_ctxs(bp, bp->rx_nr_rings)) {
+		new_tbl_size = bnxt_get_nr_rss_ctxs(bp, req_rx_rings) *
+			       BNXT_RSS_TABLE_ENTRIES_P5;
+		old_tbl_size = bnxt_get_rxfh_indir_size(dev);
+
+		if (netif_is_rxfh_configured(dev) &&
+		    ethtool_rxfh_can_resize(bp->rss_indir_tbl,
+					    old_tbl_size, new_tbl_size)) {
+			netdev_warn(dev, "RSS table resize not possible\n");
+			return -EINVAL;
+		}
+
+		rc = ethtool_rxfh_ctxs_can_resize(dev, new_tbl_size);
+		if (rc)
+			return rc;
+	}
+
 	if (netif_running(dev)) {
 		if (BNXT_PF(bp)) {
 			/* TODO CHIMP_FW: Send message to all VF's
@@ -999,6 +1014,13 @@ static int bnxt_set_channels(struct net_device *dev,
 		bnxt_close_nic(bp, true, false);
 	}
 
+	if (new_tbl_size) {
+		if (netif_is_rxfh_configured(dev))
+			ethtool_rxfh_resize(bp->rss_indir_tbl,
+					    old_tbl_size, new_tbl_size);
+		ethtool_rxfh_ctxs_resize(dev, new_tbl_size);
+	}
+
 	if (sh) {
 		bp->flags |= BNXT_FLAG_SHARED_RINGS;
 		bp->rx_nr_rings = channel->combined_count;
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH net-next v2 3/3] selftests: rss_drv: Add RSS indirection table resize tests
  2026-03-04 13:18 [PATCH net-next v2 0/3] ethtool: Dynamic RSS context indirection table resizing Björn Töpel
  2026-03-04 13:18 ` [PATCH net-next v2 1/3] ethtool: Add RSS indirection table resize helpers Björn Töpel
  2026-03-04 13:18 ` [PATCH net-next v2 2/3] bnxt_en: Resize RSS contexts on channel count change Björn Töpel
@ 2026-03-04 13:18 ` Björn Töpel
  2026-03-05  9:25 ` [PATCH net-next v2 0/3] ethtool: Dynamic RSS context indirection table resizing Pavan Chebbi
  3 siblings, 0 replies; 7+ messages in thread
From: Björn Töpel @ 2026-03-04 13:18 UTC (permalink / raw)
  To: Michael Chan, Pavan Chebbi, Andrew Lunn, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman,
	linux-kernel, netdev, linux-kselftest
  Cc: Björn Töpel, Willem de Bruijn

Add resize tests to rss_drv.py. Devices without dynamic table sizing
are skipped via _require_dynamic_indir_size().

resize_periodic: set a periodic table (equal 4), shrink channels to
fold, grow back to unfold. Check the exact pattern is preserved. Has
main and non-default context variants.

resize_nonperiodic_reject: set a non-periodic table (equal N), verify
that channel reduction is rejected.

Signed-off-by: Björn Töpel <bjorn@kernel.org>
---
 .../selftests/drivers/net/hw/rss_drv.py       | 163 +++++++++++++++++-
 1 file changed, 159 insertions(+), 4 deletions(-)

diff --git a/tools/testing/selftests/drivers/net/hw/rss_drv.py b/tools/testing/selftests/drivers/net/hw/rss_drv.py
index 2d1a33189076..9763760f8306 100755
--- a/tools/testing/selftests/drivers/net/hw/rss_drv.py
+++ b/tools/testing/selftests/drivers/net/hw/rss_drv.py
@@ -5,9 +5,9 @@
 Driver-related behavior tests for RSS.
 """
 
-from lib.py import ksft_run, ksft_exit, ksft_ge
-from lib.py import ksft_variants, KsftNamedVariant, KsftSkipEx
-from lib.py import defer, ethtool
+from lib.py import ksft_run, ksft_exit, ksft_eq, ksft_ge
+from lib.py import ksft_variants, KsftNamedVariant, KsftSkipEx, ksft_raises
+from lib.py import defer, ethtool, CmdExitFailure
 from lib.py import EthtoolFamily, NlError
 from lib.py import NetDrvEnv
 
@@ -45,6 +45,18 @@ def _maybe_create_context(cfg, create_context):
     return ctx_id
 
 
+def _require_dynamic_indir_size(cfg, ch_max):
+    """Skip if the device does not dynamically size its indirection table."""
+    ethtool(f"-X {cfg.ifname} default")
+    ethtool(f"-L {cfg.ifname} combined 2")
+    small = len(_get_rss(cfg)['rss-indirection-table'])
+    ethtool(f"-L {cfg.ifname} combined {ch_max}")
+    large = len(_get_rss(cfg)['rss-indirection-table'])
+
+    if small == large:
+        raise KsftSkipEx("Device does not dynamically size indirection table")
+
+
 @ksft_variants([
     KsftNamedVariant("main", False),
     KsftNamedVariant("ctx", True),
@@ -76,11 +88,154 @@ def indir_size_4x(cfg, create_context):
         _test_rss_indir_size(cfg, test_max, context=ctx_id)
 
 
+@ksft_variants([
+    KsftNamedVariant("main", False),
+    KsftNamedVariant("ctx", True),
+])
+def resize_periodic(cfg, create_context):
+    """Test that a periodic indirection table survives channel changes.
+
+    Set a non-default periodic table ([3, 2, 1, 0] x N) via netlink,
+    reduce channels to trigger a fold, then increase to trigger an
+    unfold. Using a reversed pattern (instead of [0, 1, 2, 3]) ensures
+    the test can distinguish a correct fold from a driver that silently
+    resets the table to defaults. Verify the exact pattern is preserved
+    and the size tracks the channel count.
+    """
+    channels = cfg.ethnl.channels_get({'header': {'dev-index': cfg.ifindex}})
+    ch_max = channels.get('combined-max', 0)
+    qcnt = channels['combined-count']
+
+    if ch_max < 4:
+        raise KsftSkipEx(f"Not enough queues for the test: max={ch_max}")
+
+    defer(ethtool, f"-L {cfg.ifname} combined {qcnt}")
+
+    _require_dynamic_indir_size(cfg, ch_max)
+
+    ctx_id = _maybe_create_context(cfg, create_context)
+
+    # Set a non-default periodic pattern via netlink
+    rss = _get_rss(cfg, context=ctx_id)
+    orig_size = len(rss['rss-indirection-table'])
+    pattern = [3, 2, 1, 0] * (orig_size // 4)
+    req = {'header': {'dev-index': cfg.ifindex}, 'indir': pattern}
+    if ctx_id:
+        req['context'] = ctx_id
+    else:
+        defer(ethtool, f"-X {cfg.ifname} default")
+    cfg.ethnl.rss_set(req)
+
+    # Shrink — should fold
+    ethtool(f"-L {cfg.ifname} combined 4")
+    rss = _get_rss(cfg, context=ctx_id)
+    indir = rss['rss-indirection-table']
+
+    ksft_ge(orig_size, len(indir), "Table did not shrink")
+    ksft_eq(indir, [3, 2, 1, 0] * (len(indir) // 4),
+            "Folded table has wrong pattern")
+
+    # Grow back — should unfold
+    ethtool(f"-L {cfg.ifname} combined {ch_max}")
+    rss = _get_rss(cfg, context=ctx_id)
+    indir = rss['rss-indirection-table']
+
+    ksft_eq(len(indir), orig_size, "Table size not restored")
+    ksft_eq(indir, [3, 2, 1, 0] * (len(indir) // 4),
+            "Unfolded table has wrong pattern")
+
+
+@ksft_variants([
+    KsftNamedVariant("main", False),
+    KsftNamedVariant("ctx", True),
+])
+def resize_nonperiodic_reject(cfg, create_context):
+    """Test that a non-periodic table blocks channel reduction.
+
+    Set equal weight across all queues so the table is not periodic
+    at any smaller size, then verify channel reduction is rejected.
+    An additional context with a periodic table is created to verify
+    that validation catches the non-periodic one even when others
+    are fine.
+    """
+    channels = cfg.ethnl.channels_get({'header': {'dev-index': cfg.ifindex}})
+    ch_max = channels.get('combined-max', 0)
+    qcnt = channels['combined-count']
+
+    if ch_max < 4:
+        raise KsftSkipEx(f"Not enough queues for the test: max={ch_max}")
+
+    defer(ethtool, f"-L {cfg.ifname} combined {qcnt}")
+
+    _require_dynamic_indir_size(cfg, ch_max)
+
+    ctx_id = _maybe_create_context(cfg, create_context)
+    ctx_ref = f"context {ctx_id}" if ctx_id else ""
+
+    # Create an extra context with a periodic (foldable) table so that
+    # the validation must iterate all contexts to find the bad one.
+    extra_ctx = _maybe_create_context(cfg, True)
+    ethtool(f"-X {cfg.ifname} context {extra_ctx} equal 2")
+
+    ethtool(f"-X {cfg.ifname} {ctx_ref} equal {ch_max}")
+    if not create_context:
+        defer(ethtool, f"-X {cfg.ifname} default")
+
+    with ksft_raises(CmdExitFailure):
+        ethtool(f"-L {cfg.ifname} combined 2")
+
+
+@ksft_variants([
+    KsftNamedVariant("main", False),
+    KsftNamedVariant("ctx", True),
+])
+def resize_nonperiodic_no_corruption(cfg, create_context):
+    """Test that a failed resize does not corrupt table or channel count.
+
+    Set a non-periodic table, attempt a channel reduction (which must
+    fail), then verify both the indirection table contents and the
+    channel count are unchanged.
+    """
+    channels = cfg.ethnl.channels_get({'header': {'dev-index': cfg.ifindex}})
+    ch_max = channels.get('combined-max', 0)
+    qcnt = channels['combined-count']
+
+    if ch_max < 4:
+        raise KsftSkipEx(f"Not enough queues for the test: max={ch_max}")
+
+    defer(ethtool, f"-L {cfg.ifname} combined {qcnt}")
+
+    _require_dynamic_indir_size(cfg, ch_max)
+
+    ctx_id = _maybe_create_context(cfg, create_context)
+    ctx_ref = f"context {ctx_id}" if ctx_id else ""
+
+    ethtool(f"-X {cfg.ifname} {ctx_ref} equal {ch_max}")
+    if not create_context:
+        defer(ethtool, f"-X {cfg.ifname} default")
+
+    rss_before = _get_rss(cfg, context=ctx_id)
+
+    with ksft_raises(CmdExitFailure):
+        ethtool(f"-L {cfg.ifname} combined 2")
+
+    rss_after = _get_rss(cfg, context=ctx_id)
+    ksft_eq(rss_after['rss-indirection-table'],
+            rss_before['rss-indirection-table'],
+            "Indirection table corrupted after failed resize")
+
+    channels = cfg.ethnl.channels_get({'header': {'dev-index': cfg.ifindex}})
+    ksft_eq(channels['combined-count'], ch_max,
+            "Channel count changed after failed resize")
+
+
 def main() -> None:
     """ Ksft boiler plate main """
     with NetDrvEnv(__file__) as cfg:
         cfg.ethnl = EthtoolFamily()
-        ksft_run([indir_size_4x], args=(cfg, ))
+        ksft_run([indir_size_4x, resize_periodic,
+                  resize_nonperiodic_reject,
+                  resize_nonperiodic_no_corruption], args=(cfg, ))
     ksft_exit()
 
 
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH net-next v2 0/3] ethtool: Dynamic RSS context indirection table resizing
  2026-03-04 13:18 [PATCH net-next v2 0/3] ethtool: Dynamic RSS context indirection table resizing Björn Töpel
                   ` (2 preceding siblings ...)
  2026-03-04 13:18 ` [PATCH net-next v2 3/3] selftests: rss_drv: Add RSS indirection table resize tests Björn Töpel
@ 2026-03-05  9:25 ` Pavan Chebbi
  3 siblings, 0 replies; 7+ messages in thread
From: Pavan Chebbi @ 2026-03-05  9:25 UTC (permalink / raw)
  To: Björn Töpel
  Cc: Michael Chan, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Simon Horman, linux-kernel, netdev,
	linux-kselftest, Willem de Bruijn

[-- Attachment #1: Type: text/plain, Size: 3990 bytes --]

On Wed, Mar 4, 2026 at 6:49 PM Björn Töpel <bjorn@kernel.org> wrote:
>
> Hi!
>
> Some NICs (e.g. bnxt) change their RSS indirection table size based on
> the queue count, because the hardware table is a shared resource. The
> ethtool core locks ctx->indir_size at context creation, so drivers
> have to reject channel changes when RSS contexts exist.
>
> This series adds resize helpers and wires them up in bnxt.

Tested-by: Pavan Chebbi <pavan.chebbi@broadcom.com>


>
> Patch 1 adds core helpers:
>   ethtool_rxfh_can_resize() - read-only validation
>   ethtool_rxfh_resize() - fold/unfold a raw table in place
>   ethtool_rxfh_ctxs_can_resize() - validate all non-default contexts
>   ethtool_rxfh_ctxs_resize() - resize all non-default contexts,
>     with locking and RSS_NTF notifications
>
> Patch 2 uses them in bnxt_set_channels(). Validation runs before
> bnxt_close_nic(); actual resize is deferred until after. RSS table
> size only changes on P5 chips with older firmware.
>
> Patch 3 adds HW tests in rss_drv.py (devices without dynamic table
> sizing are skipped):
>   resize_periodic - fold/unfold with a non-default [3,2,1,0]xN
>     pattern, verifying exact content preservation (main + ctx)
>   resize_nonperiodic_reject - non-periodic table blocks channel
>     reduction, with an extra periodic context to exercise
>     multi-context validation (main + ctx)
>   resize_nonperiodic_no_corruption - failed resize leaves table
>     contents and channel count unchanged (main + ctx)
>
> Running the tests:
>
>   # On real hardware
>   sudo NETIF=eth0 ./rss_drv.py
>
> Changes v1 -> v2:
>
>  - Dropped netdevsim support and netdevsim selftest (Jakub)
>  - Split ethtool_rxfh_contexts_resize_all() into separate validate
>    (ethtool_rxfh_ctxs_can_resize) and apply (ethtool_rxfh_ctxs_resize)
>    so drivers can validate before closing the device (Jakub)
>  - Shortened helper names (Jakub)
>  - Replaced scoped_guard(mutex) with explicit mutex_lock/unlock
>    (Jakub)
>  - Removed defensive zero-size check, bare expressions instead of != 0
>    comparisons, ! instead of == 0 (Jakub)
>  - In bnxt, moved bnxt_check_rings() before RSS validation and
>    deferred actual resize to after bnxt_close_nic() (Jakub, Michael)
>  - Added comment that RSS table size only changes on P5 chips with
>    older firmware (Michael)
>  - Use non-default [3,2,1,0]xN pattern set via netlink to distinguish
>    correct fold from driver resetting to defaults (Jakub)
>  - Check exact indirection table pattern, not just set(indir) (Jakub)
>  - Use ksft_raises() instead of try/except/else (Jakub)
>  - Removed queue_count=8 from NetDrvEnv (Jakub)
>  - Added ksft_variants to resize_nonperiodic_reject for ctx coverage
>  - Added extra periodic context in reject test for multi-context
>    validation coverage
>  - Added resize_nonperiodic_no_corruption test
>
> Open items:
>
>  - No user-controlled minimum table size yet. The plan is to record
>    the user-provided indirection table length in the context (e.g.
>    ctx->user_indir_size) and use it as a floor when folding: reject if
>    new_size < user_indir_size. This way the user's original table size
>    serves as an implicit minimum, preventing the driver from shrinking
>    below what the user intended. Left for a follow-up.
>
>
> Björn Töpel (3):
>   ethtool: Add RSS indirection table resize helpers
>   bnxt_en: Resize RSS contexts on channel count change
>   selftests: rss_drv: Add RSS indirection table resize tests
>
>  .../net/ethernet/broadcom/bnxt/bnxt_ethtool.c |  36 +++-
>  include/linux/ethtool.h                       |   4 +
>  net/ethtool/common.c                          | 146 ++++++++++++++++
>  .../selftests/drivers/net/hw/rss_drv.py       | 163 +++++++++++++++++-
>  4 files changed, 338 insertions(+), 11 deletions(-)
>
>
> base-commit: ed0abfe93fd135dac223e87a3c945017b1fa8bfc
> --
> 2.53.0
>

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 5469 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH net-next v2 2/3] bnxt_en: Resize RSS contexts on channel count change
  2026-03-04 13:18 ` [PATCH net-next v2 2/3] bnxt_en: Resize RSS contexts on channel count change Björn Töpel
@ 2026-03-06  3:05   ` Jakub Kicinski
  2026-03-06  8:13     ` Björn Töpel
  0 siblings, 1 reply; 7+ messages in thread
From: Jakub Kicinski @ 2026-03-06  3:05 UTC (permalink / raw)
  To: Björn Töpel
  Cc: Michael Chan, Pavan Chebbi, Andrew Lunn, David S. Miller,
	Eric Dumazet, Paolo Abeni, Simon Horman, linux-kernel, netdev,
	linux-kselftest, Willem de Bruijn

On Wed,  4 Mar 2026 14:18:52 +0100 Björn Töpel wrote:
> +		if (netif_is_rxfh_configured(dev) &&
> +		    ethtool_rxfh_can_resize(bp->rss_indir_tbl,
> +					    old_tbl_size, new_tbl_size)) {

Doesn't this read a little odd? Shouldn't ethtool_rxfh_can_resize()
return true when ... we can resize? You end up ignoring the real rc
here, and it can only ever be -EINVAL.

> +			netdev_warn(dev, "RSS table resize not possible\n");
> +			return -EINVAL;
> +		}

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH net-next v2 2/3] bnxt_en: Resize RSS contexts on channel count change
  2026-03-06  3:05   ` Jakub Kicinski
@ 2026-03-06  8:13     ` Björn Töpel
  0 siblings, 0 replies; 7+ messages in thread
From: Björn Töpel @ 2026-03-06  8:13 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: Michael Chan, Pavan Chebbi, Andrew Lunn, David S. Miller,
	Eric Dumazet, Paolo Abeni, Simon Horman, linux-kernel, netdev,
	linux-kselftest, Willem de Bruijn

Jakub!

On Fri, 6 Mar 2026 at 04:05, Jakub Kicinski <kuba@kernel.org> wrote:
>
> On Wed,  4 Mar 2026 14:18:52 +0100 Björn Töpel wrote:
> > +             if (netif_is_rxfh_configured(dev) &&
> > +                 ethtool_rxfh_can_resize(bp->rss_indir_tbl,
> > +                                         old_tbl_size, new_tbl_size)) {
>
> Doesn't this read a little odd? Shouldn't ethtool_rxfh_can_resize()
> return true when ... we can resize? You end up ignoring the real rc
> here, and it can only ever be -EINVAL.

Yeah, it does. I'll change to return a bool, and inverse the check!

Thanks,
Björn

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-03-06  8:13 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-04 13:18 [PATCH net-next v2 0/3] ethtool: Dynamic RSS context indirection table resizing Björn Töpel
2026-03-04 13:18 ` [PATCH net-next v2 1/3] ethtool: Add RSS indirection table resize helpers Björn Töpel
2026-03-04 13:18 ` [PATCH net-next v2 2/3] bnxt_en: Resize RSS contexts on channel count change Björn Töpel
2026-03-06  3:05   ` Jakub Kicinski
2026-03-06  8:13     ` Björn Töpel
2026-03-04 13:18 ` [PATCH net-next v2 3/3] selftests: rss_drv: Add RSS indirection table resize tests Björn Töpel
2026-03-05  9:25 ` [PATCH net-next v2 0/3] ethtool: Dynamic RSS context indirection table resizing Pavan Chebbi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox