Skip to contentSkip to conversation

ethtool: Fix context creation with no parameters

PATCH In review Gal Pressman 3 participants 3 messages Aug 7, 2024 – Aug 8, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 ethtool: Fix context creation with no parameters

The 'at least one change' requirement is not applicable for context creation, skip the check in such case.
This allows a command such as 'ethtool -X eth0 context new' to work.

The command works by mistake when using older versions of userspace ethtool due to an incompatibility issue where rxfh.input_xfrm is passed as zero (unset) instead of RXH_XFRM_NO_CHANGE as done with recent userspace. This patch does not try to solve the incompatibility issue.

Fixes 84a1d9c48200 ("net: ethtool: extend RXNFC API to support RSS spreading of filter matches")

---
v1->v2: https://lore.kernel.org/netdev/[email protected]/
* Split the check to two, one for validation and one for 'no change'
* Only check for !change in the 'no change' check
* Remove wrong comment

---
 net/ethtool/ioctl.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
net/ethtool/ioctl.c +8 -6
index 8ca13208d240..118d69bc3c76 100644
@@ -1369,15 +1369,17 @@ static noinline_for_stack int ethtool_set_rxfh(struct net_device *dev,
 		return -EOPNOTSUPP;
 	create = rxfh.rss_context == ETH_RXFH_CONTEXT_ALLOC;
 
-	/* If either indir, hash key or function is valid, proceed further.
-	 * Must request at least one change: indir size, hash key, function
-	 * or input transformation.
-	 */
 	if ((rxfh.indir_size &&
 	     rxfh.indir_size != ETH_RXFH_INDIR_NO_CHANGE &&
 	     rxfh.indir_size != dev_indir_size) ||
-	    (rxfh.key_size && (rxfh.key_size != dev_key_size)) ||
-	    (rxfh.indir_size == ETH_RXFH_INDIR_NO_CHANGE &&
+	    (rxfh.key_size && (rxfh.key_size != dev_key_size)))
+		return -EINVAL;
+
+	/* Must request at least one change: indir size, hash key, function
+	 * or input transformation.
+	 * There's no need for any of it in case of context creation.
+	 */
+	if (!create && (rxfh.indir_size == ETH_RXFH_INDIR_NO_CHANGE &&
 	     rxfh.key_size == 0 && rxfh.hfunc == ETH_RSS_HASH_NO_CHANGE &&
 	     rxfh.input_xfrm == RXH_XFRM_NO_CHANGE))
 		return -EINVAL;
Signature · 1 line
2.40.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 9 lines · Gal Pressman

The 'at least one change' requirement is not applicable for context creation, skip the check in such case.
This allows a command such as 'ethtool -X eth0 context new' to work.

The command works by mistake when using older versions of userspace ethtool due to an incompatibility issue where rxfh.input_xfrm is passed as zero (unset) instead of RXH_XFRM_NO_CHANGE as done with recent userspace. This patch does not try to solve the incompatibility issue.

Quoted 5 lines
Fixes 84a1d9c48200 ("net: ethtool: extend RXNFC API to support RSS spreading of filter matches")
maintainer
#2 lore raw
In reply to Gal Pressman

I'll make some minor modifications when applying..

net/ethtool/ioctl.c static noinline_for_stack int ethtool_set_rxfh(struct net_device *dev, · line 1375

Quoted 6 lines · On Wed, 7 Aug 2024 20:33:52 +0300 Gal Pressman wrote:
net/ethtool/ioctl.c +1 -2
 	if ((rxfh.indir_size &&
 	     rxfh.indir_size != ETH_RXFH_INDIR_NO_CHANGE &&
 	     rxfh.indir_size != dev_indir_size) ||
-	    (rxfh.key_size && (rxfh.key_size != dev_key_size)) ||
-	    (rxfh.indir_size == ETH_RXFH_INDIR_NO_CHANGE &&
+	    (rxfh.key_size && (rxfh.key_size != dev_key_size)))

We should take this opportunity to remove the pointless brackets around key size comparison. Same clause for indir is not bracketed.

net/ethtool/ioctl.c static noinline_for_stack int ethtool_set_rxfh(struct net_device *dev, · line 1383

Quoted 8 lines
net/ethtool/ioctl.c +7 -0
+		return -EINVAL;
+
+	/* Must request at least one change: indir size, hash key, function
+	 * or input transformation.
+	 * There's no need for any of it in case of context creation.
+	 */
+	if (!create && (rxfh.indir_size == ETH_RXFH_INDIR_NO_CHANGE &&
 	     rxfh.key_size == 0 && rxfh.hfunc == ETH_RSS_HASH_NO_CHANGE &&

And here if (!create should probably be on a line of its own. Otherwise continuation lines don't align with the opening bracket.