netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] net: ethtool: fix off-by-one error in max RSS context IDs
@ 2024-08-06 16:01 edward.cree
  2024-08-06 16:07 ` Edward Cree
  2024-08-06 16:54 ` Jakub Kicinski
  0 siblings, 2 replies; 5+ messages in thread
From: edward.cree @ 2024-08-06 16:01 UTC (permalink / raw)
  To: davem, kuba, edumazet, pabeni; +Cc: Edward Cree, netdev

From: Edward Cree <ecree.xilinx@gmail.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@gmail.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;

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-08-07 14:07 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-06 16:01 [PATCH net] net: ethtool: fix off-by-one error in max RSS context IDs edward.cree
2024-08-06 16:07 ` Edward Cree
2024-08-06 16:54 ` Jakub Kicinski
2024-08-07 10:30   ` Edward Cree
2024-08-07 14:07     ` Jakub Kicinski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).