From: "Björn Töpel" <bjorn@kernel.org>
To: Michael Chan <michael.chan@broadcom.com>,
Pavan Chebbi <pavan.chebbi@broadcom.com>,
Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>,
linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
linux-kselftest@vger.kernel.org
Cc: "Björn Töpel" <bjorn@kernel.org>,
"Willem de Bruijn" <willemb@google.com>
Subject: [PATCH net-next 1/5] ethtool: Add RSS indirection table resize helpers
Date: Tue, 3 Mar 2026 19:15:29 +0100 [thread overview]
Message-ID: <20260303181535.2671734-2-bjorn@kernel.org> (raw)
In-Reply-To: <20260303181535.2671734-1-bjorn@kernel.org>
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_indir_can_resize() checks whether a table can be resized
without modifying it.
ethtool_rxfh_indir_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_contexts_resize_all() resizes all non-default RSS
contexts. Validates every context before modifying any, so either all
succeed or none are changed. 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 | 3 +
net/ethtool/common.c | 126 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 129 insertions(+)
diff --git a/include/linux/ethtool.h b/include/linux/ethtool.h
index 798abec67a1b..add7d16ca398 100644
--- a/include/linux/ethtool.h
+++ b/include/linux/ethtool.h
@@ -214,6 +214,9 @@ 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_indir_can_resize(const u32 *tbl, u32 old_size, u32 new_size);
+int ethtool_rxfh_indir_resize(u32 *tbl, u32 old_size, u32 new_size);
+int ethtool_rxfh_contexts_resize_all(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..8df84ff9efa4 100644
--- a/net/ethtool/common.c
+++ b/net/ethtool/common.c
@@ -1204,6 +1204,132 @@ void ethtool_rxfh_context_lost(struct net_device *dev, u32 context_id)
}
EXPORT_SYMBOL(ethtool_rxfh_context_lost);
+static bool ethtool_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_indir_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_indir_can_resize(const u32 *tbl, u32 old_size, u32 new_size)
+{
+ if (old_size == 0 || new_size == 0)
+ return -EINVAL;
+ if (new_size == old_size)
+ return 0;
+
+ if (new_size < old_size) {
+ if (old_size % new_size != 0)
+ return -EINVAL;
+ if (!ethtool_rxfh_indir_is_periodic(tbl, old_size, new_size))
+ return -EINVAL;
+ return 0;
+ }
+
+ if (new_size % old_size != 0)
+ return -EINVAL;
+ return 0;
+}
+EXPORT_SYMBOL(ethtool_rxfh_indir_can_resize);
+
+/* Resize without validation; caller must have called can_resize first */
+static void __ethtool_rxfh_indir_resize(u32 *tbl, u32 old_size, u32 new_size)
+{
+ u32 i;
+
+ /* Unfold (grow): replicate existing pattern; fold is a no-op on the data */
+ for (i = old_size; i < new_size; i++)
+ tbl[i] = tbl[i % old_size];
+}
+
+/**
+ * ethtool_rxfh_indir_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_indir_resize(u32 *tbl, u32 old_size, u32 new_size)
+{
+ int ret;
+
+ ret = ethtool_rxfh_indir_can_resize(tbl, old_size, new_size);
+ if (ret)
+ return ret;
+
+ __ethtool_rxfh_indir_resize(tbl, old_size, new_size);
+ return 0;
+}
+EXPORT_SYMBOL(ethtool_rxfh_indir_resize);
+
+/**
+ * ethtool_rxfh_contexts_resize_all - 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. Intended to be called from drivers when the
+ * device's indirection table size changes (e.g. on channel count
+ * change). An %ETHTOOL_MSG_RSS_NTF is sent for each resized context.
+ *
+ * All contexts are validated before any are modified, so either all
+ * contexts are resized or none are.
+ *
+ * Return: 0 on success, negative errno on failure.
+ */
+int ethtool_rxfh_contexts_resize_all(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 == 0 ||
+ new_indir_size > dev->ethtool_ops->rxfh_indir_space)
+ return -EINVAL;
+
+ scoped_guard(mutex, &dev->ethtool->rss_lock) {
+ xa_for_each(&dev->ethtool->rss_ctx, context, ctx) {
+ ret = ethtool_rxfh_indir_can_resize(ethtool_rxfh_context_indir(ctx),
+ ctx->indir_size, new_indir_size);
+ if (ret)
+ return ret;
+ }
+
+ xa_for_each(&dev->ethtool->rss_ctx, context, ctx) {
+ __ethtool_rxfh_indir_resize(ethtool_rxfh_context_indir(ctx),
+ ctx->indir_size, new_indir_size);
+ ctx->indir_size = new_indir_size;
+ }
+ }
+
+ xa_for_each(&dev->ethtool->rss_ctx, context, ctx)
+ ethtool_rss_notify(dev, ETHTOOL_MSG_RSS_NTF, context);
+
+ return 0;
+}
+EXPORT_SYMBOL(ethtool_rxfh_contexts_resize_all);
+
enum ethtool_link_medium ethtool_str_to_medium(const char *str)
{
int i;
--
2.53.0
next prev parent reply other threads:[~2026-03-03 18:15 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-03 18:15 [PATCH net-next 0/5] ethtool: Dynamic RSS context indirection table resizing Björn Töpel
2026-03-03 18:15 ` Björn Töpel [this message]
2026-03-04 0:03 ` [PATCH net-next 1/5] ethtool: Add RSS indirection table resize helpers Jakub Kicinski
2026-03-04 11:37 ` Björn Töpel
2026-03-04 17:09 ` Jakub Kicinski
2026-03-03 18:15 ` [PATCH net-next 2/5] bnxt_en: Resize RSS contexts on channel count change Björn Töpel
2026-03-03 19:20 ` Michael Chan
2026-03-04 11:38 ` Björn Töpel
2026-03-04 0:05 ` Jakub Kicinski
2026-03-04 11:39 ` Björn Töpel
2026-03-03 18:15 ` [PATCH net-next 3/5] netdevsim: Add RSS context support with dynamic table sizing Björn Töpel
2026-03-04 0:07 ` Jakub Kicinski
2026-03-04 11:40 ` Björn Töpel
2026-03-03 18:15 ` [PATCH net-next 4/5] selftests: netdevsim: Add RSS indirection table resize test Björn Töpel
2026-03-04 0:07 ` Jakub Kicinski
2026-03-03 18:15 ` [PATCH net-next 5/5] selftests: rss_drv: Add RSS indirection table resize tests Björn Töpel
2026-03-04 0:16 ` Jakub Kicinski
2026-03-04 8:23 ` [PATCH net-next 0/5] ethtool: Dynamic RSS context indirection table resizing Pavan Chebbi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260303181535.2671734-2-bjorn@kernel.org \
--to=bjorn@kernel.org \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=michael.chan@broadcom.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=pavan.chebbi@broadcom.com \
--cc=willemb@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.