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 E8390A0C4D; Fri, 13 Aug 2021 10:16:40 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6B2FA40151; Fri, 13 Aug 2021 10:16: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 07BBE40140 for ; Fri, 13 Aug 2021 10:16:37 +0200 (CEST) Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4GmGWR63hPz8716; Fri, 13 Aug 2021 16:12:35 +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 16:16:21 +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 16:16:20 +0800 To: Thomas Monjalon CC: "Yigit, Ferruh" , Andrew Rybchenko , "dev@dpdk.org" References: <1627908397-51565-1-git-send-email-lihuisong@huawei.com> <1627957839-38279-1-git-send-email-lihuisong@huawei.com> <9670389d-ebbc-9d9c-0cac-c7e8826ecb6f@huawei.com> <21383486.34YfpWhNxb@thomas> From: Huisong Li Message-ID: Date: Fri, 13 Aug 2021 16:16:20 +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: <21383486.34YfpWhNxb@thomas> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.66.74.184] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) 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" 在 2021/8/13 14:12, Thomas Monjalon 写道: > 13/08/2021 04:11, Huisong Li: >> 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, > It is not a bad scenario. > If there is no more port for the device after calling close, > the device should be removed automatically. > Keep in mind "close" is for one port, "remove" is for the entire device > which can have more than one port. I know. dev_close() is for removing an eth device. And rte_dev_remove() can be used for removing the rte device and all its eth devices belonging to the rte device. In rte_dev_remove(), "remove" is executed in primary or one of secondary, all eth devices having same pci address will be closed and removed. > >>> 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. > If a port is closed in primary, it should be the same in secondary. > > >>> + /* >>> + * 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. > This assumption is not clear. All should be closed together. However, dev_close() does not have the feature similar to rte_dev_remove(). Namely, it is not guaranteed that all eth devices are closed together in ethdev layer. It depends on app or user. If the app does not close together, the operation of repeatedly uninstalling an eth device in the secondary process will be triggered when dev_close() is first called by one secondary process, and then rte_dev_remove() is called. So I think it should be avoided. > >>> + * 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; >>> + } > > > .