]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
net: ethtool: fix off-by-one error in max RSS context IDs
authorEdward Cree <ecree.xilinx@gmail.com>
Wed, 7 Aug 2024 16:06:12 +0000 (17:06 +0100)
committerJakub Kicinski <kuba@kernel.org>
Thu, 8 Aug 2024 15:54:33 +0000 (08:54 -0700)
Both ethtool_ops.rxfh_max_context_id and the default value used when
 it's not specified are supposed to be exclusive maxima (the former
 is documented as such; the latter, U32_MAX, cannot be used as an ID
 since it equals ETH_RXFH_CONTEXT_ALLOC), but xa_alloc() expects an
 inclusive maximum.
Subtract one from 'limit' to produce an inclusive maximum, and pass
 that to xa_alloc().
Increase bnxt's max by one to prevent a (very minor) regression, as
 BNXT_MAX_ETH_RSS_CTX is an inclusive max.  This is safe since bnxt
 is not actually hard-limited; BNXT_MAX_ETH_RSS_CTX is just a
 leftover from old driver code that managed context IDs itself.
Rename rxfh_max_context_id to rxfh_max_num_contexts to make its
 semantics (hopefully) more obvious.

Fixes: 847a8ab18676 ("net: ethtool: let the core choose RSS context IDs")
Signed-off-by: Edward Cree <ecree.xilinx@gmail.com>
Link: https://patch.msgid.link/5a2d11a599aa5b0cc6141072c01accfb7758650c.1723045898.git.ecree.xilinx@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c
include/linux/ethtool.h
net/ethtool/ioctl.c

index ab8e3f197e7b12f4c7271db879c30a363015fd26..9dadc89378f02ee4ee628bb289366322eaa9d5f8 100644 (file)
@@ -5290,7 +5290,7 @@ void bnxt_ethtool_free(struct bnxt *bp)
 const struct ethtool_ops bnxt_ethtool_ops = {
        .cap_link_lanes_supported       = 1,
        .cap_rss_ctx_supported          = 1,
-       .rxfh_max_context_id            = BNXT_MAX_ETH_RSS_CTX,
+       .rxfh_max_num_contexts          = BNXT_MAX_ETH_RSS_CTX + 1,
        .rxfh_indir_space               = BNXT_MAX_RSS_TABLE_ENTRIES_P5,
        .rxfh_priv_size                 = sizeof(struct bnxt_rss_ctx),
        .supported_coalesce_params = ETHTOOL_COALESCE_USECS |
index 303fda54ef17915e9c682acf01e4b80498ed7838..989c94eddb2b4ffd45c32aa0b440a6a2016f84b2 100644 (file)
@@ -736,10 +736,10 @@ struct kernel_ethtool_ts_info {
  * @rxfh_key_space: same as @rxfh_indir_space, but for the key.
  * @rxfh_priv_size: size of the driver private data area the core should
  *     allocate for an RSS context (in &struct ethtool_rxfh_context).
- * @rxfh_max_context_id: maximum (exclusive) supported RSS context ID.  If this
- *     is zero then the core may choose any (nonzero) ID, otherwise the core
- *     will only use IDs strictly less than this value, as the @rss_context
- *     argument to @create_rxfh_context and friends.
+ * @rxfh_max_num_contexts: maximum (exclusive) supported RSS context ID.
+ *     If this is zero then the core may choose any (nonzero) ID, otherwise
+ *     the core will only use IDs strictly less than this value, as the
+ *     @rss_context argument to @create_rxfh_context and friends.
  * @supported_coalesce_params: supported types of interrupt coalescing.
  * @supported_ring_params: supported ring params.
  * @get_drvinfo: Report driver/device information. Modern drivers no
@@ -954,7 +954,7 @@ struct ethtool_ops {
        u32     rxfh_indir_space;
        u16     rxfh_key_space;
        u16     rxfh_priv_size;
-       u32     rxfh_max_context_id;
+       u32     rxfh_max_num_contexts;
        u32     supported_coalesce_params;
        u32     supported_ring_params;
        void    (*get_drvinfo)(struct net_device *, struct ethtool_drvinfo *);
index 8ca13208d240f297e59edea30b4cde8f0786d0d4..a8e276ecf7233e165bac1fb1a76eab475210586f 100644 (file)
@@ -1449,12 +1449,13 @@ static noinline_for_stack int ethtool_set_rxfh(struct net_device *dev,
                }
 
                if (ops->create_rxfh_context) {
-                       u32 limit = ops->rxfh_max_context_id ?: U32_MAX;
+                       u32 limit = ops->rxfh_max_num_contexts ?: U32_MAX;
                        u32 ctx_id;
 
                        /* driver uses new API, core allocates ID */
                        ret = xa_alloc(&dev->ethtool->rss_ctx, &ctx_id, ctx,
-                                      XA_LIMIT(1, limit), GFP_KERNEL_ACCOUNT);
+                                      XA_LIMIT(1, limit - 1),
+                                      GFP_KERNEL_ACCOUNT);
                        if (ret < 0) {
                                kfree(ctx);
                                goto out;