From patchwork Sat Nov 2 17:25:40 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: 13860193 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 D91BCE67807 for ; Sat, 2 Nov 2024 17:26:29 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.829559.1244554 (Exim 4.92) (envelope-from ) id 1t7HtG-0005AD-79; Sat, 02 Nov 2024 17:26:22 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 829559.1244554; Sat, 02 Nov 2024 17:26:22 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t7HtG-0005A0-4D; Sat, 02 Nov 2024 17:26:22 +0000 Received: by outflank-mailman (input) for mailman id 829559; Sat, 02 Nov 2024 17:26:21 +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 1t7HtF-0004r4-7a for xen-devel@lists.xenproject.org; Sat, 02 Nov 2024 17:26:21 +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 8ef6b234-993f-11ef-99a3-01e77a169b0f; Sat, 02 Nov 2024 18:26:14 +0100 (CET) Received: by mx.zohomail.com with SMTPS id 1730568360842714.6163680866581; Sat, 2 Nov 2024 10:26:00 -0700 (PDT) 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: 8ef6b234-993f-11ef-99a3-01e77a169b0f X-Custom-Connection: eyJyZW1vdGVpcCI6IjEzNi4xNDMuMTg4LjUxIiwiaGVsbyI6InNlbmRlcjQtb2YtbzUxLnpvaG8uY29tIn0= X-Custom-Transaction: eyJpZCI6IjhlZjZiMjM0LTk5M2YtMTFlZi05OWEzLTAxZTc3YTE2OWIwZiIsInRzIjoxNzMwNTY4Mzc1LjA0MDUwMSwic2VuZGVyIjoiZHBzbWl0aEBhcGVydHVzc29sdXRpb25zLmNvbSIsInJlY2lwaWVudCI6Inhlbi1kZXZlbEBsaXN0cy54ZW5wcm9qZWN0Lm9yZyJ9 ARC-Seal: i=1; a=rsa-sha256; t=1730568367; cv=none; d=zohomail.com; s=zohoarc; b=gOXvqeIJINXmDJf/CC0P5TlgB3n0EUwvGeb85hEV3ewSRZFI1GOG1Kv0dEwF4cw3zEjQC0aO2A1bJe4YcKq7pBRlyywkOMvGNym+OwxYxllX+4fcfptq1HDgUUoL0hFhW0vc5xgwh8F6CsdLZtNoP5MEPj+OKExfrAUQjX6VDPU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730568367; 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=Gr0Bo47Cp6rQWLc3HgBA4fLt5SBG4Kw79tWuOGibWjw=; b=YEHhRXWhPRKmxq7TQtkZ+2NLoZaFumFTmmeQ137suNCGxKEPtACcFjD81jKRKwYwiwMrWuc/DIAlfmsAzMo50Gx0til4OmfzmjCFJZVCRIEzq6AoVPUhP42On9AlUbS9myf4F3ho0Q28wGN21+qMbQAPdMJ9OkNoHpwp5zHhlZg= 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=1730568367; 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=Gr0Bo47Cp6rQWLc3HgBA4fLt5SBG4Kw79tWuOGibWjw=; b=RSOHPynlurMFkn2C/yLIJc7VqCGWAZbSj0T8VUjlBC1zsODpkFSCXw4fA1BkvS5g KlAsWOBO82LVMkBk5FtJai825y1aPt9oiDzPk520On/6eE9gd/nF7OHrI8jLmIoqEc9 gT1DaT+I26byylqYUu8mQ1JaGDCURtkPG/WQGbcM= 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 01/12] x86/boot: introduce boot module types Date: Sat, 2 Nov 2024 13:25:40 -0400 Message-Id: <20241102172551.17233-2-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 X-ZohoMailClient: External This commit introduces module types for the types of boot modules that may be passed to Xen. These include xen, kernel, ramdisk, microcode, and xsm policy. This reduces the need for hard coded order assumptions and global variables to be used by consumers of boot modules, such as domain construction. Signed-off-by: Daniel P. Smith Reviewed-by: Andrew Cooper , albeit it with --- Changes since v7: - merged the addition of microcode and xsm boot mod types Changes since v5: - added guard around initrd type assignment - removed a missed rebase artifact --- xen/arch/x86/cpu/microcode/core.c | 1 + xen/arch/x86/include/asm/bootinfo.h | 12 ++++++++++++ xen/arch/x86/setup.c | 4 ++++ xen/xsm/xsm_policy.c | 1 + 4 files changed, 18 insertions(+) diff --git a/xen/arch/x86/cpu/microcode/core.c b/xen/arch/x86/cpu/microcode/core.c index 1fa6cbf3d364..f46464241557 100644 --- a/xen/arch/x86/cpu/microcode/core.c +++ b/xen/arch/x86/cpu/microcode/core.c @@ -845,6 +845,7 @@ static int __init early_microcode_load(struct boot_info *bi) printk(XENLOG_WARNING "Microcode: Chosen module %d already used\n", idx); return -ENODEV; } + bi->mods[idx].type = BOOTMOD_MICROCODE; size = bi->mods[idx].mod->mod_end; data = bootstrap_map_bm(&bi->mods[idx]); diff --git a/xen/arch/x86/include/asm/bootinfo.h b/xen/arch/x86/include/asm/bootinfo.h index 6237da7e4d86..fc74e3b224e7 100644 --- a/xen/arch/x86/include/asm/bootinfo.h +++ b/xen/arch/x86/include/asm/bootinfo.h @@ -14,9 +14,21 @@ /* Max number of boot modules a bootloader can provide in addition to Xen */ #define MAX_NR_BOOTMODS 63 +/* Boot module binary type / purpose */ +enum bootmod_type { + BOOTMOD_UNKNOWN, + BOOTMOD_XEN, + BOOTMOD_KERNEL, + BOOTMOD_RAMDISK, + BOOTMOD_MICROCODE, + BOOTMOD_XSM_POLICY, +}; + struct boot_module { /* Transitionary only */ module_t *mod; + + enum bootmod_type type; }; /* diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 5db57e1b1af2..fac08b6242e9 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -316,6 +316,7 @@ static struct boot_info *__init multiboot_fill_boot_info( /* 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; } @@ -1217,6 +1218,7 @@ void asmlinkage __init noreturn __start_xen(void) bitmap_fill(module_map, bi->nr_modules); __clear_bit(0, module_map); /* Dom0 kernel is always first */ + bi->mods[0].type = BOOTMOD_KERNEL; if ( pvh_boot ) { @@ -2097,6 +2099,8 @@ void asmlinkage __init noreturn __start_xen(void) cpu_has_nx ? "" : "not "); initrdidx = find_first_bit(module_map, bi->nr_modules); + if ( initrdidx < bi->nr_modules ) + bi->mods[initrdidx].type = BOOTMOD_RAMDISK; if ( bitmap_weight(module_map, bi->nr_modules) > 1 ) printk(XENLOG_WARNING "Multiple initrd candidates, picking module #%u\n", diff --git a/xen/xsm/xsm_policy.c b/xen/xsm/xsm_policy.c index 35f36c6f2359..4c195411d05b 100644 --- a/xen/xsm/xsm_policy.c +++ b/xen/xsm/xsm_policy.c @@ -59,6 +59,7 @@ int __init xsm_multiboot_policy_init( _policy_len,_policy_start); __clear_bit(i, bi->module_map); + bi->mods[i].type = BOOTMOD_XSM_POLICY; break; } From patchwork Sat Nov 2 17:25:41 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: 13860194 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 2DF5FE67805 for ; Sat, 2 Nov 2024 17:26:40 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.829561.1244564 (Exim 4.92) (envelope-from ) id 1t7HtQ-0005cb-G8; Sat, 02 Nov 2024 17:26:32 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 829561.1244564; Sat, 02 Nov 2024 17:26:32 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t7HtQ-0005cS-CN; Sat, 02 Nov 2024 17:26:32 +0000 Received: by outflank-mailman (input) for mailman id 829561; Sat, 02 Nov 2024 17:26:31 +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 1t7HtP-0004r4-6f for xen-devel@lists.xenproject.org; Sat, 02 Nov 2024 17:26:31 +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 96d410c4-993f-11ef-99a3-01e77a169b0f; Sat, 02 Nov 2024 18:26:27 +0100 (CET) Received: by mx.zohomail.com with SMTPS id 173056836207092.5618760022054; Sat, 2 Nov 2024 10:26:02 -0700 (PDT) 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: 96d410c4-993f-11ef-99a3-01e77a169b0f X-Custom-Connection: eyJyZW1vdGVpcCI6IjEzNi4xNDMuMTg4LjUxIiwiaGVsbyI6InNlbmRlcjQtb2YtbzUxLnpvaG8uY29tIn0= X-Custom-Transaction: eyJpZCI6Ijk2ZDQxMGM0LTk5M2YtMTFlZi05OWEzLTAxZTc3YTE2OWIwZiIsInRzIjoxNzMwNTY4Mzg4LjA1MDgxNCwic2VuZGVyIjoiZHBzbWl0aEBhcGVydHVzc29sdXRpb25zLmNvbSIsInJlY2lwaWVudCI6Inhlbi1kZXZlbEBsaXN0cy54ZW5wcm9qZWN0Lm9yZyJ9 ARC-Seal: i=1; a=rsa-sha256; t=1730568370; cv=none; d=zohomail.com; s=zohoarc; b=dUI3wqdDoph7S1XYVUqdxX/7PlP8MddaQqSm1ootBmufcxdXEaJMqVw8K34vjdI4KBqq7zLwtU7lhEcOH/pWe8Pl3rDZac4Bfc3Hranus3s4scONhAktbyEv87yZu5Az4wq/eBnyIjjKLsFC2PdaVNrexZs11cp56Gkh3xGfEdE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730568370; 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=jNx/3SoBTvToEoU/tE6YgPkXOEv7nkcy+Lso0iBfWHw=; b=UR/wiT+YM+Y65CIH865oeH3gvFR5Nitkv+sVej56QIeOq/9yNljGY1kwA6DqcHJUzLgRHllIOsRZDquPEJKiFzur66RQJkpcxDjm7fcJGWo9+TFkXCJTW5rlyaR1n/A04fEB9uhrrv+ZQLNFqH+noLTReSKnL5dRsQFz9VTGcm8= 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=1730568370; 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=jNx/3SoBTvToEoU/tE6YgPkXOEv7nkcy+Lso0iBfWHw=; b=l2cIrvL8nj8VguIribLhqPtiBZT8nVI2hnN3x49fw0YdwUYHRll3Nat6vQb3GKjp k7BoL9fuw+dFuCLdUokcD19fXNzdwmyaoHVv9iy2bjcn6kNcZP9RYaqwPWUxfkh2S9H R57L9dfAH64Cfb+OKc5fODglwxhOcFPDC0K7XDxE= 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 02/12] x86/boot: eliminate module_map Date: Sat, 2 Nov 2024 13:25:41 -0400 Message-Id: <20241102172551.17233-3-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 X-ZohoMailClient: External With all boot modules now labeled by type, it is no longer necessary to track whether a boot module was identified via the module_map bitmap. Introduce a set of helpers to search the list of boot modules based on type and the reference type, pointer or array index, desired. Then drop all uses of setting a bit in module_map and replace its use for looping with the helpers. Signed-off-by: Daniel P. Smith --- Changes since v7: - collapse the three module_map patches into one, - x86/boot: remove module_map usage from microcode loading - x86/boot: remove module_map usage from xsm policy loading - x86/boot: remove module_map usage by ramdisk loading --- xen/arch/x86/cpu/microcode/core.c | 12 ++++----- xen/arch/x86/include/asm/bootinfo.h | 42 ++++++++++++++++++++++++++++- xen/arch/x86/setup.c | 28 +++++++++++-------- xen/xsm/xsm_policy.c | 19 +++++-------- 4 files changed, 70 insertions(+), 31 deletions(-) diff --git a/xen/arch/x86/cpu/microcode/core.c b/xen/arch/x86/cpu/microcode/core.c index f46464241557..b09cf83249f6 100644 --- a/xen/arch/x86/cpu/microcode/core.c +++ b/xen/arch/x86/cpu/microcode/core.c @@ -790,15 +790,13 @@ static int __init early_microcode_load(struct boot_info *bi) if ( opt_scan ) /* Scan for a CPIO archive */ { - for ( idx = 1; idx < bi->nr_modules; ++idx ) + for_each_boot_module_by_type(idx, bi, BOOTMOD_UNKNOWN) { + struct boot_module *bm = &bi->mods[idx]; struct cpio_data cd; - if ( !test_bit(idx, bi->module_map) ) - continue; - - size = bi->mods[idx].mod->mod_end; - data = bootstrap_map_bm(&bi->mods[idx]); + size = bm->mod->mod_end; + data = bootstrap_map_bm(bm); if ( !data ) { printk(XENLOG_WARNING "Microcode: Could not map module %d, size %zu\n", @@ -840,7 +838,7 @@ static int __init early_microcode_load(struct boot_info *bi) return -ENODEV; } - if ( !__test_and_clear_bit(idx, bi->module_map) ) + if ( bi->mods[idx].type != BOOTMOD_UNKNOWN ) { printk(XENLOG_WARNING "Microcode: Chosen module %d already used\n", idx); return -ENODEV; diff --git a/xen/arch/x86/include/asm/bootinfo.h b/xen/arch/x86/include/asm/bootinfo.h index fc74e3b224e7..37dfcc14fa7d 100644 --- a/xen/arch/x86/include/asm/bootinfo.h +++ b/xen/arch/x86/include/asm/bootinfo.h @@ -43,10 +43,50 @@ struct boot_info { size_t memmap_length; unsigned int nr_modules; - unsigned long *module_map; /* Temporary */ struct boot_module mods[MAX_NR_BOOTMODS + 1]; }; +/* + * next_boot_module_index: + * Finds the next boot module of type t, starting at array index start. + * + * Returns: + * Success - index in boot_module array + * Failure - a value greater than MAX_NR_BOOTMODS + */ +static inline unsigned int __init next_boot_module_index( + const struct boot_info *bi, enum bootmod_type t, unsigned int start) +{ + unsigned int i; + + if ( t == BOOTMOD_XEN ) + return bi->nr_modules; + + for ( i = start; i < bi->nr_modules; i++ ) + { + if ( bi->mods[i].type == t ) + return i; + } + + return MAX_NR_BOOTMODS + 1; +} + +/* + * first_boot_module_index: + * Finds the first boot module of type t. + * + * Returns: + * Success - index in boot_module array + * Failure - a value greater than MAX_NR_BOOTMODS + */ +#define first_boot_module_index(bi, t) \ + next_boot_module_index(bi, t, 0) + +#define for_each_boot_module_by_type(i, b, t) \ + for ( i = first_boot_module_index(b, t); \ + i <= (b)->nr_modules; \ + i = next_boot_module_index(b, t, i + 1) ) + #endif /* X86_BOOTINFO_H */ /* diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index fac08b6242e9..92dbdfe12a3d 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -1034,7 +1034,7 @@ void asmlinkage __init noreturn __start_xen(void) struct cpu_info *info = get_cpu_info(), *bsp_info; unsigned int initrdidx, num_parked = 0; struct boot_info *bi; - unsigned long nr_pages, raw_max_page, modules_headroom, module_map[1]; + unsigned long nr_pages, raw_max_page, modules_headroom; int i, j, e820_warn = 0, bytes = 0; unsigned long eb_start, eb_end; bool acpi_boot_table_init_done = false, relocated = false; @@ -1097,8 +1097,6 @@ void asmlinkage __init noreturn __start_xen(void) ASSERT(multiboot_ptr < MB(1) || xen_phys_start); } - bi->module_map = module_map; /* Temporary */ - /* Parse the command-line options. */ if ( (kextra = strstr(bi->cmdline, " -- ")) != NULL ) { @@ -1216,8 +1214,7 @@ void asmlinkage __init noreturn __start_xen(void) bi->nr_modules); } - bitmap_fill(module_map, bi->nr_modules); - __clear_bit(0, module_map); /* Dom0 kernel is always first */ + /* Dom0 kernel is always first */ bi->mods[0].type = BOOTMOD_KERNEL; if ( pvh_boot ) @@ -2098,13 +2095,22 @@ void asmlinkage __init noreturn __start_xen(void) cpu_has_nx ? XENLOG_INFO : XENLOG_WARNING "Warning: ", cpu_has_nx ? "" : "not "); - initrdidx = find_first_bit(module_map, bi->nr_modules); - if ( initrdidx < bi->nr_modules ) + /* + * At this point all capabilities that consume boot modules should have + * claimed their boot modules. Find the first unclaimed boot module and + * claim it as the initrd ramdisk. Do a second search to see if there are + * any remaining unclaimed boot modules, and report them as unusued initrd + * candidates. + */ + initrdidx = first_boot_module_index(bi, BOOTMOD_UNKNOWN); + if ( initrdidx < MAX_NR_BOOTMODS ) + { bi->mods[initrdidx].type = BOOTMOD_RAMDISK; - if ( bitmap_weight(module_map, bi->nr_modules) > 1 ) - printk(XENLOG_WARNING - "Multiple initrd candidates, picking module #%u\n", - initrdidx); + if ( first_boot_module_index(bi, BOOTMOD_UNKNOWN) < MAX_NR_BOOTMODS ) + printk(XENLOG_WARNING + "Multiple initrd candidates, picking module #%u\n", + initrdidx); + } /* * We're going to setup domain0 using the module(s) that we stashed safely diff --git a/xen/xsm/xsm_policy.c b/xen/xsm/xsm_policy.c index 4c195411d05b..12c9de5a1fbf 100644 --- a/xen/xsm/xsm_policy.c +++ b/xen/xsm/xsm_policy.c @@ -33,22 +33,18 @@ int __init xsm_multiboot_policy_init( struct boot_info *bi, void **policy_buffer, size_t *policy_size) { - int i; + unsigned int i; int rc = 0; u32 *_policy_start; unsigned long _policy_len; - /* - * Try all modules and see whichever could be the binary policy. - * Adjust module_map for the module that is the binary policy. - */ - for ( i = bi->nr_modules - 1; i >= 1; i-- ) + /* Try all unknown modules and see whichever could be the binary policy. */ + for_each_boot_module_by_type(i, bi, BOOTMOD_UNKNOWN) { - if ( !test_bit(i, bi->module_map) ) - continue; + struct boot_module *bm = &bi->mods[i]; - _policy_start = bootstrap_map(bi->mods[i].mod); - _policy_len = bi->mods[i].mod->mod_end; + _policy_start = bootstrap_map(bm->mod); + _policy_len = bm->mod->mod_end; if ( (xsm_magic_t)(*_policy_start) == XSM_MAGIC ) { @@ -58,8 +54,7 @@ int __init xsm_multiboot_policy_init( printk("Policy len %#lx, start at %p.\n", _policy_len,_policy_start); - __clear_bit(i, bi->module_map); - bi->mods[i].type = BOOTMOD_XSM_POLICY; + bm->type = BOOTMOD_XSM_POLICY; break; } From patchwork Sat Nov 2 17:25:42 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: 13860195 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 31A39E67807 for ; Sat, 2 Nov 2024 17:26:48 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.829570.1244574 (Exim 4.92) (envelope-from ) id 1t7Hta-0006Ck-O5; Sat, 02 Nov 2024 17:26:42 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 829570.1244574; Sat, 02 Nov 2024 17:26:42 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t7Hta-0006CY-Ki; Sat, 02 Nov 2024 17:26:42 +0000 Received: by outflank-mailman (input) for mailman id 829570; Sat, 02 Nov 2024 17:26:41 +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 1t7HtZ-0005zO-H2 for xen-devel@lists.xenproject.org; Sat, 02 Nov 2024 17:26:41 +0000 Received: from sender4-of-o51.zoho.com (sender4-of-o51.zoho.com [136.143.188.51]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 9d21230b-993f-11ef-a0c5-8be0dac302b0; Sat, 02 Nov 2024 18:26:38 +0100 (CET) Received: by mx.zohomail.com with SMTPS id 1730568363326833.7879973254649; Sat, 2 Nov 2024 10:26:03 -0700 (PDT) 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: 9d21230b-993f-11ef-a0c5-8be0dac302b0 X-Custom-Connection: eyJyZW1vdGVpcCI6IjEzNi4xNDMuMTg4LjUxIiwiaGVsbyI6InNlbmRlcjQtb2YtbzUxLnpvaG8uY29tIn0= X-Custom-Transaction: eyJpZCI6IjlkMjEyMzBiLTk5M2YtMTFlZi1hMGM1LThiZTBkYWMzMDJiMCIsInRzIjoxNzMwNTY4Mzk5LjA2MDI4Mywic2VuZGVyIjoiZHBzbWl0aEBhcGVydHVzc29sdXRpb25zLmNvbSIsInJlY2lwaWVudCI6Inhlbi1kZXZlbEBsaXN0cy54ZW5wcm9qZWN0Lm9yZyJ9 ARC-Seal: i=1; a=rsa-sha256; t=1730568371; cv=none; d=zohomail.com; s=zohoarc; b=HFi/r/GDxbDE0VePkjwtbYsGJYlfYuTWJfm4B/wZotDKLu0nJs12lIsd+8QHmpHE/QogUi0ekV54vPIoyL9tkYPRHXuTtvxEZP3749r7uu4uk5mTbBMnZ07J6uALm/GkbKgxMRuR+OFV/XbbTvGqPAhKRJ0Tlk3YHQa3ntZa170= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730568371; 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=cldlTjNG2X0IEi+ADcYbrRHkM0Zd7pCxKFfx6gZwAx4=; b=iNk/IFq2UuGeGuMTxhzenE6No3ZT50h/u5jJwhMSESw3bzVnApGuoQhHS9HKu3jNwTt0pAfRFqEmLc3gT82Qs3xlLdoWqOSqgXFwUEC7O4Q2zQA9hmmIT1o/qd92HULNqWOOIrD1N9AaL0HTXlOh9jY/F9OZgWEWGPztLJ0OYJ4= 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=1730568371; 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=cldlTjNG2X0IEi+ADcYbrRHkM0Zd7pCxKFfx6gZwAx4=; b=IqvHUs8veLwEkrbCuInEwuyCIKtdaL/waH4FGQWUz0NYvmSGXPfnK1v/hhvFREn6 0xk0qiMfTGKFUhBT3052KdVw7tWOtC/rqeqfJ+gZtRfMZ3yRODYMx+xr/3Gmh4ectZ8 G/hxksDmuROJNr7jnTP/LPw3B/G0pISSVSwyeAFI= 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 03/12] x86/boot: introduce boot module flags Date: Sat, 2 Nov 2024 13:25:42 -0400 Message-Id: <20241102172551.17233-4-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 X-ZohoMailClient: External The existing startup code employs various ad-hoc state tracking about certain boot module types by each area of the code. A boot module flags bitfield is added to enable tracking these different states. The first state to be transition by this commit is module relocation. Signed-off-by: Daniel P. Smith Reviewed-by: Andrew Cooper --- Changes since v6: - replaced bitmask flags field with the bitfield, relocated - slight update to commit message to mention bitfield - dropped Rb and Ab due to approach change Changes since v5: - removed trailing blank line. --- xen/arch/x86/include/asm/bootinfo.h | 6 ++++++ xen/arch/x86/setup.c | 7 +++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/xen/arch/x86/include/asm/bootinfo.h b/xen/arch/x86/include/asm/bootinfo.h index 37dfcc14fa7d..0fbf36739782 100644 --- a/xen/arch/x86/include/asm/bootinfo.h +++ b/xen/arch/x86/include/asm/bootinfo.h @@ -29,6 +29,12 @@ struct boot_module { module_t *mod; enum bootmod_type type; + + /* + * Module State Flags: + * relocated: indicates module has been relocated in memory. + */ + bool relocated:1; }; /* diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 92dbdfe12a3d..d061ece0541f 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -1392,7 +1392,6 @@ void asmlinkage __init noreturn __start_xen(void) 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; - bi->mods[i].mod->reserved = 0; } /* @@ -1508,7 +1507,7 @@ void asmlinkage __init noreturn __start_xen(void) unsigned long headroom = j ? 0 : modules_headroom; unsigned long size = PAGE_ALIGN(headroom + bm->mod->mod_end); - if ( bm->mod->reserved ) + if ( bm->relocated ) continue; /* Don't overlap with other modules (or Xen itself). */ @@ -1526,7 +1525,7 @@ void asmlinkage __init noreturn __start_xen(void) pfn_to_paddr(bm->mod->mod_start), bm->mod->mod_end); bm->mod->mod_start = (end - size) >> PAGE_SHIFT; bm->mod->mod_end += headroom; - bm->mod->reserved = 1; + bm->relocated = true; } } @@ -1552,7 +1551,7 @@ void asmlinkage __init noreturn __start_xen(void) #endif } - if ( modules_headroom && !bi->mods[0].mod->reserved ) + if ( modules_headroom && !bi->mods[0].relocated ) panic("Not enough memory to relocate the dom0 kernel image\n"); for ( i = 0; i < bi->nr_modules; ++i ) { From patchwork Sat Nov 2 17:25:43 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: 13860196 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 4E83BE67807 for ; Sat, 2 Nov 2024 17:27:02 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.829575.1244584 (Exim 4.92) (envelope-from ) id 1t7Htl-0006nI-Vl; Sat, 02 Nov 2024 17:26:53 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 829575.1244584; Sat, 02 Nov 2024 17:26:53 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t7Htl-0006n9-Su; Sat, 02 Nov 2024 17:26:53 +0000 Received: by outflank-mailman (input) for mailman id 829575; Sat, 02 Nov 2024 17:26:52 +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 1t7Htk-0005zO-8V for xen-devel@lists.xenproject.org; Sat, 02 Nov 2024 17:26:52 +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 a396f37c-993f-11ef-a0c5-8be0dac302b0; Sat, 02 Nov 2024 18:26:49 +0100 (CET) Received: by mx.zohomail.com with SMTPS id 1730568365486995.6070687004028; Sat, 2 Nov 2024 10:26:05 -0700 (PDT) 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: a396f37c-993f-11ef-a0c5-8be0dac302b0 X-Custom-Connection: eyJyZW1vdGVpcCI6IjEzNi4xNDMuMTg0LjU3IiwiaGVsbyI6InNlbmRlcjMtb2YtbzU3LnpvaG8uY29tIn0= X-Custom-Transaction: eyJpZCI6ImEzOTZmMzdjLTk5M2YtMTFlZi1hMGM1LThiZTBkYWMzMDJiMCIsInRzIjoxNzMwNTY4NDA5LjYyODEzLCJzZW5kZXIiOiJkcHNtaXRoQGFwZXJ0dXNzb2x1dGlvbnMuY29tIiwicmVjaXBpZW50IjoieGVuLWRldmVsQGxpc3RzLnhlbnByb2plY3Qub3JnIn0= ARC-Seal: i=1; a=rsa-sha256; t=1730568372; cv=none; d=zohomail.com; s=zohoarc; b=h/d0e3JJo5w/7SvCKkTsi3kCw1xMIg8Phnq0Njv6Wl0Q/9BrhL158pOX3T7pZQ+0H2UUPYcYfMZgc2gc268WkKjjkWpxUQXxNoJX2cTzijobcWKoMbeMDSTVGUxNue9K9j4GRWgdCfieDnfbhSfohV9gL4QyA2IKDHFIGg2b2lE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730568372; 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=hUGH3RDsDf1IJruHP2Kvrv3CdfGhOfh0xY63XM5AYas=; b=gZZtJEuxMXMNrVyxcAP6O2chvCiJfrc7gsDUVuXG9MI1lPLJndg5ATz/qck2kl3CaQiS3cK4WX5enpk/8nwFN2cIFk/9kVcqr6z+uGKMSDMJtMpdPBOiBquLCGRSaKmzY9qMdcm9bPurx42zCODzr59yZeghm6ZP+YAE1NTMAcM= 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=1730568372; 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=hUGH3RDsDf1IJruHP2Kvrv3CdfGhOfh0xY63XM5AYas=; b=MckSqtGkfpRDMv8MtYbE5UcHK+4ijbl57rLme/js6NhApym2d9OrnAlDLbdpVFZQ dD4mis2Fi5VWLQ/WNfERxuLCVoL+F0mNMPeG4MT1Vt8R+WCefZlrgzeIvGrh2jHQdnd ctZ7oZ9a4DOzO7S4dxVNcJXI2FK513pmX3PTqLsE= 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 04/12] x86/boot: introduce module release Date: Sat, 2 Nov 2024 13:25:43 -0400 Message-Id: <20241102172551.17233-5-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 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 explicitly copied into the dom0 address space. So to handle this situation, 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. A function is introduced to release a module when it is no longer needed that accepts a boolean parameter, free_mem, to indicate if the corresponding pages can be freed. To track that a module has been released, the boot module flag `released` is introduced. The previous release model was a free all at once except those of size zeros, which would handle any unused modules passed. The new model is one of, free consumed module after usage is complete, thus unconsumed modules do not have a consumer to free them. To address this, the discard_uknown_boot_modules() is introduced and called after the last module identification occurs, initrd, to free the pages of any boot modules that are identified as not being released. After domain construction completes, all modules should be freed. A walk of the boot modules is added after domain construction to validate and notify if a module is found not to have been released. Signed-off-by: Daniel P. Smith --- Changes since v7: - This is a new approach as an alternative to the `consumed` flag. --- xen/arch/x86/cpu/microcode/core.c | 4 ++ xen/arch/x86/hvm/dom0_build.c | 7 ++-- xen/arch/x86/include/asm/bootinfo.h | 2 + xen/arch/x86/include/asm/setup.h | 3 +- xen/arch/x86/pv/dom0_build.c | 20 ++-------- xen/arch/x86/setup.c | 57 +++++++++++++++++++++++------ xen/xsm/xsm_core.c | 5 +++ 7 files changed, 67 insertions(+), 31 deletions(-) diff --git a/xen/arch/x86/cpu/microcode/core.c b/xen/arch/x86/cpu/microcode/core.c index b09cf83249f6..349e857f539a 100644 --- a/xen/arch/x86/cpu/microcode/core.c +++ b/xen/arch/x86/cpu/microcode/core.c @@ -756,6 +756,10 @@ static int __init cf_check microcode_init_cache(void) return rc; } + /* If raw module, we can free it now */ + if ( !opt_scan ) + release_boot_module(&bi->mods[early_mod_idx], true); + if ( !patch ) return -ENOENT; diff --git a/xen/arch/x86/hvm/dom0_build.c b/xen/arch/x86/hvm/dom0_build.c index 3dd913bdb029..a4ac262db463 100644 --- a/xen/arch/x86/hvm/dom0_build.c +++ b/xen/arch/x86/hvm/dom0_build.c @@ -704,6 +704,8 @@ static int __init pvh_load_kernel(struct domain *d, const module_t *image, return rc; } + release_module(image, true); + /* * Find a RAM region big enough (and that doesn't overlap with the loaded * kernel) in order to load the initrd and the metadata. Note it could be @@ -751,10 +753,9 @@ static int __init pvh_load_kernel(struct domain *d, const module_t *image, last_addr += len; } last_addr = ROUNDUP(last_addr, PAGE_SIZE); - } - /* Free temporary buffers. */ - discard_initial_images(); + release_module(initrd, true); + } if ( cmdline != NULL ) { diff --git a/xen/arch/x86/include/asm/bootinfo.h b/xen/arch/x86/include/asm/bootinfo.h index 0fbf36739782..b1549d8c8f93 100644 --- a/xen/arch/x86/include/asm/bootinfo.h +++ b/xen/arch/x86/include/asm/bootinfo.h @@ -33,8 +33,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; }; /* diff --git a/xen/arch/x86/include/asm/setup.h b/xen/arch/x86/include/asm/setup.h index d7ed4f40024c..d68d37a5293b 100644 --- a/xen/arch/x86/include/asm/setup.h +++ b/xen/arch/x86/include/asm/setup.h @@ -36,12 +36,13 @@ 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 release_module(const module_t *m, bool mapped); 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, bool mapped); 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 cc882bee61c3..c1f44502a1ac 100644 --- a/xen/arch/x86/pv/dom0_build.c +++ b/xen/arch/x86/pv/dom0_build.c @@ -630,9 +630,7 @@ static int __init dom0_construct(struct domain *d, } memcpy(page_to_virt(page), mfn_to_virt(initrd->mod_start), initrd_len); - mpt_alloc = (paddr_t)initrd->mod_start << PAGE_SHIFT; - init_domheap_pages(mpt_alloc, - mpt_alloc + PAGE_ALIGN(initrd_len)); + release_module(initrd, true); initrd->mod_start = initrd_mfn = mfn_x(page_to_mfn(page)); } else @@ -640,18 +638,9 @@ static int __init dom0_construct(struct domain *d, while ( count-- ) if ( assign_pages(mfn_to_page(_mfn(mfn++)), 1, d, 0) ) BUG(); + release_module(initrd, false); } - /* - * 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_end = 0; - iommu_memory_setup(d, "initrd", mfn_to_page(_mfn(initrd_mfn)), PFN_UP(initrd_len), &flush_flags); } @@ -839,7 +828,9 @@ static int __init dom0_construct(struct domain *d, printk("Failed to load the kernel binary\n"); goto out; } + /* All done with kernel, release the module pages */ bootstrap_unmap(); + release_module(image, true); if ( UNSET_ADDR != parms.virt_hypercall ) { @@ -854,9 +845,6 @@ static int __init dom0_construct(struct domain *d, init_hypercall_page(d, _p(parms.virt_hypercall)); } - /* Free temporary buffers. */ - discard_initial_images(); - /* Set up start info area. */ si = (start_info_t *)vstartinfo_start; clear_page(si); diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index d061ece0541f..e6d2d25fd038 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -341,27 +341,55 @@ 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, bool free_mem) +{ + uint64_t start = pfn_to_paddr(bm->mod->mod_start); + uint64_t size = bm->mod->mod_end; + + if ( bm->released ) + { + printk(XENLOG_WARNING "Attempt second release boot module of type %d\n", + bm->type); + return; + } + + if ( free_mem ) + init_domheap_pages(start, start + PAGE_ALIGN(size)); + + bm->released = true; +} + +void __init release_module(const module_t *m, bool free_mem) { struct boot_info *bi = &xen_boot_info; unsigned int i; - for ( i = 0; i < bi->nr_modules; ++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; + if ( bi->mods[i].mod == m ) + release_boot_module(&bi->mods[i], free_mem); + } +} - /* - * 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 ) +static void __init discard_unknown_boot_modules(void) +{ + struct boot_info *bi = &xen_boot_info; + unsigned int i, count = 0; + + for_each_boot_module_by_type(i, bi, BOOTMOD_UNKNOWN) + { + struct boot_module *bm = &bi->mods[i]; + + if ( bm == NULL || bm->released ) continue; - init_domheap_pages(start, start + PAGE_ALIGN(size)); + release_boot_module(bm, true); + count++; } - bi->nr_modules = 0; + if ( count ) + printk(XENLOG_DEBUG "Releasing pages for uknown boot module %d\n", + count); } static void __init init_idle_domain(void) @@ -2111,6 +2139,8 @@ void asmlinkage __init noreturn __start_xen(void) initrdidx); } + discard_unknown_boot_modules(); + /* * 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. @@ -2122,6 +2152,11 @@ void asmlinkage __init noreturn __start_xen(void) if ( !dom0 ) panic("Could not set up DOM0 guest OS\n"); + /* Check and warn if any modules did not get released */ + for ( i = 0; i < bi->nr_modules; i++ ) + if ( !bi->mods[i].released ) + printk(XENLOG_ERR "Boot module %d not released, memory leaked", i); + heap_init_late(); init_trace_bufs(); diff --git a/xen/xsm/xsm_core.c b/xen/xsm/xsm_core.c index f255fb63bf6f..d5875599b63a 100644 --- a/xen/xsm/xsm_core.c +++ b/xen/xsm/xsm_core.c @@ -162,6 +162,11 @@ int __init xsm_multiboot_init(struct boot_info *bi) ret = xsm_core_init(policy_buffer, policy_size); bootstrap_unmap(); + /* If the policy was loaded from a boot module, release it's memory */ + ret = first_boot_module_index(bi, BOOTMOD_XSM_POLICY); + if ( ret >= 0 && ret < bi->nr_modules ) + release_boot_module(&bi->mods[ret], true); + return 0; } #endif From patchwork Sat Nov 2 17:25:44 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: 13860197 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 D5788E67805 for ; Sat, 2 Nov 2024 17:27:10 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.829582.1244594 (Exim 4.92) (envelope-from ) id 1t7Htv-0007N3-CH; Sat, 02 Nov 2024 17:27:03 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 829582.1244594; Sat, 02 Nov 2024 17:27:03 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t7Htv-0007Mu-9Z; Sat, 02 Nov 2024 17:27:03 +0000 Received: by outflank-mailman (input) for mailman id 829582; Sat, 02 Nov 2024 17:27:02 +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 1t7Htu-0005zO-3A for xen-devel@lists.xenproject.org; Sat, 02 Nov 2024 17:27:02 +0000 Received: from sender4-of-o51.zoho.com (sender4-of-o51.zoho.com [136.143.188.51]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id a999790a-993f-11ef-a0c5-8be0dac302b0; Sat, 02 Nov 2024 18:26:59 +0100 (CET) Received: by mx.zohomail.com with SMTPS id 1730568366662651.7865909718565; Sat, 2 Nov 2024 10:26:06 -0700 (PDT) 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: a999790a-993f-11ef-a0c5-8be0dac302b0 X-Custom-Connection: eyJyZW1vdGVpcCI6IjEzNi4xNDMuMTg4LjUxIiwiaGVsbyI6InNlbmRlcjQtb2YtbzUxLnpvaG8uY29tIn0= X-Custom-Transaction: eyJpZCI6ImE5OTk3OTBhLTk5M2YtMTFlZi1hMGM1LThiZTBkYWMzMDJiMCIsInRzIjoxNzMwNTY4NDE5Ljk1MTM0Nywic2VuZGVyIjoiZHBzbWl0aEBhcGVydHVzc29sdXRpb25zLmNvbSIsInJlY2lwaWVudCI6Inhlbi1kZXZlbEBsaXN0cy54ZW5wcm9qZWN0Lm9yZyJ9 ARC-Seal: i=1; a=rsa-sha256; t=1730568379; cv=none; d=zohomail.com; s=zohoarc; b=MDs4UQlt+6cs2MV/bWPoLf5yewGv93jWyeHDuTpMW6SgVw2/JVod3CnrXWklN+pLDNKziIrJb9KVATzKRFkUxkZuokVak1GIfmKZI8C6K8lL4qVUVKMQvzDVcxyKnTcW8d8bizs3lctc4ihG6PjNksGe4w3eCDaSWz0e9tKJjfA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730568379; 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=IkU4V9zheGmMbE9F1wh08/Ap7m7WOTpvdQ1/oa+ZpD8=; b=NYUw0b5xZJxFu0ddjhlUI0/2WD7p6PD+ndizVHfUaKOUjDxTg6o37hSHMrVklqUupX1pb8ndpRoyshKCX3LozvxiX9tuIkFeW98JQlrstT6VeeOjEWD3E05Ze6bKbb1OvZ1oVbclB4EBK45mjibU9ChedPKOPJc7+66XjfI9NVY= 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=1730568379; 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=IkU4V9zheGmMbE9F1wh08/Ap7m7WOTpvdQ1/oa+ZpD8=; b=dY/uCFEpDm5b3izFTvNScs7KUuXIQXWi+S3qUfNUXqYyvWtVqtXq5U4KZBgoYpWm 7yu8yXnXIPkgY+3iIqTr8+eMc42UmqB7W/nMPpmqS60p3qKtUgOwx3JxaQOFQC9yqTE J7hmKJGntWDgOtQuwd956fZieo6gAi52IyUFQocc= 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 05/12] x86/boot: move headroom to boot modules Date: Sat, 2 Nov 2024 13:25:44 -0400 Message-Id: <20241102172551.17233-6-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 X-ZohoMailClient: External The purpose of struct boot_module is to encapsulate the state of boot module as it is processed by Xen. Locating boot module state struct boot_module reduces the number of global variables as well as the number of state variables that must be passed around. It also lays the groundwork for hyperlaunch mult-domain construction, where multiple instances of state variables like headroom will be needed. Signed-off-by: Daniel P. Smith Reviewed-by: Jason Andryuk --- Changes since v7: - adopted headroom comment from Andy Cooper Changes since v6: - add blank line to separate comment from line above it Changes since v5: - reword and expand comment on headroom - consolidated declaration and assignment --- xen/arch/x86/include/asm/bootinfo.h | 22 ++++++++++++++++++++++ xen/arch/x86/setup.c | 23 ++++++++--------------- 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/xen/arch/x86/include/asm/bootinfo.h b/xen/arch/x86/include/asm/bootinfo.h index b1549d8c8f93..e337baa905f0 100644 --- a/xen/arch/x86/include/asm/bootinfo.h +++ b/xen/arch/x86/include/asm/bootinfo.h @@ -30,6 +30,28 @@ struct boot_module { enum bootmod_type type; + /* + * A boot module may need decompressing by Xen. Headroom is an estimate of + * the additional space required to decompress the module. + * + * Headroom is accounted for at the start of the module. Decompressing is + * done in-place with input=start, output=start-headroom, expecting the + * pointers to become equal (give or take some rounding) when decompression + * is complete. + * + * Memory layout at boot: + * + * start ----+ + * v + * |<-----headroom------>|<------size------->| + * +-------------------+ + * | Compressed Module | + * +---------------------+-------------------+ + * | Decompressed Module | + * +-----------------------------------------+ + */ + unsigned long headroom; + /* * Module State Flags: * relocated: indicates module has been relocated in memory. diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index e6d2d25fd038..633319d39d80 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -1062,7 +1062,7 @@ void asmlinkage __init noreturn __start_xen(void) struct cpu_info *info = get_cpu_info(), *bsp_info; unsigned int initrdidx, num_parked = 0; struct boot_info *bi; - unsigned long nr_pages, raw_max_page, modules_headroom; + unsigned long nr_pages, raw_max_page; int i, j, e820_warn = 0, bytes = 0; unsigned long eb_start, eb_end; bool acpi_boot_table_init_done = false, relocated = false; @@ -1443,7 +1443,7 @@ void asmlinkage __init noreturn __start_xen(void) xen->mod->mod_end = __2M_rwdata_end - _stext; } - modules_headroom = + bi->mods[0].headroom = bzimage_headroom(bootstrap_map_bm(&bi->mods[0]), bi->mods[0].mod->mod_end); bootstrap_unmap(); @@ -1526,14 +1526,7 @@ void asmlinkage __init noreturn __start_xen(void) for ( j = bi->nr_modules - 1; j >= 0; j-- ) { struct boot_module *bm = &bi->mods[j]; - - /* - * 'headroom' is a guess for the decompressed size and - * decompressor overheads of mod[0] (the dom0 kernel). When we - * move mod[0], we incorporate this as extra space at the start. - */ - unsigned long headroom = j ? 0 : modules_headroom; - unsigned long size = PAGE_ALIGN(headroom + bm->mod->mod_end); + unsigned long size = PAGE_ALIGN(bm->headroom + bm->mod->mod_end); if ( bm->relocated ) continue; @@ -1546,13 +1539,13 @@ void asmlinkage __init noreturn __start_xen(void) continue; if ( s < end && - (headroom || + (bm->headroom || ((end - size) >> PAGE_SHIFT) > bm->mod->mod_start) ) { - move_memory(end - size + headroom, + 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 += headroom; + bm->mod->mod_end += bm->headroom; bm->relocated = true; } } @@ -1579,7 +1572,7 @@ void asmlinkage __init noreturn __start_xen(void) #endif } - if ( modules_headroom && !bi->mods[0].relocated ) + if ( bi->mods[0].headroom && !bi->mods[0].relocated ) panic("Not enough memory to relocate the dom0 kernel image\n"); for ( i = 0; i < bi->nr_modules; ++i ) { @@ -2145,7 +2138,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, modules_headroom, + dom0 = create_dom0(bi->mods[0].mod, bi->mods[0].headroom, initrdidx < bi->nr_modules ? bi->mods[initrdidx].mod : NULL, kextra, bi->loader); From patchwork Sat Nov 2 17:25:45 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: 13860201 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 2FF74E677E8 for ; Sat, 2 Nov 2024 17:37:47 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.829614.1244624 (Exim 4.92) (envelope-from ) id 1t7I49-0002a7-Rb; Sat, 02 Nov 2024 17:37:37 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 829614.1244624; Sat, 02 Nov 2024 17:37:37 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t7I49-0002a0-Oo; Sat, 02 Nov 2024 17:37:37 +0000 Received: by outflank-mailman (input) for mailman id 829614; Sat, 02 Nov 2024 17:37:36 +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 1t7Hu3-0005zO-Ly for xen-devel@lists.xenproject.org; Sat, 02 Nov 2024 17:27:11 +0000 Received: from sender4-of-o51.zoho.com (sender4-of-o51.zoho.com [136.143.188.51]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id aef35b32-993f-11ef-a0c5-8be0dac302b0; Sat, 02 Nov 2024 18:27:08 +0100 (CET) Received: by mx.zohomail.com with SMTPS id 1730568368262930.5138048817796; Sat, 2 Nov 2024 10:26:08 -0700 (PDT) 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: aef35b32-993f-11ef-a0c5-8be0dac302b0 X-Custom-Connection: eyJyZW1vdGVpcCI6IjEzNi4xNDMuMTg4LjUxIiwiaGVsbyI6InNlbmRlcjQtb2YtbzUxLnpvaG8uY29tIn0= X-Custom-Transaction: eyJpZCI6ImFlZjM1YjMyLTk5M2YtMTFlZi1hMGM1LThiZTBkYWMzMDJiMCIsInRzIjoxNzMwNTY4NDI4Ljk0MTQxMSwic2VuZGVyIjoiZHBzbWl0aEBhcGVydHVzc29sdXRpb25zLmNvbSIsInJlY2lwaWVudCI6Inhlbi1kZXZlbEBsaXN0cy54ZW5wcm9qZWN0Lm9yZyJ9 ARC-Seal: i=1; a=rsa-sha256; t=1730568380; cv=none; d=zohomail.com; s=zohoarc; b=eseagGIWxSDS05FvDZ1vaX8iLM4KFZPv5hQwSOpgiaW1krIObSkWnLUcPHkjQjtNkpPznvEmBW8576Sips77kyH7RVKF65oOJFw7GAZlappArKt8pdu4LMM5f4CvwsBg8RQS9uVlFSdH3fHI/udJKiH9lcYhewpCvhyoBykff28= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730568380; 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=9OF7jr3+XP9qd3JfzPB9uF0lHAJIr0GJpZTZwT478GE=; b=l2nApuwB+FebU4gSAE8VsY+yHxacx1YWedZy26toqYRn2/JHxE1A32b5SaMYwjpXlE9n+8d5eFAz9+FA+w2iXhRFILFzuqQvsLk9wsTAcoqQ1xlT1YcSL5Vep/z92+9NWAWvuzDrPQHl6Bx0izxgzMT2KxHtdcUiZvgJAVevE6k= 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=1730568380; 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=9OF7jr3+XP9qd3JfzPB9uF0lHAJIr0GJpZTZwT478GE=; b=RhvDDm3GI4rx4r3df+BhgoYdgln8UhlBBLXT0tZUOPxOw1cq/6osnOdYt1NjTB4U XNJZtLi9KnCkU2AWv3TR6pscoLvbpkPDofcfFEMC4bphO4j27vQUH4eqwMbL2kaD8Vi n7IENw/XiWaBp7HQdvlI9czN/h1r640bDLZcYhVA= 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 06/12] x86/boot: relocate kextra into boot info Date: Sat, 2 Nov 2024 13:25:45 -0400 Message-Id: <20241102172551.17233-7-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 X-ZohoMailClient: External Move kextra into struct boot_info, thus no longer needed to be passed as a parameter to create_dom0. Signed-off-by: Daniel P. Smith Reviewed-by: Jason Andryuk --- xen/arch/x86/include/asm/bootinfo.h | 1 + xen/arch/x86/setup.c | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/include/asm/bootinfo.h b/xen/arch/x86/include/asm/bootinfo.h index e337baa905f0..6638da597073 100644 --- a/xen/arch/x86/include/asm/bootinfo.h +++ b/xen/arch/x86/include/asm/bootinfo.h @@ -68,6 +68,7 @@ struct boot_module { struct boot_info { const char *loader; const char *cmdline; + const char *kextra; paddr_t memmap_addr; size_t memmap_length; diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 633319d39d80..425467a0d977 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -1136,6 +1136,7 @@ void asmlinkage __init noreturn __start_xen(void) *kextra = '\0'; kextra += 3; while ( kextra[1] == ' ' ) kextra++; + bi->kextra = kextra; } cmdline_parse(bi->cmdline); @@ -2141,7 +2142,7 @@ void asmlinkage __init noreturn __start_xen(void) dom0 = create_dom0(bi->mods[0].mod, bi->mods[0].headroom, initrdidx < bi->nr_modules ? bi->mods[initrdidx].mod : NULL, - kextra, bi->loader); + bi->kextra, bi->loader); if ( !dom0 ) panic("Could not set up DOM0 guest OS\n"); From patchwork Sat Nov 2 17:25:46 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: 13860203 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 AE4B7E677E8 for ; Sat, 2 Nov 2024 17:38:04 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.829623.1244654 (Exim 4.92) (envelope-from ) id 1t7I4R-0003wk-Na; Sat, 02 Nov 2024 17:37:55 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 829623.1244654; Sat, 02 Nov 2024 17:37:55 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t7I4R-0003w6-Jw; Sat, 02 Nov 2024 17:37:55 +0000 Received: by outflank-mailman (input) for mailman id 829623; Sat, 02 Nov 2024 17:37:53 +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 1t7HuB-0005zO-5n for xen-devel@lists.xenproject.org; Sat, 02 Nov 2024 17:27:19 +0000 Received: from sender4-of-o51.zoho.com (sender4-of-o51.zoho.com [136.143.188.51]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id b41bade3-993f-11ef-a0c5-8be0dac302b0; Sat, 02 Nov 2024 18:27:17 +0100 (CET) Received: by mx.zohomail.com with SMTPS id 1730568370382770.7062276164702; Sat, 2 Nov 2024 10:26:10 -0700 (PDT) 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: b41bade3-993f-11ef-a0c5-8be0dac302b0 X-Custom-Connection: eyJyZW1vdGVpcCI6IjEzNi4xNDMuMTg4LjUxIiwiaGVsbyI6InNlbmRlcjQtb2YtbzUxLnpvaG8uY29tIn0= X-Custom-Transaction: eyJpZCI6ImI0MWJhZGUzLTk5M2YtMTFlZi1hMGM1LThiZTBkYWMzMDJiMCIsInRzIjoxNzMwNTY4NDM3LjQxNjQzMiwic2VuZGVyIjoiZHBzbWl0aEBhcGVydHVzc29sdXRpb25zLmNvbSIsInJlY2lwaWVudCI6Inhlbi1kZXZlbEBsaXN0cy54ZW5wcm9qZWN0Lm9yZyJ9 ARC-Seal: i=1; a=rsa-sha256; t=1730568381; cv=none; d=zohomail.com; s=zohoarc; b=Pv3kCvtoVTibz+u51wsTPJ5JitINxwAOpevWtkWjGtA+JWT3fCFys7qKisjDpRspKF8cE6Na4u4P4sAYgIvXnib8ogDHD7qa917MB6/CKAkrP9LxqenNtAEhstgVWQeMv9GFHykAYSXCk45kqYNj+YV3iKZ79QN/5kMnAkvkMVM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730568381; 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=EoeU2cNTcSm145aYChZTxXF4zyu19NL3WvcyiomLUIo=; b=VmD2X8mPFmLcbOXuactLxKobkuST/Ivf/owiVPogZTbNDA3U5hp6bXL1jUgkZu6svuNJ7CgpT12T7bvzAHC7dOzDsvQgoyVZr5UkGhPnu5jfqd9ZaXpnoMeb7xvcETzJ4QJxzBCwaUVA+W98zWzUN+JqxTTBeZNNCJcISAWeGxg= 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=1730568381; 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=EoeU2cNTcSm145aYChZTxXF4zyu19NL3WvcyiomLUIo=; b=ZZPR73ighyafEVqyrtsLosPv4w8AMkNG1vIMUwR2wEX8gS0HeRb6MWv+rm27fc02 IJSeCj0PKuKslzoyprxSm0jNIFoT0D+RsLnQUKgXmx649F5vHK55RlKrj6XbThwT6kO iMW89A6SL33oOQ6BczXIstFLxYVy1kgZZBPlfw6c= 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 07/12] x86/boot: add cmdline_pa to struct boot_module Date: Sat, 2 Nov 2024 13:25:46 -0400 Message-Id: <20241102172551.17233-8-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 X-ZohoMailClient: External Add an address field, cmdline_pa, to struct boot_module to hold the address of the string field from struct mod. Signed-off-by: Daniel P. Smith Reviewed-by: Jason Andryuk --- Changes since v7: - renamed cmdline to cmdline_pa - reword commit message for field rename Changes since v5: - changed boot_module element cmdline to paddr_t --- xen/arch/x86/include/asm/bootinfo.h | 2 ++ xen/arch/x86/setup.c | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/xen/arch/x86/include/asm/bootinfo.h b/xen/arch/x86/include/asm/bootinfo.h index 6638da597073..819c8224d715 100644 --- a/xen/arch/x86/include/asm/bootinfo.h +++ b/xen/arch/x86/include/asm/bootinfo.h @@ -59,6 +59,8 @@ struct boot_module { */ bool relocated:1; bool released:1; + + paddr_t cmdline_pa; }; /* diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 425467a0d977..aba9df8620ef 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -312,8 +312,12 @@ static struct boot_info *__init multiboot_fill_boot_info( * reserved for Xen. */ 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; + } + /* Variable 'i' should be one entry past the last module. */ bi->mods[i].mod = &mods[bi->nr_modules]; bi->mods[i].type = BOOTMOD_XEN; From patchwork Sat Nov 2 17:25:47 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: 13860198 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 70ED9E67805 for ; Sat, 2 Nov 2024 17:36:48 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.829598.1244604 (Exim 4.92) (envelope-from ) id 1t7I31-00019U-8X; Sat, 02 Nov 2024 17:36:27 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 829598.1244604; 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-00019N-5s; Sat, 02 Nov 2024 17:36:27 +0000 Received: by outflank-mailman (input) for mailman id 829598; Sat, 02 Nov 2024 17:36:26 +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 1t7HuK-0005zO-6m for xen-devel@lists.xenproject.org; Sat, 02 Nov 2024 17:27:28 +0000 Received: from sender4-of-o51.zoho.com (sender4-of-o51.zoho.com [136.143.188.51]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id b9042e17-993f-11ef-a0c5-8be0dac302b0; Sat, 02 Nov 2024 18:27:25 +0100 (CET) Received: by mx.zohomail.com with SMTPS id 1730568371686592.9410739240645; Sat, 2 Nov 2024 10:26:11 -0700 (PDT) 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: b9042e17-993f-11ef-a0c5-8be0dac302b0 X-Custom-Connection: eyJyZW1vdGVpcCI6IjEzNi4xNDMuMTg4LjUxIiwiaGVsbyI6InNlbmRlcjQtb2YtbzUxLnpvaG8uY29tIn0= X-Custom-Transaction: eyJpZCI6ImI5MDQyZTE3LTk5M2YtMTFlZi1hMGM1LThiZTBkYWMzMDJiMCIsInRzIjoxNzMwNTY4NDQ1LjYwOTg4OCwic2VuZGVyIjoiZHBzbWl0aEBhcGVydHVzc29sdXRpb25zLmNvbSIsInJlY2lwaWVudCI6Inhlbi1kZXZlbEBsaXN0cy54ZW5wcm9qZWN0Lm9yZyJ9 ARC-Seal: i=1; a=rsa-sha256; t=1730568382; cv=none; d=zohomail.com; s=zohoarc; b=mTxocaw2aTmmjbtNyLxeZlPAg6zz7wgDZuCq2P1ZmgTQ318SnYwvsHxs++ub8gBGADVllyy8TIp0jNLmAPUnVxrxqbAsG1jWeEOWQef07ePN2dmsbPYYcnKzYh3Gtptlfr7VPy2AiZvbG8jaEJ4MBL3tzWvkGS/VgyMx9VDjE3U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730568382; 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=Lqch7F1xargZBo/VkvL/BtzwFfKefeZoUmZw1HodarM=; b=QTwU7SPpLluNGZbz96hnXDrB1BK94BqPuCfkrHryY5Vf5qq5eUThL9vib1sGfIIH18tMkvh4M4RSvzCWYbxbLQGi2U6VhorARbRR1HcNsPFv73KKHewL0HqnLizN0rJLfznKZE9YuxoXaGMfNG1MoTNx/VffnszhOk0ahOyvwqI= 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=1730568382; 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=Lqch7F1xargZBo/VkvL/BtzwFfKefeZoUmZw1HodarM=; b=GyszozVMlcznzwc55Q8draW6XhURdi9eZotdbZmL4ZVrD/Rq4qmnsP81psy67uFb IV2Jjy26eexd9JM/W1IcwlHx4PP29dmLiBKHRpjtJ4JJujhNyNto7Q4A95fus7N/3yg X93HiWdGd9yUAn4CuFyqS2pd0w5T4BahotUszOHk= 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 08/12] x86/boot: convert domain construction to use boot info Date: Sat, 2 Nov 2024 13:25:47 -0400 Message-Id: <20241102172551.17233-9-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 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 --- Changes since v5: - 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 | 9 ++-- xen/arch/x86/hvm/dom0_build.c | 49 +++++++++++++--------- xen/arch/x86/include/asm/dom0_build.h | 13 ++---- xen/arch/x86/include/asm/setup.h | 7 ++-- xen/arch/x86/pv/dom0_build.c | 59 ++++++++++++++++----------- xen/arch/x86/setup.c | 33 ++++++++------- 6 files changed, 95 insertions(+), 75 deletions(-) diff --git a/xen/arch/x86/dom0_build.c b/xen/arch/x86/dom0_build.c index 8d56705a0861..2276965c02bd 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,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 +609,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 a4ac262db463..cd97f94a168a 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; @@ -704,7 +705,7 @@ static int __init pvh_load_kernel(struct domain *d, const module_t *image, return rc; } - release_module(image, true); + release_boot_module(image, true); /* * Find a RAM region big enough (and that doesn't overlap with the loaded @@ -727,8 +728,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"); @@ -738,9 +739,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); @@ -754,7 +755,7 @@ static int __init pvh_load_kernel(struct domain *d, const module_t *image, } last_addr = ROUNDUP(last_addr, PAGE_SIZE); - release_module(initrd, true); + release_boot_module(initrd, true); } if ( cmdline != NULL ) @@ -1301,16 +1302,25 @@ 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; int rc; printk(XENLOG_INFO "*** Building a PVH Dom%d ***\n", d->domain_id); + rc = first_boot_module_index(bi, BOOTMOD_KERNEL); + if ( unlikely(rc < 0 || rc > bi->nr_modules) ) + panic("Missing kernel boot module for %pd construction\n", d); + + image = &bi->mods[rc]; + + rc = first_boot_module_index(bi, BOOTMOD_RAMDISK); + if ( rc > 0 || rc < bi->nr_modules ) + initrd = &bi->mods[rc]; + if ( is_hardware_domain(d) ) { /* @@ -1348,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..4c2193c4a982 100644 --- a/xen/arch/x86/include/asm/dom0_build.h +++ b/xen/arch/x86/include/asm/dom0_build.h @@ -13,15 +13,10 @@ 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 d68d37a5293b..1e23f55be51b 100644 --- a/xen/arch/x86/include/asm/setup.h +++ b/xen/arch/x86/include/asm/setup.h @@ -26,11 +26,10 @@ void subarch_init_memory(void); void init_IRQ(void); +struct boot_info; int construct_dom0( - struct domain *d, - const module_t *image, unsigned long image_headroom, - module_t *initrd, - const char *cmdline); + 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 c1f44502a1ac..594874cd8d85 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,11 +355,7 @@ 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; bool compatible, compat; @@ -374,10 +371,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 +414,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 ( unlikely(i < 0 || 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 > 0 || 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 +630,7 @@ 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 = mfn = initrd->mod->mod_start; count = PFN_UP(initrd_len); if ( d->arch.physaddr_bitsize && ((mfn + count - 1) >> (d->arch.physaddr_bitsize - PAGE_SHIFT)) ) @@ -628,17 +645,17 @@ 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); - release_module(initrd, true); - initrd->mod_start = initrd_mfn = mfn_x(page_to_mfn(page)); + release_boot_module(initrd, true); + initrd->mod->mod_start = initrd_mfn = mfn_x(page_to_mfn(page)); } else { while ( count-- ) if ( assign_pages(mfn_to_page(_mfn(mfn++)), 1, d, 0) ) BUG(); - release_module(initrd, false); + release_boot_module(initrd, false); } iommu_memory_setup(d, "initrd", mfn_to_page(_mfn(initrd_mfn)), @@ -653,7 +670,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 = (paddr_t)initrd->mod->mod_start << PAGE_SHIFT; printk("\n Init. ramdisk: %"PRIpaddr"->%"PRIpaddr, mpt_alloc, mpt_alloc + initrd_len); } @@ -830,7 +847,7 @@ static int __init dom0_construct(struct domain *d, } /* All done with kernel, release the module pages */ bootstrap_unmap(); - release_module(image, true); + release_boot_module(image, true); if ( UNSET_ADDR != parms.virt_hypercall ) { @@ -880,7 +897,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); } @@ -1048,11 +1065,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; @@ -1070,7 +1083,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 aba9df8620ef..d9785acf89b6 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -977,10 +977,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]; @@ -997,6 +994,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 ( unlikely(idx < 0 || idx > bi->nr_modules) ) + panic("Missing kernel boot module for building Dom0\n"); + + image = &bi->mods[idx]; if ( opt_dom0_pvh ) { @@ -1023,14 +1028,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") ) @@ -1047,9 +1053,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; @@ -2143,10 +2151,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 Sat Nov 2 17:25:48 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: 13860200 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 A7334E67805 for ; Sat, 2 Nov 2024 17:37:45 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.829615.1244631 (Exim 4.92) (envelope-from ) id 1t7I4A-0002dM-7B; Sat, 02 Nov 2024 17:37:38 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 829615.1244631; Sat, 02 Nov 2024 17:37:38 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t7I49-0002cE-Vt; Sat, 02 Nov 2024 17:37:37 +0000 Received: by outflank-mailman (input) for mailman id 829615; Sat, 02 Nov 2024 17:37:36 +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 1t7HuT-0005zO-Mk for xen-devel@lists.xenproject.org; Sat, 02 Nov 2024 17:27:37 +0000 Received: from sender4-of-o51.zoho.com (sender4-of-o51.zoho.com [136.143.188.51]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id bea09c15-993f-11ef-a0c5-8be0dac302b0; Sat, 02 Nov 2024 18:27:34 +0100 (CET) Received: by mx.zohomail.com with SMTPS id 1730568372958973.0588263222835; Sat, 2 Nov 2024 10:26:12 -0700 (PDT) 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: bea09c15-993f-11ef-a0c5-8be0dac302b0 X-Custom-Connection: eyJyZW1vdGVpcCI6IjEzNi4xNDMuMTg4LjUxIiwiaGVsbyI6InNlbmRlcjQtb2YtbzUxLnpvaG8uY29tIn0= X-Custom-Transaction: eyJpZCI6ImJlYTA5YzE1LTk5M2YtMTFlZi1hMGM1LThiZTBkYWMzMDJiMCIsInRzIjoxNzMwNTY4NDU1LjAyOTYyOSwic2VuZGVyIjoiZHBzbWl0aEBhcGVydHVzc29sdXRpb25zLmNvbSIsInJlY2lwaWVudCI6Inhlbi1kZXZlbEBsaXN0cy54ZW5wcm9qZWN0Lm9yZyJ9 ARC-Seal: i=1; a=rsa-sha256; t=1730568383; cv=none; d=zohomail.com; s=zohoarc; b=OMPoFSoueO83CWAIaqTMkpDlMSMCtn2hOusrNcYNXQl3sNtsC4QKoLbKUzNQJKFY/oUofmA2IS4rPE7/5d3LFEGx8g3MjuGq8SFEFMzjYM/duefSMXfqJ6SDUTMdjpD7Y+/VhbaKxUyp9ETOdqPkUlLI+sKy1dhXMcQ9wXT1QRs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730568383; 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=vCeE70zl4N0GlCwS3QvCnOR8vYrFq8AHq0hy/S+7yQ0=; b=oA2STv2bb9th+YTZ13EEEWc+pQFXqFd8raWxDgm1wcq3t7++2MflaXS5pmFXaXLfx/uaFAWfmkli9Nn0dVYHTADR7D129/Rzkn6DrJsn0CDgjQjgumUtov62ueWyaCOjf5nvOhXLvxOOUyvwrOkJqqafwbW2S8+v7UJCw+fstco= 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=1730568383; 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=vCeE70zl4N0GlCwS3QvCnOR8vYrFq8AHq0hy/S+7yQ0=; b=S8fnDq3uPgVq4fEhPI629C6RAwGc1s64AkEoF7lmvZc1+qoW5I6SUc7zyiDzLKlZ Ak0WkIfciMSYBgq5Z0eqsu3ViRcJkIVzQh9/x2I0rDc+PinmAhc5lKwWD3ZM1KRS6E9 J1cylnVi4OjPuEOe+UzPd+uheLos2B3NsXS9k8sw= 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 09/12] x86/boot: add start and size fields to struct boot_module Date: Sat, 2 Nov 2024 13:25:48 -0400 Message-Id: <20241102172551.17233-10-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 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 --- 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 a# edit 336ac1fc0019 x86/boot: introduce boot domain --- 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 | 2 - xen/arch/x86/pv/dom0_build.c | 17 ++--- xen/arch/x86/setup.c | 100 ++++++++++++---------------- xen/xsm/xsm_policy.c | 4 +- 7 files changed, 64 insertions(+), 79 deletions(-) diff --git a/xen/arch/x86/cpu/microcode/core.c b/xen/arch/x86/cpu/microcode/core.c index 349e857f539a..891e6d29c7f4 100644 --- a/xen/arch/x86/cpu/microcode/core.c +++ b/xen/arch/x86/cpu/microcode/core.c @@ -726,8 +726,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 @@ -799,7 +799,7 @@ static int __init early_microcode_load(struct boot_info *bi) struct boot_module *bm = &bi->mods[idx]; struct cpio_data cd; - size = bm->mod->mod_end; + size = bm->size; data = bootstrap_map_bm(bm); if ( !data ) { @@ -849,7 +849,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 cd97f94a168a..e74684f10b12 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; @@ -729,7 +729,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 819c8224d715..a5ee90a36607 100644 --- a/xen/arch/x86/include/asm/bootinfo.h +++ b/xen/arch/x86/include/asm/bootinfo.h @@ -25,9 +25,6 @@ enum bootmod_type { }; struct boot_module { - /* Transitionary only */ - module_t *mod; - enum bootmod_type type; /* @@ -61,6 +58,9 @@ struct boot_module { bool released:1; 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 1e23f55be51b..0591847c57e6 100644 --- a/xen/arch/x86/include/asm/setup.h +++ b/xen/arch/x86/include/asm/setup.h @@ -35,11 +35,9 @@ void setup_io_bitmap(struct domain *d); extern struct boot_info xen_boot_info; unsigned long initial_images_nrpages(nodeid_t node); -void release_module(const module_t *m, bool mapped); 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, bool mapped); diff --git a/xen/arch/x86/pv/dom0_build.c b/xen/arch/x86/pv/dom0_build.c index 594874cd8d85..5efc650eeff0 100644 --- a/xen/arch/x86/pv/dom0_build.c +++ b/xen/arch/x86/pv/dom0_build.c @@ -420,7 +420,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); @@ -428,7 +428,7 @@ static int __init dom0_construct(struct boot_info *bi, struct domain *d) if ( i > 0 || i < bi->nr_modules ) { initrd = &bi->mods[i]; - initrd_len = initrd->mod->mod_end; + initrd_len = initrd->size; } d->max_pages = ~0U; @@ -630,7 +630,8 @@ 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 = 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 && ((mfn + count - 1) >> (d->arch.physaddr_bitsize - PAGE_SHIFT)) ) @@ -645,10 +646,10 @@ 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); release_boot_module(initrd, true); - initrd->mod->mod_start = initrd_mfn = mfn_x(page_to_mfn(page)); + initrd_mfn = mfn_x(page_to_mfn(page)); + initrd->start = pfn_to_paddr(initrd_mfn); } else { @@ -670,7 +671,7 @@ static int __init dom0_construct(struct boot_info *bi, struct domain *d) nr_pages - domain_tot_pages(d)); if ( initrd ) { - mpt_alloc = (paddr_t)initrd->mod->mod_start << PAGE_SHIFT; + mpt_alloc = initrd->start; printk("\n Init. ramdisk: %"PRIpaddr"->%"PRIpaddr, mpt_alloc, mpt_alloc + initrd_len); } @@ -897,7 +898,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 d9785acf89b6..18b93d6a272a 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -313,13 +313,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 already frame/size. + * Switch back to address/size. + */ + bi->mods[i].start = mods[i].mod_start; + bi->mods[i].size = mods[i].mod_end - mods[i].mod_start; + } + else + { + /* + * PVH and BIOS loaders give us modules which are start/end. + * Switch to address/size. + */ + bi->mods[i].start = pfn_to_paddr(mods[i].mod_start); + bi->mods[i].size = mods[i].mod_end; + } } /* 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; @@ -335,8 +351,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 = 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); @@ -347,8 +363,8 @@ unsigned long __init initial_images_nrpages(nodeid_t node) void __init release_boot_module(struct boot_module *bm, bool free_mem) { - uint64_t start = pfn_to_paddr(bm->mod->mod_start); - uint64_t size = bm->mod->mod_end; + uint64_t start = bm->start; + uint64_t size = bm->size; if ( bm->released ) { @@ -363,18 +379,6 @@ void __init release_boot_module(struct boot_module *bm, bool free_mem) bm->released = true; } -void __init release_module(const module_t *m, bool free_mem) -{ - struct boot_info *bi = &xen_boot_info; - unsigned int i; - - for ( i = 0; i < bi->nr_modules; i++ ) - { - if ( bi->mods[i].mod == m ) - release_boot_module(&bi->mods[i], free_mem); - } -} - static void __init discard_unknown_boot_modules(void) { struct boot_info *bi = &xen_boot_info; @@ -509,15 +513,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) @@ -695,8 +693,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; @@ -1427,13 +1425,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 @@ -1452,13 +1446,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 @@ -1539,7 +1532,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; @@ -1551,14 +1544,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; } } @@ -1589,10 +1579,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 ) @@ -1670,8 +1659,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; @@ -1745,13 +1733,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) + PFN_UP(l)); + 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 12c9de5a1fbf..f8836026f63b 100644 --- a/xen/xsm/xsm_policy.c +++ b/xen/xsm/xsm_policy.c @@ -43,8 +43,8 @@ int __init xsm_multiboot_policy_init( { struct boot_module *bm = &bi->mods[i]; - _policy_start = bootstrap_map(bm->mod); - _policy_len = bm->mod->mod_end; + _policy_start = bootstrap_map_bm(bm); + _policy_len = bm->size; if ( (xsm_magic_t)(*_policy_start) == XSM_MAGIC ) { From patchwork Sat Nov 2 17:25:49 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: 13860199 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 C7314E677E8 for ; Sat, 2 Nov 2024 17:36:50 +0000 (UTC) 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 X-Outflank-Mailman: Message body and most headers restored to incoming version 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-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_Pau_Monn=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 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 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; } -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); @@ -609,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 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 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; + 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); - rc = first_boot_module_index(bi, BOOTMOD_KERNEL); - if ( unlikely(rc < 0 || rc > bi->nr_modules) ) + if ( unlikely(image == NULL) ) panic("Missing kernel boot module for %pd construction\n", d); - image = &bi->mods[rc]; - - rc = first_boot_module_index(bi, BOOTMOD_RAMDISK); - if ( rc > 0 || rc < bi->nr_modules ) - initrd = &bi->mods[rc]; - 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 a5ee90a36607..7b793ca62f19 100644 --- a/xen/arch/x86/include/asm/bootinfo.h +++ b/xen/arch/x86/include/asm/bootinfo.h @@ -10,10 +10,14 @@ #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, @@ -77,6 +81,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 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); -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); -int dom0_construct_pvh(struct boot_info *bi, struct domain *d); +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 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); 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); 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 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) { 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 = 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; @@ -414,23 +415,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 ( unlikely(i < 0 || 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 > 0 || 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 ) @@ -1066,7 +1058,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; @@ -1084,7 +1076,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 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_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 ( unlikely(idx < 0 || idx > bi->nr_modules) ) - panic("Missing kernel boot module for building Dom0\n"); - - image = &bi->mods[idx]; if ( opt_dom0_pvh ) { @@ -1026,11 +1019,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. */ @@ -1052,10 +1045,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; @@ -1255,6 +1249,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 ) { @@ -2125,6 +2120,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 Sat Nov 2 17:25:50 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: 13860202 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 78884E677E8 for ; Sat, 2 Nov 2024 17:37:51 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.829618.1244644 (Exim 4.92) (envelope-from ) id 1t7I4F-00039p-CD; Sat, 02 Nov 2024 17:37:43 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 829618.1244644; Sat, 02 Nov 2024 17:37:43 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t7I4F-00039i-93; Sat, 02 Nov 2024 17:37:43 +0000 Received: by outflank-mailman (input) for mailman id 829618; Sat, 02 Nov 2024 17:37:41 +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 1t7Hun-0004r4-9v for xen-devel@lists.xenproject.org; Sat, 02 Nov 2024 17:27:57 +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 ca29640c-993f-11ef-99a3-01e77a169b0f; Sat, 02 Nov 2024 18:27:53 +0100 (CET) Received: by mx.zohomail.com with SMTPS id 1730568375366826.8780724690604; Sat, 2 Nov 2024 10:26:15 -0700 (PDT) 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: ca29640c-993f-11ef-99a3-01e77a169b0f X-Custom-Connection: eyJyZW1vdGVpcCI6IjEzNi4xNDMuMTg4LjUxIiwiaGVsbyI6InNlbmRlcjQtb2YtbzUxLnpvaG8uY29tIn0= X-Custom-Transaction: eyJpZCI6ImNhMjk2NDBjLTk5M2YtMTFlZi05OWEzLTAxZTc3YTE2OWIwZiIsInRzIjoxNzMwNTY4NDc0LjMzNzU3OSwic2VuZGVyIjoiZHBzbWl0aEBhcGVydHVzc29sdXRpb25zLmNvbSIsInJlY2lwaWVudCI6Inhlbi1kZXZlbEBsaXN0cy54ZW5wcm9qZWN0Lm9yZyJ9 ARC-Seal: i=1; a=rsa-sha256; t=1730568385; cv=none; d=zohomail.com; s=zohoarc; b=GXqqM1eguA2Hqrwqld2IRWlUOBtvX8mk9HblxiZfWXdP/aj1BP9a5wi1WfnGxKZ2tOsCAkQtzlqjToD4/DvxrcTcyE6fnSZqvLufchVowmN0iXbypL/XgzczSpDoqhiiLp8SEUX+NsxVio4QOl4yakoYWF/skV8Qvn2nGrDoIhk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730568385; 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=DlW8869YgbQ7b/dFXUZq70NRQ3QZ7VjwhbTQzGdmgBI=; b=I+2RzWb/pZzKdYO+rh73X4evInsrClFR8eSFoAeooQNTxy2IxTEu4ikeU9zssfOedLlBXEktKUA4cXhDXbz67mTFeW2Jt4twun0AalK3AEdlbLE/KqvUTvUqQf1PzB7t0rKQ2YjcGgM7EuuTCSvQuTCioSSThYBqrRwPxfQ4nhw= 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=1730568385; 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=DlW8869YgbQ7b/dFXUZq70NRQ3QZ7VjwhbTQzGdmgBI=; b=sv3Zz7Ca7Dka+jjB3+AIr+geIunMXPPzH8L9winziOCf+Sj/eAN1BeNDCzdSDOvk nYerP8gDK/GMTZpH4xNbclrpFd+8WcAscOZD/JOE5ULW54tuGiXZANtSVuX7ljKmD1J 0/sxtHVm4koGvK2vxj8vssW/vDssFhaK91W7NLn0= 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 11/12] x86/boot: introduce domid field to struct boot_domain Date: Sat, 2 Nov 2024 13:25:50 -0400 Message-Id: <20241102172551.17233-12-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 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 6e25a9f726c7..7b78bd9c7c8d 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -338,6 +338,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; } @@ -992,7 +995,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 ) { @@ -1008,15 +1010,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 Sat Nov 2 17:25:51 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: 13860204 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 05419E67805 for ; Sat, 2 Nov 2024 17:38:06 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.829624.1244658 (Exim 4.92) (envelope-from ) id 1t7I4S-000400-0p; Sat, 02 Nov 2024 17:37:56 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 829624.1244658; Sat, 02 Nov 2024 17:37:55 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t7I4R-0003yy-Qw; Sat, 02 Nov 2024 17:37:55 +0000 Received: by outflank-mailman (input) for mailman id 829624; Sat, 02 Nov 2024 17:37:54 +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 1t7Hux-0004r4-No for xen-devel@lists.xenproject.org; Sat, 02 Nov 2024 17:28:07 +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 d062b535-993f-11ef-99a3-01e77a169b0f; Sat, 02 Nov 2024 18:28:04 +0100 (CET) Received: by mx.zohomail.com with SMTPS id 1730568376554254.352253814322; Sat, 2 Nov 2024 10:26:16 -0700 (PDT) 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: d062b535-993f-11ef-99a3-01e77a169b0f X-Custom-Connection: eyJyZW1vdGVpcCI6IjEzNi4xNDMuMTg4LjUxIiwiaGVsbyI6InNlbmRlcjQtb2YtbzUxLnpvaG8uY29tIn0= X-Custom-Transaction: eyJpZCI6ImQwNjJiNTM1LTk5M2YtMTFlZi05OWEzLTAxZTc3YTE2OWIwZiIsInRzIjoxNzMwNTY4NDg0LjgwMDUzMiwic2VuZGVyIjoiZHBzbWl0aEBhcGVydHVzc29sdXRpb25zLmNvbSIsInJlY2lwaWVudCI6Inhlbi1kZXZlbEBsaXN0cy54ZW5wcm9qZWN0Lm9yZyJ9 ARC-Seal: i=1; a=rsa-sha256; t=1730568385; cv=none; d=zohomail.com; s=zohoarc; b=DaE1msTh9OL/UMNeyEU+I+slUVIkmCcBLTOkiP4IeAh0AFi0/le5UTAY2mPxrvmSFKIax7cucpovfwpc6qUvdMAy76Ak6ZYVS3fLy/a5JmP2URQwX7pJVW65yfp0FuiGWoAfxRs3R92xHYz1/89WXYl+YRcK1pSD/cDgUyotk/I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730568385; 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=D+Ero9Cx9cs2ogNCswgWtWOJ14E6rK5H6+adO3A9JUc=; b=cz5B2xs55xJa3cNJI30LvbySktK7yR3NFJn38I5WZq+Z9irgJN+KntUaa/Bc+WxOWl2mbX+4wRLGn7JYfsI2eAGUUzfPii+t1LHFfJ0JhDqA1IXZ1luND/pYufhlxSBZB7otSUDnh2CbPuiMsbY4YRrgcijLpiUym4spH+8Z4Pg= 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=1730568385; 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=D+Ero9Cx9cs2ogNCswgWtWOJ14E6rK5H6+adO3A9JUc=; b=ebpNRVEcdLj7MAIUFRuaw3inmi9D37/O6u5vIVXXw/L86ZiXaNzV+opQt23bJGD4 yrso92wIMRz+DnfIOPyh91WTJnLqBhqk6e4yMQkBlJJ2R0KLb53dEht4VjUnerXcW+O YYZoAj58haXpOymqXpqtXjGJjVWfww7ZiayQbX3A= 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 12/12] x86/boot: add cmdline to struct boot_domain Date: Sat, 2 Nov 2024 13:25:51 -0400 Message-Id: <20241102172551.17233-13-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 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 v7: - updated commit message to expand on intent and purpose --- xen/arch/x86/include/asm/bootdomain.h | 4 ++++ xen/arch/x86/include/asm/dom0_build.h | 1 + xen/arch/x86/pv/dom0_build.c | 4 ++-- xen/arch/x86/setup.c | 18 ++++++++---------- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/xen/arch/x86/include/asm/bootdomain.h b/xen/arch/x86/include/asm/bootdomain.h index 3873f916f854..bc51f04a1df6 100644 --- a/xen/arch/x86/include/asm/bootdomain.h +++ b/xen/arch/x86/include/asm/bootdomain.h @@ -8,10 +8,14 @@ #ifndef __XEN_X86_BOOTDOMAIN_H__ #define __XEN_X86_BOOTDOMAIN_H__ +#include + struct boot_module; struct domain; struct boot_domain { + char cmdline[MAX_GUEST_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 4a75fb25a801..982bc1fa9e6b 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 28257bf13127..2c84af52de3e 100644 --- a/xen/arch/x86/pv/dom0_build.c +++ b/xen/arch/x86/pv/dom0_build.c @@ -960,8 +960,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 ( cmdline[0] != '\0' ) + 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 7b78bd9c7c8d..9db8a650ecc2 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -980,8 +980,6 @@ static unsigned int __init copy_bios_e820(struct e820entry *map, unsigned int li static struct domain *__init create_dom0(struct boot_info *bi) { - static char __initdata cmdline[MAX_GUEST_CMDLINE]; - struct xen_domctl_createdomain dom0_cfg = { .flags = IS_ENABLED(CONFIG_TBOOT) ? XEN_DOMCTL_CDF_s3_integrity : 0, .max_evtchn_port = -1, @@ -1024,16 +1022,16 @@ static struct domain *__init create_dom0(struct boot_info *bi) if ( bd->kernel->cmdline_pa || bi->kextra ) { if ( bd->kernel->cmdline_pa ) - safe_strcpy(cmdline, cmdline_cook(__va(bd->kernel->cmdline_pa), + safe_strcpy(bd->cmdline, cmdline_cook(__va(bd->kernel->cmdline_pa), bi->loader)); if ( bi->kextra ) /* kextra always includes exactly one leading space. */ - safe_strcat(cmdline, bi->kextra); + safe_strcat(bd->cmdline, bi->kextra); /* Append any extra parameters. */ - if ( skip_ioapic_setup && !strstr(cmdline, "noapic") ) - safe_strcat(cmdline, " noapic"); + if ( skip_ioapic_setup && !strstr(bd->cmdline, "noapic") ) + safe_strcat(bd->cmdline, " noapic"); if ( (strlen(acpi_param) == 0) && acpi_disabled ) { @@ -1041,13 +1039,13 @@ static struct domain *__init create_dom0(struct boot_info *bi) safe_strcpy(acpi_param, "off"); } - if ( (strlen(acpi_param) != 0) && !strstr(cmdline, "acpi=") ) + if ( (strlen(acpi_param) != 0) && !strstr(bd->cmdline, "acpi=") ) { - safe_strcat(cmdline, " acpi="); - safe_strcat(cmdline, acpi_param); + safe_strcat(bd->cmdline, " acpi="); + safe_strcat(bd->cmdline, acpi_param); } - bd->kernel->cmdline_pa = __pa(cmdline); + bd->kernel->cmdline_pa = __pa(bd->cmdline); } bd->d = d;