ethdev: update GENEVE option item structure
cover ethdev: update GENEVE option item structure
The "rte_flow_item_geneve_opt" structure describes the GENEVE TLV option header according to RFC 8926 [1]:
struct rte_flow_item_geneve_opt {
rte_be16_t option_class;
uint8_t option_type;
uint8_t option_len;
uint32_t *data;
};The "option_len" field is used for two different purposes:
1. item field for matching with value/mask.
2. descriptor for data array size.
Those two different purposes might limit each other. For example, when matching on length with full mask (0x1f), the data array in the mask structure might be taken as size 31 and read invalid memory.
This problem appears in conversion API. In current implementation, the "rte_flow_conv" API copies the "rte_flow_item_geneve_opt" structure without taking care about data deep-copy. The attempt to solve this revealed the problem in determining the size of the mask data array. To resolve this issue, two solutions are suggested.
Immediate Workaround:
The data array size in the "mask" structure is determined by "option_len" field in the "spec" structure. This workaround can be integrated soon to avoid deep-copy missing.
Long Run Solution:
Add a new field into "rte_flow_item_geneve_opt" structure regardless to "option_len" field. This solution should wait to "24.11" version since it contains API change.
When the API is changed, I'll take the opportunity to add documentation for this item in "rte_flow.rst" file and update the data type to "rte_be32_t".
[1] https://datatracker.ietf.org/doc/html/rfc8926
Michael Baum (2):
ethdev: fix GENEVE option item conversion
ethdev: add data size field to GENEVE option item
app/test-pmd/cmdline_flow.c | 10 +++++++ doc/guides/prog_guide/rte_flow.rst | 16 ++++++++++++ doc/guides/testpmd_app_ug/testpmd_funcs.rst | 3 ++- lib/ethdev/rte_flow.c | 29 +++++++++++++++++---- lib/ethdev/rte_flow.h | 3 ++- 5 files changed, 54 insertions(+), 7 deletions(-)
Signature · 1 line
2.25.1
RFC 1/2 ethdev: fix GENEVE option item conversion
The "rte_flow_conv()" function, enables, among other things, to copy item list.
For GENEVE option item, the function copies it without considering deep copy. It copies the "data" pointer without copying the pointed values.
This patch adds deep copy for after regular copy.
--- lib/ethdev/rte_flow.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-)
lib/ethdev/rte_flow.c +25 -4
@@ -622,6 +622,7 @@ rte_flow_conv_item_spec(void *buf, const size_t size,switch (item->type) {union {const struct rte_flow_item_raw *raw; +const struct rte_flow_item_geneve_opt *geneve_opt; } spec;union {const struct rte_flow_item_raw *raw;
@@ -631,10 +632,13 @@ rte_flow_conv_item_spec(void *buf, const size_t size, } mask;union {const struct rte_flow_item_raw *raw; +const struct rte_flow_item_geneve_opt *geneve_opt; } src;union {struct rte_flow_item_raw *raw; +struct rte_flow_item_geneve_opt *geneve_opt; } dst; +void *deep_src;size_t tmp;case RTE_FLOW_ITEM_TYPE_RAW :
@@ -663,13 +667,30 @@ rte_flow_conv_item_spec(void *buf, const size_t size, tmp = last.raw->length & mask.raw->length;if (tmp) { off =RTE_ALIGN_CEIL (off,sizeof (*dst.raw->pattern)); -if (size >= off + tmp) - dst.raw->pattern =rte_memcpy - ((void *)((uintptr_t )dst.raw + off), - src.raw->pattern, tmp); +if (size >= off + tmp) { + deep_src = (void *)((uintptr_t )dst.raw + off); + dst.raw->pattern =rte_memcpy (deep_src, + src.raw->pattern, + tmp); + } off += tmp; }break ; +case RTE_FLOW_ITEM_TYPE_GENEVE_OPT : + off =rte_flow_conv_copy (buf, data, size, + rte_flow_desc_item, item->type); + spec.geneve_opt = item->spec; + src.geneve_opt = data; + dst.geneve_opt = buf; + tmp = spec.geneve_opt->option_len <<2 ; +if (size >0 && src.geneve_opt->data) { + deep_src = (void *)((uintptr_t )(dst.geneve_opt +1 )); + dst.geneve_opt->data =rte_memcpy (deep_src, + src.geneve_opt->data, + tmp); + } + off += tmp; +break ;default : off =rte_flow_conv_copy (buf, data, size, rte_flow_desc_item, item->type);
Signature · 1 line
2.25.1
RFC 2/2 ethdev: add data size field to GENEVE option item
In reply to Michael BaumThe "rte_flow_item_geneve_opt" structure has field for option length. This field has 2 different usages which might limit each other:
1. field to matching with value/mask.
2. descriptor for data array size.
This patch adds a new field "data_array_size" into "rte_flow_item_geneve_opt" structure in addition to existing "option_len" field.
--- app/test-pmd/cmdline_flow.c | 10 ++++++ doc/guides/prog_guide/rte_flow.rst | 16 +++++++++ doc/guides/testpmd_app_ug/testpmd_funcs.rst | 3 +- lib/ethdev/rte_flow.c | 36 ++++++++++----------- lib/ethdev/rte_flow.h | 3 +- 5 files changed, 47 insertions(+), 21 deletions(-)
app/test-pmd/cmdline_flow.c +10 -0
@@ -492,6 +492,7 @@ enum index {ITEM_GENEVE_OPT_TYPE ,ITEM_GENEVE_OPT_LENGTH ,ITEM_GENEVE_OPT_DATA , +ITEM_GENEVE_OPT_DATA_ARRAY_SIZE ,ITEM_INTEGRITY ,ITEM_INTEGRITY_LEVEL , ITEM_INTEGRITY_VALUE,
@@ -2032,6 +2033,7 @@ static const enum index item_geneve_opt[] = {ITEM_GENEVE_OPT_TYPE ,ITEM_GENEVE_OPT_LENGTH ,ITEM_GENEVE_OPT_DATA , +ITEM_GENEVE_OPT_DATA_ARRAY_SIZE ,ITEM_NEXT , ZERO, };
@@ -5772,6 +5774,14 @@ static const struct token token_list[] = { (sizeof (struct rte_flow_item_geneve_opt ), ITEM_GENEVE_OPT_DATA_SIZE)), }, + [ITEM_GENEVE_OPT_DATA_ARRAY_SIZE] = { + .name = "data_size", + .help = "GENEVE option data array size", + .next =NEXT (item_geneve_opt,NEXT_ENTRY (COMMON_UNSIGNED ), + item_param), + .args = ARGS(ARGS_ENTRY(struct rte_flow_item_geneve_opt, + data_array_size)), + }, [ITEM_INTEGRITY] = { .name = "integrity", .help = "match packet integrity",
doc/guides/prog_guide/rte_flow.rst +16 -0
@@ -1092,6 +1092,22 @@ Matches a GENEVE header. - ``rsvd1``: reserved, normally 0x00. - Default ``mask`` matches VNI only. + +Item: ``GENEVE_OPT`` +^^^^^^^^^^^^^^^^^^^^ + +Matches a GENEVE TLV option header. + +- ``option_class``: option class ID. +- ``option_type``: option type. +- ``option_len``: option data length in 4-bytes granularity. +- ``data``: option data array. +- ``data_array_size``: option data array size. + This field is not matchable, it is descriptor how to read the array. + It should be specified in ``mask`` as well. +- Default ``mask`` matches type only. + + Item: ``VXLAN-GPE`` ^^^^^^^^^^^^^^^^^^^
doc/guides/testpmd_app_ug/testpmd_funcs.rst +2 -1
@@ -3743,7 +3743,8 @@ This section lists supported pattern items and their attributes, if any. - ``type {unsigned}``: GENEVE option type. - ``length {unsigned}``: GENEVE option length in 32-bit words. - ``data {hex string}``: GENEVE option data, the length is defined by - ``length`` field. + ``data_size`` field. + - ``data_size {unsigned}``: GENEVE option data size in 32-bit words. - ``vxlan-gpe``: match VXLAN-GPE header.
lib/ethdev/rte_flow.c +17 -19
@@ -81,6 +81,21 @@ rte_flow_item_flex_conv(void *buf, const void *data)return src->length; } +static size_t +rte_flow_item_geneve_opt_conv (void *buf,const void *data) +{ +const struct rte_flow_item_geneve_opt *src = data; +uint16_t byte_size = src->data_array_size <<2 ; + +if (buf) { +struct rte_flow_item_geneve_opt *dst = buf; +void *deep_src = (void *)((uintptr_t )(dst +1 )); + + dst->data =rte_memcpy (deep_src, src->data, byte_size); + } +return byte_size; +} +/** Generate flow_item[] entry. */ #define MK_FLOW_ITEM (t, s) \ [RTE_FLOW_ITEM_TYPE_ ## t] = { \
@@ -155,7 +170,8 @@ static const struct rte_flow_desc_data rte_flow_desc_item[] = {MK_FLOW_ITEM (L2TPV3OIP ,sizeof (struct rte_flow_item_l2tpv3oip )),MK_FLOW_ITEM (PFCP ,sizeof (struct rte_flow_item_pfcp )),MK_FLOW_ITEM (ECPRI ,sizeof (struct rte_flow_item_ecpri )), -MK_FLOW_ITEM (GENEVE_OPT ,sizeof (struct rte_flow_item_geneve_opt )), +MK_FLOW_ITEM_FN (GENEVE_OPT ,sizeof (struct rte_flow_item_geneve_opt ), + rte_flow_item_geneve_opt_conv),MK_FLOW_ITEM (INTEGRITY ,sizeof (struct rte_flow_item_integrity )),MK_FLOW_ITEM (CONNTRACK ,sizeof (uint32_t )), MK_FLOW_ITEM(PORT_REPRESENTOR, sizeof(struct rte_flow_item_ethdev)),
@@ -622,7 +638,6 @@ rte_flow_conv_item_spec(void *buf, const size_t size,switch (item->type) {union {const struct rte_flow_item_raw *raw; -const struct rte_flow_item_geneve_opt *geneve_opt; } spec;union {const struct rte_flow_item_raw *raw;
@@ -632,11 +647,9 @@ rte_flow_conv_item_spec(void *buf, const size_t size, } mask;union {const struct rte_flow_item_raw *raw; -const struct rte_flow_item_geneve_opt *geneve_opt; } src;union {struct rte_flow_item_raw *raw; -struct rte_flow_item_geneve_opt *geneve_opt; } dst;void *deep_src;size_t tmp;
@@ -676,21 +689,6 @@ rte_flow_conv_item_spec(void *buf, const size_t size, off += tmp; }break ; -case RTE_FLOW_ITEM_TYPE_GENEVE_OPT : - off =rte_flow_conv_copy (buf, data, size, - rte_flow_desc_item, item->type); - spec.geneve_opt = item->spec; - src.geneve_opt = data; - dst.geneve_opt = buf; - tmp = spec.geneve_opt->option_len <<2 ; -if (size >0 && src.geneve_opt->data) { - deep_src = (void *)((uintptr_t )(dst.geneve_opt +1 )); - dst.geneve_opt->data =rte_memcpy (deep_src, - src.geneve_opt->data, - tmp); - } - off += tmp; -break ;default : off =rte_flow_conv_copy (buf, data, size, rte_flow_desc_item, item->type);
lib/ethdev/rte_flow.h +2 -1
@@ -1876,7 +1876,8 @@ struct rte_flow_item_geneve_opt {rte_be16_t option_class;uint8_t option_type;uint8_t option_len; -uint32_t *data; +rte_be32_t *data; +uint8_t data_array_size; };/** Default mask for RTE_FLOW_ITEM_TYPE_GENEVE_OPT. */
Signature · 1 line
2.25.1
Re: [RFC 2/2] ethdev: add data size field to GENEVE option item
Quoted 12 lines · Michael Baum
The "
rte_flow_item_geneve_opt" structure has field for option length. This field has 2 different usages which might limit each other:1. field to matching with value/mask.
2. descriptor for data array size.This patch adds a new field "
data_array_size" into "rte_flow_item_geneve_opt" structure in addition to existing "option_len" field.Signed-off-by Michael Baum <[email protected]>
Hi Michael,
The first patch of the RFC sent separately later and merged [1], but I don't know status of patch 2/2, is it still valid?
Since this is old patch, I will mark whole set as "Superseded", if this patch is still relevant please send a new version, RFC or an actual patch.
Thanks,
ferruh
[1]
https://patches.dpdk.org/project/dpdk/patch/[email protected]/
Quoted 10 lines · Michael Baum
The "
rte_flow_item_geneve_opt" structure describes the GENEVE TLV option header according to RFC 8926 [1]:struct rte_flow_item_geneve_opt { rte_be16_t option_class; uint8_t option_type; uint8_t option_len; uint32_t *data; };
Quoted 4 lines
The "
option_len" field is used for two different purposes:
1. item field for matching with value/mask.
2. descriptor for data array size.
For the long run solution, we may consider adding geneve option header to net/rte_geneve.h and make "struct rte_flow_item_geneve_opt" + data size ?
Quoted 10 lines
Those two different purposes might limit each other. For example, when matching on length with full mask (
0x1f), the data array in the mask structure might be taken as size 31 and read invalid memory.This problem appears in conversion API. In current implementation, the "
rte_flow_conv" API copies the "rte_flow_item_geneve_opt" structure without taking care about data deep-copy. The attempt to solve this revealed the problem in determining the size of the mask data array. To resolve this issue, two solutions are suggested.
Are we having this problem only with geneve options because data size is not fixed / defined for the header?
Quoted 5 lines
Immediate Workaround:
The data array size in the "mask" structure is determined by "option_len" field in the "spec" structure. This workaround can be integrated soon to avoid deep-copy missing.
This requires a geneve specific pointer in the item spec, which is not really nice, although it is temporary solution. Perhaps we can skip this, can you please check below comment.
Quoted 5 lines
Long Run Solution:
Add a new field into "rte_flow_item_geneve_opt" structure regardless to "option_len" field. This solution should wait to "24.11" version since it contains API change.
I was expecting the same, but CI seems passed ABI test case [1], it may be because new field appended end of the struct.
Can you please double check, if ABI is not broken, we can go with this solution directly?
[1]
https://mails.dpdk.org/archives/test-report/2024-April/643570.html
Quoted 4 lines
When the API is changed, I'll take the opportunity to add documentation for this item in "
rte_flow.rst" file and update the data type to "rte_be32_t".
If we can go with updating struct in this release, adding protocol option struct in net library can wait v24.11 release. So "rte_be32_t" type change in this struct won't be a thing.
Quoted 7 lines
[1] https://datatracker.ietf.org/doc/html/rfc8926
Michael Baum (2):
ethdev: fix GENEVE option item conversion
ethdev: add data size field to GENEVE option item
@Ori, Can you please help reviewing this patch?
At worst, it can be good to address the fix in this release.