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 5B947A0C47; Tue, 12 Oct 2021 13:43:53 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 3B8F441143; Tue, 12 Oct 2021 13:43:53 +0200 (CEST) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mails.dpdk.org (Postfix) with ESMTP id 740EF4113A for ; Tue, 12 Oct 2021 13:43:51 +0200 (CEST) Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4HTDGL0GbTzbn2j; Tue, 12 Oct 2021 19:39:22 +0800 (CST) Received: from dggema767-chm.china.huawei.com (10.1.198.209) by dggemv704-chm.china.huawei.com (10.3.19.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2308.8; Tue, 12 Oct 2021 19:43:49 +0800 Received: from localhost.localdomain (10.67.165.24) by dggema767-chm.china.huawei.com (10.1.198.209) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.8; Tue, 12 Oct 2021 19:43:48 +0800 From: Huisong Li To: CC: , , , , , Date: Tue, 12 Oct 2021 19:39:34 +0800 Message-ID: <20211012113934.23611-1-lihuisong@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <1627908397-51565-1-git-send-email-lihuisong@huawei.com> References: <1627908397-51565-1-git-send-email-lihuisong@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.67.165.24] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggema767-chm.china.huawei.com (10.1.198.209) X-CFilter-Loop: Reflected Subject: [dpdk-dev] [PATCH V2] ethdev: fix eth device released repeatedly 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" The rte_eth_dev_pci_generic_remove() will be called to detach an Ethernet device when App calls rte_dev_remove() to detach a pci device. In addition, the rte_eth_dev_close() can also detach an Ethernet device. In secondary process, if App first calls rte_eth_dev_close() and then calls rte_dev_remove(), because rte_eth_dev_close() doesn't clear "eth_dev->data" , the address of the released Ethernet device can still be found by device name. As a result, the Ethernet device will be released repeatedly in this case. The state of the Ethernet device is equal to RTE_ETH_DEV_UNUSED after calling rte_eth_dev_close(). Use this state to avoid this problem. Signed-off-by: Huisong Li --- v1 -> v2: * fix the commit log description. RFC -> v1: * fix commit log and add a judgment for secondary process. --- lib/ethdev/ethdev_pci.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/ethdev/ethdev_pci.h b/lib/ethdev/ethdev_pci.h index 8edca82ce8..af01cceddf 100644 --- a/lib/ethdev/ethdev_pci.h +++ b/lib/ethdev/ethdev_pci.h @@ -151,6 +151,21 @@ rte_eth_dev_pci_generic_remove(struct rte_pci_device *pci_dev, if (!eth_dev) return 0; + /* + * In secondary process, if applications first call rte_eth_dev_close() + * and then call this interface, because rte_eth_dev_close() doesn't + * clear eth_dev->data, the address of the released Ethernet device can + * still be found by device name. As a result, the Ethernet device will + * be released repeatedly in this case. + * The state of the Ethernet device is equal to RTE_ETH_DEV_UNUSED after + * calling rte_eth_dev_close(). Use this state to avoid this problem. + */ + if (rte_eal_process_type() != RTE_PROC_PRIMARY && + eth_dev->state == RTE_ETH_DEV_UNUSED) { + RTE_ETHDEV_LOG(INFO, "The ethdev port has been released."); + return 0; + } + if (dev_uninit) { ret = dev_uninit(eth_dev); if (ret) -- 2.33.0