From: David Marchand <david.marchand@redhat.com>
To: dev@dpdk.org
Cc: "Thomas Monjalon" <thomas@monjalon.net>,
"Ferruh Yigit" <ferruh.yigit@amd.com>,
"Andrew Rybchenko" <andrew.rybchenko@oktetlabs.ru>,
"Anatoly Burakov" <anatoly.burakov@intel.com>,
"Morten Brørup" <mb@smartsharesystems.com>
Subject: [PATCH] ethdev: refresh shared memory reference in secondary process
Date: Fri, 20 Oct 2023 14:06:29 +0200 [thread overview]
Message-ID: <20231020120629.2158219-1-david.marchand@redhat.com> (raw)
In the process of releasing ethdev port in the primary process,
secondary processes are asked to stop referencing such a port.
Doing so, those processes can't predict whether the primary process
will later invalidate/free the shared memory. So they may live with a
reference to an old shared memory memzone and location in memory.
Refresh the shared memory pointer in secondary process when requesting
access to the shared memory: this is the best moment ethdev can check
it because the primary process will (re-)create a shared memory only if
no secondary process is referencing a ethdev port.
Bugzilla ID: 1303
Fixes: 36c46e738120 ("ethdev: cleanup shared data with the last port")
Signed-off-by: David Marchand <david.marchand@redhat.com>
---
lib/ethdev/ethdev_private.c | 46 ++++++++++++++++++++++++-------------
1 file changed, 30 insertions(+), 16 deletions(-)
diff --git a/lib/ethdev/ethdev_private.c b/lib/ethdev/ethdev_private.c
index 7cc7f28296..a78a66bbfd 100644
--- a/lib/ethdev/ethdev_private.c
+++ b/lib/ethdev/ethdev_private.c
@@ -324,17 +324,18 @@ rte_eth_call_tx_callbacks(uint16_t port_id, uint16_t queue_id,
void *
eth_dev_shared_data_prepare(void)
{
- const unsigned int flags = 0;
const struct rte_memzone *mz;
- if (eth_dev_shared_mz == NULL) {
- if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
- /* Allocate port data and ownership shared memory. */
- mz = rte_memzone_reserve(MZ_RTE_ETH_DEV_DATA,
- sizeof(*eth_dev_shared_data),
- rte_socket_id(), flags);
- } else
- mz = rte_memzone_lookup(MZ_RTE_ETH_DEV_DATA);
+ if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
+ const unsigned int flags = 0;
+
+ if (eth_dev_shared_mz != NULL)
+ goto out;
+
+ /* Allocate port data and ownership shared memory. */
+ mz = rte_memzone_reserve(MZ_RTE_ETH_DEV_DATA,
+ sizeof(*eth_dev_shared_data),
+ rte_socket_id(), flags);
if (mz == NULL) {
RTE_ETHDEV_LOG(ERR, "Cannot allocate ethdev shared data\n");
goto out;
@@ -342,14 +343,27 @@ eth_dev_shared_data_prepare(void)
eth_dev_shared_mz = mz;
eth_dev_shared_data = mz->addr;
- if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
- eth_dev_shared_data->allocated_owners = 0;
- eth_dev_shared_data->next_owner_id =
- RTE_ETH_DEV_NO_OWNER + 1;
- eth_dev_shared_data->allocated_ports = 0;
- memset(eth_dev_shared_data->data, 0,
- sizeof(eth_dev_shared_data->data));
+ eth_dev_shared_data->allocated_owners = 0;
+ eth_dev_shared_data->next_owner_id =
+ RTE_ETH_DEV_NO_OWNER + 1;
+ eth_dev_shared_data->allocated_ports = 0;
+ memset(eth_dev_shared_data->data, 0,
+ sizeof(eth_dev_shared_data->data));
+ } else {
+ mz = rte_memzone_lookup(MZ_RTE_ETH_DEV_DATA);
+ if (mz == NULL) {
+ /* Clean remaining any traces of a previous shared mem */
+ eth_dev_shared_mz = NULL;
+ eth_dev_shared_data = NULL;
+ RTE_ETHDEV_LOG(ERR, "Cannot lookup ethdev shared data\n");
+ goto out;
}
+ if (mz == eth_dev_shared_mz && mz->addr == eth_dev_shared_data)
+ goto out;
+
+ /* Shared mem changed in primary process, refresh pointers */
+ eth_dev_shared_mz = mz;
+ eth_dev_shared_data = mz->addr;
}
out:
return eth_dev_shared_data;
--
2.41.0
next reply other threads:[~2023-10-20 12:06 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-20 12:06 David Marchand [this message]
2023-10-26 13:11 ` Ferruh Yigit
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=20231020120629.2158219-1-david.marchand@redhat.com \
--to=david.marchand@redhat.com \
--cc=anatoly.burakov@intel.com \
--cc=andrew.rybchenko@oktetlabs.ru \
--cc=dev@dpdk.org \
--cc=ferruh.yigit@amd.com \
--cc=mb@smartsharesystems.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).