Skip to contentSkip to conversation

net/mlx5e: Add GBP VxLAN HW offload support

PATCH Superseded Gavin Li 3 participants 20 messages Feb 14, 2023 – Feb 20, 2023

Subsystems (4)

v1 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
author
#9 lore raw

PATCH 3/3 net/mlx5e: TC, Add support for VxLAN GBP encap/decap flows offload

In reply to Gavin Li

Add HW offloading support for TC flows with VxLAN GBP encap/decap.

Example of encap rule:
tc filter add dev eth0 protocol ip ingress flower \
action tunnel_key set id 42 vxlan_opts 512 \
action mirred egress redirect dev vxlan1

Example of decap rule:
tc filter add dev vxlan1 protocol ip ingress flower \
enc_key_id 42 enc_dst_port 4789 vxlan_opts 1024 \
action tunnel_key unset action mirred egress redirect dev eth0

Change-Id I48f61d02201bf3f79dcbe5d0f022f7bb27ed630f
---
 .../mellanox/mlx5/core/en/tc_tun_vxlan.c      | 85 ++++++++++++++++++-
 include/linux/mlx5/device.h                   |  6 ++
 include/linux/mlx5/mlx5_ifc.h                 | 13 ++-
 3 files changed, 100 insertions(+), 4 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c +83 -2
index 1f62c702b625..444512ca9e0d 100644
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
 /* Copyright (c) 2018 Mellanox Technologies. */
 
+#include <net/ip_tunnels.h>
 #include <net/vxlan.h>
 #include "lib/vxlan.h"
 #include "en/tc_tun.h"
@@ -86,9 +87,11 @@ static int mlx5e_gen_ip_tunnel_header_vxlan(char buf[],
 	const struct ip_tunnel_key *tun_key = &e->tun_info->key;
 	__be32 tun_id = tunnel_id_to_key32(tun_key->tun_id);
 	struct udphdr *udp = (struct udphdr *)(buf);
+	const struct vxlan_metadata *md;
 	struct vxlanhdr *vxh;
 
-	if (tun_key->tun_flags & TUNNEL_VXLAN_OPT)
+	if (tun_key->tun_flags & TUNNEL_VXLAN_OPT &&
+	    e->tun_info->options_len != sizeof(*md))
 		return -EOPNOTSUPP;
 	vxh = (struct vxlanhdr *)((char *)udp + sizeof(struct udphdr));
 	*ip_proto = IPPROTO_UDP;
@@ -96,6 +99,70 @@ static int mlx5e_gen_ip_tunnel_header_vxlan(char buf[],
 	udp->dest = tun_key->tp_dst;
 	vxh->vx_flags = VXLAN_HF_VNI;
 	vxh->vx_vni = vxlan_vni_field(tun_id);
+	if (tun_key->tun_flags & TUNNEL_VXLAN_OPT) {
+		md = ip_tunnel_info_opts((struct ip_tunnel_info *)e->tun_info);
+		vxlan_build_gbp_hdr(vxh, tun_key->tun_flags,
+				    (struct vxlan_metadata *)md);
+	}
+
+	return 0;
+}
+
+static int mlx5e_tc_tun_parse_vxlan_gbp_option(struct mlx5e_priv *priv,
+					       struct mlx5_flow_spec *spec,
+					       struct flow_cls_offload *f)
+{
+	struct flow_rule *rule = flow_cls_offload_flow_rule(f);
+	struct netlink_ext_ack *extack = f->common.extack;
+	struct flow_match_enc_opts enc_opts;
+	void *misc5_c, *misc5_v;
+	u32 *gbp, *gbp_mask;
+
+	flow_rule_match_enc_opts(rule, &enc_opts);
+
+	if (memchr_inv(&enc_opts.mask->data, 0, sizeof(enc_opts.mask->data)) &&
+	    !MLX5_CAP_ESW_FT_FIELD_SUPPORT_2(priv->mdev, tunnel_header_0_1)) {
+		NL_SET_ERR_MSG_MOD(extack,
+				   "Matching on VxLAN GBP is not supported");
+		netdev_warn(priv->netdev,
+			    "Matching on VxLAN GBP is not supported\n");
+		return -EOPNOTSUPP;
+	}
+
+	if (enc_opts.key->dst_opt_type != TUNNEL_VXLAN_OPT) {
+		NL_SET_ERR_MSG_MOD(extack,
+				   "Wrong VxLAN option type: not GBP");
+		netdev_warn(priv->netdev,
+			    "Wrong VxLAN option type: not GBP\n");
+		return -EOPNOTSUPP;
+	}
+
+	if (enc_opts.key->len != sizeof(*gbp) ||
+	    enc_opts.mask->len != sizeof(*gbp_mask)) {
+		NL_SET_ERR_MSG_MOD(extack,
+				   "VxLAN GBP option/mask len is not 32 bits");
+		netdev_warn(priv->netdev,
+			    "VxLAN GBP option/mask len is not 32 bits\n");
+		return -EINVAL;
+	}
+
+	gbp = (u32 *)&enc_opts.key->data[0];
+	gbp_mask = (u32 *)&enc_opts.mask->data[0];
+
+	if (*gbp_mask & ~VXLAN_GBP_MASK) {
+		NL_SET_ERR_MSG_MOD(extack,
+				   "Wrong VxLAN GBP mask");
+		netdev_warn(priv->netdev,
+			    "Wrong VxLAN GBP mask(0x%08X)\n", *gbp_mask);
+		return -EINVAL;
+	}
+
+	misc5_c = MLX5_ADDR_OF(fte_match_param, spec->match_criteria, misc_parameters_5);
+	misc5_v = MLX5_ADDR_OF(fte_match_param, spec->match_value, misc_parameters_5);
+	MLX5_SET(fte_match_set_misc5, misc5_c, tunnel_header_0, *gbp_mask);
+	MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_0, *gbp);
+
+	spec->match_criteria_enable |= MLX5_MATCH_MISC_PARAMETERS_5;
 
 	return 0;
 }
@@ -122,6 +189,14 @@ static int mlx5e_tc_tun_parse_vxlan(struct mlx5e_priv *priv,
 	if (!enc_keyid.mask->keyid)
 		return 0;
 
+	if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_ENC_OPTS)) {
+		int err;
+
+		err = mlx5e_tc_tun_parse_vxlan_gbp_option(priv, spec, f);
+		if (err)
+			return err;
+	}
+
 	/* match on VNI is required */
 
 	if (!MLX5_CAP_ESW_FLOWTABLE_FDB(priv->mdev,
@@ -143,6 +218,12 @@ static int mlx5e_tc_tun_parse_vxlan(struct mlx5e_priv *priv,
 	return 0;
 }
 
+static bool mlx5e_tc_tun_encap_info_equal_vxlan(struct mlx5e_encap_key *a,
+						struct mlx5e_encap_key *b)
+{
+	return mlx5e_tc_tun_encap_info_equal_options(a, b, TUNNEL_VXLAN_OPT);
+}
+
 static int mlx5e_tc_tun_get_remote_ifindex(struct net_device *mirred_dev)
 {
 	const struct vxlan_dev *vxlan = netdev_priv(mirred_dev);
@@ -160,6 +241,6 @@ struct mlx5e_tc_tunnel vxlan_tunnel = {
 	.generate_ip_tun_hdr  = mlx5e_gen_ip_tunnel_header_vxlan,
 	.parse_udp_ports      = mlx5e_tc_tun_parse_udp_ports_vxlan,
 	.parse_tunnel         = mlx5e_tc_tun_parse_vxlan,
-	.encap_info_equal     = mlx5e_tc_tun_encap_info_equal_generic,
+	.encap_info_equal     = mlx5e_tc_tun_encap_info_equal_vxlan,
 	.get_remote_ifindex   = mlx5e_tc_tun_get_remote_ifindex,
 };
include/linux/mlx5/device.h +6 -0
index 71b06ebad402..af4dd536a52c 100644
@@ -1357,6 +1357,12 @@ enum mlx5_qcam_feature_groups {
 #define MLX5_CAP_ESW_INGRESS_ACL_MAX(mdev, cap) \
 	MLX5_CAP_ESW_FLOWTABLE_MAX(mdev, flow_table_properties_esw_acl_ingress.cap)
 
+#define MLX5_CAP_ESW_FT_FIELD_SUPPORT_2(mdev, cap) \
+	MLX5_CAP_ESW_FLOWTABLE(mdev, ft_field_support_2_esw_fdb.cap)
+
+#define MLX5_CAP_ESW_FT_FIELD_SUPPORT_2_MAX(mdev, cap) \
+	MLX5_CAP_ESW_FLOWTABLE_MAX(mdev, ft_field_support_2_esw_fdb.cap)
+
 #define MLX5_CAP_ESW(mdev, cap) \
 	MLX5_GET(e_switch_cap, \
 		 mdev->caps.hca[MLX5_CAP_ESWITCH]->cur, cap)
include/linux/mlx5/mlx5_ifc.h +11 -2
index 1e530a8a2cf5..caef6aa20454 100644
@@ -399,10 +399,13 @@ struct mlx5_ifc_flow_table_fields_supported_bits {
 	u8         metadata_reg_c_0[0x1];
 };
 
+/* Table 2170 - Flow Table Fields Supported 2 Format */
 struct mlx5_ifc_flow_table_fields_supported_2_bits {
 	u8         reserved_at_0[0xe];
 	u8         bth_opcode[0x1];
-	u8         reserved_at_f[0x11];
+	u8         reserved_at_f[0x1];
+	u8         tunnel_header_0_1[0x1];
+	u8         reserved_at_11[0xf];
 
 	u8         reserved_at_20[0x60];
 };
@@ -890,7 +893,13 @@ struct mlx5_ifc_flow_table_eswitch_cap_bits {
 
 	struct mlx5_ifc_flow_table_prop_layout_bits flow_table_properties_esw_acl_egress;
 
-	u8      reserved_at_800[0x1000];
+	u8      reserved_at_800[0xC00];
+
+	struct mlx5_ifc_flow_table_fields_supported_2_bits ft_field_support_2_esw_fdb;
+
+	struct mlx5_ifc_flow_table_fields_supported_2_bits ft_field_bitmask_support_2_esw_fdb;
+
+	u8      reserved_at_1500[0x300];
 
 	u8      sw_steering_fdb_action_drop_icm_address_rx[0x40];
 
Signature · 1 line
2.31.1

Gavin Li

author
#0 lore raw

cover net/mlx5e: Add GBP VxLAN HW offload support

This patch series adds HW offloading support for TC flows with VxLAN GBP encap/decap.

Patch-1: Expose helper function vxlan_build_gbp_hdr.
Patch-2: Add helper function for encap_info_equal for tunnels with options.
Patch-3: Add HW offloading support for TC flows with VxLAN GBP encap/decap
in mlx ethernet driver.

Gavin Li (3):
vxlan: Expose helper vxlan_build_gbp_hdr
net/mlx5e: Add helper for encap_info_equal for tunnels with options net/mlx5e: TC, Add support for VxLAN GBP encap/decap flows offload

 .../ethernet/mellanox/mlx5/core/en/tc_tun.h   |  3 +
 .../mellanox/mlx5/core/en/tc_tun_encap.c      | 29 +++++++
 .../mellanox/mlx5/core/en/tc_tun_geneve.c     | 24 +-----
 .../mellanox/mlx5/core/en/tc_tun_vxlan.c      | 85 ++++++++++++++++++-
 drivers/net/vxlan/vxlan_core.c                | 20 -----
 include/linux/mlx5/device.h                   |  6 ++
 include/linux/mlx5/mlx5_ifc.h                 | 13 ++-
 include/net/vxlan.h                           | 20 +++++
 8 files changed, 153 insertions(+), 47 deletions(-)
Signature · 1 line
2.31.1
author
#1 lore raw

PATCH 1/3 vxlan: Expose helper vxlan_build_gbp_hdr

vxlan_build_gbp_hdr will be used by other modules to build gbp option in vxlan header according to gbp flags.

Change-Id I10d8dd31d6048e1fcd08cd76ee3bcd3029053552
---
 drivers/net/vxlan/vxlan_core.c | 20 --------------------
 include/net/vxlan.h            | 20 ++++++++++++++++++++
 2 files changed, 20 insertions(+), 20 deletions(-)
drivers/net/vxlan/vxlan_core.c +0 -20
index b1b179effe2a..bd44467a5a39 100644
@@ -2140,26 +2140,6 @@ static bool route_shortcircuit(struct net_device *dev, struct sk_buff *skb)
 	return false;
 }
 
-static void vxlan_build_gbp_hdr(struct vxlanhdr *vxh, u32 vxflags,
-				struct vxlan_metadata *md)
-{
-	struct vxlanhdr_gbp *gbp;
-
-	if (!md->gbp)
-		return;
-
-	gbp = (struct vxlanhdr_gbp *)vxh;
-	vxh->vx_flags |= VXLAN_HF_GBP;
-
-	if (md->gbp & VXLAN_GBP_DONT_LEARN)
-		gbp->dont_learn = 1;
-
-	if (md->gbp & VXLAN_GBP_POLICY_APPLIED)
-		gbp->policy_applied = 1;
-
-	gbp->policy_id = htons(md->gbp & VXLAN_GBP_ID_MASK);
-}
-
 static int vxlan_build_gpe_hdr(struct vxlanhdr *vxh, u32 vxflags,
 			       __be16 protocol)
 {
include/net/vxlan.h +20 -0
index bca5b01af247..08bc762a7e94 100644
@@ -566,4 +566,24 @@ static inline bool vxlan_fdb_nh_path_select(struct nexthop *nh,
 	return true;
 }
 
+static inline void vxlan_build_gbp_hdr(struct vxlanhdr *vxh, u32 vxflags,
+				       struct vxlan_metadata *md)
+{
+	struct vxlanhdr_gbp *gbp;
+
+	if (!md->gbp)
+		return;
+
+	gbp = (struct vxlanhdr_gbp *)vxh;
+	vxh->vx_flags |= VXLAN_HF_GBP;
+
+	if (md->gbp & VXLAN_GBP_DONT_LEARN)
+		gbp->dont_learn = 1;
+
+	if (md->gbp & VXLAN_GBP_POLICY_APPLIED)
+		gbp->policy_applied = 1;
+
+	gbp->policy_id = htons(md->gbp & VXLAN_GBP_ID_MASK);
+}
+
 #endif
Signature · 1 line
2.31.1
author
#4 lore raw

PATCH 2/3 net/mlx5e: Add helper for encap_info_equal for tunnels with options

In reply to Gavin Li

For tunnels with options, eg, geneve and vxlan with gbp, they share the same way to compare the headers and options. Extract the code as a common function for them

Change-Id I3ea697293c8d5d66c0c20080dbde88f60bcbd62f
---
 .../ethernet/mellanox/mlx5/core/en/tc_tun.h   |  3 ++
 .../mellanox/mlx5/core/en/tc_tun_encap.c      | 29 +++++++++++++++++++
 .../mellanox/mlx5/core/en/tc_tun_geneve.c     | 24 +--------------
 3 files changed, 33 insertions(+), 23 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.h +3 -0
index b38f693bbb52..92065568bb19 100644
@@ -115,6 +115,9 @@ int mlx5e_tc_tun_parse_udp_ports(struct mlx5e_priv *priv,
 bool mlx5e_tc_tun_encap_info_equal_generic(struct mlx5e_encap_key *a,
 					   struct mlx5e_encap_key *b);
 
+bool mlx5e_tc_tun_encap_info_equal_options(struct mlx5e_encap_key *a,
+					   struct mlx5e_encap_key *b,
+					   __be16 tun_flags);
 #endif /* CONFIG_MLX5_ESWITCH */
 
 #endif //__MLX5_EN_TC_TUNNEL_H__
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c +29 -0
index 780224fd67a1..4df9d27a63ad 100644
@@ -571,6 +571,35 @@ bool mlx5e_tc_tun_encap_info_equal_generic(struct mlx5e_encap_key *a,
 		a->tc_tunnel->tunnel_type == b->tc_tunnel->tunnel_type;
 }
 
+bool mlx5e_tc_tun_encap_info_equal_options(struct mlx5e_encap_key *a,
+					   struct mlx5e_encap_key *b,
+					   __be16 tun_flags)
+{
+	struct ip_tunnel_info *a_info;
+	struct ip_tunnel_info *b_info;
+	bool a_has_opts, b_has_opts;
+
+	if (!mlx5e_tc_tun_encap_info_equal_generic(a, b))
+		return false;
+
+	a_has_opts = !!(a->ip_tun_key->tun_flags & tun_flags);
+	b_has_opts = !!(b->ip_tun_key->tun_flags & tun_flags);
+
+	/* keys are equal when both don't have any options attached */
+	if (!a_has_opts && !b_has_opts)
+		return true;
+
+	if (a_has_opts != b_has_opts)
+		return false;
+
+	/* options stored in memory next to ip_tunnel_info struct */
+	a_info = container_of(a->ip_tun_key, struct ip_tunnel_info, key);
+	b_info = container_of(b->ip_tun_key, struct ip_tunnel_info, key);
+
+	return a_info->options_len == b_info->options_len &&
+		memcmp(a_info + 1, b_info + 1, a_info->options_len) == 0;
+}
+
 static int cmp_decap_info(struct mlx5e_decap_key *a,
 			  struct mlx5e_decap_key *b)
 {
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_geneve.c +1 -23
index 054d80c4e65c..2bcd10b6d653 100644
@@ -337,29 +337,7 @@ static int mlx5e_tc_tun_parse_geneve(struct mlx5e_priv *priv,
 static bool mlx5e_tc_tun_encap_info_equal_geneve(struct mlx5e_encap_key *a,
 						 struct mlx5e_encap_key *b)
 {
-	struct ip_tunnel_info *a_info;
-	struct ip_tunnel_info *b_info;
-	bool a_has_opts, b_has_opts;
-
-	if (!mlx5e_tc_tun_encap_info_equal_generic(a, b))
-		return false;
-
-	a_has_opts = !!(a->ip_tun_key->tun_flags & TUNNEL_GENEVE_OPT);
-	b_has_opts = !!(b->ip_tun_key->tun_flags & TUNNEL_GENEVE_OPT);
-
-	/* keys are equal when both don't have any options attached */
-	if (!a_has_opts && !b_has_opts)
-		return true;
-
-	if (a_has_opts != b_has_opts)
-		return false;
-
-	/* geneve options stored in memory next to ip_tunnel_info struct */
-	a_info = container_of(a->ip_tun_key, struct ip_tunnel_info, key);
-	b_info = container_of(b->ip_tun_key, struct ip_tunnel_info, key);
-
-	return a_info->options_len == b_info->options_len &&
-		memcmp(a_info + 1, b_info + 1, a_info->options_len) == 0;
+	return mlx5e_tc_tun_encap_info_equal_options(a, b, TUNNEL_GENEVE_OPT);
 }
 
 struct mlx5e_tc_tunnel geneve_tunnel = {
Signature · 1 line
2.31.1
Reviewed-by on v1 1/3
#2 lore raw

Re: [PATCH net-next v1 1/3] vxlan: Expose helper vxlan_build_gbp_hdr

In reply to Gavin Li

From: Gavin Li <[email protected]>
Date: Tue, 14 Feb 2023 15:41:35 +0200

Quoted 2 lines

vxlan_build_gbp_hdr will be used by other modules to build gbp option in vxlan header according to gbp flags.

(not sure if it's okay to write abbreviations with non-capital)

Quoted 6 lines
Change-Id I10d8dd31d6048e1fcd08cd76ee3bcd3029053552

Besides the nit above:

Quoted 55 lines
---
 drivers/net/vxlan/vxlan_core.c | 20 --------------------
 include/net/vxlan.h            | 20 ++++++++++++++++++++
 2 files changed, 20 insertions(+), 20 deletions(-)
drivers/net/vxlan/vxlan_core.c +0 -20
index b1b179effe2a..bd44467a5a39 100644
@@ -2140,26 +2140,6 @@ static bool route_shortcircuit(struct net_device *dev, struct sk_buff *skb)
 	return false;
 }
 
-static void vxlan_build_gbp_hdr(struct vxlanhdr *vxh, u32 vxflags,
-				struct vxlan_metadata *md)
-{
-	struct vxlanhdr_gbp *gbp;
-
-	if (!md->gbp)
-		return;
-
-	gbp = (struct vxlanhdr_gbp *)vxh;
-	vxh->vx_flags |= VXLAN_HF_GBP;
-
-	if (md->gbp & VXLAN_GBP_DONT_LEARN)
-		gbp->dont_learn = 1;
-
-	if (md->gbp & VXLAN_GBP_POLICY_APPLIED)
-		gbp->policy_applied = 1;
-
-	gbp->policy_id = htons(md->gbp & VXLAN_GBP_ID_MASK);
-}
-
 static int vxlan_build_gpe_hdr(struct vxlanhdr *vxh, u32 vxflags,
 			       __be16 protocol)
 {
include/net/vxlan.h +11 -0
index bca5b01af247..08bc762a7e94 100644
@@ -566,4 +566,24 @@ static inline bool vxlan_fdb_nh_path_select(struct nexthop *nh,
 	return true;
 }
 
+static inline void vxlan_build_gbp_hdr(struct vxlanhdr *vxh, u32 vxflags,
+				       struct vxlan_metadata *md)
+{
+	struct vxlanhdr_gbp *gbp;
+
+	if (!md->gbp)
+		return;
+
+	gbp = (struct vxlanhdr_gbp *)vxh;
+	vxh->vx_flags |= VXLAN_HF_GBP;
+

include/net/vxlan.h static inline bool vxlan_fdb_nh_path_select(struct nexthop *nh, · line 589

Quoted 10 lines
include/net/vxlan.h +9 -0
+	if (md->gbp & VXLAN_GBP_DONT_LEARN)
+		gbp->dont_learn = 1;
+
+	if (md->gbp & VXLAN_GBP_POLICY_APPLIED)
+		gbp->policy_applied = 1;
+
+	gbp->policy_id = htons(md->gbp & VXLAN_GBP_ID_MASK);
+}
+
 #endif

Thanks,
Olek

#5 lore raw

Re: [PATCH net-next v1 2/3] net/mlx5e: Add helper for encap_info_equal for tunnels with options

In reply to Gavin Li

From: Gavin Li <[email protected]>
Date: Tue, 14 Feb 2023 15:41:36 +0200

(dropping non-existent [email protected])

Quoted 9 lines

For tunnels with options, eg, geneve and vxlan with gbp, they share the same way to compare the headers and options. Extract the code as a common function for them

Change-Id I3ea697293c8d5d66c0c20080dbde88f60bcbd62f

[...]

Quoted 25 lines
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c +17 -0
index 780224fd67a1..4df9d27a63ad 100644
@@ -571,6 +571,35 @@ bool mlx5e_tc_tun_encap_info_equal_generic(struct mlx5e_encap_key *a,
 		a->tc_tunnel->tunnel_type == b->tc_tunnel->tunnel_type;
 }
 
+bool mlx5e_tc_tun_encap_info_equal_options(struct mlx5e_encap_key *a,
+					   struct mlx5e_encap_key *b,
+					   __be16 tun_flags)
+{
+	struct ip_tunnel_info *a_info;
+	struct ip_tunnel_info *b_info;
+	bool a_has_opts, b_has_opts;
+
+	if (!mlx5e_tc_tun_encap_info_equal_generic(a, b))
+		return false;
+
+	a_has_opts = !!(a->ip_tun_key->tun_flags & tun_flags);
+	b_has_opts = !!(b->ip_tun_key->tun_flags & tun_flags);
+
+	/* keys are equal when both don't have any options attached */
+	if (!a_has_opts && !b_has_opts)
+		return true;

drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c bool mlx5e_tc_tun_encap_info_equal_generic(struct mlx5e_encap_key *a, · line 600

Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c +10 -0
+
+	if (a_has_opts != b_has_opts)
+		return false;
+
+	/* options stored in memory next to ip_tunnel_info struct */
+	a_info = container_of(a->ip_tun_key, struct ip_tunnel_info, key);
+	b_info = container_of(b->ip_tun_key, struct ip_tunnel_info, key);
+
+	return a_info->options_len == b_info->options_len &&
+		memcmp(a_info + 1, b_info + 1, a_info->options_len) == 0;

1. memcmp() is not aligned to the first expr (off-by-one to the right).
2. !expr is preferred over expr == 0.

drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c bool mlx5e_tc_tun_encap_info_equal_generic(struct mlx5e_encap_key *a, · line 605

Quoted 5 lines
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c +2 -0
+}
+
 static int cmp_decap_info(struct mlx5e_decap_key *a,
 			  struct mlx5e_decap_key *b)
 {

[...]

Thanks,
Olek

#10 lore raw

Re: [PATCH net-next v1 3/3] net/mlx5e: TC, Add support for VxLAN GBP encap/decap flows offload

In reply to Gavin Li

From: Gavin Li <[email protected]>
Date: Tue, 14 Feb 2023 15:41:37 +0200

Quoted 36 lines

Add HW offloading support for TC flows with VxLAN GBP encap/decap.

Example of encap rule:
tc filter add dev eth0 protocol ip ingress flower \
action tunnel_key set id 42 vxlan_opts 512 \
action mirred egress redirect dev vxlan1

Example of decap rule:
tc filter add dev vxlan1 protocol ip ingress flower \
enc_key_id 42 enc_dst_port 4789 vxlan_opts 1024 \
action tunnel_key unset action mirred egress redirect dev eth0

Change-Id I48f61d02201bf3f79dcbe5d0f022f7bb27ed630f
---
 .../mellanox/mlx5/core/en/tc_tun_vxlan.c      | 85 ++++++++++++++++++-
 include/linux/mlx5/device.h                   |  6 ++
 include/linux/mlx5/mlx5_ifc.h                 | 13 ++-
 3 files changed, 100 insertions(+), 4 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c +1 -0
index 1f62c702b625..444512ca9e0d 100644
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
 /* Copyright (c) 2018 Mellanox Technologies. */
 
+#include <net/ip_tunnels.h>
 #include <net/vxlan.h>
 #include "lib/vxlan.h"
 #include "en/tc_tun.h"

drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c static int mlx5e_gen_ip_tunnel_header_vxlan(char buf[], · line 93

Quoted 8 lines
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c +2 -1
@@ -86,9 +87,11 @@ static int mlx5e_gen_ip_tunnel_header_vxlan(char buf[],
 	const struct ip_tunnel_key *tun_key = &e->tun_info->key;
 	__be32 tun_id = tunnel_id_to_key32(tun_key->tun_id);
 	struct udphdr *udp = (struct udphdr *)(buf);
+	const struct vxlan_metadata *md;
 	struct vxlanhdr *vxh;
 
-	if (tun_key->tun_flags & TUNNEL_VXLAN_OPT)
+	if (tun_key->tun_flags & TUNNEL_VXLAN_OPT &&

A separate pair of braces is preferred around bitops.

drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c static int mlx5e_gen_ip_tunnel_header_vxlan(char buf[], · line 105

Quoted 12 lines
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c +5 -0
+	    e->tun_info->options_len != sizeof(*md))
 		return -EOPNOTSUPP;
 	vxh = (struct vxlanhdr *)((char *)udp + sizeof(struct udphdr));
 	*ip_proto = IPPROTO_UDP;
@@ -96,6 +99,70 @@ static int mlx5e_gen_ip_tunnel_header_vxlan(char buf[],
 	udp->dest = tun_key->tp_dst;
 	vxh->vx_flags = VXLAN_HF_VNI;
 	vxh->vx_vni = vxlan_vni_field(tun_id);
+	if (tun_key->tun_flags & TUNNEL_VXLAN_OPT) {
+		md = ip_tunnel_info_opts((struct ip_tunnel_info *)e->tun_info);
+		vxlan_build_gbp_hdr(vxh, tun_key->tun_flags,
+				    (struct vxlan_metadata *)md);

Maybe constify both ip_tunnel_info_opts() and vxlan_build_gbp_hdr() arguments instead of working around by casting away?

Quoted 19 lines
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c +19 -0
+	}
+
+	return 0;
+}
+
+static int mlx5e_tc_tun_parse_vxlan_gbp_option(struct mlx5e_priv *priv,
+					       struct mlx5_flow_spec *spec,
+					       struct flow_cls_offload *f)
+{
+	struct flow_rule *rule = flow_cls_offload_flow_rule(f);
+	struct netlink_ext_ack *extack = f->common.extack;
+	struct flow_match_enc_opts enc_opts;
+	void *misc5_c, *misc5_v;
+	u32 *gbp, *gbp_mask;
+
+	flow_rule_match_enc_opts(rule, &enc_opts);
+
+	if (memchr_inv(&enc_opts.mask->data, 0, sizeof(enc_opts.mask->data)) &&
+	    !MLX5_CAP_ESW_FT_FIELD_SUPPORT_2(priv->mdev, tunnel_header_0_1)) {

drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c static int mlx5e_gen_ip_tunnel_header_vxlan(char buf[], · line 134

Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c +10 -0
+		NL_SET_ERR_MSG_MOD(extack,
+				   "Matching on VxLAN GBP is not supported");
+		netdev_warn(priv->netdev,
+			    "Matching on VxLAN GBP is not supported\n");
+		return -EOPNOTSUPP;
+	}
+
+	if (enc_opts.key->dst_opt_type != TUNNEL_VXLAN_OPT) {
+		NL_SET_ERR_MSG_MOD(extack,
+				   "Wrong VxLAN option type: not GBP");

Fits into one line I believe.

Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c +10 -0
+		netdev_warn(priv->netdev,
+			    "Wrong VxLAN option type: not GBP\n");
+		return -EOPNOTSUPP;
+	}
+
+	if (enc_opts.key->len != sizeof(*gbp) ||
+	    enc_opts.mask->len != sizeof(*gbp_mask)) {
+		NL_SET_ERR_MSG_MOD(extack,
+				   "VxLAN GBP option/mask len is not 32 bits");
+		netdev_warn(priv->netdev,

drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c static int mlx5e_gen_ip_tunnel_header_vxlan(char buf[], · line 154

Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c +10 -0
+			    "VxLAN GBP option/mask len is not 32 bits\n");
+		return -EINVAL;
+	}
+
+	gbp = (u32 *)&enc_opts.key->data[0];
+	gbp_mask = (u32 *)&enc_opts.mask->data[0];
+
+	if (*gbp_mask & ~VXLAN_GBP_MASK) {
+		NL_SET_ERR_MSG_MOD(extack,
+				   "Wrong VxLAN GBP mask");

You can use new NL_SET_ERR_MSG_FMT_MOD() here to print @gbp_mask to the user, as you do it next line.

Quoted 4 lines
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c +4 -0
+		netdev_warn(priv->netdev,
+			    "Wrong VxLAN GBP mask(0x%08X)\n", *gbp_mask);
+		return -EINVAL;
+	}

drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c static int mlx5e_gen_ip_tunnel_header_vxlan(char buf[], · line 168

Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c +7 -0
+
+	misc5_c = MLX5_ADDR_OF(fte_match_param, spec->match_criteria, misc_parameters_5);
+	misc5_v = MLX5_ADDR_OF(fte_match_param, spec->match_value, misc_parameters_5);
+	MLX5_SET(fte_match_set_misc5, misc5_c, tunnel_header_0, *gbp_mask);
+	MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_0, *gbp);
+
+	spec->match_criteria_enable |= MLX5_MATCH_MISC_PARAMETERS_5;
 
 	return 0;
 }

Thanks,
Olek

author
#11 lore raw

Re: [PATCH net-next v1 3/3] net/mlx5e: TC, Add support for VxLAN GBP encap/decap flows offload

Quoted 48 lines · Alexander Lobakin

External email: Use caution opening links or attachments

From: Gavin Li <[email protected]>
Date: Tue, 14 Feb 2023 15:41:37 +0200

Quoted 42 lines

Add HW offloading support for TC flows with VxLAN GBP encap/decap.

Example of encap rule:
tc filter add dev eth0 protocol ip ingress flower \
action tunnel_key set id 42 vxlan_opts 512 \
action mirred egress redirect dev vxlan1

Example of decap rule:
tc filter add dev vxlan1 protocol ip ingress flower \
enc_key_id 42 enc_dst_port 4789 vxlan_opts 1024 \
action tunnel_key unset action mirred egress redirect dev eth0

Change-Id I48f61d02201bf3f79dcbe5d0f022f7bb27ed630f
---
  .../mellanox/mlx5/core/en/tc_tun_vxlan.c      | 85 ++++++++++++++++++-
  include/linux/mlx5/device.h                   |  6 ++
  include/linux/mlx5/mlx5_ifc.h                 | 13 ++-
  3 files changed, 100 insertions(+), 4 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c +2 -0
index 1f62c702b625..444512ca9e0d 100644
@@ -1,6 +1,7 @@
  // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
  /* Copyright (c) 2018 Mellanox Technologies. */
 
+#include <net/ip_tunnels.h>
  #include <net/vxlan.h>
  #include "lib/vxlan.h"
  #include "en/tc_tun.h"
@@ -86,9 +87,11 @@ static int mlx5e_gen_ip_tunnel_header_vxlan(char buf[],
       const struct ip_tunnel_key *tun_key = &e->tun_info->key;
       __be32 tun_id = tunnel_id_to_key32(tun_key->tun_id);
       struct udphdr *udp = (struct udphdr *)(buf);
+     const struct vxlan_metadata *md;
       struct vxlanhdr *vxh;
 
Quoted 3 lines

drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c static int mlx5e_gen_ip_tunnel_header_vxlan(char buf[], · line 93

Quoted 2 lines
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c +1 -1
-     if (tun_key->tun_flags & TUNNEL_VXLAN_OPT)
+     if (tun_key->tun_flags & TUNNEL_VXLAN_OPT &&

A separate pair of braces is preferred around bitops.

ACK

Quoted 15 lines

drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c static int mlx5e_gen_ip_tunnel_header_vxlan(char buf[], · line 105

Quoted 13 lines
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c +5 -0
+         e->tun_info->options_len != sizeof(*md))
               return -EOPNOTSUPP;
       vxh = (struct vxlanhdr *)((char *)udp + sizeof(struct udphdr));
       *ip_proto = IPPROTO_UDP;
@@ -96,6 +99,70 @@ static int mlx5e_gen_ip_tunnel_header_vxlan(char buf[],
       udp->dest = tun_key->tp_dst;
       vxh->vx_flags = VXLAN_HF_VNI;
       vxh->vx_vni = vxlan_vni_field(tun_id);
+     if (tun_key->tun_flags & TUNNEL_VXLAN_OPT) {
+             md = ip_tunnel_info_opts((struct ip_tunnel_info *)e->tun_info);
+             vxlan_build_gbp_hdr(vxh, tun_key->tun_flags,
+                                 (struct vxlan_metadata *)md);

Maybe constify both ip_tunnel_info_opts() and vxlan_build_gbp_hdr() arguments instead of working around by casting away?

The reason to cast it is a WA to use ip_tunnel_info_opts which takes non-const arg while

e->tun_info here is a const one.

Quoted 23 lines
Quoted 23 lines
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c +22 -0
+     }
+
+     return 0;
+}
+
+static int mlx5e_tc_tun_parse_vxlan_gbp_option(struct mlx5e_priv *priv,
+                                            struct mlx5_flow_spec *spec,
+                                            struct flow_cls_offload *f)
+{
+     struct flow_rule *rule = flow_cls_offload_flow_rule(f);
+     struct netlink_ext_ack *extack = f->common.extack;
+     struct flow_match_enc_opts enc_opts;
+     void *misc5_c, *misc5_v;
+     u32 *gbp, *gbp_mask;
+
+     flow_rule_match_enc_opts(rule, &enc_opts);
+
+     if (memchr_inv(&enc_opts.mask->data, 0, sizeof(enc_opts.mask->data)) &&
+         !MLX5_CAP_ESW_FT_FIELD_SUPPORT_2(priv->mdev, tunnel_header_0_1)) {
+             NL_SET_ERR_MSG_MOD(extack,
+                                "Matching on VxLAN GBP is not supported");
+             netdev_warn(priv->netdev,
Quoted 8 lines

drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c static int mlx5e_gen_ip_tunnel_header_vxlan(char buf[], · line 134

Quoted 7 lines
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c +7 -0
+                         "Matching on VxLAN GBP is not supported\n");
+             return -EOPNOTSUPP;
+     }
+
+     if (enc_opts.key->dst_opt_type != TUNNEL_VXLAN_OPT) {
+             NL_SET_ERR_MSG_MOD(extack,
+                                "Wrong VxLAN option type: not GBP");

Fits into one line I believe.

ACK

Quoted 15 lines
Quoted 15 lines
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c +14 -0
+             netdev_warn(priv->netdev,
+                         "Wrong VxLAN option type: not GBP\n");
+             return -EOPNOTSUPP;
+     }
+
+     if (enc_opts.key->len != sizeof(*gbp) ||
+         enc_opts.mask->len != sizeof(*gbp_mask)) {
+             NL_SET_ERR_MSG_MOD(extack,
+                                "VxLAN GBP option/mask len is not 32 bits");
+             netdev_warn(priv->netdev,
+                         "VxLAN GBP option/mask len is not 32 bits\n");
+             return -EINVAL;
+     }
+
Quoted 8 lines

drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c static int mlx5e_gen_ip_tunnel_header_vxlan(char buf[], · line 154

Quoted 6 lines
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c +6 -0
+     gbp = (u32 *)&enc_opts.key->data[0];
+     gbp_mask = (u32 *)&enc_opts.mask->data[0];
+
+     if (*gbp_mask & ~VXLAN_GBP_MASK) {
+             NL_SET_ERR_MSG_MOD(extack,
+                                "Wrong VxLAN GBP mask");

You can use new NL_SET_ERR_MSG_FMT_MOD() here to print @gbp_mask to the user, as you do it next line.

ACK

Quoted 17 lines
Quoted 5 lines
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c +4 -0
+             netdev_warn(priv->netdev,
+                         "Wrong VxLAN GBP mask(0x%08X)\n", *gbp_mask);
+             return -EINVAL;
+     }

drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c static int mlx5e_gen_ip_tunnel_header_vxlan(char buf[], · line 168

Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c +7 -0
+
+     misc5_c = MLX5_ADDR_OF(fte_match_param, spec->match_criteria, misc_parameters_5);
+     misc5_v = MLX5_ADDR_OF(fte_match_param, spec->match_value, misc_parameters_5);
+     MLX5_SET(fte_match_set_misc5, misc5_c, tunnel_header_0, *gbp_mask);
+     MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_0, *gbp);
+
+     spec->match_criteria_enable |= MLX5_MATCH_MISC_PARAMETERS_5;
 
       return 0;
  }

Thanks,
Olek

author
#6 lore raw

Re: [PATCH net-next v1 2/3] net/mlx5e: Add helper for encap_info_equal for tunnels with options

In reply to Alexander Lobakin
Quoted 47 lines · Alexander Lobakin

External email: Use caution opening links or attachments

From: Gavin Li <[email protected]>
Date: Tue, 14 Feb 2023 15:41:36 +0200

(dropping non-existent [email protected])

Quoted 9 lines

For tunnels with options, eg, geneve and vxlan with gbp, they share the same way to compare the headers and options. Extract the code as a common function for them

Change-Id I3ea697293c8d5d66c0c20080dbde88f60bcbd62f

[...]

Quoted 28 lines
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c +20 -0
index 780224fd67a1..4df9d27a63ad 100644
@@ -571,6 +571,35 @@ bool mlx5e_tc_tun_encap_info_equal_generic(struct mlx5e_encap_key *a,
               a->tc_tunnel->tunnel_type == b->tc_tunnel->tunnel_type;
  }
 
+bool mlx5e_tc_tun_encap_info_equal_options(struct mlx5e_encap_key *a,
+                                        struct mlx5e_encap_key *b,
+                                        __be16 tun_flags)
+{
+     struct ip_tunnel_info *a_info;
+     struct ip_tunnel_info *b_info;
+     bool a_has_opts, b_has_opts;
+
+     if (!mlx5e_tc_tun_encap_info_equal_generic(a, b))
+             return false;
+
+     a_has_opts = !!(a->ip_tun_key->tun_flags & tun_flags);
+     b_has_opts = !!(b->ip_tun_key->tun_flags & tun_flags);
+
+     /* keys are equal when both don't have any options attached */
+     if (!a_has_opts && !b_has_opts)
+             return true;
+
+     if (a_has_opts != b_has_opts)
+             return false;
Quoted 8 lines

drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c bool mlx5e_tc_tun_encap_info_equal_generic(struct mlx5e_encap_key *a, · line 600

Quoted 7 lines
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c +7 -0
+
+     /* options stored in memory next to ip_tunnel_info struct */
+     a_info = container_of(a->ip_tun_key, struct ip_tunnel_info, key);
+     b_info = container_of(b->ip_tun_key, struct ip_tunnel_info, key);
+
+     return a_info->options_len == b_info->options_len &&
+             memcmp(a_info + 1, b_info + 1, a_info->options_len) == 0;

1. memcmp() is not aligned to the first expr (off-by-one to the right).

Options start from "info + 1", see ip_tunnel_info_opts and will use it here to replace the "info+1".

Quoted 1 line

2. !expr is preferred over expr == 0.

ACK

Quoted 10 lines

drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c bool mlx5e_tc_tun_encap_info_equal_generic(struct mlx5e_encap_key *a, · line 605

Quoted 6 lines
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c +2 -0
+}
+
  static int cmp_decap_info(struct mlx5e_decap_key *a,
                         struct mlx5e_decap_key *b)
  {

[...]

Thanks,
Olek

author
#13 lore raw

Re: [PATCH net-next v1 3/3] net/mlx5e: TC, Add support for VxLAN GBP encap/decap flows offload

In reply to Alexander Lobakin
Quoted 52 lines · Alexander Lobakin

External email: Use caution opening links or attachments

From: Gavin Li <[email protected]>
Date: Tue, 14 Feb 2023 15:41:37 +0200

Quoted 36 lines

Add HW offloading support for TC flows with VxLAN GBP encap/decap.

Example of encap rule:
tc filter add dev eth0 protocol ip ingress flower \
action tunnel_key set id 42 vxlan_opts 512 \
action mirred egress redirect dev vxlan1

Example of decap rule:
tc filter add dev vxlan1 protocol ip ingress flower \
enc_key_id 42 enc_dst_port 4789 vxlan_opts 1024 \
action tunnel_key unset action mirred egress redirect dev eth0

Change-Id I48f61d02201bf3f79dcbe5d0f022f7bb27ed630f
---
  .../mellanox/mlx5/core/en/tc_tun_vxlan.c      | 85 ++++++++++++++++++-
  include/linux/mlx5/device.h                   |  6 ++
  include/linux/mlx5/mlx5_ifc.h                 | 13 ++-
  3 files changed, 100 insertions(+), 4 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c +1 -0
index 1f62c702b625..444512ca9e0d 100644
@@ -1,6 +1,7 @@
  // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
  /* Copyright (c) 2018 Mellanox Technologies. */
 
+#include <net/ip_tunnels.h>
  #include <net/vxlan.h>
  #include "lib/vxlan.h"
  #include "en/tc_tun.h"

drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c static int mlx5e_gen_ip_tunnel_header_vxlan(char buf[], · line 93

Quoted 8 lines
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c +2 -1
@@ -86,9 +87,11 @@ static int mlx5e_gen_ip_tunnel_header_vxlan(char buf[],
       const struct ip_tunnel_key *tun_key = &e->tun_info->key;
       __be32 tun_id = tunnel_id_to_key32(tun_key->tun_id);
       struct udphdr *udp = (struct udphdr *)(buf);
+     const struct vxlan_metadata *md;
       struct vxlanhdr *vxh;
 
-     if (tun_key->tun_flags & TUNNEL_VXLAN_OPT)
+     if (tun_key->tun_flags & TUNNEL_VXLAN_OPT &&

A separate pair of braces is preferred around bitops.

Quoted 14 lines

drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c static int mlx5e_gen_ip_tunnel_header_vxlan(char buf[], · line 105

Quoted 12 lines
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c +5 -0
+         e->tun_info->options_len != sizeof(*md))
               return -EOPNOTSUPP;
       vxh = (struct vxlanhdr *)((char *)udp + sizeof(struct udphdr));
       *ip_proto = IPPROTO_UDP;
@@ -96,6 +99,70 @@ static int mlx5e_gen_ip_tunnel_header_vxlan(char buf[],
       udp->dest = tun_key->tp_dst;
       vxh->vx_flags = VXLAN_HF_VNI;
       vxh->vx_vni = vxlan_vni_field(tun_id);
+     if (tun_key->tun_flags & TUNNEL_VXLAN_OPT) {
+             md = ip_tunnel_info_opts((struct ip_tunnel_info *)e->tun_info);
+             vxlan_build_gbp_hdr(vxh, tun_key->tun_flags,
+                                 (struct vxlan_metadata *)md);

Maybe constify both ip_tunnel_info_opts() and vxlan_build_gbp_hdr() arguments instead of working around by casting away?

ACK. Sorry for the confusion---I misunderstood the comment.

Quoted 71 lines
Quoted 20 lines
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c +19 -0
+     }
+
+     return 0;
+}
+
+static int mlx5e_tc_tun_parse_vxlan_gbp_option(struct mlx5e_priv *priv,
+                                            struct mlx5_flow_spec *spec,
+                                            struct flow_cls_offload *f)
+{
+     struct flow_rule *rule = flow_cls_offload_flow_rule(f);
+     struct netlink_ext_ack *extack = f->common.extack;
+     struct flow_match_enc_opts enc_opts;
+     void *misc5_c, *misc5_v;
+     u32 *gbp, *gbp_mask;
+
+     flow_rule_match_enc_opts(rule, &enc_opts);
+
+     if (memchr_inv(&enc_opts.mask->data, 0, sizeof(enc_opts.mask->data)) &&
+         !MLX5_CAP_ESW_FT_FIELD_SUPPORT_2(priv->mdev, tunnel_header_0_1)) {

drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c static int mlx5e_gen_ip_tunnel_header_vxlan(char buf[], · line 134

Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c +10 -0
+             NL_SET_ERR_MSG_MOD(extack,
+                                "Matching on VxLAN GBP is not supported");
+             netdev_warn(priv->netdev,
+                         "Matching on VxLAN GBP is not supported\n");
+             return -EOPNOTSUPP;
+     }
+
+     if (enc_opts.key->dst_opt_type != TUNNEL_VXLAN_OPT) {
+             NL_SET_ERR_MSG_MOD(extack,
+                                "Wrong VxLAN option type: not GBP");

Fits into one line I believe.

Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c +10 -0
+             netdev_warn(priv->netdev,
+                         "Wrong VxLAN option type: not GBP\n");
+             return -EOPNOTSUPP;
+     }
+
+     if (enc_opts.key->len != sizeof(*gbp) ||
+         enc_opts.mask->len != sizeof(*gbp_mask)) {
+             NL_SET_ERR_MSG_MOD(extack,
+                                "VxLAN GBP option/mask len is not 32 bits");
+             netdev_warn(priv->netdev,

drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c static int mlx5e_gen_ip_tunnel_header_vxlan(char buf[], · line 154

Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c +10 -0
+                         "VxLAN GBP option/mask len is not 32 bits\n");
+             return -EINVAL;
+     }
+
+     gbp = (u32 *)&enc_opts.key->data[0];
+     gbp_mask = (u32 *)&enc_opts.mask->data[0];
+
+     if (*gbp_mask & ~VXLAN_GBP_MASK) {
+             NL_SET_ERR_MSG_MOD(extack,
+                                "Wrong VxLAN GBP mask");

You can use new NL_SET_ERR_MSG_FMT_MOD() here to print @gbp_mask to the user, as you do it next line.

Quoted 4 lines
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c +4 -0
+             netdev_warn(priv->netdev,
+                         "Wrong VxLAN GBP mask(0x%08X)\n", *gbp_mask);
+             return -EINVAL;
+     }

drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c static int mlx5e_gen_ip_tunnel_header_vxlan(char buf[], · line 168

Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c +7 -0
+
+     misc5_c = MLX5_ADDR_OF(fte_match_param, spec->match_criteria, misc_parameters_5);
+     misc5_v = MLX5_ADDR_OF(fte_match_param, spec->match_value, misc_parameters_5);
+     MLX5_SET(fte_match_set_misc5, misc5_c, tunnel_header_0, *gbp_mask);
+     MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_0, *gbp);
+
+     spec->match_criteria_enable |= MLX5_MATCH_MISC_PARAMETERS_5;
 
       return 0;
  }

Thanks,
Olek

author
#3 lore raw

Re: [PATCH net-next v1 1/3] vxlan: Expose helper vxlan_build_gbp_hdr

In reply to Alexander Lobakin
Quoted 9 lines · Alexander Lobakin

External email: Use caution opening links or attachments

From: Gavin Li <[email protected]>
Date: Tue, 14 Feb 2023 15:41:35 +0200

Quoted 2 lines

vxlan_build_gbp_hdr will be used by other modules to build gbp option in vxlan header according to gbp flags.

(not sure if it's okay to write abbreviations with non-capital)

Don't sure either but most of the functions in vxlan (if not all) are declared in this way.

Quoted 77 lines
Quoted 6 lines
Change-Id I10d8dd31d6048e1fcd08cd76ee3bcd3029053552

Besides the nit above:

Quoted 55 lines
---
  drivers/net/vxlan/vxlan_core.c | 20 --------------------
  include/net/vxlan.h            | 20 ++++++++++++++++++++
  2 files changed, 20 insertions(+), 20 deletions(-)
drivers/net/vxlan/vxlan_core.c +0 -20
index b1b179effe2a..bd44467a5a39 100644
@@ -2140,26 +2140,6 @@ static bool route_shortcircuit(struct net_device *dev, struct sk_buff *skb)
       return false;
  }
 
-static void vxlan_build_gbp_hdr(struct vxlanhdr *vxh, u32 vxflags,
-                             struct vxlan_metadata *md)
-{
-     struct vxlanhdr_gbp *gbp;
-
-     if (!md->gbp)
-             return;
-
-     gbp = (struct vxlanhdr_gbp *)vxh;
-     vxh->vx_flags |= VXLAN_HF_GBP;
-
-     if (md->gbp & VXLAN_GBP_DONT_LEARN)
-             gbp->dont_learn = 1;
-
-     if (md->gbp & VXLAN_GBP_POLICY_APPLIED)
-             gbp->policy_applied = 1;
-
-     gbp->policy_id = htons(md->gbp & VXLAN_GBP_ID_MASK);
-}
-
  static int vxlan_build_gpe_hdr(struct vxlanhdr *vxh, u32 vxflags,
                              __be16 protocol)
  {
include/net/vxlan.h +11 -0
index bca5b01af247..08bc762a7e94 100644
@@ -566,4 +566,24 @@ static inline bool vxlan_fdb_nh_path_select(struct nexthop *nh,
       return true;
  }
 
+static inline void vxlan_build_gbp_hdr(struct vxlanhdr *vxh, u32 vxflags,
+                                    struct vxlan_metadata *md)
+{
+     struct vxlanhdr_gbp *gbp;
+
+     if (!md->gbp)
+             return;
+
+     gbp = (struct vxlanhdr_gbp *)vxh;
+     vxh->vx_flags |= VXLAN_HF_GBP;
+

include/net/vxlan.h static inline bool vxlan_fdb_nh_path_select(struct nexthop *nh, · line 589

Quoted 10 lines
include/net/vxlan.h +9 -0
+     if (md->gbp & VXLAN_GBP_DONT_LEARN)
+             gbp->dont_learn = 1;
+
+     if (md->gbp & VXLAN_GBP_POLICY_APPLIED)
+             gbp->policy_applied = 1;
+
+     gbp->policy_id = htons(md->gbp & VXLAN_GBP_ID_MASK);
+}
+
  #endif

Thanks,
Olek

author
#14 lore raw

Re: [PATCH net-next v1 3/3] net/mlx5e: TC, Add support for VxLAN GBP encap/decap flows offload

In reply to Gavin Li
Quoted 57 lines · Gavin Li

External email: Use caution opening links or attachments

Quoted 53 lines · Alexander Lobakin

External email: Use caution opening links or attachments

From: Gavin Li <[email protected]>
Date: Tue, 14 Feb 2023 15:41:37 +0200

Quoted 37 lines

Add HW offloading support for TC flows with VxLAN GBP encap/decap.

Example of encap rule:
tc filter add dev eth0 protocol ip ingress flower \
     action tunnel_key set id 42 vxlan_opts 512 \
     action mirred egress redirect dev vxlan1

Example of decap rule:
tc filter add dev vxlan1 protocol ip ingress flower \
     enc_key_id 42 enc_dst_port 4789 vxlan_opts 1024 \
     action tunnel_key unset action mirred egress redirect dev eth0

Change-Id I48f61d02201bf3f79dcbe5d0f022f7bb27ed630f

---
  .../mellanox/mlx5/core/en/tc_tun_vxlan.c      | 85
++++++++++++++++++-
  include/linux/mlx5/device.h                   |  6 ++ include/linux/mlx5/mlx5_ifc.h                 | 13 ++-

  3 files changed, 100 insertions(+), 4 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c +1 -0
index 1f62c702b625..444512ca9e0d 100644
@@ -1,6 +1,7 @@
   // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
   /* Copyright (c) 2018 Mellanox Technologies. */
 
+#include <net/ip_tunnels.h>
   #include <net/vxlan.h>
   #include "lib/vxlan.h"
   #include "en/tc_tun.h"

drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c static int mlx5e_gen_ip_tunnel_header_vxlan(char · line 94

Quoted 9 lines
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c +2 -1
@@ -86,9 +87,11 @@ static int mlx5e_gen_ip_tunnel_header_vxlan(char 
 buf[],
        const struct ip_tunnel_key *tun_key = &e->tun_info->key;
        __be32 tun_id = tunnel_id_to_key32(tun_key->tun_id);
        struct udphdr *udp = (struct udphdr *)(buf);
+     const struct vxlan_metadata *md;
        struct vxlanhdr *vxh;
 
-     if (tun_key->tun_flags & TUNNEL_VXLAN_OPT)
+     if (tun_key->tun_flags & TUNNEL_VXLAN_OPT &&

A separate pair of braces is preferred around bitops.

ACK

Quoted 17 lines
Quoted 17 lines
Quoted 6 lines
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c +1 -0
+         e->tun_info->options_len != sizeof(*md))
                return -EOPNOTSUPP;
        vxh = (struct vxlanhdr *)((char *)udp + sizeof(struct udphdr));

       *ip_proto = IPPROTO_UDP;

drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c static int mlx5e_gen_ip_tunnel_header_vxlan(char · line 107

Quoted 9 lines
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c +4 -0
@@ -96,6 +99,70 @@ static int mlx5e_gen_ip_tunnel_header_vxlan(char 
 buf[],
        udp->dest = tun_key->tp_dst;
        vxh->vx_flags = VXLAN_HF_VNI;
        vxh->vx_vni = vxlan_vni_field(tun_id);
+     if (tun_key->tun_flags & TUNNEL_VXLAN_OPT) {
+             md = ip_tunnel_info_opts((struct ip_tunnel_info 
 *)e->tun_info);
+             vxlan_build_gbp_hdr(vxh, tun_key->tun_flags,
+                                 (struct vxlan_metadata *)md);

Maybe constify both ip_tunnel_info_opts() and vxlan_build_gbp_hdr() arguments instead of working around by casting away?

Quoted 1 line

ACK. Sorry for the confusion---I misunderstood the comment.

This ip_tunnel_info_opts is tricky to use const to annotate the arg because it will have to cast from const to non-const again upon returning.

Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c +7 -0
+     }
+
+     return 0;
+}
+
+static int mlx5e_tc_tun_parse_vxlan_gbp_option(struct mlx5e_priv 
 *priv,
+                                            struct mlx5_flow_spec 

*spec,
+                                            struct flow_cls_offload *f)

drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c +10 -0
+{
+     struct flow_rule *rule = flow_cls_offload_flow_rule(f);
+     struct netlink_ext_ack *extack = f->common.extack;
+     struct flow_match_enc_opts enc_opts;
+     void *misc5_c, *misc5_v;
+     u32 *gbp, *gbp_mask;
+
+     flow_rule_match_enc_opts(rule, &enc_opts);
+
+     if (memchr_inv(&enc_opts.mask->data, 0, 

sizeof(enc_opts.mask->data)) &&
+         !MLX5_CAP_ESW_FT_FIELD_SUPPORT_2(priv->mdev, tunnel_header_0_1)) {
+             NL_SET_ERR_MSG_MOD(extack,
+                                "Matching on VxLAN GBP is not supported");
+             netdev_warn(priv->netdev,

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines

+                         "Matching on VxLAN GBP is not supported\n"); +             return -EOPNOTSUPP;
+     }
+
+     if (enc_opts.key->dst_opt_type != TUNNEL_VXLAN_OPT) { +             NL_SET_ERR_MSG_MOD(extack,
+                                "Wrong VxLAN option type: not GBP");

Fits into one line I believe.

ACK

Quoted 17 lines
Quoted 17 lines
Quoted 17 lines

+ netdev_warn(priv->netdev,
+                         "Wrong VxLAN option type: not GBP\n"); +             return -EOPNOTSUPP;
+     }
+
+     if (enc_opts.key->len != sizeof(*gbp) ||
+         enc_opts.mask->len != sizeof(*gbp_mask)) {
+             NL_SET_ERR_MSG_MOD(extack,
+                                "VxLAN GBP option/mask len is not 32 bits");
+             netdev_warn(priv->netdev,
+                         "VxLAN GBP option/mask len is not 32 bits\n");
+             return -EINVAL;
+     }
+

Quoted 8 lines
Quoted 8 lines
Quoted 6 lines

+     gbp = (u32 *)&enc_opts.key->data[0];
+     gbp_mask = (u32 *)&enc_opts.mask->data[0]; +
+     if (*gbp_mask & ~VXLAN_GBP_MASK) {
+             NL_SET_ERR_MSG_MOD(extack,
+                                "Wrong VxLAN GBP mask");

You can use new NL_SET_ERR_MSG_FMT_MOD() here to print @gbp_mask to the user, as you do it next line.

ACK

Quoted 20 lines
Quoted 20 lines
Quoted 16 lines

+ netdev_warn(priv->netdev,
+                         "Wrong VxLAN GBP mask(0x%08X)\n", *gbp_mask); +             return -EINVAL;
+     }
+
+     misc5_c = MLX5_ADDR_OF(fte_match_param, spec->match_criteria, misc_parameters_5);
+     misc5_v = MLX5_ADDR_OF(fte_match_param, spec->match_value, misc_parameters_5);
+     MLX5_SET(fte_match_set_misc5, misc5_c, tunnel_header_0, *gbp_mask);
+     MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_0, *gbp); +
+     spec->match_criteria_enable |= MLX5_MATCH_MISC_PARAMETERS_5;

Quoted 2 lines

       return 0;
  }

Thanks,
Olek

#12 lore raw

Re: [PATCH net-next v1 3/3] net/mlx5e: TC, Add support for VxLAN GBP encap/decap flows offload

In reply to Gavin Li

From: Gavin Li <[email protected]>
Date: Wed, 15 Feb 2023 10:50:04 +0800

Quoted 9 lines · Alexander Lobakin
Quoted 7 lines

External email: Use caution opening links or attachments

From: Gavin Li <[email protected]>
Date: Tue, 14 Feb 2023 15:41:37 +0200

Quoted 1 line

Add HW offloading support for TC flows with VxLAN GBP encap/decap.

[...]

Quoted 12 lines
Quoted 4 lines
Quoted 4 lines
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c +0 -0
@@ -96,6 +99,70 @@ static int mlx5e_gen_ip_tunnel_header_vxlan(char
 buf[],
        udp->dest = tun_key->tp_dst;
        vxh->vx_flags = VXLAN_HF_VNI;
Quoted 8 lines

drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c static int mlx5e_gen_ip_tunnel_header_vxlan(char buf[], · line 105

Quoted 6 lines
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c +4 -0
        vxh->vx_vni = vxlan_vni_field(tun_id);
+     if (tun_key->tun_flags & TUNNEL_VXLAN_OPT) {
+             md = ip_tunnel_info_opts((struct ip_tunnel_info
 *)e->tun_info);
+             vxlan_build_gbp_hdr(vxh, tun_key->tun_flags,
+                                 (struct vxlan_metadata *)md);

Maybe constify both ip_tunnel_info_opts() and vxlan_build_gbp_hdr() arguments instead of working around by casting away?

Quoted 3 lines

The reason to cast it is a WA to use ip_tunnel_info_opts which takes non-const arg while>
e->tun_info here is a const one.

That's what I'm asking - why not make ip_tunnel_info_opts() and vxlan_build_gbp_hdr() take const tun_info?

Quoted 6 lines
Quoted 6 lines

drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c static int mlx5e_gen_ip_tunnel_header_vxlan(char buf[], · line 109

Quoted 6 lines
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c +4 -0
+     }
+
+     return 0;
+}

[...]

Thanks,
Olek

#7 lore raw

Re: [PATCH net-next v1 2/3] net/mlx5e: Add helper for encap_info_equal for tunnels with options

In reply to Gavin Li

From: Gavin Li <[email protected]>
Date: Wed, 15 Feb 2023 10:54:12 +0800

Quoted 7 lines · Alexander Lobakin
Quoted 5 lines

External email: Use caution opening links or attachments

From: Gavin Li <[email protected]>
Date: Tue, 14 Feb 2023 15:41:36 +0200

[...]

Quoted 10 lines
Quoted 10 lines

drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c bool mlx5e_tc_tun_encap_info_equal_generic(struct mlx5e_encap_key *a, · line 600

Quoted 9 lines

+     if (a_has_opts != b_has_opts)
+             return false;

drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c +7 -0
+
+     /* options stored in memory next to ip_tunnel_info struct */
+     a_info = container_of(a->ip_tun_key, struct ip_tunnel_info, key);
+     b_info = container_of(b->ip_tun_key, struct ip_tunnel_info, key);
+
+     return a_info->options_len == b_info->options_len &&
+             memcmp(a_info + 1, b_info + 1, a_info->options_len) == 0;

1. memcmp() is not aligned to the first expr (off-by-one to the right).

Quoted 2 lines

Options start from "info + 1", see ip_tunnel_info_opts and will use it here to replace the "info+1".

Nah, I mean the following. Your code:

	return a_info->options_len == b_info->options_len &&
		memcmp(a_info + 1, b_info + 1, ...

should be:

	return a_info->options_len == b_info->options_len &&
	       memcmp(a_info + 1, b_info + 1, ...

7 spaces instead of a tab to have it aligned to the prev line.

Quoted 12 lines
Quoted 1 line

2. !expr is preferred over expr == 0.

ACK

Quoted 10 lines
Quoted 6 lines
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c +2 -0
+}
+

  static int cmp_decap_info(struct mlx5e_decap_key *a, struct mlx5e_decap_key *b) {

[...]

Thanks,
Olek

Thanks,
Olek

#19 lore raw

Re: [PATCH net-next v1 3/3] net/mlx5e: TC, Add support for VxLAN GBP encap/decap flows offload

In reply to Gavin Li

From: Gavin Li <[email protected]>
Date: Wed, 15 Feb 2023 11:36:24 +0800

Quoted 7 lines · Alexander Lobakin
Quoted 5 lines

External email: Use caution opening links or attachments

From: Gavin Li <[email protected]>
Date: Tue, 14 Feb 2023 15:41:37 +0200

[...]

Quoted 12 lines
Quoted 4 lines
Quoted 4 lines
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c +0 -0
@@ -96,6 +99,70 @@ static int mlx5e_gen_ip_tunnel_header_vxlan(char
 buf[],
        udp->dest = tun_key->tp_dst;
        vxh->vx_flags = VXLAN_HF_VNI;
Quoted 8 lines

drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c static int mlx5e_gen_ip_tunnel_header_vxlan(char buf[], · line 105

Quoted 6 lines
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c +4 -0
        vxh->vx_vni = vxlan_vni_field(tun_id);
+     if (tun_key->tun_flags & TUNNEL_VXLAN_OPT) {
+             md = ip_tunnel_info_opts((struct ip_tunnel_info
 *)e->tun_info);
+             vxlan_build_gbp_hdr(vxh, tun_key->tun_flags,
+                                 (struct vxlan_metadata *)md);

Maybe constify both ip_tunnel_info_opts() and vxlan_build_gbp_hdr() arguments instead of working around by casting away?

Quoted 1 line

ACK. Sorry for the confusion---I misunderstood the comment.

Ah, no worries :D Sorry that I sent the prev mail and only then opened this one.

Quoted 5 lines
Quoted 5 lines

drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c static int mlx5e_gen_ip_tunnel_header_vxlan(char buf[], · line 109

Quoted 5 lines
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c +4 -0
+     }
+
+     return 0;
+}

Thanks,
Olek

#15 lore raw

Re: [PATCH net-next v1 3/3] net/mlx5e: TC, Add support for VxLAN GBP encap/decap flows offload

In reply to Gavin Li

From: Gavin Li <[email protected]>
Date: Wed, 15 Feb 2023 16:30:04 +0800

Quoted 11 lines · Gavin Li
Quoted 9 lines

External email: Use caution opening links or attachments

Quoted 5 lines · Alexander Lobakin

External email: Use caution opening links or attachments

From: Gavin Li <[email protected]>
Date: Tue, 14 Feb 2023 15:41:37 +0200

[...]

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines

drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c static int mlx5e_gen_ip_tunnel_header_vxlan(char · line 107

Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c +4 -0
@@ -96,6 +99,70 @@ static int mlx5e_gen_ip_tunnel_header_vxlan(char
 buf[],
        udp->dest = tun_key->tp_dst;
        vxh->vx_flags = VXLAN_HF_VNI;
        vxh->vx_vni = vxlan_vni_field(tun_id);
+     if (tun_key->tun_flags & TUNNEL_VXLAN_OPT) {
+             md = ip_tunnel_info_opts((struct ip_tunnel_info
 *)e->tun_info);
+             vxlan_build_gbp_hdr(vxh, tun_key->tun_flags,
+                                 (struct vxlan_metadata *)md);

Maybe constify both ip_tunnel_info_opts() and vxlan_build_gbp_hdr() arguments instead of working around by casting away?

Quoted 3 lines
Quoted 1 line

ACK. Sorry for the confusion---I misunderstood the comment.

This ip_tunnel_info_opts is tricky to use const to annotate the arg because it will have to cast from const to non-const again upon returning.

It's okay to cast away for the void * returned. Alternatively, use can convert it to a macro and use __builtin_choose_expr() or _Generic to return const or non-const depending on whether the argument is constant. That's what was recently done for container_of() IIRC.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c static int mlx5e_gen_ip_tunnel_header_vxlan(char buf[], · line 109

Quoted 5 lines
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c +4 -0
+     }
+
+     return 0;
+}

[...]

Thanks,
Olek

author
#16 lore raw

Re: [PATCH net-next v1 3/3] net/mlx5e: TC, Add support for VxLAN GBP encap/decap flows offload

Quoted 30 lines · Alexander Lobakin

External email: Use caution opening links or attachments

From: Gavin Li <[email protected]>
Date: Wed, 15 Feb 2023 16:30:04 +0800

Quoted 10 lines · Gavin Li
Quoted 9 lines

External email: Use caution opening links or attachments

Quoted 5 lines · Alexander Lobakin

External email: Use caution opening links or attachments

From: Gavin Li <[email protected]>
Date: Tue, 14 Feb 2023 15:41:37 +0200

[...]

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines

drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c static int mlx5e_gen_ip_tunnel_header_vxlan(char · line 107

Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c +4 -0
@@ -96,6 +99,70 @@ static int mlx5e_gen_ip_tunnel_header_vxlan(char
 buf[],
        udp->dest = tun_key->tp_dst;
        vxh->vx_flags = VXLAN_HF_VNI;
        vxh->vx_vni = vxlan_vni_field(tun_id);
+     if (tun_key->tun_flags & TUNNEL_VXLAN_OPT) {
+             md = ip_tunnel_info_opts((struct ip_tunnel_info
 *)e->tun_info);
+             vxlan_build_gbp_hdr(vxh, tun_key->tun_flags,
+                                 (struct vxlan_metadata *)md);

Maybe constify both ip_tunnel_info_opts() and vxlan_build_gbp_hdr() arguments instead of working around by casting away?

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

ACK. Sorry for the confusion---I misunderstood the comment.

This ip_tunnel_info_opts is tricky to use const to annotate the arg because it will have to cast from const to non-const again upon returning.

It's okay to cast away for the void * returned. Alternatively, use can convert it to a macro and use __builtin_choose_expr() or _Generic to return const or non-const depending on whether the argument is constant. That's what was recently done for container_of() IIRC.

I've fixed vxlan_build_gbp_hdr in V2. For ip_tunnel_info_opts, it's confusing to me.

It would be as below after constifying the parameter.

static inline void *ip_tunnel_info_opts(const struct ip_tunnel_info *info) {
    return (void *)(info + 1);
}
Is there any value gained by this change?

Quoted 9 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c static int mlx5e_gen_ip_tunnel_header_vxlan(char buf[], · line 109

Quoted 5 lines
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c +4 -0
+     }
+
+     return 0;
+}

[...]

Thanks,
Olek

#17 lore raw

Re: [PATCH net-next v1 3/3] net/mlx5e: TC, Add support for VxLAN GBP encap/decap flows offload

From: Gavin Li <[email protected]>
Date: Thu, 16 Feb 2023 16:40:33 +0800

Quoted 45 lines · Alexander Lobakin
Quoted 31 lines

External email: Use caution opening links or attachments

From: Gavin Li <[email protected]>
Date: Wed, 15 Feb 2023 16:30:04 +0800

Quoted 10 lines · Gavin Li
Quoted 9 lines

External email: Use caution opening links or attachments

Quoted 5 lines · Alexander Lobakin

External email: Use caution opening links or attachments

From: Gavin Li <[email protected]>
Date: Tue, 14 Feb 2023 15:41:37 +0200

[...]

Quoted 13 lines
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c +0 -0
@@ -96,6 +99,70 @@ static int mlx5e_gen_ip_tunnel_header_vxlan(char
 buf[],
         udp->dest = tun_key->tp_dst;
         vxh->vx_flags = VXLAN_HF_VNI;
Quoted 8 lines

drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c static int mlx5e_gen_ip_tunnel_header_vxlan(char buf[], · line 105

Quoted 6 lines
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c +4 -0
         vxh->vx_vni = vxlan_vni_field(tun_id);
+     if (tun_key->tun_flags & TUNNEL_VXLAN_OPT) {
+             md = ip_tunnel_info_opts((struct ip_tunnel_info
 *)e->tun_info);
+             vxlan_build_gbp_hdr(vxh, tun_key->tun_flags,
+                                 (struct vxlan_metadata *)md);

Maybe constify both ip_tunnel_info_opts() and vxlan_build_gbp_hdr() arguments instead of working around by casting away?

ACK. Sorry for the confusion---I misunderstood the comment.

Quoted 8 lines
Quoted 3 lines

This ip_tunnel_info_opts is tricky to use const to annotate the arg because it will have to cast from const to non-const again upon returning.

It's okay to cast away for the void * returned. Alternatively, use can convert it to a macro and use __builtin_choose_expr() or _Generic to return const or non-const depending on whether the argument is constant. That's what was recently done for container_of() IIRC.

I've fixed vxlan_build_gbp_hdr in V2. For ip_tunnel_info_opts, it's confusing to me.

Quoted 7 lines

It would be as below after constifying the parameter.

static inline void *ip_tunnel_info_opts(const struct ip_tunnel_info *info) {
    return (void *)(info + 1);
}
Is there any value gained by this change?

You wouldn't need to W/A it each time in each driver, just do it once in the inline itself.
I did it once in __skb_header_pointer()[0] to be able to pass data pointer as const to optimize code a bit and point out explicitly that the function doesn't modify the packet anyhow, don't see any reason to not do the same here.
Or, as I said, you can use macros + __builtin_choose_expr() or _Generic. container_of_const() uses the latter[1]. A __builtin_choose_expr() variant could rely on the __same_type() macro to check whether the pointer passed from the driver const or not.

Quoted 10 lines
Quoted 10 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c static int mlx5e_gen_ip_tunnel_header_vxlan(char buf[], · line 109

Quoted 6 lines
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c +4 -0
+     }
+
+     return 0;
+}

[...]

Thanks,
Olek

[0]
https://elixir.bootlin.com/linux/v6.2-rc8/source/include/linux/skbuff.h#L3992
[1]
https://elixir.bootlin.com/linux/v6.2-rc8/source/include/linux/container_of.h#L33

Thanks,
Olek

author
#18 lore raw

Re: [PATCH net-next v1 3/3] net/mlx5e: TC, Add support for VxLAN GBP encap/decap flows offload

Quoted 56 lines · Alexander Lobakin

External email: Use caution opening links or attachments

From: Gavin Li <[email protected]>
Date: Thu, 16 Feb 2023 16:40:33 +0800

Quoted 43 lines · Alexander Lobakin
Quoted 31 lines

External email: Use caution opening links or attachments

From: Gavin Li <[email protected]>
Date: Wed, 15 Feb 2023 16:30:04 +0800

Quoted 10 lines · Gavin Li
Quoted 9 lines

External email: Use caution opening links or attachments

Quoted 5 lines · Alexander Lobakin

External email: Use caution opening links or attachments

From: Gavin Li <[email protected]>
Date: Tue, 14 Feb 2023 15:41:37 +0200

[...]

Quoted 13 lines
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
(quoted diff) +0 -0
@@ -96,6 +99,70 @@ static int mlx5e_gen_ip_tunnel_header_vxlan(char
 buf[],
         udp->dest = tun_key->tp_dst;
         vxh->vx_flags = VXLAN_HF_VNI;
Quoted 8 lines

Review static int mlx5e_gen_ip_tunnel_header_vxlan(char · line 107

Quoted 6 lines
(quoted diff) +4 -0
         vxh->vx_vni = vxlan_vni_field(tun_id);
+     if (tun_key->tun_flags & TUNNEL_VXLAN_OPT) {
+             md = ip_tunnel_info_opts((struct ip_tunnel_info
 *)e->tun_info);
+             vxlan_build_gbp_hdr(vxh, tun_key->tun_flags,
+                                 (struct vxlan_metadata *)md);

Maybe constify both ip_tunnel_info_opts() and vxlan_build_gbp_hdr() arguments instead of working around by casting away?

ACK. Sorry for the confusion---I misunderstood the comment.

Quoted 8 lines
Quoted 3 lines

This ip_tunnel_info_opts is tricky to use const to annotate the arg because it will have to cast from const to non-const again upon returning.

It's okay to cast away for the void * returned. Alternatively, use can convert it to a macro and use __builtin_choose_expr() or _Generic to return const or non-const depending on whether the argument is constant. That's what was recently done for container_of() IIRC.

I've fixed vxlan_build_gbp_hdr in V2. For ip_tunnel_info_opts, it's confusing to me.

Quoted 7 lines

It would be as below after constifying the parameter.

static inline void *ip_tunnel_info_opts(const struct ip_tunnel_info *info)

{
     return (void *)(info + 1);
}

Is there any value gained by this change?

Quoted 10 lines

You wouldn't need to W/A it each time in each driver, just do it once in the inline itself.
I did it once in __skb_header_pointer()[0] to be able to pass data pointer as const to optimize code a bit and point out explicitly that the function doesn't modify the packet anyhow, don't see any reason to not do the same here.
Or, as I said, you can use macros + __builtin_choose_expr() or _Generic. container_of_const() uses the latter[1]. A __builtin_choose_expr() variant could rely on the __same_type() macro to check whether the pointer passed from the driver const or not.

ACK

Quoted 16 lines
Quoted 9 lines
Quoted 9 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Review static int mlx5e_gen_ip_tunnel_header_vxlan(char · line 111

Quoted 5 lines
(quoted diff) +4 -0
+     }
+
+     return 0;
+}

[...]

Thanks,
Olek

[0]
https://elixir.bootlin.com/linux/v6.2-rc8/source/include/linux/skbuff.h#L3992
[1]
https://elixir.bootlin.com/linux/v6.2-rc8/source/include/linux/container_of.h#L33

Thanks,
Olek

author
#8 lore raw

Re: [PATCH net-next v1 2/3] net/mlx5e: Add helper for encap_info_equal for tunnels with options

In reply to Alexander Lobakin
Quoted 31 lines · Alexander Lobakin

External email: Use caution opening links or attachments

From: Gavin Li <[email protected]>
Date: Wed, 15 Feb 2023 10:54:12 +0800

Quoted 6 lines · Alexander Lobakin
Quoted 5 lines

External email: Use caution opening links or attachments

From: Gavin Li <[email protected]>
Date: Tue, 14 Feb 2023 15:41:36 +0200

[...]

Quoted 10 lines
Quoted 10 lines

drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c bool mlx5e_tc_tun_encap_info_equal_generic(struct mlx5e_encap_key *a, · line 600

Quoted 9 lines
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c +9 -0
+     if (a_has_opts != b_has_opts)
+             return false;
+
+     /* options stored in memory next to ip_tunnel_info struct */
+     a_info = container_of(a->ip_tun_key, struct ip_tunnel_info, key);
+     b_info = container_of(b->ip_tun_key, struct ip_tunnel_info, key);
+
+     return a_info->options_len == b_info->options_len &&
+             memcmp(a_info + 1, b_info + 1, a_info->options_len) == 0;

1. memcmp() is not aligned to the first expr (off-by-one to the right).

Quoted 2 lines

Options start from "info + 1", see ip_tunnel_info_opts and will use it here to replace the "info+1".

Nah, I mean the following. Your code:

         return a_info->options_len == b_info->options_len &&
                 memcmp(a_info + 1, b_info + 1, ...
Quoted 6 lines

should be:

         return a_info->options_len == b_info->options_len &&
                memcmp(a_info + 1, b_info + 1, ...

7 spaces instead of a tab to have it aligned to the prev line.

ACK

Quoted 14 lines
Quoted 12 lines
Quoted 2 lines

2. !expr is preferred over expr == 0.

ACK

Quoted 9 lines

drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c bool mlx5e_tc_tun_encap_info_equal_generic(struct mlx5e_encap_key *a, · line 605

Quoted 5 lines
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c +2 -0
+}
+
   static int cmp_decap_info(struct mlx5e_decap_key *a,
                          struct mlx5e_decap_key *b)
   {

[...]

Thanks,
Olek

Thanks,
Olek