Fix loss of data stored in udata64 mbuf field
PATCH 1/1 Fix loss of data stored in udata64 mbuf field
DPDK v20.11 removed udata64 field, and changed type of the dynfield1 to uint32_t.
Due to define:
lib/common/pg_compat.h:#define udata64 dynfield1[0]
the copy of udata64 was in fact copying only the first 32 bits.
Using udata64 as an address is ok, as it will point to the beginning of the dynfield1 array.
--- lib/common/mbuf.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
lib/common/mbuf.h +5 -1
@@ -30,7 +30,11 @@ pktmbuf_reset(struct rte_mbuf *m) {union pktgen_data d; - d.udata = m->udata64;/* Save the original value */ +/* Save the original value. As udata64 can be either single field or the +* first value of the 32-bit elements array, the whole memory chunk must +* be converted directly to 64-bit. +*/ + d.udata = *(uint64_t *)(&m->udata64);rte_pktmbuf_reset (m);
Signature · 1 line
2.25.1
Quoted 7 lines · Michal Krawczyk
DPDK v20.11 removed udata64 field, and changed type of the dynfield1 to
uint32_t.Due to define:
lib/common/pg_compat.h:#define udata64 dynfield1[0]
the copy of udata64 was in fact copying only the first 32 bits.
I did not look at the pktgen code, but directly accessing mbuf field dynfieldX is likely a bug.
pktgen should register a dynfield for its own usage to avoid conflicts with other parts of the dpdk.
Example of such a conversion to the new mechanism:
https://git.dpdk.org/dpdk/commit/?id=eb8258402b3f
Signature · 1 line
David Marchand
czw., 4 lut 2021 o 10:01 David Marchand <[email protected]> napisał(a):
Quoted 10 lines · Michal Krawczyk
Quoted 7 lines
DPDK v20.11 removed udata64 field, and changed type of the dynfield1 to
uint32_t.Due to define:
lib/common/pg_compat.h:#define udata64 dynfield1[0]
the copy of udata64 was in fact copying only the first 32 bits.
Quoted 8 lines
I did not look at the pktgen code, but directly accessing mbuf field dynfieldX is likely a bug.
pktgen should register a dynfield for its own usage to avoid conflicts with other parts of the dpdk.
Example of such a conversion to the new mechanism:
https://git.dpdk.org/dpdk/commit/?id=eb8258402b3f
Hi David,
thanks for pointing this out. I wasn't aware of that, I'll rework my fix to satisfy the dynfield requirements.
Best regards,
Michal
Quoted 4 lines
--
David Marchand
04/02/2021 10:17, Michał Krawczyk:
Quoted 20 lines
czw., 4 lut 2021 o 10:01 David Marchand <[email protected]> napisał(a):
Quoted 10 lines · Michal Krawczyk
Quoted 7 lines
DPDK v20.11 removed udata64 field, and changed type of the dynfield1 to
uint32_t.Due to define:
lib/common/pg_compat.h:#define udata64 dynfield1[0]
the copy of udata64 was in fact copying only the first 32 bits.Quoted 8 lines
I did not look at the pktgen code, but directly accessing mbuf field dynfieldX is likely a bug.
pktgen should register a dynfield for its own usage to avoid conflicts with other parts of the dpdk.
Example of such a conversion to the new mechanism:
https://git.dpdk.org/dpdk/commit/?id=eb8258402b3f
Quoted 4 lines
Hi David,
thanks for pointing this out. I wasn't aware of that, I'll rework my fix to satisfy the dynfield requirements.
Sorry for having to say that,
but you are supposed to read the release notes when upgrading.
PATCH v2 1/1 Fix loss of data stored in udata64 mbuf field
In reply to Michal KrawczykDPDK v20.11 removed mbuf's udata64 field, and changed type of the dynfield1 to uint32_t.
Due to pktgen's define for DPDK v20.11+:
lib/common/pg_compat.h:#define udata64 dynfield1[0]
udata64 field was being mapped to the first entry of the dynfield1 array.
Because of that, accessing dynfield1 directly was causing 2 issues:
* As dynfield1 is 32-bit array, using it interchangeably with the udata64 is causing only the first 32-bits of the intended 64-bits to be copied
* dynfield1 may also be used by the other parts of the DPDK and it may cause conflicts
To fix that, the dynfield1 is no longer mapped to the udata64 as those fields are uncompatible. Instead, the dynamic field API is used to get the pktgen data offset from the dynfield1 array.
It was wrapped into an getter function, which could be reworked if backward compatibility will be needed.
---
v2:
* Converted pktgen to use mbuf's dynamic fields API, instead of accessing dynfield1 directly
app/pktgen-main.c | 16 ++++++++++++++++ app/pktgen-pcap.c | 2 +- app/pktgen.c | 2 +- lib/common/mbuf.h | 21 ++++++++++++++++++++- lib/common/pg_compat.h | 1 - 5 files changed, 38 insertions(+), 4 deletions(-)
app/pktgen-main.c +16 -0
@@ -29,6 +29,16 @@#include "pktgen-log.h" #include "cli-functions.h" +/* Offset to the mbuf dynamic field holding pktgen data. */ +int pktgen_dynfield_offset =-1 ; + +/* Descriptor used for the mbuf dynamic field configuration. */ +static const struct rte_mbuf_dynfield pktgen_dynfield_desc = { + .name ="pktgen_dynfield_data" , + .size =sizeof (union pktgen_data ), + .align = __alignof__(union pktgen_data ), +}; +#ifdef GUI int pktgen_gui_main (int argc,char *argv[]);#endif
@@ -455,6 +465,12 @@ main(int argc, char **argv) argc -= ret; argv += ret; +/* Configure pktgen data which will be encapsulated in the mbuf. */ + pktgen_dynfield_offset = +rte_mbuf_dynfield_register (&pktgen_dynfield_desc); +if (pktgen_dynfield_offset <0 ) +rte_exit (EXIT_FAILURE ,"Cannot register mbuf field\n" ); +if (pktgen_cli_create ())return -1 ;
app/pktgen-pcap.c +1 -1
@@ -258,7 +258,7 @@ pktgen_pcap_mbuf_ctor(struct rte_mempool *mp, m->next =NULL ;for (;; ) { -union pktgen_data *d = (union pktgen_data *)&m->udata64; +union pktgen_data *d =pktgen_data_field (m);if ( (i &0x3ff ) ==0 ) {scrn_printf (1 ,1 ,"%c\b" ,"-\\|/" [(i >>10 ) &3 ]);
app/pktgen.c +1 -1
@@ -927,7 +927,7 @@ pktgen_setup_cb(struct rte_mempool *mp, {pkt_data_t *data = (pkt_data_t *)opaque;struct rte_mbuf *m = (struct rte_mbuf *)obj; -union pktgen_data *d = (union pktgen_data *)&m->udata64; +union pktgen_data *d =pktgen_data_field (m);port_info_t *info;pkt_seq_t *pkt;uint16_t qid, idx;
lib/common/mbuf.h +20 -1
@@ -25,12 +25,31 @@ union pktgen_data { }; }; +extern int pktgen_dynfield_offset; + +/** +* Get pointer to the pktgen specific data encapsulated in the mbuf. Dynamic +* field API has to be used for this purpose, to avoid conflicts with other +* parts of the DPDK. +* +* @param m +* Pointer to the mbuf from which the pktgen data should be retrieved. +* @return +* Pointer to the pktgen specific data encapsulated in the mbuf. +*/ +static inline union pktgen_data * +pktgen_data_field (struct rte_mbuf *m) +{ +return RTE_MBUF_DYNFIELD (m, pktgen_dynfield_offset, + union pktgen_data *); +} +static inline void pktmbuf_reset (struct rte_mbuf *m) {union pktgen_data d; - d.udata = m->udata64;/* Save the original value */ + d = *pktgen_data_field (m);/* Save the original value */ rte_pktmbuf_reset (m);
lib/common/pg_compat.h +0 -1
@@ -33,7 +33,6 @@ extern "C" {#if RTE_VERSION >=RTE_VERSION_NUM (20 ,11 ,0 ,0 )#define pg_get_initial_lcore rte_get_main_lcore -#define udata64 dynfield1[0]#define PG_DEVTYPE_BLOCKED RTE_DEVTYPE_BLOCKED#define PG_DEVTYPE_ALLOWED RTE_DEVTYPE_ALLOWED#else
Signature · 1 line
2.25.1