From nobody Fri Oct 31 04:22:38 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1749664298; cv=pass; d=zohomail.com; s=zohoarc; b=Gd+943kodBhPEsLNMIAU7ISK3FzjXDFKS1XLX3hJPCHmutbIVrkUFD3XgVoFDBVt/UaqYlA2VmwwIcLkEe9uNWvFIsGtOHWJ2oAl3zrqccgZ10tDZgvpHnNZ3Hg1ODUy6QijWXUpO9rBKQ2oblMYUqxch7Z3sBCysNpUUJpErzo= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749664298; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=iGmqazHG8KK3KvSeo0zM4HF7mf0mYqw7CBlFxC1daAE=; b=EEcJ3APIZ7EQcDEE2x15Lk3g89xVG1ZWFxAf/eyVZSlXH0s4GotSvEHdMHJil23ie7FzkJ0S5aEbLhUBQROtIvfu5OfiDzLhLUf2xwMNPq4sKYGcMtpZfLK+KSfK3ciiTbMcjTXgvQDw9Nokth9orbO0rOqj5SEm/FzTl46BlB8= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1749664298619751.0951491394424; Wed, 11 Jun 2025 10:51:38 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1012051.1390606 (Exim 4.92) (envelope-from ) id 1uPPbi-0004uc-Qa; Wed, 11 Jun 2025 17:51:26 +0000 Received: by outflank-mailman (output) from mailman id 1012051.1390606; Wed, 11 Jun 2025 17:51:26 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uPPbi-0004uT-Nr; Wed, 11 Jun 2025 17:51:26 +0000 Received: by outflank-mailman (input) for mailman id 1012051; Wed, 11 Jun 2025 17:51:24 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uPPbg-0004au-TJ for xen-devel@lists.xenproject.org; Wed, 11 Jun 2025 17:51:24 +0000 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on20628.outbound.protection.outlook.com [2a01:111:f403:2418::628]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id b02e8e19-46ec-11f0-a307-13f23c93f187; Wed, 11 Jun 2025 19:51:24 +0200 (CEST) Received: from CH2PR18CA0056.namprd18.prod.outlook.com (2603:10b6:610:55::36) by DS7PR12MB5742.namprd12.prod.outlook.com (2603:10b6:8:71::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8835.18; Wed, 11 Jun 2025 17:51:18 +0000 Received: from CH3PEPF0000000F.namprd04.prod.outlook.com (2603:10b6:610:55:cafe::fd) by CH2PR18CA0056.outlook.office365.com (2603:10b6:610:55::36) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8792.21 via Frontend Transport; Wed, 11 Jun 2025 17:51:17 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CH3PEPF0000000F.mail.protection.outlook.com (10.167.244.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8835.15 via Frontend Transport; Wed, 11 Jun 2025 17:51:17 +0000 Received: from SATLEXMB05.amd.com (10.181.40.146) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Wed, 11 Jun 2025 12:51:16 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB05.amd.com (10.181.40.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Wed, 11 Jun 2025 12:51:16 -0500 Received: from ubuntu.mshome.net (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.39 via Frontend Transport; Wed, 11 Jun 2025 12:51:15 -0500 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: b02e8e19-46ec-11f0-a307-13f23c93f187 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=yMFqcERwWDoSUDEoD/hYDKZcSOCFqPOuOJrUmsc8sbH9qCTcuPJOqbx28FBI/MZW3P0wM1XsqWZsYicGQMJWJhB31c5gmd2hGlcWiWo4bYE2K5QQPATXveh363inF231DBLo3Oz1b8/cTsaGyAeF3QkJqmakK+ogLAjqlBbJlHNxN+h8udUrOc2lYd/829spsxmQVLqiXJAcoaX9UGqXaZyjpiWvvIIDdxm1xvUQv1rJseOVnRP42EEPg8JIOHTeOvIxDyyeQiNpkLp6jVmPiDUUkQmdYI+jWZABp/+1bC9pqXvxk/FEgH1kcE9zOADNxsZVZUQI7zyVoRq/Gm1c/Q== 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=iGmqazHG8KK3KvSeo0zM4HF7mf0mYqw7CBlFxC1daAE=; b=rBONs30pi728r7QrsrZ5pMfTAC+I7Ff81Xiy0Q/EEjI6hjQn9sDb4A9yxuootq8gKLuBvfDP0W8Pt3YqvtjLF80jTV3MsUL1y+WAP9YRGF5OHdIOFV6bGu9AMVL6pg5yjPeCFaHesNheNv+bJJbIRRf7q4HD4QxxsyGo2Afb/xCRjmcdU3hQiGeTKE05a/COA6fjFkny6Y7h0pgJKQmiMOkBZcwu9PRiM/kl19CB7wqOfAXOlYjpZlsavh2hod8GI/NcgAAosulXhsLVQJguzcW/oXw+oMJncCh4rPIIvS7CYXJWIrFg8H75IqglYJNAFb7aAI9u6JvST7wJeKyexw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=iGmqazHG8KK3KvSeo0zM4HF7mf0mYqw7CBlFxC1daAE=; b=J9kvqau/dc2iQPfhvnpLHi71GHQhxMWxaa0oclSmFMsQIDkKhBHaL4ALnxoqAEvmb2Lh8U4+uTt7rGJ0MrPnSm50Q+9+u6rGJj0IQ5cKUBhm5krVtqphKz5S+v95szdSXpD7zs4m6MmdPCjpURNFiBsqeFXE+aco6JtzAdS7qP8= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C From: Stewart Hildebrand To: CC: Stewart Hildebrand , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , "Volodymyr Babchuk" Subject: [PATCH v5 1/2] xen/arm: exclude xen,reg from direct-map domU extended regions Date: Wed, 11 Jun 2025 13:51:03 -0400 Message-ID: <20250611175106.269829-2-stewart.hildebrand@amd.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250611175106.269829-1-stewart.hildebrand@amd.com> References: <20250611175106.269829-1-stewart.hildebrand@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: None (SATLEXMB05.amd.com: stewart.hildebrand@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PEPF0000000F:EE_|DS7PR12MB5742:EE_ X-MS-Office365-Filtering-Correlation-Id: 79dc2d44-ed21-47de-f0c2-08dda9109143 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|82310400026|376014|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?nMtf5re1GBEoaUrL8XfurncGXQYHbJWUqMdFY/Y9atPq27P3/kJk4n2HJfFd?= =?us-ascii?Q?/EpadufYrWWFkRlgHVNe7n9njniGrKL2/4SVxjYWNR29iOiUIAYnLrCoVCws?= =?us-ascii?Q?/6PevyIaAUxZUqiKYrC/eYlAjC7aid2oCO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vc5/tPCjGH5kC9xCMZRDFcjJX5no9bknh91e4AQhcsS4gnPiS5Y?= =?us-ascii?Q?UfTKGuRI8M2EmClqkvoni1RhVFRvCGskBB82wiIdlQGVLcqWm4VtUL1LT8o9?= =?us-ascii?Q?o+TixcjUOGIEYtnsijVvUIuYhCclJf7G3YyiV57nubwb51JdvSzy+5ue/95E?= =?us-ascii?Q?02cupB3RVFiMkvRjOth1ID88KRwqkEzhMWJ7/P2FsOSnuSBBVX9IrxbL6TGa?= =?us-ascii?Q?eS6NhKZgqcKZEO5JwU6Nqq8UfshzykVP2p4/8iTV73g2fyRHuB7HdVDyuf0n?= =?us-ascii?Q?Bt7b04NhXawv1QIF2vG/D51ZYLjXyInJmYDH5UtHYvjxuTf0t2BrLXtfZpcx?= =?us-ascii?Q?yg1rLCZ94qyJo/CL74hRv4ASe0iz1Y9T5uWXPL6tNtBJsCkmVO+AcAQZrCPm?= =?us-ascii?Q?ejI1+e2rkQU3gQzSBvvJbkl04NHUs7DpFISN+LfiSJ3DyN+Xvc3GpwGJE0bs?= =?us-ascii?Q?aKXYRjWiCbfSAdtq6Budbdr6jm9emJDvSL92?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700013)(82310400026)(376014)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Jun 2025 17:51:17.7665 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 79dc2d44-ed21-47de-f0c2-08dda9109143 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CH3PEPF0000000F.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB5742 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1749664301022116600 Content-Type: text/plain; charset="utf-8" Similarly to fba1b0974dd8, when a device is passed through to a direct-map dom0less domU, the xen,reg ranges may overlap with the extended regions. Remove xen,reg from direct-map domU extended regions. Take the opportunity to update the comment ahead of find_memory_holes(). Signed-off-by: Stewart Hildebrand Reviewed-by: Michal Orzel --- v4->v5: * remove extranous -1 and +1 * create local helper function to count ranges v3->v4: * conditionally allocate xen_reg * use rangeset_report_ranges() * make find_unallocated_memory() cope with NULL entry v2->v3: * new patch --- xen/arch/arm/domain_build.c | 80 +++++++++++++++++++++++++-- xen/common/device-tree/domain-build.c | 5 ++ 2 files changed, 80 insertions(+), 5 deletions(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 590f38e52053..cef6c85e22ec 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -792,15 +792,17 @@ static int __init handle_pci_range(const struct dt_de= vice_node *dev, } =20 /* - * Find the holes in the Host DT which can be exposed to Dom0 as extended - * regions for the special memory mappings. In order to calculate regions - * we exclude every addressable memory region described by "reg" and "rang= es" - * properties from the maximum possible addressable physical memory range: + * Find the holes in the Host DT which can be exposed to Dom0 or a direct-= map + * domU as extended regions for the special memory mappings. In order to + * calculate regions we exclude every addressable memory region described = by + * "reg" and "ranges" properties from the maximum possible addressable phy= sical + * memory range: * - MMIO * - Host RAM * - PCI aperture * - Static shared memory regions, which are described by special property * "xen,shared-mem" + * - xen,reg mappings */ static int __init find_memory_holes(const struct kernel_info *kinfo, struct membanks *ext_regions) @@ -882,6 +884,13 @@ static int __init find_memory_holes(const struct kerne= l_info *kinfo, } } =20 + if ( kinfo->xen_reg_assigned ) + { + res =3D rangeset_subtract(mem_holes, kinfo->xen_reg_assigned); + if ( res ) + goto out; + } + start =3D 0; end =3D (1ULL << p2m_ipa_bits) - 1; res =3D rangeset_report_ranges(mem_holes, PFN_DOWN(start), PFN_DOWN(en= d), @@ -962,11 +971,51 @@ static int __init find_domU_holes(const struct kernel= _info *kinfo, return res; } =20 +static int __init count(unsigned long s, unsigned long e, void *data) +{ + unsigned int *cnt =3D data; + + (*cnt)++; + + return 0; +} + +static unsigned int __init count_ranges(struct rangeset *r) +{ + unsigned int cnt =3D 0; + + rangeset_report_ranges(r, 0, PFN_DOWN((1ULL << p2m_ipa_bits) - 1), cou= nt, + &cnt); + + return cnt; +} + +static int __init rangeset_to_membank(unsigned long s_gfn, unsigned long e= _gfn, + void *data) +{ + struct membanks *membank =3D data; + paddr_t s =3D pfn_to_paddr(s_gfn); + paddr_t e =3D pfn_to_paddr(e_gfn + 1); + + if ( membank->nr_banks >=3D membank->max_banks ) + return 0; + + membank->bank[membank->nr_banks].start =3D s; + membank->bank[membank->nr_banks].size =3D e - s; + membank->nr_banks++; + + return 0; +} + static int __init find_host_extended_regions(const struct kernel_info *kin= fo, struct membanks *ext_regions) { int res; struct membanks *gnttab =3D membanks_xzalloc(1, MEMORY); + struct membanks *xen_reg =3D + kinfo->xen_reg_assigned + ? membanks_xzalloc(count_ranges(kinfo->xen_reg_assigned), MEMORY) + : NULL; =20 /* * Exclude the following regions: @@ -974,6 +1023,7 @@ static int __init find_host_extended_regions(const str= uct kernel_info *kinfo, * 2) Remove reserved memory * 3) Grant table assigned to domain * 4) Remove static shared memory (when the feature is enabled) + * 5) Remove xen,reg */ const struct membanks *mem_banks[] =3D { kernel_info_get_mem_const(kinfo), @@ -982,12 +1032,29 @@ static int __init find_host_extended_regions(const s= truct kernel_info *kinfo, #ifdef CONFIG_STATIC_SHM bootinfo_get_shmem(), #endif + xen_reg, }; =20 dt_dprintk("Find unallocated memory for extended regions\n"); =20 if ( !gnttab ) - return -ENOMEM; + { + res =3D -ENOMEM; + goto out; + } + + if ( kinfo->xen_reg_assigned ) + { + if ( !xen_reg ) + { + res =3D -ENOMEM; + goto out; + } + + rangeset_report_ranges(kinfo->xen_reg_assigned, 0, + PFN_DOWN((1ULL << p2m_ipa_bits) - 1), + rangeset_to_membank, xen_reg); + } =20 gnttab->nr_banks =3D 1; gnttab->bank[0].start =3D kinfo->gnttab_start; @@ -995,6 +1062,9 @@ static int __init find_host_extended_regions(const str= uct kernel_info *kinfo, =20 res =3D find_unallocated_memory(kinfo, mem_banks, ARRAY_SIZE(mem_banks= ), ext_regions, add_ext_regions); + + out: + xfree(xen_reg); xfree(gnttab); =20 return res; diff --git a/xen/common/device-tree/domain-build.c b/xen/common/device-tree= /domain-build.c index 6b8b8d7cacb6..99ea81198a76 100644 --- a/xen/common/device-tree/domain-build.c +++ b/xen/common/device-tree/domain-build.c @@ -193,6 +193,10 @@ int __init find_unallocated_memory(const struct kernel= _info *kinfo, =20 /* Remove all regions listed in mem_banks */ for ( i =3D 0; i < nr_mem_banks; i++ ) + { + if ( !mem_banks[i] ) + continue; + for ( j =3D 0; j < mem_banks[i]->nr_banks; j++ ) { start =3D mem_banks[i]->bank[j].start; @@ -212,6 +216,7 @@ int __init find_unallocated_memory(const struct kernel_= info *kinfo, goto out; } } + } =20 start =3D 0; end =3D (1ULL << p2m_ipa_bits) - 1; --=20 2.49.0 From nobody Fri Oct 31 04:22:38 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1749664303; cv=pass; d=zohomail.com; s=zohoarc; b=c7ya3pjDs451t91088GK6d6psmnON1BTWz2aGSdxzBjhZEwUP9C2j9gXqYnLXNwkc95UDFT0bthhMjPimkgAbsZwl+Ky8gPRZsG7dw9eoax65S1wHwChGQD8aUsGBLCiy/yfZRky/zB9VLqlOB8fgU4fmFEjaaW6gmThKmeYiWo= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749664303; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=OGLNAcHMQN3tEn5Sq+wi+jklFsofF17Ha4Z5ZK5ekUI=; b=NVXWSWqVYxl7n/8QS/5ZiZ6kYPGfsnmIb4gTfL1hPd9487PkTlYejD+JVRJB7izb+3S3sRDFLMDz/tbZQ2S76J24qbhhgvgUerYWOQAcD4m62LtECFihLSNhFYd4yA8gZcX1kMRZVbkKX+GeoIj4Cs2Rs+xIgNwqKpfkC+l7Okg= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1749664303739722.5953459883804; Wed, 11 Jun 2025 10:51:43 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1012053.1390616 (Exim 4.92) (envelope-from ) id 1uPPbp-0005GC-4H; Wed, 11 Jun 2025 17:51:33 +0000 Received: by outflank-mailman (output) from mailman id 1012053.1390616; Wed, 11 Jun 2025 17:51:33 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uPPbp-0005Fz-19; Wed, 11 Jun 2025 17:51:33 +0000 Received: by outflank-mailman (input) for mailman id 1012053; Wed, 11 Jun 2025 17:51:32 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uPPbn-0005Bu-U8 for xen-devel@lists.xenproject.org; Wed, 11 Jun 2025 17:51:32 +0000 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2060c.outbound.protection.outlook.com [2a01:111:f403:200a::60c]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id b33a52c0-46ec-11f0-b894-0df219b8e170; Wed, 11 Jun 2025 19:51:29 +0200 (CEST) Received: from DS7PR03CA0082.namprd03.prod.outlook.com (2603:10b6:5:3bb::27) by DS0PR12MB8019.namprd12.prod.outlook.com (2603:10b6:8:14e::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8792.38; Wed, 11 Jun 2025 17:51:25 +0000 Received: from CH3PEPF00000016.namprd21.prod.outlook.com (2603:10b6:5:3bb:cafe::86) by DS7PR03CA0082.outlook.office365.com (2603:10b6:5:3bb::27) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8769.18 via Frontend Transport; Wed, 11 Jun 2025 17:51:24 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CH3PEPF00000016.mail.protection.outlook.com (10.167.244.121) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8835.2 via Frontend Transport; Wed, 11 Jun 2025 17:51:24 +0000 Received: from SATLEXMB05.amd.com (10.181.40.146) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Wed, 11 Jun 2025 12:51:22 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB05.amd.com (10.181.40.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Wed, 11 Jun 2025 12:51:22 -0500 Received: from ubuntu.mshome.net (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.39 via Frontend Transport; Wed, 11 Jun 2025 12:51:21 -0500 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: b33a52c0-46ec-11f0-b894-0df219b8e170 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=SDh/NYOK76VAUfe3NsGqu1T3/MPqr8CCvZI3gmkQOWiYtvucNaor135smGAN7awzZfA5zqq4FAH/vw1mz2FTuF6I6WiJ4x+ezkVlgCtHxZY74DaXvhYGjPhDHhwcS0z3WVxYjpZYhFdXEIcvy1MnVWjjTBFa33yT1jBDuUF70+JonvVVXPS6yZqZcJOgL9LE9/GdKVvjHUGbwlgAuRt8AmCkCCPXO8XDqkxyBH/woChVBn3M1lEU8OS/BZNO/5mXyoPIVsypqLZFiD03yQMl53i/phJCLTKcn7gKNd8UMYt6UUGywiIXYDk49B8mIDu0uicsN15vBw5H0b4HDh6RKQ== 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=OGLNAcHMQN3tEn5Sq+wi+jklFsofF17Ha4Z5ZK5ekUI=; b=m6VnlhnL6Sj9R+naMbZgq1d6M+CSZqCPsCa5AJ3HCYByS6VaM6y29CCatt+oWQ6lUHdt150OD1FoiFrM6hCEFtA0p2HnZpf/qpwPUVwF40VWzlnG9TZWL2mFW5K7IJyIw22jRsaLeH0XmuEaZN669kGqjUq+zGEZdVLhwtQwfsMqESRXOpiHKUj+3fFvwvdmWK+v/Q9U9gKSvD7I/+S66b0Jy1UFmAulw766PrGVfbVWT6RpeNsC2/HG9zuvzkpA3KEuImWTJI2pASE0rVddDbWuGUm8CcfdqMy5A2NjdafMWZ0CfKdYORQ76KLgToFE/npdaecfcESxpK06Gn20/A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=OGLNAcHMQN3tEn5Sq+wi+jklFsofF17Ha4Z5ZK5ekUI=; b=YTmAHGjgvQZ35G+xnQckZU0RMs2aZcbm+dlTZv/lxCsyrHy+wRZiOm/xocHOqD1/whsf00d5S8nWG0OhNJSwtcYiw2ZcQu7Ce70j1wNfnR2Cj3VuLxKLIEHxKKcxFGyLAar9esWbWFbIihm1Z1XaN0HQqfJfP0tcJnvkDJ8Djvk= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C From: Stewart Hildebrand To: CC: Stewart Hildebrand , Anthony PERARD , Juergen Gross , "Stefano Stabellini" Subject: [PATCH v5 2/2] tools/arm: exclude iomem from domU extended regions Date: Wed, 11 Jun 2025 13:51:04 -0400 Message-ID: <20250611175106.269829-3-stewart.hildebrand@amd.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250611175106.269829-1-stewart.hildebrand@amd.com> References: <20250611175106.269829-1-stewart.hildebrand@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: None (SATLEXMB05.amd.com: stewart.hildebrand@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PEPF00000016:EE_|DS0PR12MB8019:EE_ X-MS-Office365-Filtering-Correlation-Id: 369f911f-cf31-4ca9-d5e8-08dda9109558 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|82310400026|376014|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?7iqFYPSaJBweMpj9Ldb35LKxV6mXE1vQapHUx06ySHGTXMGKJh7RD5M8Poxr?= =?us-ascii?Q?6SjE4Ew9dQTfU0Nld4VzTUyXWN85pQ3dTDj/0k2F3bRBSFeacnQ2w6Pd1ZRR?= =?us-ascii?Q?HaPobUQgLFSqWyr0emPQQDAzysoMrrRD823DtBcQ5crk2huheJbaXKPKE+DH?= =?us-ascii?Q?SaSOLbU/ZKrwJ4gl1h5463jZSOAv/hKu/vQb0prOH+/pUZX6+d1y5PjtoIKa?= =?us-ascii?Q?hefl3+F0UiToxzqp2L1cgYUaEkfZVP6DQCaIihS629ggLMICrbqRqDw+wXml?= =?us-ascii?Q?kTXSZhU8yGJ0/LDdjlc/ta4Ta7qo6NWxivIyiUMYRcUovwNotTd1neg2LCU5?= =?us-ascii?Q?QYiO124W+qhJDdFDFVHzs34Wkgyv+sSOyvo/4NkYhwLMEYgYmmikqE8yhAEE?= =?us-ascii?Q?1obXLoW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= =?us-ascii?Q?r298kCeE+gWnt8NZagrHX5LJVcf4TlQcNwnjXjOdJYXHXMCeTK6vaeH4ATCW?= =?us-ascii?Q?Kl4WlEu2MlY4Yjx3Jo3RuHHKOXNBgsYVcf4aPHWunGuDl6CCd8lIJkQLuzz/?= =?us-ascii?Q?KQebHvjqufmftvnVNUGT+5wlLgavQFXddXBmbbdaAkiHt7W6VENrs7tC05ep?= =?us-ascii?Q?YF2W4VQaVgFL5uE=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700013)(82310400026)(376014)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Jun 2025 17:51:24.6125 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 369f911f-cf31-4ca9-d5e8-08dda9109558 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CH3PEPF00000016.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB8019 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1749664305121116600 Content-Type: text/plain; charset="utf-8" When a device is passed through to a xl domU, the iomem ranges may overlap with the extended regions. Remove iomem from extended regions. Signed-off-by: Stewart Hildebrand Reviewed-by: Anthony PERARD --- Not sure if we need a Fixes: tag, but if we do: Fixes: 57f87857dc2d ("libxl/arm: Add handling of extended regions for DomU") v4->v5: * add Anthony's R-b v3->v4: * use "else" instead of continue + another if statement * remove assert * s/iomem.end >=3D/unallocated.start >/ in two conditions * new variable to distinguish unallocated size from region size * print base + size - 1 v2->v3: * no change v1->v2: * no change --- tools/libs/light/libxl_arm.c | 110 +++++++++++++++++++++++++++++------ 1 file changed, 91 insertions(+), 19 deletions(-) diff --git a/tools/libs/light/libxl_arm.c b/tools/libs/light/libxl_arm.c index 75c811053c7c..3086c52acf83 100644 --- a/tools/libs/light/libxl_arm.c +++ b/tools/libs/light/libxl_arm.c @@ -798,6 +798,8 @@ static int make_timer_node(libxl__gc *gc, void *fdt, return 0; } =20 +#define MAX_NR_EXT_REGIONS 256 + static int make_hypervisor_node(libxl__gc *gc, void *fdt, const libxl_version_info *vers) { @@ -821,7 +823,7 @@ static int make_hypervisor_node(libxl__gc *gc, void *fd= t, */ res =3D fdt_property_reg_placeholder(gc, fdt, GUEST_ROOT_ADDRESS_CELLS, GUEST_ROOT_SIZE_CELLS, - GUEST_RAM_BANKS + 1); + MAX_NR_EXT_REGIONS + 1); if (res) return res; =20 /* @@ -1517,17 +1519,29 @@ static void finalise_one_node(libxl__gc *gc, void *= fdt, const char *uname, =20 #define EXT_REGION_MIN_SIZE xen_mk_ullong(0x0004000000) /* 64MB */ =20 -static int finalize_hypervisor_node(libxl__gc *gc, struct xc_dom_image *do= m) +static int compare_iomem(const void *a, const void *b) +{ + const libxl_iomem_range *x =3D a, *y =3D b; + + if (x->gfn < y->gfn) + return -1; + if (x->gfn > y->gfn) + return 1; + return 0; +} + +static int finalize_hypervisor_node(libxl__gc *gc, + libxl_domain_build_info *b_info, + struct xc_dom_image *dom) { void *fdt =3D dom->devicetree_blob; - uint64_t region_size[GUEST_RAM_BANKS] =3D {0}, region_base[GUEST_RAM_B= ANKS], - bankend[GUEST_RAM_BANKS]; + uint64_t region_base[MAX_NR_EXT_REGIONS], region_size[MAX_NR_EXT_REGIO= NS]; uint32_t regs[(GUEST_ROOT_ADDRESS_CELLS + GUEST_ROOT_SIZE_CELLS) * - (GUEST_RAM_BANKS + 1)]; + (MAX_NR_EXT_REGIONS + 1)]; be32 *cells =3D ®s[0]; const uint64_t bankbase[] =3D GUEST_RAM_BANK_BASES; const uint64_t banksize[] =3D GUEST_RAM_BANK_SIZES; - unsigned int i, len, nr_regions =3D 0; + unsigned int i, j, len, nr_regions =3D 0; libxl_dominfo info; int offset, rc; =20 @@ -1542,20 +1556,82 @@ static int finalize_hypervisor_node(libxl__gc *gc, = struct xc_dom_image *dom) if (info.gpaddr_bits > 64) return ERROR_INVAL; =20 + qsort(b_info->iomem, b_info->num_iomem, sizeof(libxl_iomem_range), + compare_iomem); + /* * Try to allocate separate 2MB-aligned extended regions from the first * and second RAM banks taking into the account the maximum supported * guest physical address space size and the amount of memory assigned * to the guest. */ - for (i =3D 0; i < GUEST_RAM_BANKS; i++) { - region_base[i] =3D bankbase[i] + + for (i =3D 0; i < GUEST_RAM_BANKS && nr_regions < MAX_NR_EXT_REGIONS; = i++) { + struct { + uint64_t start; + uint64_t end; /* inclusive */ + } unallocated; + uint64_t unallocated_size =3D 0; + + unallocated.start =3D bankbase[i] + ALIGN_UP_TO_2MB((uint64_t)dom->rambank_size[i] << XC_PAGE_SHIF= T); =20 - bankend[i] =3D ~0ULL >> (64 - info.gpaddr_bits); - bankend[i] =3D min(bankend[i], bankbase[i] + banksize[i] - 1); - if (bankend[i] > region_base[i]) - region_size[i] =3D bankend[i] - region_base[i] + 1; + unallocated.end =3D ~0ULL >> (64 - info.gpaddr_bits); + unallocated.end =3D min(unallocated.end, bankbase[i] + banksize[i]= - 1); + + if (unallocated.end >=3D unallocated.start) + unallocated_size =3D unallocated.end - unallocated.start + 1; + + if (unallocated_size < EXT_REGION_MIN_SIZE) + continue; + + /* Exclude iomem */ + for (j =3D 0; j < b_info->num_iomem && nr_regions < MAX_NR_EXT_REG= IONS; + j++) { + struct { + uint64_t start; + uint64_t end; /* inclusive */ + } iomem; + + iomem.start =3D b_info->iomem[j].gfn << XC_PAGE_SHIFT; + iomem.end =3D ((b_info->iomem[j].gfn + b_info->iomem[j].number) + << XC_PAGE_SHIFT) - 1; + + if (iomem.end >=3D unallocated.start + && iomem.start <=3D unallocated.end) { + + if (iomem.start <=3D unallocated.start) { + unallocated.start =3D iomem.end + 1; + + if (unallocated.start > unallocated.end) + break; + } else { + uint64_t size =3D iomem.start - unallocated.start; + + if (size >=3D EXT_REGION_MIN_SIZE) { + region_base[nr_regions] =3D unallocated.start; + region_size[nr_regions] =3D size; + nr_regions++; + } + + unallocated.start =3D iomem.end + 1; + + if (unallocated.start > unallocated.end) + break; + } + } + } + + if (unallocated.end >=3D unallocated.start + && nr_regions < MAX_NR_EXT_REGIONS) + { + uint64_t size =3D unallocated.end - unallocated.start + 1; + + if (size >=3D EXT_REGION_MIN_SIZE) { + region_base[nr_regions] =3D unallocated.start; + region_size[nr_regions] =3D size; + nr_regions++; + } + } } =20 /* @@ -1565,16 +1641,12 @@ static int finalize_hypervisor_node(libxl__gc *gc, = struct xc_dom_image *dom) set_range(&cells, GUEST_ROOT_ADDRESS_CELLS, GUEST_ROOT_SIZE_CELLS, GUEST_GNTTAB_BASE, GUEST_GNTTAB_SIZE); =20 - for (i =3D 0; i < GUEST_RAM_BANKS; i++) { - if (region_size[i] < EXT_REGION_MIN_SIZE) - continue; - + for (i =3D 0; i < nr_regions; i++) { LOG(DEBUG, "Extended region %u: %#"PRIx64"->%#"PRIx64"", - nr_regions, region_base[i], region_base[i] + region_size[i]); + i, region_base[i], region_base[i] + region_size[i] - 1); =20 set_range(&cells, GUEST_ROOT_ADDRESS_CELLS, GUEST_ROOT_SIZE_CELLS, region_base[i], region_size[i]); - nr_regions++; } =20 if (!nr_regions) @@ -1626,7 +1698,7 @@ int libxl__arch_domain_finalise_hw_description(libxl_= _gc *gc, =20 } =20 - res =3D finalize_hypervisor_node(gc, dom); + res =3D finalize_hypervisor_node(gc, &d_config->b_info, dom); if (res) return res; =20 --=20 2.49.0