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 9C517423AC; Wed, 11 Jan 2023 13:51:55 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 92CD942D1F; Wed, 11 Jan 2023 13:51:55 +0100 (CET) Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2046.outbound.protection.outlook.com [40.107.237.46]) by mails.dpdk.org (Postfix) with ESMTP id BD51240A7D for ; Wed, 11 Jan 2023 13:51:53 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FgWEFx+NbWUz2AX/rlOhvU3Hfum9hBR+WkASGFTEoUAuk2sAFaZcTbSaMGSTbPXF3iK54YjQeB0gkypYeb5N6ZXlqhfnUVBYTiu38lsUw8UXdSnc7XrlJSXLQpuj3GmqX1v09fNldxaa/sU1+eTiNqxYPLdLRtnscZmfR7/WR8V+6Me4smLKgsq9h6eSp42Vc3u7rDIzLb9aDz9pgv7cpxK8d8L7m60oYiziT/p+7mezAcIYCii0AhpDfxZFcP4VmfAhP7ygSjA3CQ5ArB4CQSLV9bSK19aUdGn1wcUPbfIU26zNWnozSadfgiRY9p780kBSLqUehhpmhwW6PBN1zQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=NqsnKpiOJtMwvMPMiqbSnJlvqEDQJyUR86RSIpbECFo=; b=gDHE3NA5omRJx5C1Z1cfnXCbRdFD1J0Xq4Gg14k2LvSvRWLTeM9WZwQuCx8WgqtBYSy4DxUo9xqER/3ETxqgXr5zNQOMQCd56xaV5QfaL8QBdc3cquIpS9kk7uveLzK/G487AR7Kqqh5YBO4lUQB9NyWiCmoBYanp9Tbr0+NPW2p8og8xnUZCj8opX+RiQhl6Yb9LBBrBMZtd8x6pfp9vBzyJ1NP2RzIaYeg66emtYz1iPVaP4YxBlMMTEdpEi+GxB78yQYNSq5Q/GKnhcUAY+dOBDIBR6q0xClHjYF9zJpJQ0rnV6O7UpyoWhuO7v0pWmTcLU6/OfpAUHM9LI++Gg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=NqsnKpiOJtMwvMPMiqbSnJlvqEDQJyUR86RSIpbECFo=; b=fIKJOnpJyXBl44nVgv3ppIaxB2mK/DSPnGI0MmTDi5jJpSAbEsrqTUU385yLGM13j9nfY29bhItTozsAPe7ViNLeB6MxeLXUa7MKL2lyELnY0NYIfGAwcrdrJU7kbKF3jDvU+lt3S8PWEEQZf6PH0CJbENUdtKIK3F0H+1PEAks= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Received: from CH2PR12MB4294.namprd12.prod.outlook.com (2603:10b6:610:a9::11) by CH0PR12MB5332.namprd12.prod.outlook.com (2603:10b6:610:d7::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5986.18; Wed, 11 Jan 2023 12:51:52 +0000 Received: from CH2PR12MB4294.namprd12.prod.outlook.com ([fe80::4807:1f44:5e04:e05a]) by CH2PR12MB4294.namprd12.prod.outlook.com ([fe80::4807:1f44:5e04:e05a%9]) with mapi id 15.20.5986.018; Wed, 11 Jan 2023 12:51:52 +0000 Message-ID: Date: Wed, 11 Jan 2023 12:51:45 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Content-Language: en-US To: Huisong Li , dev@dpdk.org, andrew.rybchenko@oktetlabs.ru Cc: thomas@monjalon.net, liudongdong3@huawei.com, huangdaode@huawei.com, fengchengwen@huawei.com References: <20220825024425.10534-1-lihuisong@huawei.com> <20221206092649.8287-1-lihuisong@huawei.com> <20221206092649.8287-3-lihuisong@huawei.com> From: Ferruh Yigit Subject: Re: [PATCH V4 2/5] ethdev: fix skip valid port in probing callback In-Reply-To: <20221206092649.8287-3-lihuisong@huawei.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-ClientProxiedBy: LO2P123CA0106.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:139::21) To CH2PR12MB4294.namprd12.prod.outlook.com (2603:10b6:610:a9::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PR12MB4294:EE_|CH0PR12MB5332:EE_ X-MS-Office365-Filtering-Correlation-Id: cc9ce4d4-e7b2-488e-b19a-08daf3d29c53 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 0XeQZuTL8xqH7wNRB++wVwC3zFz681eLPNYQzDtchejbjlcdJI2xOgpuR3bKHtWa/zZYHUGYuRTnw6+z63udNFQK89PY8unowIrgzal/zCbFfsvBRCOUWaTFZYhTdeSmKpenMF4XopTfcV6D86u1H3/z4gZaiBhstNXRLYGs+QQvbpLC46qc6ftYnh6QKlH5BXasb6DByksE2EQe/zhqMdKpuD6pw0rfxtMsuyMTNLGPCN/LkI7kr72YKpD7krv0+5zQple9s/x7szPQNC1U+T8aGkMIOEy1a6xxEtdPbcrZUyAx8Z9IWBsRgC8e4V6MzGEpfDPNgEFQU08Of2p+w1IJq18wpfn1W7SR2MZ6GPio3J+h0QOEqxgSF8sFRoEmuAwCNzHqfLXQhqW2srdYSMWB9CLMCQpoR3Ns8EonuFmLnOJfCQVnq9ENvn8QRLXiZN4618OgI4Q9a0Lj8KwkjfI1FJ6q5DdO+ZGtInN9OAtmIrJlkuSWEJMd3g7U3ssqIL7gLJn1TIkFFuoSN5GYky61ZiAhSgf8WLCHVFZ86S+UHFf9cOcEB9UpDnvXSgrnVMfFQo2zoZltyTyphJN/u1J8/nKS0qg4EHAu5mx+kVpqByibAgM9IqQn1fxqUFuZQRToULW9UV4g1Iap6zpsc8ef69ZNH2s6Hj79ZlcpD3e/1aNx4I7xrpkzk/OY9THee8eZwwMQmx5yZ98MkVzry9Tk8SciELZn3+KuKGy6uGw= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CH2PR12MB4294.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(4636009)(346002)(396003)(39860400002)(136003)(366004)(376002)(451199015)(6506007)(38100700002)(6666004)(53546011)(31686004)(2906002)(44832011)(478600001)(2616005)(6486002)(186003)(6512007)(26005)(316002)(5660300002)(31696002)(83380400001)(8936002)(36756003)(86362001)(66476007)(4326008)(8676002)(41300700001)(66556008)(66946007)(45980500001)(43740500002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?Y251bkgxRjgyK2FPWEN2QjlkVzZ1Q25NSW1XMFRaVkEyMVJVcnFnRUo5NEtX?= =?utf-8?B?Y254ekNRS3B6c205V1FFVFlzM2R2TTJjanY2WTJ4NmROazFSSmpyLzFkQlZF?= =?utf-8?B?bXRadjhRMWlxSGJLbng5QzE0cVgvRFdjSHFDNGpDak51ajRmT1FBNmNrZjdD?= =?utf-8?B?eTExYlBLUjJUcmt0UEtZbEQxVHBMa1NpUDZnU0ZzLzVLQWdEbTJ5UDdBUmRX?= =?utf-8?B?alVqNE92MEY1eXdObk5yZm1DZkE4eUJGQX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f-8?B?clRCLy80eFNmS3JaZmY0elY4VFV4anQ0UWpkd3kyNHVWRUNCMEVGQ282QWFz?= =?utf-8?Q?YsFjiADRxjI7qKm+kueHXKAbH?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: cc9ce4d4-e7b2-488e-b19a-08daf3d29c53 X-MS-Exchange-CrossTenant-AuthSource: CH2PR12MB4294.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Jan 2023 12:51:51.9477 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: ggueLaigH+YbUgq7Mnjfvmwt2yuc/0phJRY9SabaxS9PDkDytGG8GqThVKHTogG1 X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR12MB5332 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 On 12/6/2022 9:26 AM, Huisong Li wrote: > The event callback in application may use the macro RTE_ETH_FOREACH_DEV to > iterate over all enabled ports to do something(like, verifying the port id > validity) when receive a probing event. If the ethdev state of a port is > RTE_ETH_DEV_UNUSED, this port will be skipped. > > Currently, this state is set to RTE_ETH_DEV_ATTACHED after pushing probing > event. It means that probing callback will skip this port. But this > assignment can not move to front of probing notification. See > commit be8cd210379a ("ethdev: fix port probing notification") > OK to abstract ethdev state check to a function, 'rte_eth_dev_in_used'. BTW, I guess intention is to say 'is' instead of 'in', like 'rte_eth_dev_is_used'. But not sure if new state is necessary. I can see from next patches that if testpmd event callback wants to validate port_id, it is using 'port_id_is_invalid()' function which is using 'RTE_ETH_FOREACH_DEV' macro. And using 'RTE_ETH_FOREACH_DEV' macro in callback function has the problem you described above. 1) Do we really need to validate port_id in the event callback, callback provided 'port_id' from 'rte_eth_dev_callback_process()' API, from 'dev->data->port_id'. I am not sure if there is case that 'dev->data->port_id' can be invalid. 2) is there any other specific usecase to use 'RTE_ETH_FOREACH_DEV' in the 'RTE_ETH_EVENT_NEW' event callback function? > So this patch has to add a new state, RTE_ETH_DEV_ALLOCATED. Set the ethdev > state to RTE_ETH_DEV_ALLOCATED before pushing probing event and to > RTE_ETH_DEV_ATTACHED when definitely probed. And this port is valid if its > device state is ALLOCATED or ATTACHED. Naturally, a lot of places had to be > modified for this change. > > Fixes: be8cd210379a ("ethdev: fix port probing notification") > Cc: stable@dpdk.org > > Signed-off-by: Huisong Li > --- > drivers/net/bnxt/bnxt_ethdev.c | 3 ++- > drivers/net/mlx5/mlx5.c | 2 +- > lib/ethdev/ethdev_driver.c | 13 ++++++++++--- > lib/ethdev/ethdev_driver.h | 12 ++++++++++++ > lib/ethdev/ethdev_pci.h | 2 +- > lib/ethdev/rte_class_eth.c | 2 +- > lib/ethdev/rte_ethdev.c | 4 ++-- > lib/ethdev/rte_ethdev.h | 4 +++- > lib/ethdev/version.map | 1 + > 9 files changed, 33 insertions(+), 10 deletions(-) > > diff --git a/drivers/net/bnxt/bnxt_ethdev.c b/drivers/net/bnxt/bnxt_ethdev.c > index b3de490d36..7b08353ed5 100644 > --- a/drivers/net/bnxt/bnxt_ethdev.c > +++ b/drivers/net/bnxt/bnxt_ethdev.c > @@ -6003,7 +6003,8 @@ bnxt_dev_uninit(struct rte_eth_dev *eth_dev) > > PMD_DRV_LOG(DEBUG, "Calling Device uninit\n"); > > - if (eth_dev->state != RTE_ETH_DEV_UNUSED) > + > + if (rte_eth_dev_in_used(eth_dev->state)) > bnxt_dev_close_op(eth_dev); > > return 0; > diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c > index e55be8720e..949d8c1367 100644 > --- a/drivers/net/mlx5/mlx5.c > +++ b/drivers/net/mlx5/mlx5.c > @@ -3014,7 +3014,7 @@ mlx5_eth_find_next(uint16_t port_id, struct rte_device *odev) > while (port_id < RTE_MAX_ETHPORTS) { > struct rte_eth_dev *dev = &rte_eth_devices[port_id]; > > - if (dev->state != RTE_ETH_DEV_UNUSED && > + if (rte_eth_dev_in_used(dev->state) && > dev->device && > (dev->device == odev || > (dev->device->driver && > diff --git a/lib/ethdev/ethdev_driver.c b/lib/ethdev/ethdev_driver.c > index 0be1e8ca04..7868958dff 100644 > --- a/lib/ethdev/ethdev_driver.c > +++ b/lib/ethdev/ethdev_driver.c > @@ -50,8 +50,8 @@ eth_dev_find_free_port(void) > for (i = 0; i < RTE_MAX_ETHPORTS; i++) { > /* Using shared name field to find a free port. */ > if (eth_dev_shared_data->data[i].name[0] == '\0') { > - RTE_ASSERT(rte_eth_devices[i].state == > - RTE_ETH_DEV_UNUSED); > + RTE_ASSERT(!rte_eth_dev_in_used( > + rte_eth_devices[i].state)); > return i; > } > } > @@ -208,11 +208,18 @@ rte_eth_dev_probing_finish(struct rte_eth_dev *dev) > if (rte_eal_process_type() == RTE_PROC_SECONDARY) > eth_dev_fp_ops_setup(rte_eth_fp_ops + dev->data->port_id, dev); > > + dev->state = RTE_ETH_DEV_ALLOCATED; > rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_NEW, NULL); > > dev->state = RTE_ETH_DEV_ATTACHED; > } > > +bool rte_eth_dev_in_used(uint16_t dev_state) > +{ > + return dev_state == RTE_ETH_DEV_ALLOCATED || > + dev_state == RTE_ETH_DEV_ATTACHED; > +} > + > int > rte_eth_dev_release_port(struct rte_eth_dev *eth_dev) > { > @@ -221,7 +228,7 @@ rte_eth_dev_release_port(struct rte_eth_dev *eth_dev) > > eth_dev_shared_data_prepare(); > > - if (eth_dev->state != RTE_ETH_DEV_UNUSED) > + if (rte_eth_dev_in_used(eth_dev->state)) > rte_eth_dev_callback_process(eth_dev, > RTE_ETH_EVENT_DESTROY, NULL); > > diff --git a/lib/ethdev/ethdev_driver.h b/lib/ethdev/ethdev_driver.h > index 6a550cfc83..e04f88fe46 100644 > --- a/lib/ethdev/ethdev_driver.h > +++ b/lib/ethdev/ethdev_driver.h > @@ -1542,6 +1542,18 @@ int rte_eth_dev_callback_process(struct rte_eth_dev *dev, > __rte_internal > void rte_eth_dev_probing_finish(struct rte_eth_dev *dev); > > +/** > + * Check if a Ethernet device state is in used or not > + * > + * @param dev_state > + * The state of the Ethernet device > + * @return > + * - true if the state of the Ethernet device is allocated or attached > + * - false if this state is neither allocated nor attached > + */ > +__rte_internal > +bool rte_eth_dev_in_used(uint16_t dev_state); > + > /** > * Create memzone for HW rings. > * malloc can't be used as the physical address is needed. > diff --git a/lib/ethdev/ethdev_pci.h b/lib/ethdev/ethdev_pci.h > index 94b8fba5d7..362e5c2dec 100644 > --- a/lib/ethdev/ethdev_pci.h > +++ b/lib/ethdev/ethdev_pci.h > @@ -164,7 +164,7 @@ rte_eth_dev_pci_generic_remove(struct rte_pci_device *pci_dev, > * eth device has been released. > */ > if (rte_eal_process_type() == RTE_PROC_SECONDARY && > - eth_dev->state == RTE_ETH_DEV_UNUSED) > + !rte_eth_dev_in_used(eth_dev->state)) > return 0; > > if (dev_uninit) { > diff --git a/lib/ethdev/rte_class_eth.c b/lib/ethdev/rte_class_eth.c > index 838b3a8f9f..a78d503e59 100644 > --- a/lib/ethdev/rte_class_eth.c > +++ b/lib/ethdev/rte_class_eth.c > @@ -118,7 +118,7 @@ eth_dev_match(const struct rte_eth_dev *edev, > const struct rte_kvargs *kvlist = arg->kvlist; > unsigned int pair; > > - if (edev->state == RTE_ETH_DEV_UNUSED) > + if (!rte_eth_dev_in_used(edev->state)) > return -1; > if (arg->device != NULL && arg->device != edev->device) > return -1; > diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c > index 5d5e18db1e..a225141937 100644 > --- a/lib/ethdev/rte_ethdev.c > +++ b/lib/ethdev/rte_ethdev.c > @@ -325,7 +325,7 @@ uint16_t > rte_eth_find_next(uint16_t port_id) > { > while (port_id < RTE_MAX_ETHPORTS && > - rte_eth_devices[port_id].state == RTE_ETH_DEV_UNUSED) > + !rte_eth_dev_in_used(rte_eth_devices[port_id].state)) > port_id++; > > if (port_id >= RTE_MAX_ETHPORTS) > @@ -372,7 +372,7 @@ int > rte_eth_dev_is_valid_port(uint16_t port_id) > { > if (port_id >= RTE_MAX_ETHPORTS || > - (rte_eth_devices[port_id].state == RTE_ETH_DEV_UNUSED)) > + !rte_eth_dev_in_used(rte_eth_devices[port_id].state)) > return 0; > else > return 1; > diff --git a/lib/ethdev/rte_ethdev.h b/lib/ethdev/rte_ethdev.h > index c129ca1eaf..459ad44021 100644 > --- a/lib/ethdev/rte_ethdev.h > +++ b/lib/ethdev/rte_ethdev.h > @@ -2000,7 +2000,9 @@ typedef uint16_t (*rte_tx_callback_fn)(uint16_t port_id, uint16_t queue, > enum rte_eth_dev_state { > /** Device is unused before being probed. */ > RTE_ETH_DEV_UNUSED = 0, > - /** Device is attached when allocated in probing. */ > + /** Device is allocated and is set before reporting new event. */ > + RTE_ETH_DEV_ALLOCATED, > + /** Device is attached when definitely probed. */ > RTE_ETH_DEV_ATTACHED, > /** Device is in removed state when plug-out is detected. */ > RTE_ETH_DEV_REMOVED, > diff --git a/lib/ethdev/version.map b/lib/ethdev/version.map > index 17201fbe0f..66d70f1aac 100644 > --- a/lib/ethdev/version.map > +++ b/lib/ethdev/version.map > @@ -327,4 +327,5 @@ INTERNAL { > rte_eth_representor_id_get; > rte_eth_switch_domain_alloc; > rte_eth_switch_domain_free; > + rte_eth_dev_in_used; > };