diff mbox series

[net-next,2/2] net: ethtool: add a NO_CHANGE uAPI for new RXFH's input_xfrm

Message ID 20231221184235.9192-3-ahmed.zaki@intel.com (mailing list archive)
State Accepted
Commit 0dd415d155050f5c1cf360b97f905d42d44f33ed
Delegated to: Netdev Maintainers
Headers show
Series Bug fixes for RSS symmetric-xor | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 2925 this patch: 2925
netdev/cc_maintainers fail 1 blamed authors not CCed: wojciech.drewek@intel.com; 2 maintainers not CCed: keescook@chromium.org wojciech.drewek@intel.com
netdev/build_clang fail Errors and warnings before: 138 this patch: 138
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 3133 this patch: 3133
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 25 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Ahmed Zaki Dec. 21, 2023, 6:42 p.m. UTC
Add a NO_CHANGE uAPI value for the new RXFH/RSS input_xfrm uAPI field.
This needed so that user-space can set other RSS values (hkey or indir
table) without affecting input_xfrm.

Should have been part of [1].

Link: https://lore.kernel.org/netdev/20231213003321.605376-1-ahmed.zaki@intel.com/ [1]
Fixes: 13e59344fb9d ("net: ethtool: add support for symmetric-xor RSS hash")
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
Signed-off-by: Ahmed Zaki <ahmed.zaki@intel.com>
---
 include/uapi/linux/ethtool.h | 1 +
 net/ethtool/ioctl.c          | 6 ++++--
 2 files changed, 5 insertions(+), 2 deletions(-)

Comments

Jakub Kicinski Jan. 3, 2024, 12:05 a.m. UTC | #1
On Thu, 21 Dec 2023 11:42:35 -0700 Ahmed Zaki wrote:
> +	     rxfh.key_size == 0 && rxfh.hfunc == ETH_RSS_HASH_NO_CHANGE &&
> +	     rxfh.input_xfrm == RXH_XFRM_NO_CHANGE))

This looks fine, but we also need a check to make sure input_xfrm
doesn't have bits other than RXH_XFRM_SYM_XOR set, right?
Ahmed Zaki Jan. 3, 2024, 3:40 p.m. UTC | #2
On 2024-01-02 17:05, Jakub Kicinski wrote:
> On Thu, 21 Dec 2023 11:42:35 -0700 Ahmed Zaki wrote:
>> +	     rxfh.key_size == 0 && rxfh.hfunc == ETH_RSS_HASH_NO_CHANGE &&
>> +	     rxfh.input_xfrm == RXH_XFRM_NO_CHANGE))
> 
> This looks fine, but we also need a check to make sure input_xfrm
> doesn't have bits other than RXH_XFRM_SYM_XOR set, right?

I wrote the xfrm as a  bitmap/flags assuming we can have multiple 
transformations set. Not sure what future transformations will look like 
(other than RSS-sort,... and discussed before).

Else, we can do the check you mentioned or may be better to have it as 
enum (which would give us 256, not 8, allowable transformations).
Jakub Kicinski Jan. 3, 2024, 10:16 p.m. UTC | #3
On Wed, 3 Jan 2024 08:40:47 -0700 Ahmed Zaki wrote:
> On 2024-01-02 17:05, Jakub Kicinski wrote:
> > On Thu, 21 Dec 2023 11:42:35 -0700 Ahmed Zaki wrote:  
> >> +	     rxfh.key_size == 0 && rxfh.hfunc == ETH_RSS_HASH_NO_CHANGE &&
> >> +	     rxfh.input_xfrm == RXH_XFRM_NO_CHANGE))  
> > 
> > This looks fine, but we also need a check to make sure input_xfrm
> > doesn't have bits other than RXH_XFRM_SYM_XOR set, right?  
> 
> I wrote the xfrm as a  bitmap/flags assuming we can have multiple 
> transformations set. Not sure what future transformations will look like 
> (other than RSS-sort,... and discussed before).

Ack, but right now the only valid inputs for the kernel are
0 (disable all), RXH_XFRM_NO_CHANGE and RXH_XFRM_SYM_XOR.
We need to reject all other inputs. If we accept random
inputs without validation we won't be able to use them later.
Refer to many LWN articles about how some syscall didn't check
that unused flags are 0 and now they can't allocate bits.
Because some user space was passing in garbage.

> Else, we can do the check you mentioned or may be better to have it as 
> enum (which would give us 256, not 8, allowable transformations).

Given that RXH_XFRM_SYM_XOR is 1 we can change the exact semantics
later. All that matters is that we reject unsupported for now.
diff mbox series

Patch

diff --git a/include/uapi/linux/ethtool.h b/include/uapi/linux/ethtool.h
index 0787d561ace0..361c96653632 100644
--- a/include/uapi/linux/ethtool.h
+++ b/include/uapi/linux/ethtool.h
@@ -2002,6 +2002,7 @@  static inline int ethtool_validate_duplex(__u8 duplex)
  * be exploited to reduce the RSS queue spread.
  */
 #define	RXH_XFRM_SYM_XOR	(1 << 0)
+#define	RXH_XFRM_NO_CHANGE	0xff
 
 /* L2-L4 network traffic flow types */
 #define	TCP_V4_FLOW	0x01	/* hash or spec (tcp_ip4_spec) */
diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c
index 9adc240b8f0e..4c4f46dfc251 100644
--- a/net/ethtool/ioctl.c
+++ b/net/ethtool/ioctl.c
@@ -1304,14 +1304,16 @@  static noinline_for_stack int ethtool_set_rxfh(struct net_device *dev,
 		return -EOPNOTSUPP;
 
 	/* If either indir, hash key or function is valid, proceed further.
-	 * Must request at least one change: indir size, hash key or function.
+	 * 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 == 0 && rxfh.hfunc == ETH_RSS_HASH_NO_CHANGE))
+	     rxfh.key_size == 0 && rxfh.hfunc == ETH_RSS_HASH_NO_CHANGE &&
+	     rxfh.input_xfrm == RXH_XFRM_NO_CHANGE))
 		return -EINVAL;
 
 	if (rxfh.indir_size != ETH_RXFH_INDIR_NO_CHANGE)