net/mlx5: HWS, Improve IP version handling
Subsystems (4)
Mark Bloch
maintainercover net/mlx5: HWS, Improve IP version handling
This small series hardens our checks against a single matcher containing rules that match on IPv4 and IPv6. This scenario is not supported by hardware steering and the implementation now signals this instead of failing silently.
Patches:
* Patch 1 forbids a single definer to match on mixed IP versions for source and destination address.
* Patch 2 reproduces a couple of firmware checks: it forbids creating a definer that matches on IP address without matching on IP version, and also disallows matching on IPv6 addresses and the IPv4 IHL fields in the same definer.
* Patch 3 forbids mixing rules that match on IPv4 and IPv6 addresses in the same matcher. The underlying definer mechanism does not support that.
Thanks,
Mark
Vlad Dogaru (3):
net/mlx5: HWS, Fix IP version decision net/mlx5: HWS, Harden IP version definer checks net/mlx5: HWS, Disallow matcher IP version mixing
.../mellanox/mlx5/core/steering/hws/definer.c | 78 +++++++---- .../mellanox/mlx5/core/steering/hws/matcher.c | 26 ++++ .../mellanox/mlx5/core/steering/hws/matcher.h | 12 ++ .../mellanox/mlx5/core/steering/hws/rule.c | 122 ++++++++++++++++++ 4 files changed, 216 insertions(+), 22 deletions(-)
base-commit: 07e32237ed9d3f5815fb900dee9458b5f115a678
Signature · 1 line
2.34.1
Mark Bloch
maintainerPATCH 1/3 net/mlx5: HWS, Fix IP version decision
From: Vlad Dogaru <[email protected]>
Unify the check for IP version when creating a definer. A given matcher is deemed to match on IPv6 if any of the higher order (>31) bits of source or destination address mask are set.
A single packet cannot mix IP versions between source and destination addresses, so it makes no sense that they would be decided on independently.
--- .../mellanox/mlx5/core/steering/hws/definer.c | 38 ++++++++----------- 1 file changed, 16 insertions(+), 22 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/steering/hws/definer.c +16 -22
@@ -509,9 +509,9 @@ static int hws_definer_conv_outer(struct mlx5hws_definer_conv_data *cd, u32 *match_param) { - bool is_s_ipv6, is_d_ipv6, smac_set, dmac_set; struct mlx5hws_definer_fc *fc = cd->fc;struct mlx5hws_definer_fc *curr_fc; +bool is_ipv6, smac_set, dmac_set;u32 *s_ipv6, *d_ipv6; if (HWS_IS_FLD_SET_SZ(match_param, outer_headers.l4_type, 0x2) ||
@@ -570,10 +570,10 @@ hws_definer_conv_outer(struct mlx5hws_definer_conv_data *cd, outer_headers.dst_ipv4_dst_ipv6.ipv6_layout);/* Assume IPv6 is used if ipv6 bits are set */ - is_s_ipv6 = s_ipv6[0 ] || s_ipv6[1 ] || s_ipv6[2 ]; - is_d_ipv6 = d_ipv6[0 ] || d_ipv6[1 ] || d_ipv6[2 ]; + is_ipv6 = s_ipv6[0 ] || s_ipv6[1 ] || s_ipv6[2 ] || + d_ipv6[0 ] || d_ipv6[1 ] || d_ipv6[2 ]; -if (is_s_ipv6) { +if (is_ipv6) {/* Handle IPv6 source address */ HWS_SET_HDR(fc, match_param, IPV6_SRC_127_96_O, outer_headers.src_ipv4_src_ipv6.ipv6_simple_layout.ipv6_127_96,
@@ -587,13 +587,6 @@ hws_definer_conv_outer(struct mlx5hws_definer_conv_data *cd,HWS_SET_HDR (fc, match_param,IPV6_SRC_31_0_O , outer_headers.src_ipv4_src_ipv6.ipv6_simple_layout.ipv6_31_0, ipv6_src_outer.ipv6_address_31_0); - }else { -/* Handle IPv4 source address */ -HWS_SET_HDR (fc, match_param,IPV4_SRC_O , - outer_headers.src_ipv4_src_ipv6.ipv6_simple_layout.ipv6_31_0, - ipv4_src_dest_outer.source_address); - } -if (is_d_ipv6) {/* Handle IPv6 destination address */ HWS_SET_HDR(fc, match_param, IPV6_DST_127_96_O, outer_headers.dst_ipv4_dst_ipv6.ipv6_simple_layout.ipv6_127_96,
@@ -608,6 +601,10 @@ hws_definer_conv_outer(struct mlx5hws_definer_conv_data *cd, outer_headers.dst_ipv4_dst_ipv6.ipv6_simple_layout.ipv6_31_0, ipv6_dst_outer.ipv6_address_31_0); }else { +/* Handle IPv4 source address */ +HWS_SET_HDR (fc, match_param,IPV4_SRC_O , + outer_headers.src_ipv4_src_ipv6.ipv6_simple_layout.ipv6_31_0, + ipv4_src_dest_outer.source_address);/* Handle IPv4 destination address */ HWS_SET_HDR(fc, match_param, IPV4_DST_O, outer_headers.dst_ipv4_dst_ipv6.ipv6_simple_layout.ipv6_31_0,
@@ -665,9 +662,9 @@ static int hws_definer_conv_inner(struct mlx5hws_definer_conv_data *cd, u32 *match_param) { - bool is_s_ipv6, is_d_ipv6, smac_set, dmac_set; struct mlx5hws_definer_fc *fc = cd->fc;struct mlx5hws_definer_fc *curr_fc; +bool is_ipv6, smac_set, dmac_set;u32 *s_ipv6, *d_ipv6; if (HWS_IS_FLD_SET_SZ(match_param, inner_headers.l4_type, 0x2) ||
@@ -728,10 +725,10 @@ hws_definer_conv_inner(struct mlx5hws_definer_conv_data *cd, inner_headers.dst_ipv4_dst_ipv6.ipv6_layout);/* Assume IPv6 is used if ipv6 bits are set */ - is_s_ipv6 = s_ipv6[0 ] || s_ipv6[1 ] || s_ipv6[2 ]; - is_d_ipv6 = d_ipv6[0 ] || d_ipv6[1 ] || d_ipv6[2 ]; + is_ipv6 = s_ipv6[0 ] || s_ipv6[1 ] || s_ipv6[2 ] || + d_ipv6[0 ] || d_ipv6[1 ] || d_ipv6[2 ]; -if (is_s_ipv6) { +if (is_ipv6) {/* Handle IPv6 source address */ HWS_SET_HDR(fc, match_param, IPV6_SRC_127_96_I, inner_headers.src_ipv4_src_ipv6.ipv6_simple_layout.ipv6_127_96,
@@ -745,13 +742,6 @@ hws_definer_conv_inner(struct mlx5hws_definer_conv_data *cd,HWS_SET_HDR (fc, match_param,IPV6_SRC_31_0_I , inner_headers.src_ipv4_src_ipv6.ipv6_simple_layout.ipv6_31_0, ipv6_src_inner.ipv6_address_31_0); - }else { -/* Handle IPv4 source address */ -HWS_SET_HDR (fc, match_param,IPV4_SRC_I , - inner_headers.src_ipv4_src_ipv6.ipv6_simple_layout.ipv6_31_0, - ipv4_src_dest_inner.source_address); - } -if (is_d_ipv6) {/* Handle IPv6 destination address */ HWS_SET_HDR(fc, match_param, IPV6_DST_127_96_I, inner_headers.dst_ipv4_dst_ipv6.ipv6_simple_layout.ipv6_127_96,
@@ -766,6 +756,10 @@ hws_definer_conv_inner(struct mlx5hws_definer_conv_data *cd, inner_headers.dst_ipv4_dst_ipv6.ipv6_simple_layout.ipv6_31_0, ipv6_dst_inner.ipv6_address_31_0); }else { +/* Handle IPv4 source address */ +HWS_SET_HDR (fc, match_param,IPV4_SRC_I , + inner_headers.src_ipv4_src_ipv6.ipv6_simple_layout.ipv6_31_0, + ipv4_src_dest_inner.source_address);/* Handle IPv4 destination address */ HWS_SET_HDR(fc, match_param, IPV4_DST_I, inner_headers.dst_ipv4_dst_ipv6.ipv6_simple_layout.ipv6_31_0,
Signature · 1 line
2.34.1
Mark Bloch
maintainerPATCH 2/3 net/mlx5: HWS, Harden IP version definer checks
In reply to Mark BlochFrom: Vlad Dogaru <[email protected]>
Replicate some sanity checks that firmware does, since hardware steering does not go through firmware.
When creating a definer, disallow matching on IP addresses without also matching on IP version. The latter can be satisfied by matching either on the version field in the IP header, or on the ethertype field.
Also refuse to match IPv4 IHL alongside IPv6.
--- .../mellanox/mlx5/core/steering/hws/definer.c | 44 ++++++++++++++++++- 1 file changed, 42 insertions(+), 2 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/steering/hws/definer.c +42 -2
@@ -509,9 +509,9 @@ static int hws_definer_conv_outer(struct mlx5hws_definer_conv_data *cd, u32 *match_param) { + bool is_ipv6, smac_set, dmac_set, ip_addr_set, ip_ver_set;struct mlx5hws_definer_fc *fc = cd->fc;struct mlx5hws_definer_fc *curr_fc; -bool is_ipv6, smac_set, dmac_set;u32 *s_ipv6, *d_ipv6; if (HWS_IS_FLD_SET_SZ(match_param, outer_headers.l4_type, 0x2) ||
@@ -521,6 +521,20 @@ hws_definer_conv_outer(struct mlx5hws_definer_conv_data *cd,return -EINVAL ; } + ip_addr_set =HWS_IS_FLD_SET_SZ (match_param, + outer_headers.src_ipv4_src_ipv6, +0x80 ) || +HWS_IS_FLD_SET_SZ (match_param, + outer_headers.dst_ipv4_dst_ipv6,0x80 ); + ip_ver_set =HWS_IS_FLD_SET (match_param, outer_headers.ip_version) || +HWS_IS_FLD_SET (match_param, outer_headers.ethertype); + +if (ip_addr_set && !ip_ver_set) { +mlx5hws_err (cd->ctx, +"Unsupported match on IP address without version or ethertype\n" ); +return -EINVAL ; + } +/* L2 Check ethertype */ HWS_SET_HDR(fc, match_param, ETH_TYPE_O, outer_headers.ethertype,
@@ -573,6 +587,12 @@ hws_definer_conv_outer(struct mlx5hws_definer_conv_data *cd, is_ipv6 = s_ipv6[0 ] || s_ipv6[1 ] || s_ipv6[2 ] || d_ipv6[0 ] || d_ipv6[1 ] || d_ipv6[2 ]; +/* IHL is an IPv4-specific field. */ +if (is_ipv6 &&HWS_IS_FLD_SET (match_param, outer_headers.ipv4_ihl)) { +mlx5hws_err (cd->ctx,"Unsupported match on IPv6 address and IPv4 IHL\n" ); +return -EINVAL ; + } +if (is_ipv6) {/* Handle IPv6 source address */ HWS_SET_HDR(fc, match_param, IPV6_SRC_127_96_O,
@@ -662,9 +682,9 @@ static int hws_definer_conv_inner(struct mlx5hws_definer_conv_data *cd, u32 *match_param) { + bool is_ipv6, smac_set, dmac_set, ip_addr_set, ip_ver_set;struct mlx5hws_definer_fc *fc = cd->fc;struct mlx5hws_definer_fc *curr_fc; -bool is_ipv6, smac_set, dmac_set;u32 *s_ipv6, *d_ipv6; if (HWS_IS_FLD_SET_SZ(match_param, inner_headers.l4_type, 0x2) ||
@@ -674,6 +694,20 @@ hws_definer_conv_inner(struct mlx5hws_definer_conv_data *cd,return -EINVAL ; } + ip_addr_set =HWS_IS_FLD_SET_SZ (match_param, + inner_headers.src_ipv4_src_ipv6, +0x80 ) || +HWS_IS_FLD_SET_SZ (match_param, + inner_headers.dst_ipv4_dst_ipv6,0x80 ); + ip_ver_set =HWS_IS_FLD_SET (match_param, inner_headers.ip_version) || +HWS_IS_FLD_SET (match_param, inner_headers.ethertype); + +if (ip_addr_set && !ip_ver_set) { +mlx5hws_err (cd->ctx, +"Unsupported match on IP address without version or ethertype\n" ); +return -EINVAL ; + } +/* L2 Check ethertype */ HWS_SET_HDR(fc, match_param, ETH_TYPE_I, inner_headers.ethertype,
@@ -728,6 +762,12 @@ hws_definer_conv_inner(struct mlx5hws_definer_conv_data *cd, is_ipv6 = s_ipv6[0 ] || s_ipv6[1 ] || s_ipv6[2 ] || d_ipv6[0 ] || d_ipv6[1 ] || d_ipv6[2 ]; +/* IHL is an IPv4-specific field. */ +if (is_ipv6 &&HWS_IS_FLD_SET (match_param, inner_headers.ipv4_ihl)) { +mlx5hws_err (cd->ctx,"Unsupported match on IPv6 address and IPv4 IHL\n" ); +return -EINVAL ; + } +if (is_ipv6) {/* Handle IPv6 source address */ HWS_SET_HDR(fc, match_param, IPV6_SRC_127_96_I,
Signature · 1 line
2.34.1
Mark Bloch
maintainerPATCH 3/3 net/mlx5: HWS, Disallow matcher IP version mixing
In reply to Mark BlochFrom: Vlad Dogaru <[email protected]>
Signal clearly to the user, via an error, that mixing IPv4 and IPv6 rules in the same matcher is not supported. Previously such cases silently failed by adding a rule that did not work correctly.
Rules can specify an IP version by one of two fields: IP version or ethertype. At matcher creation, store whether the template matches on any of these two fields. If yes, inspect each rule for its corresponding match value and store the IP version inside the matcher to guard against inconsistencies with subsequent rules.
Furthermore, also check rules for internal consistency, i.e. verify that the ethertype and IP version match values do not contradict each other.
The logic applies to inner and outer headers independently, to account for tunneling.
Rules that do not match on IP addresses are not affected.
--- .../mellanox/mlx5/core/steering/hws/matcher.c | 26 ++++ .../mellanox/mlx5/core/steering/hws/matcher.h | 12 ++ .../mellanox/mlx5/core/steering/hws/rule.c | 122 ++++++++++++++++++ 3 files changed, 160 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/steering/hws/matcher.c +26 -0
@@ -385,6 +385,30 @@ static int hws_matcher_bind_at(struct mlx5hws_matcher *matcher)return 0 ; } +static void hws_matcher_set_ip_version_match (struct mlx5hws_matcher *matcher) +{ +int i; + +for (i =0 ; i < matcher->mt->fc_sz; i++) { +switch (matcher->mt->fc[i].fname) { +case MLX5HWS_DEFINER_FNAME_ETH_TYPE_O : + matcher->matches_outer_ethertype =1 ; +break ; +case MLX5HWS_DEFINER_FNAME_ETH_L3_TYPE_O : + matcher->matches_outer_ip_version =1 ; +break ; +case MLX5HWS_DEFINER_FNAME_ETH_TYPE_I : + matcher->matches_inner_ethertype =1 ; +break ; +case MLX5HWS_DEFINER_FNAME_ETH_L3_TYPE_I : + matcher->matches_inner_ip_version =1 ; +break ; +default : +break ; + } + } +} +static int hws_matcher_bind_mt (struct mlx5hws_matcher *matcher) {struct mlx5hws_context *ctx = matcher->tbl->ctx;
@@ -401,6 +425,8 @@ static int hws_matcher_bind_mt(struct mlx5hws_matcher *matcher) } } +hws_matcher_set_ip_version_match (matcher); +/* Create an STE pool per matcher*/ pool_attr.table_type = matcher->tbl->type; pool_attr.pool_type =MLX5HWS_POOL_TYPE_STE ;
drivers/net/ethernet/mellanox/mlx5/core/steering/hws/matcher.h +12 -0
@@ -50,6 +50,12 @@ struct mlx5hws_matcher_match_ste {struct mlx5hws_pool *pool; }; +enum { +MLX5HWS_MATCHER_IPV_UNSET =0 , +MLX5HWS_MATCHER_IPV_4 =1 , +MLX5HWS_MATCHER_IPV_6 =2 , +}; +struct mlx5hws_matcher {struct mlx5hws_table *tbl;struct mlx5hws_matcher_attr attr;
@@ -61,6 +67,12 @@ struct mlx5hws_matcher {u8 num_of_action_stes;/* enum mlx5hws_matcher_flags */ u8 flags; + u8 matches_outer_ethertype:1; + u8 matches_outer_ip_version:1; + u8 matches_inner_ethertype:1; + u8 matches_inner_ip_version:1; + u8 outer_ip_version:2; + u8 inner_ip_version:2;u32 end_ft_id;struct mlx5hws_matcher *col_matcher;struct mlx5hws_matcher *resize_dst;
drivers/net/ethernet/mellanox/mlx5/core/steering/hws/rule.c +122 -0
134 lines not on this page · raw message
Signature · 1 line
2.34.1
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 16 lines · On Tue, 22 Apr 2025 12:25:37 +0300 you wrote:
This small series hardens our checks against a single matcher containing rules that match on IPv4 and IPv6. This scenario is not supported by hardware steering and the implementation now signals this instead of failing silently.
Patches:
* Patch 1 forbids a single definer to match on mixed IP versions for source and destination address.
* Patch 2 reproduces a couple of firmware checks: it forbids creating a definer that matches on IP address without matching on IP version, and also disallows matching on IPv6 addresses and the IPv4 IHL fields in the same definer.
* Patch 3 forbids mixing rules that match on IPv4 and IPv6 addresses in the same matcher. The underlying definer mechanism does not support that.
Quoted 1 line
[...]
Here is the summary with links:
- [net-next,1/3] net/mlx5: HWS, Fix IP version decision
https://git.kernel.org/netdev/net-next/c/5f2f8d8b6800 - [net-next,2/3] net/mlx5: HWS, Harden IP version definer checks https://git.kernel.org/netdev/net-next/c/6991a975e416 - [net-next,3/3] net/mlx5: HWS, Disallow matcher IP version mixing https://git.kernel.org/netdev/net-next/c/f41f3edf0b15
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html