From patchwork Fri Oct 20 12:06:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Marchand X-Patchwork-Id: 133074 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 4734A431A1; Fri, 20 Oct 2023 14:06:58 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id BEC6E402C2; Fri, 20 Oct 2023 14:06:57 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id BF96140283 for ; Fri, 20 Oct 2023 14:06:55 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697803615; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=LefwVJEU4jbCY3ndl53vfe1pZV10FgCgCuJAww44Vtc=; b=IYeeMoJ/CYakvsqD9aMsVw2fa+s3bo1EdRO3GoQgRdk503YpYQrZdoaC24prUx7rRnGZgY GDCQBZvA3XPCitzhFXUSUHMW1GKiG4G+jRvd2IJX8H7qO4xBUvFl4YuwmtR6kd1/yGy3qy YdkdrOCAnhzXHvuzUQPdvdsdAl6yH5o= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-68-wDGyeU0zPGmhwBZndeaKRQ-1; Fri, 20 Oct 2023 08:06:45 -0400 X-MC-Unique: wDGyeU0zPGmhwBZndeaKRQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9313F2825EA2; Fri, 20 Oct 2023 12:06:44 +0000 (UTC) Received: from dmarchan.redhat.com (unknown [10.45.225.182]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1B0DAC15BB8; Fri, 20 Oct 2023 12:06:42 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: Thomas Monjalon , Ferruh Yigit , Andrew Rybchenko , Anatoly Burakov , =?utf-8?q?Morten_Br=C3=B8rup?= Subject: [PATCH] ethdev: refresh shared memory reference in secondary process Date: Fri, 20 Oct 2023 14:06:29 +0200 Message-ID: <20231020120629.2158219-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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 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 Reviewed-by: Ferruh Yigit --- 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;