From nobody Fri Oct 31 23:25:25 2025 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; dkim=pass header.i=dpsmith@apertussolutions.com; 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=apertussolutions.com) ARC-Seal: i=2; a=rsa-sha256; t=1745101302; cv=pass; d=zohomail.com; s=zohoarc; b=BgPAngQxpcyI8SSu44gDjLRpiDng6UZjIemgfl8NxcwDIZbc7+OVR6Il+uivWr8nNn4JloM04l3fFypGD7GU0WnDPSnauhZy8cSWRfqCBY81eFB1is18Ppw1a5qb4sN96Z18NtJOzGCNsEZlJVQbgezimcRwZXyZJLYTxAGm6Cc= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745101302; h=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=2DObGwETdwh7JUH3NaImfvU+NN7DFUDrg2HJnLwWc6A=; b=HwydyggISvqwY0n3qT3mCoQIKnz2Q8cEAOHeK+QS4nyMwXExoy6VdouxQTHzEjSoJRhy+ScO4pTcCIdMrbETJtnnvSDS8aiwmdOkYlabEeE3fwNpMZTqJptWcKW3TTUEK7ZXahrGiC/JHE5wy5FbFW7Rf1Irwc5sfmg/wvZL3EU= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass header.i=dpsmith@apertussolutions.com; 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=apertussolutions.com) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1745101302632737.7105307086844; Sat, 19 Apr 2025 15:21:42 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.960257.1352355 (Exim 4.92) (envelope-from ) id 1u6GYw-0004v1-Tm; Sat, 19 Apr 2025 22:21:26 +0000 Received: by outflank-mailman (output) from mailman id 960257.1352355; Sat, 19 Apr 2025 22:21: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 1u6GYw-0004tw-Ib; Sat, 19 Apr 2025 22:21:26 +0000 Received: by outflank-mailman (input) for mailman id 960257; Sat, 19 Apr 2025 22:21:25 +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 1u6GP5-0004yY-0x for xen-devel@lists.xenproject.org; Sat, 19 Apr 2025 22:11:15 +0000 Received: from sender4-of-o50.zoho.com (sender4-of-o50.zoho.com [136.143.188.50]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 3368e8e3-1d6b-11f0-9eb0-5ba50f476ded; Sun, 20 Apr 2025 00:11:12 +0200 (CEST) Received: by mx.zohomail.com with SMTPS id 1745100535464486.0908090025065; Sat, 19 Apr 2025 15:08:55 -0700 (PDT) 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: 3368e8e3-1d6b-11f0-9eb0-5ba50f476ded ARC-Seal: i=1; a=rsa-sha256; t=1745100540; cv=none; d=zohomail.com; s=zohoarc; b=bCgIUk8XLrSRb2+emrpZXS/xMRZZzP/JIQEx1NDclO9uqk/xo1tzfOwUe5TWhyTHKmAUnTQxyNgwAnCptS/HRCwT6CVUODWnuJa8pIhv+1dRMx1Kd0N7jYeueGQWPMhOQHX/peSUAytuXsMQnIYK9ksVQxWCrW4G6nfgKuj+gwY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745100540; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=2DObGwETdwh7JUH3NaImfvU+NN7DFUDrg2HJnLwWc6A=; b=HAgOY8rb0aTpjt9jpcc8JTsXxQdP/tXtGgTf14h4A35Y1BD6tm0EP1lKs24DCbLIqL332Iazdt7b8V3ylm/MnhPfLg+1QK7kjNspHIISCIIzllaKSIIdY8aPcIxmRrJZc0B1FqBf7DQdyjmrOTmDPDiKWiD5Iby6gtbS0scO/KQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=apertussolutions.com; spf=pass smtp.mailfrom=dpsmith@apertussolutions.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1745100540; s=zoho; d=apertussolutions.com; i=dpsmith@apertussolutions.com; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-Id:Message-Id:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Reply-To; bh=2DObGwETdwh7JUH3NaImfvU+NN7DFUDrg2HJnLwWc6A=; b=j+nMrzDa8bS4dUdaFEuJ1m3fb5Ec2PI3xjnWjgqj98wZLn3l4uteUQanGDU1VSIM yvc6mqxYUxvOnpR+C3bad+Yh+Ut+XDE/AwFJUAY/2e7LPGY8ZsysxbKSsEnYrhPxu8C VCOHJC9PwyhX7FPPzoJNSlk4Reu9Cs88hBOyrqEo= From: "Daniel P. Smith" To: xen-devel@lists.xenproject.org Cc: "Daniel P. Smith" , jason.andryuk@amd.com, stefano.stabellini@amd.com, agarciav@amd.com, Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [RFC 19/38] x86/hyperlaunch: add domu memory map construction Date: Sat, 19 Apr 2025 18:08:01 -0400 Message-Id: <20250419220820.4234-20-dpsmith@apertussolutions.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20250419220820.4234-1-dpsmith@apertussolutions.com> References: <20250419220820.4234-1-dpsmith@apertussolutions.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External X-ZohoMail-DKIM: pass (identity dpsmith@apertussolutions.com) X-ZM-MESSAGEID: 1745101305485019100 Content-Type: text/plain; charset="utf-8" Introduce hvm_setup_e820() that will build the e820 memory map for a general domU. To populate the ACPI entry, ACPI table size helpers are introduced. A conditional is added to the domain builder to select between calling hvm_setup_e820() and dom0_pvh_setup_e820() depending on if it is building d= om0 or a domU. Signed-off-by: Daniel P. Smith --- xen/arch/x86/hvm/dom_build.c | 149 ++++++++++++++++++++++++++++++++++- 1 file changed, 148 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/hvm/dom_build.c b/xen/arch/x86/hvm/dom_build.c index 078e42447b0a..658d3d170e64 100644 --- a/xen/arch/x86/hvm/dom_build.c +++ b/xen/arch/x86/hvm/dom_build.c @@ -16,6 +16,7 @@ =20 #include =20 +#include #include =20 #include @@ -43,12 +44,158 @@ static void __hwdom_init pvh_setup_mmcfg(struct domain= *d) } } =20 +static unsigned long __init hvm_size_acpi_madt(struct domain *d) +{ + unsigned long size =3D sizeof(struct acpi_table_madt); + + size +=3D sizeof(struct acpi_madt_local_apic) * d->max_vcpus; + + return size; +} + +static unsigned long __init hvm_size_acpi_xsdt(struct domain *d) +{ + unsigned long size =3D sizeof(struct acpi_table_xsdt); + /* Only adding the MADT table to the XSDT. */ + unsigned int num_tables =3D 1; + + /* + * No need to add or subtract anything because struct acpi_table_xsdt + * includes one array slot already. + */ + size +=3D num_tables * sizeof(uint64_t); + + return size; +} + +static unsigned long __init hvm_size_acpi_region(struct domain *d) +{ + unsigned long size =3D sizeof(struct acpi_table_rsdp); + + size +=3D hvm_size_acpi_xsdt(d); + size +=3D hvm_size_acpi_madt(d); + + return ROUNDUP(size, PAGE_SIZE); +} + +/* From xenguest lib */ +#define END_SPECIAL_REGION 0xff000U +#define NR_SPECIAL_PAGES 8 +#define START_SPECIAL_REGION (END_SPECIAL_REGION - NR_SPECIAL_PAGES) + +#define SPECIALPAGE_PAGING 0 +#define SPECIALPAGE_ACCESS 1 +#define SPECIALPAGE_SHARING 2 +#define SPECIALPAGE_BUFIOREQ 3 +#define SPECIALPAGE_XENSTORE 4 +#define SPECIALPAGE_IOREQ 5 +#define SPECIALPAGE_IDENT_PT 6 +#define SPECIALPAGE_CONSOLE 7 +#define special_pfn(x) (START_SPECIAL_REGION + (x)) + +/* + * Allocation scheme, derived from xenlight/xenguest: + * + * | <4G MMIO Hole | + * [ Low Mem ][ RDM Mem ][ >1M Mem ][ ACPI ][ Special ][ High Mem ] + * + */ +static void __init hvm_setup_e820(struct domain *d, unsigned long nr_pages) +{ + const uint32_t lowmem_reserved_base =3D 0x9e000; + const uint32_t rdm_base =3D 0xa0000, rdm_size =3D 0x60; + unsigned long low_pages, ext_pages, mmio_pages, acpi_pages, high_pages= =3D 0; + unsigned long max_ext_pages =3D (HVM_BELOW_4G_MMIO_START - MB(1)) >> P= AGE_SHIFT, + page_count =3D 0; + unsigned nr =3D 0, e820_entries =3D 5; + + /* low pages: below 1MB */ + low_pages =3D lowmem_reserved_base >> PAGE_SHIFT; + if ( low_pages > nr_pages ) + panic("Insufficient memory for HVM/PVH domain (%pd)\n", d); + + acpi_pages =3D hvm_size_acpi_region(d) >> PAGE_SHIFT; + mmio_pages =3D acpi_pages + NR_SPECIAL_PAGES; + + /* ext pages: from 1MB to mmio hole */ + ext_pages =3D nr_pages - (low_pages + mmio_pages); + if ( ext_pages > max_ext_pages ) + ext_pages =3D max_ext_pages; + + /* high pages: above 4GB */ + if ( nr_pages > (low_pages + mmio_pages + ext_pages) ) + high_pages =3D nr_pages - (low_pages + mmio_pages + ext_pages); + + /* If we should have a highmem range, add one more e820 entry */ + if ( high_pages ) + e820_entries++; + + ASSERT(e820_entries < E820MAX); + + d->arch.e820 =3D xzalloc_array(struct e820entry, e820_entries); + if ( !d->arch.e820 ) + panic("Unable to allocate memory for boot domain e820 map\n"); + + /* usable: Low memory */ + d->arch.e820[nr].addr =3D 0x000000; + d->arch.e820[nr].size =3D low_pages << PAGE_SHIFT; + d->arch.e820[nr].type =3D E820_RAM; + page_count +=3D d->arch.e820[nr].size >> PAGE_SHIFT; + nr++; + + /* reserved: lowmem reserved device memory */ + d->arch.e820[nr].addr =3D rdm_base; + d->arch.e820[nr].size =3D rdm_size; + d->arch.e820[nr].type =3D E820_RESERVED; + nr++; + + /* usable: extended memory from 1MB */ + d->arch.e820[nr].addr =3D 0x100000; + d->arch.e820[nr].size =3D ext_pages << PAGE_SHIFT; + d->arch.e820[nr].type =3D E820_RAM; + page_count +=3D d->arch.e820[nr].size >> PAGE_SHIFT; + nr++; + + /* reserved: ACPI entry, ACPI_INFO_PHYSICAL_ADDRESS */ + d->arch.e820[nr].addr =3D 0xFC000000; + d->arch.e820[nr].size =3D acpi_pages << PAGE_SHIFT; + d->arch.e820[nr].type =3D E820_ACPI; + page_count +=3D d->arch.e820[nr].size >> PAGE_SHIFT; + nr++; + + /* reserved: HVM special pages, X86_HVM_END_SPECIAL_REGION */ + d->arch.e820[nr].addr =3D START_SPECIAL_REGION << PAGE_SHIFT; + d->arch.e820[nr].size =3D NR_SPECIAL_PAGES << PAGE_SHIFT; + d->arch.e820[nr].type =3D E820_RESERVED; + page_count +=3D d->arch.e820[nr].size >> PAGE_SHIFT; + nr++; + + /* usable: highmem */ + if ( high_pages ) + { + d->arch.e820[nr].addr =3D 0x100000000; + d->arch.e820[nr].size =3D high_pages << PAGE_SHIFT; + d->arch.e820[nr].type =3D E820_RAM; + page_count +=3D d->arch.e820[nr].size >> PAGE_SHIFT; + nr++; + } + + d->arch.nr_e820 =3D nr; + + ASSERT(nr =3D=3D e820_entries); + ASSERT(nr_pages =3D=3D page_count); +} + static void __init pvh_init_p2m(struct boot_domain *bd) { unsigned long nr_pages =3D dom_compute_nr_pages(bd, NULL); bool preempted; =20 - dom0_pvh_setup_e820(bd->d, nr_pages); + if ( bd->capabilities & (BUILD_CAPS_CONTROL | BUILD_CAPS_HARDWARE) ) + dom0_pvh_setup_e820(bd->d, nr_pages); + else + hvm_setup_e820(bd->d, nr_pages); + do { preempted =3D false; paging_set_allocation(bd->d, dom_paging_pages(bd, nr_pages), --=20 2.30.2