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 F09C94553F; Mon, 1 Jul 2024 22:01:59 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C56B3402CD; Mon, 1 Jul 2024 22:01:59 +0200 (CEST) Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2049.outbound.protection.outlook.com [40.107.92.49]) by mails.dpdk.org (Postfix) with ESMTP id 1A700402A3 for ; Mon, 1 Jul 2024 22:01:58 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=K0YduHSJV8FStSH7+OLZPGK96Vu/uaK8wPmCRH2GgIHcMc1nqIYmzseNQ0ln92eJ/L+bfDP1C2oAHBYxSBo/ybTVgAExEBfb1I4Y12Hag0x5F0SiISq1AQ5DvZx9mqB50Mag/bHABvWPpPsekOYh/BYGLiraGosTz+bxaiK835cYB2EwzMrUPHiGlqcVZxKSwR9+1vOIJfn6B6ST/6KIEaa2SlCNsG+CSg1bWhBz2+7Ik0zFE/O2YuyXJq2Hr0iyFZhBZDO9Id3SdfqLR2tFFvH0vswGUK6htuf4+Ni+SikPp669fv5Hu9dh3xUAef6m2xOa/hs/6sVAqPjJKZtuNA== 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=nCCwQMJkJhjH+lClYOSFl1M9d+QI0hS6PhN992WcEm0=; b=k2Y2zO47L7TlcSA33KvWK6vRkOHLBcfDzG+jwPu4cRQ9Axyq87pAYKOCgUph3F8Pc4JQELX04i3zEqhAUHypf3b1d+IMX2KocYZ/0CdxqcxUZjh1/arQprX/+W13mVYEc6HhwnrISSFyPk7TnEwDkYSDGnyTE0N+ly41sAeN30u7wEpqvK3UD7vhCsmiCrWXwX9IzoItDCtyQ1RP+JJH6sNOK0rsOfd0Tw/UTZCzVxF5p+fMB0IpYM+FUxwwadbZaZi+MFXPPLlwvKdkjLFiI/zBJzhuzVVbpKacpMSvUglgwjcx8tJzYurUVnzQmFvxcZHjtsO2oVOwqIH9EvQC9w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) 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=nCCwQMJkJhjH+lClYOSFl1M9d+QI0hS6PhN992WcEm0=; b=tR8CmSaqERVtLd+LL6mmgOrPOeqo1DkxHe4a4mxRXgPoV92HrbHXK8n9hTSLbjHXsMKBZpVqLX/Jzr8FUvmFiV3sHDc4Hef6F0LCXc5UA4oRDQkx4UQzO42d4OodXrLpN4n2Rw14yLLsFo3PFUmOte8QtkPCUts1kojB4xyYj4q2Aq3esKuyLW1gi4jVG6+kCsAK1OqX2aNd9ROTrsQOMp6mJkmOjH97fzmcX24l/lYpgYoBtY5PGF23EsaZovSCw0xngPNd/q2CZVNvCz9VNw0ceijiOlvucroM3LhfF14Nrb5ZAVJ3tZNVWSB4alOXWq3La2/6/l8g4rhaqsU++w== Received: from PH7P220CA0014.NAMP220.PROD.OUTLOOK.COM (2603:10b6:510:326::28) by IA1PR12MB6041.namprd12.prod.outlook.com (2603:10b6:208:3d7::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7719.33; Mon, 1 Jul 2024 20:01:53 +0000 Received: from SN1PEPF000397AE.namprd05.prod.outlook.com (2603:10b6:510:326:cafe::6b) by PH7P220CA0014.outlook.office365.com (2603:10b6:510:326::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7719.33 via Frontend Transport; Mon, 1 Jul 2024 20:01:53 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) 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.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by SN1PEPF000397AE.mail.protection.outlook.com (10.167.248.52) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7741.18 via Frontend Transport; Mon, 1 Jul 2024 20:01:51 +0000 Received: from rnnvmail205.nvidia.com (10.129.68.10) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Mon, 1 Jul 2024 13:01:25 -0700 Received: from rnnvmail201.nvidia.com (10.129.68.8) by rnnvmail205.nvidia.com (10.129.68.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Mon, 1 Jul 2024 13:01:25 -0700 Received: from nvidia.com (10.127.8.10) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4 via Frontend Transport; Mon, 1 Jul 2024 13:01:22 -0700 From: Shani Peretz To: CC: , , , Dariusz Sosnowski , Thomas Monjalon , Chenbo Xia , Nipun Gupta , Tyler Retzlaff Subject: [PATCH] eal/common: fix inconsistent representation of PCI numbers Date: Mon, 1 Jul 2024 23:01:17 +0300 Message-ID: <20240701200117.6349-1-shperetz@nvidia.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF000397AE:EE_|IA1PR12MB6041:EE_ X-MS-Office365-Filtering-Correlation-Id: feceb3bd-c5dc-42ce-10b6-08dc9a08a614 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|82310400026|376014|1800799024|36860700013; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?QoFZmxunkpiggj5BRNjVbwCdqVm+0LimrAqXRHi7pQrZhEQkH71SwkmP2F+w?= =?us-ascii?Q?MUU6i3MXrWqZucuICOJ5g0T3WUuUDfMfBMljwMr3b41VyREEnSM5WOZRSb5f?= =?us-ascii?Q?YH+TnVJ0nfSwZn+rPZCKKfR9rr+t/fkAoddIWVEh24WG24n3b7qciAwNhWLq?= =?us-ascii?Q?fLXB7EcB7rwYRzpHY0M7xZ0cwj+1h1mNsKBGHtjNqpVo7GsI7pjhis5rQ068?= =?us-ascii?Q?UNhCRvvH15c1gJ0lIwUue+a4i71cLjCuW+BhCEC+Fky56YCXYqfmWOjTDGbf?= =?us-ascii?Q?jJeq6DyRL10DhFd+bt3vMzuacHFNLf0V0F5ksoQ0bAGmPgqLIPLkrnF6N3Pu?= =?us-ascii?Q?7L0JyvivS7/GTVHwzq+dR7lzZN6A+amaKoHnYhjULFXAhT1XNOiQsMOVbopG?= =?us-ascii?Q?AztuLNQF35+aWY8FZOK14X1J/ZQNoQzoCEpjMcHqtoZNqQr0Vu5t+cBOFxib?= =?us-ascii?Q?oO9n2fvN4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X?= =?us-ascii?Q?qC6NDddxfz1JDDS0xjCxFDDskDXnKpcWUz9Fx7Ot7weqGkpCOPt3alaTOINl?= =?us-ascii?Q?HTFojSvQO1qFgp1aED/lVHrAfu4YaAvs?= X-Forefront-Antispam-Report: CIP:216.228.117.161; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc6edge2.nvidia.com; CAT:NONE; SFS:(13230040)(82310400026)(376014)(1800799024)(36860700013); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Jul 2024 20:01:51.5110 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: feceb3bd-c5dc-42ce-10b6-08dc9a08a614 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.117.161]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: SN1PEPF000397AE.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6041 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 allows for two ways to specify PCI device numbers: a full version ("0000:08:00.0") and a short version ("08:00.0"). The problem arises when the application uses one format (e.g., full) when running testpmd, but then tries to use the other format (e.g., short) in a subsequent command, leading to a failure. The cmp_dev_name func, which is responsible for comparing PCI device names, is not handling the inconsistent PCI number representations correctly. The suggested fix is to use the pci_parse function, which can parse the PCI device name and fill a struct rte_pci_addr with the standardized representation of the PCI number. By comparing the struct rte_pci_addr instances instead of the string representations, the application can ensure consistent handling of PCI device numbers, regardless of the format used. Fixes: a3ee360f4440 ("eal: add hotplug add/remove device") Cc: jblunck@infradead.org Signed-off-by: Shani Peretz Acked-by: Dariusz Sosnowski Acked-by: Thomas Monjalon --- app/test/test_vdev.c | 10 ++-------- drivers/bus/pci/pci_common.c | 10 ++++++++++ lib/eal/common/eal_common_dev.c | 11 ++++++----- lib/eal/common/hotplug_mp.c | 11 ++--------- lib/eal/include/bus_driver.h | 18 ++++++++++++++++++ lib/eal/include/rte_dev.h | 16 ++++++++++++++++ lib/eal/linux/eal_dev.c | 10 +--------- lib/eal/version.map | 3 +++ 8 files changed, 58 insertions(+), 31 deletions(-) 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/pci/pci_common.c b/drivers/bus/pci/pci_common.c index 889a48d2af..6b3bf070ae 100644 --- a/drivers/bus/pci/pci_common.c +++ b/drivers/bus/pci/pci_common.c @@ -501,6 +501,15 @@ rte_pci_dump(FILE *f) pci_dump_one_device(f, dev); } } +static int +pci_cmp_name(const struct rte_device *dev1, const void *name2) +{ + const struct rte_pci_device *dev = RTE_DEV_TO_PCI_CONST(dev1); + char name2_addr[sizeof(struct rte_pci_addr)] = {0}; + dev1->bus->parse(name2, (void *)&name2_addr); + + return memcmp(&name2_addr, &(dev->addr), sizeof(struct rte_pci_addr)); +} static int pci_parse(const char *name, void *addr) @@ -956,6 +965,7 @@ struct rte_pci_bus rte_pci_bus = { .plug = pci_plug, .unplug = pci_unplug, .parse = pci_parse, + .cmp_name = pci_cmp_name, .devargs_parse = rte_pci_devargs_parse, .dma_map = pci_dma_map, .dma_unmap = pci_dma_unmap, diff --git a/lib/eal/common/eal_common_dev.c b/lib/eal/common/eal_common_dev.c index a99252b02f..12d68c3605 100644 --- a/lib/eal/common/eal_common_dev.c +++ b/lib/eal/common/eal_common_dev.c @@ -107,11 +107,12 @@ 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; + if (dev1->bus->cmp_name) + return dev1->bus->cmp_name(dev1, name2); - return strcmp(dev->name, name); + return strcmp(dev1->name, (const char *)name2); } int @@ -197,7 +198,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 +336,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 7b85a17a09..eba820f36c 100644 --- a/lib/eal/include/bus_driver.h +++ b/lib/eal/include/bus_driver.h @@ -118,6 +118,23 @@ typedef int (*rte_bus_unplug_t)(struct rte_device *dev); */ typedef int (*rte_bus_parse_t)(const char *name, void *addr); +/** + * 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 +275,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 cefa04f905..a3d666c110 100644 --- a/lib/eal/include/rte_dev.h +++ b/lib/eal/include/rte_dev.h @@ -21,6 +21,7 @@ extern "C" { #include #include +#include #include struct rte_bus; @@ -170,6 +171,21 @@ 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_experimental +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 fff4e8fa83..5c8effd7be 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 3df50c3fbb..e4355ef890 100644 --- a/lib/eal/version.map +++ b/lib/eal/version.map @@ -396,6 +396,9 @@ EXPERIMENTAL { # added in 24.03 rte_vfio_get_device_info; # WINDOWS_NO_EXPORT + + # added in 24.07 + rte_cmp_dev_name; }; INTERNAL { -- 2.34.1