From patchwork Mon Aug 2 12:46:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "lihuisong (C)" X-Patchwork-Id: 96535 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 3C8B5A0C41; Mon, 2 Aug 2021 14:50:30 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B5A2641147; Mon, 2 Aug 2021 14:50:29 +0200 (CEST) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mails.dpdk.org (Postfix) with ESMTP id DBBAE40140 for ; Mon, 2 Aug 2021 14:50:28 +0200 (CEST) Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Gdd722CZVzZwdk; Mon, 2 Aug 2021 20:46:54 +0800 (CST) Received: from dggema767-chm.china.huawei.com (10.1.198.209) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2176.2; Mon, 2 Aug 2021 20:50:26 +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; Mon, 2 Aug 2021 20:50:26 +0800 From: Huisong Li To: CC: , , Date: Mon, 2 Aug 2021 20:46:37 +0800 Message-ID: <1627908397-51565-1-git-send-email-lihuisong@huawei.com> X-Mailer: git-send-email 2.8.1 MIME-Version: 1.0 X-Originating-IP: [10.67.165.24] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggema767-chm.china.huawei.com (10.1.198.209) X-CFilter-Loop: Reflected Subject: [dpdk-dev] [RFC V1] ethdev: fix the issue that dev uninit may be called 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(). However, these two APIs do not have explicit invocation restrictions. In other words, at the ethdev layer, calling rte_eth_dev_close() and then rte_dev_remove() or rte_eal_hotplug_remove() is allowed. In such a bad scenario, the primary process may be fine, but it may cause that dev_unint() in the secondary process will be called twice, and even other serious problems. So this patch fixes it. Fixes: 99a2dd955fba ("lib: remove librte_ prefix from directory names") Signed-off-by: Huisong Li --- 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..14a0e01 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 precess, + * 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 precess and secondary precess, 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)