]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
net/mlx5e: resize configured default RSS context table on channel change
authorYael Chemla <ychemla@nvidia.com>
Mon, 11 May 2026 17:27:18 +0000 (20:27 +0300)
committerJakub Kicinski <kuba@kernel.org>
Thu, 14 May 2026 02:10:24 +0000 (19:10 -0700)
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 <ychemla@nvidia.com>
Reviewed-by: Nimrod Oren <noren@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
Link: https://patch.msgid.link/20260511172719.330490-5-tariqt@nvidia.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/mellanox/mlx5/core/en/rss.c
drivers/net/ethernet/mellanox/mlx5/core/en/rss.h
drivers/net/ethernet/mellanox/mlx5/core/en/rx_res.c
drivers/net/ethernet/mellanox/mlx5/core/en/rx_res.h
drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c
drivers/net/ethernet/mellanox/mlx5/core/en_main.c

index 992a78580a40fee4ab174bc2af35a2b40c0bda3c..de435df7ca50ba5debb0a29a324d407129b4ea6b 100644 (file)
@@ -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)
 {
index e48070e0297916b72ff010e001a5a2ac56f4d620..1bb0434612a41c8f996bf5665b0bbdc788440b0d 100644 (file)
@@ -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);
index d81a91eb7664e6d8229afb4f10d4bd6cf357fa4f..e940635f5dcbce57c3cef3a181507bcab64cfefa 100644 (file)
@@ -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)
 {
index 675780120a20d8104859831bda774edba628d582..8fff18d649787326de51d0c6d9c112cf0e76b749 100644 (file)
@@ -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);
index 4462cf29e97719b276c712caa48fd4245290e5ef..300d1cb2e0703abaf2c98b1eeb794591ecd0774f 100644 (file)
@@ -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,
index 85b1ccbd351fb8145be3e74b9f0e4fa51b2d6a65..a904e468c1977acdb56a2f2437ad85c06b070647 100644 (file)
@@ -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;
 }