[PATCH net-next 4/5] net/mlx5e: resize configured default RSS context table on channel change
From: Tariq Toukan <tariqt@nvidia.com>
Date: 2026-05-11 17:28:31
Also in:
linux-rdma, lkml
Subsystem:
mellanox ethernet driver (mlx5e), mellanox mlx5 core vpi driver, networking drivers, the rest · Maintainers:
Saeed Mahameed, Tariq Toukan, Mark Bloch, Leon Romanovsky, Andrew Lunn, "David S. Miller", Eric Dumazet, Jakub Kicinski, Paolo Abeni, Linus Torvalds
From: Yael Chemla <redacted>
mlx5e_ethtool_set_channels() rejected channel count changes that
required a different RQT size when the default context indirection
table was user-configured. This restriction was introduced by
commit ee3572409f74 ("net/mlx5e: RSS, Block changing channels number
when RXFH is configured").
Lift the restriction. Validate the resize upfront with
ethtool_rxfh_indir_can_resize(), then fold or unfold the table
in-place via ethtool_rxfh_indir_resize() inside state_lock, before
mlx5e_safe_switch_params(), so the preactivate callback sees the
correct table content when it programs the HW.
Signed-off-by: Yael Chemla <redacted>
Reviewed-by: Nimrod Oren <redacted>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
.../net/ethernet/mellanox/mlx5/core/en/rss.c | 13 +++++++++
.../net/ethernet/mellanox/mlx5/core/en/rss.h | 3 +++
.../ethernet/mellanox/mlx5/core/en/rx_res.c | 27 ++++++++++++-------
.../ethernet/mellanox/mlx5/core/en/rx_res.h | 4 +--
.../ethernet/mellanox/mlx5/core/en_ethtool.c | 22 +++++++--------
.../net/ethernet/mellanox/mlx5/core/en_main.c | 9 +++----
6 files changed, 49 insertions(+), 29 deletions(-)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/rss.c b/drivers/net/ethernet/mellanox/mlx5/core/en/rss.c
index 992a78580a40..de435df7ca50 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en/rss.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en/rss.c@@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB // Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. +#include <linux/ethtool.h> #include "rss.h" #define mlx5e_rss_warn(__dev, format, ...) \
@@ -85,6 +86,11 @@ bool mlx5e_rss_get_inner_ft_support(struct mlx5e_rss *rss) return rss->params.inner_ft_support; } +u32 *mlx5e_rss_get_indir_table(struct mlx5e_rss *rss) +{ + return rss->indir.table; +} + void mlx5e_rss_set_indir_actual_size(struct mlx5e_rss *rss, u32 size) { rss->indir.actual_table_size = size;
@@ -102,6 +108,13 @@ void mlx5e_rss_ctx_resize(struct mlx5e_rss *rss, u32 new_size) rss->indir.table[i] = rss->indir.table[i % old_size]; } +void mlx5e_rss_indir_resize(struct mlx5e_rss *rss, struct net_device *netdev, + u32 new_size) +{ + ethtool_rxfh_indir_resize(netdev, rss->indir.table, + rss->indir.actual_table_size, new_size); +} + int mlx5e_rss_params_indir_init(struct mlx5e_rss_params_indir *indir, u32 actual_table_size, u32 max_table_size) {
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/rss.h b/drivers/net/ethernet/mellanox/mlx5/core/en/rss.h
index e48070e02979..1bb0434612a4 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en/rss.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en/rss.h@@ -35,6 +35,8 @@ int mlx5e_rss_params_indir_init(struct mlx5e_rss_params_indir *indir, u32 actual_table_size, u32 max_table_size); void mlx5e_rss_params_indir_cleanup(struct mlx5e_rss_params_indir *indir); void mlx5e_rss_ctx_resize(struct mlx5e_rss *rss, u32 new_size); +void mlx5e_rss_indir_resize(struct mlx5e_rss *rss, struct net_device *netdev, + u32 new_size); struct mlx5e_rss * mlx5e_rss_init(struct mlx5_core_dev *mdev, const struct mlx5e_rss_params *params,
@@ -46,6 +48,7 @@ void mlx5e_rss_refcnt_dec(struct mlx5e_rss *rss); unsigned int mlx5e_rss_refcnt_read(struct mlx5e_rss *rss); bool mlx5e_rss_get_inner_ft_support(struct mlx5e_rss *rss); +u32 *mlx5e_rss_get_indir_table(struct mlx5e_rss *rss); void mlx5e_rss_set_indir_actual_size(struct mlx5e_rss *rss, u32 size); u32 mlx5e_rss_get_tirn(struct mlx5e_rss *rss, enum mlx5_traffic_types tt, bool inner);
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/rx_res.c b/drivers/net/ethernet/mellanox/mlx5/core/en/rx_res.c
index d81a91eb7664..e940635f5dcb 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en/rx_res.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en/rx_res.c@@ -40,15 +40,31 @@ static u32 *get_vhca_ids(struct mlx5e_rx_res *res, int offset) return multi_vhca ? res->rss_vhca_ids + offset : NULL; } -void mlx5e_rx_res_rss_update_num_channels(struct mlx5e_rx_res *res, u32 nch) +/* Updates the indirection table SW shadow, does not update the HW resources yet + */ +void mlx5e_rx_res_rss_update_num_channels(struct mlx5e_rx_res *res, u32 nch, + struct net_device *netdev) { u32 new_size = mlx5e_rqt_size(res->mdev, nch); int i; WARN_ON_ONCE(res->rss_active); - /* Default context */ + /* Default context: fold/unfold user-configured table, then update size + * and reset to uniform when unconfigured. + */ + mlx5e_rss_indir_resize(res->rss[0], netdev, new_size); + + /* mlx5e_rss_indir_resize() is a no-op when the table is not + * user-configured. actual_table_size is updated after the resize + * because ethtool_rxfh_indir_resize() uses it as the old size to + * replicate the pattern; updating it first would make the grow a no-op. + * It must be updated before mlx5e_rss_set_indir_uniform() so that + * the uniform fill covers all new entries, not just the old ones. + */ mlx5e_rss_set_indir_actual_size(res->rss[0], new_size); + if (!netif_is_rxfh_configured(netdev)) + mlx5e_rss_set_indir_uniform(res->rss[0], nch); /* Non-default contexts */ for (i = 1; i < MLX5E_MAX_NUM_RSS; i++) {
@@ -218,13 +234,6 @@ static void mlx5e_rx_res_rss_disable(struct mlx5e_rx_res *res) } } -/* Updates the indirection table SW shadow, does not update the HW resources yet */ -void mlx5e_rx_res_rss_set_indir_uniform(struct mlx5e_rx_res *res, unsigned int nch) -{ - WARN_ON_ONCE(res->rss_active); - mlx5e_rss_set_indir_uniform(res->rss[0], nch); -} - void mlx5e_rx_res_rss_get_rxfh(struct mlx5e_rx_res *res, u32 rss_idx, u32 *indir, u8 *key, u8 *hfunc, bool *symmetric) {
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/rx_res.h b/drivers/net/ethernet/mellanox/mlx5/core/en/rx_res.h
index 675780120a20..8fff18d64978 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en/rx_res.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en/rx_res.h@@ -48,7 +48,6 @@ void mlx5e_rx_res_xsk_update(struct mlx5e_rx_res *res, struct mlx5e_channels *ch unsigned int ix, bool xsk); /* Configuration API */ -void mlx5e_rx_res_rss_set_indir_uniform(struct mlx5e_rx_res *res, unsigned int nch); void mlx5e_rx_res_rss_get_rxfh(struct mlx5e_rx_res *res, u32 rss_idx, u32 *indir, u8 *key, u8 *hfunc, bool *symmetric);
@@ -68,7 +67,8 @@ int mlx5e_rx_res_rss_destroy(struct mlx5e_rx_res *res, u32 rss_idx); int mlx5e_rx_res_rss_cnt(struct mlx5e_rx_res *res); int mlx5e_rx_res_rss_index(struct mlx5e_rx_res *res, struct mlx5e_rss *rss); struct mlx5e_rss *mlx5e_rx_res_rss_get(struct mlx5e_rx_res *res, u32 rss_idx); -void mlx5e_rx_res_rss_update_num_channels(struct mlx5e_rx_res *res, u32 nch); +void mlx5e_rx_res_rss_update_num_channels(struct mlx5e_rx_res *res, u32 nch, + struct net_device *netdev); /* Workaround for hairpin */ struct mlx5e_rss_params_hash mlx5e_rx_res_get_current_hash(struct mlx5e_rx_res *res);
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c b/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c
index 4462cf29e977..300d1cb2e070 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c@@ -501,6 +501,7 @@ int mlx5e_ethtool_set_channels(struct mlx5e_priv *priv, unsigned int count = ch->combined_count; int new_rqt_size, cur_rqt_size; struct mlx5e_params new_params; + struct mlx5e_rss *rss0; bool arfs_enabled; bool has_rss_ctxs; bool opened;
@@ -538,19 +539,16 @@ int mlx5e_ethtool_set_channels(struct mlx5e_priv *priv, } cur_rqt_size = mlx5e_rqt_size(priv->mdev, cur_params->num_channels); + rss0 = mlx5e_rx_res_rss_get(priv->rx_res, 0); - /* If RXFH is configured, changing the channels number is allowed only if - * it does not require resizing the RSS table. This is because the previous - * configuration may no longer be compatible with the new RSS table. - */ - if (netif_is_rxfh_configured(priv->netdev)) { - if (new_rqt_size != cur_rqt_size) { - err = -EINVAL; - netdev_err(priv->netdev, - "%s: RXFH is configured, block changing channels number that affects RSS table size (new: %d, current: %d)\n", - __func__, new_rqt_size, cur_rqt_size); - goto out; - } + if (!ethtool_rxfh_indir_can_resize(priv->netdev, + mlx5e_rss_get_indir_table(rss0), + cur_rqt_size, new_rqt_size)) { + netdev_err(priv->netdev, + "%s: cannot resize RSS table (%u -> %u); reset indirection table to allow this change\n", + __func__, cur_rqt_size, new_rqt_size); + err = -EINVAL; + goto out; } /* Don't allow changing the number of channels if HTB offload is active,
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
index 85b1ccbd351f..a904e468c197 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c@@ -3296,12 +3296,9 @@ static int mlx5e_num_channels_changed(struct mlx5e_priv *priv) } /* This function may be called on attach, before priv->rx_res is created. */ - if (priv->rx_res) { - mlx5e_rx_res_rss_update_num_channels(priv->rx_res, count); - - if (!netif_is_rxfh_configured(priv->netdev)) - mlx5e_rx_res_rss_set_indir_uniform(priv->rx_res, count); - } + if (priv->rx_res) + mlx5e_rx_res_rss_update_num_channels(priv->rx_res, count, + netdev); return 0; }
--
2.44.0