From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 6C555A0524; Thu, 4 Feb 2021 13:25:00 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 02ABA240634; Thu, 4 Feb 2021 13:25:00 +0100 (CET) Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com [209.85.167.44]) by mails.dpdk.org (Postfix) with ESMTP id 4377C2405C1 for ; Thu, 4 Feb 2021 13:24:58 +0100 (CET) Received: by mail-lf1-f44.google.com with SMTP id a12so4280482lfb.1 for ; Thu, 04 Feb 2021 04:24:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5YrVbx+OUoXkMMPebqg2ckhFJjFugaXusY/a2YSNve4=; b=0kw8tV0lX3UhDmzRgdJ/1cbyYD//CuOpbpk72l9DYSo1EBc3dbFSwBv6VRiPqKJBIj MRDnIKFM+oJzBFE6KSuoh4PysDSOlQr1AMFuDAK55LDY4/25XDCB7fcpbScyb069d7bW F0kJeYhZc7XHllCDP7N14b6Mw3DhVVg0JieSVjv88cdoXdv0w7yhh+z69ZoA5NOu3ow2 iw9TF429W3g5uJ1/1qVVZE0pM5nJAVugL0tp5Ti5fwu4oAX9Xhcddvlm91iilKGkHCUw cl3FI1gZca6AspjKZXxsuLH1wUjtgHCMaVgYA9OFISWxqQdRAkXmTJmdEZBlFiKvIsp6 po1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5YrVbx+OUoXkMMPebqg2ckhFJjFugaXusY/a2YSNve4=; b=Di/yZwk2gR0H5e7KeFMUhGHx92TExCqnf9MfAkbCFAN88ABi26av29bPTZyRY4fXTH w0g/YRVoIZtaGHDyxGoW3i4zPJsWzSpXOi/jtNCep2UtfBpmCyiuT2K1ziIURcbqWtXv RVe6zOgQ1rQlZVHXMxl2WF5l0WcrNxppjNNq6THujNVWK5rzuJa1xu9ZvGPWpvypawX4 SDkIW7LxsEST5C2UG63oYA9T1EXq3tL1gjPBzNbh/EknK59FysrfeRuPgdSd/w9tkZQn KprxWLx0oe96L6v9Ir4g5y4n7G+WFliPzMGZwu55jgtDepPtiMCbE0/vZXW6I5mz8j1l zLUg== X-Gm-Message-State: AOAM530xXy/yWjVb+CVxwwVCtXVajS2udAmEPEVy3buF1MywrT4LcgXO +bkKxUcgor0Lm+af63fpBfC68TYhWrsSrw== X-Google-Smtp-Source: ABdhPJx9xRqAMNZRjiffnCD3Nv2GGu9en/wKXE0sZbZ4xIVGd1PacwRe+zO8wbq1FX/ioitd2A7EbQ== X-Received: by 2002:ac2:5e2d:: with SMTP id o13mr4668769lfg.431.1612441497292; Thu, 04 Feb 2021 04:24:57 -0800 (PST) Received: from mkPC.int.semihalf.com (193-106-246-138.noc.fibertech.net.pl. [193.106.246.138]) by smtp.gmail.com with ESMTPSA id q3sm621419ljp.108.2021.02.04.04.24.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Feb 2021 04:24:55 -0800 (PST) From: Michal Krawczyk To: dev@dpdk.org, keith.wiles@intel.com Cc: igorch@amazon.com, david.marchand@redhat.com, thomas@monjalon.net, Michal Krawczyk Date: Thu, 4 Feb 2021 13:24:46 +0100 Message-Id: <20210204122446.2720934-1-mk@semihalf.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210204085209.2716232-1-mk@semihalf.com> References: <20210204085209.2716232-1-mk@semihalf.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v2] Fix loss of data stored in udata64 mbuf field X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 Reviewed-by: Igor Chauskin --- 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