2023-02-14 13:44:06

by Gavin Li

[permalink] [raw]
Subject: [PATCH net-next v1 0/3] 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(-)

--
2.31.1



2023-02-14 13:44:48

by Gavin Li

[permalink] [raw]
Subject: [PATCH net-next v1 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
Signed-off-by: Gavin Li <[email protected]>
Reviewed-by: Roi Dayan <[email protected]>
Reviewed-by: Maor Dickman <[email protected]>
Acked-by: Saeed Mahameed <[email protected]>
---
drivers/net/vxlan/vxlan_core.c | 20 --------------------
include/net/vxlan.h | 20 ++++++++++++++++++++
2 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/drivers/net/vxlan/vxlan_core.c b/drivers/net/vxlan/vxlan_core.c
index b1b179effe2a..bd44467a5a39 100644
--- a/drivers/net/vxlan/vxlan_core.c
+++ b/drivers/net/vxlan/vxlan_core.c
@@ -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)
{
diff --git a/include/net/vxlan.h b/include/net/vxlan.h
index bca5b01af247..08bc762a7e94 100644
--- a/include/net/vxlan.h
+++ b/include/net/vxlan.h
@@ -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
--
2.31.1


2023-02-14 13:44:50

by Gavin Li

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

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
Signed-off-by: Gavin Li <[email protected]>
Reviewed-by: Roi Dayan <[email protected]>
Reviewed-by: Maor Dickman <[email protected]>
Acked-by: Saeed Mahameed <[email protected]>
---
.../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(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.h b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.h
index b38f693bbb52..92065568bb19 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.h
@@ -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__
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c
index 780224fd67a1..4df9d27a63ad 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c
@@ -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)
{
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_geneve.c b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_geneve.c
index 054d80c4e65c..2bcd10b6d653 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_geneve.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_geneve.c
@@ -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 = {
--
2.31.1


2023-02-14 14:58:36

by Alexander Lobakin

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

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

> 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)

>
> Change-Id: I10d8dd31d6048e1fcd08cd76ee3bcd3029053552
> Signed-off-by: Gavin Li <[email protected]>
> Reviewed-by: Roi Dayan <[email protected]>
> Reviewed-by: Maor Dickman <[email protected]>
> Acked-by: Saeed Mahameed <[email protected]>

Besides the nit above:

Reviewed-by: Alexander Lobakin <[email protected]>

> ---
> drivers/net/vxlan/vxlan_core.c | 20 --------------------
> include/net/vxlan.h | 20 ++++++++++++++++++++
> 2 files changed, 20 insertions(+), 20 deletions(-)
>
> diff --git a/drivers/net/vxlan/vxlan_core.c b/drivers/net/vxlan/vxlan_core.c
> index b1b179effe2a..bd44467a5a39 100644
> --- a/drivers/net/vxlan/vxlan_core.c
> +++ b/drivers/net/vxlan/vxlan_core.c
> @@ -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)
> {
> diff --git a/include/net/vxlan.h b/include/net/vxlan.h
> index bca5b01af247..08bc762a7e94 100644
> --- a/include/net/vxlan.h
> +++ b/include/net/vxlan.h
> @@ -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

Thanks,
Olek

2023-02-14 15:03:08

by Alexander Lobakin

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

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

(dropping non-existent [email protected])

> 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
> Signed-off-by: Gavin Li <[email protected]>
> Reviewed-by: Roi Dayan <[email protected]>
> Reviewed-by: Maor Dickman <[email protected]>
> Acked-by: Saeed Mahameed <[email protected]>

[...]

> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c
> index 780224fd67a1..4df9d27a63ad 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c
> @@ -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;

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

> +}
> +
> static int cmp_decap_info(struct mlx5e_decap_key *a,
> struct mlx5e_decap_key *b)
> {
[...]

Thanks,
Olek 

2023-02-15 02:54:38

by Gavin Li

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


On 2/14/2023 11:01 PM, Alexander Lobakin wrote:
> 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])
>
>> 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
>> Signed-off-by: Gavin Li <[email protected]>
>> Reviewed-by: Roi Dayan <[email protected]>
>> Reviewed-by: Maor Dickman <[email protected]>
>> Acked-by: Saeed Mahameed <[email protected]>
> [...]
>
>> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c
>> index 780224fd67a1..4df9d27a63ad 100644
>> --- a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c
>> +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c
>> @@ -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;
> 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".
> 2. `!expr` is preferred over `expr == 0`.
ACK
>
>> +}
>> +
>> static int cmp_decap_info(struct mlx5e_decap_key *a,
>> struct mlx5e_decap_key *b)
>> {
> [...]
>
> Thanks,
> Olek

2023-02-15 08:26:57

by Gavin Li

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


On 2/14/2023 10:56 PM, Alexander Lobakin wrote:
> External email: Use caution opening links or attachments
>
>
> From: Gavin Li <[email protected]>
> Date: Tue, 14 Feb 2023 15:41:35 +0200
>
>> 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.
>
>> Change-Id: I10d8dd31d6048e1fcd08cd76ee3bcd3029053552
>> Signed-off-by: Gavin Li <[email protected]>
>> Reviewed-by: Roi Dayan <[email protected]>
>> Reviewed-by: Maor Dickman <[email protected]>
>> Acked-by: Saeed Mahameed <[email protected]>
> Besides the nit above:
>
> Reviewed-by: Alexander Lobakin <[email protected]>
>
>> ---
>> drivers/net/vxlan/vxlan_core.c | 20 --------------------
>> include/net/vxlan.h | 20 ++++++++++++++++++++
>> 2 files changed, 20 insertions(+), 20 deletions(-)
>>
>> diff --git a/drivers/net/vxlan/vxlan_core.c b/drivers/net/vxlan/vxlan_core.c
>> index b1b179effe2a..bd44467a5a39 100644
>> --- a/drivers/net/vxlan/vxlan_core.c
>> +++ b/drivers/net/vxlan/vxlan_core.c
>> @@ -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)
>> {
>> diff --git a/include/net/vxlan.h b/include/net/vxlan.h
>> index bca5b01af247..08bc762a7e94 100644
>> --- a/include/net/vxlan.h
>> +++ b/include/net/vxlan.h
>> @@ -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
> Thanks,
> Olek

2023-02-15 16:57:57

by Alexander Lobakin

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

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

>
> On 2/14/2023 11:01 PM, Alexander Lobakin wrote:
>> External email: Use caution opening links or attachments
>>
>>
>> From: Gavin Li <[email protected]>
>> Date: Tue, 14 Feb 2023 15:41:36 +0200

[...]

>>> +     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).
> 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.

>> 2. `!expr` is preferred over `expr == 0`.
> ACK
>>
>>> +}
>>> +
>>>   static int cmp_decap_info(struct mlx5e_decap_key *a,
>>>                          struct mlx5e_decap_key *b)
>>>   {
>> [...]
>>
>> Thanks,
>> Olek
Thanks,
Olek

2023-02-20 11:32:11

by Gavin Li

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


On 2/16/2023 12:56 AM, Alexander Lobakin wrote:
> External email: Use caution opening links or attachments
>
>
> From: Gavin Li <[email protected]>
> Date: Wed, 15 Feb 2023 10:54:12 +0800
>
>> On 2/14/2023 11:01 PM, Alexander Lobakin wrote:
>>> External email: Use caution opening links or attachments
>>>
>>>
>>> From: Gavin Li <[email protected]>
>>> Date: Tue, 14 Feb 2023 15:41:36 +0200
> [...]
>
>>>> + 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).
>> 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.
ACK
>
>>> 2. `!expr` is preferred over `expr == 0`.
>> ACK
>>>> +}
>>>> +
>>>> static int cmp_decap_info(struct mlx5e_decap_key *a,
>>>> struct mlx5e_decap_key *b)
>>>> {
>>> [...]
>>>
>>> Thanks,
>>> Olek
> Thanks,
> Olek