Skip to content

Commit b54de55

Browse files
Edward Creekuba-moo
authored andcommitted
net: ethtool: fix off-by-one error in max RSS context IDs
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: 847a8ab ("net: ethtool: let the core choose RSS context IDs") Signed-off-by: Edward Cree <[email protected]> Link: https://patch.msgid.link/5a2d11a599aa5b0cc6141072c01accfb7758650c.1723045898.git.ecree.xilinx@gmail.com Signed-off-by: Jakub Kicinski <[email protected]>
1 parent a70b637 commit b54de55

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5290,7 +5290,7 @@ void bnxt_ethtool_free(struct bnxt *bp)
52905290
const struct ethtool_ops bnxt_ethtool_ops = {
52915291
.cap_link_lanes_supported = 1,
52925292
.cap_rss_ctx_supported = 1,
5293-
.rxfh_max_context_id = BNXT_MAX_ETH_RSS_CTX,
5293+
.rxfh_max_num_contexts = BNXT_MAX_ETH_RSS_CTX + 1,
52945294
.rxfh_indir_space = BNXT_MAX_RSS_TABLE_ENTRIES_P5,
52955295
.rxfh_priv_size = sizeof(struct bnxt_rss_ctx),
52965296
.supported_coalesce_params = ETHTOOL_COALESCE_USECS |

include/linux/ethtool.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -736,10 +736,10 @@ struct kernel_ethtool_ts_info {
736736
* @rxfh_key_space: same as @rxfh_indir_space, but for the key.
737737
* @rxfh_priv_size: size of the driver private data area the core should
738738
* allocate for an RSS context (in &struct ethtool_rxfh_context).
739-
* @rxfh_max_context_id: maximum (exclusive) supported RSS context ID. If this
740-
* is zero then the core may choose any (nonzero) ID, otherwise the core
741-
* will only use IDs strictly less than this value, as the @rss_context
742-
* argument to @create_rxfh_context and friends.
739+
* @rxfh_max_num_contexts: maximum (exclusive) supported RSS context ID.
740+
* If this is zero then the core may choose any (nonzero) ID, otherwise
741+
* the core will only use IDs strictly less than this value, as the
742+
* @rss_context argument to @create_rxfh_context and friends.
743743
* @supported_coalesce_params: supported types of interrupt coalescing.
744744
* @supported_ring_params: supported ring params.
745745
* @get_drvinfo: Report driver/device information. Modern drivers no
@@ -954,7 +954,7 @@ struct ethtool_ops {
954954
u32 rxfh_indir_space;
955955
u16 rxfh_key_space;
956956
u16 rxfh_priv_size;
957-
u32 rxfh_max_context_id;
957+
u32 rxfh_max_num_contexts;
958958
u32 supported_coalesce_params;
959959
u32 supported_ring_params;
960960
void (*get_drvinfo)(struct net_device *, struct ethtool_drvinfo *);

net/ethtool/ioctl.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,12 +1449,13 @@ static noinline_for_stack int ethtool_set_rxfh(struct net_device *dev,
14491449
}
14501450

14511451
if (ops->create_rxfh_context) {
1452-
u32 limit = ops->rxfh_max_context_id ?: U32_MAX;
1452+
u32 limit = ops->rxfh_max_num_contexts ?: U32_MAX;
14531453
u32 ctx_id;
14541454

14551455
/* driver uses new API, core allocates ID */
14561456
ret = xa_alloc(&dev->ethtool->rss_ctx, &ctx_id, ctx,
1457-
XA_LIMIT(1, limit), GFP_KERNEL_ACCOUNT);
1457+
XA_LIMIT(1, limit - 1),
1458+
GFP_KERNEL_ACCOUNT);
14581459
if (ret < 0) {
14591460
kfree(ctx);
14601461
goto out;

0 commit comments

Comments
 (0)