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 BDA95439B4; Wed, 24 Jan 2024 11:46:45 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5279D40294; Wed, 24 Jan 2024 11:46:45 +0100 (CET) Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2122.outbound.protection.outlook.com [40.107.93.122]) by mails.dpdk.org (Postfix) with ESMTP id 024284026F; Wed, 24 Jan 2024 11:46:43 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iEH6KbRRAQgTFuURfmGRuhMAQEu7mjpIvbA5zaTg8zLx0gUyMdYi2vranLUAAN+BrUY8wxWvOM4eUZFEYkokBSSV7Ni6BARxtgN89/whKoMuH/10Kfd6tj9JErnrCODcZCzByCnLHDVcRjlUa+do6VoDH2PJ9SGKmk7nYT+ws1A5sVCtT6EhFh31Fxl2RLDefeWmU+F9OuLs42R7xA6pxXpOWFTCWqRUYuUGHZQ8Zt0FXYXMpZc2NGssZ1v+sCZBrfDsAms0DVhQ5c7T3jwwkcwBMK8QOA2jZ4DPe96XmPUJX2B3mCP0TKAdUYA7UW3oM9hpG5zk4TB8xe35s8EdWw== 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=OL3PmuDQ3znPHJldV9NpFcGyxbXR/opqxozaQmq0S3c=; b=FEBOaUc8o9YHUT0heUQSGQgEqZGDGilDIjYIdaQGQTYMbWzt2szAc88tMEPCkbXmSwnv+RxsSN9IZaFDfcSAvqrcpYmB5lcvK8WsMFQLBlPOKdaOcyoK7eZ+fSvWAS6Q2hc+fPxFsY4uxQSYjKTuuAJ05Zk5a3/Xp1+/0A4GIzwcEATQeduC+UhLR1V1aUMV7O2ree9ziBGmp3EdG1XsFFM6OMRbnBV8t16QCwzVlDe/6HdEYr1JiCO0o4Ieu77dPaVszuqMLXR7CSjB7E9gU5Y8dCHB9frylhOq/VUJzWWWgp8pPE4xQsUwU4Zj3H9h5qWno3I6lFKiNDpjjZwlDA== 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=OL3PmuDQ3znPHJldV9NpFcGyxbXR/opqxozaQmq0S3c=; b=XdadcACxu7+WcDWaHHGmYYeBr5yAbBIWu9nQIW6QwPTdgSswn3dSZ8limuqnP8rFa163kS8f0xyEFoJGcCKvYMfK2W388c32VQX2ErvO8CQhRqWofqD5Db6qqG1xJQELJFNMmNG7RencL24NjinExBaVEgtzXVG0/uohzgLoQq0= 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 IA2PR13MB6702.namprd13.prod.outlook.com (2603:10b6:208:4ac::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7202.34; Wed, 24 Jan 2024 10:46:39 +0000 Received: from SJ0PR13MB5545.namprd13.prod.outlook.com ([fe80::8e02:f738:570a:f8aa]) by SJ0PR13MB5545.namprd13.prod.outlook.com ([fe80::8e02:f738:570a:f8aa%7]) with mapi id 15.20.7228.022; Wed, 24 Jan 2024 10:46:38 +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] bus/pci: fix secondary process PCI uio resource map problem Date: Wed, 24 Jan 2024 18:45:23 +0800 Message-Id: <20240124104523.2022242-1-chaoyong.he@corigine.com> X-Mailer: git-send-email 2.39.1 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: PH8PR15CA0014.namprd15.prod.outlook.com (2603:10b6:510:2d2::17) To SJ0PR13MB5545.namprd13.prod.outlook.com (2603:10b6:a03:424::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR13MB5545:EE_|IA2PR13MB6702:EE_ X-MS-Office365-Filtering-Correlation-Id: 6013f108-3523-4d1a-30ae-08dc1cc9be20 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ohEgYLM1ASljOycYYv1rendFG1kUj+sz3NSeeBRAYosGgUxwcpgjfB3lqICayWiYBcZ+TyTLsd75wEkhzE43PvxiZ7xJY1KypU2geJn6zEWbBIqIyrYmmfCS2c9scSj4Go3zLhkmGLLaT/I1wUa5QR4zHDcbah919ZYv47N7wuW5iY+3FFubRY7puwKkb0/c0d01QuuvNVWr9ymrNFRwNqURCl9GsYpmXJ4xT5RxfQYRZfNfhFQk89Gh0xWIC3HK01Rr7tPKv5Uv6z/OzTueHrSCx+D/xv2j/tDOAHA9BRk0zH/9N1f/qyL2mupQrUvQyIELs+WLbT9lckLKY5erCZ7VZpsOkLBA6WKRpLyIMRl3c3VMS5JehuqK/kPyj8Mo36m7uaiQaCTihRkkoYOYT5TcFlEV4igfy+/qfDGTmkcXx5teZESB9Kl+AG9J7mhg+EAv86Exemh9dr/bblQPoJhxcfT1fX3uP1+4Q30vaPtSS8O8DaVBzhaZb0R8vSdUqWbELaV6Nb8+ipxTygI2y1NgXj6g4ioQa1SvY5jqVL/mnPGJDS9osUIo4wszLjjAXWHLPAZW28UY39eVZ6EafTpylhm2v9o5crcmgF8kyVEk3Gb5jjerFct8kOXf5Cpd 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)(39840400004)(366004)(376002)(396003)(346002)(136003)(230922051799003)(451199024)(186009)(64100799003)(1800799012)(478600001)(6486002)(38100700002)(107886003)(6916009)(8676002)(44832011)(5660300002)(4326008)(8936002)(1076003)(83380400001)(26005)(2906002)(41300700001)(316002)(6666004)(86362001)(38350700005)(6506007)(52116002)(6512007)(54906003)(66556008)(66476007)(36756003)(2616005)(66946007); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?efB1uCff4XpBnMivGcx7Mo/hbP5qQkDZPLoXPg51M6U+2roQsztXxuX5odl0?= =?us-ascii?Q?CWnnbeNizaVKCzrWeeSXNubI74TR3Bb3hsJzms6hg9hV1qbIQcOT/pmAhEUL?= =?us-ascii?Q?4/n618LSJ6E2KEghG0vr2ptlAZ7n0vlUrbCG+fmMVvS6eKODgdM8ng2r0rhJ?= =?us-ascii?Q?RCl+Ds3mbou+sm43tHwkuer+g2NMrtm6OmLGds8qaXXzNV7iY5l0oC8OoeIN?= =?us-ascii?Q?rqB1qgYG8aLCK50I1VBq2HlVynhSWh/c5hmPOon41oB9imQQOnkOAdOskEaG?= =?us-ascii?Q?b1EfQ+zhrXaC6zcm1ENetC7gEjfiQhSf9hnmTdinrIDfWupf7ItfX651Hsmz?= =?us-ascii?Q?9vzGUdEEgvDyVbCqwjQb23ZZXfK7OdeamJVaemmibl5R7v6YxPvEMLzhUS1N?= =?us-ascii?Q?aScc+8sm+6n492J1eZ+qQd5/v6pXkzXDbKPWv24yummwh4084UZLMW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xo+dIrBAZ5lqSsg0+L9nlGdgHZSCiqyi3aelGz8FNchBuD?= =?us-ascii?Q?jbmvUKENTs6j17+I8lCvfq/MfozrONCnDYZAtcoG7j9D11/e632dE0YNXLQ+?= =?us-ascii?Q?vlvT6mAnVxtzp/scuUx8NaWNQ3TMh+296jO05MUn204DD8f93XekfzKDDmgz?= =?us-ascii?Q?zKMBwZCHApFWHXmOU0mpAs87SKWbIbM0Yl/AlUibcjFBFAFf6mB8YeIy8YEf?= =?us-ascii?Q?echAYQWqEz6i1sfsgUj8ADhj7jHPLFESLjIVzwRgIe9V2dmk7vFbrFUz4EH6?= =?us-ascii?Q?Vw=3D=3D?= X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6013f108-3523-4d1a-30ae-08dc1cc9be20 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR13MB5545.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jan 2024 10:46:38.6493 (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: aLCoTmeRKElMyHaic4IyC2p9BsAszjk3PEW6O3McsdeqkD1az5B15memM0Cz8wKaMtrzo1Ic/1E2u7ec0HsNVlr054yIOpLAEq2g/ec1QOs= X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA2PR13MB6702 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 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 | 94 ++++++++++++++++++++------------ 1 file changed, 60 insertions(+), 34 deletions(-) diff --git a/drivers/bus/pci/pci_common_uio.c b/drivers/bus/pci/pci_common_uio.c index 76c661f054..fcd8a49daf 100644 --- a/drivers/bus/pci/pci_common_uio.c +++ b/drivers/bus/pci/pci_common_uio.c @@ -23,10 +23,57 @@ static struct rte_tailq_elem rte_uio_tailq = { }; EAL_REGISTER_TAILQ(rte_uio_tailq) +static int +pci_uio_map_secondary_resource_by_index(struct rte_pci_device *dev, + int res_idx, struct mapped_pci_resource *uio_res, int map_idx) +{ + int fd, i; + + if (map_idx >= uio_res->nb_maps) + return -1; + + /* + * open devname, to mmap it + */ + 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[map_idx].path, strerror(errno)); + return -1; + } + + 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[map_idx].addr) { + RTE_LOG(ERR, EAL, + "Cannot mmap device resource file %s to address: %p\n", + uio_res->maps[map_idx].path, + uio_res->maps[map_idx].addr); + if (mapaddr != NULL) { + /* unmap addrs correctly mapped */ + for (i = 0; i < map_idx; i++) + pci_unmap_resource( + 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[map_idx].size); + } + return -1; + } + dev->mem_resource[res_idx].addr = mapaddr; + + return 0; +} + static int pci_uio_map_secondary(struct rte_pci_device *dev) { - int fd, i, j; + int map_idx = 0, res_idx, ret; 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 +84,20 @@ 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++) { - /* - * open devname, to mmap it - */ - fd = open(uio_res->maps[i].path, O_RDWR); - if (fd < 0) { - RTE_LOG(ERR, EAL, "Cannot open %s: %s\n", - uio_res->maps[i].path, strerror(errno)); - return -1; + /* 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; + + ret = pci_uio_map_secondary_resource_by_index(dev, res_idx, + uio_res, map_idx); + if (ret < 0) { + RTE_LOG(ERR, EAL, "Failed to map resources\n"); + return ret; } - 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); - - /* fd is not needed in secondary process, close it */ - close(fd); - if (mapaddr != uio_res->maps[i].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); - if (mapaddr != NULL) { - /* unmap addrs correctly mapped */ - for (j = 0; j < i; j++) - pci_unmap_resource( - uio_res->maps[j].addr, - (size_t)uio_res->maps[j].size); - /* unmap addr wrongly mapped */ - pci_unmap_resource(mapaddr, - (size_t)uio_res->maps[i].size); - } - return -1; - } - dev->mem_resource[i].addr = mapaddr; + map_idx++; } return 0; } -- 2.39.1