From patchwork Fri Nov 15 13:11:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Daniel P. Smith" X-Patchwork-Id: 13876217 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9B746D6DDF8 for ; Fri, 15 Nov 2024 13:12:47 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.837561.1253485 (Exim 4.92) (envelope-from ) id 1tBw7n-0007Eh-0V; Fri, 15 Nov 2024 13:12:35 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 837561.1253485; Fri, 15 Nov 2024 13:12:34 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tBw7m-0007Ea-T8; Fri, 15 Nov 2024 13:12:34 +0000 Received: by outflank-mailman (input) for mailman id 837561; Fri, 15 Nov 2024 13:12:33 +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 1tBw7l-0006v7-NS for xen-devel@lists.xenproject.org; Fri, 15 Nov 2024 13:12:33 +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 4383f925-a353-11ef-99a3-01e77a169b0f; Fri, 15 Nov 2024 14:12:29 +0100 (CET) Received: by mx.zohomail.com with SMTPS id 1731676332910286.5289440972075; Fri, 15 Nov 2024 05:12:12 -0800 (PST) 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: 4383f925-a353-11ef-99a3-01e77a169b0f X-Custom-Connection: eyJyZW1vdGVpcCI6IjEzNi4xNDMuMTg4LjUxIiwiaGVsbyI6InNlbmRlcjQtb2YtbzUxLnpvaG8uY29tIn0= X-Custom-Transaction: eyJpZCI6IjQzODNmOTI1LWEzNTMtMTFlZi05OWEzLTAxZTc3YTE2OWIwZiIsInRzIjoxNzMxNjc2MzQ5Ljk3NjYyMSwic2VuZGVyIjoiZHBzbWl0aEBhcGVydHVzc29sdXRpb25zLmNvbSIsInJlY2lwaWVudCI6Inhlbi1kZXZlbEBsaXN0cy54ZW5wcm9qZWN0Lm9yZyJ9 ARC-Seal: i=1; a=rsa-sha256; t=1731676335; cv=none; d=zohomail.com; s=zohoarc; b=RyjrH5jZBLGfC2T3QFvh3yHy1fwVypbpkRsUzULSjDk63acIB7dEJL1xmn1vkw7NzgWooRbgDSbFgqr4f8uovAEG9sNC5v6CJmd0ZvKU/N94gFlDBgRKLMdFmBcB5/5OdYu/+LvzeGX2GYK5/GDd+MBcmScI2o/dTSWmiJMJNaU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1731676335; 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=VzSieBjkOBJnnpxsq7w+NmNX7HbgJy32WIO1NLNWBIo=; b=IgDPo+09caTali1H0gN+XUMRmEjbhQdiNs+upve7vJYIzkEOxr5a970t4RkHauY6fyhTpsaicSm3nwiI+Hs/Yu1aMNavU/xZg+COaI8dcV7NXZQ+O0d+zd+GIFu+/VuJ1SKLcUHGOW6YcafzHtEoURkHSQZ3OpL7BqDs2a4yCy8= 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=1731676335; 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=VzSieBjkOBJnnpxsq7w+NmNX7HbgJy32WIO1NLNWBIo=; b=BhRdaI//kbKABUP7pIEyZ3Hfcn8Y1yHAvbMDUZ++amLvxVi8pR0SwL7ns8+3c6Nl gSqdK0OaWHQwGH6ykjM4R9Ae6muF3aqGjzhBJOSlLqmxEo0dypvW9404SAv3SiaB24y u6MeS+szM+2CPuOwEYb5zdN61xFQy0zAlY3c9CHc= 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_Pau_Monn=C3=A9?= Subject: [PATCH v9 1/6] x86/boot: convert domain construction to use boot info Date: Fri, 15 Nov 2024 08:11:59 -0500 Message-Id: <20241115131204.32135-2-dpsmith@apertussolutions.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20241115131204.32135-1-dpsmith@apertussolutions.com> References: <20241115131204.32135-1-dpsmith@apertussolutions.com> MIME-Version: 1.0 X-ZohoMailClient: External With all the components used to construct dom0 encapsulated in struct boot_info and struct boot_module, it is no longer necessary to pass all them as parameters down the domain construction call chain. Change the parameter list to pass the struct boot_info instance and the struct domain reference. Signed-off-by: Daniel P. Smith Reviewed-by: Jason Andryuk --- Changes since v8: - moved forward in the series Changes since v7: - renamed from "x86/boot: convert create_dom0 to use boot info" Changes since v5: - change headroom back to unsigned long - make mod_idx unsigned int --- xen/arch/x86/dom0_build.c | 8 ++-- xen/arch/x86/hvm/dom0_build.c | 46 ++++++++++++-------- xen/arch/x86/include/asm/dom0_build.h | 12 ++---- xen/arch/x86/include/asm/setup.h | 8 ++-- xen/arch/x86/pv/dom0_build.c | 62 +++++++++++++++++---------- xen/arch/x86/setup.c | 33 ++++++++------ 6 files changed, 95 insertions(+), 74 deletions(-) diff --git a/xen/arch/x86/dom0_build.c b/xen/arch/x86/dom0_build.c index 72747b92475a..e8f5bf5447bc 100644 --- a/xen/arch/x86/dom0_build.c +++ b/xen/arch/x86/dom0_build.c @@ -596,9 +596,7 @@ int __init dom0_setup_permissions(struct domain *d) return rc; } -int __init construct_dom0(struct domain *d, const module_t *image, - unsigned long image_headroom, module_t *initrd, - const char *cmdline) +int __init construct_dom0(struct boot_info *bi, struct domain *d) { int rc; @@ -610,9 +608,9 @@ int __init construct_dom0(struct domain *d, const module_t *image, process_pending_softirqs(); if ( is_hvm_domain(d) ) - rc = dom0_construct_pvh(d, image, image_headroom, initrd, cmdline); + rc = dom0_construct_pvh(bi, d); else if ( is_pv_domain(d) ) - rc = dom0_construct_pv(d, image, image_headroom, initrd, cmdline); + rc = dom0_construct_pv(bi, d); else panic("Cannot construct Dom0. No guest interface available\n"); diff --git a/xen/arch/x86/hvm/dom0_build.c b/xen/arch/x86/hvm/dom0_build.c index 3dd913bdb029..d1bdf1b14601 100644 --- a/xen/arch/x86/hvm/dom0_build.c +++ b/xen/arch/x86/hvm/dom0_build.c @@ -16,6 +16,7 @@ #include +#include #include #include #include @@ -642,15 +643,15 @@ static bool __init check_and_adjust_load_address( return true; } -static int __init pvh_load_kernel(struct domain *d, const module_t *image, - unsigned long image_headroom, - module_t *initrd, void *image_base, - const char *cmdline, paddr_t *entry, - paddr_t *start_info_addr) +static int __init pvh_load_kernel( + struct domain *d, struct boot_module *image, struct boot_module *initrd, + paddr_t *entry, paddr_t *start_info_addr) { - void *image_start = image_base + image_headroom; - unsigned long image_len = image->mod_end; - unsigned long initrd_len = initrd ? initrd->mod_end : 0; + void *image_base = bootstrap_map_bm(image); + void *image_start = image_base + image->headroom; + unsigned long image_len = image->mod->mod_end; + unsigned long initrd_len = initrd ? initrd->mod->mod_end : 0; + const char *cmdline = __va(image->cmdline_pa); struct elf_binary elf; struct elf_dom_parms parms; paddr_t last_addr; @@ -725,8 +726,8 @@ static int __init pvh_load_kernel(struct domain *d, const module_t *image, if ( initrd != NULL ) { - rc = hvm_copy_to_guest_phys(last_addr, mfn_to_virt(initrd->mod_start), - initrd_len, v); + rc = hvm_copy_to_guest_phys( + last_addr, mfn_to_virt(initrd->mod->mod_start), initrd_len, v); if ( rc ) { printk("Unable to copy initrd to guest\n"); @@ -736,9 +737,9 @@ static int __init pvh_load_kernel(struct domain *d, const module_t *image, mod.paddr = last_addr; mod.size = initrd_len; last_addr += ROUNDUP(initrd_len, elf_64bit(&elf) ? 8 : 4); - if ( initrd->string ) + if ( initrd->cmdline_pa ) { - char *str = __va(initrd->string); + char *str = __va(initrd->cmdline_pa); size_t len = strlen(str) + 1; rc = hvm_copy_to_guest_phys(last_addr, str, len, v); @@ -1300,16 +1301,26 @@ static void __hwdom_init pvh_setup_mmcfg(struct domain *d) } } -int __init dom0_construct_pvh(struct domain *d, const module_t *image, - unsigned long image_headroom, - module_t *initrd, - const char *cmdline) +int __init dom0_construct_pvh(struct boot_info *bi, struct domain *d) { paddr_t entry, start_info; + struct boot_module *image; + struct boot_module *initrd = NULL; + unsigned int idx; int rc; printk(XENLOG_INFO "*** Building a PVH Dom%d ***\n", d->domain_id); + idx = first_boot_module_index(bi, BOOTMOD_KERNEL); + if ( idx >= bi->nr_modules ) + panic("Missing kernel boot module for %pd construction\n", d); + + image = &bi->mods[idx]; + + idx = first_boot_module_index(bi, BOOTMOD_RAMDISK); + if ( idx < bi->nr_modules ) + initrd = &bi->mods[idx]; + if ( is_hardware_domain(d) ) { /* @@ -1347,8 +1358,7 @@ int __init dom0_construct_pvh(struct domain *d, const module_t *image, return rc; } - rc = pvh_load_kernel(d, image, image_headroom, initrd, bootstrap_map(image), - cmdline, &entry, &start_info); + rc = pvh_load_kernel(d, image, initrd, &entry, &start_info); if ( rc ) { printk("Failed to load Dom0 kernel\n"); diff --git a/xen/arch/x86/include/asm/dom0_build.h b/xen/arch/x86/include/asm/dom0_build.h index 107c1ff98367..2d67b17213dc 100644 --- a/xen/arch/x86/include/asm/dom0_build.h +++ b/xen/arch/x86/include/asm/dom0_build.h @@ -13,15 +13,9 @@ unsigned long dom0_compute_nr_pages(struct domain *d, unsigned long initrd_len); int dom0_setup_permissions(struct domain *d); -int dom0_construct_pv(struct domain *d, const module_t *image, - unsigned long image_headroom, - module_t *initrd, - const char *cmdline); - -int dom0_construct_pvh(struct domain *d, const module_t *image, - unsigned long image_headroom, - module_t *initrd, - const char *cmdline); +struct boot_info; +int dom0_construct_pv(struct boot_info *bi, struct domain *d); +int dom0_construct_pvh(struct boot_info *bi, struct domain *d); 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/setup.h index 25c15ef9140d..8a415087e9a4 100644 --- a/xen/arch/x86/include/asm/setup.h +++ b/xen/arch/x86/include/asm/setup.h @@ -26,11 +26,9 @@ void subarch_init_memory(void); void init_IRQ(void); -int construct_dom0( - struct domain *d, - const module_t *image, unsigned long image_headroom, - module_t *initrd, - const char *cmdline); +struct boot_info; +int construct_dom0(struct boot_info *bi, struct domain *d); + void setup_io_bitmap(struct domain *d); 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 cc882bee61c3..6be3d7745fab 100644 --- a/xen/arch/x86/pv/dom0_build.c +++ b/xen/arch/x86/pv/dom0_build.c @@ -14,6 +14,7 @@ #include #include +#include #include #include #include @@ -354,13 +355,10 @@ static struct page_info * __init alloc_chunk(struct domain *d, return page; } -static int __init dom0_construct(struct domain *d, - const module_t *image, - unsigned long image_headroom, - module_t *initrd, - const char *cmdline) +static int __init dom0_construct(struct boot_info *bi, struct domain *d) { - int i, rc, order, machine; + unsigned int i; + int rc, order, machine; bool compatible, compat; struct cpu_user_regs *regs; unsigned long pfn, mfn; @@ -374,10 +372,13 @@ static int __init dom0_construct(struct domain *d, unsigned int flush_flags = 0; start_info_t *si; struct vcpu *v = d->vcpu[0]; - void *image_base = bootstrap_map(image); - unsigned long image_len = image->mod_end; - void *image_start = image_base + image_headroom; - unsigned long initrd_len = initrd ? initrd->mod_end : 0; + struct boot_module *image; + struct boot_module *initrd = NULL; + void *image_base; + unsigned long image_len; + void *image_start; + unsigned long initrd_len = 0; + const char *cmdline; l4_pgentry_t *l4tab = NULL, *l4start = NULL; l3_pgentry_t *l3tab = NULL, *l3start = NULL; l2_pgentry_t *l2tab = NULL, *l2start = NULL; @@ -414,6 +415,23 @@ static int __init dom0_construct(struct domain *d, printk(XENLOG_INFO "*** Building a PV Dom%d ***\n", d->domain_id); + i = first_boot_module_index(bi, BOOTMOD_KERNEL); + if ( i >= bi->nr_modules ) + panic("Missing kernel boot module for %pd construction\n", d); + + image = &bi->mods[i]; + image_base = bootstrap_map_bm(image); + image_len = image->mod->mod_end; + image_start = image_base + image->headroom; + cmdline = __va(image->cmdline_pa); + + i = first_boot_module_index(bi, BOOTMOD_RAMDISK); + if ( i < bi->nr_modules ) + { + initrd = &bi->mods[i]; + initrd_len = initrd->mod->mod_end; + } + d->max_pages = ~0U; if ( (rc = bzimage_parse(image_base, &image_start, &image_len)) != 0 ) @@ -613,7 +631,8 @@ static int __init dom0_construct(struct domain *d, initrd_pfn = vinitrd_start ? (vinitrd_start - v_start) >> PAGE_SHIFT : domain_tot_pages(d); - initrd_mfn = mfn = initrd->mod_start; + initrd_mfn = initrd->mod->mod_start; + mfn = initrd_mfn; count = PFN_UP(initrd_len); if ( d->arch.physaddr_bitsize && ((mfn + count - 1) >> (d->arch.physaddr_bitsize - PAGE_SHIFT)) ) @@ -628,12 +647,13 @@ static int __init dom0_construct(struct domain *d, free_domheap_pages(page, order); page += 1UL << order; } - memcpy(page_to_virt(page), mfn_to_virt(initrd->mod_start), + memcpy(page_to_virt(page), mfn_to_virt(initrd->mod->mod_start), initrd_len); - mpt_alloc = (paddr_t)initrd->mod_start << PAGE_SHIFT; + mpt_alloc = pfn_to_paddr(initrd->mod->mod_start); init_domheap_pages(mpt_alloc, mpt_alloc + PAGE_ALIGN(initrd_len)); - initrd->mod_start = initrd_mfn = mfn_x(page_to_mfn(page)); + initrd_mfn = mfn_x(page_to_mfn(page)); + initrd->mod->mod_start = initrd_mfn; } else { @@ -650,7 +670,7 @@ static int __init dom0_construct(struct domain *d, * Either way, tell discard_initial_images() to not free it a second * time. */ - initrd->mod_end = 0; + initrd->mod->mod_end = 0; iommu_memory_setup(d, "initrd", mfn_to_page(_mfn(initrd_mfn)), PFN_UP(initrd_len), &flush_flags); @@ -664,7 +684,7 @@ static int __init dom0_construct(struct domain *d, nr_pages - domain_tot_pages(d)); if ( initrd ) { - mpt_alloc = (paddr_t)initrd->mod_start << PAGE_SHIFT; + mpt_alloc = pfn_to_paddr(initrd->mod->mod_start); printk("\n Init. ramdisk: %"PRIpaddr"->%"PRIpaddr, mpt_alloc, mpt_alloc + initrd_len); } @@ -892,7 +912,7 @@ static int __init dom0_construct(struct domain *d, if ( pfn >= initrd_pfn ) { if ( pfn < initrd_pfn + PFN_UP(initrd_len) ) - mfn = initrd->mod_start + (pfn - initrd_pfn); + mfn = initrd->mod->mod_start + (pfn - initrd_pfn); else mfn -= PFN_UP(initrd_len); } @@ -1060,11 +1080,7 @@ out: return rc; } -int __init dom0_construct_pv(struct domain *d, - const module_t *image, - unsigned long image_headroom, - module_t *initrd, - const char *cmdline) +int __init dom0_construct_pv(struct boot_info *bi, struct domain *d) { unsigned long cr4 = read_cr4(); int rc; @@ -1082,7 +1098,7 @@ int __init dom0_construct_pv(struct domain *d, write_cr4(cr4 & ~X86_CR4_SMAP); } - rc = dom0_construct(d, image, image_headroom, initrd, cmdline); + rc = dom0_construct(bi, d); if ( cr4 & X86_CR4_SMAP ) { diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 4feef9f2e05a..495e90a7e132 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -950,10 +950,7 @@ static unsigned int __init copy_bios_e820(struct e820entry *map, unsigned int li return n; } -static struct domain *__init create_dom0(const module_t *image, - unsigned long headroom, - module_t *initrd, const char *kextra, - const char *loader) +static struct domain *__init create_dom0(struct boot_info *bi) { static char __initdata cmdline[MAX_GUEST_CMDLINE]; @@ -970,6 +967,14 @@ static struct domain *__init create_dom0(const module_t *image, }; struct domain *d; domid_t domid; + struct boot_module *image; + unsigned int idx; + + idx = first_boot_module_index(bi, BOOTMOD_KERNEL); + if ( idx >= bi->nr_modules ) + panic("Missing kernel boot module for building domain\n"); + + image = &bi->mods[idx]; if ( opt_dom0_pvh ) { @@ -996,14 +1001,15 @@ static struct domain *__init create_dom0(const module_t *image, panic("Error creating d%uv0\n", domid); /* Grab the DOM0 command line. */ - if ( image->string || kextra ) + if ( image->cmdline_pa || bi->kextra ) { - if ( image->string ) - safe_strcpy(cmdline, cmdline_cook(__va(image->string), loader)); + if ( image->cmdline_pa ) + safe_strcpy( + cmdline, cmdline_cook(__va(image->cmdline_pa), bi->loader)); - if ( kextra ) + if ( bi->kextra ) /* kextra always includes exactly one leading space. */ - safe_strcat(cmdline, kextra); + safe_strcat(cmdline, bi->kextra); /* Append any extra parameters. */ if ( skip_ioapic_setup && !strstr(cmdline, "noapic") ) @@ -1020,9 +1026,11 @@ static struct domain *__init create_dom0(const module_t *image, safe_strcat(cmdline, " acpi="); safe_strcat(cmdline, acpi_param); } + + image->cmdline_pa = __pa(cmdline); } - if ( construct_dom0(d, image, headroom, initrd, cmdline) != 0 ) + if ( construct_dom0(bi, d) != 0 ) panic("Could not construct domain 0\n"); return d; @@ -2114,10 +2122,7 @@ void asmlinkage __init noreturn __start_xen(void) * We're going to setup domain0 using the module(s) that we stashed safely * above our heap. The second module, if present, is an initrd ramdisk. */ - dom0 = create_dom0(bi->mods[0].mod, bi->mods[0].headroom, - initrdidx < bi->nr_modules ? bi->mods[initrdidx].mod - : NULL, - bi->kextra, bi->loader); + dom0 = create_dom0(bi); if ( !dom0 ) panic("Could not set up DOM0 guest OS\n"); From patchwork Fri Nov 15 13:12:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Daniel P. Smith" X-Patchwork-Id: 13876218 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 635B6D6DDD8 for ; Fri, 15 Nov 2024 13:12:58 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.837562.1253496 (Exim 4.92) (envelope-from ) id 1tBw7x-0007fz-8e; Fri, 15 Nov 2024 13:12:45 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 837562.1253496; Fri, 15 Nov 2024 13:12:45 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tBw7x-0007fq-3a; Fri, 15 Nov 2024 13:12:45 +0000 Received: by outflank-mailman (input) for mailman id 837562; Fri, 15 Nov 2024 13:12:43 +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 1tBw7v-0006v7-KE for xen-devel@lists.xenproject.org; Fri, 15 Nov 2024 13:12:43 +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 499c6c43-a353-11ef-99a3-01e77a169b0f; Fri, 15 Nov 2024 14:12:40 +0100 (CET) Received: by mx.zohomail.com with SMTPS id 1731676334302852.445542045448; Fri, 15 Nov 2024 05:12:14 -0800 (PST) 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: 499c6c43-a353-11ef-99a3-01e77a169b0f X-Custom-Connection: eyJyZW1vdGVpcCI6IjEzNi4xNDMuMTg4LjUxIiwiaGVsbyI6InNlbmRlcjQtb2YtbzUxLnpvaG8uY29tIn0= X-Custom-Transaction: eyJpZCI6IjQ5OWM2YzQzLWEzNTMtMTFlZi05OWEzLTAxZTc3YTE2OWIwZiIsInRzIjoxNzMxNjc2MzYwLjIwMjQ0OSwic2VuZGVyIjoiZHBzbWl0aEBhcGVydHVzc29sdXRpb25zLmNvbSIsInJlY2lwaWVudCI6Inhlbi1kZXZlbEBsaXN0cy54ZW5wcm9qZWN0Lm9yZyJ9 ARC-Seal: i=1; a=rsa-sha256; t=1731676336; cv=none; d=zohomail.com; s=zohoarc; b=Qhc6IKuwaOSg2pIRjpS1E1UmTqSVt/2essstn4HTMbfY9y0KISmZYfvHpL+SLdc76ox3+cG5LWbf4Qmy6i5xFOB2FGeGjxLHb9EVrFmW230ZIgWaYjIvq/DE9XHkzKCfJuwKMjV6AQ4jnavJvhKK234OmCAQHqphma6mdTT13fI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1731676336; 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=45XOFNojx3tCAZbzmL3SALvSEtU+6rTfX9Oyt2Zgwf4=; b=eG2GZPXJeBkITiNIToeUknDBlEI6G0LdtdR0uOso2puOzFtqjX4ERY0DGwvE3MNE9CAjJaD/RVO6p1uL3GwlWg7MXvuCbegLzElmAxoJGZ1cz/v3WZXo3BNS92rlSCrSzqup5YVzPMtEnt2iGgg2CyHoqFSIC+q69Us5vRUEklY= 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=1731676336; 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=45XOFNojx3tCAZbzmL3SALvSEtU+6rTfX9Oyt2Zgwf4=; b=PARDKyLBPsDDZZcOje/5GaOPZRI4ytZMeaIfQCktIYcO4hVfotNVUJvk3GZEEZjk KxLQQx8adxGymV7bY4Y6zXFvPjchLcYFuSLyBx3tAVY9Qn4Sg9b/9JVZ9EUOaMuNP1E BChVZEUp+VEM9Re9AIobHIojMMzEGoW9CMy1TKOc= 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_Pau_Monn=C3=A9?= Subject: [PATCH v9 2/6] x86/boot: introduce module release Date: Fri, 15 Nov 2024 08:12:00 -0500 Message-Id: <20241115131204.32135-3-dpsmith@apertussolutions.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20241115131204.32135-1-dpsmith@apertussolutions.com> References: <20241115131204.32135-1-dpsmith@apertussolutions.com> MIME-Version: 1.0 X-ZohoMailClient: External A precarious approach was used to release the pages used to hold a boot module. The precariousness stemmed from the fact that in the case of PV dom0, the initrd module pages may be either mapped or copied into the dom0 address space. In the former case, the PV dom0 construction code will set the size of the module to zero, relying on discard_initial_images() to skip any modules with a size of zero. In the latter case, the pages are freed by the PV dom0 construction code. This freeing of pages is done so that in either case, the initrd variable can be reused for tracking the initrd location in dom0 memory through the remaining dom0 construction code. To encapsulate the logical action of releasing a boot module, the function release_boot_module() is introduced along with the `released` flag added to boot module. The boot module flag `released` allows the tracking of when a boot module has been released by release_boot_module(). As part of adopting release_boot_module() the function discard_initial_images() is renamed to free_boot_modules(), a name that better reflects the functions actions. Signed-off-by: Daniel P. Smith --- Changes since v8: - completely reworked the commit - switch backed to a releasing all but pv initrd approach - renamed discard_initial_images to free_boot_modules --- xen/arch/x86/hvm/dom0_build.c | 2 +- xen/arch/x86/include/asm/bootinfo.h | 2 ++ xen/arch/x86/include/asm/setup.h | 4 +++- xen/arch/x86/pv/dom0_build.c | 27 +++++++++++++-------------- xen/arch/x86/setup.c | 27 +++++++++++++++------------ 5 files changed, 34 insertions(+), 28 deletions(-) diff --git a/xen/arch/x86/hvm/dom0_build.c b/xen/arch/x86/hvm/dom0_build.c index d1bdf1b14601..d1410e1a02b0 100644 --- a/xen/arch/x86/hvm/dom0_build.c +++ b/xen/arch/x86/hvm/dom0_build.c @@ -755,7 +755,7 @@ static int __init pvh_load_kernel( } /* Free temporary buffers. */ - discard_initial_images(); + free_boot_modules(); if ( cmdline != NULL ) { diff --git a/xen/arch/x86/include/asm/bootinfo.h b/xen/arch/x86/include/asm/bootinfo.h index b9c94b370d57..f76876386763 100644 --- a/xen/arch/x86/include/asm/bootinfo.h +++ b/xen/arch/x86/include/asm/bootinfo.h @@ -34,8 +34,10 @@ struct boot_module { /* * Module State Flags: * relocated: indicates module has been relocated in memory. + * released: indicates module's pages have been freed. */ bool relocated:1; + bool released:1; /* * A boot module may need decompressing by Xen. Headroom is an estimate of diff --git a/xen/arch/x86/include/asm/setup.h b/xen/arch/x86/include/asm/setup.h index 8a415087e9a4..4ad493637892 100644 --- a/xen/arch/x86/include/asm/setup.h +++ b/xen/arch/x86/include/asm/setup.h @@ -34,13 +34,15 @@ void setup_io_bitmap(struct domain *d); extern struct boot_info xen_boot_info; unsigned long initial_images_nrpages(nodeid_t node); -void discard_initial_images(void); +void free_boot_modules(void); struct boot_module; void *bootstrap_map_bm(const struct boot_module *bm); void *bootstrap_map(const module_t *mod); void bootstrap_unmap(void); +void release_boot_module(struct boot_module *bm); + struct rangeset; int remove_xen_ranges(struct rangeset *r); diff --git a/xen/arch/x86/pv/dom0_build.c b/xen/arch/x86/pv/dom0_build.c index 6be3d7745fab..2580162f3df4 100644 --- a/xen/arch/x86/pv/dom0_build.c +++ b/xen/arch/x86/pv/dom0_build.c @@ -649,9 +649,12 @@ static int __init dom0_construct(struct boot_info *bi, struct domain *d) } memcpy(page_to_virt(page), mfn_to_virt(initrd->mod->mod_start), initrd_len); - mpt_alloc = pfn_to_paddr(initrd->mod->mod_start); - init_domheap_pages(mpt_alloc, - mpt_alloc + PAGE_ALIGN(initrd_len)); + /* + * The initrd was copied but the initrd variable is reused in the + * calculations below. As to not leak the memory used for the + * module free at this time. + */ + release_boot_module(initrd); initrd_mfn = mfn_x(page_to_mfn(page)); initrd->mod->mod_start = initrd_mfn; } @@ -660,18 +663,14 @@ static int __init dom0_construct(struct boot_info *bi, struct domain *d) while ( count-- ) if ( assign_pages(mfn_to_page(_mfn(mfn++)), 1, d, 0) ) BUG(); + /* + * We have mapped the initrd directly into dom0, and assigned the + * pages. Tell the boot_module handling that we've freed it, so the + * memory is left alone. + */ + initrd->released = true; } - /* - * We have either: - * - Mapped the initrd directly into dom0, or - * - Copied it and freed the module. - * - * Either way, tell discard_initial_images() to not free it a second - * time. - */ - initrd->mod->mod_end = 0; - iommu_memory_setup(d, "initrd", mfn_to_page(_mfn(initrd_mfn)), PFN_UP(initrd_len), &flush_flags); } @@ -875,7 +874,7 @@ static int __init dom0_construct(struct boot_info *bi, struct domain *d) } /* Free temporary buffers. */ - discard_initial_images(); + free_boot_modules(); /* Set up start info area. */ si = (start_info_t *)vstartinfo_start; diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 495e90a7e132..0bda1326a485 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -346,27 +346,30 @@ unsigned long __init initial_images_nrpages(nodeid_t node) return nr; } -void __init discard_initial_images(void) /* a.k.a. Free boot modules */ +void __init release_boot_module(struct boot_module *bm) +{ + uint64_t start = pfn_to_paddr(bm->mod->mod_start); + uint64_t size = bm->mod->mod_end; + + ASSERT(!bm->released); + + init_domheap_pages(start, start + PAGE_ALIGN(size)); + + bm->released = true; +} + +void __init free_boot_modules(void) { struct boot_info *bi = &xen_boot_info; unsigned int i; for ( i = 0; i < bi->nr_modules; ++i ) { - uint64_t start = pfn_to_paddr(bi->mods[i].mod->mod_start); - uint64_t size = bi->mods[i].mod->mod_end; - - /* - * Sometimes the initrd is mapped, rather than copied, into dom0. - * Size being 0 is how we're instructed to leave the module alone. - */ - if ( size == 0 ) + if ( bi->mods[i].released ) continue; - init_domheap_pages(start, start + PAGE_ALIGN(size)); + release_boot_module(&bi->mods[i]); } - - bi->nr_modules = 0; } static void __init init_idle_domain(void) From patchwork Fri Nov 15 13:12:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Daniel P. Smith" X-Patchwork-Id: 13876219 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 16412D6DDD8 for ; Fri, 15 Nov 2024 13:13:09 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.837570.1253505 (Exim 4.92) (envelope-from ) id 1tBw89-0008EK-Iq; Fri, 15 Nov 2024 13:12:57 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 837570.1253505; Fri, 15 Nov 2024 13:12:57 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tBw89-0008ED-G8; Fri, 15 Nov 2024 13:12:57 +0000 Received: by outflank-mailman (input) for mailman id 837570; Fri, 15 Nov 2024 13:12:55 +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 1tBw87-0006v7-CX for xen-devel@lists.xenproject.org; Fri, 15 Nov 2024 13:12:55 +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 5044f3bd-a353-11ef-99a3-01e77a169b0f; Fri, 15 Nov 2024 14:12:51 +0100 (CET) Received: by mx.zohomail.com with SMTPS id 1731676335598530.5770613675592; Fri, 15 Nov 2024 05:12:15 -0800 (PST) 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: 5044f3bd-a353-11ef-99a3-01e77a169b0f X-Custom-Connection: eyJyZW1vdGVpcCI6IjEzNi4xNDMuMTg4LjUxIiwiaGVsbyI6InNlbmRlcjQtb2YtbzUxLnpvaG8uY29tIn0= X-Custom-Transaction: eyJpZCI6IjUwNDRmM2JkLWEzNTMtMTFlZi05OWEzLTAxZTc3YTE2OWIwZiIsInRzIjoxNzMxNjc2MzcxLjM4NzQyOCwic2VuZGVyIjoiZHBzbWl0aEBhcGVydHVzc29sdXRpb25zLmNvbSIsInJlY2lwaWVudCI6Inhlbi1kZXZlbEBsaXN0cy54ZW5wcm9qZWN0Lm9yZyJ9 ARC-Seal: i=1; a=rsa-sha256; t=1731676337; cv=none; d=zohomail.com; s=zohoarc; b=YK4fThjfWMkx7UnS7pUTpgrBac5kNQwQjNGa2TF1XEjZ+nApX7OYRt9eiesEiMLHj5N83yJe4uQ4RoK0bAJpWe3i+UGTcqv9zU8bimccWgI2dyeI3Ls1HfN9+njWiZLfseMMdxl0723KgonHV7yXnjZe+o0UVZ1uQPHuMIc+9ng= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1731676337; 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=lC7UJWnbMWc4RpQfKr8UGN6FjxqhttPxoGHw6Bmoiok=; b=fb0a3fpq/S9A5mkGf0IbAbisZfTPWEy692iO8T2NV9tHSU/lciibLl7AwZD5rGoMrNtqZB1glAB3cdeexdMiJAuoP5wznGERktEp17pAJhx2Z8jQZI/uLN22CQELXbkxKgmCH1YHUXToGRtyQ/HIh+yJjPM1FRSEWWNxoeW8a70= 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=1731676337; 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=lC7UJWnbMWc4RpQfKr8UGN6FjxqhttPxoGHw6Bmoiok=; b=QMX62pqmtCSqfZm7BiRT9rNSaXG2tKNRwRpTrdPGbcImjUnl6bhWYfs/tDayC4la yjrMYxDTg5JRvnh8r7GRZfaNO+WM4rSg5ltmb2KkUiflVVxCe9I/D02wzeUNMR2XiZF Cjqv2wVFpU9dVHokHRk4IF4PkhkMGu4sSH2hk2ek= 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_Pau_Monn=C3=A9?= Subject: [PATCH v9 3/6] x86/boot: add start and size fields to struct boot_module Date: Fri, 15 Nov 2024 08:12:01 -0500 Message-Id: <20241115131204.32135-4-dpsmith@apertussolutions.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20241115131204.32135-1-dpsmith@apertussolutions.com> References: <20241115131204.32135-1-dpsmith@apertussolutions.com> MIME-Version: 1.0 X-ZohoMailClient: External Introduce the start and size fields to struct boot_module and assigns their value during boot_info construction. All uses of module_t to get the address and size of a module are replaced with start and size. The EFI entry point is a special case, as the EFI file loading boot service may load a file beyond the 4G barrier. As a result, to make the address fit in the 32bit integer used by the MB1 module_t structure, the frame number is stored in mod_start and size in mod_end. Until the EFI entry point is enlightened to work with boot_info and boot_module, multiboot_fill_boot_info will handle the alternate values in mod_start and mod_end when EFI is detected. A result of the switch to start/size removes all uses of the mod field in struct boot_modules, along with the uses of bootstra_map() and release_module() functions. With all usage gone, they all are dropped here. Signed-off-by: Daniel P. Smith Reviewed-by: Jason Andryuk --- Changes since v8: - reversed logic for efi case in multiboot_fill_bootinfo() - corrected missed paddr_to_pfn() Changes since v7: - add the start/size change to bootstrap_map_bm() - convert all BM start/size when introduced, consolidates: x86/boot: populate boot module for xen entry x86/boot: transition relocation calculations to struct boot_module - consolidates all the removal commits Changes since v6: - put the efi conversion for mod_start and mod_end back along with check - dropped unnecessary cast - updated the population of start and size fields to take into account efi Changes since v5: - switched EFI population of mod_start/mod_end to addresses --- xen/arch/x86/cpu/microcode/core.c | 8 +-- xen/arch/x86/hvm/dom0_build.c | 6 +- xen/arch/x86/include/asm/bootinfo.h | 6 +- xen/arch/x86/include/asm/setup.h | 1 - xen/arch/x86/pv/dom0_build.c | 15 +++-- xen/arch/x86/setup.c | 89 ++++++++++++++--------------- xen/xsm/xsm_policy.c | 2 +- 7 files changed, 60 insertions(+), 67 deletions(-) diff --git a/xen/arch/x86/cpu/microcode/core.c b/xen/arch/x86/cpu/microcode/core.c index fd4b08b45388..1176d5fbd502 100644 --- a/xen/arch/x86/cpu/microcode/core.c +++ b/xen/arch/x86/cpu/microcode/core.c @@ -709,8 +709,8 @@ static int __init cf_check microcode_init_cache(void) /* early_microcode_load() didn't leave us any work to do. */ return 0; - size = bi->mods[early_mod_idx].mod->mod_end; - data = __mfn_to_virt(bi->mods[early_mod_idx].mod->mod_start); + size = bi->mods[early_mod_idx].size; + data = __va(bi->mods[early_mod_idx].start); /* * If opt_scan is set, we're looking for a CPIO archive rather than a raw @@ -786,7 +786,7 @@ static int __init early_microcode_load(struct boot_info *bi) bm->type != BOOTMOD_RAMDISK ) continue; - size = bm->mod->mod_end; + size = bm->size; data = bootstrap_map_bm(bm); if ( !data ) { @@ -840,7 +840,7 @@ static int __init early_microcode_load(struct boot_info *bi) } bi->mods[idx].type = BOOTMOD_MICROCODE; - size = bi->mods[idx].mod->mod_end; + size = bi->mods[idx].size; data = bootstrap_map_bm(&bi->mods[idx]); if ( !data ) { diff --git a/xen/arch/x86/hvm/dom0_build.c b/xen/arch/x86/hvm/dom0_build.c index d1410e1a02b0..0bd1e4277bff 100644 --- a/xen/arch/x86/hvm/dom0_build.c +++ b/xen/arch/x86/hvm/dom0_build.c @@ -649,8 +649,8 @@ static int __init pvh_load_kernel( { void *image_base = bootstrap_map_bm(image); void *image_start = image_base + image->headroom; - unsigned long image_len = image->mod->mod_end; - unsigned long initrd_len = initrd ? initrd->mod->mod_end : 0; + unsigned long image_len = image->size; + unsigned long initrd_len = initrd ? initrd->size : 0; const char *cmdline = __va(image->cmdline_pa); struct elf_binary elf; struct elf_dom_parms parms; @@ -727,7 +727,7 @@ static int __init pvh_load_kernel( if ( initrd != NULL ) { rc = hvm_copy_to_guest_phys( - last_addr, mfn_to_virt(initrd->mod->mod_start), initrd_len, v); + last_addr, __va(initrd->start), initrd_len, v); if ( rc ) { printk("Unable to copy initrd to guest\n"); diff --git a/xen/arch/x86/include/asm/bootinfo.h b/xen/arch/x86/include/asm/bootinfo.h index f76876386763..f8b422913063 100644 --- a/xen/arch/x86/include/asm/bootinfo.h +++ b/xen/arch/x86/include/asm/bootinfo.h @@ -26,9 +26,6 @@ enum bootmod_type { }; struct boot_module { - /* Transitionary only */ - module_t *mod; - enum bootmod_type type; /* @@ -62,6 +59,9 @@ struct boot_module { unsigned long headroom; paddr_t cmdline_pa; + + paddr_t start; + size_t size; }; /* diff --git a/xen/arch/x86/include/asm/setup.h b/xen/arch/x86/include/asm/setup.h index 4ad493637892..5c2391a8684b 100644 --- a/xen/arch/x86/include/asm/setup.h +++ b/xen/arch/x86/include/asm/setup.h @@ -38,7 +38,6 @@ void free_boot_modules(void); struct boot_module; void *bootstrap_map_bm(const struct boot_module *bm); -void *bootstrap_map(const module_t *mod); void bootstrap_unmap(void); void release_boot_module(struct boot_module *bm); diff --git a/xen/arch/x86/pv/dom0_build.c b/xen/arch/x86/pv/dom0_build.c index 2580162f3df4..09df12dce694 100644 --- a/xen/arch/x86/pv/dom0_build.c +++ b/xen/arch/x86/pv/dom0_build.c @@ -421,7 +421,7 @@ static int __init dom0_construct(struct boot_info *bi, struct domain *d) image = &bi->mods[i]; image_base = bootstrap_map_bm(image); - image_len = image->mod->mod_end; + image_len = image->size; image_start = image_base + image->headroom; cmdline = __va(image->cmdline_pa); @@ -429,7 +429,7 @@ static int __init dom0_construct(struct boot_info *bi, struct domain *d) if ( i < bi->nr_modules ) { initrd = &bi->mods[i]; - initrd_len = initrd->mod->mod_end; + initrd_len = initrd->size; } d->max_pages = ~0U; @@ -631,7 +631,7 @@ static int __init dom0_construct(struct boot_info *bi, struct domain *d) initrd_pfn = vinitrd_start ? (vinitrd_start - v_start) >> PAGE_SHIFT : domain_tot_pages(d); - initrd_mfn = initrd->mod->mod_start; + initrd_mfn = paddr_to_pfn(initrd->start); mfn = initrd_mfn; count = PFN_UP(initrd_len); if ( d->arch.physaddr_bitsize && @@ -647,8 +647,7 @@ static int __init dom0_construct(struct boot_info *bi, struct domain *d) free_domheap_pages(page, order); page += 1UL << order; } - memcpy(page_to_virt(page), mfn_to_virt(initrd->mod->mod_start), - initrd_len); + memcpy(page_to_virt(page), __va(initrd->start), initrd_len); /* * The initrd was copied but the initrd variable is reused in the * calculations below. As to not leak the memory used for the @@ -656,7 +655,7 @@ static int __init dom0_construct(struct boot_info *bi, struct domain *d) */ release_boot_module(initrd); initrd_mfn = mfn_x(page_to_mfn(page)); - initrd->mod->mod_start = initrd_mfn; + initrd->start = pfn_to_paddr(initrd_mfn); } else { @@ -683,7 +682,7 @@ static int __init dom0_construct(struct boot_info *bi, struct domain *d) nr_pages - domain_tot_pages(d)); if ( initrd ) { - mpt_alloc = pfn_to_paddr(initrd->mod->mod_start); + mpt_alloc = initrd->start; printk("\n Init. ramdisk: %"PRIpaddr"->%"PRIpaddr, mpt_alloc, mpt_alloc + initrd_len); } @@ -911,7 +910,7 @@ static int __init dom0_construct(struct boot_info *bi, struct domain *d) if ( pfn >= initrd_pfn ) { if ( pfn < initrd_pfn + PFN_UP(initrd_len) ) - mfn = initrd->mod->mod_start + (pfn - initrd_pfn); + mfn = paddr_to_pfn(initrd->start) + (pfn - initrd_pfn); else mfn -= PFN_UP(initrd_len); } diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 0bda1326a485..b4eba122d8a5 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -314,13 +314,29 @@ static struct boot_info *__init multiboot_fill_boot_info( */ for ( i = 0; i < MAX_NR_BOOTMODS && i < bi->nr_modules; i++ ) { - bi->mods[i].mod = &mods[i]; - bi->mods[i].cmdline_pa = mods[i].string; + + if ( efi_enabled(EFI_LOADER) ) + { + /* + * The EFI loader gives us modules which are in frame/size. Switch + * to address/size. + */ + bi->mods[i].start = pfn_to_paddr(mods[i].mod_start); + bi->mods[i].size = mods[i].mod_end; + } + else + { + /* + * PVH and BIOS loaders give us modules which are start/end. + * Switch to address/size. + */ + bi->mods[i].start = mods[i].mod_start; + bi->mods[i].size = mods[i].mod_end - mods[i].mod_start; + } } /* Variable 'i' should be one entry past the last module. */ - bi->mods[i].mod = &mods[bi->nr_modules]; bi->mods[i].type = BOOTMOD_XEN; return bi; @@ -336,8 +352,8 @@ unsigned long __init initial_images_nrpages(nodeid_t node) for ( nr = i = 0; i < bi->nr_modules; ++i ) { - unsigned long start = bi->mods[i].mod->mod_start; - unsigned long end = start + PFN_UP(bi->mods[i].mod->mod_end); + unsigned long start = paddr_to_pfn(bi->mods[i].start); + unsigned long end = start + PFN_UP(bi->mods[i].size); if ( end > node_start && node_end > start ) nr += min(node_end, end) - max(node_start, start); @@ -348,12 +364,9 @@ unsigned long __init initial_images_nrpages(nodeid_t node) void __init release_boot_module(struct boot_module *bm) { - uint64_t start = pfn_to_paddr(bm->mod->mod_start); - uint64_t size = bm->mod->mod_end; - ASSERT(!bm->released); - init_domheap_pages(start, start + PAGE_ALIGN(size)); + init_domheap_pages(bm->start, bm->start + PAGE_ALIGN(bm->size)); bm->released = true; } @@ -485,15 +498,9 @@ static void *__init bootstrap_map_addr(paddr_t start, paddr_t end) return ret; } -void *__init bootstrap_map(const module_t *mod) -{ - return bootstrap_map_addr(pfn_to_paddr(mod->mod_start), - pfn_to_paddr(mod->mod_start) + mod->mod_end); -} - void *__init bootstrap_map_bm(const struct boot_module *bm) { - return bootstrap_map(bm->mod); + return bootstrap_map_addr(bm->start, bm->start + bm->size); } void __init bootstrap_unmap(void) @@ -671,8 +678,8 @@ static uint64_t __init consider_modules( for ( i = 0; i < nr_mods ; ++i ) { - uint64_t start = pfn_to_paddr(mods[i].mod->mod_start); - uint64_t end = start + PAGE_ALIGN(mods[i].mod->mod_end); + uint64_t start = mods[i].start; + uint64_t end = start + PAGE_ALIGN(mods[i].size); if ( i == this_mod ) continue; @@ -1403,13 +1410,9 @@ void asmlinkage __init noreturn __start_xen(void) set_kexec_crash_area_size((u64)nr_pages << PAGE_SHIFT); kexec_reserve_area(); - for ( i = 0; !efi_enabled(EFI_LOADER) && i < bi->nr_modules; i++ ) - { - if ( bi->mods[i].mod->mod_start & (PAGE_SIZE - 1) ) + for ( i = 0; i < bi->nr_modules; i++ ) + if ( bi->mods[i].start & (PAGE_SIZE - 1) ) panic("Bootloader didn't honor module alignment request\n"); - bi->mods[i].mod->mod_end -= bi->mods[i].mod->mod_start; - bi->mods[i].mod->mod_start >>= PAGE_SHIFT; - } /* * TODO: load ucode earlier once multiboot modules become accessible @@ -1428,13 +1431,12 @@ void asmlinkage __init noreturn __start_xen(void) * respective reserve_e820_ram() invocation below. No need to * query efi_boot_mem_unused() here, though. */ - xen->mod->mod_start = virt_to_mfn(_stext); - xen->mod->mod_end = __2M_rwdata_end - _stext; + xen->start = virt_to_maddr(_stext); + xen->size = __2M_rwdata_end - _stext; } bi->mods[0].headroom = - bzimage_headroom(bootstrap_map_bm(&bi->mods[0]), - bi->mods[0].mod->mod_end); + bzimage_headroom(bootstrap_map_bm(&bi->mods[0]), bi->mods[0].size); bootstrap_unmap(); #ifndef highmem_start @@ -1515,7 +1517,7 @@ void asmlinkage __init noreturn __start_xen(void) for ( j = bi->nr_modules - 1; j >= 0; j-- ) { struct boot_module *bm = &bi->mods[j]; - unsigned long size = PAGE_ALIGN(bm->headroom + bm->mod->mod_end); + unsigned long size = PAGE_ALIGN(bm->headroom + bm->size); if ( bm->relocated ) continue; @@ -1527,14 +1529,11 @@ void asmlinkage __init noreturn __start_xen(void) if ( highmem_start && end > highmem_start ) continue; - if ( s < end && - (bm->headroom || - ((end - size) >> PAGE_SHIFT) > bm->mod->mod_start) ) + if ( s < end && (bm->headroom || (end - size) > bm->start) ) { - move_memory(end - size + bm->headroom, - pfn_to_paddr(bm->mod->mod_start), bm->mod->mod_end); - bm->mod->mod_start = (end - size) >> PAGE_SHIFT; - bm->mod->mod_end += bm->headroom; + move_memory(end - size + bm->headroom, bm->start, bm->size); + bm->start = (end - size); + bm->size += bm->headroom; bm->relocated = true; } } @@ -1565,10 +1564,9 @@ void asmlinkage __init noreturn __start_xen(void) panic("Not enough memory to relocate the dom0 kernel image\n"); for ( i = 0; i < bi->nr_modules; ++i ) { - const struct boot_module *bm = &bi->mods[i]; - uint64_t s = pfn_to_paddr(bm->mod->mod_start); + uint64_t s = bi->mods[i].start, l = bi->mods[i].size; - reserve_e820_ram(&boot_e820, s, s + PAGE_ALIGN(bm->mod->mod_end)); + reserve_e820_ram(&boot_e820, s, s + PAGE_ALIGN(l)); } if ( !xen_phys_start ) @@ -1646,8 +1644,7 @@ void asmlinkage __init noreturn __start_xen(void) map_e = boot_e820.map[j].addr + boot_e820.map[j].size; for ( j = 0; j < bi->nr_modules; ++j ) { - uint64_t end = pfn_to_paddr(bi->mods[j].mod->mod_start) + - bi->mods[j].mod->mod_end; + uint64_t end = bi->mods[j].start + bi->mods[j].size; if ( map_e < end ) map_e = end; @@ -1721,13 +1718,11 @@ void asmlinkage __init noreturn __start_xen(void) for ( i = 0; i < bi->nr_modules; ++i ) { - const struct boot_module *bm = &bi->mods[i]; + unsigned long s = bi->mods[i].start, l = bi->mods[i].size; - set_pdx_range(bm->mod->mod_start, - bm->mod->mod_start + PFN_UP(bm->mod->mod_end)); - map_pages_to_xen((unsigned long)mfn_to_virt(bm->mod->mod_start), - _mfn(bm->mod->mod_start), - PFN_UP(bm->mod->mod_end), PAGE_HYPERVISOR); + set_pdx_range(paddr_to_pfn(s), paddr_to_pfn(s + l) + 1); + map_pages_to_xen((unsigned long)maddr_to_virt(s), maddr_to_mfn(s), + PFN_UP(l), PAGE_HYPERVISOR); } #ifdef CONFIG_KEXEC diff --git a/xen/xsm/xsm_policy.c b/xen/xsm/xsm_policy.c index 76280903d5be..7f70d860bd65 100644 --- a/xen/xsm/xsm_policy.c +++ b/xen/xsm/xsm_policy.c @@ -43,7 +43,7 @@ int __init xsm_multiboot_policy_init( struct boot_module *bm = &bi->mods[i]; _policy_start = bootstrap_map_bm(bm); - _policy_len = bm->mod->mod_end; + _policy_len = bm->size; if ( (xsm_magic_t)(*_policy_start) == XSM_MAGIC ) { From patchwork Fri Nov 15 13:12:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Daniel P. Smith" X-Patchwork-Id: 13876220 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 92172D6DDD8 for ; Fri, 15 Nov 2024 13:13:14 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.837577.1253515 (Exim 4.92) (envelope-from ) id 1tBw8J-0000Ka-Rx; Fri, 15 Nov 2024 13:13:07 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 837577.1253515; Fri, 15 Nov 2024 13:13:07 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tBw8J-0000KP-Or; Fri, 15 Nov 2024 13:13:07 +0000 Received: by outflank-mailman (input) for mailman id 837577; Fri, 15 Nov 2024 13:13:06 +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 1tBw8I-0006v7-E3 for xen-devel@lists.xenproject.org; Fri, 15 Nov 2024 13:13:06 +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 56eb7dc6-a353-11ef-99a3-01e77a169b0f; Fri, 15 Nov 2024 14:13:02 +0100 (CET) Received: by mx.zohomail.com with SMTPS id 1731676336898210.23232910970785; Fri, 15 Nov 2024 05:12:16 -0800 (PST) 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: 56eb7dc6-a353-11ef-99a3-01e77a169b0f X-Custom-Connection: eyJyZW1vdGVpcCI6IjEzNi4xNDMuMTg4LjUxIiwiaGVsbyI6InNlbmRlcjQtb2YtbzUxLnpvaG8uY29tIn0= X-Custom-Transaction: eyJpZCI6IjU2ZWI3ZGM2LWEzNTMtMTFlZi05OWEzLTAxZTc3YTE2OWIwZiIsInRzIjoxNzMxNjc2MzgyLjcxOTkwMywic2VuZGVyIjoiZHBzbWl0aEBhcGVydHVzc29sdXRpb25zLmNvbSIsInJlY2lwaWVudCI6Inhlbi1kZXZlbEBsaXN0cy54ZW5wcm9qZWN0Lm9yZyJ9 ARC-Seal: i=1; a=rsa-sha256; t=1731676339; cv=none; d=zohomail.com; s=zohoarc; b=TNLdk+kZ3wIsXjMVdGHmQdoT2Lpgy6teW3Mri33QY/2TXSdo+hcoO+vzN5wN/hEtK6oRigwPYxAUk8aDtJAb1g1bWp6lPgH1JgCXTTvFNqwFbpbWTPXhW75fvlb0g8IsOokmftlhBcHlc3+lZTxxV7EwgkMjl2rPHl8TMaWjbcw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1731676339; 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=ElW812RXFpILnCxwwVsvGFK8JqOefDd9+I2R3fwUEc0=; b=nN8dMTl9nVrR2NQN0rIVABe0EjIGImpzfpmL1uTwiKWnzbpd7qEA9+/W2we3iFksYe1AzNifaFdu1FZ6f02QqdQcRG0Lh5EemRgQjNwLuj6LNiY69T1o1kAk4nVTh+bEZoU+LdRorzbcqhGW4F6Lbbc/YYnKRsU5xTsg3jWgJVg= 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=1731676339; 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=ElW812RXFpILnCxwwVsvGFK8JqOefDd9+I2R3fwUEc0=; b=awdErlJ1nfEhNl5c/4u8eGNuRAf+s01i8CatdiD49ASkbBLkn47AqE6rpJ/oaBSL ATu8PYHZJYGIdUPXA8Wfx9u+tAdZWg2KQh8ThlpJPGikWahxWjDpg9Q+mNR0nYhTcoE efIQg5/o7pgAwUROVOxlzKzOBXDE6u43XlgpYnEM= 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_Pau_Monn=C3=A9?= Subject: [PATCH v9 4/6] x86/boot: introduce boot domain Date: Fri, 15 Nov 2024 08:12:02 -0500 Message-Id: <20241115131204.32135-5-dpsmith@apertussolutions.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20241115131204.32135-1-dpsmith@apertussolutions.com> References: <20241115131204.32135-1-dpsmith@apertussolutions.com> MIME-Version: 1.0 X-ZohoMailClient: External 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 v8: - code style correction --- xen/arch/x86/dom0_build.c | 8 ++++--- xen/arch/x86/hvm/dom0_build.c | 17 +++++---------- 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 | 4 ++-- xen/arch/x86/pv/dom0_build.c | 24 +++++++-------------- xen/arch/x86/setup.c | 24 +++++++++------------ 8 files changed, 69 insertions(+), 50 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 e8f5bf5447bc..c231191faec7 100644 --- a/xen/arch/x86/dom0_build.c +++ b/xen/arch/x86/dom0_build.c @@ -13,6 +13,7 @@ #include #include +#include #include #include #include @@ -596,9 +597,10 @@ int __init dom0_setup_permissions(struct domain *d) return rc; } -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 = bd->d; /* Sanity! */ BUG_ON(!pv_shim && d->domain_id != 0); @@ -608,9 +610,9 @@ int __init construct_dom0(struct boot_info *bi, struct domain *d) process_pending_softirqs(); if ( is_hvm_domain(d) ) - rc = dom0_construct_pvh(bi, d); + rc = dom0_construct_pvh(bd); else if ( is_pv_domain(d) ) - rc = dom0_construct_pv(bi, d); + rc = dom0_construct_pv(bd); else panic("Cannot construct Dom0. No guest interface available\n"); diff --git a/xen/arch/x86/hvm/dom0_build.c b/xen/arch/x86/hvm/dom0_build.c index 0bd1e4277bff..69881599e77e 100644 --- a/xen/arch/x86/hvm/dom0_build.c +++ b/xen/arch/x86/hvm/dom0_build.c @@ -1301,26 +1301,19 @@ static void __hwdom_init pvh_setup_mmcfg(struct domain *d) } } -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 = NULL; - unsigned int idx; + struct boot_module *image = bd->kernel; + struct boot_module *initrd = bd->ramdisk; + struct domain *d = bd->d; int rc; printk(XENLOG_INFO "*** Building a PVH Dom%d ***\n", d->domain_id); - idx = first_boot_module_index(bi, BOOTMOD_KERNEL); - if ( idx >= bi->nr_modules ) + if ( image == NULL ) panic("Missing kernel boot module for %pd construction\n", d); - image = &bi->mods[idx]; - - idx = first_boot_module_index(bi, BOOTMOD_RAMDISK); - if ( idx < bi->nr_modules ) - initrd = &bi->mods[idx]; - if ( is_hardware_domain(d) ) { /* diff --git a/xen/arch/x86/include/asm/bootdomain.h b/xen/arch/x86/include/asm/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 f8b422913063..9f65e2c8f62d 100644 --- a/xen/arch/x86/include/asm/bootinfo.h +++ b/xen/arch/x86/include/asm/bootinfo.h @@ -11,10 +11,14 @@ #include #include #include +#include /* Max number of boot modules a bootloader can provide in addition to Xen */ #define MAX_NR_BOOTMODS 63 +/* Max number of boot domains that Xen can construct */ +#define MAX_NR_BOOTDOMS 1 + /* Boot module binary type / purpose */ enum bootmod_type { BOOTMOD_UNKNOWN, @@ -78,6 +82,7 @@ struct boot_info { unsigned int nr_modules; struct boot_module mods[MAX_NR_BOOTMODS + 1]; + struct boot_domain domains[MAX_NR_BOOTDOMS]; }; /* diff --git a/xen/arch/x86/include/asm/dom0_build.h b/xen/arch/x86/include/asm/dom0_build.h index 2d67b17213dc..8c94e87dc576 100644 --- a/xen/arch/x86/include/asm/dom0_build.h +++ b/xen/arch/x86/include/asm/dom0_build.h @@ -13,9 +13,9 @@ unsigned long dom0_compute_nr_pages(struct domain *d, unsigned long initrd_len); int dom0_setup_permissions(struct domain *d); -struct boot_info; -int dom0_construct_pv(struct boot_info *bi, struct domain *d); -int dom0_construct_pvh(struct boot_info *bi, struct domain *d); +struct boot_domain; +int dom0_construct_pv(struct boot_domain *bd); +int dom0_construct_pvh(struct boot_domain *bd); 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/setup.h index 5c2391a8684b..b517da6144de 100644 --- a/xen/arch/x86/include/asm/setup.h +++ b/xen/arch/x86/include/asm/setup.h @@ -26,8 +26,8 @@ void subarch_init_memory(void); void init_IRQ(void); -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); diff --git a/xen/arch/x86/pv/dom0_build.c b/xen/arch/x86/pv/dom0_build.c index 09df12dce694..f42aeb031694 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 domain *d, return page; } -static int __init dom0_construct(struct boot_info *bi, struct domain *d) +static int __init dom0_construct(struct boot_domain *bd) { unsigned int i; int rc, order, machine; @@ -371,13 +371,14 @@ static int __init dom0_construct(struct boot_info *bi, struct domain *d) struct page_info *page = NULL; unsigned int flush_flags = 0; start_info_t *si; + struct domain *d = bd->d; struct vcpu *v = d->vcpu[0]; - struct boot_module *image; - struct boot_module *initrd = NULL; + struct boot_module *image = bd->kernel; + struct boot_module *initrd = bd->ramdisk; void *image_base; unsigned long image_len; void *image_start; - unsigned long initrd_len = 0; + unsigned long initrd_len = initrd ? initrd->size : 0; const char *cmdline; l4_pgentry_t *l4tab = NULL, *l4start = NULL; l3_pgentry_t *l3tab = NULL, *l3start = NULL; @@ -415,23 +416,14 @@ static int __init dom0_construct(struct boot_info *bi, struct domain *d) printk(XENLOG_INFO "*** Building a PV Dom%d ***\n", d->domain_id); - i = first_boot_module_index(bi, BOOTMOD_KERNEL); - if ( i >= bi->nr_modules ) + if ( unlikely(image == NULL) ) panic("Missing kernel boot module for %pd construction\n", d); - image = &bi->mods[i]; image_base = bootstrap_map_bm(image); image_len = image->size; image_start = image_base + image->headroom; cmdline = __va(image->cmdline_pa); - i = first_boot_module_index(bi, BOOTMOD_RAMDISK); - if ( i < bi->nr_modules ) - { - initrd = &bi->mods[i]; - initrd_len = initrd->size; - } - d->max_pages = ~0U; if ( (rc = bzimage_parse(image_base, &image_start, &image_len)) != 0 ) @@ -1078,7 +1070,7 @@ out: return rc; } -int __init dom0_construct_pv(struct boot_info *bi, struct domain *d) +int __init dom0_construct_pv(struct boot_domain *bd) { unsigned long cr4 = read_cr4(); int rc; @@ -1096,7 +1088,7 @@ int __init dom0_construct_pv(struct boot_info *bi, struct domain *d) write_cr4(cr4 & ~X86_CR4_SMAP); } - rc = dom0_construct(bi, d); + rc = dom0_construct(bd); if ( cr4 & X86_CR4_SMAP ) { diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index b4eba122d8a5..2ccaa7dc965b 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -975,16 +975,9 @@ static struct domain *__init create_dom0(struct boot_info *bi) .misc_flags = opt_dom0_msr_relaxed ? XEN_X86_MSR_RELAXED : 0, }, }; + struct boot_domain *bd = &bi->domains[0]; struct domain *d; domid_t domid; - struct boot_module *image; - unsigned int idx; - - idx = first_boot_module_index(bi, BOOTMOD_KERNEL); - if ( idx >= bi->nr_modules ) - panic("Missing kernel boot module for building domain\n"); - - image = &bi->mods[idx]; if ( opt_dom0_pvh ) { @@ -1011,11 +1004,11 @@ static struct domain *__init create_dom0(struct boot_info *bi) panic("Error creating d%uv0\n", domid); /* 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)); if ( bi->kextra ) /* kextra always includes exactly one leading space. */ @@ -1037,10 +1030,11 @@ static struct domain *__init create_dom0(struct boot_info *bi) safe_strcat(cmdline, acpi_param); } - image->cmdline_pa = __pa(cmdline); + bd->kernel->cmdline_pa = __pa(cmdline); } - if ( construct_dom0(bi, d) != 0 ) + bd->d = d; + if ( construct_dom0(bd) != 0 ) panic("Could not construct domain 0\n"); return d; @@ -1240,6 +1234,7 @@ void asmlinkage __init noreturn __start_xen(void) /* Dom0 kernel is always first */ bi->mods[0].type = BOOTMOD_KERNEL; + bi->domains[0].kernel = &bi->mods[0]; if ( pvh_boot ) { @@ -2110,6 +2105,7 @@ void asmlinkage __init noreturn __start_xen(void) if ( initrdidx < MAX_NR_BOOTMODS ) { bi->mods[initrdidx].type = BOOTMOD_RAMDISK; + bi->domains[0].ramdisk = &bi->mods[initrdidx]; if ( first_boot_module_index(bi, BOOTMOD_UNKNOWN) < MAX_NR_BOOTMODS ) printk(XENLOG_WARNING "Multiple initrd candidates, picking module #%u\n", From patchwork Fri Nov 15 13:12:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Daniel P. Smith" X-Patchwork-Id: 13876223 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8807ED6DDFD for ; Fri, 15 Nov 2024 13:22:45 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.837621.1253548 (Exim 4.92) (envelope-from ) id 1tBwHN-0004ov-7P; Fri, 15 Nov 2024 13:22:29 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 837621.1253548; Fri, 15 Nov 2024 13:22:29 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tBwHN-0004oo-4x; Fri, 15 Nov 2024 13:22:29 +0000 Received: by outflank-mailman (input) for mailman id 837621; Fri, 15 Nov 2024 13:22:27 +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 1tBw8R-0006v7-Un for xen-devel@lists.xenproject.org; Fri, 15 Nov 2024 13:13:15 +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 5d1fae5f-a353-11ef-99a3-01e77a169b0f; Fri, 15 Nov 2024 14:13:12 +0100 (CET) Received: by mx.zohomail.com with SMTPS id 1731676338126593.7092805148436; Fri, 15 Nov 2024 05:12:18 -0800 (PST) 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: 5d1fae5f-a353-11ef-99a3-01e77a169b0f X-Custom-Connection: eyJyZW1vdGVpcCI6IjEzNi4xNDMuMTg4LjUxIiwiaGVsbyI6InNlbmRlcjQtb2YtbzUxLnpvaG8uY29tIn0= X-Custom-Transaction: eyJpZCI6IjVkMWZhZTVmLWEzNTMtMTFlZi05OWEzLTAxZTc3YTE2OWIwZiIsInRzIjoxNzMxNjc2MzkzLjAxNzQ0Mywic2VuZGVyIjoiZHBzbWl0aEBhcGVydHVzc29sdXRpb25zLmNvbSIsInJlY2lwaWVudCI6Inhlbi1kZXZlbEBsaXN0cy54ZW5wcm9qZWN0Lm9yZyJ9 ARC-Seal: i=1; a=rsa-sha256; t=1731676340; cv=none; d=zohomail.com; s=zohoarc; b=Z9e/3YKyb3RRCE5tGYsc88W9Ea4/y5BTZ3oXrdZPV627uueOKJIfQoXWXCMFUnWuXJRaa93jnkV9iCbSDdwMEp+7CAxy6JpkBkwNlu69osdrJvwNWSTgc8rdfaAQLpdZKWJ36LbgRPKDrIsb+JskwhwfK9kMQcncr5LUSqGYSNE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1731676340; 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=bhl7E1mvlo9SO98XxLqZrhL5BHZQCoyp4nD+tEiZihE=; b=FLoJOgt4hMA0q6Qlkfk9BtOgxbNr2Q/7Mi6U2D1u83AIhqewpzbY5EFu7L5IEQWLMGb1lZEb2EM7c8296cVe+eHc8woy+PfGaqno6B8oJGeQGQ/TBbDQre2Wg9WQHUWiOY2tYq/BfPwYa+NKbm6Mqoj+ukZLmgWoUfBmeok4x0s= 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=1731676340; 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=bhl7E1mvlo9SO98XxLqZrhL5BHZQCoyp4nD+tEiZihE=; b=kFxRu0P+j0A0IlvOO+Yih4j31JT3Is7P4+aOLfP+U96Cgq7qeuOazqT5niKeuB5I NY50+/gFKw8lxmNq+Lcw3oOe+h353PAGYNrcZr1dXptrundY8ScC/Jko8M/r3/gJFYK f0nNnMAukrhe2xQmleQ3BeowE/ChvTlmxdC1cS5M= 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_Pau_Monn=C3=A9?= Subject: [PATCH v9 5/6] x86/boot: introduce domid field to struct boot_domain Date: Fri, 15 Nov 2024 08:12:03 -0500 Message-Id: <20241115131204.32135-6-dpsmith@apertussolutions.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20241115131204.32135-1-dpsmith@apertussolutions.com> References: <20241115131204.32135-1-dpsmith@apertussolutions.com> MIME-Version: 1.0 X-ZohoMailClient: External Add a domid field to struct boot_domain to hold the assigned domain id for the domain. During initialization, ensure all instances of struct boot_domain have the invalid domid to ensure that the domid must be set either by convention or configuration. Signed-off-by: Daniel P. Smith Reviewed-by: Jason Andryuk --- xen/arch/x86/include/asm/bootdomain.h | 2 ++ xen/arch/x86/setup.c | 12 +++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/xen/arch/x86/include/asm/bootdomain.h b/xen/arch/x86/include/asm/bootdomain.h index 12c19ab37bd8..3873f916f854 100644 --- a/xen/arch/x86/include/asm/bootdomain.h +++ b/xen/arch/x86/include/asm/bootdomain.h @@ -12,6 +12,8 @@ struct boot_module; struct domain; struct boot_domain { + domid_t domid; + struct boot_module *kernel; struct boot_module *ramdisk; diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 2ccaa7dc965b..533a1e2bbe05 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -339,6 +339,9 @@ static struct boot_info *__init multiboot_fill_boot_info( /* Variable 'i' should be one entry past the last module. */ bi->mods[i].type = BOOTMOD_XEN; + for ( i = 0; i < MAX_NR_BOOTDOMS; i++ ) + bi->domains[i].domid = DOMID_INVALID; + return bi; } @@ -977,7 +980,6 @@ static struct domain *__init create_dom0(struct boot_info *bi) }; struct boot_domain *bd = &bi->domains[0]; struct domain *d; - domid_t domid; if ( opt_dom0_pvh ) { @@ -993,15 +995,15 @@ static struct domain *__init create_dom0(struct boot_info *bi) dom0_cfg.flags |= XEN_DOMCTL_CDF_iommu; /* Create initial domain. Not d0 for pvshim. */ - domid = get_initial_domain_id(); - d = domain_create(domid, &dom0_cfg, pv_shim ? 0 : CDF_privileged); + bd->domid = get_initial_domain_id(); + d = domain_create(bd->domid, &dom0_cfg, pv_shim ? 0 : CDF_privileged); if ( IS_ERR(d) ) - panic("Error creating d%u: %ld\n", domid, PTR_ERR(d)); + panic("Error creating d%u: %ld\n", bd->domid, PTR_ERR(d)); init_dom0_cpuid_policy(d); if ( alloc_dom0_vcpu0(d) == NULL ) - panic("Error creating d%uv0\n", domid); + panic("Error creating d%uv0\n", bd->domid); /* Grab the DOM0 command line. */ if ( bd->kernel->cmdline_pa || bi->kextra ) From patchwork Fri Nov 15 13:12:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Daniel P. Smith" X-Patchwork-Id: 13876221 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 52050D6DDD8 for ; Fri, 15 Nov 2024 13:13:35 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.837583.1253525 (Exim 4.92) (envelope-from ) id 1tBw8c-0001EO-5s; Fri, 15 Nov 2024 13:13:26 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 837583.1253525; Fri, 15 Nov 2024 13:13: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 1tBw8c-0001EE-31; Fri, 15 Nov 2024 13:13:26 +0000 Received: by outflank-mailman (input) for mailman id 837583; Fri, 15 Nov 2024 13:13: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 1tBw8b-00085h-1I for xen-devel@lists.xenproject.org; Fri, 15 Nov 2024 13:13:25 +0000 Received: from sender3-of-o57.zoho.com (sender3-of-o57.zoho.com [136.143.184.57]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 6294ff26-a353-11ef-a0c7-8be0dac302b0; Fri, 15 Nov 2024 14:13:21 +0100 (CET) Received: by mx.zohomail.com with SMTPS id 1731676339398284.4595211557644; Fri, 15 Nov 2024 05:12:19 -0800 (PST) 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: 6294ff26-a353-11ef-a0c7-8be0dac302b0 X-Custom-Connection: eyJyZW1vdGVpcCI6IjEzNi4xNDMuMTg0LjU3IiwiaGVsbyI6InNlbmRlcjMtb2YtbzU3LnpvaG8uY29tIn0= X-Custom-Transaction: eyJpZCI6IjYyOTRmZjI2LWEzNTMtMTFlZi1hMGM3LThiZTBkYWMzMDJiMCIsInRzIjoxNzMxNjc2NDAyLjE3MzY2Nywic2VuZGVyIjoiZHBzbWl0aEBhcGVydHVzc29sdXRpb25zLmNvbSIsInJlY2lwaWVudCI6Inhlbi1kZXZlbEBsaXN0cy54ZW5wcm9qZWN0Lm9yZyJ9 ARC-Seal: i=1; a=rsa-sha256; t=1731676341; cv=none; d=zohomail.com; s=zohoarc; b=ekj/4JnJS7AE9hySFZNQ5YbKSfJfC82Xap7g8WbBG7qxZ/HUINjh/CGf/DzCqZiGieK+RynOvrzGQS/9iM2+LlijRgKToesmWC8xB9ImiVqnmT1yuI2O5UvDLlgERzTsy5dE79IDuGYn4pCuNodJD3X7izkFMaqpobq7Qz/8IWc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1731676341; 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=bSzO7sAd2L8LHq1LVIVbhwl38gEAx7Fm3b8FDdjS27I=; b=AK/Lup5O62ylDiTjBIcBz0qiCw0NbbKKtQ5y16eW1Fc92a56qsoNYEPSuR70D2yUEGrwP1pjgR3gXjP+W4Lnb2fThoDeBRRALKiTZScmX97M1yR174ZqNpCYu2wwkJANwvAtIBSyLgKhuRUfAUonQxjap8FvE8cl32IgFo465CQ= 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=1731676341; 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=bSzO7sAd2L8LHq1LVIVbhwl38gEAx7Fm3b8FDdjS27I=; b=BVLxK7ijGhycuQynLiPH19qi/ivtF5NP7fPEFq7Spg5CShs0Ss5xe0dFFSI1IIwA pfI2NXMScZxNKuBiWiPfdR70Aw9S7RXuRfcYOQpbpXPGeKCQFU5uRicWIqgIEvOJcpd E6mTZkYHPagBazMfVRwQBLs116yOhVnW3Pg9DfMU= 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_Pau_Monn=C3=A9?= Subject: [PATCH v9 6/6] x86/boot: add cmdline to struct boot_domain Date: Fri, 15 Nov 2024 08:12:04 -0500 Message-Id: <20241115131204.32135-7-dpsmith@apertussolutions.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20241115131204.32135-1-dpsmith@apertussolutions.com> References: <20241115131204.32135-1-dpsmith@apertussolutions.com> MIME-Version: 1.0 X-ZohoMailClient: External Add a container for the "cooked" command line for a domain. This provides for the backing memory to be directly associated with the domain being constructed. This is done in anticipation that the domain construction path may need to be invoked multiple times, thus ensuring each instance had a distinct memory allocation. Signed-off-by: Daniel P. Smith --- Changes since v8: - switch to a dynamically allocated buffer - dropped local cmdline var in pv dom0_construct() Changes since v7: - updated commit message to expand on intent and purpose --- xen/arch/x86/include/asm/bootdomain.h | 2 ++ xen/arch/x86/include/asm/dom0_build.h | 1 + xen/arch/x86/pv/dom0_build.c | 6 ++-- xen/arch/x86/setup.c | 49 ++++++++++++++++++++++----- 4 files changed, 45 insertions(+), 13 deletions(-) diff --git a/xen/arch/x86/include/asm/bootdomain.h b/xen/arch/x86/include/asm/bootdomain.h index 3873f916f854..75e7c706d86e 100644 --- a/xen/arch/x86/include/asm/bootdomain.h +++ b/xen/arch/x86/include/asm/bootdomain.h @@ -12,6 +12,8 @@ struct boot_module; struct domain; struct boot_domain { + const char *cmdline; + domid_t domid; struct boot_module *kernel; diff --git a/xen/arch/x86/include/asm/dom0_build.h b/xen/arch/x86/include/asm/dom0_build.h index 8c94e87dc576..6ca3ca7c8a43 100644 --- a/xen/arch/x86/include/asm/dom0_build.h +++ b/xen/arch/x86/include/asm/dom0_build.h @@ -4,6 +4,7 @@ #include #include +#include #include extern unsigned int dom0_memflags; diff --git a/xen/arch/x86/pv/dom0_build.c b/xen/arch/x86/pv/dom0_build.c index f42aeb031694..91bcce1542bc 100644 --- a/xen/arch/x86/pv/dom0_build.c +++ b/xen/arch/x86/pv/dom0_build.c @@ -379,7 +379,6 @@ static int __init dom0_construct(struct boot_domain *bd) unsigned long image_len; void *image_start; unsigned long initrd_len = initrd ? initrd->size : 0; - const char *cmdline; l4_pgentry_t *l4tab = NULL, *l4start = NULL; l3_pgentry_t *l3tab = NULL, *l3start = NULL; l2_pgentry_t *l2tab = NULL, *l2start = NULL; @@ -422,7 +421,6 @@ static int __init dom0_construct(struct boot_domain *bd) image_base = bootstrap_map_bm(image); image_len = image->size; image_start = image_base + image->headroom; - cmdline = __va(image->cmdline_pa); d->max_pages = ~0U; @@ -972,8 +970,8 @@ static int __init dom0_construct(struct boot_domain *bd) } memset(si->cmd_line, 0, sizeof(si->cmd_line)); - if ( cmdline != NULL ) - strlcpy((char *)si->cmd_line, cmdline, sizeof(si->cmd_line)); + if ( bd->cmdline ) + strlcpy((char *)si->cmd_line, bd->cmdline, sizeof(si->cmd_line)); #ifdef CONFIG_VIDEO if ( !pv_shim && fill_console_start_info((void *)(si + 1)) ) diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 533a1e2bbe05..b9ca9c486fe5 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -963,10 +963,31 @@ static unsigned int __init copy_bios_e820(struct e820entry *map, unsigned int li return n; } -static struct domain *__init create_dom0(struct boot_info *bi) +static size_t __init domain_cmdline_size( + struct boot_info *bi, struct boot_domain *bd) { - static char __initdata cmdline[MAX_GUEST_CMDLINE]; + size_t s = 0; + + s += bi->kextra ? strlen(bi->kextra) : 0; + s += bd->kernel->cmdline_pa ? strlen(__va(bd->kernel->cmdline_pa)) : 0; + /* Should only be called if one of extra or cmdline_pa are valid */ + ASSERT(s > 0); + + /* + * Add additional space for the following cases: + * - 7 chars for " noapic" + * - 13 chars for longest acpi opiton, " acpi=verbose" + * - 1 char to hold \0 + */ + s += 7 + 13 + 1; + + return s; +} + +static struct domain *__init create_dom0(struct boot_info *bi) +{ + char *cmdline = NULL; struct xen_domctl_createdomain dom0_cfg = { .flags = IS_ENABLED(CONFIG_TBOOT) ? XEN_DOMCTL_CDF_s3_integrity : 0, .max_evtchn_port = -1, @@ -1008,17 +1029,23 @@ static struct domain *__init create_dom0(struct boot_info *bi) /* Grab the DOM0 command line. */ if ( bd->kernel->cmdline_pa || bi->kextra ) { + size_t cmdline_size = domain_cmdline_size(bi, bd); + + if ( !(cmdline = xzalloc_array(char, cmdline_size)) ) + panic("Error allocating cmdline buffer for %pd\n", d); + if ( bd->kernel->cmdline_pa ) - safe_strcpy(cmdline, - cmdline_cook(__va(bd->kernel->cmdline_pa), bi->loader)); + strlcpy(cmdline, + cmdline_cook(__va(bd->kernel->cmdline_pa),bi->loader), + cmdline_size); if ( bi->kextra ) /* kextra always includes exactly one leading space. */ - safe_strcat(cmdline, bi->kextra); + strlcat(cmdline, bi->kextra, cmdline_size); /* Append any extra parameters. */ if ( skip_ioapic_setup && !strstr(cmdline, "noapic") ) - safe_strcat(cmdline, " noapic"); + strlcat(cmdline, " noapic", cmdline_size); if ( (strlen(acpi_param) == 0) && acpi_disabled ) { @@ -1028,17 +1055,21 @@ static struct domain *__init create_dom0(struct boot_info *bi) if ( (strlen(acpi_param) != 0) && !strstr(cmdline, "acpi=") ) { - safe_strcat(cmdline, " acpi="); - safe_strcat(cmdline, acpi_param); + strlcat(cmdline, " acpi=", cmdline_size); + strlcat(cmdline, acpi_param, cmdline_size); } - bd->kernel->cmdline_pa = __pa(cmdline); + bd->cmdline = cmdline; + bd->kernel->cmdline_pa = __pa(bd->cmdline); } bd->d = d; if ( construct_dom0(bd) != 0 ) panic("Could not construct domain 0\n"); + if ( cmdline ) + xfree(cmdline); + return d; }