net/mlx5: fix the eCPRI common header endianness
PATCH 1/1 net/mlx5: fix the eCPRI common header endianness
The input header of a RTE flow item is with network byte order. In the host with little endian, the bit field order are the same as the byte order.
When checking the an eCPRI message type, the wrong field will be selected. Right now, since the whole u32 is being checked and for all types, the following implementation is unique. There is no functional risk but it is still an error to fix.
--- drivers/net/mlx5/mlx5_flow_dv.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/mlx5/mlx5_flow_dv.c +3 -1
@@ -7798,6 +7798,7 @@ struct mlx5_hlist_entry *struct mlx5_priv *priv = dev->data->dev_private;const struct rte_flow_item_ecpri *ecpri_m = item->mask;const struct rte_flow_item_ecpri *ecpri_v = item->spec; +struct rte_ecpri_common_hdr common;void *misc4_m =MLX5_ADDR_OF (fte_match_param, matcher, misc_parameters_4);void *misc4_v =MLX5_ADDR_OF (fte_match_param, key, misc_parameters_4);
@@ -7838,7 +7839,8 @@ struct mlx5_hlist_entry ** Some wildcard rules only matching type field should be supported. */ if (ecpri_m->hdr.dummy[0 ]) { -switch (ecpri_v->hdr.common.type) { + common.u32 =rte_be_to_cpu_32 (ecpri_v->hdr.common.u32); +switch (common.type) {case RTE_ECPRI_MSG_TYPE_IQ_DATA :case RTE_ECPRI_MSG_TYPE_RTC_CTRL :case RTE_ECPRI_MSG_TYPE_DLY_MSR :
Signature · 1 line
1.8.3.1
Hi,
Quoted 19 lines
-----Original Message-----
From: Bing Zhao <[email protected]>
Sent: Tuesday, November 3, 2020 7:42 AM
To: Slava Ovsiienko <[email protected]>; Matan Azrad <[email protected]>
Cc: [email protected]; Ori Kam <[email protected]>; Raslan Darawsheh <[email protected]>; [email protected]
Subject: [PATCH] net/mlx5: fix the eCPRI common header endiannessThe input header of a RTE flow item is with network byte order. In the host with little endian, the bit field order are the same as the byte order.
When checking the an eCPRI message type, the wrong field will be selected. Right now, since the whole u32 is being checked and for all types, the following implementation is unique. There is no functional risk but it is still an error to fix.Fixes daa38a8924a0 ("net/mlx5: add flow translation of eCPRI header")
Quoted 8 lines
Signed-off-by Bing Zhao <[email protected]>--- drivers/net/mlx5/mlx5_flow_dv.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
Patch applied to next-net-mlx,
Kindest regards,
Raslan Darawsheh
Quoted 8 lines · Bing Zhao
The input header of a RTE flow item is with network byte order. In the host with little endian, the bit field order are the same as the byte order.
When checking the an eCPRI message type, the wrong field will be selected. Right now, since the whole u32 is being checked and for all types, the following implementation is unique. There is no functional risk but it is still an error to fix.
Isn't the 'ecpri_v' filled by application (CPU), why there is an assumption that it is big endian?
And even if it is big endian, it should be broken previously right? Since it was checking wrong field as 'type' as you said, why there were no functional risk?
Quoted 34 lines
Fixes daa38a8924a0 ("net/mlx5: add flow translation of eCPRI header")Signed-off-by Bing Zhao <[email protected]>--- drivers/net/mlx5/mlx5_flow_dv.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/net/mlx5/mlx5_flow_dv.c +3
-1@@ -7798,6 +7798,7 @@ struct mlx5_hlist_entry *struct mlx5_priv *priv = dev->data->dev_private;const struct rte_flow_item_ecpri *ecpri_m = item->mask;const struct rte_flow_item_ecpri *ecpri_v = item->spec; +struct rte_ecpri_common_hdr common;void *misc4_m =MLX5_ADDR_OF (fte_match_param, matcher, misc_parameters_4);void *misc4_v =MLX5_ADDR_OF (fte_match_param, key, misc_parameters_4);@@ -7838,7 +7839,8 @@ struct mlx5_hlist_entry ** Some wildcard rules only matching type field should be supported. */ if (ecpri_m->hdr.dummy[0 ]) { -switch (ecpri_v->hdr.common.type) { + common.u32 =rte_be_to_cpu_32 (ecpri_v->hdr.common.u32); +switch (common.type) {case RTE_ECPRI_MSG_TYPE_IQ_DATA :case RTE_ECPRI_MSG_TYPE_RTC_CTRL :case RTE_ECPRI_MSG_TYPE_DLY_MSR :
Hi Ferruh,
Thanks for your review and comments, PSB.
Quoted 21 lines
-----Original Message-----
From: Ferruh Yigit <[email protected]>
Sent: Friday, November 6, 2020 7:20 PM
To: Bing Zhao <[email protected]>; Slava Ovsiienko <[email protected]>; Matan Azrad <[email protected]>
Cc: [email protected]; Ori Kam <[email protected]>; Raslan Darawsheh <[email protected]>; [email protected]
Subject: Re: [dpdk-dev] [PATCH] net/mlx5: fix the eCPRI common header endiannessExternal email: Use caution opening links or attachments
Quoted 1 line · Bing Zhao
The input header of a RTE flow item is with network byte order. In
the
Quoted 1 line
host with little endian, the bit field order are the same as the
byte
Quoted 3 lines
order.
When checking the an eCPRI message type, the wrong field will be selected. Right now, since the whole u32 is being checked and for
Quoted 9 lines
all
Quoted 1 line
types, the following implementation is unique. There is no
functional
Quoted 2 lines
risk but it is still an error to fix.
Isn't the '
ecpri_v' filled by application (CPU), why there is an assumption that it is big endian?
Yes, this is filled by the application SW. I checked the current code of other headers and current implementation.
1. In the testpmd flow example, all the headers of network stack like IPv4 are translated into to be in BE, "ARGS_ENTRY_HTON"
2. All fields are with "rte_be*_t"type, even though only a typedef, it should be considered in BE.
3. RTE flow will just pass the flow items pointer to the PMD drivers, so in the PMD part, the headers should be treated as in BE. So, to my understanding, this is not an assumption but some constraint.
Correct me if my understanding is wrong.
Quoted 3 lines
And even if it is big endian, it should be broken previously right? Since it was checking wrong field as 'type' as you said, why there were no functional risk?
In the PMD driver, the first u32 *value containing this type is already used for matching. And a checking is used for the following "sub-headers" matching. Indeed, the first u32 *mask is used to confirm if the following sub-header need to be matched.
Since different types will lead to different variants of the packets, the switch-of-type is used.
But all the 3 types supported in PMD now almost have the same results (part of the second u32, remaining will be all 0s). So even if the type of the value is always "0" by mistake, the cases are the same and it still works by coincidence.
If more types are supported in the future, this will be problematic.
Quoted 39 lines
Quoted 3 lines
Fixes daa38a8924a0 ("net/mlx5: add flow translation of eCPRIheader")
Quoted 21 lines
Signed-off-by Bing Zhao <[email protected]>--- drivers/net/mlx5/mlx5_flow_dv.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)(quoted diff) +0
-0
b/drivers/net/mlx5/mlx5_flow_dv.cindex 01b6e7c..7af01e9 100644drivers/net/mlx5/mlx5_flow_dv.c +1
-0@@ -7798,6 +7798,7 @@ struct mlx5_hlist_entry *struct mlx5_priv *priv = dev->data->dev_private;const struct rte_flow_item_ecpri *ecpri_m = item->mask;const struct rte_flow_item_ecpri *ecpri_v = item->spec; +struct rte_ecpri_common_hdr common;void *misc4_m =MLX5_ADDR_OF (fte_match_param, matcher, misc_parameters_4); void *misc4_v = MLX5_ADDR_OF(fte_match_param, key,Quoted 1 line
misc_parameters_4); @@ -7838,7 +7839,8 @@ structmlx5_hlist_entry*
Quoted 1 line
* Some wildcard rules only matching type field should be
supported.
Quoted 10 lines
*/ if (ecpri_m->hdr.dummy[0]) {drivers/net/mlx5/mlx5_flow_dv.c +1
-1-switch (ecpri_v->hdr.common.type) { + common.u32 = rte_be_to_cpu_32(ecpri_v-hdr.common.u32);
+ switch (common.type) {
caseRTE_ECPRI_MSG_TYPE_IQ_DATA:
caseRTE_ECPRI_MSG_TYPE_RTC_CTRL:
caseRTE_ECPRI_MSG_TYPE_DLY_MSR:
Quoted 35 lines · Bing Zhao
Hi Ferruh,
Thanks for your review and comments, PSB.
Quoted 21 lines
-----Original Message-----
From: Ferruh Yigit <[email protected]>
Sent: Friday, November 6, 2020 7:20 PM
To: Bing Zhao <[email protected]>; Slava Ovsiienko <[email protected]>; Matan Azrad <[email protected]>
Cc: [email protected]; Ori Kam <[email protected]>; Raslan Darawsheh <[email protected]>; [email protected]
Subject: Re: [dpdk-dev] [PATCH] net/mlx5: fix the eCPRI common header endiannessExternal email: Use caution opening links or attachments
Quoted 1 line · Bing Zhao
The input header of a RTE flow item is with network byte order. In
the
Quoted 1 line
host with little endian, the bit field order are the same as the
byte
Quoted 3 lines
order.
When checking the an eCPRI message type, the wrong field will be selected. Right now, since the whole u32 is being checked and forQuoted 9 lines
all
Quoted 1 line
types, the following implementation is unique. There is no
functional
Quoted 2 lines
risk but it is still an error to fix.
Isn't the '
ecpri_v' filled by application (CPU), why there is an assumption that it is big endian?
Quoted 6 lines
Yes, this is filled by the application SW. I checked the current code of other headers and current implementation.
1. In the testpmd flow example, all the headers of network stack like IPv4 are translated into to be in BE, "ARGS_ENTRY_HTON"
2. All fields are with "rte_be*_t"type, even though only a typedef, it should be considered in BE.
3. RTE flow will just pass the flow items pointer to the PMD drivers, so in the PMD part, the headers should be treated as in BE. So, to my understanding, this is not an assumption but some constraint.
Correct me if my understanding is wrong.
I missed in 'cmdline_flow.c' big endian conversion done via 'arg->hton' check, so yes PMD getting big endian values makes sense, thanks for clarification.
Quoted 10 lines
Quoted 4 lines
And even if it is big endian, it should be broken previously right? Since it was checking wrong field as 'type' as you said, why there were no functional risk?
In the PMD driver, the first u32 *value containing this type is already used for matching. And a checking is used for the following "sub-headers" matching. Indeed, the first u32 *mask is used to confirm if the following sub-header need to be matched.
Since different types will lead to different variants of the packets, the switch-of-type is used.
But all the 3 types supported in PMD now almost have the same results (part of the second u32, remaining will be all 0s). So even if the type of the value is always "0" by mistake, the cases are the same and it still works by coincidence.
if 'type' is '0' I see it works, but what if the 'type' is something other than values covered in 'switch', than it may fail matching 'sub-headers' and I guess that can happen based on value of 'size' field.
Anyway, since you are already fixing it, will you be OK if I drop last two sentences from the commit log and proceed?
Hi Ferruh,
Quoted 83 lines
-----Original Message-----
From: Ferruh Yigit <[email protected]>
Sent: Saturday, November 7, 2020 1:41 AM
To: Bing Zhao <[email protected]>; Slava Ovsiienko <[email protected]>; Matan Azrad <[email protected]>
Cc: [email protected]; Ori Kam <[email protected]>; Raslan Darawsheh <[email protected]>; [email protected]
Subject: Re: [dpdk-dev] [PATCH] net/mlx5: fix the eCPRI common header endiannessExternal email: Use caution opening links or attachments
Quoted 12 lines · Bing Zhao
Hi Ferruh,
Thanks for your review and comments, PSB.
Quoted 8 lines
-----Original Message-----
From: Ferruh Yigit <[email protected]>
Sent: Friday, November 6, 2020 7:20 PM
To: Bing Zhao <[email protected]>; Slava Ovsiienko <[email protected]>; Matan Azrad <[email protected]>
Cc: [email protected]; Ori Kam <[email protected]>; Raslan Darawsheh <[email protected]>; [email protected]
Subject: Re: [dpdk-dev] [PATCH] net/mlx5: fix the eCPRI commonheader
Quoted 7 lines
Quoted 7 lines
endianness
External email: Use caution opening links or attachments
Quoted 1 line · Bing Zhao
The input header of a RTE flow item is with network byte order.
In
Quoted 6 lines
Quoted 6 lines
the
Quoted 1 line
host with little endian, the bit field order are the same as the
byte
Quoted 3 lines
order.
When checking the an eCPRI message type, the wrong field will be selected. Right now, since the whole u32 is being checked andfor
Quoted 11 lines
Quoted 9 lines
all
Quoted 1 line
types, the following implementation is unique. There is no
functional
Quoted 2 lines
risk but it is still an error to fix.
Isn't the '
ecpri_v' filled by application (CPU), why there is an assumption that it is big endian?Yes, this is filled by the application SW. I checked the current
code of other headers and current implementation.
Quoted 1 line
1. In the testpmd flow example, all the headers of network stack
like IPv4 are translated into to be in BE, "
ARGS_ENTRY_HTON"Quoted 1 line
2. All fields are with "rte_be*_t"type, even though only a typedef,
it should be considered in BE.
Quoted 1 line
3. RTE flow will just pass the flow items pointer to the PMD
drivers, so in the PMD part, the headers should be treated as in BE.
Quoted 1 line
So, to my understanding, this is not an assumption but some
constraint.
Quoted 1 line
Correct me if my understanding is wrong.
I missed in '
cmdline_flow.c' big endian conversion done via 'arg-Quoted 1 line
hton' check, so yes PMD getting big endian values makes sense,
thanks for clarification.
Quoted 2 lines
Quoted 2 lines
And even if it is big endian, it should be broken previously
right?
Quoted 1 line
Quoted 1 line
Since it was checking wrong field as 'type' as you said, why
there
Quoted 3 lines
Quoted 1 line
were no functional risk?
In the PMD driver, the first u32 *value containing this type is
already used for matching. And a checking is used for the following "sub-headers"
Quoted 1 line
matching. Indeed, the first u32 *mask is used to confirm if the
following sub-header need to be matched.
Quoted 1 line
Since different types will lead to different variants of the
packets, the switch-of-type is used.
Quoted 1 line
But all the 3 types supported in PMD now almost have the same
Quoted 8 lines
results (part of the second u32, remaining will be all 0s).
Quoted 1 line
So even if the type of the value is always "0" by mistake, the
cases are the same and it still works by coincidence.
if 'type' is '0' I see it works, but what if the 'type' is something other than values covered in 'switch', than it may fail matching 'sub-headers' and I guess that can happen based on value of 'size' field.
Yes, it has the risk. In the past, the packet's length tested didn't expose this issue. So when it change the size upper byte to other value instead of 0/2/5, then the flow will get a failure when being created. Thanks for catching this point.
Quoted 3 lines
Anyway, since you are already fixing it, will you be OK if I drop last two sentences from the commit log and proceed?
Sure, thanks a lot for your help.
BR. Bing