From nobody Thu Nov 21 21:08:58 2024 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=1730569017; cv=pass; d=zohomail.com; s=zohoarc; b=I9UnadDNFnEvprLBBgrbWDcgzGKn4ZHCpm/OAhvkP7pEYDmnl7X30RqBq0vnCZhgGyXDSVRwduNFo1ZeVw512upwOS0Hvu+yR7DBOBFas9qmwZlMMu/jhZkGcmum+bvPg4Yw6efga9/Gk5q6lQhwbMI4hHoCMXcL2Ca5k6qYvpk= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730569017; 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=BanyZbKdg0T0KbDMwIGAn8rkRguFwufoO5593eI1GXs=; b=I5P3yv9+pG5TR66Y+U8bpaE1BppT0MllgdbdfIhKbT3u0aRlD1RktwZ6JdHa1T2+QXZ7F6YN0P2O2kkgvdelOgGQr6RJHkiMKHi8daKRIl/6vMrw6BQrV+f5jYW+VERpZdE1cUXI6JxiXbCRYIVEc58LfczTdAt4yo4V5kPNmp4= 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 1730569017910725.7487245595546; Sat, 2 Nov 2024 10:36:57 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.829599.1244611 (Exim 4.92) (envelope-from ) id 1t7I31-0001CL-Io; Sat, 02 Nov 2024 17:36:27 +0000 Received: by outflank-mailman (output) from mailman id 829599.1244611; Sat, 02 Nov 2024 17:36:27 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t7I31-0001BQ-BR; Sat, 02 Nov 2024 17:36:27 +0000 Received: by outflank-mailman (input) for mailman id 829599; Sat, 02 Nov 2024 17:36:26 +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 1t7Hud-0004r4-H4 for xen-devel@lists.xenproject.org; Sat, 02 Nov 2024 17:27:47 +0000 Received: from sender4-of-o51.zoho.com (sender4-of-o51.zoho.com [136.143.188.51]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id c42a77d5-993f-11ef-99a3-01e77a169b0f; Sat, 02 Nov 2024 18:27:43 +0100 (CET) Received: by mx.zohomail.com with SMTPS id 1730568374182907.7832620165392; Sat, 2 Nov 2024 10:26:14 -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: c42a77d5-993f-11ef-99a3-01e77a169b0f X-Custom-Connection: eyJyZW1vdGVpcCI6IjEzNi4xNDMuMTg4LjUxIiwiaGVsbyI6InNlbmRlcjQtb2YtbzUxLnpvaG8uY29tIn0= X-Custom-Transaction: eyJpZCI6ImM0MmE3N2Q1LTk5M2YtMTFlZi05OWEzLTAxZTc3YTE2OWIwZiIsInRzIjoxNzMwNTY4NDY0LjA5MTg2Mywic2VuZGVyIjoiZHBzbWl0aEBhcGVydHVzc29sdXRpb25zLmNvbSIsInJlY2lwaWVudCI6Inhlbi1kZXZlbEBsaXN0cy54ZW5wcm9qZWN0Lm9yZyJ9 ARC-Seal: i=1; a=rsa-sha256; t=1730568384; cv=none; d=zohomail.com; s=zohoarc; b=EbK0LHLHm1J7bAzjzo7Yq0KlmM0opYOILP4NhGcy0cwwqFRBQK2+5R0mpXzZwwzGX3lURjW1Db4ASb43mRKQ6pXMkwpSXtbhgMBGfhw+zzoQ7h1LxGFq4Fiv6CI4Kc2/Q+Tc/XEH33WPwCTfMe0iA6wXIMdONmEMRs0KJBWgIYQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730568384; 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=BanyZbKdg0T0KbDMwIGAn8rkRguFwufoO5593eI1GXs=; b=BYsMCPPaXAqIEOSH+Bxy87ZozWFsiuQMSxCDdu4CXUOdQX5/rnIAwc0rCE6dVNsFZ36uNeFXH/oSGNhVp+lC2Gk/oDAsV+XWifK18dxvKOLDNEZd5B0ejsukrw1Mvj7e/2/KUDD26OoWjhRsunSNwLR0I1WV9ZlM31OIpAGtb1I= 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=1730568384; 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=BanyZbKdg0T0KbDMwIGAn8rkRguFwufoO5593eI1GXs=; b=Bnhb55YJbsmVlMOpcw5lXSIo/drVPSpd1rV5mCpptVvnBl7DgNo78EwSsIeF0wzx iafTEied21NF7aM85DFkp+diElAhHuGfV7begn+qlntOx9/Z4pSg9ZfEgnm2wKjZOpx baPbBCu8XJvp1m0OWRB+cN/bRJ2o9BZBpOUEA+Uk= From: "Daniel P. Smith" To: xen-devel@lists.xenproject.org Cc: "Daniel P. Smith" , jason.andryuk@amd.com, christopher.w.clark@gmail.com, stefano.stabellini@amd.com, Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [PATCH 10/12] x86/boot: introduce boot domain Date: Sat, 2 Nov 2024 13:25:49 -0400 Message-Id: <20241102172551.17233-11-dpsmith@apertussolutions.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20241102172551.17233-1-dpsmith@apertussolutions.com> References: <20241102172551.17233-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: 1730569019204116600 Content-Type: text/plain; charset="utf-8" To begin moving toward allowing the hypervisor to construct more than one domain at boot, a container is needed for a domain's build information. Introduce a new header, , that contains the initial struct boot_domain that encapsulate the build information for a domain. Add a kernel and ramdisk boot module reference along with a struct domain reference to the new struct boot_domain. This allows a struct boot_domain reference to be the only parameter necessary to pass down through the domain construction call chain. Signed-off-by: Daniel P. Smith Reviewed-by: Jason Andryuk --- Changes since v7 - collapsed the incremental changes to the call chain into this commit --- xen/arch/x86/dom0_build.c | 7 +++--- xen/arch/x86/hvm/dom0_build.c | 16 +++++--------- xen/arch/x86/include/asm/bootdomain.h | 31 +++++++++++++++++++++++++++ xen/arch/x86/include/asm/bootinfo.h | 5 +++++ xen/arch/x86/include/asm/dom0_build.h | 6 +++--- xen/arch/x86/include/asm/setup.h | 6 ++---- xen/arch/x86/pv/dom0_build.c | 24 +++++++-------------- xen/arch/x86/setup.c | 24 +++++++++------------ 8 files changed, 68 insertions(+), 51 deletions(-) create mode 100644 xen/arch/x86/include/asm/bootdomain.h diff --git a/xen/arch/x86/dom0_build.c b/xen/arch/x86/dom0_build.c index 2276965c02bd..2f71d01a03e2 100644 --- a/xen/arch/x86/dom0_build.c +++ b/xen/arch/x86/dom0_build.c @@ -597,9 +597,10 @@ int __init dom0_setup_permissions(struct domain *d) return rc; } =20 -int __init construct_dom0(struct boot_info *bi, struct domain *d) +int __init construct_dom0(struct boot_domain *bd) { int rc; + const struct domain *d =3D bd->d; =20 /* Sanity! */ BUG_ON(!pv_shim && d->domain_id !=3D 0); @@ -609,9 +610,9 @@ int __init construct_dom0(struct boot_info *bi, struct = domain *d) process_pending_softirqs(); =20 if ( is_hvm_domain(d) ) - rc =3D dom0_construct_pvh(bi, d); + rc =3D dom0_construct_pvh(bd); else if ( is_pv_domain(d) ) - rc =3D dom0_construct_pv(bi, d); + rc =3D dom0_construct_pv(bd); else panic("Cannot construct Dom0. No guest interface available\n"); =20 diff --git a/xen/arch/x86/hvm/dom0_build.c b/xen/arch/x86/hvm/dom0_build.c index e74684f10b12..5aacfeb21fcf 100644 --- a/xen/arch/x86/hvm/dom0_build.c +++ b/xen/arch/x86/hvm/dom0_build.c @@ -1302,25 +1302,19 @@ static void __hwdom_init pvh_setup_mmcfg(struct dom= ain *d) } } =20 -int __init dom0_construct_pvh(struct boot_info *bi, struct domain *d) +int __init dom0_construct_pvh(struct boot_domain *bd) { paddr_t entry, start_info; - struct boot_module *image; - struct boot_module *initrd =3D NULL; + struct boot_module *image =3D bd->kernel; + struct boot_module *initrd =3D bd->ramdisk; + struct domain *d =3D bd->d; int rc; =20 printk(XENLOG_INFO "*** Building a PVH Dom%d ***\n", d->domain_id); =20 - rc =3D first_boot_module_index(bi, BOOTMOD_KERNEL); - if ( unlikely(rc < 0 || rc > bi->nr_modules) ) + if ( unlikely(image =3D=3D NULL) ) panic("Missing kernel boot module for %pd construction\n", d); =20 - image =3D &bi->mods[rc]; - - rc =3D first_boot_module_index(bi, BOOTMOD_RAMDISK); - if ( rc > 0 || rc < bi->nr_modules ) - initrd =3D &bi->mods[rc]; - if ( is_hardware_domain(d) ) { /* diff --git a/xen/arch/x86/include/asm/bootdomain.h b/xen/arch/x86/include/a= sm/bootdomain.h new file mode 100644 index 000000000000..12c19ab37bd8 --- /dev/null +++ b/xen/arch/x86/include/asm/bootdomain.h @@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (c) 2024 Apertus Solutions, LLC + * Author: Daniel P. Smith + * Copyright (c) 2024 Christopher Clark + */ + +#ifndef __XEN_X86_BOOTDOMAIN_H__ +#define __XEN_X86_BOOTDOMAIN_H__ + +struct boot_module; +struct domain; + +struct boot_domain { + struct boot_module *kernel; + struct boot_module *ramdisk; + + struct domain *d; +}; + +#endif + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/arch/x86/include/asm/bootinfo.h b/xen/arch/x86/include/asm= /bootinfo.h index a5ee90a36607..7b793ca62f19 100644 --- a/xen/arch/x86/include/asm/bootinfo.h +++ b/xen/arch/x86/include/asm/bootinfo.h @@ -10,10 +10,14 @@ =20 #include #include +#include =20 /* Max number of boot modules a bootloader can provide in addition to Xen = */ #define MAX_NR_BOOTMODS 63 =20 +/* Max number of boot domains that Xen can construct */ +#define MAX_NR_BOOTDOMS 1 + /* Boot module binary type / purpose */ enum bootmod_type { BOOTMOD_UNKNOWN, @@ -77,6 +81,7 @@ struct boot_info { =20 unsigned int nr_modules; struct boot_module mods[MAX_NR_BOOTMODS + 1]; + struct boot_domain domains[MAX_NR_BOOTDOMS]; }; =20 /* diff --git a/xen/arch/x86/include/asm/dom0_build.h b/xen/arch/x86/include/a= sm/dom0_build.h index 4c2193c4a982..4a75fb25a801 100644 --- a/xen/arch/x86/include/asm/dom0_build.h +++ b/xen/arch/x86/include/asm/dom0_build.h @@ -13,10 +13,10 @@ unsigned long dom0_compute_nr_pages(struct domain *d, unsigned long initrd_len); int dom0_setup_permissions(struct domain *d); =20 -struct boot_info; -int dom0_construct_pv(struct boot_info *bi, struct domain *d); +struct boot_domain; +int dom0_construct_pv(struct boot_domain *bd); =20 -int dom0_construct_pvh(struct boot_info *bi, struct domain *d); +int dom0_construct_pvh(struct boot_domain *bd); =20 unsigned long dom0_paging_pages(const struct domain *d, unsigned long nr_pages); diff --git a/xen/arch/x86/include/asm/setup.h b/xen/arch/x86/include/asm/se= tup.h index 0591847c57e6..4968ac38398b 100644 --- a/xen/arch/x86/include/asm/setup.h +++ b/xen/arch/x86/include/asm/setup.h @@ -26,10 +26,8 @@ void subarch_init_memory(void); =20 void init_IRQ(void); =20 -struct boot_info; -int construct_dom0( - struct boot_info *bi, - struct domain *d); +struct boot_domain; +int construct_dom0(struct boot_domain *bd); void setup_io_bitmap(struct domain *d); =20 extern struct boot_info xen_boot_info; diff --git a/xen/arch/x86/pv/dom0_build.c b/xen/arch/x86/pv/dom0_build.c index 5efc650eeff0..28257bf13127 100644 --- a/xen/arch/x86/pv/dom0_build.c +++ b/xen/arch/x86/pv/dom0_build.c @@ -355,7 +355,7 @@ static struct page_info * __init alloc_chunk(struct dom= ain *d, return page; } =20 -static int __init dom0_construct(struct boot_info *bi, struct domain *d) +static int __init dom0_construct(struct boot_domain *bd) { int i, rc, order, machine; bool compatible, compat; @@ -370,13 +370,14 @@ static int __init dom0_construct(struct boot_info *bi= , struct domain *d) struct page_info *page =3D NULL; unsigned int flush_flags =3D 0; start_info_t *si; + struct domain *d =3D bd->d; struct vcpu *v =3D d->vcpu[0]; - struct boot_module *image; - struct boot_module *initrd =3D NULL; + struct boot_module *image =3D bd->kernel; + struct boot_module *initrd =3D bd->ramdisk; void *image_base; unsigned long image_len; void *image_start; - unsigned long initrd_len =3D 0; + unsigned long initrd_len =3D initrd ? initrd->size : 0; const char *cmdline; l4_pgentry_t *l4tab =3D NULL, *l4start =3D NULL; l3_pgentry_t *l3tab =3D NULL, *l3start =3D NULL; @@ -414,23 +415,14 @@ static int __init dom0_construct(struct boot_info *bi= , struct domain *d) =20 printk(XENLOG_INFO "*** Building a PV Dom%d ***\n", d->domain_id); =20 - i =3D first_boot_module_index(bi, BOOTMOD_KERNEL); - if ( unlikely(i < 0 || i > bi->nr_modules) ) + if ( unlikely(image =3D=3D NULL) ) panic("Missing kernel boot module for %pd construction\n", d); =20 - image =3D &bi->mods[i]; image_base =3D bootstrap_map_bm(image); image_len =3D image->size; image_start =3D image_base + image->headroom; cmdline =3D __va(image->cmdline_pa); =20 - i =3D first_boot_module_index(bi, BOOTMOD_RAMDISK); - if ( i > 0 || i < bi->nr_modules ) - { - initrd =3D &bi->mods[i]; - initrd_len =3D initrd->size; - } - d->max_pages =3D ~0U; =20 if ( (rc =3D bzimage_parse(image_base, &image_start, &image_len)) !=3D= 0 ) @@ -1066,7 +1058,7 @@ out: return rc; } =20 -int __init dom0_construct_pv(struct boot_info *bi, struct domain *d) +int __init dom0_construct_pv(struct boot_domain *bd) { unsigned long cr4 =3D read_cr4(); int rc; @@ -1084,7 +1076,7 @@ int __init dom0_construct_pv(struct boot_info *bi, st= ruct domain *d) write_cr4(cr4 & ~X86_CR4_SMAP); } =20 - rc =3D dom0_construct(bi, d); + rc =3D dom0_construct(bd); =20 if ( cr4 & X86_CR4_SMAP ) { diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 18b93d6a272a..6e25a9f726c7 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -990,16 +990,9 @@ static struct domain *__init create_dom0(struct boot_i= nfo *bi) .misc_flags =3D opt_dom0_msr_relaxed ? XEN_X86_MSR_RELAXED : 0, }, }; + struct boot_domain *bd =3D &bi->domains[0]; struct domain *d; domid_t domid; - struct boot_module *image; - unsigned int idx; - - idx =3D first_boot_module_index(bi, BOOTMOD_KERNEL); - if ( unlikely(idx < 0 || idx > bi->nr_modules) ) - panic("Missing kernel boot module for building Dom0\n"); - - image =3D &bi->mods[idx]; =20 if ( opt_dom0_pvh ) { @@ -1026,11 +1019,11 @@ static struct domain *__init create_dom0(struct boo= t_info *bi) panic("Error creating d%uv0\n", domid); =20 /* Grab the DOM0 command line. */ - if ( image->cmdline_pa || bi->kextra ) + if ( bd->kernel->cmdline_pa || bi->kextra ) { - if ( image->cmdline_pa ) - safe_strcpy( - cmdline, cmdline_cook(__va(image->cmdline_pa), bi->loader)= ); + if ( bd->kernel->cmdline_pa ) + safe_strcpy(cmdline, cmdline_cook(__va(bd->kernel->cmdline_pa), + bi->loader)); =20 if ( bi->kextra ) /* kextra always includes exactly one leading space. */ @@ -1052,10 +1045,11 @@ static struct domain *__init create_dom0(struct boo= t_info *bi) safe_strcat(cmdline, acpi_param); } =20 - image->cmdline_pa =3D __pa(cmdline); + bd->kernel->cmdline_pa =3D __pa(cmdline); } =20 - if ( construct_dom0(bi, d) !=3D 0 ) + bd->d =3D d; + if ( construct_dom0(bd) !=3D 0 ) panic("Could not construct domain 0\n"); =20 return d; @@ -1255,6 +1249,7 @@ void asmlinkage __init noreturn __start_xen(void) =20 /* Dom0 kernel is always first */ bi->mods[0].type =3D BOOTMOD_KERNEL; + bi->domains[0].kernel =3D &bi->mods[0]; =20 if ( pvh_boot ) { @@ -2125,6 +2120,7 @@ void asmlinkage __init noreturn __start_xen(void) if ( initrdidx < MAX_NR_BOOTMODS ) { bi->mods[initrdidx].type =3D BOOTMOD_RAMDISK; + bi->domains[0].ramdisk =3D &bi->mods[initrdidx]; if ( first_boot_module_index(bi, BOOTMOD_UNKNOWN) < MAX_NR_BOOTMOD= S ) printk(XENLOG_WARNING "Multiple initrd candidates, picking module #%u\n", --=20 2.30.2