From: Michal Krawczyk <mk@semihalf.com>
To: dev@dpdk.org, keith.wiles@intel.com
Cc: igorch@amazon.com, david.marchand@redhat.com,
thomas@monjalon.net, Michal Krawczyk <mk@semihalf.com>
Subject: [dpdk-dev] [PATCH v2] Fix loss of data stored in udata64 mbuf field
Date: Thu, 4 Feb 2021 13:24:46 +0100 [thread overview]
Message-ID: <20210204122446.2720934-1-mk@semihalf.com> (raw)
In-Reply-To: <20210204085209.2716232-1-mk@semihalf.com>
DPDK 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.
Signed-off-by: Michal Krawczyk <mk@semihalf.com>
Reviewed-by: Igor Chauskin <igorch@amazon.com>
---
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(-)
diff --git a/app/pktgen-main.c b/app/pktgen-main.c
index 2d9d754..8dd31e9 100644
--- a/app/pktgen-main.c
+++ b/app/pktgen-main.c
@@ -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;
diff --git a/app/pktgen-pcap.c b/app/pktgen-pcap.c
index 249d62c..6732919 100644
--- a/app/pktgen-pcap.c
+++ b/app/pktgen-pcap.c
@@ -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]);
diff --git a/app/pktgen.c b/app/pktgen.c
index ef9f531..fd28606 100644
--- a/app/pktgen.c
+++ b/app/pktgen.c
@@ -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;
diff --git a/lib/common/mbuf.h b/lib/common/mbuf.h
index 2951454..88cc7b0 100644
--- a/lib/common/mbuf.h
+++ b/lib/common/mbuf.h
@@ -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);
diff --git a/lib/common/pg_compat.h b/lib/common/pg_compat.h
index 2da1014..aba2863 100644
--- a/lib/common/pg_compat.h
+++ b/lib/common/pg_compat.h
@@ -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
--
2.25.1
prev parent reply other threads:[~2021-02-04 12:25 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-04 8:52 [dpdk-dev] [PATCH] " Michal Krawczyk
2021-02-04 9:01 ` David Marchand
2021-02-04 9:17 ` Michał Krawczyk
2021-02-04 9:35 ` Thomas Monjalon
2021-02-04 12:24 ` Michal Krawczyk [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210204122446.2720934-1-mk@semihalf.com \
--to=mk@semihalf.com \
--cc=david.marchand@redhat.com \
--cc=dev@dpdk.org \
--cc=igorch@amazon.com \
--cc=keith.wiles@intel.com \
--cc=thomas@monjalon.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).