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 55E70460E4; Wed, 29 Jan 2025 09:54:34 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id DFB3340270; Wed, 29 Jan 2025 09:54:33 +0100 (CET) Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2048.outbound.protection.outlook.com [40.107.243.48]) by mails.dpdk.org (Postfix) with ESMTP id DCB0C4026B for ; Wed, 29 Jan 2025 09:54:32 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=cutLkYj/dDjWxcmGq5McBLqaEYzBwL7MtilvWbq242videkrYR4LBfb2VsNL4mPFXAgjCEHaY83PyTZWC+Ve3OpI8mGwMoPc+kdK6it7Xb285u8y88ZnKjAUxins9EQZtH4aRdgHXu8u3+l9LRHH9TaksTPjIMuEzdQH/YKVwqtaUKRSLIZx9AvCFxls7xmgaoNquLwM4B1HmaZBKUcYJnJqTNzaATay7V4Afpi6u2iNt0y0nU7DPoXIeXpgco1X0m5MreXpODmpDm8vfr+g9lTYpdUHaB1v4B7OU6PuBgNrm/Mjm/+Lqn47f0mnDR1nDemc97Yfm7aYTWquhJf8RA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=XyhG1s7ZZmYMdzYGUt0paq96hQbeh7783Dn/PnrkFg0=; b=Mgy8RvmAIgyuSbLn4DHs3icoWuy/k8hhfJgZHWNwR3e+RFqiKFP/Dr2Zm/or3v6JAH2DJYpgjfeTmsF5zoo97otJJjmykjC21rW7znAxscP2mrrc5p8uj4yEponZWENwjJYmgRoNF+dePasLOSeg5SOtr0rZpchD52Ln+6eVtWJE1uviS+xQLgWXM0gB0ZfTX19GqsOMBi5A8NruxP1zTO1EQsCmWXpqfITonrVFKqR6gXEePMZu3BJDvbxnaEUZWInmjg2YZnEU8rpZSqQfZQD9boQOmwgf/n+XVm3HmnoQeLZ+9VdKnvk64STlkHMvOghuKUP2fzXxMbzxV8+4Bg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.233) smtp.rcpttodomain=dpdk.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=XyhG1s7ZZmYMdzYGUt0paq96hQbeh7783Dn/PnrkFg0=; b=Rt9XYxJpHvMIw2R2dIX8Y+CwAkD8iz4qAFl0AdZ9h4it+Lfm4tZP4xwgSPaOtNQL/3Wr+YjznAWiR0V74qtRrOoioLhMG5focldsSirQuZEo/KHZsp/2hDySgXcGCbuPRxSZ5Jjd35xIdK9XuX7rGsOwSCnuLIGdscfHBVye/tmNMZGH8Hu8QrwIhWxbt0ZLkuz5Avfipj8fjHxqoOIPnY4HGX/m5gmVHmla28GT69tzssJrlyaEDBeoxmHXyH914/sgvGBVDyCfu5onfHXqLBVLnPQZve4IZ6eQZBJLpclWVV8WkZeKv5YbZC3qnRrMCK/Rj1ulBO8nN9qEm/Z0SQ== Received: from CH0PR04CA0059.namprd04.prod.outlook.com (2603:10b6:610:77::34) by PH8PR12MB7446.namprd12.prod.outlook.com (2603:10b6:510:216::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8377.22; Wed, 29 Jan 2025 08:54:27 +0000 Received: from CH2PEPF00000144.namprd02.prod.outlook.com (2603:10b6:610:77:cafe::37) by CH0PR04CA0059.outlook.office365.com (2603:10b6:610:77::34) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8398.17 via Frontend Transport; Wed, 29 Jan 2025 08:54:27 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.233) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.118.233 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.233; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.233) by CH2PEPF00000144.mail.protection.outlook.com (10.167.244.101) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8398.14 via Frontend Transport; Wed, 29 Jan 2025 08:54:26 +0000 Received: from drhqmail203.nvidia.com (10.126.190.182) by mail.nvidia.com (10.127.129.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Wed, 29 Jan 2025 00:54:25 -0800 Received: from drhqmail201.nvidia.com (10.126.190.180) by drhqmail203.nvidia.com (10.126.190.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.14; Wed, 29 Jan 2025 00:54:24 -0800 Received: from nvidia.com (10.127.8.14) by mail.nvidia.com (10.126.190.180) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.14 via Frontend Transport; Wed, 29 Jan 2025 00:54:20 -0800 From: Shani Peretz To: CC: , Shani Peretz , Tyler Retzlaff , Parav Pandit , Xueming Li , Nipun Gupta , Nikhil Agarwal , Hemant Agrawal , "Sachin Saxena" , Rosen Xu , Chenbo Xia , Tomasz Duszynski , "Chengwen Feng" , Long Li , Wei Hu , Bruce Richardson , "Kevin Laatz" , Jan Blunck Subject: [PATCH v4] bus: fix inconsistent representation of PCI numbers Date: Wed, 29 Jan 2025 10:54:16 +0200 Message-ID: <20250129085416.226718-1-shperetz@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240708165145.1405107-1-shperetz@nvidia.com> References: <20240708165145.1405107-1-shperetz@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-NV-OnPremToCloud: AnonymousSubmission X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PEPF00000144:EE_|PH8PR12MB7446:EE_ X-MS-Office365-Filtering-Correlation-Id: 692a82f5-be44-43b1-cf75-08dd4042890a X-LD-Processed: 43083d15-7273-40c1-b7db-39efd9ccc17a,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|82310400026|36860700013|1800799024|7416014; X-Microsoft-Antispam-Message-Info: =?utf-8?B?c2U5UVV0M05LK0RDWmJwb0JGeTc3RjB6ODBvVDFRaDliQlJsSXZuc20rcFM3?= =?utf-8?B?TzI5ZE8rZmxJam9jVmpOcVZnQWE0ZkxjNm4xMXF3WWlmYXZnWkR1MGU5a2t5?= =?utf-8?B?TCtjTkJHY1VjRXlFTzkvd3ZrbkVJanprK052WHozNWwwVTdrYmtVRXBtQzdh?= =?utf-8?B?ME1Jc3BtQm5JT0NMLzFGQUhxdjQrR2hYR0NnMithc1FETUpVeEk4ZThOUnVs?= =?utf-8?B?Q1NYeUhkOFpCZ2pSZG1naFE3cWUxVzE2L056NFN3OTk2aHZnditMekF5eHE0?= =?utf-8?B?bW5lUkpzQ1dySThmU1FjYnIxNDg2aTBwUS9zL0RjQzlOZlIxajZwNWJPRnU1?= =?utf-8?B?czd1OWRVVkJHbHNuQXo2dGdWUUVPNmJvemwxZWE0ZzhZdjd2NW92dVk4VnJn?= =?utf-8?B?SEtqZFhZQlRGdTE2cmtxeERIYUpoY2YvMXJXOS9WVlhMUmJsbkRnYUFxTm5J?= =?utf-8?B?M1Uyak5kRGZiWWhSTG9sdUpxcHRRUlE1blJycDZKOFhCWnAwdFlNdmoyaFFq?= =?utf-8?B?Sk9rZkY2bFExK004K21yZkx2U1EyQmFHNEczRUFBR0dGMUdFSDJoMEJCUG1X?= =?utf-8?B?eTF1Y3lia0VMME9BLzJNQlkzdDVaZ3U2WFR0M1VrbmV6ZzAxaVVRcXF5YXZo?= =?utf-8?B?ZnFDMldmNzlDZWdVMnVhRkFVMS9DcWl2b1dCcTdrcTFyZzRaQmM4MHdKeWMy?= =?utf-8?B?TXhjQ1JobzhsV1cwRWlJTTRpV2dOTVRnSmhQU05SbmY4ZDAwL0ZTWm9odmZH?= =?utf-8?B?VkxMRzlrMkxCTU1kbmdQRUFGempvWTB4amNGTXFCa2dZVHZZR0ZOYnQzbG9Y?= =?utf-8?B?ZWs3MGNoN3EyZCtVZnFCM1dLb0k3WHZEK0kwV0ZxZkt6K3FDNk1yNlR1alZn?= =?utf-8?B?U2RLaXFLQklCQ0ZoMHFFdVlPcGxhcWc4aVhSWHhjK0pISk1rc213R2Z3czlt?= =?utf-8?B?eW9nUEltYzBGS1o1Y3M5UUl1ZHQvSi9PeWd2MGdFQ2hNVGQxTTVnTlZmM243?= =?utf-8?B?UGpaejJPdm04ZitvbTFLNDh0SE56ZTN2aDh6am4xb00zUkR4N1BPSElyUy9W?= =?utf-8?B?TGVaNm8vNmpjMDFiTndHUjZoTkRyVEpIYjZiTjZSKytsS2F4SFdtOEFEakRF?= =?utf-8?B?YkF1Z29NYmVWUXhQYUI1N2hxdVR1TVJLZTZzNmRDMk9EbFF0UU9HeU13Vllx?= =?utf-8?B?eHBBc2d4MDdBUDdrd2FYKzRsRVJsME9Fd24wenowWGJhMnRuUDJtWDNoTldw?= =?utf-8?B?eVdiK2IzaW5WclBLVzhlQVlkVS9ZUzhLMk5IRTRsekQvOFYrQXBodkVpOWhM?= =?utf-8?B?ZjBvakFuRWFsQ2NFZXRoMURCZ0lCUDZRK2dlOGZ5MzlGRzJ4QWEyQmxEU25E?= =?utf-8?B?Und0S1UxVElhekxNYW9OVkZGYVl4eTJBcjVOWm9ZcHlqQzFSeVNSM3pLbEZp?= =?utf-8?B?VXRUdzVkOTJpZWxVQjBoWmZmRksxeHV1K3Y0WU81R3Vrb0xnNWR3cC83Mytp?= =?utf-8?B?VzR3eU50QkZ0T01mUk9nSE51NW03NGJDSXBhSWtzeFR4UUhGS1B6dFRvSUgy?= =?utf-8?B?aHgvRTdOU2k1SllnSngyblpybVBwOS9pZ0FKYnNDNnlmWkd6amU5UFJyRmFj?= =?utf-8?B?T3ZxdTJEMUpWUVdYS2lLRjgySHV6ZUhacWJDK1E5SWRLVkhDNVQwNTVMallL?= =?utf-8?B?aUtSK25QMkNoMWdCTWk5RFpFNGFOT0pEMnU5RUptV2tYM3dkc0w3T29xVXdo?= =?utf-8?B?c2dyRzg5dFBFbk56anIwSGpROFB1VEwzRGE5eXJqa1hVTStQZ1hiU0MyK1Ey?= =?utf-8?B?dXp2dE83Q2Y3VWkxZDZCVUx2MHFKOFVNcU5TaVZ3VDRFNWxHL0w2Z0h2R2Fp?= =?utf-8?B?OSt0L1h6ZEc4U0xKeFk2RWRSbUhHS2c2cDNkUURYVFM3VERRQW05am1pRk90?= =?utf-8?B?N1VOdGNvbVVOZkJnZjJSaXdQaUsyTis0b2lrbllMZEZyajhBS2Uxd09TRFU5?= =?utf-8?Q?Z4cJ4C0CTkjGG49eJd5KtXR13zJppA=3D?= X-Forefront-Antispam-Report: CIP:216.228.118.233; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc7edge2.nvidia.com; CAT:NONE; SFS:(13230040)(376014)(82310400026)(36860700013)(1800799024)(7416014); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jan 2025 08:54:26.6278 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 692a82f5-be44-43b1-cf75-08dd4042890a X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.118.233]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CH2PEPF00000144.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR12MB7446 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 DPDK provides two formats for specifying PCI device numbers: a full version ("0000:08:00.0") and a short version ("08:00.0"). Issues can occur when an application uses one format (e.g., short) while running testpmd, then attempts to use the other format (e.g., full) in a later command, resulting in a failure. The issue is that find_device goes over the list of devices and compares the user-provided string to the rte_device structure's device->name (device->name is just the string received from devargs (i.e "08:00.0" or "0000:08:00.0")). Notice that there's another field that represents the device name, but this one is in the rte_pci_bus struct. This name is actually the result of the PCI parse function ("0000:08:00.0"). If we want to accurately compare these names, we'll need to bring both sides to the same representation by invoking the parse function on the user input. To make the cmp_dev_name function applicable to all buses—not just PCI— the proposed solution is to utilize the parse function implemented by each bus. When comparing names, we will call parse on the supplied string as well as on the device name itself and compare the results. This will allow consistent comparisons between different representations of same devices. Also, the pci_common_set function has been modified to improve naming consistency for PCI buses. Now, the name stored in rte_device for PCI buses will match the parsed name that is also stored in rte_pci_device name, rather than using the user-provided string from devargs. As a result, when a new PCI device is registered, the name displayed in the device list will be the parsed version. Added tests that compare and find devices in various forms of names under test_devargs. Fixes: a3ee360f4440 ("eal: add hotplug add/remove device") Signed-off-by: Shani Peretz --- app/test/test_devargs.c | 123 ++++++++++++++++++++++- app/test/test_vdev.c | 10 +- drivers/bus/auxiliary/auxiliary_common.c | 17 +++- drivers/bus/cdx/cdx.c | 13 ++- drivers/bus/dpaa/dpaa_bus.c | 7 +- drivers/bus/fslmc/fslmc_bus.c | 9 +- drivers/bus/ifpga/ifpga_bus.c | 14 ++- drivers/bus/pci/pci_common.c | 22 ++-- drivers/bus/platform/platform.c | 15 ++- drivers/bus/uacce/uacce.c | 14 ++- drivers/bus/vdev/vdev.c | 23 ++++- drivers/bus/vmbus/vmbus_common.c | 9 +- drivers/dma/idxd/idxd_bus.c | 9 +- drivers/raw/ifpga/ifpga_rawdev.c | 8 +- lib/eal/common/eal_common_bus.c | 2 +- lib/eal/common/eal_common_dev.c | 41 +++++++- lib/eal/common/hotplug_mp.c | 11 +- lib/eal/include/bus_driver.h | 24 ++++- lib/eal/include/rte_dev.h | 15 +++ lib/eal/linux/eal_dev.c | 10 +- lib/eal/version.map | 1 + 21 files changed, 305 insertions(+), 92 deletions(-) diff --git a/app/test/test_devargs.c b/app/test/test_devargs.c index 4166b2bea2..1c21e7f6fe 100644 --- a/app/test/test_devargs.c +++ b/app/test/test_devargs.c @@ -12,7 +12,9 @@ #include #include #include +#include +#include "virtual_pmd.h" #include "test.h" /* Check layer arguments. */ @@ -171,7 +173,7 @@ test_valid_devargs(void) int ret; ret = test_valid_devargs_cases(list, RTE_DIM(list)); - if (vdev_bus != NULL && vdev_bus->parse("net_ring0", NULL) == 0) + if (vdev_bus != NULL && vdev_bus->parse("net_ring0", NULL, NULL) == 0) /* Ring vdev driver enabled. */ ret |= test_valid_devargs_cases(legacy_ring_list, RTE_DIM(legacy_ring_list)); @@ -302,6 +304,119 @@ test_invalid_devargs_parsing(void) return fail; } +static struct rte_device * +create_pci_dev(const char *name) +{ + int port_id; + uint8_t slave_mac1[] = {0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00 }; + struct rte_ether_addr *mac_addr = (struct rte_ether_addr *)slave_mac1; + char pmd_name[RTE_ETH_NAME_MAX_LEN]; + + mac_addr->addr_bytes[RTE_ETHER_ADDR_LEN - 1] = 0; + strlcpy(pmd_name, name, RTE_ETH_NAME_MAX_LEN); + + port_id = virtual_ethdev_create(pmd_name, + mac_addr, rte_socket_id(), 1); + + if (port_id < 0) + return NULL; + + return (&rte_eth_devices[port_id])->device; +} + +static int +test_pci(struct rte_bus *pci_bus, const char *dev_name, const char *name2) +{ + struct rte_device *pci_dev = create_pci_dev(dev_name); + + if (pci_dev == NULL) + return -1; + + pci_dev->bus = pci_bus; + + if (rte_cmp_dev_name(pci_dev, name2) != 0) { + printf("rte_cmp_dev_name(%s, %s) device name (%s) not expected (%s)\n", + pci_dev->name, name2, pci_dev->name, name2); + return -1; + } + return 0; +} + +static int +test_vdev(struct rte_bus *vdev_bus, const char *dev_name, const char *name2) +{ + /* create vdev */ + if (rte_vdev_init(dev_name, "") < 0) { + printf("Failed to create vdev %s\n", dev_name); + return -1; + } + + struct rte_device *vdev_dev = vdev_bus->find_device(NULL, rte_cmp_dev_name, dev_name); + if (vdev_dev == NULL) { + printf("Cannot find %s vdev\n", dev_name); + rte_vdev_uninit(dev_name); + return -1; + } + int ret = rte_cmp_dev_name(vdev_dev, name2); + if (ret != 0) { + printf("rte_cmp_dev_name(%s, %s) device name (%s) not expected (%s)\n", + vdev_dev->name, name2, vdev_dev->name, name2); + return -1; + } + + if (vdev_dev != vdev_bus->find_device(NULL, rte_cmp_dev_name, name2)) { + printf("rte_cmp_dev_name(%s, %s) device name (%s) not expected (%s)\n", + vdev_dev->name, name2, vdev_dev->name, name2); + return -1; + } + + rte_vdev_uninit(dev_name); + return 0; +} + +static int +test_valid_cmp_dev_name(void) +{ + struct rte_bus *pci_bus = rte_bus_find_by_name("pci"); + struct rte_bus *vdev_bus = rte_bus_find_by_name("vdev"); + + if (pci_bus) { + if ((test_pci(pci_bus, "0000:08:11.0", "08:11.0") != 0) || + (test_pci(pci_bus, "08:12.0", "0000:08:12.0") != 0) || + (test_pci(pci_bus, "08:13.0", "08:13.0") != 0) || + (test_pci(pci_bus, "0000:08:14.0", "0000:08:14.0") != 0)) + return -1; + } + + if (vdev_bus) { + if (test_vdev(vdev_bus, "net_null_test0", "net_null_test0") != 0) + return -1; + } + return 0; +} + +static int +test_invalid_cmp_dev_name(void) +{ + struct rte_bus *pci_bus = rte_bus_find_by_name("pci"); + struct rte_bus *vdev_bus = rte_bus_find_by_name("vdev"); + + if (pci_bus) { + if ((test_pci(pci_bus, "0000:08:15.0", "08:00.0") == 0) || + (test_pci(pci_bus, "08:16.0", "0000:08:15.0") == 0) || + (test_pci(pci_bus, "08:17.0", "08:13.0") == 0) || + (test_pci(pci_bus, "0000:08:18.0", "0000:08:14.0") == 0)) + return -1; + } + + if (vdev_bus) { + if ((test_vdev(vdev_bus, "net_null_test0", "net_null_test") == 0) || + (test_vdev(vdev_bus, "net_null_test1", "net_null_test2") == 0)) + return -1; + } + return 0; +} + static int test_devargs(void) { @@ -317,6 +432,12 @@ test_devargs(void) printf("== test devargs parsing invalid case ==\n"); if (test_invalid_devargs_parsing() < 0) return -1; + printf("== test find device valid case ==\n"); + if (test_valid_cmp_dev_name() < 0) + return -1; + printf("== test find device invalid case ==\n"); + if (test_invalid_cmp_dev_name() < 0) + return -1; return 0; } diff --git a/app/test/test_vdev.c b/app/test/test_vdev.c index 3e262f30bc..860fa260af 100644 --- a/app/test/test_vdev.c +++ b/app/test/test_vdev.c @@ -20,12 +20,6 @@ static const char * const valid_keys[] = { NULL, }; -static int -cmp_dev_name(const struct rte_device *dev, const void *name) -{ - return strcmp(rte_dev_name(dev), name); -} - static int cmp_dev_match(const struct rte_device *dev, const void *_kvlist) { @@ -82,7 +76,7 @@ test_vdev_bus(void) printf("Failed to create vdev net_null_test0\n"); goto fail; } - dev0 = vdev_bus->find_device(NULL, cmp_dev_name, "net_null_test0"); + dev0 = vdev_bus->find_device(NULL, rte_cmp_dev_name, "net_null_test0"); if (dev0 == NULL) { printf("Cannot find net_null_test0 vdev\n"); goto fail; @@ -93,7 +87,7 @@ test_vdev_bus(void) printf("Failed to create vdev net_null_test1\n"); goto fail; } - dev1 = vdev_bus->find_device(NULL, cmp_dev_name, "net_null_test1"); + dev1 = vdev_bus->find_device(NULL, rte_cmp_dev_name, "net_null_test1"); if (dev1 == NULL) { printf("Cannot find net_null_test1 vdev\n"); goto fail; diff --git a/drivers/bus/auxiliary/auxiliary_common.c b/drivers/bus/auxiliary/auxiliary_common.c index e6cbc4d356..ba2f69e851 100644 --- a/drivers/bus/auxiliary/auxiliary_common.c +++ b/drivers/bus/auxiliary/auxiliary_common.c @@ -237,10 +237,9 @@ auxiliary_probe(void) } static int -auxiliary_parse(const char *name, void *addr) +auxiliary_parse(const char *name, void *addr, int *size) { struct rte_auxiliary_driver *drv = NULL; - const char **out = addr; /* Allow empty device name "auxiliary:" to bypass entire bus scan. */ if (strlen(name) == 0) @@ -250,9 +249,17 @@ auxiliary_parse(const char *name, void *addr) if (drv->match(name)) break; } - if (drv != NULL && addr != NULL) - *out = name; - return drv != NULL ? 0 : -1; + + if (drv == NULL) + return -1; + + if (size != NULL) + *size = strlen(name) + 1; + + if (addr != NULL) + rte_strscpy(addr, name, strlen(name) + 1); + + return 0; } /* Register a driver */ diff --git a/drivers/bus/cdx/cdx.c b/drivers/bus/cdx/cdx.c index 62b108e082..b97f1ce1af 100644 --- a/drivers/bus/cdx/cdx.c +++ b/drivers/bus/cdx/cdx.c @@ -464,15 +464,20 @@ cdx_probe(void) } static int -cdx_parse(const char *name, void *addr) +cdx_parse(const char *name, void *addr, int *size) { - const char **out = addr; int ret; ret = strncmp(name, CDX_DEV_PREFIX, strlen(CDX_DEV_PREFIX)); - if (ret == 0 && addr) - *out = name; + if (ret != 0) + return ret; + + if (size != NULL) + *size = strlen(name) + 1; + + if (addr != NULL) + rte_strscpy(addr, name, strlen(name) + 1); return ret; } diff --git a/drivers/bus/dpaa/dpaa_bus.c b/drivers/bus/dpaa/dpaa_bus.c index 9ffbe07c93..f768fb9454 100644 --- a/drivers/bus/dpaa/dpaa_bus.c +++ b/drivers/bus/dpaa/dpaa_bus.c @@ -153,7 +153,7 @@ dpaa_devargs_lookup(struct rte_dpaa_device *dev) char dev_name[32]; RTE_EAL_DEVARGS_FOREACH("dpaa_bus", devargs) { - devargs->bus->parse(devargs->name, &dev_name); + devargs->bus->parse(devargs->name, &dev_name, NULL); if (strcmp(dev_name, dev->device.name) == 0) { DPAA_BUS_INFO("**Devargs matched %s", dev_name); return devargs; @@ -447,7 +447,7 @@ dpaa_portal_finish(void *arg) } static int -rte_dpaa_bus_parse(const char *name, void *out) +rte_dpaa_bus_parse(const char *name, void *out, int *size) { unsigned int i, j; size_t delta, dev_delta; @@ -494,6 +494,9 @@ rte_dpaa_bus_parse(const char *name, void *out) max_name_len = sizeof("fm.-mac..") - 1; } + if (size != NULL) + *size = max_name_len + 1; + if (out != NULL) { char *out_name = out; diff --git a/drivers/bus/fslmc/fslmc_bus.c b/drivers/bus/fslmc/fslmc_bus.c index 68ad2b801e..a525b5e245 100644 --- a/drivers/bus/fslmc/fslmc_bus.c +++ b/drivers/bus/fslmc/fslmc_bus.c @@ -103,7 +103,7 @@ fslmc_devargs_lookup(struct rte_dpaa2_device *dev) char dev_name[32]; RTE_EAL_DEVARGS_FOREACH("fslmc", devargs) { - devargs->bus->parse(devargs->name, &dev_name); + devargs->bus->parse(devargs->name, &dev_name, NULL); if (strcmp(dev_name, dev->device.name) == 0) { DPAA2_BUS_INFO("**Devargs matched %s", dev_name); return devargs; @@ -235,7 +235,7 @@ scan_one_fslmc_device(char *dev_name) } static int -rte_fslmc_parse(const char *name, void *addr) +rte_fslmc_parse(const char *name, void *addr, int *size) { uint16_t dev_id; char *t_ptr; @@ -298,7 +298,10 @@ rte_fslmc_parse(const char *name, void *addr) goto err_out; } - if (addr) + if (size != NULL) + *size = strlen(sep) + 1; + + if (addr != NULL) strcpy(addr, sep); ret = 0; diff --git a/drivers/bus/ifpga/ifpga_bus.c b/drivers/bus/ifpga/ifpga_bus.c index 11b31eee4f..d5d9a86a97 100644 --- a/drivers/bus/ifpga/ifpga_bus.c +++ b/drivers/bus/ifpga/ifpga_bus.c @@ -459,9 +459,8 @@ ifpga_find_device(const struct rte_device *start, return NULL; } static int -ifpga_parse(const char *name, void *addr) +ifpga_parse(const char *name, void *addr, int *size) { - int *out = addr; struct rte_rawdev *rawdev = NULL; char rawdev_name[RTE_RAWDEV_NAME_MAX_LEN]; char *c1 = NULL; @@ -491,9 +490,14 @@ ifpga_parse(const char *name, void *addr) rawdev = rte_rawdev_pmd_get_named_dev(rawdev_name); if ((port < IFPGA_BUS_DEV_PORT_MAX) && - rawdev && - (addr != NULL)) - *out = port; + rawdev) { + if (size != NULL) + *size = sizeof(port); + + if (addr != NULL) + *(int *)addr = port; + } + if ((port < IFPGA_BUS_DEV_PORT_MAX) && rawdev) diff --git a/drivers/bus/pci/pci_common.c b/drivers/bus/pci/pci_common.c index 1173f0887c..25e161f321 100644 --- a/drivers/bus/pci/pci_common.c +++ b/drivers/bus/pci/pci_common.c @@ -84,7 +84,7 @@ pci_devargs_lookup(const struct rte_pci_addr *pci_addr) struct rte_pci_addr addr; RTE_EAL_DEVARGS_FOREACH("pci", devargs) { - devargs->bus->parse(devargs->name, &addr); + devargs->bus->parse(devargs->name, &addr, NULL); if (!rte_pci_addr_cmp(pci_addr, &addr)) return devargs; } @@ -99,21 +99,11 @@ pci_common_set(struct rte_pci_device *dev) /* Each device has its internal, canonical name set. */ rte_pci_device_name(&dev->addr, dev->name, sizeof(dev->name)); + dev->device.name = dev->name; + devargs = pci_devargs_lookup(&dev->addr); dev->device.devargs = devargs; - /* When using a blocklist, only blocked devices will have - * an rte_devargs. Allowed devices won't have one. - */ - if (devargs != NULL) - /* If an rte_devargs exists, the generic rte_device uses the - * given name as its name. - */ - dev->device.name = dev->device.devargs->name; - else - /* Otherwise, it uses the internal, canonical form. */ - dev->device.name = dev->name; - if (dev->bus_info != NULL || asprintf(&dev->bus_info, "vendor_id=%"PRIx16", device_id=%"PRIx16, dev->id.vendor_id, dev->id.device_id) != -1) @@ -497,15 +487,19 @@ rte_pci_dump(FILE *f) } static int -pci_parse(const char *name, void *addr) +pci_parse(const char *name, void *addr, int *size) { struct rte_pci_addr *out = addr; struct rte_pci_addr pci_addr; bool parse; + if (size != NULL) + *size = sizeof(struct rte_pci_addr); + parse = (rte_pci_addr_parse(name, &pci_addr) == 0); if (parse && addr != NULL) *out = pci_addr; + return parse == false; } diff --git a/drivers/bus/platform/platform.c b/drivers/bus/platform/platform.c index 11892caa24..87ed7404e1 100644 --- a/drivers/bus/platform/platform.c +++ b/drivers/bus/platform/platform.c @@ -542,11 +542,10 @@ platform_bus_unplug(struct rte_device *dev) } static int -platform_bus_parse(const char *name, void *addr) +platform_bus_parse(const char *name, void *addr, int *size) { struct rte_platform_device pdev = { }; struct rte_platform_driver *pdrv; - const char **out = addr; rte_strscpy(pdev.name, name, sizeof(pdev.name)); @@ -555,10 +554,16 @@ platform_bus_parse(const char *name, void *addr) break; } - if (pdrv != NULL && addr != NULL) - *out = name; + if (pdrv == NULL) + return -ENODEV; + + if (size != NULL) + *size = strlen(name) + 1; - return pdrv != NULL ? 0 : -ENODEV; + if (addr != NULL) + rte_strscpy(addr, name, strlen(name) + 1); + + return 0; } static int diff --git a/drivers/bus/uacce/uacce.c b/drivers/bus/uacce/uacce.c index 9ca048122d..b18fbe1103 100644 --- a/drivers/bus/uacce/uacce.c +++ b/drivers/bus/uacce/uacce.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include "bus_uacce_driver.h" @@ -529,15 +530,20 @@ uacce_find_device(const struct rte_device *start, rte_dev_cmp_t cmp, const void } static int -uacce_parse(const char *name, void *addr) +uacce_parse(const char *name, void *addr, int *size) { - const char **out = addr; int ret; ret = strncmp(name, UACCE_DEV_PREFIX, strlen(UACCE_DEV_PREFIX)); - if (ret == 0 && addr) - *out = name; + if (ret != 0) + return ret; + + if (size != NULL) + *size = strlen(name) + 1; + + if (addr != NULL) + rte_strscpy(addr, name, strlen(name) + 1); return ret; } diff --git a/drivers/bus/vdev/vdev.c b/drivers/bus/vdev/vdev.c index ec7abe7cda..cc87461f27 100644 --- a/drivers/bus/vdev/vdev.c +++ b/drivers/bus/vdev/vdev.c @@ -113,7 +113,7 @@ rte_vdev_remove_custom_scan(rte_vdev_scan_callback callback, void *user_arg) } static int -vdev_parse(const char *name, void *addr) +vdev_find_driver(const char *name, void *addr) { struct rte_vdev_driver **out = addr; struct rte_vdev_driver *driver = NULL; @@ -197,7 +197,7 @@ vdev_probe_all_drivers(struct rte_vdev_device *dev) name = rte_vdev_device_name(dev); VDEV_LOG(DEBUG, "Search driver to probe device %s", name); - if (vdev_parse(name, &driver)) + if (vdev_find_driver(name, &driver)) return -1; iova_mode = rte_eal_iova_mode(); @@ -232,6 +232,23 @@ find_vdev(const char *name) return NULL; } +static int +vdev_parse(const char *name, void *addr, int *size) +{ + struct rte_vdev_device *dev = find_vdev(name); + + if (dev == NULL) + return 1; + + if (size != NULL) + *size = strlen(name) + 1; + + if (addr != NULL) + rte_strscpy(addr, name, strlen(name) + 1); + + return 0; +} + static struct rte_devargs * alloc_devargs(const char *name, const char *args) { @@ -647,7 +664,7 @@ vdev_get_iommu_class(void) TAILQ_FOREACH(dev, &vdev_device_list, next) { name = rte_vdev_device_name(dev); - if (vdev_parse(name, &driver)) + if (vdev_find_driver(name, &driver)) continue; if (driver->drv_flags & RTE_VDEV_DRV_NEED_IOVA_AS_VA) diff --git a/drivers/bus/vmbus/vmbus_common.c b/drivers/bus/vmbus/vmbus_common.c index 8a965d10d9..18805aee0d 100644 --- a/drivers/bus/vmbus/vmbus_common.c +++ b/drivers/bus/vmbus/vmbus_common.c @@ -245,13 +245,16 @@ rte_vmbus_cleanup(void) } static int -vmbus_parse(const char *name, void *addr) +vmbus_parse(const char *name, void *addr, int *size) { rte_uuid_t guid; int ret; + if (size != NULL) + *size = sizeof(guid); + ret = rte_uuid_parse(name, guid); - if (ret == 0 && addr) + if (ret == 0 && addr != NULL) memcpy(addr, &guid, sizeof(guid)); return ret; @@ -269,7 +272,7 @@ vmbus_devargs_lookup(struct rte_vmbus_device *dev) rte_uuid_t addr; RTE_EAL_DEVARGS_FOREACH("vmbus", devargs) { - vmbus_parse(devargs->name, &addr); + vmbus_parse(devargs->name, &addr, NULL); if (rte_uuid_compare(dev->device_id, addr) == 0) return devargs; diff --git a/drivers/dma/idxd/idxd_bus.c b/drivers/dma/idxd/idxd_bus.c index ba8076715d..d68e8b630e 100644 --- a/drivers/dma/idxd/idxd_bus.c +++ b/drivers/dma/idxd/idxd_bus.c @@ -47,7 +47,7 @@ static int dsa_probe(void); static struct rte_device *dsa_find_device(const struct rte_device *start, rte_dev_cmp_t cmp, const void *data); static enum rte_iova_mode dsa_get_iommu_class(void); -static int dsa_addr_parse(const char *name, void *addr); +static int dsa_addr_parse(const char *name, void *addr, int *size); /** List of devices */ TAILQ_HEAD(dsa_device_list, rte_dsa_device); @@ -345,7 +345,7 @@ dsa_scan(void) closedir(dev_dir); return -ENOMEM; } - if (dsa_addr_parse(wq->d_name, &dev->addr) < 0) { + if (dsa_addr_parse(wq->d_name, &dev->addr, NULL) < 0) { IDXD_PMD_ERR("Error parsing WQ name: %s", wq->d_name); free(dev); continue; @@ -391,11 +391,14 @@ dsa_get_iommu_class(void) } static int -dsa_addr_parse(const char *name, void *addr) +dsa_addr_parse(const char *name, void *addr, int *size) { struct dsa_wq_addr *wq = addr; unsigned int device_id, wq_id; + if (size != NULL) + *size = sizeof(struct dsa_wq_addr); + if (sscanf(name, "wq%u.%u", &device_id, &wq_id) != 2) { IDXD_PMD_DEBUG("Parsing WQ name failed: %s", name); return -1; diff --git a/drivers/raw/ifpga/ifpga_rawdev.c b/drivers/raw/ifpga/ifpga_rawdev.c index 5b9b596435..7238246e1c 100644 --- a/drivers/raw/ifpga/ifpga_rawdev.c +++ b/drivers/raw/ifpga/ifpga_rawdev.c @@ -1833,12 +1833,6 @@ ifpga_cfg_probe(struct rte_vdev_device *vdev) return ret; } -static int cmp_dev_name(const struct rte_device *dev, const void *_name) -{ - const char *name = _name; - return strcmp(dev->name, name); -} - static int ifpga_cfg_remove(struct rte_vdev_device *vdev) { @@ -1874,7 +1868,7 @@ ifpga_cfg_remove(struct rte_vdev_device *vdev) args.port, args.bdf); bus = rte_bus_find_by_name(RTE_STR(IFPGA_BUS_NAME)); if (bus) { - if (bus->find_device(NULL, cmp_dev_name, dev_name)) { + if (bus->find_device(NULL, rte_cmp_dev_name, dev_name)) { ret = rte_eal_hotplug_remove(RTE_STR(IFPGA_BUS_NAME), dev_name); } diff --git a/lib/eal/common/eal_common_bus.c b/lib/eal/common/eal_common_bus.c index 7cbd09c421..b1bb5df5b7 100644 --- a/lib/eal/common/eal_common_bus.c +++ b/lib/eal/common/eal_common_bus.c @@ -200,7 +200,7 @@ bus_can_parse(const struct rte_bus *bus, const void *_name) { const char *name = _name; - return !(bus->parse && bus->parse(name, NULL) == 0); + return !(bus->parse && bus->parse(name, NULL, NULL) == 0); } struct rte_bus * diff --git a/lib/eal/common/eal_common_dev.c b/lib/eal/common/eal_common_dev.c index 70aa04dcd9..c0e2202482 100644 --- a/lib/eal/common/eal_common_dev.c +++ b/lib/eal/common/eal_common_dev.c @@ -107,11 +107,42 @@ struct dev_next_ctx { #define CLSCTX(ptr) \ (((struct dev_next_ctx *)(intptr_t)ptr)->cls_str) -static int cmp_dev_name(const struct rte_device *dev, const void *_name) +int +rte_cmp_dev_name(const struct rte_device *dev1, const void *name2) { - const char *name = _name; + void *parsed_name1; + void *parsed_name2; + int size1 = 0; + int size2 = 0; + int ret; + + if (dev1->bus->parse(dev1->name, NULL, &size1) != 0 || + dev1->bus->parse(name2, NULL, &size2) != 0) + return 1; + + if (size1 != size2) + return 1; + + parsed_name1 = malloc(size1); + if (parsed_name1 == NULL) + return 1; + + parsed_name2 = malloc(size2); + if (parsed_name2 == NULL) { + free(parsed_name1); + return 1; + } - return strcmp(dev->name, name); + memset(parsed_name1, 0, size1); + memset(parsed_name2, 0, size2); + + dev1->bus->parse(dev1->name, parsed_name1, NULL); + dev1->bus->parse(name2, parsed_name2, NULL); + + ret = memcmp(parsed_name1, parsed_name2, size1); + free(parsed_name1); + free(parsed_name2); + return ret; } int @@ -197,7 +228,7 @@ local_dev_probe(const char *devargs, struct rte_device **new_dev) if (ret) goto err_devarg; - dev = da->bus->find_device(NULL, cmp_dev_name, da->name); + dev = da->bus->find_device(NULL, rte_cmp_dev_name, da->name); if (dev == NULL) { EAL_LOG(ERR, "Cannot find device (%s)", da->name); @@ -335,7 +366,7 @@ rte_eal_hotplug_remove(const char *busname, const char *devname) return -ENOENT; } - dev = bus->find_device(NULL, cmp_dev_name, devname); + dev = bus->find_device(NULL, rte_cmp_dev_name, devname); if (dev == NULL) { EAL_LOG(ERR, "Cannot find plugged device (%s)", devname); return -EINVAL; diff --git a/lib/eal/common/hotplug_mp.c b/lib/eal/common/hotplug_mp.c index 17089ca3db..a2623c96c3 100644 --- a/lib/eal/common/hotplug_mp.c +++ b/lib/eal/common/hotplug_mp.c @@ -21,13 +21,6 @@ struct mp_reply_bundle { void *peer; }; -static int cmp_dev_name(const struct rte_device *dev, const void *_name) -{ - const char *name = _name; - - return strcmp(dev->name, name); -} - /** * Secondary to primary request. * start from function eal_dev_hotplug_request_to_primary. @@ -135,7 +128,7 @@ __handle_secondary_request(void *param) goto finish; } - dev = bus->find_device(NULL, cmp_dev_name, da.name); + dev = bus->find_device(NULL, rte_cmp_dev_name, da.name); if (dev == NULL) { EAL_LOG(ERR, "Cannot find plugged device (%s)", da.name); ret = -ENOENT; @@ -262,7 +255,7 @@ static void __handle_primary_request(void *param) goto quit; } - dev = bus->find_device(NULL, cmp_dev_name, da->name); + dev = bus->find_device(NULL, rte_cmp_dev_name, da->name); if (dev == NULL) { EAL_LOG(ERR, "Cannot find plugged device (%s)", da->name); ret = -ENOENT; diff --git a/lib/eal/include/bus_driver.h b/lib/eal/include/bus_driver.h index 60527b75b6..01447670de 100644 --- a/lib/eal/include/bus_driver.h +++ b/lib/eal/include/bus_driver.h @@ -112,11 +112,32 @@ typedef int (*rte_bus_unplug_t)(struct rte_device *dev); * should be written. If NULL, nothing should be written, which * is not an error. * + * @param[out] size + * device information size. If NULL, nothing should + * be written, which is not an error. + * * @return * 0 if parsing was successful. * !0 for any error. */ -typedef int (*rte_bus_parse_t)(const char *name, void *addr); +typedef int (*rte_bus_parse_t)(const char *name, void *addr, int *size); + +/** + * Bus specific device name comparison function. + * + * This type of function is used to compare a bus name with an arbitrary + * name. + * + * @param dev + * Device handle. + * + * @param name + * Name to compare against. + * + * @return + * 0 if the device matches the name. Nonzero otherwise. + */ +typedef int (*rte_bus_cmp_name_t)(const struct rte_device *dev, const void *name); /** * Parse bus part of the device arguments. @@ -258,6 +279,7 @@ struct rte_bus { rte_bus_plug_t plug; /**< Probe single device for drivers */ rte_bus_unplug_t unplug; /**< Remove single device from driver */ rte_bus_parse_t parse; /**< Parse a device name */ + rte_bus_cmp_name_t cmp_name; /**< Compare device name */ rte_bus_devargs_parse_t devargs_parse; /**< Parse bus devargs */ rte_dev_dma_map_t dma_map; /**< DMA map for device in the bus */ rte_dev_dma_unmap_t dma_unmap; /**< DMA unmap for device in the bus */ diff --git a/lib/eal/include/rte_dev.h b/lib/eal/include/rte_dev.h index 738400e8d1..2df8143af1 100644 --- a/lib/eal/include/rte_dev.h +++ b/lib/eal/include/rte_dev.h @@ -17,6 +17,7 @@ #include #include +#include #include #ifdef __cplusplus @@ -170,6 +171,20 @@ int rte_dev_is_probed(const struct rte_device *dev); int rte_eal_hotplug_add(const char *busname, const char *devname, const char *drvargs); +/** + * General device name comparison. Will compare by using the specific bus + * compare function or by comparing the names directly. + * + * @param dev + * Device handle. + * @param name + * Name to compare against. + * @return + * 0 if the device matches the name. Nonzero otherwise. + */ +__rte_internal +int rte_cmp_dev_name(const struct rte_device *dev, const void *name); + /** * Add matching devices. * diff --git a/lib/eal/linux/eal_dev.c b/lib/eal/linux/eal_dev.c index e63f24d108..3b68cda87f 100644 --- a/lib/eal/linux/eal_dev.c +++ b/lib/eal/linux/eal_dev.c @@ -91,14 +91,6 @@ static void sigbus_handler(int signum, siginfo_t *info, EAL_LOG(DEBUG, "Success to handle SIGBUS for hot-unplug!"); } -static int cmp_dev_name(const struct rte_device *dev, - const void *_name) -{ - const char *name = _name; - - return strcmp(dev->name, name); -} - static int dev_uev_socket_fd_create(void) { @@ -280,7 +272,7 @@ dev_uev_handler(__rte_unused void *param) goto failure_handle_err; } - dev = bus->find_device(NULL, cmp_dev_name, + dev = bus->find_device(NULL, rte_cmp_dev_name, uevent.devname); if (dev == NULL) { EAL_LOG(ERR, "Cannot find device (%s) on " diff --git a/lib/eal/version.map b/lib/eal/version.map index a20c713eb1..e50a95fd31 100644 --- a/lib/eal/version.map +++ b/lib/eal/version.map @@ -448,4 +448,5 @@ INTERNAL { rte_mem_unmap; rte_thread_create_internal_control; rte_thread_set_prefixed_name; + rte_cmp_dev_name; }; -- 2.34.1