[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240806160126.551306-1-edward.cree@amd.com>
Date: Tue, 6 Aug 2024 17:01:26 +0100
From: <edward.cree@....com>
To: <davem@...emloft.net>, <kuba@...nel.org>, <edumazet@...gle.com>,
<pabeni@...hat.com>
CC: Edward Cree <ecree.xilinx@...il.com>, <netdev@...r.kernel.org>
Subject: [PATCH net] net: ethtool: fix off-by-one error in max RSS context IDs
From: Edward Cree <ecree.xilinx@...il.com>
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(). Special-case limit==0 to avoid overflow.
Fixes: 6603754cd914 ("net: ethtool: let the core choose RSS context IDs")
Signed-off-by: Edward Cree <ecree.xilinx@...il.com>
---
net/ethtool/ioctl.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c
index 8ca13208d240..de34ea9b9665 100644
--- a/net/ethtool/ioctl.c
+++ b/net/ethtool/ioctl.c
@@ -1453,8 +1453,13 @@ static noinline_for_stack int ethtool_set_rxfh(struct net_device *dev,
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);
+ if (limit)
+ ret = xa_alloc(&dev->ethtool->rss_ctx, &ctx_id,
+ ctx, XA_LIMIT(1, limit - 1),
+ GFP_KERNEL_ACCOUNT);
+ else
+ /* match xa_alloc's 'no free entries' result */
+ ret = -EBUSY;
if (ret < 0) {
kfree(ctx);
goto out;
Powered by blists - more mailing lists