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 58DCA43EA9 for ; Fri, 19 Apr 2024 05:26:57 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 444F34067E; Fri, 19 Apr 2024 05:26:57 +0200 (CEST) Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2108.outbound.protection.outlook.com [40.107.236.108]) by mails.dpdk.org (Postfix) with ESMTP id 16BAB40273; Fri, 19 Apr 2024 05:26:52 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NhAG8zlR6op048oW+NevbhJ4kO/1606v6xzYD57Q1S4jlXJprae2QnDUZPEI96krRYMDZzZYhThzmYygZkuJnBw6YBg0nSm3w/ZDc4yDz3px0GltvD+gZRHj429s3wG8SoK3OX29joaU/EI0MlQ3Os4NookVQu6L8bYqHS02xDftshwS7NihkgqvlGfYa13csRpnnGn63C0wOVEEr5STpOZ9M/uhla9mlt7THWrzsOhjPp+gMqmWr75k3oPmsS5G1Qp7/LNjnhyRgthcd2FYRUhKcz0luL1XYw4dx6YeF2E7B0eqZQIeup+ryi83UVdw6rgM3obrHNPkxD2LnTTUqQ== 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=xLhataWRZeS2l3E9kPIQQk5JFrqIwPjJx2R0fzhpRnw=; b=X8e6fmcT5/iNBjVCCZKExB2SpWYg0ipyylt/qrv350gylmOR0U2w4GNBecz00hRfTS4Mej+71YJGnUT8nPiU7PlXgBVfU29wLHEkZ1eEnG+MPY/diXzukLceYXyavIzr8PH7iOF4ymLSMlHa/Uiz1ns1zfB9ppH4WrwFU7TlJRXx35cIDWAaTxEJSgpDqUvWZQ7ppEwIX8zJ2AcmVw3Q7gdgHdKySRVKBvmBGmO8sh0WuYeUeei2Dzr5QvUoCK2dBSzQeXQ4qAAi6K39n16MzCtWevHtKD2McS/sR7GVBVxCjW3XqrMSgKoJdS90AIbTS2DEocvqBdzHOQkiYQC3cA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=corigine.com; dmarc=pass action=none header.from=corigine.com; dkim=pass header.d=corigine.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=corigine.onmicrosoft.com; s=selector2-corigine-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=xLhataWRZeS2l3E9kPIQQk5JFrqIwPjJx2R0fzhpRnw=; b=W+pFi9mcHvgC5zy/99RRMd2pKf+0O4fdVPo+EVaj+IcVKHczyga+uCtdieZ/mvOX17wCramtmOoekAbb2zTK2iEK7Fzc3CRVC7Ivwsrdfx6shLpZJLgYEP/EFpAzwSQf+AqoAKmI3VD6vheI5oKNRjH9n7z0JdcZx+4U5z8KGwA= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=corigine.com; Received: from SJ0PR13MB5545.namprd13.prod.outlook.com (2603:10b6:a03:424::5) by PH7PR13MB6170.namprd13.prod.outlook.com (2603:10b6:510:241::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.41; Fri, 19 Apr 2024 03:26:50 +0000 Received: from SJ0PR13MB5545.namprd13.prod.outlook.com ([fe80::ec12:7411:559a:850e]) by SJ0PR13MB5545.namprd13.prod.outlook.com ([fe80::ec12:7411:559a:850e%5]) with mapi id 15.20.7472.042; Fri, 19 Apr 2024 03:26:50 +0000 From: Chaoyong He To: dev@dpdk.org Cc: oss-drivers@corigine.com, Zerun Fu , mukawa@igel.co.jp, stable@dpdk.org, Chaoyong He , Long Wu , Peng Zhang Subject: [PATCH v3 1/2] bus/pci: fix secondary process PCI uio resource map problem Date: Fri, 19 Apr 2024 11:26:29 +0800 Message-Id: <20240419032630.1215256-2-chaoyong.he@corigine.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20240419032630.1215256-1-chaoyong.he@corigine.com> References: <20240129092231.3531217-1-chaoyong.he@corigine.com> <20240419032630.1215256-1-chaoyong.he@corigine.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: SI2PR01CA0008.apcprd01.prod.exchangelabs.com (2603:1096:4:191::10) To SJ0PR13MB5545.namprd13.prod.outlook.com (2603:10b6:a03:424::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR13MB5545:EE_|PH7PR13MB6170:EE_ X-MS-Office365-Filtering-Correlation-Id: 918d5302-030d-4a17-fd93-08dc60208d42 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?AVd96sVMNnHSCq0LJ8M0LwQge9fmLqyyCTgZHSV0XYn6frath2dcqsLZWvuf?= =?us-ascii?Q?twisEbCVM90IMNfAG7WKwYSFxZ1Ty8+lwZI/J2fbbNo7hYdUuFe1YgrATqM7?= =?us-ascii?Q?qP/o1dPJjxTKxYxXZAmOzEZcjWiSW0Q1tEHJ22A3iRbx7mqYkI7tqgYPcNgh?= =?us-ascii?Q?snQiqQwJm6TXbxQyZv0Ilfw3VdRzNrQMAO57gUOoCt6TetY9MnT4vHrdJSKm?= =?us-ascii?Q?7OLhwRkhw2X7Z4+1aLzgRgexm/852iDLR66NlPFkM+PcDQ0ilKPSFDOu07J3?= =?us-ascii?Q?+QmKipEuy+LjFidV3naY+EC0iFLE/Ig/exy2AZATTJaYOR2lus8kfVeby/LO?= =?us-ascii?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GbUpN1QRBgg?= =?us-ascii?Q?rCKxrImXAJel9bVV3wQpnnkpDFCt6bemQaeGBduYkBgwOxMFHOWqGi5M+Mcd?= =?us-ascii?Q?yt8oGOZ6lZaO46nljmYAwjYbplyMpWU8sZXyhdrnnhNXng=3D=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SJ0PR13MB5545.namprd13.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(1800799015)(366007)(376005)(52116005)(38350700005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?0XP8RBVEeuSbD2KhmquUoFf7fNsN4v61XrY2cvlUx551gf62ZnivMjmMTjdp?= =?us-ascii?Q?vY/SVIWrlCJw42NU0nt+5IdAeeAg/SShPxC3TV1QStK2NIh6f/K+1qoKabuY?= =?us-ascii?Q?cVbXyig1FIQj9Jgw0WmQS2BYc4MrminwU0OLvLdEUq7LZ3Ki9opdLXf1plXG?= =?us-ascii?Q?f4KVAvj0Z6ycVw+1nDJMu9dNosT0rOErZJqGYayOL9N8syEM3sN9Z8x2P4Go?= =?us-ascii?Q?ly63L/NZkVqmV84WSKbv7/eD1Nc9q6LNALWT0fpCEX/kLgb5jF7SW3iINi9P?= =?us-ascii?Q?ZRy7GcZPJ5YIuzHmJg26Zr0v9BOZpS03TfUz5SkUKOZ4ywjMsv8BaATPSvGd?= =?us-ascii?Q?ogyGxIls6TJ4/ltwbCE9+daEcPh1LEMfxcufhULUJX/AENZY4vfljn6EXslF?= =?us-ascii?Q?YfeNAPmRb/5/541/r3CLU9j2pQyMmtsyeP5HWLUPWgsj9dYGxP4hQ7QvCQyY?= =?us-ascii?Q?Bd7l0WrqAKptcKaYtIncHewJ+Wrb92I9gFyOkLzxWBr/no95sQSFzaqobXLa?= =?us-ascii?Q?mKgyXo3+johNJeeYzH2FPqhEzK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DlZjNJeUgFxh5KmrUZ18ka4sWL/cJFHqOTinqQ0dtFHzMa6nlmR+bT/6ALqL?= =?us-ascii?Q?bZyelwJCScdCvN23b66TU2YREpKof+fF/KbBZEN6r3cPY4JOFjpN6WyUZcfL?= =?us-ascii?Q?EDkdhKrrW2wMp2CUKVBLHOczG8dkYL5NVXtGRp1uBnee4Dv2HLfLiBMDOhGR?= =?us-ascii?Q?+w=3D=3D?= X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: 918d5302-030d-4a17-fd93-08dc60208d42 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR13MB5545.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Apr 2024 03:26:50.6358 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: fe128f2c-073b-4c20-818e-7246a585940c X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Bev7dUSxs/eJI/NpEEHFEXR32x37LMhiteGpNDVp6u9y/SVes6Rv/ZHkN1C2I5rSlCVtnCmJA/okx/3+uKs7xINQ1NJJWjwn1TQIs9ojMu0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR13MB6170 X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org From: Zerun Fu For the primary process, the logic loops all BARs and will skip the map of BAR with an invalid physical address (0), also will assign 'uio_res->nb_maps' with the real mapped BARs number. But for the secondary process, instead of loops all BARs, the logic using the 'uio_res->nb_map' as index. If the device uses continuous BARs there will be no problem, whereas if it uses discrete BARs, it will lead to mapping errors. Fix this problem by also loops all BARs and skip the map of BAR with an invalid physical address in secondary process. Fixes: 9b957f378abf ("pci: merge uio functions for linux and bsd") Cc: mukawa@igel.co.jp Cc: stable@dpdk.org Signed-off-by: Zerun Fu Reviewed-by: Chaoyong He Reviewed-by: Long Wu Reviewed-by: Peng Zhang --- drivers/bus/pci/pci_common_uio.c | 40 ++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/drivers/bus/pci/pci_common_uio.c b/drivers/bus/pci/pci_common_uio.c index 76c661f054..432d68b12c 100644 --- a/drivers/bus/pci/pci_common_uio.c +++ b/drivers/bus/pci/pci_common_uio.c @@ -26,7 +26,7 @@ EAL_REGISTER_TAILQ(rte_uio_tailq) static int pci_uio_map_secondary(struct rte_pci_device *dev) { - int fd, i, j; + int fd, i, map_idx = 0, res_idx; struct mapped_pci_resource *uio_res; struct mapped_pci_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list); @@ -37,41 +37,51 @@ pci_uio_map_secondary(struct rte_pci_device *dev) if (rte_pci_addr_cmp(&uio_res->pci_addr, &dev->addr)) continue; - for (i = 0; i != uio_res->nb_maps; i++) { + /* Map all BARs */ + for (res_idx = 0; res_idx != PCI_MAX_RESOURCE; res_idx++) { + /* skip empty BAR */ + if (dev->mem_resource[res_idx].phys_addr == 0) + continue; + + if (map_idx >= uio_res->nb_maps) + return -1; + /* * open devname, to mmap it */ - fd = open(uio_res->maps[i].path, O_RDWR); + fd = open(uio_res->maps[map_idx].path, O_RDWR); if (fd < 0) { RTE_LOG(ERR, EAL, "Cannot open %s: %s\n", - uio_res->maps[i].path, strerror(errno)); + uio_res->maps[map_idx].path, strerror(errno)); return -1; } - void *mapaddr = pci_map_resource(uio_res->maps[i].addr, - fd, (off_t)uio_res->maps[i].offset, - (size_t)uio_res->maps[i].size, 0); + void *mapaddr = pci_map_resource(uio_res->maps[map_idx].addr, + fd, (off_t)uio_res->maps[map_idx].offset, + (size_t)uio_res->maps[map_idx].size, 0); /* fd is not needed in secondary process, close it */ close(fd); - if (mapaddr != uio_res->maps[i].addr) { + if (mapaddr != uio_res->maps[map_idx].addr) { RTE_LOG(ERR, EAL, "Cannot mmap device resource file %s to address: %p\n", - uio_res->maps[i].path, - uio_res->maps[i].addr); + uio_res->maps[map_idx].path, + uio_res->maps[map_idx].addr); if (mapaddr != NULL) { /* unmap addrs correctly mapped */ - for (j = 0; j < i; j++) + for (i = 0; i < map_idx; i++) pci_unmap_resource( - uio_res->maps[j].addr, - (size_t)uio_res->maps[j].size); + uio_res->maps[i].addr, + (size_t)uio_res->maps[i].size); /* unmap addr wrongly mapped */ pci_unmap_resource(mapaddr, - (size_t)uio_res->maps[i].size); + (size_t)uio_res->maps[map_idx].size); } return -1; } - dev->mem_resource[i].addr = mapaddr; + dev->mem_resource[res_idx].addr = mapaddr; + + map_idx++; } return 0; } -- 2.39.1