From nobody Fri Oct 31 09:56:12 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=1749494119; cv=pass; d=zohomail.com; s=zohoarc; b=kRQtxe7xs6HRHnyV5Z86f7tTuwe+1nReucWDYqdJIt/FabqLJKsiXCFMmJUQFUn9NwzSugmWd0w4tx4Hmc8NOrM8CEbq1+nXgpMB1qm5NaIoXCOfaqDPajuKYc++i6JhhM+o9EEwk5LH7aKUfIzSlktwRHIM9hHbGApR56xLb8I= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749494119; 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=jy3/PnBlKCLoGe2ac+z/3nKSFm8cz+n19wqlfOIaulw=; b=YCxYLp3QrKEc+2iyff9iyrpBxv2oWXhOwOo5d2sBU/khWPKmUmTVfbXl+FG+/H1nJlzjW2dR/Lu+/kj10SVrweD4GpCIHm6kaNrCnO/uX82i8BulHVLmgbHzoHUSknKR/p9rbPFs7kS8ydFTEHTZ5aU5cX5nZX/EwCfreV+YFdE= 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 1749494119907125.39205610525164; Mon, 9 Jun 2025 11:35:19 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1010405.1388516 (Exim 4.92) (envelope-from ) id 1uOhKm-0004W7-MM; Mon, 09 Jun 2025 18:35:00 +0000 Received: by outflank-mailman (output) from mailman id 1010405.1388516; Mon, 09 Jun 2025 18:35:00 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uOhKm-0004W0-IO; Mon, 09 Jun 2025 18:35:00 +0000 Received: by outflank-mailman (input) for mailman id 1010405; Mon, 09 Jun 2025 18:35:00 +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 1uOhKm-0004Vd-6X for xen-devel@lists.xenproject.org; Mon, 09 Jun 2025 18:35:00 +0000 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on20618.outbound.protection.outlook.com [2a01:111:f403:2009::618]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 707f2a5f-4560-11f0-b894-0df219b8e170; Mon, 09 Jun 2025 20:34:56 +0200 (CEST) Received: from MN0PR04CA0012.namprd04.prod.outlook.com (2603:10b6:208:52d::31) by CYYPR12MB8990.namprd12.prod.outlook.com (2603:10b6:930:ba::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8792.34; Mon, 9 Jun 2025 18:34:51 +0000 Received: from BN1PEPF00006000.namprd05.prod.outlook.com (2603:10b6:208:52d:cafe::ff) by MN0PR04CA0012.outlook.office365.com (2603:10b6:208:52d::31) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8792.35 via Frontend Transport; Mon, 9 Jun 2025 18:34:51 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by BN1PEPF00006000.mail.protection.outlook.com (10.167.243.232) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8835.15 via Frontend Transport; Mon, 9 Jun 2025 18:34:50 +0000 Received: from SATLEXMB06.amd.com (10.181.40.147) 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; Mon, 9 Jun 2025 13:34:50 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB06.amd.com (10.181.40.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Mon, 9 Jun 2025 13:34:50 -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; Mon, 9 Jun 2025 13:34:49 -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: 707f2a5f-4560-11f0-b894-0df219b8e170 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=fxs3JEd6KzLI9ubbxdOirv1MJ0MsHlh8R+E+jAcbtPLQK3TPlbXIfS1lRHip2eFTLopc8IZZ5o+RYsG5ib88A2pu582r+oOAuzkTtvWMK1/ppY0w5sOSIVkZLvxEMBLwdTt+5hNekMfDsiDjWi7iCy0enhLM/5q2wZAqDfp/Bpwozxo3sfpeLBxaTN62ch+AJWrwgmTqweSWraK4peJvNE1FBf+CmW3r4bn7BZxYcXnUUGfEbm4xYmzeMGi8kAUiwh8c2JN+62a3N3DoSYa71czPsH8tmQMne30znoB8cN+bWvIkX9usAZNuq1cBFHaP9oq6yWdmpANc4rnlf9KYmw== 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=jy3/PnBlKCLoGe2ac+z/3nKSFm8cz+n19wqlfOIaulw=; b=l/2jsWLL88Wu18wHcq3ZkeQAzLOa+B9T9N9FLm8E9T5lR11t7QPIYHYcnsxwjqpBfDW8WciBktbJN2x8oMCoOOBIm52d7wCIGr9vixVH5a/cu3P3M9MON1rQgq6/i+aJsCba8YpJ/45KcHeFtr3PyHIDLX6sBfLtJXV7wrjnHgHqUE2ZKiYKIdsSIrcHf3fVVo4UUrRb/JSvIvCzgBLOd8mP+89+EsnLAxBFSj3Uj6mBnWsKXJc23vYFI2+uzqbUhJuDzkSfPd9zuJ0VFPV2tf438Xi37DSrNZBbUsv3OacZH2PwZfRgbaIcZNfJyC8jqKF7UC7UHTnNGsMsiNm90g== 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=jy3/PnBlKCLoGe2ac+z/3nKSFm8cz+n19wqlfOIaulw=; b=q7LkVMOSzCu+waenvQURiNTRbwzWYrSk6tAyPd5BXChil+Vpt+uChaur+0V7Dx93J7dXpU1vwaH/w30Q6kghd8Zqx4uwYpTmaRHkq8KEwz7qV5ekN+K0+K33UhGFEoi01liw0yVnJ02bIBbYxYC8dFSBeuqTR0RBH0xcub40O4A= 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 , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , "Volodymyr Babchuk" Subject: [PATCH v4 1/2] xen/arm: exclude xen,reg from direct-map domU extended regions Date: Mon, 9 Jun 2025 14:34:32 -0400 Message-ID: <20250609183438.178214-2-stewart.hildebrand@amd.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250609183438.178214-1-stewart.hildebrand@amd.com> References: <20250609183438.178214-1-stewart.hildebrand@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN1PEPF00006000:EE_|CYYPR12MB8990:EE_ X-MS-Office365-Filtering-Correlation-Id: df7a48ae-f14b-48e9-ff03-08dda7845207 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|36860700013|376014|82310400026; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?BEEOXhoRAhyj9OZ/YtV36p/PlgI/nSS42RhC8aMqnSN9DjzwM0XjvncrVOKV?= =?us-ascii?Q?4WhM3N9Nbl5JcjbH2Wl7lfzWF0tVPE8kgc1Ag1nbLmtCoqMBeLCUDCJUxO+d?= =?us-ascii?Q?lPe+c5zIztYUr9+5++ekVLbthsDEjFIxRX7LLger/tdVAspKlA5Alqa6ZAnx?= =?us-ascii?Q?eXcI4llv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?= =?us-ascii?Q?+7odKILSkN7PAb+Pdm3j8HsccMAvPW9/jlEdnh9TUwq4N0/RkjlsvoxA9vvK?= =?us-ascii?Q?xTIHx6ynZ5E/hgvZvzLlNPorUXUy/5jSa5ZDVyA7mMNDSVxFVvJihBsrpB+y?= =?us-ascii?Q?N69Q2tZ0erFjYZqjlqaznukWW9ORJLj83q1hwwoeEwbjj8SeOFE826hB6Kz/?= =?us-ascii?Q?14Ezn1RpFPMumWu4oJsS6CmwywC/Ih8rN95wxJEoVwsdoTW0dZXx3RpIBjWn?= =?us-ascii?Q?3MtYb6BDdpo/9P8ygG3g9a23N845RVp3cAqp81aUCWNCAp/kldu0P7e/g3K0?= =?us-ascii?Q?J4l64m0ci6xTkdJ5eV3u9v2uD+ur6qBdSK2NaVTpAJavRhTof0Hn7IOMHrEH?= =?us-ascii?Q?EauC9hSR3nA17xlqmsJHXS0WnVwsM0XpLUZm5ZUfXJyIJPp+m3nLYEAa1fWJ?= =?us-ascii?Q?ZvI7qgkBWBcGlzW53RVrJcIUjvmR7w78Re1q?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(36860700013)(376014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Jun 2025 18:34:50.9833 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: df7a48ae-f14b-48e9-ff03-08dda7845207 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: BN1PEPF00006000.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CYYPR12MB8990 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1749494122085116600 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 --- 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 | 77 +++++++++++++++++++++++++-- xen/common/device-tree/domain-build.c | 5 ++ 2 files changed, 77 insertions(+), 5 deletions(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 590f38e52053..6632191cf602 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,48 @@ 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 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) - 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 + 1; + 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 + ? ({ + unsigned int xen_reg_cnt =3D 0; + + rangeset_report_ranges(kinfo->xen_reg_assigned, 0, + PFN_DOWN((1ULL << p2m_ipa_bits) - 1), c= ount, + &xen_reg_cnt); + membanks_xzalloc(xen_reg_cnt, MEMORY); + }) + : NULL; =20 /* * Exclude the following regions: @@ -974,6 +1020,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 +1029,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 +1059,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