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 3E54FA0C41; Tue, 3 Aug 2021 04:34:26 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 058C740E32; Tue, 3 Aug 2021 04:34:25 +0200 (CEST) Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by mails.dpdk.org (Postfix) with ESMTP id B218A4069C for ; Tue, 3 Aug 2021 04:34:23 +0200 (CEST) Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.57]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4GdzNC1vwFz81Bv; Tue, 3 Aug 2021 10:29:31 +0800 (CST) Received: from dggema767-chm.china.huawei.com (10.1.198.209) by dggemv711-chm.china.huawei.com (10.1.198.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2176.2; Tue, 3 Aug 2021 10:34:20 +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.2176.2; Tue, 3 Aug 2021 10:34:20 +0800 From: Huisong Li To: CC: , , Date: Tue, 3 Aug 2021 10:30:39 +0800 Message-ID: <1627957839-38279-1-git-send-email-lihuisong@huawei.com> X-Mailer: git-send-email 2.8.1 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-Type: text/plain X-Originating-IP: [10.67.165.24] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggema767-chm.china.huawei.com (10.1.198.209) X-CFilter-Loop: Reflected Subject: [dpdk-dev] [RFC V2] ethdev: fix issue that dev close in PMD calls twice 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" Ethernet devices in DPDK can be released by rte_eth_dev_close() and rte_dev_remove(). These APIs both call xxx_dev_close() in PMD layer to uninstall hardware. However, the two APIs do not have explicit invocation restrictions. In other words, at the ethdev layer, it is possible to call rte_eth_dev_close() before calling rte_dev_remove() or rte_eal_hotplug_remove(). In such a bad scenario, the primary process may be fine, but it may cause that xxx_dev_close() in the PMD layer will be called twice in the secondary process. So this patch fixes it. Fixes: 99a2dd955fba ("lib: remove librte_ prefix from directory names") Signed-off-by: Huisong Li --- v2: fix commit description --- lib/ethdev/ethdev_pci.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/ethdev/ethdev_pci.h b/lib/ethdev/ethdev_pci.h index 8edca82..429c4c7 100644 --- a/lib/ethdev/ethdev_pci.h +++ b/lib/ethdev/ethdev_pci.h @@ -151,6 +151,19 @@ rte_eth_dev_pci_generic_remove(struct rte_pci_device *pci_dev, if (!eth_dev) return 0; + /* + * The eth_dev->data->name doesn't be cleared by the secondary process, + * so above "eth_dev" isn't NULL after rte_eth_dev_close() called. + * Namely, whether "eth_dev" is NULL cannot be used to determine whether + * an ethdev port has been released. + * For both primary process and secondary process, eth_dev->state is + * RTE_ETH_DEV_UNUSED, which means the ethdev port has been released. + */ + if (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.8.1