From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 93BCAC4338F for ; Tue, 3 Aug 2021 02:34:27 +0000 (UTC) Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by mail.kernel.org (Postfix) with ESMTP id 05BE260724 for ; Tue, 3 Aug 2021 02:34:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 05BE260724 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=dpdk.org 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