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 391EFA0C52; Fri, 13 Aug 2021 04:11:41 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id AAB9B4069E; Fri, 13 Aug 2021 04:11:40 +0200 (CEST) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by mails.dpdk.org (Postfix) with ESMTP id E860640151 for ; Fri, 13 Aug 2021 04:11:38 +0200 (CEST) Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Gm6Qf70YlzdZMc; Fri, 13 Aug 2021 10:07: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; Fri, 13 Aug 2021 10:11:35 +0800 Received: from [10.66.74.184] (10.66.74.184) 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; Fri, 13 Aug 2021 10:11:34 +0800 To: Thomas Monjalon , "Yigit, Ferruh" , Andrew Rybchenko CC: "dev@dpdk.org" References: <1627908397-51565-1-git-send-email-lihuisong@huawei.com> <1627957839-38279-1-git-send-email-lihuisong@huawei.com> From: Huisong Li Message-ID: <9670389d-ebbc-9d9c-0cac-c7e8826ecb6f@huawei.com> Date: Fri, 13 Aug 2021 10:11:34 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.8.0 MIME-Version: 1.0 In-Reply-To: <1627957839-38279-1-git-send-email-lihuisong@huawei.com> Content-Type: text/plain; charset="gbk"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.66.74.184] 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: Re: [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" Hi, all This patch can enhance the security of device uninstallation to eliminate dependency on user usage methods. Can you check this patch? ÔÚ 2021/8/3 10:30, Huisong Li дµÀ: > 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)