Skip to contentSkip to conversation

net/mlx5e: Fix ethtool -N flow-type ip4 to RSS context

PATCH Applied Maxim Mikityanskiy 6 participants 12 messages Mar 19, 2025 – Mar 24, 2025

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

PATCH 1/1 net/mlx5e: Fix ethtool -N flow-type ip4 to RSS context

There commands can be used to add an RSS context and steer some traffic into it:

    # ethtool -X eth0 context new
    New RSS context is 1
    # ethtool -N eth0 flow-type ip4 dst-ip 1.1.1.1 context 1
    Added rule with ID 1023

However, the second command fails with EINVAL on mlx5e:

    # ethtool -N eth0 flow-type ip4 dst-ip 1.1.1.1 context 1
    rmgr: Cannot insert RX class rule: Invalid argument
    Cannot insert classification rule

It happens when flow_get_tirn calls flow_type_to_traffic_type with flow_type = IP_USER_FLOW or IPV6_USER_FLOW. That function only handles IPV4_FLOW and IPV6_FLOW cases, but unlike all other cases which are common for hash and spec, IPv4 and IPv6 defines different contants for hash and for spec:

    #define	TCP_V4_FLOW	0x01	/* hash or spec (tcp_ip4_spec) */
    #define	UDP_V4_FLOW	0x02	/* hash or spec (udp_ip4_spec) */
    ...
    #define	IPV4_USER_FLOW	0x0d	/* spec only (usr_ip4_spec) */
    #define	IP_USER_FLOW	IPV4_USER_FLOW
    #define	IPV6_USER_FLOW	0x0e	/* spec only (usr_ip6_spec; nfc only) */
    #define	IPV4_FLOW	0x10	/* hash only */
    #define	IPV6_FLOW	0x11	/* hash only */

Extend the switch in flow_type_to_traffic_type to support both, which fixes the failing ethtool -N command with flow-type ip4 or ip6.

Fixes 248d3b4c9a39 ("net/mlx5e: Support flow classification into RSS contexts")
---
 drivers/net/ethernet/mellanox/mlx5/core/en_fs_ethtool.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/en_fs_ethtool.c +2 -0
index 773624bb2c5d..d68230a7b9f4 100644
@@ -884,8 +884,10 @@ static int flow_type_to_traffic_type(u32 flow_type)
 	case ESP_V6_FLOW:
 		return MLX5_TT_IPV6_IPSEC_ESP;
 	case IPV4_FLOW:
+	case IP_USER_FLOW:
 		return MLX5_TT_IPV4;
 	case IPV6_FLOW:
+	case IPV6_USER_FLOW:
 		return MLX5_TT_IPV6;
 	default:
 		return -EINVAL;
Signature · 1 line
2.48.1
Tested-by on v1 1/1
#1 lore raw
Quoted 29 lines · Maxim Mikityanskiy

There commands can be used to add an RSS context and steer some traffic into it:

     # ethtool -X eth0 context new
     New RSS context is 1
     # ethtool -N eth0 flow-type ip4 dst-ip 1.1.1.1 context 1
     Added rule with ID 1023

However, the second command fails with EINVAL on mlx5e:

     # ethtool -N eth0 flow-type ip4 dst-ip 1.1.1.1 context 1
     rmgr: Cannot insert RX class rule: Invalid argument
     Cannot insert classification rule

It happens when flow_get_tirn calls flow_type_to_traffic_type with flow_type = IP_USER_FLOW or IPV6_USER_FLOW. That function only handles IPV4_FLOW and IPV6_FLOW cases, but unlike all other cases which are common for hash and spec, IPv4 and IPv6 defines different contants for hash and for spec:

     #define	TCP_V4_FLOW	0x01	/* hash or spec (tcp_ip4_spec) */
     #define	UDP_V4_FLOW	0x02	/* hash or spec (udp_ip4_spec) */
     ...
     #define	IPV4_USER_FLOW	0x0d	/* spec only (usr_ip4_spec) */
     #define	IP_USER_FLOW	IPV4_USER_FLOW
     #define	IPV6_USER_FLOW	0x0e	/* spec only (usr_ip6_spec; nfc only) */
     #define	IPV4_FLOW	0x10	/* hash only */
     #define	IPV6_FLOW	0x11	/* hash only */
Quoted 5 lines

Extend the switch in flow_type_to_traffic_type to support both, which fixes the failing ethtool -N command with flow-type ip4 or ip6.

Fixes 248d3b4c9a39 ("net/mlx5e: Support flow classification into RSS contexts")

Awesome, thanks Max!

Reviewed-by on v1 1/1
#2 lore raw
In reply to Maxim Mikityanskiy
Quoted 43 lines · Maxim Mikityanskiy

There commands can be used to add an RSS context and steer some traffic into it:

    # ethtool -X eth0 context new
    New RSS context is 1
    # ethtool -N eth0 flow-type ip4 dst-ip 1.1.1.1 context 1
    Added rule with ID 1023

However, the second command fails with EINVAL on mlx5e:

    # ethtool -N eth0 flow-type ip4 dst-ip 1.1.1.1 context 1
    rmgr: Cannot insert RX class rule: Invalid argument
    Cannot insert classification rule

It happens when flow_get_tirn calls flow_type_to_traffic_type with flow_type = IP_USER_FLOW or IPV6_USER_FLOW. That function only handles IPV4_FLOW and IPV6_FLOW cases, but unlike all other cases which are common for hash and spec, IPv4 and IPv6 defines different contants for hash and for spec:

    #define	TCP_V4_FLOW	0x01	/* hash or spec (tcp_ip4_spec) */
    #define	UDP_V4_FLOW	0x02	/* hash or spec (udp_ip4_spec) */
    ...
    #define	IPV4_USER_FLOW	0x0d	/* spec only (usr_ip4_spec) */
    #define	IP_USER_FLOW	IPV4_USER_FLOW
    #define	IPV6_USER_FLOW	0x0e	/* spec only (usr_ip6_spec; nfc only) */
    #define	IPV4_FLOW	0x10	/* hash only */
    #define	IPV6_FLOW	0x11	/* hash only */

Extend the switch in flow_type_to_traffic_type to support both, which fixes the failing ethtool -N command with flow-type ip4 or ip6.

Fixes 248d3b4c9a39 ("net/mlx5e: Support flow classification into RSS contexts")
---
 drivers/net/ethernet/mellanox/mlx5/core/en_fs_ethtool.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/en_fs_ethtool.c +0 -0
index 773624bb2c5d..d68230a7b9f4 100644

drivers/net/ethernet/mellanox/mlx5/core/en_fs_ethtool.c static int flow_type_to_traffic_type(u32 flow_type) · line 893

Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/core/en_fs_ethtool.c +2 -0
@@ -884,8 +884,10 @@ static int flow_type_to_traffic_type(u32 flow_type)
 	case ESP_V6_FLOW:
 		return MLX5_TT_IPV6_IPSEC_ESP;
 	case IPV4_FLOW:
+	case IP_USER_FLOW:
 		return MLX5_TT_IPV4;
 	case IPV6_FLOW:
+	case IPV6_USER_FLOW:
 		return MLX5_TT_IPV6;
 	default:
 		return -EINVAL;

Good catch.

#3 lore raw
In reply to Maxim Mikityanskiy
Quoted 29 lines · Maxim Mikityanskiy

There commands can be used to add an RSS context and steer some traffic into it:

     # ethtool -X eth0 context new
     New RSS context is 1
     # ethtool -N eth0 flow-type ip4 dst-ip 1.1.1.1 context 1
     Added rule with ID 1023

However, the second command fails with EINVAL on mlx5e:

     # ethtool -N eth0 flow-type ip4 dst-ip 1.1.1.1 context 1
     rmgr: Cannot insert RX class rule: Invalid argument
     Cannot insert classification rule

It happens when flow_get_tirn calls flow_type_to_traffic_type with flow_type = IP_USER_FLOW or IPV6_USER_FLOW. That function only handles IPV4_FLOW and IPV6_FLOW cases, but unlike all other cases which are common for hash and spec, IPv4 and IPv6 defines different contants for hash and for spec:

     #define	TCP_V4_FLOW	0x01	/* hash or spec (tcp_ip4_spec) */
     #define	UDP_V4_FLOW	0x02	/* hash or spec (udp_ip4_spec) */
     ...
     #define	IPV4_USER_FLOW	0x0d	/* spec only (usr_ip4_spec) */
     #define	IP_USER_FLOW	IPV4_USER_FLOW
     #define	IPV6_USER_FLOW	0x0e	/* spec only (usr_ip6_spec; nfc only) */
     #define	IPV4_FLOW	0x10	/* hash only */
     #define	IPV6_FLOW	0x11	/* hash only */
Quoted 3 lines

Extend the switch in flow_type_to_traffic_type to support both, which fixes the failing ethtool -N command with flow-type ip4 or ip6.

Hi Maxim,
Thanks for your patch!

Quoted 1 line
Fixes 248d3b4c9a39 ("net/mlx5e: Support flow classification into RSS contexts")

Seems that the issue originates in commit 756c41603a18 ("net/mlx5e: ethtool, Support user configuration for RX hash fields"), when directly classifying into an RQ, before the multi RSS context support.

Quoted 20 lines
---
  drivers/net/ethernet/mellanox/mlx5/core/en_fs_ethtool.c | 2 ++
  1 file changed, 2 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/en_fs_ethtool.c +2 -0
index 773624bb2c5d..d68230a7b9f4 100644
@@ -884,8 +884,10 @@ static int flow_type_to_traffic_type(u32 flow_type)
  	case ESP_V6_FLOW:
  		return MLX5_TT_IPV6_IPSEC_ESP;
  	case IPV4_FLOW:
+	case IP_USER_FLOW:
  		return MLX5_TT_IPV4;
  	case IPV6_FLOW:
+	case IPV6_USER_FLOW:
  		return MLX5_TT_IPV6;
  	default:
  		return -EINVAL;
#4 lore raw
Quoted 37 lines · Tariq Toukan
Quoted 29 lines · Maxim Mikityanskiy

There commands can be used to add an RSS context and steer some traffic into it:

     # ethtool -X eth0 context new
     New RSS context is 1
     # ethtool -N eth0 flow-type ip4 dst-ip 1.1.1.1 context 1
     Added rule with ID 1023

However, the second command fails with EINVAL on mlx5e:

     # ethtool -N eth0 flow-type ip4 dst-ip 1.1.1.1 context 1
     rmgr: Cannot insert RX class rule: Invalid argument
     Cannot insert classification rule

It happens when flow_get_tirn calls flow_type_to_traffic_type with flow_type = IP_USER_FLOW or IPV6_USER_FLOW. That function only handles IPV4_FLOW and IPV6_FLOW cases, but unlike all other cases which are common for hash and spec, IPv4 and IPv6 defines different contants for hash and for spec:

     #define  TCP_V4_FLOW     0x01    /* hash or spec (tcp_ip4_spec) */
     #define  UDP_V4_FLOW     0x02    /* hash or spec (udp_ip4_spec) */
     ...
     #define  IPV4_USER_FLOW  0x0d    /* spec only (usr_ip4_spec) */
     #define  IP_USER_FLOW    IPV4_USER_FLOW
     #define  IPV6_USER_FLOW  0x0e    /* spec only (usr_ip6_spec; nfc only) */
     #define  IPV4_FLOW       0x10    /* hash only */
     #define  IPV6_FLOW       0x11    /* hash only */
Quoted 3 lines

Extend the switch in flow_type_to_traffic_type to support both, which fixes the failing ethtool -N command with flow-type ip4 or ip6.

Quoted 7 lines

Hi Maxim,
Thanks for your patch!

Quoted 1 line
Fixes 248d3b4c9a39 ("net/mlx5e: Support flow classification into RSS contexts")

Seems that the issue originates in commit 756c41603a18 ("net/mlx5e:
ethtool, Support user configuration for RX hash fields"),

Not really; commit 756c41603a18 configures the hash (not flow direction), and IPV4_FLOW/IPV6_FLOW are already correct constants for IP-based hashes. Moreover, we don't support them anyway, see mlx5e_set_rss_hash_opt:

    /*  RSS does not support anything other than hashing to queues
     *  on src IP, dest IP, TCP/UDP src port and TCP/UDP dest
     *  port.
     */
    if (flow_type != TCP_V4_FLOW &&
        flow_type != TCP_V6_FLOW &&
        flow_type != UDP_V4_FLOW &&
        flow_type != UDP_V6_FLOW)
        return -EOPNOTSUPP;
Quoted 2 lines

when directly
classifying into an RQ, before the multi RSS context support.

Direct classification into an RQ actually works before my fix, because it goes to another branch in flow_get_tirn, that doesn't call flow_type_to_traffic_type. It's only steering to an RSS context that was broken for flow-type ip4/ip6.

Quoted 21 lines
Quoted 20 lines
---
  drivers/net/ethernet/mellanox/mlx5/core/en_fs_ethtool.c | 2 ++
  1 file changed, 2 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/en_fs_ethtool.c +2 -0
index 773624bb2c5d..d68230a7b9f4 100644
@@ -884,8 +884,10 @@ static int flow_type_to_traffic_type(u32 flow_type)
      case ESP_V6_FLOW:
              return MLX5_TT_IPV6_IPSEC_ESP;
      case IPV4_FLOW:
+     case IP_USER_FLOW:
              return MLX5_TT_IPV4;
      case IPV6_FLOW:
+     case IPV6_USER_FLOW:
              return MLX5_TT_IPV6;
      default:
              return -EINVAL;
Reviewed-by
#5 lore raw
Quoted 61 lines · Maxim Mikityanskiy
Quoted 37 lines · Tariq Toukan
Quoted 29 lines · Maxim Mikityanskiy

There commands can be used to add an RSS context and steer some traffic into it:

      # ethtool -X eth0 context new
      New RSS context is 1
      # ethtool -N eth0 flow-type ip4 dst-ip 1.1.1.1 context 1
      Added rule with ID 1023

However, the second command fails with EINVAL on mlx5e:

      # ethtool -N eth0 flow-type ip4 dst-ip 1.1.1.1 context 1
      rmgr: Cannot insert RX class rule: Invalid argument
      Cannot insert classification rule

It happens when flow_get_tirn calls flow_type_to_traffic_type with flow_type = IP_USER_FLOW or IPV6_USER_FLOW. That function only handles IPV4_FLOW and IPV6_FLOW cases, but unlike all other cases which are common for hash and spec, IPv4 and IPv6 defines different contants for hash and for spec:

      #define  TCP_V4_FLOW     0x01    /* hash or spec (tcp_ip4_spec) */
      #define  UDP_V4_FLOW     0x02    /* hash or spec (udp_ip4_spec) */
      ...
      #define  IPV4_USER_FLOW  0x0d    /* spec only (usr_ip4_spec) */
      #define  IP_USER_FLOW    IPV4_USER_FLOW
      #define  IPV6_USER_FLOW  0x0e    /* spec only (usr_ip6_spec; nfc only) */
      #define  IPV4_FLOW       0x10    /* hash only */
      #define  IPV6_FLOW       0x11    /* hash only */
Quoted 3 lines

Extend the switch in flow_type_to_traffic_type to support both, which fixes the failing ethtool -N command with flow-type ip4 or ip6.

Quoted 7 lines

Hi Maxim,
Thanks for your patch!

Quoted 1 line
Fixes 248d3b4c9a39 ("net/mlx5e: Support flow classification into RSS contexts")

Seems that the issue originates in commit 756c41603a18 ("net/mlx5e:
ethtool, Support user configuration for RX hash fields"),

Not really; commit 756c41603a18 configures the hash (not flow direction), and IPV4_FLOW/IPV6_FLOW are already correct constants for IP-based hashes. Moreover, we don't support them anyway, see mlx5e_set_rss_hash_opt:

     /*  RSS does not support anything other than hashing to queues
      *  on src IP, dest IP, TCP/UDP src port and TCP/UDP dest
      *  port.
      */
     if (flow_type != TCP_V4_FLOW &&
         flow_type != TCP_V6_FLOW &&
         flow_type != UDP_V4_FLOW &&
         flow_type != UDP_V6_FLOW)
         return -EOPNOTSUPP;
Quoted 8 lines
Quoted 2 lines

when directly
classifying into an RQ, before the multi RSS context support.

Direct classification into an RQ actually works before my fix, because it goes to another branch in flow_get_tirn, that doesn't call flow_type_to_traffic_type. It's only steering to an RSS context that was broken for flow-type ip4/ip6.

Thanks for your patch.
LGTM.

Regards,
Tariq

Quoted 21 lines
Quoted 21 lines
Quoted 20 lines
---
   drivers/net/ethernet/mellanox/mlx5/core/en_fs_ethtool.c | 2 ++
   1 file changed, 2 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/en_fs_ethtool.c +2 -0
index 773624bb2c5d..d68230a7b9f4 100644
@@ -884,8 +884,10 @@ static int flow_type_to_traffic_type(u32 flow_type)
       case ESP_V6_FLOW:
               return MLX5_TT_IPV6_IPSEC_ESP;
       case IPV4_FLOW:
+     case IP_USER_FLOW:
               return MLX5_TT_IPV4;
       case IPV6_FLOW:
+     case IPV6_USER_FLOW:
               return MLX5_TT_IPV6;
       default:
               return -EINVAL;
#6 lore raw
In reply to Maxim Mikityanskiy

Hey Maxim!

drivers/net/ethernet/mellanox/mlx5/core/en_fs_ethtool.c static int flow_type_to_traffic_type(u32 flow_type) · line 887

Quoted 9 lines · Maxim Mikityanskiy
drivers/net/ethernet/mellanox/mlx5/core/en_fs_ethtool.c +1 -0
index 773624bb2c5d..d68230a7b9f4 100644
@@ -884,8 +884,10 @@ static int flow_type_to_traffic_type(u32 flow_type)
 	case ESP_V6_FLOW:
 		return MLX5_TT_IPV6_IPSEC_ESP;
 	case IPV4_FLOW:
+	case IP_USER_FLOW:

They're the same, but I think IPV4_USER_FLOW is the "modern" define that should be used.

Quoted 6 lines
drivers/net/ethernet/mellanox/mlx5/core/en_fs_ethtool.c +1 -0
 		return MLX5_TT_IPV4;
 	case IPV6_FLOW:
+	case IPV6_USER_FLOW:
 		return MLX5_TT_IPV6;
 	default:
 		return -EINVAL;
#7 lore raw
Quoted 4 lines · Gal Pressman

Hey Maxim!

On 19/03/2025 14:45, Maxim Mikityanskiy wrote:

Quoted 12 lines

drivers/net/ethernet/mellanox/mlx5/core/en_fs_ethtool.c static int flow_type_to_traffic_type(u32 flow_type) · line 887

Quoted 9 lines
drivers/net/ethernet/mellanox/mlx5/core/en_fs_ethtool.c +1 -0
index 773624bb2c5d..d68230a7b9f4 100644
@@ -884,8 +884,10 @@ static int flow_type_to_traffic_type(u32 flow_type)
      case ESP_V6_FLOW:
              return MLX5_TT_IPV6_IPSEC_ESP;
      case IPV4_FLOW:
+     case IP_USER_FLOW:

They're the same, but I think IPV4_USER_FLOW is the "modern" define that should be used.

Yeah, I used IP_USER_FLOW for consistency with other places in this file. If you prefer that, I can resubmit with IPV4_USER_FLOW.

Quoted 7 lines
Quoted 7 lines
drivers/net/ethernet/mellanox/mlx5/core/en_fs_ethtool.c +1 -0
              return MLX5_TT_IPV4;
      case IPV6_FLOW:
+     case IPV6_USER_FLOW:
              return MLX5_TT_IPV6;
      default:
              return -EINVAL;
#8 lore raw
Quoted 18 lines · Maxim Mikityanskiy
Quoted 4 lines · Gal Pressman

Hey Maxim!

On 19/03/2025 14:45, Maxim Mikityanskiy wrote:

Quoted 12 lines

drivers/net/ethernet/mellanox/mlx5/core/en_fs_ethtool.c static int flow_type_to_traffic_type(u32 flow_type) · line 887

Quoted 9 lines
drivers/net/ethernet/mellanox/mlx5/core/en_fs_ethtool.c +1 -0
index 773624bb2c5d..d68230a7b9f4 100644
@@ -884,8 +884,10 @@ static int flow_type_to_traffic_type(u32 flow_type)
      case ESP_V6_FLOW:
              return MLX5_TT_IPV6_IPSEC_ESP;
      case IPV4_FLOW:
+     case IP_USER_FLOW:

They're the same, but I think IPV4_USER_FLOW is the "modern" define that should be used.

Quoted 2 lines

Yeah, I used IP_USER_FLOW for consistency with other places in this file. If you prefer that, I can resubmit with IPV4_USER_FLOW.

I don't mind, up to Tariq.
We can followup with a patch that converts all usages.

#9 lore raw
Quoted 19 lines · Gal Pressman
Quoted 18 lines · Maxim Mikityanskiy
Quoted 16 lines · Gal Pressman

Hey Maxim!

drivers/net/ethernet/mellanox/mlx5/core/en_fs_ethtool.c static int flow_type_to_traffic_type(u32 flow_type) · line 887

Quoted 9 lines · Maxim Mikityanskiy
drivers/net/ethernet/mellanox/mlx5/core/en_fs_ethtool.c +1 -0
index 773624bb2c5d..d68230a7b9f4 100644
@@ -884,8 +884,10 @@ static int flow_type_to_traffic_type(u32 flow_type)
       case ESP_V6_FLOW:
               return MLX5_TT_IPV6_IPSEC_ESP;
       case IPV4_FLOW:
+     case IP_USER_FLOW:

They're the same, but I think IPV4_USER_FLOW is the "modern" define that should be used.

Quoted 6 lines
Quoted 2 lines

Yeah, I used IP_USER_FLOW for consistency with other places in this file. If you prefer that, I can resubmit with IPV4_USER_FLOW.

I don't mind, up to Tariq.
We can followup with a patch that converts all usages.

Please keep using IP_USER_FLOW for consistency with existing code. We may converts them all together later.

#10 lore raw
Quoted 26 lines · Tariq Toukan
Quoted 22 lines · Gal Pressman
Quoted 20 lines · Maxim Mikityanskiy
Quoted 4 lines · Gal Pressman

Hey Maxim!

On 19/03/2025 14:45, Maxim Mikityanskiy wrote:

Quoted 12 lines

drivers/net/ethernet/mellanox/mlx5/core/en_fs_ethtool.c static int flow_type_to_traffic_type(u32 flow_type) · line 887

Quoted 9 lines
drivers/net/ethernet/mellanox/mlx5/core/en_fs_ethtool.c +1 -0
index 773624bb2c5d..d68230a7b9f4 100644
@@ -884,8 +884,10 @@ static int flow_type_to_traffic_type(u32 flow_type)
       case ESP_V6_FLOW:
               return MLX5_TT_IPV6_IPSEC_ESP;
       case IPV4_FLOW:
+     case IP_USER_FLOW:

They're the same, but I think IPV4_USER_FLOW is the "modern" define that should be used.

Yeah, I used IP_USER_FLOW for consistency with other places in this file. If you prefer that, I can resubmit with IPV4_USER_FLOW.

Quoted 6 lines
Quoted 3 lines

I don't mind, up to Tariq.
We can followup with a patch that converts all usages.

Please keep using IP_USER_FLOW for consistency with existing code. We may converts them all together later.

OK, sounds good to me, keeping as is.

Thanks for the reviews!

#11 lore raw
In reply to Maxim Mikityanskiy
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 9 lines · On Wed, 19 Mar 2025 14:45:08 +0200 you wrote:

There commands can be used to add an RSS context and steer some traffic into it:

    # ethtool -X eth0 context new
    New RSS context is 1
    # ethtool -N eth0 flow-type ip4 dst-ip 1.1.1.1 context 1
    Added rule with ID 1023

[...]

Here is the summary with links:
- [net] net/mlx5e: Fix ethtool -N flow-type ip4 to RSS context

    https://git.kernel.org/netdev/net/c/3865bec60683

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html