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 4784D439FC; Mon, 29 Jan 2024 10:23:01 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4742D40DDC; Mon, 29 Jan 2024 10:22:58 +0100 (CET) Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2109.outbound.protection.outlook.com [40.107.93.109]) by mails.dpdk.org (Postfix) with ESMTP id 26D3040DCD; Mon, 29 Jan 2024 10:22:56 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lYBYkW4IWHm2YquBV3HMZGcA9MrxmakPLGDgqrNBiUqjUU0sXRRWLBlo7JoFn3PA7S4YYwITEYVOOv4jDeETwGMld2UTulgFTp9wNdKPblPhf+n9uoc66keKjm7u+treqo8bd97S1Hm+ZGGM3A5uM5yIFfxaRNjzDYi+dOZ2IHFzpZ46bbFlbaJ1sJEBKQiGZlb+Lvck3meM1okIXzkwwkVoR+oBD6iRUYqwedfI/oH5GQJe11tCJ5SIe6xXy69ercuAnEpqnTUmlPwuFZ8eSojnZ1kclrT97qtpSGsFdG3YnBpQOgPuX9vgsxNiy/v1P91bYsGnIPmGL05fbtxDUw== 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=QqTFvywW7Iz/zjhDxbMjXZ3HIB6JO92VrEVZOcn2RpjpSkXJ9qRyFC1O+2wszaYX1uLBpA+M0ExAZ7qSg+ecvd8XXDNuUWlh+9IPRZhVD+itrjbZF2svXXsmaUmyzNQgMFiH1b3XXZqZlw+6o8NOYyDM9XR1tmCi8Fx7aMAkCzpV4r1UiIZzt/tt26KbbFLfH2UXeCBKaBHn9Ue31B5JX/WYSBQNKgmNObM6cbWY+sYbnGn0/lvJ0fb23xaH7OMME2u+vpaI5FUyqEBDblwfhU57ynfPHbW1p5JDL1Eq01vqZQw9oPXYueAi6lfGgEmGt/MUL+Os4svP0TDOHBdSFQ== 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=vynryJVinWv2FN/o2q/N9D+/b7HDDOXHMiMc7+zZFbmnTQBw5m+DOeEmb+0Nwn4jl4zD0zNYLxOT+PVrLP0ebYEXw6aIoLZH606rzOucKp3U5CZW4aa6bRJaAu4lCfmW2NvPdBcO+RQr2IFKA8mO9jpXwJvcRn/25/zUN88APsk= 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 PH7PR13MB5868.namprd13.prod.outlook.com (2603:10b6:510:15a::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.34; Mon, 29 Jan 2024 09:22:53 +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.029; Mon, 29 Jan 2024 09:22:52 +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 v2 1/2] bus/pci: fix secondary process PCI uio resource map problem Date: Mon, 29 Jan 2024 17:22:30 +0800 Message-Id: <20240129092231.3531217-2-chaoyong.he@corigine.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20240129092231.3531217-1-chaoyong.he@corigine.com> References: <20240124104523.2022242-1-chaoyong.he@corigine.com> <20240129092231.3531217-1-chaoyong.he@corigine.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: BYAPR21CA0021.namprd21.prod.outlook.com (2603:10b6:a03:114::31) To SJ0PR13MB5545.namprd13.prod.outlook.com (2603:10b6:a03:424::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR13MB5545:EE_|PH7PR13MB5868:EE_ X-MS-Office365-Filtering-Correlation-Id: 89fddbd2-b128-4248-76c9-08dc20abde88 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: HUq07eLnq54f+zO1+mkbSSLXXoykFtBrQDpjtkRBfNpe6JIyHAz2rWV5NveG2W0rrjDf0kQLr9hZIEBi0aswy6OV8OWDOfvJo51rcyJaP2mvw5j86WJ5o3yKi2M9IO6ghOat4a4sCbJbusytLYQBcT/kM+cgTFJ1HOTeq2BcW5bND7nu6zn0wQgQ2qeltrURDv9McqXBKotoCDiFTSCCaNt23rx2SM5rnh49cTeEGKVGhr8wBLEWj7mNrDv0ka56ZN6A/5HsPJPIQSHbE6pRxTP35qoBNXxPDvNtbIAhl02OPztECKOPwzOkbJ4zYRtyuOIe/GVH+RplqgX9uhf7fxIwQIY76268m3ibCrtURD6de6oTqkW3aylJpyMqcvVXhd9TEC5FaFBl63LZS6JpAvLMCXDoc/jEs190UK2CUXRo0pl515YGrldCSMyZb0FjTLPU/qL9xcCi6Crh1bqtQ9s62znJe1nZ0tX25JgwGPwZfMUwMZ/SYNd+zHZFMR74Y72t/xR9cC+VaRgzbPu/hYakbypR4+AJjBYzSrJbcuN6kbjhUAQG2avhQeaXyDILnuT37yoqhDnAvxRVAAobjF2MUytdSgbbb+Fs6XxT/IrxSGkOGFFT/drfaLKTXfCS 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)(396003)(39830400003)(366004)(346002)(136003)(376002)(230922051799003)(451199024)(64100799003)(186009)(1800799012)(83380400001)(2906002)(5660300002)(38100700002)(6486002)(66556008)(66476007)(316002)(66946007)(41300700001)(54906003)(6916009)(107886003)(26005)(1076003)(2616005)(8936002)(8676002)(6506007)(44832011)(6666004)(6512007)(52116002)(4326008)(478600001)(36756003)(86362001)(38350700005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?6rz2MZ4ribyOcKxs9+sMHpxUtlPmQTBKa9nkVKtZJtpgIJPXlwZ87upySepu?= =?us-ascii?Q?NwEvfWbB3jX629fCS9b9DQucEDCE8RByM+QSCaslG99b5Ty12LU/ai66pqjR?= =?us-ascii?Q?ZzEtjvQ2HWW9M+LgqepjZrMVVU6eFjnAWgWCjW7vRiKn3acg6aIcKBuX8kvX?= =?us-ascii?Q?VAosvjgQ1E1LforHCI71mfd3D9V7KTydpl323pgXW1Qu1HUL0b7J6+iDohV+?= =?us-ascii?Q?itfmi3jqsBwzhCSss1HqbkrO64zTwqIS94Sf7GmRPmSAPcvV5IMquLXMaAld?= =?us-ascii?Q?PNeZgt91LO99BZJaynVeprbwIVG1ffF/OWwdoKilFw0BoiELbRGA7MmJcfth?= =?us-ascii?Q?xj4E4TMoB2WRYAEZmC89n485bXYbIY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us-ascii?Q?kO7GuB5ErWs5LbmTAMrmyGYPeAd5U0PgmMQcyJD6bvOhqraIl/7jb0RSMKS7?= =?us-ascii?Q?xOa+DXw03VCWuJ92gXAWOW8fdLzUK5Dfza9Zr4kPQtiyqxazmZ1YPP0V2LrT?= =?us-ascii?Q?k5zCnIliqQLR0e1WQbImYOZs807U9pnPsBArFaxVyszQ1J29J00SnVmECK0f?= =?us-ascii?Q?BIzFHaB4UhOvdaZ4r/oo+oc8xSrHlRwQ//uuhm+LifMMjPH8shYfy12MMEhY?= =?us-ascii?Q?vZELBBtqU5LcOiUWNdRLcLinFKSasgbkW7lk3swqZX6GVtyaRpbyQCZieJaZ?= =?us-ascii?Q?6F5MLOOTrPzQVrd5k/0qG9nxcs3H+1t5CK0mVaKyTaZD1aavShujUTk3fr/p?= =?us-ascii?Q?mw=3D=3D?= X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: 89fddbd2-b128-4248-76c9-08dc20abde88 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR13MB5545.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jan 2024 09:22:52.7469 (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: zKDDsluAPdc52GZcLAOZkPbenuQgi1y2vOjVDmq17KOIAz0c7MP2Bap+mgdWEIC/psckX7a5EwznDHM48QNi+VTRkG5e3ed8OMJFPiWJg88= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR13MB5868 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