From patchwork Sat Jul 1 07:18:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christopher Clark X-Patchwork-Id: 13298969 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 2F522EB64DD for ; Sat, 1 Jul 2023 07:19:10 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.557771.871399 (Exim 4.92) (envelope-from ) id 1qFUsg-0006cx-Va; Sat, 01 Jul 2023 07:18:54 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 557771.871399; Sat, 01 Jul 2023 07:18:54 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qFUsg-0006cq-T3; Sat, 01 Jul 2023 07:18:54 +0000 Received: by outflank-mailman (input) for mailman id 557771; Sat, 01 Jul 2023 07:18:53 +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 1qFUsf-0006No-Gx for xen-devel@lists.xenproject.org; Sat, 01 Jul 2023 07:18:53 +0000 Received: from mail-oi1-x22e.google.com (mail-oi1-x22e.google.com [2607:f8b0:4864:20::22e]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 86e20dce-17df-11ee-8611-37d641c3527e; Sat, 01 Jul 2023 09:18:51 +0200 (CEST) Received: by mail-oi1-x22e.google.com with SMTP id 5614622812f47-3a1d9b64837so2114109b6e.0 for ; Sat, 01 Jul 2023 00:18:51 -0700 (PDT) Received: from cog-dev.home ([70.103.208.83]) by smtp.gmail.com with ESMTPSA id s19-20020aa78d53000000b00673e652985bsm4108866pfe.118.2023.07.01.00.18.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Jul 2023 00:18:48 -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 X-Inumbo-ID: 86e20dce-17df-11ee-8611-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1688195929; x=1690787929; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=4c9WAF4kmb19tJcbTDjvohxu3kd3fgp5qdmTKmSCTJE=; b=CrY0CL1mRL0QPuwcnmaQkblnBE5P1R9sxQMKRcx7enujbSgBR6HAPycMDb2gS1AY4c GSMdg9Ho2X7dHe+o+SmkXoOa4APm8vLJjz8ed+7vxoyBsabHF/6zFJRtNNnBW4mZqgs0 /Kh9Zwyvg3GVC2GvbUXvWfC+Zl6imp1Dt83c7Gz7W64GM7H2PsLp9Qawd4CWiMdGbfJ+ 4ZpLlj4Ud3KBQNyr/lOBs7ci3hfKCUjakzYDIIoGJTg8cCPtn9eEPJMUhg1WXlHQsVCH 55FvRh0m8bfNjA2aTWhCErJlfX/ZnGxZaK4J45t8b1wnqNp9Gr9qRZ6PvA6RDY+LPK40 MFzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688195929; x=1690787929; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=4c9WAF4kmb19tJcbTDjvohxu3kd3fgp5qdmTKmSCTJE=; b=SR70FPibjtK197iqGpuAocUm0X2cDizdg/b5smcuB/qjgWHuBK4bf5+aS2eY0Lylm+ tiJArrRTZpqAyauRqBFksKgcXP+gaI7OqOvuG5Gc7tqdP+utbVkifE3QwEuDA0ENiT9c 1sLdARp4psY5vz14g6eXO0L3YFG13DaQHt887/9OqaoFEZqbRQo80OgXw24onADATt7G Bx7eZjln+wMmetrJJ0ovP86NDofQ+2C8LG1JBqVthUBx7VPhiW6ZHuF4uS/QkVG9r95F qgO5o6RfCW4pNvMc5+iqN1E9zKj0dbGez4k5Upe5hoCB7aMjeyna7+qF1TCknygWHq2n pjJw== X-Gm-Message-State: AC+VfDyiX59a5d3b9UJhgPXVnpUgr2rMyZxbvCcIP9j1ob5yiDOH8HQ5 HFYikFMPxGKhnj1eONz4J7MPV9m1Cyc= X-Google-Smtp-Source: ACHHUZ5mpapv9SYTUsV6xBXMbudnVg/NReuMAxR+qtoCnfL+g9iPwcEvsPkpPiGylED5la1TTi9fsw== X-Received: by 2002:a05:6808:1b0c:b0:3a1:b309:a409 with SMTP id bx12-20020a0568081b0c00b003a1b309a409mr6482050oib.4.1688195929359; Sat, 01 Jul 2023 00:18:49 -0700 (PDT) Sender: Christopher Clark From: Christopher Clark To: xen-devel@lists.xenproject.org Cc: Daniel Smith , stefano.stabellini@amd.com, Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu , Bertrand Marquis , Luca Fancellu , Volodymyr Babchuk , Rich Persaud Subject: [PATCH 01/10] x86 setup: move x86 boot module counting into a new boot_info struct Date: Sat, 1 Jul 2023 00:18:26 -0700 Message-Id: <20230701071835.41599-2-christopher.w.clark@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230701071835.41599-1-christopher.w.clark@gmail.com> References: <20230701071835.41599-1-christopher.w.clark@gmail.com> MIME-Version: 1.0 An initial step towards a non-multiboot internal representation of boot modules for common code, starting with x86 setup and converting the fields that are accessed for the startup calculations. Introduce a new header, , and populate it with a new boot_info structure initially containing a count of the number of boot modules. The naming of the header, structure and fields is intended to respect the boot structures on Arm -- see arm/include/asm/setup.h -- as part of work towards aligning common architecture-neutral boot logic and structures. No functional change intended. Signed-off-by: Christopher Clark Signed-off-by: Daniel P. Smith --- Changes since v1: patch is a subset of v1 series patches 2 and 3. xen/arch/x86/setup.c | 58 +++++++++++++++++++++++--------------- xen/include/xen/bootinfo.h | 20 +++++++++++++ 2 files changed, 55 insertions(+), 23 deletions(-) create mode 100644 xen/include/xen/bootinfo.h diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 74e3915a4d..708639b236 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -268,7 +269,16 @@ static int __init cf_check parse_acpi_param(const char *s) custom_param("acpi", parse_acpi_param); static const module_t *__initdata initial_images; -static unsigned int __initdata nr_initial_images; +static struct boot_info __initdata *boot_info; + +static void __init multiboot_to_bootinfo(multiboot_info_t *mbi) +{ + static struct boot_info __initdata info; + + info.nr_mods = mbi->mods_count; + + boot_info = &info; +} unsigned long __init initial_images_nrpages(nodeid_t node) { @@ -277,7 +287,7 @@ unsigned long __init initial_images_nrpages(nodeid_t node) unsigned long nr; unsigned int i; - for ( nr = i = 0; i < nr_initial_images; ++i ) + for ( nr = i = 0; i < boot_info->nr_mods; ++i ) { unsigned long start = initial_images[i].mod_start; unsigned long end = start + PFN_UP(initial_images[i].mod_end); @@ -293,7 +303,7 @@ void __init discard_initial_images(void) { unsigned int i; - for ( i = 0; i < nr_initial_images; ++i ) + for ( i = 0; i < boot_info->nr_mods; ++i ) { uint64_t start = (uint64_t)initial_images[i].mod_start << PAGE_SHIFT; @@ -301,7 +311,7 @@ void __init discard_initial_images(void) start + PAGE_ALIGN(initial_images[i].mod_end)); } - nr_initial_images = 0; + boot_info->nr_mods = 0; initial_images = NULL; } @@ -1020,6 +1030,8 @@ void __init noreturn __start_xen(unsigned long mbi_p) mod = __va(mbi->mods_addr); } + multiboot_to_bootinfo(mbi); + loader = (mbi->flags & MBI_LOADERNAME) ? (char *)__va(mbi->boot_loader_name) : "unknown"; @@ -1127,18 +1139,18 @@ void __init noreturn __start_xen(unsigned long mbi_p) bootsym(boot_edd_info_nr)); /* Check that we have at least one Multiboot module. */ - if ( !(mbi->flags & MBI_MODULES) || (mbi->mods_count == 0) ) + if ( !(mbi->flags & MBI_MODULES) || (boot_info->nr_mods == 0) ) panic("dom0 kernel not specified. Check bootloader configuration\n"); /* Check that we don't have a silly number of modules. */ - if ( mbi->mods_count > sizeof(module_map) * 8 ) + if ( boot_info->nr_mods > sizeof(module_map) * 8 ) { - mbi->mods_count = sizeof(module_map) * 8; + boot_info->nr_mods = sizeof(module_map) * 8; printk("Excessive multiboot modules - using the first %u only\n", - mbi->mods_count); + boot_info->nr_mods); } - bitmap_fill(module_map, mbi->mods_count); + bitmap_fill(module_map, boot_info->nr_mods); __clear_bit(0, module_map); /* Dom0 kernel is always first */ if ( pvh_boot ) @@ -1311,9 +1323,9 @@ void __init noreturn __start_xen(unsigned long mbi_p) kexec_reserve_area(&boot_e820); initial_images = mod; - nr_initial_images = mbi->mods_count; + boot_info->nr_mods = boot_info->nr_mods; - for ( i = 0; !efi_enabled(EFI_LOADER) && i < mbi->mods_count; i++ ) + for ( i = 0; !efi_enabled(EFI_LOADER) && i < boot_info->nr_mods; i++ ) { if ( mod[i].mod_start & (PAGE_SIZE - 1) ) panic("Bootloader didn't honor module alignment request\n"); @@ -1337,8 +1349,8 @@ void __init noreturn __start_xen(unsigned long mbi_p) * respective reserve_e820_ram() invocation below. No need to * query efi_boot_mem_unused() here, though. */ - mod[mbi->mods_count].mod_start = virt_to_mfn(_stext); - mod[mbi->mods_count].mod_end = __2M_rwdata_end - _stext; + mod[boot_info->nr_mods].mod_start = virt_to_mfn(_stext); + mod[boot_info->nr_mods].mod_end = __2M_rwdata_end - _stext; } modules_headroom = bzimage_headroom(bootstrap_map(mod), mod->mod_end); @@ -1398,7 +1410,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) { /* Don't overlap with modules. */ end = consider_modules(s, e, reloc_size + mask, - mod, mbi->mods_count, -1); + mod, boot_info->nr_mods, -1); end &= ~mask; } else @@ -1419,7 +1431,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) } /* Is the region suitable for relocating the multiboot modules? */ - for ( j = mbi->mods_count - 1; j >= 0; j-- ) + for ( j = boot_info->nr_mods - 1; j >= 0; j-- ) { unsigned long headroom = j ? 0 : modules_headroom; unsigned long size = PAGE_ALIGN(headroom + mod[j].mod_end); @@ -1429,7 +1441,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) /* Don't overlap with other modules (or Xen itself). */ end = consider_modules(s, e, size, mod, - mbi->mods_count + relocated, j); + boot_info->nr_mods + relocated, j); if ( highmem_start && end > highmem_start ) continue; @@ -1456,7 +1468,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) { /* Don't overlap with modules (or Xen itself). */ e = consider_modules(s, e, PAGE_ALIGN(kexec_crash_area.size), mod, - mbi->mods_count + relocated, -1); + boot_info->nr_mods + relocated, -1); if ( s >= e ) break; if ( e > kexec_crash_area_limit ) @@ -1471,7 +1483,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) if ( modules_headroom && !mod->reserved ) panic("Not enough memory to relocate the dom0 kernel image\n"); - for ( i = 0; i < mbi->mods_count; ++i ) + for ( i = 0; i < boot_info->nr_mods; ++i ) { uint64_t s = (uint64_t)mod[i].mod_start << PAGE_SHIFT; @@ -1540,7 +1552,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) ASSERT(j); } map_e = boot_e820.map[j].addr + boot_e820.map[j].size; - for ( j = 0; j < mbi->mods_count; ++j ) + for ( j = 0; j < boot_info->nr_mods; ++j ) { uint64_t end = pfn_to_paddr(mod[j].mod_start) + mod[j].mod_end; @@ -1616,7 +1628,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) } } - for ( i = 0; i < mbi->mods_count; ++i ) + for ( i = 0; i < boot_info->nr_mods; ++i ) { set_pdx_range(mod[i].mod_start, mod[i].mod_start + PFN_UP(mod[i].mod_end)); @@ -1999,8 +2011,8 @@ void __init noreturn __start_xen(unsigned long mbi_p) cpu_has_nx ? XENLOG_INFO : XENLOG_WARNING "Warning: ", cpu_has_nx ? "" : "not "); - initrdidx = find_first_bit(module_map, mbi->mods_count); - if ( bitmap_weight(module_map, mbi->mods_count) > 1 ) + initrdidx = find_first_bit(module_map, boot_info->nr_mods); + if ( bitmap_weight(module_map, boot_info->nr_mods) > 1 ) printk(XENLOG_WARNING "Multiple initrd candidates, picking module #%u\n", initrdidx); @@ -2010,7 +2022,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) * above our heap. The second module, if present, is an initrd ramdisk. */ dom0 = create_dom0(mod, modules_headroom, - initrdidx < mbi->mods_count ? mod + initrdidx : NULL, + initrdidx < boot_info->nr_mods ? mod + initrdidx : NULL, kextra, loader); if ( !dom0 ) panic("Could not set up DOM0 guest OS\n"); diff --git a/xen/include/xen/bootinfo.h b/xen/include/xen/bootinfo.h new file mode 100644 index 0000000000..6a7d55d20e --- /dev/null +++ b/xen/include/xen/bootinfo.h @@ -0,0 +1,20 @@ +#ifndef __XEN_BOOTINFO_H__ +#define __XEN_BOOTINFO_H__ + +#include + +struct boot_info { + unsigned int nr_mods; +}; + +#endif + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ From patchwork Sat Jul 1 07:18:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christopher Clark X-Patchwork-Id: 13298974 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 CE059C001B3 for ; Sat, 1 Jul 2023 07:19:16 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.557772.871410 (Exim 4.92) (envelope-from ) id 1qFUsi-0006sV-Cc; Sat, 01 Jul 2023 07:18:56 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 557772.871410; Sat, 01 Jul 2023 07:18:56 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qFUsi-0006sI-9F; Sat, 01 Jul 2023 07:18:56 +0000 Received: by outflank-mailman (input) for mailman id 557772; Sat, 01 Jul 2023 07:18: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 1qFUsg-0006No-Gx for xen-devel@lists.xenproject.org; Sat, 01 Jul 2023 07:18:54 +0000 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [2607:f8b0:4864:20::434]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 87ad859c-17df-11ee-8611-37d641c3527e; Sat, 01 Jul 2023 09:18:52 +0200 (CEST) Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-6687446eaccso2060682b3a.3 for ; Sat, 01 Jul 2023 00:18:52 -0700 (PDT) Received: from cog-dev.home ([70.103.208.83]) by smtp.gmail.com with ESMTPSA id s19-20020aa78d53000000b00673e652985bsm4108866pfe.118.2023.07.01.00.18.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Jul 2023 00:18:49 -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 X-Inumbo-ID: 87ad859c-17df-11ee-8611-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1688195930; x=1690787930; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=Y6HSin/PPuTe3wUBWgklxdNFxDnMlcE+0e39paE0fXc=; b=rsJIkClYspba3EEC1R7kK3NAtOk5jq9qbQKs6V3a1+OyaOU9EdE4lyaLRwCxYjjR5y waqpW/joeTxkdrxBi10PoK/AZjaG5MFU0TAC4LNcWBKn/PdHFbpAAomjyxPEv6v8d6Wc My/L3c/7RcgdXVx8B4gdBlsXxc3Kyv5vQA3JMgm+XixOc9HLxFkHCAmkV/0cvQs3bmfF deiblMs2mJRWQ7elSOZskM4iJObW2t7Xd8DwX7/zQtYw3KUtyw9NnAup3AVYAzNlHXKQ eX9C1FZmaQKqFUMAAfRY08tDeXn8UUqcTPaQmf6U/vydMK1vxc+SUhlED09efS3rWVsM a/eQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688195930; x=1690787930; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=Y6HSin/PPuTe3wUBWgklxdNFxDnMlcE+0e39paE0fXc=; b=E/UuqHWhozUqX7eS/KnX0J7d5LjhTtQfG+MHTtD8xQpvICPYsOrN1EjbdotvgZFLyz frB2sMfEr5L896R7go33msGrw2Ge4XJuGZ18nC4f98Ft66gDNEEaSzS4+33ziKhRaeQd VOFonzS0pHphu3y8JY/LwKX8cOzMtBZnFR59HmVCLUCIZ2fydoGyjtOTkXuYe38K9KHS qco0w9MHe5vpG/KckdRI935qgkRXpCj+5IXCw3gGXAeki2SS5By/lSiMMqg/IlDWMFiI Rr9tp1YMgWZ4lYA9zQ37X+fChUb0jFWPOhxO9ZSqYUifEkmtyh5gjRxveh+/WvO01/cp MSVw== X-Gm-Message-State: ABy/qLaSAYxV1Qs7XMUcnRwz34tjvR57xcLzRBH1GF7b887T4SWpT/5K p6R4uNAq1WxwJi6vi6xuYmZm2seU060= X-Google-Smtp-Source: APBJJlGazLVsxb16uFiIRgEsb22Vr4uL3fUVX8OBI0LxxvRLHfsnva3PurQ+L5rtOrS/CANPnVhzgw== X-Received: by 2002:a05:6a00:24c9:b0:682:37be:c9fe with SMTP id d9-20020a056a0024c900b0068237bec9femr6300448pfv.10.1688195930443; Sat, 01 Jul 2023 00:18:50 -0700 (PDT) Sender: Christopher Clark From: Christopher Clark To: xen-devel@lists.xenproject.org Cc: Daniel Smith , stefano.stabellini@amd.com, Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu , Bertrand Marquis , Luca Fancellu , Volodymyr Babchuk , Rich Persaud Subject: [PATCH 02/10] x86 setup: per-arch bootmodule structure, headroom field Date: Sat, 1 Jul 2023 00:18:27 -0700 Message-Id: <20230701071835.41599-3-christopher.w.clark@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230701071835.41599-1-christopher.w.clark@gmail.com> References: <20230701071835.41599-1-christopher.w.clark@gmail.com> MIME-Version: 1.0 Next step in incremental work towards adding a non-multiboot internal representation of boot modules, converting the fields being accessed for the startup calculations. Add a new array of structs for per-boot-module state, though only allocate space for a single array entry in this change since that is all that is required for functionality modified in this patch: moving the headroom field for the image decompression calculation into a new per-arch boot module struct and then using it in x86 dom0 construction. Introduces a per-arch header for x86 for arch-specific boot module structures, and add a member to the common boot module structure for access to it. No functional change intended. Signed-off-by: Christopher Clark Signed-off-by: Daniel P. Smith --- Changes since v1: patch is a subset of v1 series patches 2 and 3. xen/arch/x86/bzimage.c | 10 +++++----- xen/arch/x86/hvm/dom0_build.c | 3 ++- xen/arch/x86/include/asm/bootinfo.h | 18 ++++++++++++++++++ xen/arch/x86/include/asm/bzimage.h | 2 +- xen/arch/x86/pv/dom0_build.c | 3 ++- xen/arch/x86/setup.c | 23 ++++++++++++++++------- xen/include/xen/bootinfo.h | 11 +++++++++++ 7 files changed, 55 insertions(+), 15 deletions(-) create mode 100644 xen/arch/x86/include/asm/bootinfo.h diff --git a/xen/arch/x86/bzimage.c b/xen/arch/x86/bzimage.c index ac4fd428be..dac2399b89 100644 --- a/xen/arch/x86/bzimage.c +++ b/xen/arch/x86/bzimage.c @@ -69,8 +69,6 @@ static __init int bzimage_check(struct setup_header *hdr, unsigned long len) return 1; } -static unsigned long __initdata orig_image_len; - unsigned long __init bzimage_headroom(void *image_start, unsigned long image_length) { @@ -91,7 +89,6 @@ unsigned long __init bzimage_headroom(void *image_start, if ( elf_is_elfbinary(image_start, image_length) ) return 0; - orig_image_len = image_length; headroom = output_length(image_start, image_length); if (gzip_check(image_start, image_length)) { @@ -105,11 +102,14 @@ unsigned long __init bzimage_headroom(void *image_start, } int __init bzimage_parse(void *image_base, void **image_start, + unsigned int headroom, unsigned long *image_len) { struct setup_header *hdr = (struct setup_header *)(*image_start); int err = bzimage_check(hdr, *image_len); - unsigned long output_len; + unsigned long output_len, orig_image_len; + + orig_image_len = *image_len - headroom; if ( err < 0 ) return err; @@ -125,7 +125,7 @@ int __init bzimage_parse(void *image_base, void **image_start, BUG_ON(!(image_base < *image_start)); - output_len = output_length(*image_start, orig_image_len); + output_len = output_length(*image_start, *image_len); if ( (err = perform_gunzip(image_base, *image_start, orig_image_len)) > 0 ) err = decompress(*image_start, orig_image_len, image_base); diff --git a/xen/arch/x86/hvm/dom0_build.c b/xen/arch/x86/hvm/dom0_build.c index fd2cbf68bc..bf08998862 100644 --- a/xen/arch/x86/hvm/dom0_build.c +++ b/xen/arch/x86/hvm/dom0_build.c @@ -545,7 +545,8 @@ static int __init pvh_load_kernel(struct domain *d, const module_t *image, struct vcpu *v = d->vcpu[0]; int rc; - if ( (rc = bzimage_parse(image_base, &image_start, &image_len)) != 0 ) + if ( (rc = bzimage_parse(image_base, &image_start, image_headroom, + &image_len)) != 0 ) { printk("Error trying to detect bz compressed kernel\n"); return rc; diff --git a/xen/arch/x86/include/asm/bootinfo.h b/xen/arch/x86/include/asm/bootinfo.h new file mode 100644 index 0000000000..a25054f372 --- /dev/null +++ b/xen/arch/x86/include/asm/bootinfo.h @@ -0,0 +1,18 @@ +#ifndef __ARCH_X86_BOOTINFO_H__ +#define __ARCH_X86_BOOTINFO_H__ + +struct arch_bootmodule { + unsigned headroom; +}; + +#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/bzimage.h b/xen/arch/x86/include/asm/bzimage.h index 7ed69d3910..dd784f32ef 100644 --- a/xen/arch/x86/include/asm/bzimage.h +++ b/xen/arch/x86/include/asm/bzimage.h @@ -5,7 +5,7 @@ unsigned long bzimage_headroom(void *image_start, unsigned long image_length); -int bzimage_parse(void *image_base, void **image_start, +int bzimage_parse(void *image_base, void **image_start, unsigned int headroom, unsigned long *image_len); #endif /* __X86_BZIMAGE_H__ */ diff --git a/xen/arch/x86/pv/dom0_build.c b/xen/arch/x86/pv/dom0_build.c index c99135a552..6ed9f8bbed 100644 --- a/xen/arch/x86/pv/dom0_build.c +++ b/xen/arch/x86/pv/dom0_build.c @@ -416,7 +416,8 @@ int __init dom0_construct_pv(struct domain *d, d->max_pages = ~0U; - if ( (rc = bzimage_parse(image_base, &image_start, &image_len)) != 0 ) + if ( (rc = bzimage_parse(image_base, &image_start, image_headroom, + &image_len)) != 0 ) return rc; if ( (rc = elf_init(&elf, image_start, image_len)) != 0 ) diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 708639b236..c0e8fc6ab7 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -273,10 +273,16 @@ static struct boot_info __initdata *boot_info; static void __init multiboot_to_bootinfo(multiboot_info_t *mbi) { - static struct boot_info __initdata info; + static struct boot_info __initdata info; + static struct boot_module __initdata boot_mods[1]; + static struct arch_bootmodule __initdata arch_boot_mods[1]; + + info.mods = boot_mods; info.nr_mods = mbi->mods_count; + boot_mods[0].arch = &arch_boot_mods[0]; + boot_info = &info; } @@ -961,7 +967,8 @@ static struct domain *__init create_dom0(const module_t *image, write_cr4(read_cr4() & ~X86_CR4_SMAP); } - if ( construct_dom0(d, image, headroom, initrd, cmdline) != 0 ) + if ( construct_dom0(d, image, boot_info->mods[0].arch->headroom, initrd, + cmdline) != 0 ) panic("Could not construct domain 0\n"); if ( cpu_has_smap ) @@ -985,7 +992,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) unsigned int initrdidx, num_parked = 0; multiboot_info_t *mbi; module_t *mod; - unsigned long nr_pages, raw_max_page, modules_headroom, module_map[1]; + unsigned long nr_pages, raw_max_page, module_map[1]; int i, j, e820_warn = 0, bytes = 0; unsigned long eb_start, eb_end; bool acpi_boot_table_init_done = false, relocated = false; @@ -1353,7 +1360,8 @@ void __init noreturn __start_xen(unsigned long mbi_p) mod[boot_info->nr_mods].mod_end = __2M_rwdata_end - _stext; } - modules_headroom = bzimage_headroom(bootstrap_map(mod), mod->mod_end); + boot_info->mods[0].arch->headroom = bzimage_headroom(bootstrap_map(mod), + mod->mod_end); bootstrap_map(NULL); #ifndef highmem_start @@ -1433,7 +1441,8 @@ void __init noreturn __start_xen(unsigned long mbi_p) /* Is the region suitable for relocating the multiboot modules? */ for ( j = boot_info->nr_mods - 1; j >= 0; j-- ) { - unsigned long headroom = j ? 0 : modules_headroom; + struct boot_module *boot_mods = boot_info->mods; + unsigned long headroom = j ? 0 : boot_mods[0].arch->headroom; unsigned long size = PAGE_ALIGN(headroom + mod[j].mod_end); if ( mod[j].reserved ) @@ -1481,7 +1490,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) #endif } - if ( modules_headroom && !mod->reserved ) + if ( boot_info->mods[0].arch->headroom && !mod->reserved ) panic("Not enough memory to relocate the dom0 kernel image\n"); for ( i = 0; i < boot_info->nr_mods; ++i ) { @@ -2021,7 +2030,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) * 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(mod, modules_headroom, + dom0 = create_dom0(mod, boot_info->mods[0].arch->headroom, initrdidx < boot_info->nr_mods ? mod + initrdidx : NULL, kextra, loader); if ( !dom0 ) diff --git a/xen/include/xen/bootinfo.h b/xen/include/xen/bootinfo.h index 6a7d55d20e..b72ae31a66 100644 --- a/xen/include/xen/bootinfo.h +++ b/xen/include/xen/bootinfo.h @@ -3,8 +3,19 @@ #include +#ifdef CONFIG_X86 +#include +#else + struct arch_bootmodule { }; +#endif + +struct boot_module { + struct arch_bootmodule *arch; +}; + struct boot_info { unsigned int nr_mods; + struct boot_module *mods; }; #endif From patchwork Sat Jul 1 07:18:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christopher Clark X-Patchwork-Id: 13298968 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 8FBFCEB64DC for ; Sat, 1 Jul 2023 07:19:08 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.557773.871420 (Exim 4.92) (envelope-from ) id 1qFUsj-00078X-La; Sat, 01 Jul 2023 07:18:57 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 557773.871420; Sat, 01 Jul 2023 07:18:57 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qFUsj-00077S-Go; Sat, 01 Jul 2023 07:18:57 +0000 Received: by outflank-mailman (input) for mailman id 557773; Sat, 01 Jul 2023 07:18:55 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qFUsh-0006No-Hn for xen-devel@lists.xenproject.org; Sat, 01 Jul 2023 07:18:55 +0000 Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [2607:f8b0:4864:20::435]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 885db715-17df-11ee-8611-37d641c3527e; Sat, 01 Jul 2023 09:18:53 +0200 (CEST) Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-666e6541c98so2162693b3a.2 for ; Sat, 01 Jul 2023 00:18:53 -0700 (PDT) Received: from cog-dev.home ([70.103.208.83]) by smtp.gmail.com with ESMTPSA id s19-20020aa78d53000000b00673e652985bsm4108866pfe.118.2023.07.01.00.18.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Jul 2023 00:18:50 -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 X-Inumbo-ID: 885db715-17df-11ee-8611-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1688195932; x=1690787932; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=VZN0HVDL3v266tIzCxp1Au3MTDvSJDRQFEKwXgYQOKg=; b=YpX7sawsKZYhNUkXDrP6r+4b0ejLipURz01felmUeInxxsFgxrRszTnLYke1My3tUF 07LH6tcTz2c2CX3LDds0yu7k5LeZO8mi3Xs1B8NEhbf5U8XuO713vF8UKegIVWbRGkPo tTagkO4t7k+a8h23i2OXydHe/qLeHvgvYpA+CqIkGzxMbpDy6e8B8DwvEyHV88NA+Nsj Q4BA1MovO51sb5uLAa5vKGi6o9qcZtZHNCDpjxPBBWlmzHA3R6NyeKfMwsWrzPEt/TJp j0nwnTCn+yOhFyHjujJ70n+JvuUyTED5o59t9ykYnNKsg0CxJZDewB8vVRxgmIuSnxjV s1pQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688195932; x=1690787932; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=VZN0HVDL3v266tIzCxp1Au3MTDvSJDRQFEKwXgYQOKg=; b=VubMhGoR5sLZvesgzl4NarPaQ/FN3m/9Ro3fsTcfH9VZIOAUaDfpAaTlMyzFdb4bUE jHTWLBJ+EglgrN+ywNYnHLZp/I1WUeeHwTaLPPQlE9qLZUBaeR7rPhnMptdQs5J9OP0I ctLwZP3wu4mNUj6XoieFG1OFBQKSypjbM1ATxcUMpPVmiqyWjQ0nfxzvH7HB0VHTA5ig lpjfJw07/b208Ihl+ooGo0RDN559iDHopA3OceklifHGVmdJN5e/Rn8DdczxfcUHZCrc 9gY7wQOTQp+4RWiEd66UzWXQ9i4ckRJZ2krAbS8RtiQ0VL0SGvsKvLP3VF5MWgi0gKcH V2Cw== X-Gm-Message-State: AC+VfDy+lc/itCuWmyEOHDFBaXpfU3u0BBxTctuPhW9LchB7LWG+ZGhv mHlWjBNg6/X+t4Tth3KTGWq2QnZYTaA= X-Google-Smtp-Source: ACHHUZ6n2a0BgJsHOuyBxhZoYcbAmTWwBgBp7Scj2tR+LuLllrO5p7qgwk+xteUe1+RZDeaLy+AScQ== X-Received: by 2002:a05:6a20:448:b0:126:a5e3:3938 with SMTP id b8-20020a056a20044800b00126a5e33938mr4329586pzb.19.1688195931673; Sat, 01 Jul 2023 00:18:51 -0700 (PDT) Sender: Christopher Clark From: Christopher Clark To: xen-devel@lists.xenproject.org Cc: Daniel Smith , stefano.stabellini@amd.com, Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu , Bertrand Marquis , Luca Fancellu , Volodymyr Babchuk , Rich Persaud Subject: [PATCH 03/10] x86 setup: change bootstrap map to accept new boot module structures Date: Sat, 1 Jul 2023 00:18:28 -0700 Message-Id: <20230701071835.41599-4-christopher.w.clark@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230701071835.41599-1-christopher.w.clark@gmail.com> References: <20230701071835.41599-1-christopher.w.clark@gmail.com> MIME-Version: 1.0 To convert the x86 boot logic from multiboot to boot module structures, change the bootstrap map function to accept a boot module parameter. To allow incremental change from multiboot to boot modules across all x86 setup logic, provide a temporary inline wrapper that still accepts a multiboot module parameter and use it where necessary. The wrapper is placed in a new arch/x86 header to avoid putting a static inline function into an existing header that has no such functions already. This new header will be expanded with additional functions in subsequent patches in this series. No functional change intended. Signed-off-by: Christopher Clark Signed-off-by: Daniel P. Smith --- A new patch so v1 series patch 3 can be implemented incrementally instead. xen/arch/x86/cpu/microcode/core.c | 7 ++++--- xen/arch/x86/hvm/dom0_build.c | 4 +++- xen/arch/x86/include/asm/boot.h | 32 +++++++++++++++++++++++++++++++ xen/arch/x86/include/asm/setup.h | 3 ++- xen/arch/x86/pv/dom0_build.c | 3 ++- xen/arch/x86/setup.c | 18 +++++++++-------- xen/include/xen/bootinfo.h | 3 +++ xen/xsm/xsm_policy.c | 3 ++- 8 files changed, 58 insertions(+), 15 deletions(-) create mode 100644 xen/arch/x86/include/asm/boot.h diff --git a/xen/arch/x86/cpu/microcode/core.c b/xen/arch/x86/cpu/microcode/core.c index c3fee62906..ce3c8042a2 100644 --- a/xen/arch/x86/cpu/microcode/core.c +++ b/xen/arch/x86/cpu/microcode/core.c @@ -34,6 +34,7 @@ #include #include +#include #include #include #include @@ -180,7 +181,7 @@ void __init microcode_scan_module( if ( !test_bit(i, module_map) ) continue; - _blob_start = bootstrap_map(&mod[i]); + _blob_start = bootstrap_map_multiboot(&mod[i]); _blob_size = mod[i].mod_end; if ( !_blob_start ) { @@ -798,7 +799,7 @@ int __init microcode_init_cache(unsigned long *module_map, microcode_scan_module(module_map, mbi); if ( ucode_mod.mod_end ) - rc = early_update_cache(bootstrap_map(&ucode_mod), + rc = early_update_cache(bootstrap_map_multiboot(&ucode_mod), ucode_mod.mod_end); else if ( ucode_blob.size ) rc = early_update_cache(ucode_blob.data, ucode_blob.size); @@ -821,7 +822,7 @@ static int __init early_microcode_update_cpu(void) else if ( ucode_mod.mod_end ) { len = ucode_mod.mod_end; - data = bootstrap_map(&ucode_mod); + data = bootstrap_map_multiboot(&ucode_mod); } if ( !data ) diff --git a/xen/arch/x86/hvm/dom0_build.c b/xen/arch/x86/hvm/dom0_build.c index bf08998862..56fe89632b 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 @@ -1208,7 +1209,8 @@ 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), + rc = pvh_load_kernel(d, image, image_headroom, initrd, + bootstrap_map_multiboot(image), cmdline, &entry, &start_info); if ( rc ) { diff --git a/xen/arch/x86/include/asm/boot.h b/xen/arch/x86/include/asm/boot.h new file mode 100644 index 0000000000..10b17f12b2 --- /dev/null +++ b/xen/arch/x86/include/asm/boot.h @@ -0,0 +1,32 @@ +#ifndef __ASM_X86_BOOT_H__ +#define __ASM_X86_BOOT_H__ + +#include +#include + +#include + +static inline void *bootstrap_map_multiboot(const module_t *mod) +{ + struct boot_module bm; + + if ( !mod ) + return bootstrap_map(NULL); + + bm.start = mod->mod_start << PAGE_SHIFT; + bm.size = mod->mod_end; + + return bootstrap_map(&bm); +} + +#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/setup.h b/xen/arch/x86/include/asm/setup.h index ae0dd3915a..80d0bb2a21 100644 --- a/xen/arch/x86/include/asm/setup.h +++ b/xen/arch/x86/include/asm/setup.h @@ -1,6 +1,7 @@ #ifndef __X86_SETUP_H_ #define __X86_SETUP_H_ +#include #include #include @@ -40,7 +41,7 @@ void setup_io_bitmap(struct domain *d); unsigned long initial_images_nrpages(nodeid_t node); void discard_initial_images(void); -void *bootstrap_map(const module_t *mod); +void *bootstrap_map(const struct boot_module *mod); int xen_in_range(unsigned long mfn); diff --git a/xen/arch/x86/pv/dom0_build.c b/xen/arch/x86/pv/dom0_build.c index 6ed9f8bbed..4fe806b60d 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 @@ -374,7 +375,7 @@ int __init dom0_construct_pv(struct domain *d, unsigned int flush_flags = 0; start_info_t *si; struct vcpu *v = d->vcpu[0]; - void *image_base = bootstrap_map(image); + void *image_base = bootstrap_map_multiboot(image); unsigned long image_len = image->mod_end; void *image_start = image_base + image_headroom; unsigned long initrd_len = initrd ? initrd->mod_end : 0; diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index c0e8fc6ab7..3b623a4149 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -32,6 +32,7 @@ #include #endif #include +#include #include #include #include @@ -405,14 +406,14 @@ static void __init normalise_cpu_order(void) * Ensure a given physical memory range is present in the bootstrap mappings. * Use superpage mappings to ensure that pagetable memory needn't be allocated. */ -void *__init bootstrap_map(const module_t *mod) +void *__init bootstrap_map(const struct boot_module *mod) { static unsigned long __initdata map_cur = BOOTSTRAP_MAP_BASE; uint64_t start, end, mask = (1L << L2_PAGETABLE_SHIFT) - 1; void *ret; if ( system_state != SYS_STATE_early_boot ) - return mod ? mfn_to_virt(mod->mod_start) : NULL; + return mod ? maddr_to_virt(mod->start) : NULL; if ( !mod ) { @@ -421,8 +422,8 @@ void *__init bootstrap_map(const module_t *mod) return NULL; } - start = (uint64_t)mod->mod_start << PAGE_SHIFT; - end = start + mod->mod_end; + start = (uint64_t)mod->start; + end = start + mod->size; if ( start >= end ) return NULL; @@ -460,7 +461,7 @@ static void __init move_memory( if ( mod.mod_end > blksz ) mod.mod_end = blksz; sz = mod.mod_end - soffs; - s = bootstrap_map(&mod); + s = bootstrap_map_multiboot(&mod); mod.mod_start = (dst - doffs) >> PAGE_SHIFT; mod.mod_end = doffs + size; @@ -468,7 +469,7 @@ static void __init move_memory( mod.mod_end = blksz; if ( sz > mod.mod_end - doffs ) sz = mod.mod_end - doffs; - d = bootstrap_map(&mod); + d = bootstrap_map_multiboot(&mod); memmove(d + doffs, s + soffs, sz); @@ -1360,8 +1361,9 @@ void __init noreturn __start_xen(unsigned long mbi_p) mod[boot_info->nr_mods].mod_end = __2M_rwdata_end - _stext; } - boot_info->mods[0].arch->headroom = bzimage_headroom(bootstrap_map(mod), - mod->mod_end); + boot_info->mods[0].arch->headroom = + bzimage_headroom(bootstrap_map_multiboot(mod), mod->mod_end); + bootstrap_map(NULL); #ifndef highmem_start diff --git a/xen/include/xen/bootinfo.h b/xen/include/xen/bootinfo.h index b72ae31a66..eb93cc3439 100644 --- a/xen/include/xen/bootinfo.h +++ b/xen/include/xen/bootinfo.h @@ -10,6 +10,9 @@ #endif struct boot_module { + paddr_t start; + size_t size; + struct arch_bootmodule *arch; }; diff --git a/xen/xsm/xsm_policy.c b/xen/xsm/xsm_policy.c index 8dafbc9381..c6df8c6e06 100644 --- a/xen/xsm/xsm_policy.c +++ b/xen/xsm/xsm_policy.c @@ -20,6 +20,7 @@ #include #ifdef CONFIG_MULTIBOOT +#include #include #include #endif @@ -49,7 +50,7 @@ int __init xsm_multiboot_policy_init( if ( !test_bit(i, module_map) ) continue; - _policy_start = bootstrap_map(mod + i); + _policy_start = bootstrap_map_multiboot(mod + i); _policy_len = mod[i].mod_end; if ( (xsm_magic_t)(*_policy_start) == XSM_MAGIC ) From patchwork Sat Jul 1 07:18:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christopher Clark X-Patchwork-Id: 13298977 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 D8B62C001B3 for ; Sat, 1 Jul 2023 07:19:20 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.557774.871430 (Exim 4.92) (envelope-from ) id 1qFUsl-0007Re-Vg; Sat, 01 Jul 2023 07:18:59 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 557774.871430; Sat, 01 Jul 2023 07:18:59 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qFUsl-0007RH-Q2; Sat, 01 Jul 2023 07:18:59 +0000 Received: by outflank-mailman (input) for mailman id 557774; Sat, 01 Jul 2023 07:18:57 +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 1qFUsj-00074A-Ev for xen-devel@lists.xenproject.org; Sat, 01 Jul 2023 07:18:57 +0000 Received: from mail-pg1-x52e.google.com (mail-pg1-x52e.google.com [2607:f8b0:4864:20::52e]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 895951b8-17df-11ee-b237-6b7b168915f2; Sat, 01 Jul 2023 09:18:55 +0200 (CEST) Received: by mail-pg1-x52e.google.com with SMTP id 41be03b00d2f7-54290603887so1404339a12.1 for ; Sat, 01 Jul 2023 00:18:55 -0700 (PDT) Received: from cog-dev.home ([70.103.208.83]) by smtp.gmail.com with ESMTPSA id s19-20020aa78d53000000b00673e652985bsm4108866pfe.118.2023.07.01.00.18.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Jul 2023 00:18:52 -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 X-Inumbo-ID: 895951b8-17df-11ee-b237-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1688195933; x=1690787933; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=VdOYeE2v8wd7pgUEWtK6DPA0Re6RRRDIL0/eXfCMrB4=; b=M26WsnkTZSOxTGNSkakaGyhkyNClmHwRJrKRp1N75lO7bD5GT6kPQALOP7zlWX7gKm I3KG2qmBZpmrOKz8R14XWa+tidHoDNawk/qGcYhzw/FJi3lqHtuZVKeWo47H+jfSHn5E XdU1+g2puyG9SktPWFJmJjYeZNpGQ155oZWd3UghsHDEyUDDiankrfReLoBSsfG4D8a7 hFkpcBSo6jCP/SWCkH28CA4vtBSSpho+IqcadOHA8DkY5zXLdaiZUvOfGKu+ZChE+GIT TPcRE9N2VFQ+dq9Ou0ANf/E0ivSit7ow6HZv6spzaxuI/gregJW9UO5G9jpxRU7U1Oae IKeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688195933; x=1690787933; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=VdOYeE2v8wd7pgUEWtK6DPA0Re6RRRDIL0/eXfCMrB4=; b=c/pwCAhKi7Nqn+jX5gS/jpyYfZC5hdtDKdZHPBp4jky+IllYOlgspCe7a9ypV8YLLg B4Y0A9Hm2bKX6Dz2YdVYl69LRMdAyDDsiKuwpzxU0GGpTTIGRFGHXdImi51dfbzPehpQ Wjv7hdrrIPFp3ihax1prkx4SprCvd2GlkTYZBCUKp6RzWBHyL1bXnHfOrVqf86GMaXrF aOGV0V/Y9hW5bzMeUlJ52QcZ8pu8Xz4ExMBMKbCp0572/wf9d8cB2K7ux5dh0au7z3ZS oTJ1GPuRZxqTuVkqJYI8mWK/tjI5WSevPivopuEOur+fjxCdhVmIiWes6rpgnxZkdf4e R1jw== X-Gm-Message-State: ABy/qLb53kvM6pA0WLqbPI4/8bTijooSvHshTWVDRU9OT4IQEzei2x7f IXn6Wr3KyZ6EGeQSEPED9uNfhiKZk1Q= X-Google-Smtp-Source: APBJJlF7jbiJpd/xcLRqHauN6U7/NRmIJP9XETRlf0zI9EMG4ip+NRTzFW0GrgaAnu8NEOSFJHXePg== X-Received: by 2002:a05:6a00:190c:b0:682:1319:a169 with SMTP id y12-20020a056a00190c00b006821319a169mr4904419pfi.31.1688195933125; Sat, 01 Jul 2023 00:18:53 -0700 (PDT) Sender: Christopher Clark From: Christopher Clark To: xen-devel@lists.xenproject.org Cc: Daniel Smith , stefano.stabellini@amd.com, Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu , Bertrand Marquis , Luca Fancellu , Volodymyr Babchuk , Rich Persaud Subject: [PATCH 04/10] x86 setup: porting dom0 construction logic to boot module structures Date: Sat, 1 Jul 2023 00:18:29 -0700 Message-Id: <20230701071835.41599-5-christopher.w.clark@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230701071835.41599-1-christopher.w.clark@gmail.com> References: <20230701071835.41599-1-christopher.w.clark@gmail.com> MIME-Version: 1.0 Adjust the PV and PVH dom0 construction entry points to take boot module structures as parameters, and add further fields to the boot module structures to plumb the data needed to support this use. Populate these from the multiboot module data. This change removes multiboot from the PV and PVH dom0 construction logic. Introduce and use new inline accessor functions for navigating the boot module structures. The per-boot-module arrays are expanded from singletons to accommodate all modules, up to a static maximum of 64 modules including Xen that can be accepted from a bootloader to match the previous value from the module map check. The field that identifies the type of a boot module (kernel, ramdisk, etc) is introduced to the common boot module structure and declared as a non-enum integer type to allow the field to be of a known-size and so structure can be packed in a subsequent patch in the series, and it will then be reconciled with the equivalent Arm boot field type. The command line provided by multiboot for each boot module is added directly to the boot_module structure, which is appropriate for this logic just replacing multiboot. The maximum number of boot modules that a bootloader can provide in addition to the Xen hypervisor is preserved from prior logic with the module_map at 63. Signed-off-by: Christopher Clark Signed-off-by: Daniel P. Smith --- Changes since v1: patch is a subset of v1 series patches 2 and 3. - The module_map is kept for now since still in use. - Move the static inline functions into a separate dedicated header. - and replace prior inclusion of for simpler dependencies. xen/arch/x86/dom0_build.c | 10 +- xen/arch/x86/hvm/dom0_build.c | 43 +++--- xen/arch/x86/include/asm/boot.h | 36 +++++ xen/arch/x86/include/asm/bootinfo.h | 24 +++ xen/arch/x86/include/asm/dom0_build.h | 13 +- xen/arch/x86/include/asm/setup.h | 4 +- xen/arch/x86/pv/dom0_build.c | 32 ++-- xen/arch/x86/setup.c | 206 +++++++++++++++----------- xen/include/xen/bootinfo.h | 27 ++++ 9 files changed, 254 insertions(+), 141 deletions(-) diff --git a/xen/arch/x86/dom0_build.c b/xen/arch/x86/dom0_build.c index 9f5300a3ef..42310202a2 100644 --- a/xen/arch/x86/dom0_build.c +++ b/xen/arch/x86/dom0_build.c @@ -4,6 +4,7 @@ * Copyright (c) 2002-2005, K A Fraser */ +#include #include #include #include @@ -562,9 +563,8 @@ 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, - char *cmdline) +int __init construct_dom0(struct domain *d, const struct boot_module *image, + struct boot_module *initrd, char *cmdline) { int rc; @@ -576,9 +576,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(d, image, initrd, cmdline); else if ( is_pv_domain(d) ) - rc = dom0_construct_pv(d, image, image_headroom, initrd, cmdline); + rc = dom0_construct_pv(d, image, initrd, cmdline); 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 56fe89632b..c094863bb8 100644 --- a/xen/arch/x86/hvm/dom0_build.c +++ b/xen/arch/x86/hvm/dom0_build.c @@ -8,9 +8,9 @@ */ #include +#include #include #include -#include #include #include @@ -530,14 +530,13 @@ static paddr_t __init find_memory( return INVALID_PADDR; } -static int __init pvh_load_kernel(struct domain *d, const module_t *image, - unsigned long image_headroom, - module_t *initrd, void *image_base, - char *cmdline, paddr_t *entry, - paddr_t *start_info_addr) +static int __init pvh_load_kernel( + struct domain *d, const struct boot_module *image, + struct boot_module *initrd, void *image_base, char *cmdline, paddr_t *entry, + paddr_t *start_info_addr) { - void *image_start = image_base + image_headroom; - unsigned long image_len = image->mod_end; + void *image_start = image_base + image->arch->headroom; + unsigned long image_len = image->size; struct elf_binary elf; struct elf_dom_parms parms; paddr_t last_addr; @@ -546,7 +545,7 @@ static int __init pvh_load_kernel(struct domain *d, const module_t *image, struct vcpu *v = d->vcpu[0]; int rc; - if ( (rc = bzimage_parse(image_base, &image_start, image_headroom, + if ( (rc = bzimage_parse(image_base, &image_start, image->arch->headroom, &image_len)) != 0 ) { printk("Error trying to detect bz compressed kernel\n"); @@ -594,7 +593,7 @@ static int __init pvh_load_kernel(struct domain *d, const module_t *image, * simplify it. */ last_addr = find_memory(d, &elf, sizeof(start_info) + - (initrd ? ROUNDUP(initrd->mod_end, PAGE_SIZE) + + (initrd ? ROUNDUP(initrd->size, PAGE_SIZE) + sizeof(mod) : 0) + (cmdline ? ROUNDUP(strlen(cmdline) + 1, @@ -608,8 +607,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->mod_end, v); + rc = hvm_copy_to_guest_phys(last_addr, maddr_to_virt(initrd->start), + initrd->size, v); if ( rc ) { printk("Unable to copy initrd to guest\n"); @@ -617,11 +616,11 @@ static int __init pvh_load_kernel(struct domain *d, const module_t *image, } mod.paddr = last_addr; - mod.size = initrd->mod_end; - last_addr += ROUNDUP(initrd->mod_end, elf_64bit(&elf) ? 8 : 4); - if ( initrd->string ) + mod.size = initrd->size; + last_addr += ROUNDUP(initrd->size, elf_64bit(&elf) ? 8 : 4); + if ( initrd->string.len ) { - char *str = __va(initrd->string); + char *str = initrd->string.bytes; size_t len = strlen(str) + 1; rc = hvm_copy_to_guest_phys(last_addr, str, len, v); @@ -1176,10 +1175,9 @@ 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, - char *cmdline) +int __init dom0_construct_pvh( + struct domain *d, const struct boot_module *image, + struct boot_module *initrd, char *cmdline) { paddr_t entry, start_info; int rc; @@ -1209,9 +1207,8 @@ 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_multiboot(image), - cmdline, &entry, &start_info); + rc = pvh_load_kernel(d, image, initrd, bootstrap_map(image), cmdline, + &entry, &start_info); if ( rc ) { printk("Failed to load Dom0 kernel\n"); diff --git a/xen/arch/x86/include/asm/boot.h b/xen/arch/x86/include/asm/boot.h index 10b17f12b2..bcf4f2e2e3 100644 --- a/xen/arch/x86/include/asm/boot.h +++ b/xen/arch/x86/include/asm/boot.h @@ -19,6 +19,42 @@ static inline void *bootstrap_map_multiboot(const module_t *mod) return bootstrap_map(&bm); } +static inline unsigned long bootmodule_index( + const struct boot_info *info, bootmod_type_t bootmod_type, + unsigned long start) +{ + for ( ; start < info->nr_mods; start++ ) + if ( info->mods[start].bootmod_type == bootmod_type ) + return start; + + return info->nr_mods + 1; +} + +static inline struct boot_module *bootmodule_next( + const struct boot_info *info, bootmod_type_t bootmod_type) +{ + unsigned long i; + + for ( i = 0; i < info->nr_mods; i++ ) + if ( info->mods[i].bootmod_type == bootmod_type ) + return &info->mods[i]; + + return NULL; +} + +static inline void bootmodule_update_start(struct boot_module *bm, + paddr_t new_start) +{ + bm->start = new_start; + bm->mfn = maddr_to_mfn(new_start); +} + +static inline void bootmodule_update_mfn(struct boot_module *bm, mfn_t new_mfn) +{ + bm->mfn = new_mfn; + bm->start = mfn_to_maddr(new_mfn); +} + #endif /* diff --git a/xen/arch/x86/include/asm/bootinfo.h b/xen/arch/x86/include/asm/bootinfo.h index a25054f372..30c27980e0 100644 --- a/xen/arch/x86/include/asm/bootinfo.h +++ b/xen/arch/x86/include/asm/bootinfo.h @@ -2,9 +2,33 @@ #define __ARCH_X86_BOOTINFO_H__ struct arch_bootmodule { +#define BOOTMOD_FLAG_X86_RELOCATED 1U << 0 + uint32_t flags; unsigned headroom; }; +struct arch_boot_info { + uint32_t flags; +#define BOOTINFO_FLAG_X86_CMDLINE 1U << 2 +#define BOOTINFO_FLAG_X86_MODULES 1U << 3 +#define BOOTINFO_FLAG_X86_MEMMAP 1U << 6 +#define BOOTINFO_FLAG_X86_LOADERNAME 1U << 9 + + char *boot_loader_name; + + uint32_t mmap_length; + paddr_t mmap_addr; +}; + +struct __packed mb_memmap { + uint32_t size; + uint32_t base_addr_low; + uint32_t base_addr_high; + uint32_t length_low; + uint32_t length_high; + uint32_t type; +}; + #endif /* diff --git a/xen/arch/x86/include/asm/dom0_build.h b/xen/arch/x86/include/asm/dom0_build.h index a5f8c9e67f..ca502269f2 100644 --- a/xen/arch/x86/include/asm/dom0_build.h +++ b/xen/arch/x86/include/asm/dom0_build.h @@ -1,6 +1,7 @@ #ifndef _DOM0_BUILD_H_ #define _DOM0_BUILD_H_ +#include #include #include @@ -13,15 +14,11 @@ 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, - char *cmdline); +int dom0_construct_pv(struct domain *d, const struct boot_module *image, + struct boot_module *initrd, char *cmdline); -int dom0_construct_pvh(struct domain *d, const module_t *image, - unsigned long image_headroom, - module_t *initrd, - char *cmdline); +int dom0_construct_pvh(struct domain *d, const struct boot_module *image, + struct boot_module *initrd, char *cmdline); 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 80d0bb2a21..2d620d04c7 100644 --- a/xen/arch/x86/include/asm/setup.h +++ b/xen/arch/x86/include/asm/setup.h @@ -34,8 +34,8 @@ static inline void vesa_init(void) {}; int construct_dom0( struct domain *d, - const module_t *kernel, unsigned long kernel_headroom, - module_t *initrd, + const struct boot_module *kernel, + struct boot_module *initrd, char *cmdline); void setup_io_bitmap(struct domain *d); diff --git a/xen/arch/x86/pv/dom0_build.c b/xen/arch/x86/pv/dom0_build.c index 4fe806b60d..bc0af7cf27 100644 --- a/xen/arch/x86/pv/dom0_build.c +++ b/xen/arch/x86/pv/dom0_build.c @@ -4,12 +4,12 @@ * Copyright (c) 2002-2005, K A Fraser */ +#include #include #include #include #include #include -#include #include #include #include @@ -356,9 +356,8 @@ static struct page_info * __init alloc_chunk(struct domain *d, } int __init dom0_construct_pv(struct domain *d, - const module_t *image, - unsigned long image_headroom, - module_t *initrd, + const struct boot_module *image, + struct boot_module *initrd, char *cmdline) { int i, rc, order, machine; @@ -375,10 +374,10 @@ int __init dom0_construct_pv(struct domain *d, unsigned int flush_flags = 0; start_info_t *si; struct vcpu *v = d->vcpu[0]; - void *image_base = bootstrap_map_multiboot(image); - unsigned long image_len = image->mod_end; - void *image_start = image_base + image_headroom; - unsigned long initrd_len = initrd ? initrd->mod_end : 0; + void *image_base = bootstrap_map(image); + unsigned long image_len = image->size; + void *image_start = image_base + image->arch->headroom; + unsigned long initrd_len = initrd ? initrd->size : 0; l4_pgentry_t *l4tab = NULL, *l4start = NULL; l3_pgentry_t *l3tab = NULL, *l3start = NULL; l2_pgentry_t *l2tab = NULL, *l2start = NULL; @@ -417,7 +416,7 @@ int __init dom0_construct_pv(struct domain *d, d->max_pages = ~0U; - if ( (rc = bzimage_parse(image_base, &image_start, image_headroom, + if ( (rc = bzimage_parse(image_base, &image_start, image->arch->headroom, &image_len)) != 0 ) return rc; @@ -612,7 +611,7 @@ int __init dom0_construct_pv(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 = mfn_x(initrd->mfn); count = PFN_UP(initrd_len); if ( d->arch.physaddr_bitsize && ((mfn + count - 1) >> (d->arch.physaddr_bitsize - PAGE_SHIFT)) ) @@ -627,12 +626,13 @@ int __init dom0_construct_pv(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), maddr_to_virt(initrd->start), initrd_len); - mpt_alloc = (paddr_t)initrd->mod_start << PAGE_SHIFT; + mpt_alloc = (paddr_t)initrd->start; init_domheap_pages(mpt_alloc, mpt_alloc + PAGE_ALIGN(initrd_len)); - initrd->mod_start = initrd_mfn = mfn_x(page_to_mfn(page)); + bootmodule_update_mfn(initrd, page_to_mfn(page)); + initrd_mfn = mfn_x(initrd->mfn); } else { @@ -640,7 +640,7 @@ int __init dom0_construct_pv(struct domain *d, if ( assign_pages(mfn_to_page(_mfn(mfn++)), 1, d, 0) ) BUG(); } - initrd->mod_end = 0; + initrd->size = 0; iommu_memory_setup(d, "initrd", mfn_to_page(_mfn(initrd_mfn)), PFN_UP(initrd_len), &flush_flags); @@ -654,7 +654,7 @@ int __init dom0_construct_pv(struct domain *d, nr_pages - domain_tot_pages(d)); if ( initrd ) { - mpt_alloc = (paddr_t)initrd->mod_start << PAGE_SHIFT; + mpt_alloc = initrd->start; printk("\n Init. ramdisk: %"PRIpaddr"->%"PRIpaddr, mpt_alloc, mpt_alloc + initrd_len); } @@ -880,7 +880,7 @@ int __init dom0_construct_pv(struct domain *d, if ( pfn >= initrd_pfn ) { if ( pfn < initrd_pfn + PFN_UP(initrd_len) ) - mfn = initrd->mod_start + (pfn - initrd_pfn); + mfn = mfn_x(initrd->mfn) + (pfn - initrd_pfn); else mfn -= PFN_UP(initrd_len); } diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 3b623a4149..f9b04daebd 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -59,6 +60,9 @@ #include #include +/* Max number of boot modules a bootloader can provide in addition to Xen */ +#define MAX_NR_BOOTMODS 63 + /* opt_nosmp: If true, secondary processors are ignored. */ static bool __initdata opt_nosmp; boolean_param("nosmp", opt_nosmp); @@ -269,20 +273,44 @@ static int __init cf_check parse_acpi_param(const char *s) } custom_param("acpi", parse_acpi_param); -static const module_t *__initdata initial_images; static struct boot_info __initdata *boot_info; -static void __init multiboot_to_bootinfo(multiboot_info_t *mbi) +static void __init multiboot_to_bootinfo(multiboot_info_t *mbi, module_t *mods) { static struct boot_info __initdata info; - static struct boot_module __initdata boot_mods[1]; - static struct arch_bootmodule __initdata arch_boot_mods[1]; + static struct arch_boot_info __initdata arch_info; + static struct boot_module __initdata boot_mods[MAX_NR_BOOTMODS + 1]; + static struct arch_bootmodule __initdata arch_boot_mods[ + MAX_NR_BOOTMODS + 1]; + int i; + + info.arch = &arch_info; info.mods = boot_mods; + info.cmdline = __va(mbi->cmdline); + + /* The BOOTINFO_FLAG_X86_* flags are a 1-1 map to MBI_* */ + arch_info.flags = mbi->flags; + arch_info.mmap_length = mbi->mmap_length; + arch_info.mmap_addr = mbi->mmap_addr; + arch_info.boot_loader_name = __va(mbi->boot_loader_name); + info.nr_mods = mbi->mods_count; + for ( i = 0; i <= MAX_NR_BOOTMODS; i++ ) + { + boot_mods[i].arch = &arch_boot_mods[i]; - boot_mods[0].arch = &arch_boot_mods[0]; + if ( i < info.nr_mods ) + { + bootmodule_update_start(&boot_mods[i], mods[i].mod_start); + boot_mods[i].size = mods[i].mod_end - mods[i].mod_start; + + boot_mods[i].string.len = strlcpy(boot_mods[i].string.bytes, + __va(mods[i].string), + BOOTMOD_STRING_MAX_LEN); + } + } boot_info = &info; } @@ -296,8 +324,8 @@ unsigned long __init initial_images_nrpages(nodeid_t node) for ( nr = i = 0; i < boot_info->nr_mods; ++i ) { - unsigned long start = initial_images[i].mod_start; - unsigned long end = start + PFN_UP(initial_images[i].mod_end); + unsigned long start = mfn_x(boot_info->mods[i].mfn); + unsigned long end = start + PFN_UP(boot_info->mods[i].size); if ( end > node_start && node_end > start ) nr += min(node_end, end) - max(node_start, start); @@ -312,14 +340,13 @@ void __init discard_initial_images(void) for ( i = 0; i < boot_info->nr_mods; ++i ) { - uint64_t start = (uint64_t)initial_images[i].mod_start << PAGE_SHIFT; + uint64_t start = boot_info->mods[i].start; init_domheap_pages(start, - start + PAGE_ALIGN(initial_images[i].mod_end)); + start + PAGE_ALIGN(boot_info->mods[i].size)); } boot_info->nr_mods = 0; - initial_images = NULL; } extern unsigned char __init_begin[], __init_end[]; @@ -450,26 +477,26 @@ static void __init move_memory( while ( size ) { - module_t mod; + struct boot_module mod; unsigned int soffs = src & mask; unsigned int doffs = dst & mask; unsigned int sz; void *d, *s; - mod.mod_start = (src - soffs) >> PAGE_SHIFT; - mod.mod_end = soffs + size; - if ( mod.mod_end > blksz ) - mod.mod_end = blksz; - sz = mod.mod_end - soffs; - s = bootstrap_map_multiboot(&mod); - - mod.mod_start = (dst - doffs) >> PAGE_SHIFT; - mod.mod_end = doffs + size; - if ( mod.mod_end > blksz ) - mod.mod_end = blksz; - if ( sz > mod.mod_end - doffs ) - sz = mod.mod_end - doffs; - d = bootstrap_map_multiboot(&mod); + mod.start = src - soffs; + mod.size = soffs + size; + if ( mod.size > blksz ) + mod.size = blksz; + sz = mod.size - soffs; + s = bootstrap_map(&mod); + + mod.start = dst - doffs; + mod.size = doffs + size; + if ( mod.size > blksz ) + mod.size = blksz; + if ( sz > mod.size - doffs ) + sz = mod.size - doffs; + d = bootstrap_map(&mod); memmove(d + doffs, s + soffs, sz); @@ -602,7 +629,7 @@ static void __init noinline move_xen(void) #undef BOOTSTRAP_MAP_LIMIT static uint64_t __init consider_modules( - uint64_t s, uint64_t e, uint32_t size, const module_t *mod, + uint64_t s, uint64_t e, uint32_t size, const struct boot_module *mod, unsigned int nr_mods, unsigned int this_mod) { unsigned int i; @@ -612,8 +639,8 @@ static uint64_t __init consider_modules( for ( i = 0; i < nr_mods ; ++i ) { - uint64_t start = (uint64_t)mod[i].mod_start << PAGE_SHIFT; - uint64_t end = start + PAGE_ALIGN(mod[i].mod_end); + uint64_t start = mod[i].start; + uint64_t end = start + PAGE_ALIGN(mod[i].size); if ( i == this_mod ) continue; @@ -883,9 +910,8 @@ 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, +static struct domain *__init create_dom0(const struct boot_info *bootinfo, + const char *kextra, const char *loader) { struct xen_domctl_createdomain dom0_cfg = { @@ -899,9 +925,14 @@ static struct domain *__init create_dom0(const module_t *image, .misc_flags = opt_dom0_msr_relaxed ? XEN_X86_MSR_RELAXED : 0, }, }; + struct boot_module *image = bootmodule_next(bootinfo, BOOTMOD_KERNEL); + struct boot_module *initrd = bootmodule_next(bootinfo, BOOTMOD_RAMDISK); struct domain *d; char *cmdline; - domid_t domid; + domid_t domid = 0; + + if ( image == NULL ) + panic("Error creating d%uv0\n", domid); if ( opt_dom0_pvh ) { @@ -928,7 +959,7 @@ static struct domain *__init create_dom0(const module_t *image, panic("Error creating d%uv0\n", domid); /* Grab the DOM0 command line. */ - cmdline = image->string ? __va(image->string) : NULL; + cmdline = image->string.len ? image->string.bytes : NULL; if ( cmdline || kextra ) { static char __initdata dom0_cmdline[MAX_GUEST_CMDLINE]; @@ -968,8 +999,7 @@ static struct domain *__init create_dom0(const module_t *image, write_cr4(read_cr4() & ~X86_CR4_SMAP); } - if ( construct_dom0(d, image, boot_info->mods[0].arch->headroom, initrd, - cmdline) != 0 ) + if ( construct_dom0(d, image, initrd, cmdline) != 0 ) panic("Could not construct domain 0\n"); if ( cpu_has_smap ) @@ -1038,14 +1068,14 @@ void __init noreturn __start_xen(unsigned long mbi_p) mod = __va(mbi->mods_addr); } - multiboot_to_bootinfo(mbi); + multiboot_to_bootinfo(mbi, mod); - loader = (mbi->flags & MBI_LOADERNAME) - ? (char *)__va(mbi->boot_loader_name) : "unknown"; + loader = (boot_info->arch->flags & BOOTINFO_FLAG_X86_LOADERNAME) + ? boot_info->arch->boot_loader_name : "unknown"; /* Parse the command-line options. */ - cmdline = cmdline_cook((mbi->flags & MBI_CMDLINE) ? - __va(mbi->cmdline) : NULL, + cmdline = cmdline_cook((boot_info->arch->flags & BOOTINFO_FLAG_X86_CMDLINE) ? + boot_info->cmdline : NULL, loader); if ( (kextra = strstr(cmdline, " -- ")) != NULL ) { @@ -1147,19 +1177,22 @@ void __init noreturn __start_xen(unsigned long mbi_p) bootsym(boot_edd_info_nr)); /* Check that we have at least one Multiboot module. */ - if ( !(mbi->flags & MBI_MODULES) || (boot_info->nr_mods == 0) ) + if ( !(boot_info->arch->flags & BOOTINFO_FLAG_X86_MODULES) || + (boot_info->nr_mods == 0) ) panic("dom0 kernel not specified. Check bootloader configuration\n"); /* Check that we don't have a silly number of modules. */ - if ( boot_info->nr_mods > sizeof(module_map) * 8 ) + if ( boot_info->nr_mods > MAX_NR_BOOTMODS + 1 ) { - boot_info->nr_mods = sizeof(module_map) * 8; + boot_info->nr_mods = MAX_NR_BOOTMODS + 1; printk("Excessive multiboot modules - using the first %u only\n", boot_info->nr_mods); } - bitmap_fill(module_map, boot_info->nr_mods); + /* Dom0 kernel is the first boot module */ + bitmap_fill(module_map, mbi->mods_count); __clear_bit(0, module_map); /* Dom0 kernel is always first */ + boot_info->mods[0].bootmod_type = BOOTMOD_KERNEL; if ( pvh_boot ) { @@ -1189,13 +1222,13 @@ void __init noreturn __start_xen(unsigned long mbi_p) { memmap_type = "Xen-e820"; } - else if ( mbi->flags & MBI_MEMMAP ) + else if ( boot_info->arch->flags & BOOTINFO_FLAG_X86_MEMMAP ) { memmap_type = "Multiboot-e820"; - while ( bytes < mbi->mmap_length && + while ( bytes < boot_info->arch->mmap_length && e820_raw.nr_map < ARRAY_SIZE(e820_raw.map) ) { - memory_map_t *map = __va(mbi->mmap_addr + bytes); + struct mb_memmap *map = __va(boot_info->arch->mmap_addr + bytes); /* * This is a gross workaround for a BIOS bug. Some bootloaders do @@ -1330,17 +1363,9 @@ void __init noreturn __start_xen(unsigned long mbi_p) set_kexec_crash_area_size((u64)nr_pages << PAGE_SHIFT); kexec_reserve_area(&boot_e820); - initial_images = mod; - boot_info->nr_mods = boot_info->nr_mods; - for ( i = 0; !efi_enabled(EFI_LOADER) && i < boot_info->nr_mods; i++ ) - { - if ( mod[i].mod_start & (PAGE_SIZE - 1) ) + if ( boot_info->mods[i].start & (PAGE_SIZE - 1) ) panic("Bootloader didn't honor module alignment request\n"); - mod[i].mod_end -= mod[i].mod_start; - mod[i].mod_start >>= PAGE_SHIFT; - mod[i].reserved = 0; - } /* * TODO: load ucode earlier once multiboot modules become accessible @@ -1357,12 +1382,14 @@ void __init noreturn __start_xen(unsigned long mbi_p) * respective reserve_e820_ram() invocation below. No need to * query efi_boot_mem_unused() here, though. */ - mod[boot_info->nr_mods].mod_start = virt_to_mfn(_stext); - mod[boot_info->nr_mods].mod_end = __2M_rwdata_end - _stext; + bootmodule_update_start(&boot_info->mods[boot_info->nr_mods], + virt_to_maddr(_stext)); + boot_info->mods[boot_info->nr_mods].size = __2M_rwdata_end - _stext; } boot_info->mods[0].arch->headroom = - bzimage_headroom(bootstrap_map_multiboot(mod), mod->mod_end); + bzimage_headroom(bootstrap_map(&boot_info->mods[0]), + boot_info->mods[0].size); bootstrap_map(NULL); @@ -1420,7 +1447,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) { /* Don't overlap with modules. */ end = consider_modules(s, e, reloc_size + mask, - mod, boot_info->nr_mods, -1); + boot_info->mods, boot_info->nr_mods, -1); end &= ~mask; } else @@ -1443,15 +1470,15 @@ void __init noreturn __start_xen(unsigned long mbi_p) /* Is the region suitable for relocating the multiboot modules? */ for ( j = boot_info->nr_mods - 1; j >= 0; j-- ) { - struct boot_module *boot_mods = boot_info->mods; - unsigned long headroom = j ? 0 : boot_mods[0].arch->headroom; - unsigned long size = PAGE_ALIGN(headroom + mod[j].mod_end); + struct boot_module *boot_mod = boot_info->mods; + unsigned long headroom = j ? 0 : boot_mod[0].arch->headroom; + unsigned long size = PAGE_ALIGN(headroom + boot_mod[j].size); - if ( mod[j].reserved ) + if ( boot_mod[j].arch->flags & BOOTMOD_FLAG_X86_RELOCATED ) continue; /* Don't overlap with other modules (or Xen itself). */ - end = consider_modules(s, e, size, mod, + end = consider_modules(s, e, size, boot_info->mods, boot_info->nr_mods + relocated, j); if ( highmem_start && end > highmem_start ) @@ -1459,14 +1486,14 @@ void __init noreturn __start_xen(unsigned long mbi_p) if ( s < end && (headroom || - ((end - size) >> PAGE_SHIFT) > mod[j].mod_start) ) + ((end - size) >> PAGE_SHIFT) > mfn_x(boot_mod[j].mfn)) ) { move_memory(end - size + headroom, - (uint64_t)mod[j].mod_start << PAGE_SHIFT, - mod[j].mod_end); - mod[j].mod_start = (end - size) >> PAGE_SHIFT; - mod[j].mod_end += headroom; - mod[j].reserved = 1; + (uint64_t)boot_mod[j].start, + boot_mod[j].size); + bootmodule_update_start(&boot_mod[j], end - size); + boot_mod[j].size += headroom; + boot_mod[j].arch->flags |= BOOTMOD_FLAG_X86_RELOCATED; } } @@ -1478,7 +1505,8 @@ void __init noreturn __start_xen(unsigned long mbi_p) while ( !kexec_crash_area.start ) { /* Don't overlap with modules (or Xen itself). */ - e = consider_modules(s, e, PAGE_ALIGN(kexec_crash_area.size), mod, + e = consider_modules(s, e, PAGE_ALIGN(kexec_crash_area.size), + boot_info->mods, boot_info->nr_mods + relocated, -1); if ( s >= e ) break; @@ -1492,13 +1520,14 @@ void __init noreturn __start_xen(unsigned long mbi_p) #endif } - if ( boot_info->mods[0].arch->headroom && !mod->reserved ) + if ( boot_info->mods[0].arch->headroom && + !(boot_info->mods[0].arch->flags & BOOTMOD_FLAG_X86_RELOCATED) ) panic("Not enough memory to relocate the dom0 kernel image\n"); for ( i = 0; i < boot_info->nr_mods; ++i ) { - uint64_t s = (uint64_t)mod[i].mod_start << PAGE_SHIFT; + uint64_t s = (uint64_t)boot_info->mods[i].start; - reserve_e820_ram(&boot_e820, s, s + PAGE_ALIGN(mod[i].mod_end)); + reserve_e820_ram(&boot_e820, s, s + PAGE_ALIGN(boot_info->mods[i].size)); } if ( !xen_phys_start ) @@ -1565,8 +1594,8 @@ void __init noreturn __start_xen(unsigned long mbi_p) map_e = boot_e820.map[j].addr + boot_e820.map[j].size; for ( j = 0; j < boot_info->nr_mods; ++j ) { - uint64_t end = pfn_to_paddr(mod[j].mod_start) + - mod[j].mod_end; + uint64_t end = mfn_to_maddr(boot_info->mods[j].mfn) + + boot_info->mods[j].size; if ( map_e < end ) map_e = end; @@ -1641,11 +1670,12 @@ void __init noreturn __start_xen(unsigned long mbi_p) for ( i = 0; i < boot_info->nr_mods; ++i ) { - set_pdx_range(mod[i].mod_start, - mod[i].mod_start + PFN_UP(mod[i].mod_end)); - map_pages_to_xen((unsigned long)mfn_to_virt(mod[i].mod_start), - _mfn(mod[i].mod_start), - PFN_UP(mod[i].mod_end), PAGE_HYPERVISOR); + set_pdx_range(mfn_x(boot_info->mods[i].mfn), + mfn_x(boot_info->mods[i].mfn) + + PFN_UP(boot_info->mods[i].size)); + map_pages_to_xen((unsigned long)maddr_to_virt(boot_info->mods[i].start), + boot_info->mods[i].mfn, + PFN_UP(boot_info->mods[i].size), PAGE_HYPERVISOR); } #ifdef CONFIG_KEXEC @@ -2022,8 +2052,12 @@ void __init noreturn __start_xen(unsigned long mbi_p) cpu_has_nx ? XENLOG_INFO : XENLOG_WARNING "Warning: ", cpu_has_nx ? "" : "not "); - initrdidx = find_first_bit(module_map, boot_info->nr_mods); - if ( bitmap_weight(module_map, boot_info->nr_mods) > 1 ) + initrdidx = bootmodule_index(boot_info, BOOTMOD_UNKNOWN, 0); + if ( initrdidx < boot_info->nr_mods ) + boot_info->mods[initrdidx].bootmod_type = BOOTMOD_RAMDISK; + + if ( bootmodule_index(boot_info, BOOTMOD_UNKNOWN, 0) > + boot_info->nr_mods ) printk(XENLOG_WARNING "Multiple initrd candidates, picking module #%u\n", initrdidx); @@ -2032,9 +2066,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) * 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(mod, boot_info->mods[0].arch->headroom, - initrdidx < boot_info->nr_mods ? mod + initrdidx : NULL, - kextra, loader); + dom0 = create_dom0(boot_info, kextra, loader); if ( !dom0 ) panic("Could not set up DOM0 guest OS\n"); diff --git a/xen/include/xen/bootinfo.h b/xen/include/xen/bootinfo.h index eb93cc3439..2f4284a91f 100644 --- a/xen/include/xen/bootinfo.h +++ b/xen/include/xen/bootinfo.h @@ -2,23 +2,50 @@ #define __XEN_BOOTINFO_H__ #include +#include +#include #ifdef CONFIG_X86 #include #else struct arch_bootmodule { }; + struct arch_boot_info { }; #endif +/* Boot module binary type / purpose */ +#define BOOTMOD_UNKNOWN 0 +#define BOOTMOD_XEN 1 +#define BOOTMOD_FDT 2 +#define BOOTMOD_KERNEL 3 +#define BOOTMOD_RAMDISK 4 +#define BOOTMOD_XSM 5 +#define BOOTMOD_UCODE 6 +#define BOOTMOD_GUEST_DTB 7 +typedef unsigned int bootmod_type_t; + +#define BOOTMOD_STRING_MAX_LEN 1024 +struct boot_string { + char bytes[BOOTMOD_STRING_MAX_LEN]; + size_t len; +}; + struct boot_module { + bootmod_type_t bootmod_type; paddr_t start; + mfn_t mfn; size_t size; struct arch_bootmodule *arch; + struct boot_string string; }; struct boot_info { + char *cmdline; + unsigned int nr_mods; struct boot_module *mods; + + struct arch_boot_info *arch; }; #endif From patchwork Sat Jul 1 07:18:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christopher Clark X-Patchwork-Id: 13298970 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 7114DC001B0 for ; Sat, 1 Jul 2023 07:19:11 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.557775.871435 (Exim 4.92) (envelope-from ) id 1qFUsm-0007VE-Bn; Sat, 01 Jul 2023 07:19:00 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 557775.871435; Sat, 01 Jul 2023 07:19:00 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qFUsm-0007Tv-4v; Sat, 01 Jul 2023 07:19:00 +0000 Received: by outflank-mailman (input) for mailman id 557775; Sat, 01 Jul 2023 07:18:58 +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 1qFUsk-00074A-4S for xen-devel@lists.xenproject.org; Sat, 01 Jul 2023 07:18:58 +0000 Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [2607:f8b0:4864:20::436]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 8a442a66-17df-11ee-b237-6b7b168915f2; Sat, 01 Jul 2023 09:18:56 +0200 (CEST) Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-666e97fcc60so1887762b3a.3 for ; Sat, 01 Jul 2023 00:18:56 -0700 (PDT) Received: from cog-dev.home ([70.103.208.83]) by smtp.gmail.com with ESMTPSA id s19-20020aa78d53000000b00673e652985bsm4108866pfe.118.2023.07.01.00.18.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Jul 2023 00:18:53 -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 X-Inumbo-ID: 8a442a66-17df-11ee-b237-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1688195934; x=1690787934; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=2CCuYNE2IdEGJiRf9KcQxz9oSopCuIZzH05nVBt98V4=; b=L/C1FJaAKKXcrKwwbXfoXKbQbJyRAJdJNLqD8rSSdTsYDwF3QnFSP2qbAA042bSu5Z OFZIrW0J+Zhh+BmakoPWDH4ZzFTQsvVUEeVlHYaCl918lGW6Wh1jbVC1a924pKTMIMLT ixYBYRX9jRyGqkbarfkYRUMvVl5fs3x8ji0pYYcTxKG4Let565+Wt7m4ReGqVoGYWV/Q eZAegTnZa6qvgzw7JfcDFp7OBQWvL2j5oe7Y+LfTbHhysp/YtRNS3at1rUL4Y9/Ctk9C 0nM3B33hMsgll472cqdFo+kHWDEq4HWIonXRH9BcfTq55X2I9HyYK3UkD8bHLjcEwR6W CSSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688195934; x=1690787934; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=2CCuYNE2IdEGJiRf9KcQxz9oSopCuIZzH05nVBt98V4=; b=BLwRZZzEoDJzHnnwu9u+6xKgS38426q7sDor8LUo5G9n1xX+eM9GItEq65nOWeUyZ9 DnWseHP9hzHpvh7FuwDsMogLViTUOEo5qGByRb6dSMrFMZkC9w93CSbdksJDCh1gSwYO QLTiXu8vVjsIgHAgDN4PJFCkC5YHDZmMXT/Cmu4LOISBJ5cp0Zo456YUM9LNnCUBWJfT GtvSqeAHVPTdzcH+XyaSR7mDpMT7/+k/nEsw2HsczTs5qNWPJJ98BWM+J8AXDZRuIHzV UpNTah1Qq6i+qRSYwepddB277+r+5vaWBy+FSDbhlkp3wbar3bkciF99bo+nfk7CLpZw j24g== X-Gm-Message-State: ABy/qLZ9tzvuTjkna5RzisUUdxkxoNud6/YggGePXYZ+Dz2xXuWoOVWN OYoRrxonIbDhan10ZXkD8WW8fWvo7zE= X-Google-Smtp-Source: APBJJlFwakyPH8XJc7p5VcZt6PmkVcFDYaVMV4ECD1CzygH3D1pud2JwVpwTI/RepQYB4r6d0mLbRQ== X-Received: by 2002:a05:6a00:1792:b0:64d:1c59:6767 with SMTP id s18-20020a056a00179200b0064d1c596767mr4767504pfg.24.1688195934527; Sat, 01 Jul 2023 00:18:54 -0700 (PDT) Sender: Christopher Clark From: Christopher Clark To: xen-devel@lists.xenproject.org Cc: Daniel Smith , stefano.stabellini@amd.com, Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu , Bertrand Marquis , Luca Fancellu , Volodymyr Babchuk , Rich Persaud Subject: [PATCH 05/10] xsm: switch XSM init to boot info structures Date: Sat, 1 Jul 2023 00:18:30 -0700 Message-Id: <20230701071835.41599-6-christopher.w.clark@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230701071835.41599-1-christopher.w.clark@gmail.com> References: <20230701071835.41599-1-christopher.w.clark@gmail.com> MIME-Version: 1.0 Change the XSM implementation to use the boot info structure instead of the multiboot module_map. Drops a dependency on CONFIG_MULTIBOOT, so boot module logic is now used whenever the DEVICE_TREE specific logic (for Arm) is not, with the bootinfo header conditionally included to ensure no change on Arm. Adds a multiboot header inclusion into guest/xen/pvh-boot.c since it is no longer provided via transitive inclusion and the source in that file uses multiboot structures. Signed-off-by: Christopher Clark Signed-off-by: Daniel P. Smith --- Changes since v1: patch is a subset of v1 series patches 2 and 3. - Added the inclusion to pvh-boot.c - Use conditional inclusion for xen/arch/x86/guest/xen/pvh-boot.c | 1 + xen/arch/x86/setup.c | 2 +- xen/include/xsm/xsm.h | 28 +++++++-------- xen/xsm/xsm_core.c | 47 +++++++++++++++--------- xen/xsm/xsm_policy.c | 59 ++++++++++++++++--------------- 5 files changed, 77 insertions(+), 60 deletions(-) diff --git a/xen/arch/x86/guest/xen/pvh-boot.c b/xen/arch/x86/guest/xen/pvh-boot.c index 9cbe87b61b..1ed04d035c 100644 --- a/xen/arch/x86/guest/xen/pvh-boot.c +++ b/xen/arch/x86/guest/xen/pvh-boot.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index f9b04daebd..a616ccc0a8 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -1835,7 +1835,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) mmio_ro_ranges = rangeset_new(NULL, "r/o mmio ranges", RANGESETF_prettyprint_hex); - xsm_multiboot_init(module_map, mbi); + xsm_bootmodule_init(boot_info); /* * IOMMU-related ACPI table parsing may require some of the system domains diff --git a/xen/include/xsm/xsm.h b/xen/include/xsm/xsm.h index 8dad03fd3d..d409c30be6 100644 --- a/xen/include/xsm/xsm.h +++ b/xen/include/xsm/xsm.h @@ -16,8 +16,10 @@ #define __XSM_H__ #include +#ifndef CONFIG_HAS_DEVICE_TREE +# include +#endif #include -#include /* policy magic number (defined by XSM_MAGIC) */ typedef uint32_t xsm_magic_t; @@ -776,15 +778,14 @@ static inline int xsm_argo_send(const struct domain *d, const struct domain *t) #endif /* XSM_NO_WRAPPERS */ -#ifdef CONFIG_MULTIBOOT -int xsm_multiboot_init( - unsigned long *module_map, const multiboot_info_t *mbi); -int xsm_multiboot_policy_init( - unsigned long *module_map, const multiboot_info_t *mbi, - void **policy_buffer, size_t *policy_size); -#endif +#ifndef CONFIG_HAS_DEVICE_TREE +int xsm_bootmodule_init(const struct boot_info *info); +int xsm_bootmodule_policy_init( + const struct boot_info *info, const unsigned char **policy_buffer, + size_t *policy_size); + +#else -#ifdef CONFIG_HAS_DEVICE_TREE /* * Initialize XSM * @@ -826,15 +827,14 @@ static const inline struct xsm_ops *silo_init(void) #include -#ifdef CONFIG_MULTIBOOT -static inline int xsm_multiboot_init ( - unsigned long *module_map, const multiboot_info_t *mbi) +#ifndef CONFIG_HAS_DEVICE_TREE +static inline int xsm_bootmodule_init(const struct boot_info *info) { return 0; } -#endif -#ifdef CONFIG_HAS_DEVICE_TREE +#else + static inline int xsm_dt_init(void) { return 0; diff --git a/xen/xsm/xsm_core.c b/xen/xsm/xsm_core.c index eaa028109b..301ae4dc8b 100644 --- a/xen/xsm/xsm_core.c +++ b/xen/xsm/xsm_core.c @@ -10,8 +10,12 @@ * as published by the Free Software Foundation. */ -#include +#ifndef CONFIG_HAS_DEVICE_TREE +# include +#endif #include +#include +#include #include #include @@ -138,26 +142,35 @@ static int __init xsm_core_init(const void *policy_buffer, size_t policy_size) return 0; } -#ifdef CONFIG_MULTIBOOT -int __init xsm_multiboot_init( - unsigned long *module_map, const multiboot_info_t *mbi) +/* + * ifdef'ing this against multiboot is no longer valid as the boot module + * is agnostic and it will be possible to dropped the ifndef should Arm + * adopt boot info + */ +#ifndef CONFIG_HAS_DEVICE_TREE +int __init xsm_bootmodule_init(const struct boot_info *bootinfo) { int ret = 0; - void *policy_buffer = NULL; + const unsigned char *policy_buffer = NULL; size_t policy_size = 0; printk("XSM Framework v" XSM_FRAMEWORK_VERSION " initialized\n"); if ( XSM_MAGIC ) { - ret = xsm_multiboot_policy_init(module_map, mbi, &policy_buffer, - &policy_size); - if ( ret ) - { - bootstrap_map(NULL); - printk(XENLOG_ERR "Error %d initializing XSM policy\n", ret); - return -EINVAL; - } + int ret = xsm_bootmodule_policy_init(bootinfo, &policy_buffer, + &policy_size); + bootstrap_map(NULL); + + if ( ret == -ENOENT ) + /* + * The XSM module needs a policy file but one was not located. + * Report as a warning and continue as the XSM module may late + * load a policy file. + */ + printk(XENLOG_WARNING "xsm: starting without a policy loaded!\n"); + else if ( ret ) + panic("Error %d initializing XSM policy\n", ret); } ret = xsm_core_init(policy_buffer, policy_size); @@ -165,9 +178,9 @@ int __init xsm_multiboot_init( return 0; } -#endif -#ifdef CONFIG_HAS_DEVICE_TREE +#else + int __init xsm_dt_init(void) { int ret = 0; @@ -215,9 +228,9 @@ bool __init has_xsm_magic(paddr_t start) return false; } -#endif +#endif /* CONFIG_HAS_DEVICE_TREE */ -#endif +#endif /* CONFIG_XSM */ long do_xsm_op(XEN_GUEST_HANDLE_PARAM(void) op) { diff --git a/xen/xsm/xsm_policy.c b/xen/xsm/xsm_policy.c index c6df8c6e06..f1970c8964 100644 --- a/xen/xsm/xsm_policy.c +++ b/xen/xsm/xsm_policy.c @@ -18,62 +18,65 @@ * */ -#include -#ifdef CONFIG_MULTIBOOT -#include -#include -#include -#endif #include +#ifndef CONFIG_HAS_DEVICE_TREE +# include +#endif +#include #ifdef CONFIG_HAS_DEVICE_TREE -# include # include +#else +#include #endif -#ifdef CONFIG_MULTIBOOT -int __init xsm_multiboot_policy_init( - unsigned long *module_map, const multiboot_info_t *mbi, - void **policy_buffer, size_t *policy_size) +#include + +#ifndef CONFIG_HAS_DEVICE_TREE +int __init xsm_bootmodule_policy_init( + const struct boot_info *bootinfo, const unsigned char **policy_buffer, + size_t *policy_size) { - int i; - module_t *mod = (module_t *)__va(mbi->mods_addr); - int rc = 0; + unsigned long i; + int rc = -ENOENT; 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 = mbi->mods_count-1; i >= 1; i-- ) - { - if ( !test_bit(i, module_map) ) - continue; +#ifdef CONFIG_XSM_FLASK_POLICY + /* Initially set to builtin policy, overriden if boot module is found. */ + *policy_buffer = xsm_flask_init_policy; + *policy_size = xsm_flask_init_policy_size; + rc = 0; +#endif - _policy_start = bootstrap_map_multiboot(mod + i); - _policy_len = mod[i].mod_end; + i = bootmodule_index(bootinfo, BOOTMOD_UNKNOWN, 0); + while ( i < bootinfo->nr_mods ) + { + _policy_start = bootstrap_map(&bootinfo->mods[i]); + _policy_len = bootinfo->mods[i].size; if ( (xsm_magic_t)(*_policy_start) == XSM_MAGIC ) { - *policy_buffer = _policy_start; + *policy_buffer = (unsigned char *)_policy_start; *policy_size = _policy_len; printk("Policy len %#lx, start at %p.\n", _policy_len,_policy_start); - __clear_bit(i, module_map); + bootinfo->mods[i].bootmod_type = BOOTMOD_XSM; + rc = 0; break; } bootstrap_map(NULL); + i = bootmodule_index(bootinfo, BOOTMOD_UNKNOWN, ++i); } return rc; } -#endif -#ifdef CONFIG_HAS_DEVICE_TREE +#else + int __init xsm_dt_policy_init(void **policy_buffer, size_t *policy_size) { struct bootmodule *mod = boot_module_find_by_kind(BOOTMOD_XSM); From patchwork Sat Jul 1 07:18:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christopher Clark X-Patchwork-Id: 13298976 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 8103EEB64DD for ; Sat, 1 Jul 2023 07:19:20 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.557776.871444 (Exim 4.92) (envelope-from ) id 1qFUsn-0007hy-BI; Sat, 01 Jul 2023 07:19:01 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 557776.871444; Sat, 01 Jul 2023 07:19:01 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qFUsm-0007fn-TN; Sat, 01 Jul 2023 07:19:00 +0000 Received: by outflank-mailman (input) for mailman id 557776; Sat, 01 Jul 2023 07:18:59 +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 1qFUsl-00074A-4k for xen-devel@lists.xenproject.org; Sat, 01 Jul 2023 07:18:59 +0000 Received: from mail-qk1-x733.google.com (mail-qk1-x733.google.com [2607:f8b0:4864:20::733]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 8ae6847b-17df-11ee-b237-6b7b168915f2; Sat, 01 Jul 2023 09:18:57 +0200 (CEST) Received: by mail-qk1-x733.google.com with SMTP id af79cd13be357-765a7768f1dso259805885a.0 for ; Sat, 01 Jul 2023 00:18:57 -0700 (PDT) Received: from cog-dev.home ([70.103.208.83]) by smtp.gmail.com with ESMTPSA id s19-20020aa78d53000000b00673e652985bsm4108866pfe.118.2023.07.01.00.18.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Jul 2023 00:18:55 -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 X-Inumbo-ID: 8ae6847b-17df-11ee-b237-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1688195936; x=1690787936; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=zZcp6XBY1YAC9oeotb5zJ/fGSdzt/Mx/a1Oe4w1mVBI=; b=ILmm9e/9lTp9GTg1saAsg7g1OS7yf4jCGZwg0akeM2mI0eRae5so14i3XdhUMh+qaa WvicC4epjfhJ1KgZeK/e5xz4jBIFr1AvNW1MB8zRZGTP3UqrTmEKUDwdJ7lYGNrL0kYo W7eJJCHmsS1p5VVGOTbmnt9B25qJIGISHnW/KS3zoRc6b0p5zTwjPDP1RlEkxvb9ai26 Ff3gpgsic09OIQkUbADqfAmHETGZJiy3Lm/8TvvJqr6fuh3R7hBi4Mqs8pY02gL+6K7m Q+oAco6AU+2LzNqpPKBAyn2krxQOaAyH+0px9DeXfCeULpV16sLShIA+hMsZgendVEpi DGjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688195936; x=1690787936; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=zZcp6XBY1YAC9oeotb5zJ/fGSdzt/Mx/a1Oe4w1mVBI=; b=gMstzg2ZJq6aYPb2GEvCv8vqtB2zsXuRZIvehsreBf9UcaAXI5F3HvfgFGfrU6XGea G6+u38UvLdQDOfJecvHaFgDEFnOlXXsnparkLx3XXYQQTFAqzrzWPWf0jBhrJdJx2cYn gWbu/JPva7D6/oyTNHuBXbTJOU6/sFR2YWpYh7BYt5YT/VjJmJXcCcG1cY9An5ARexlQ xrtLWWcSk1PiTeL1dnZuhUQqnQKiJ8cvMoEO52T9up/psg3VrGvA/ba1E5DIZU2O/m4V y3gKZczkTL6bymO536zkmgvLZrnaDTHFnE19GcMuj/mfeat9A7NjxxIe3SeXw5+G+RW+ 4toQ== X-Gm-Message-State: AC+VfDzsuUMqzIcxBqUcyjhsOotH0TOLONiN8rttpgO2EFu0+vZZV8ez OWNB8X/AVzaR9h23vdp3gjxbnZqtBLI= X-Google-Smtp-Source: ACHHUZ6G4ziS9OlcacmAYXEWytMGOapbZ5lrvuY5UYngxSJMQYFoJYsz5UXL9WWUNXBnxHWZfGdaKA== X-Received: by 2002:a05:620a:450b:b0:767:2bb9:d187 with SMTP id t11-20020a05620a450b00b007672bb9d187mr6726381qkp.1.1688195936202; Sat, 01 Jul 2023 00:18:56 -0700 (PDT) Sender: Christopher Clark From: Christopher Clark To: xen-devel@lists.xenproject.org Cc: Daniel Smith , stefano.stabellini@amd.com, Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu , Bertrand Marquis , Luca Fancellu , Volodymyr Babchuk , Rich Persaud Subject: [PATCH 06/10] x86 setup, microcode: switch to the new bootinfo structures Date: Sat, 1 Jul 2023 00:18:31 -0700 Message-Id: <20230701071835.41599-7-christopher.w.clark@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230701071835.41599-1-christopher.w.clark@gmail.com> References: <20230701071835.41599-1-christopher.w.clark@gmail.com> MIME-Version: 1.0 Next step in incremental work towards adding a non-multiboot internal representation of boot modules, converting the fields being accessed for the startup calculations. Move the per-module scan logic into a dedicated function from the iteration loop and set the BOOTMOD_UCODE module type when microcode is found. Completes the conversion from the module_map bitmap in x86 setup so it can be removed, along with the temporary bootstrap_map multiboot wrapper since the last code that uses it is removed in this change. Signed-off-by: Christopher Clark Signed-off-by: Daniel P. Smith Reviewed-by: Stefano Stabellini --- Changes since v1: patch is a subset of v1 series patches 2 and 3. - Added the removal of the temporary bootstrap map function xen/arch/x86/cpu/microcode/core.c | 148 +++++++++++++++------------ xen/arch/x86/include/asm/boot.h | 13 --- xen/arch/x86/include/asm/microcode.h | 7 +- xen/arch/x86/setup.c | 8 +- 4 files changed, 89 insertions(+), 87 deletions(-) diff --git a/xen/arch/x86/cpu/microcode/core.c b/xen/arch/x86/cpu/microcode/core.c index ce3c8042a2..d2cae9b6b4 100644 --- a/xen/arch/x86/cpu/microcode/core.c +++ b/xen/arch/x86/cpu/microcode/core.c @@ -22,12 +22,12 @@ */ #include +#include #include #include #include #include #include -#include #include #include #include @@ -57,7 +57,6 @@ */ #define MICROCODE_UPDATE_TIMEOUT_US 1000000 -static module_t __initdata ucode_mod; static signed int __initdata ucode_mod_idx; static bool_t __initdata ucode_mod_forced; static unsigned int nr_cores; @@ -150,75 +149,109 @@ static int __init cf_check parse_ucode(const char *s) } custom_param("ucode", parse_ucode); -void __init microcode_scan_module( - unsigned long *module_map, - const multiboot_info_t *mbi) +#define MICROCODE_MODULE_MATCH 1 +#define MICROCODE_MODULE_NONMATCH 0 + +static int __init microcode_check_module(struct boot_module *mod) { - module_t *mod = (module_t *)__va(mbi->mods_addr); uint64_t *_blob_start; unsigned long _blob_size; - struct cpio_data cd; + struct cpio_data cd = { NULL, 0 }; long offset; const char *p = NULL; - int i; - - ucode_blob.size = 0; - if ( !ucode_scan ) - return; if ( boot_cpu_data.x86_vendor == X86_VENDOR_AMD ) p = "kernel/x86/microcode/AuthenticAMD.bin"; else if ( boot_cpu_data.x86_vendor == X86_VENDOR_INTEL ) p = "kernel/x86/microcode/GenuineIntel.bin"; else + return -EFAULT; + + _blob_start = bootstrap_map(mod); + _blob_size = mod->size; + if ( !_blob_start ) + { + printk("Could not map multiboot module (0x%lx) (size: %ld)\n", + mod->start, _blob_size); + /* Non-fatal error, so just say no match */ + return MICROCODE_MODULE_NONMATCH; + } + + cd = find_cpio_data(p, _blob_start, _blob_size, &offset /* ignore */); + + if ( cd.data ) + { + ucode_blob.size = cd.size; + ucode_blob.data = cd.data; + + mod->bootmod_type = BOOTMOD_UCODE; + return MICROCODE_MODULE_MATCH; + } + + bootstrap_map(NULL); + + return MICROCODE_MODULE_NONMATCH; +} + +void __init microcode_scan_module(struct boot_info *bootinfo) +{ + int i; + + if ( !ucode_scan ) return; - /* - * Try all modules and see whichever could be the microcode blob. - */ - for ( i = 1 /* Ignore dom0 kernel */; i < mbi->mods_count; i++ ) + i = bootmodule_index(bootinfo, BOOTMOD_UNKNOWN, 0); + while ( i < bootinfo->nr_mods ) { - if ( !test_bit(i, module_map) ) - continue; + int ret = microcode_check_module(&bootinfo->mods[i]); - _blob_start = bootstrap_map_multiboot(&mod[i]); - _blob_size = mod[i].mod_end; - if ( !_blob_start ) + switch ( ret ) { - printk("Could not map multiboot module #%d (size: %ld)\n", - i, _blob_size); + case MICROCODE_MODULE_MATCH: + return; + case MICROCODE_MODULE_NONMATCH: + i = bootmodule_index(bootinfo, BOOTMOD_UNKNOWN, ++i); continue; + default: + printk("%s: (err: %d) unable to check microcode\n", + __func__, ret); + return; } - cd.data = NULL; - cd.size = 0; - cd = find_cpio_data(p, _blob_start, _blob_size, &offset /* ignore */); - if ( cd.data ) - { - ucode_blob.size = cd.size; - ucode_blob.data = cd.data; - break; - } - bootstrap_map(NULL); } } -static void __init microcode_grab_module( - unsigned long *module_map, - const multiboot_info_t *mbi) +static void __init microcode_grab_module(struct boot_info *bootinfo) { - module_t *mod = (module_t *)__va(mbi->mods_addr); + ucode_blob.size = 0; if ( ucode_mod_idx < 0 ) - ucode_mod_idx += mbi->mods_count; - if ( ucode_mod_idx <= 0 || ucode_mod_idx >= mbi->mods_count || - !__test_and_clear_bit(ucode_mod_idx, module_map) ) - goto scan; - ucode_mod = mod[ucode_mod_idx]; -scan: + ucode_mod_idx += bootinfo->nr_mods; + if ( ucode_mod_idx >= 0 && ucode_mod_idx <= bootinfo->nr_mods && + bootinfo->mods[ucode_mod_idx].bootmod_type == BOOTMOD_UNKNOWN ) + { + int ret = microcode_check_module(&bootinfo->mods[ucode_mod_idx]); + + switch ( ret ) + { + case MICROCODE_MODULE_MATCH: + return; + case MICROCODE_MODULE_NONMATCH: + break; + default: + printk("%s: (err: %d) unable to check microcode\n", + __func__, ret); + return; + } + } + if ( ucode_scan ) - microcode_scan_module(module_map, mbi); + microcode_scan_module(bootinfo); } +/* Undefining as they are not needed anymore */ +#undef MICROCODE_MODULE_MATCH +#undef MICROCODE_MODULE_NONMATCH + static struct microcode_ops __ro_after_init ucode_ops; static DEFINE_SPINLOCK(microcode_mutex); @@ -738,11 +771,6 @@ static int __init cf_check microcode_init(void) ucode_blob.size = 0; ucode_blob.data = NULL; } - else if ( ucode_mod.mod_end ) - { - bootstrap_map(NULL); - ucode_mod.mod_end = 0; - } return 0; } @@ -786,8 +814,7 @@ static int __init early_update_cache(const void *data, size_t len) return rc; } -int __init microcode_init_cache(unsigned long *module_map, - const struct multiboot_info *mbi) +int __init microcode_init_cache(struct boot_info *bootinfo) { int rc = 0; @@ -796,12 +823,9 @@ int __init microcode_init_cache(unsigned long *module_map, if ( ucode_scan ) /* Need to rescan the modules because they might have been relocated */ - microcode_scan_module(module_map, mbi); + microcode_scan_module(bootinfo); - if ( ucode_mod.mod_end ) - rc = early_update_cache(bootstrap_map_multiboot(&ucode_mod), - ucode_mod.mod_end); - else if ( ucode_blob.size ) + if ( ucode_blob.size ) rc = early_update_cache(ucode_blob.data, ucode_blob.size); return rc; @@ -819,11 +843,6 @@ static int __init early_microcode_update_cpu(void) len = ucode_blob.size; data = ucode_blob.data; } - else if ( ucode_mod.mod_end ) - { - len = ucode_mod.mod_end; - data = bootstrap_map_multiboot(&ucode_mod); - } if ( !data ) return -ENOMEM; @@ -842,8 +861,7 @@ static int __init early_microcode_update_cpu(void) return microcode_update_cpu(patch); } -int __init early_microcode_init(unsigned long *module_map, - const struct multiboot_info *mbi) +int __init early_microcode_init(struct boot_info *bootinfo) { const struct cpuinfo_x86 *c = &boot_cpu_data; int rc = 0; @@ -867,11 +885,11 @@ int __init early_microcode_init(unsigned long *module_map, return -ENODEV; } - microcode_grab_module(module_map, mbi); + microcode_grab_module(bootinfo); ucode_ops.collect_cpu_info(); - if ( ucode_mod.mod_end || ucode_blob.size ) + if ( ucode_blob.size ) rc = early_microcode_update_cpu(); return rc; diff --git a/xen/arch/x86/include/asm/boot.h b/xen/arch/x86/include/asm/boot.h index bcf4f2e2e3..e51fd32280 100644 --- a/xen/arch/x86/include/asm/boot.h +++ b/xen/arch/x86/include/asm/boot.h @@ -6,19 +6,6 @@ #include -static inline void *bootstrap_map_multiboot(const module_t *mod) -{ - struct boot_module bm; - - if ( !mod ) - return bootstrap_map(NULL); - - bm.start = mod->mod_start << PAGE_SHIFT; - bm.size = mod->mod_end; - - return bootstrap_map(&bm); -} - static inline unsigned long bootmodule_index( const struct boot_info *info, bootmod_type_t bootmod_type, unsigned long start) diff --git a/xen/arch/x86/include/asm/microcode.h b/xen/arch/x86/include/asm/microcode.h index 62ce3418f7..803fbbb270 100644 --- a/xen/arch/x86/include/asm/microcode.h +++ b/xen/arch/x86/include/asm/microcode.h @@ -1,6 +1,7 @@ #ifndef ASM_X86__MICROCODE_H #define ASM_X86__MICROCODE_H +#include #include #include @@ -23,10 +24,8 @@ DECLARE_PER_CPU(struct cpu_signature, cpu_sig); void microcode_set_module(unsigned int idx); int microcode_update(XEN_GUEST_HANDLE(const_void), unsigned long len); -int early_microcode_init(unsigned long *module_map, - const struct multiboot_info *mbi); -int microcode_init_cache(unsigned long *module_map, - const struct multiboot_info *mbi); +int early_microcode_init(struct boot_info *bootinfo); +int microcode_init_cache(struct boot_info *bootinfo); int microcode_update_one(void); #endif /* ASM_X86__MICROCODE_H */ diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index a616ccc0a8..50a1a124b0 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -1023,7 +1023,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) unsigned int initrdidx, num_parked = 0; multiboot_info_t *mbi; module_t *mod; - unsigned long nr_pages, raw_max_page, module_map[1]; + 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; @@ -1190,8 +1190,6 @@ void __init noreturn __start_xen(unsigned long mbi_p) } /* Dom0 kernel is the first boot module */ - bitmap_fill(module_map, mbi->mods_count); - __clear_bit(0, module_map); /* Dom0 kernel is always first */ boot_info->mods[0].bootmod_type = BOOTMOD_KERNEL; if ( pvh_boot ) @@ -1371,7 +1369,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) * TODO: load ucode earlier once multiboot modules become accessible * at an earlier stage. */ - early_microcode_init(module_map, mbi); + early_microcode_init(boot_info); if ( xen_phys_start ) { @@ -1906,7 +1904,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) timer_init(); - microcode_init_cache(module_map, mbi); /* Needs xmalloc() */ + microcode_init_cache(boot_info); /* Needs xmalloc() */ tsx_init(); /* Needs microcode. May change HLE/RTM feature bits. */ From patchwork Sat Jul 1 07:18:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christopher Clark X-Patchwork-Id: 13298971 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 D419AEB64DD for ; Sat, 1 Jul 2023 07:19:12 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.557778.871457 (Exim 4.92) (envelope-from ) id 1qFUso-00087N-JZ; Sat, 01 Jul 2023 07:19:02 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 557778.871457; Sat, 01 Jul 2023 07:19:02 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qFUso-00085r-A4; Sat, 01 Jul 2023 07:19:02 +0000 Received: by outflank-mailman (input) for mailman id 557778; Sat, 01 Jul 2023 07:19:00 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qFUsm-0006No-Mf for xen-devel@lists.xenproject.org; Sat, 01 Jul 2023 07:19:00 +0000 Received: from mail-oi1-x22c.google.com (mail-oi1-x22c.google.com [2607:f8b0:4864:20::22c]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 8b9c26ca-17df-11ee-8611-37d641c3527e; Sat, 01 Jul 2023 09:18:59 +0200 (CEST) Received: by mail-oi1-x22c.google.com with SMTP id 5614622812f47-3a3373211a1so1922940b6e.0 for ; Sat, 01 Jul 2023 00:18:58 -0700 (PDT) Received: from cog-dev.home ([70.103.208.83]) by smtp.gmail.com with ESMTPSA id s19-20020aa78d53000000b00673e652985bsm4108866pfe.118.2023.07.01.00.18.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Jul 2023 00:18:56 -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 X-Inumbo-ID: 8b9c26ca-17df-11ee-8611-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1688195937; x=1690787937; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=S6Cu78312/uyuTtWf3JY9jjpC+4RgagbuKLSP43QOoI=; b=UPbuVkZz1oAK/2LyG2d2Jw8INSlnXa/NlmFvB4kRqCC2gVqMidnQRphhgxR0TSHT+3 0s32mnwZ5C2MiyRI81PFiG2f3X7YsruBzmry+l2xRuxLJooDABjPUd+qXphVLrAW/B+y 6xxLai7iGBBcCRX9fk/IIKGyDalggyofNzF//yvHePzXSplMvL5ZaLhzY/JrPkWjxaqX D6SRMilMh4UjMDBVz35siAbBdhGqP/ThyZryTLkDquTjEDgVeLyQU2nu+7oabv4Fmg4k 02BmtpWmfzce0nwrfyeA5AltLslsexA90Qc7lLM01L0VCpHq2WUAfmBo/Jp4+3M2gjMV Vmjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688195937; x=1690787937; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=S6Cu78312/uyuTtWf3JY9jjpC+4RgagbuKLSP43QOoI=; b=RdSZPZBDpO2eSdqIUe7ETNoJ3aJ+B7n2f/NGW5SeC3KXHpcE/hC6pq6f92V+ZifejX ZiGjER0sfM9QcOuAZjlP0lGTGyGLh+uk3/VDk9o+KB4BL7qDl/mbpWVv+UYHkL23DSpv HWPtPmsDf9G9qKmj/CnrOiHUIG6qRBQ2zAEeI43J+DTj/T8J5x/zfGc76aYJYyHnxQpb WXqQB5D1Qn604Wf5+o+F0eo9xFaR4WfLtp0pPJvKLwdT5Hyzjfht7rFFjUaVWCTTILAH fRwYVSoOMIe3nbqfv4XgpSKkFP0O3gel7hpViWsq+IVfU4EVM1W+e8rRWMFIYupBJ4GY BODA== X-Gm-Message-State: AC+VfDw80XbqQGGoPB5ca8mtmc4/RHNjaWUeNCbB5xMoKJ/ADRIkMSb5 hJ8Gu2lhOLUkRVrrGiTiw4vtxwV2fqk= X-Google-Smtp-Source: ACHHUZ5bs2jo7O3BDp2NAaVYCHQcw/ounbIgX+But52KUkZXfA77A5ZAv/5/HHJcZPqmWMwDeEj4RQ== X-Received: by 2002:a05:6808:1917:b0:3a0:6949:c884 with SMTP id bf23-20020a056808191700b003a06949c884mr6924756oib.34.1688195937374; Sat, 01 Jul 2023 00:18:57 -0700 (PDT) Sender: Christopher Clark From: Christopher Clark To: xen-devel@lists.xenproject.org Cc: Daniel Smith , stefano.stabellini@amd.com, Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu , Bertrand Marquis , Luca Fancellu , Volodymyr Babchuk , Rich Persaud Subject: [PATCH 07/10] x86 boot: define paddr_t and add macros for typedefing struct pointers Date: Sat, 1 Jul 2023 00:18:32 -0700 Message-Id: <20230701071835.41599-8-christopher.w.clark@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230701071835.41599-1-christopher.w.clark@gmail.com> References: <20230701071835.41599-1-christopher.w.clark@gmail.com> MIME-Version: 1.0 Pointer fields within structs need to be defined as fixed size types in the x86 boot build environment. Using a typedef for the field type rather than a struct pointer type enables the type definition to be changed in the 32-bit boot build and the main hypervisor build, allowing for a single common structure definition and a common header file. Introduces DEFINE_STRUCT_PTR_TYPE and DEFINE_PTR_TYPE which will generate typedefs with a _ptr_t suffix for pointers to the specified type. This is then used in for pointers within structs as preparation for using these headers in the x86 boot build. The 32-bit behaviour is obtained by inclusion of "defs.h" first with a check for such an existing definition on the version. paddr_t is used in so a definition is added here to the x86 boot environment defs.h header. Signed-off-by: Christopher Clark Signed-off-by: Daniel P. Smith --- Changes since v2: This is two v2 patches merged into one for v3. Changes since v1: New in v2 of series. xen/arch/x86/boot/defs.h | 9 +++++++++ xen/arch/x86/include/asm/bootinfo.h | 4 +++- xen/include/xen/bootinfo.h | 9 +++++---- xen/include/xen/types.h | 11 +++++++++++ 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/xen/arch/x86/boot/defs.h b/xen/arch/x86/boot/defs.h index f9840044ec..bc0f1b5cf8 100644 --- a/xen/arch/x86/boot/defs.h +++ b/xen/arch/x86/boot/defs.h @@ -60,4 +60,13 @@ typedef u64 uint64_t; #define U16_MAX ((u16)(~0U)) #define UINT_MAX (~0U) +typedef unsigned long long paddr_t; + +#define DEFINE_STRUCT_PTR_TYPE(struct_name) \ + typedef uint64_t struct_name ## _ptr_t; + +#define DEFINE_PTR_TYPE(type) \ + typedef uint64_t type ## _ptr_t; +DEFINE_PTR_TYPE(char); + #endif /* __BOOT_DEFS_H__ */ diff --git a/xen/arch/x86/include/asm/bootinfo.h b/xen/arch/x86/include/asm/bootinfo.h index 30c27980e0..989fb7a1da 100644 --- a/xen/arch/x86/include/asm/bootinfo.h +++ b/xen/arch/x86/include/asm/bootinfo.h @@ -6,6 +6,7 @@ struct arch_bootmodule { uint32_t flags; unsigned headroom; }; +DEFINE_STRUCT_PTR_TYPE(arch_bootmodule); struct arch_boot_info { uint32_t flags; @@ -14,11 +15,12 @@ struct arch_boot_info { #define BOOTINFO_FLAG_X86_MEMMAP 1U << 6 #define BOOTINFO_FLAG_X86_LOADERNAME 1U << 9 - char *boot_loader_name; + char_ptr_t boot_loader_name; uint32_t mmap_length; paddr_t mmap_addr; }; +DEFINE_STRUCT_PTR_TYPE(arch_boot_info); struct __packed mb_memmap { uint32_t size; diff --git a/xen/include/xen/bootinfo.h b/xen/include/xen/bootinfo.h index 2f4284a91f..8389da4f72 100644 --- a/xen/include/xen/bootinfo.h +++ b/xen/include/xen/bootinfo.h @@ -35,17 +35,18 @@ struct boot_module { mfn_t mfn; size_t size; - struct arch_bootmodule *arch; + arch_bootmodule_ptr_t arch; struct boot_string string; }; +DEFINE_STRUCT_PTR_TYPE(boot_module); struct boot_info { - char *cmdline; + char_ptr_t cmdline; unsigned int nr_mods; - struct boot_module *mods; + boot_module_ptr_t mods; - struct arch_boot_info *arch; + arch_boot_info_ptr_t arch; }; #endif diff --git a/xen/include/xen/types.h b/xen/include/xen/types.h index 6aba80500a..e807ffe255 100644 --- a/xen/include/xen/types.h +++ b/xen/include/xen/types.h @@ -71,4 +71,15 @@ typedef bool bool_t; #define test_and_set_bool(b) xchg(&(b), true) #define test_and_clear_bool(b) xchg(&(b), false) +#ifndef DEFINE_STRUCT_PTR_TYPE +#define DEFINE_STRUCT_PTR_TYPE(struct_name) \ + typedef struct struct_name * struct_name ## _ptr_t; +#endif + +#ifndef DEFINE_PTR_TYPE +#define DEFINE_PTR_TYPE(type) \ + typedef type * type ## _ptr_t; +DEFINE_PTR_TYPE(char); +#endif + #endif /* __TYPES_H__ */ From patchwork Sat Jul 1 07:18:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christopher Clark X-Patchwork-Id: 13298972 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 C7606C001B0 for ; Sat, 1 Jul 2023 07:19:14 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.557780.871469 (Exim 4.92) (envelope-from ) id 1qFUsp-0008Pl-QP; Sat, 01 Jul 2023 07:19:03 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 557780.871469; Sat, 01 Jul 2023 07:19: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 1qFUsp-0008Mf-FC; Sat, 01 Jul 2023 07:19:03 +0000 Received: by outflank-mailman (input) for mailman id 557780; Sat, 01 Jul 2023 07:19:01 +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 1qFUsn-0006No-Mk for xen-devel@lists.xenproject.org; Sat, 01 Jul 2023 07:19:01 +0000 Received: from mail-qk1-x72d.google.com (mail-qk1-x72d.google.com [2607:f8b0:4864:20::72d]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 8c2d35ba-17df-11ee-8611-37d641c3527e; Sat, 01 Jul 2023 09:18:59 +0200 (CEST) Received: by mail-qk1-x72d.google.com with SMTP id af79cd13be357-765a1690003so243658785a.0 for ; Sat, 01 Jul 2023 00:18:59 -0700 (PDT) Received: from cog-dev.home ([70.103.208.83]) by smtp.gmail.com with ESMTPSA id s19-20020aa78d53000000b00673e652985bsm4108866pfe.118.2023.07.01.00.18.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Jul 2023 00:18:57 -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 X-Inumbo-ID: 8c2d35ba-17df-11ee-8611-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1688195938; x=1690787938; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=+QhG22aQsFtoXwrbtiP3WpdRgLLL1OgLfVThRSuYPKs=; b=Xufe3eFixvp3WBnPziVs80DQh009NwLwQM6EmrmrWavtVCOa8YgwA9pfjao+cAXVas Kyh7NFdj2mutOKU6e/K9NmVnVRMHMvvsxAHM2H7s/wdfwNUJqty255GlKJlQCu5vQg96 yMvmF4cr8adBv12o8hV8+Gb6TT1qKi+BOtZsVa9JgUGb91VptVwDYhxigH7Plvht5kFk hQ/2poKjMCSRtoxMxmmCSgVCA1NxfbetFR38XRkeTHBaPjoW/7sJORRNsEHFsi/D9xsE bZgAsWrgM4RD3RrSSUWizUz9rFrt4Au3FDfBgUA6zCTlgR7lva9PPIsa/Ji9tGStjP2z jB/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688195938; x=1690787938; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=+QhG22aQsFtoXwrbtiP3WpdRgLLL1OgLfVThRSuYPKs=; b=GSxg7PyvpWJqFMZpfXtx4qBks6uNAhGXozvuXZ2cZ1yfOOFu1QKtUHoMcvfqJJUt6r 4CORg7jPzuI8XbnNnt4uX3n46gBNqm+GtqQvIXgZVwrJsNJ1JFYldpCOVRmgvH9Tc1WL 7h7vRafMgsXrYxY1LH6GF66MDx+J7vgSADyiYd4qVscK+VT1G1degNTGXEt7nt557F2z Z+Qu3S8dGuQuv6lGiaRnHbKksNOSrHPtJEA71jo/tb35V9kWyeMslQw1uhMVHcku6ZOX Ij40XVFrHazidwcutEJgyvVDMa7gHCgt6yhU2kuY0JduptZXUEWy4guetiTBkd3mmmf3 3EYQ== X-Gm-Message-State: AC+VfDxSRZ4h6HhRklzePlI35OemwAa2XePstlp/6nqR88wmfhsIMGzZ LO3NDhPIfC0mEVC7O0ZkdojQ+PlZG2Q= X-Google-Smtp-Source: ACHHUZ6vQvz5edMFsBO0yDqxfBhGyFJGqYSD7CweucRlegb7fUq3Gfct1s2EEfK8Q/Zr5W+gSLpFLg== X-Received: by 2002:a05:620a:4010:b0:766:fa1f:4ea4 with SMTP id h16-20020a05620a401000b00766fa1f4ea4mr5546488qko.1.1688195938407; Sat, 01 Jul 2023 00:18:58 -0700 (PDT) Sender: Christopher Clark From: Christopher Clark To: xen-devel@lists.xenproject.org Cc: Daniel Smith , stefano.stabellini@amd.com, Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu , Bertrand Marquis , Luca Fancellu , Volodymyr Babchuk , Rich Persaud Subject: [PATCH 08/10] x86, arm, riscv: add per-arch bootinfo headers Date: Sat, 1 Jul 2023 00:18:33 -0700 Message-Id: <20230701071835.41599-9-christopher.w.clark@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230701071835.41599-1-christopher.w.clark@gmail.com> References: <20230701071835.41599-1-christopher.w.clark@gmail.com> MIME-Version: 1.0 Changes to ensure that inclusion of succeeds in each of the main archtecture builds and in the 32-bit early x86 boot build. The header contains structures that will be used in efi logic prior to the main start of Xen, so it needs to be suitable for inclusion in Arm source files. The same header will also be included in early x86 boot logic, where asm/* headers are not reachable, and so they cannot be transitively included, so a ifdef condition is needed to prevent an attempt to include from within in that case. The early x86 boot logic can then directly include via a specified directory path where it can be included successfully. Signed-off-by: Christopher Clark Signed-off-by: Daniel P. Smith --- New for v2 series. xen/arch/arm/include/asm/bootinfo.h | 20 ++++++++++++++++++++ xen/arch/riscv/include/asm/bootinfo.h | 20 ++++++++++++++++++++ xen/include/xen/bootinfo.h | 7 ++----- 3 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 xen/arch/arm/include/asm/bootinfo.h create mode 100644 xen/arch/riscv/include/asm/bootinfo.h diff --git a/xen/arch/arm/include/asm/bootinfo.h b/xen/arch/arm/include/asm/bootinfo.h new file mode 100644 index 0000000000..5316c87a3d --- /dev/null +++ b/xen/arch/arm/include/asm/bootinfo.h @@ -0,0 +1,20 @@ +#ifndef __ARCH_ARM_BOOTINFO_H__ +#define __ARCH_ARM_BOOTINFO_H__ + +struct __packed arch_bootmodule { }; +DEFINE_STRUCT_PTR_TYPE(arch_bootmodule); + +struct __packed arch_boot_info { }; +DEFINE_STRUCT_PTR_TYPE(arch_boot_info); + +#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/riscv/include/asm/bootinfo.h b/xen/arch/riscv/include/asm/bootinfo.h new file mode 100644 index 0000000000..5316c87a3d --- /dev/null +++ b/xen/arch/riscv/include/asm/bootinfo.h @@ -0,0 +1,20 @@ +#ifndef __ARCH_ARM_BOOTINFO_H__ +#define __ARCH_ARM_BOOTINFO_H__ + +struct __packed arch_bootmodule { }; +DEFINE_STRUCT_PTR_TYPE(arch_bootmodule); + +struct __packed arch_boot_info { }; +DEFINE_STRUCT_PTR_TYPE(arch_boot_info); + +#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/include/xen/bootinfo.h b/xen/include/xen/bootinfo.h index 8389da4f72..bf5586a76b 100644 --- a/xen/include/xen/bootinfo.h +++ b/xen/include/xen/bootinfo.h @@ -5,11 +5,8 @@ #include #include -#ifdef CONFIG_X86 -#include -#else - struct arch_bootmodule { }; - struct arch_boot_info { }; +#if defined CONFIG_X86 || CONFIG_ARM || CONFIG_RISCV +# include #endif /* Boot module binary type / purpose */ From patchwork Sat Jul 1 07:18:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christopher Clark X-Patchwork-Id: 13298975 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 D2DE4EB64DC for ; Sat, 1 Jul 2023 07:19:19 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.557779.871463 (Exim 4.92) (envelope-from ) id 1qFUsp-0008F6-6P; Sat, 01 Jul 2023 07:19:03 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 557779.871463; Sat, 01 Jul 2023 07:19: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 1qFUso-0008CO-Rw; Sat, 01 Jul 2023 07:19:02 +0000 Received: by outflank-mailman (input) for mailman id 557779; Sat, 01 Jul 2023 07:19:01 +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 1qFUsn-00074A-Me for xen-devel@lists.xenproject.org; Sat, 01 Jul 2023 07:19:01 +0000 Received: from mail-oi1-x22d.google.com (mail-oi1-x22d.google.com [2607:f8b0:4864:20::22d]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 8cedc5e3-17df-11ee-b237-6b7b168915f2; Sat, 01 Jul 2023 09:19:01 +0200 (CEST) Received: by mail-oi1-x22d.google.com with SMTP id 5614622812f47-3a37909a64eso1780698b6e.1 for ; Sat, 01 Jul 2023 00:19:01 -0700 (PDT) Received: from cog-dev.home ([70.103.208.83]) by smtp.gmail.com with ESMTPSA id s19-20020aa78d53000000b00673e652985bsm4108866pfe.118.2023.07.01.00.18.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Jul 2023 00:18:58 -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 X-Inumbo-ID: 8cedc5e3-17df-11ee-b237-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1688195939; x=1690787939; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=RNpBclJ1QG7nOEKI0nkpyN963wBmUeNZP6vxgwU4hxE=; b=kkt/3rzfOezqwdUdfeP22+AXirxs+V7vl98qrWv4iiVvJsilE8IFJzXmBmEaX/PLUX lw/OLqRFNRDap66MC+0gdgpB/Ap2zXzSIBFEE0S+1g7Z5yE5mqysVH6CJTGwGKVvXCEv pcetQV5sppLEG8Tn/5o/JgQm7GVCRfWToQacCEtPstUhrfKSmOFvUkrebntKu44THLG8 GKi4rtOS+2hjrykz+X62a0+lZXAHzKPErnP1WmR5Zqpb7YJXCLmeOTih25cPXCfWOUld 15dFSnZ0YQrnqdx+nDhNAzqzmzceDG1UJXNK8uM7Q1G+2GSsRsRJ0BnjJL3igJL1Bmyt JXZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688195939; x=1690787939; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=RNpBclJ1QG7nOEKI0nkpyN963wBmUeNZP6vxgwU4hxE=; b=Vcml0c+Zwcyn1Hi3mZSxVUMiBbYKgXnlUcBF9h/Xj4YKuu4icXyQ9ZYH1VkBgVfANS D/xWXb03YoHyxtjEOH5z/1ABssV/LoOjG2nv0OAu41FcNMJmaLpa7EpqkUMUEjb45M6l oRqAD0ykz0nLNTCsAA3myN0Xw3IaH048xolTpPEbM27loL/7MUHA8nSGh+aKhxpFm+PR 2p1ag9q3J3ztQ3A2fpqzracsVipprANFhT7g3YufW7/UeTMWUXo/+kY9ua6ZVvmlw1Sg uCAuBJBRIkFl67d1XU+larkq7Zl4Nj2jnTyBWjh1I7Q1OAYMvgz4tmiY41AY4THypHpx LdKA== X-Gm-Message-State: AC+VfDznT4f16VH4NUrHOLSDSuy1UOU+Isd5cxug6CT9p7hw7iqjKnW2 S/el3BxJ77RRlSDhXmy06bXi+jBQpg0= X-Google-Smtp-Source: ACHHUZ5bYgzOgosZ6acapmMuq/fA7HvOVTh6FdoBs81Xwt7bcxLG96FryDU7aohNQTBeWJXvKMyaTg== X-Received: by 2002:a05:6808:140d:b0:3a1:aef1:bbf3 with SMTP id w13-20020a056808140d00b003a1aef1bbf3mr5761717oiv.23.1688195939678; Sat, 01 Jul 2023 00:18:59 -0700 (PDT) Sender: Christopher Clark From: Christopher Clark To: xen-devel@lists.xenproject.org Cc: Daniel Smith , stefano.stabellini@amd.com, Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu , Bertrand Marquis , Luca Fancellu , Volodymyr Babchuk , Rich Persaud Subject: [PATCH 09/10] arm setup: use common integer-typed bootmod definition Date: Sat, 1 Jul 2023 00:18:34 -0700 Message-Id: <20230701071835.41599-10-christopher.w.clark@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230701071835.41599-1-christopher.w.clark@gmail.com> References: <20230701071835.41599-1-christopher.w.clark@gmail.com> MIME-Version: 1.0 This change enables inclusion of in Arm builds, required for subsequent patches in this series. It replaces the enum definition of bootmodule_kind with bootmod_type_t as enums are not fixed size as needed for packed structs which are needed for boot structures in subsequent changes. Signed-off-by: Christopher Clark Signed-off-by: Daniel P. Smith --- New for v2 series. xen/arch/arm/include/asm/setup.h | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/xen/arch/arm/include/asm/setup.h b/xen/arch/arm/include/asm/setup.h index 19dc637d55..7e0598217a 100644 --- a/xen/arch/arm/include/asm/setup.h +++ b/xen/arch/arm/include/asm/setup.h @@ -3,6 +3,7 @@ #include #include +#include #include #define MIN_FDT_ALIGN 8 @@ -12,15 +13,7 @@ #define MAX_MODULES 32 /* Current maximum useful modules */ -typedef enum { - BOOTMOD_XEN, - BOOTMOD_FDT, - BOOTMOD_KERNEL, - BOOTMOD_RAMDISK, - BOOTMOD_XSM, - BOOTMOD_GUEST_DTB, - BOOTMOD_UNKNOWN -} bootmodule_kind; +typedef bootmod_type_t bootmodule_kind; enum membank_type { /* From patchwork Sat Jul 1 07:18:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Christopher Clark X-Patchwork-Id: 13298978 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 11A18EB64DC for ; Sat, 1 Jul 2023 07:19:27 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.557782.871489 (Exim 4.92) (envelope-from ) id 1qFUss-0000iV-He; Sat, 01 Jul 2023 07:19:06 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 557782.871489; Sat, 01 Jul 2023 07:19:06 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qFUss-0000hD-BG; Sat, 01 Jul 2023 07:19:06 +0000 Received: by outflank-mailman (input) for mailman id 557782; Sat, 01 Jul 2023 07:19:05 +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 1qFUsr-0006No-4Y for xen-devel@lists.xenproject.org; Sat, 01 Jul 2023 07:19:05 +0000 Received: from mail-qk1-x736.google.com (mail-qk1-x736.google.com [2607:f8b0:4864:20::736]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 8dd6c1a5-17df-11ee-8611-37d641c3527e; Sat, 01 Jul 2023 09:19:02 +0200 (CEST) Received: by mail-qk1-x736.google.com with SMTP id af79cd13be357-76243a787a7so258385885a.2 for ; Sat, 01 Jul 2023 00:19:02 -0700 (PDT) Received: from cog-dev.home ([70.103.208.83]) by smtp.gmail.com with ESMTPSA id s19-20020aa78d53000000b00673e652985bsm4108866pfe.118.2023.07.01.00.18.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Jul 2023 00:19: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 X-Inumbo-ID: 8dd6c1a5-17df-11ee-8611-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1688195941; x=1690787941; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=kNW+AYrQKnLKNbbn3YFHqN8Eo0KMGaoZgm6SWc5V5+U=; b=qvF+gtJkoOs75NZJtm/YNXiKKQiLpYV8Y3dP7sx/ZVMfFQucgbJ4JPROG2R+wI/TQi a45pGXHMyaE0jPCw7+//2MUPsVP9KgAysnKEicYtp3WZovkZQQPlxCuA719HmyD74HO1 unyeo+6N4GSUUDY/sgkLbehx0YyLJ2o97ems715x8/oHTNjpivLHonYtCgMz+Q0f7+CG zAx4YUuqf3WfpkY1ZSzqlQWmphc6LSVZojpSYHpqBWmmCUsIMxlBuzfmJ2PJgkRqt/l5 7OJ6GJKmx+qSaaNCfsdhuOKIk2hhC33IzQkm6bAfGj9Zq+7GsSRBTlI48iWkpMGpNVIl +8iA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688195941; x=1690787941; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=kNW+AYrQKnLKNbbn3YFHqN8Eo0KMGaoZgm6SWc5V5+U=; b=LYMPLgOObjJDJQ9abW1bEqxVRVB0a0sJ6Q1OJ0TBjXzIU883r65zWgAxe0Dgj+9k+y ueKpRDY3oSJ3OlQFQKlp+Atnbfi/AJSLlRzFQemnaHpVsMvgaN/zJFJW1LMBC98caJ/3 pYcRNMlyZvolvTgHNXiVYAF6ZRggXbYC14lVOjQAkvD0J6ErTL7sMpiifq6LjwTfEI1H I7iLX/NG45aQpBSWKrV6NHxN14xom1ak/gyiYkCEqgsQCtcrF5NJvWqqWgNDqvRVAlor B8EGL/guAC5wEBgFpL7Jm0leR/pMXN8U6Es4q2ZHQcPwyg53ZUk7ixVE9zexQSMvRWqI Z3Cg== X-Gm-Message-State: AC+VfDw2h2rGKn68hsyPwWJY/EFLhzLRW1JQG+DcT7/BTS9HV6QKtL6g o94eiNEnQ+G9eAawjSpO7/uHLaFY3w0= X-Google-Smtp-Source: APBJJlFJOLvrQlTlbqeQdDwnW6s8Hbn/JAaopGLjUO8Ra0690Bt6OVuKd2cSZp766Vnno7X0T+4SJQ== X-Received: by 2002:a05:620a:2807:b0:767:382d:a203 with SMTP id f7-20020a05620a280700b00767382da203mr4959710qkp.36.1688195940769; Sat, 01 Jul 2023 00:19:00 -0700 (PDT) Sender: Christopher Clark From: Christopher Clark To: xen-devel@lists.xenproject.org Cc: Daniel Smith , stefano.stabellini@amd.com, Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu , Bertrand Marquis , Luca Fancellu , Volodymyr Babchuk , Rich Persaud Subject: [PATCH 10/10] x86 setup: refactor efi, pvh and multiboot entrypoints to new boot info Date: Sat, 1 Jul 2023 00:18:35 -0700 Message-Id: <20230701071835.41599-11-christopher.w.clark@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230701071835.41599-1-christopher.w.clark@gmail.com> References: <20230701071835.41599-1-christopher.w.clark@gmail.com> MIME-Version: 1.0 Previous commits added a transition point from multiboot v1 structures to the new boot info structures at the earliest common point for all the x86 entrypoints. The result is that each of the entrypoints would construct a multiboot v1 structure from the structures used by each entrypoint.  This meant that multiboot2, EFI, and PVH all converted their structures over to mutliboot v1 to only be converted again upon entering __start_xen(). This commit drops the translation function and moves the population of the new boot info structures down into the various entrypoints. This change increases the maximum number of boot modules accepted on the EFI entry path and the PVH entry path to the same fixed maximum number accepted via multiboot, making it common across all x86 entry points. Signed-off-by: Christopher Clark Signed-off-by: Daniel P. Smith --- Changes since v1: patch is based on v1 series patch 4. - use main bootinfo headers in boot logic instead of adding a 32-bit version - apply packing to boot structures here rather than in earlier changes - use a defined maximum number of boot modules rather than Kconfig'd variable xen/arch/arm/efi/efi-boot.h | 6 + xen/arch/x86/boot/defs.h | 1 + xen/arch/x86/boot/reloc.c | 192 +++++++++++++++------- xen/arch/x86/efi/efi-boot.h | 95 ++++++----- xen/arch/x86/guest/xen/pvh-boot.c | 64 +++++--- xen/arch/x86/include/asm/bootinfo.h | 7 +- xen/arch/x86/include/asm/guest/pvh-boot.h | 6 +- xen/arch/x86/setup.c | 73 +++----- xen/common/efi/boot.c | 4 +- xen/include/xen/bootinfo.h | 9 +- 10 files changed, 278 insertions(+), 179 deletions(-) diff --git a/xen/arch/arm/efi/efi-boot.h b/xen/arch/arm/efi/efi-boot.h index bb64925d70..d931fe06ed 100644 --- a/xen/arch/arm/efi/efi-boot.h +++ b/xen/arch/arm/efi/efi-boot.h @@ -1003,6 +1003,12 @@ static void __init efi_arch_flush_dcache_area(const void *vaddr, UINTN size) __flush_dcache_area(vaddr, size); } +static struct boot_info __init *efi_arch_bootinfo_init(void) +{ + /* boot modules not currently in use on Arm so no init required here */ + return NULL; +} + /* * Local variables: * mode: C diff --git a/xen/arch/x86/boot/defs.h b/xen/arch/x86/boot/defs.h index bc0f1b5cf8..519ca4dae6 100644 --- a/xen/arch/x86/boot/defs.h +++ b/xen/arch/x86/boot/defs.h @@ -44,6 +44,7 @@ _x > _y ? _x : _y; }) #define _p(val) ((void *)(unsigned long)(val)) +#define _addr(val) ((unsigned long)(void *)(val)) #define tolower(c) ((c) | 0x20) diff --git a/xen/arch/x86/boot/reloc.c b/xen/arch/x86/boot/reloc.c index e22bb974bf..8a48572d5f 100644 --- a/xen/arch/x86/boot/reloc.c +++ b/xen/arch/x86/boot/reloc.c @@ -27,6 +27,8 @@ asm ( ); #include "defs.h" +#include "../include/asm/bootinfo.h" +#include "../../../include/xen/bootinfo.h" #include "../../../include/xen/multiboot.h" #include "../../../include/xen/multiboot2.h" @@ -138,65 +140,116 @@ static struct hvm_start_info *pvh_info_reloc(u32 in) return out; } -static multiboot_info_t *mbi_reloc(u32 mbi_in) +static struct boot_info *mbi_reloc(u32 mbi_in) { + const multiboot_info_t *mbi = _p(mbi_in); + struct boot_info *binfo; + struct arch_boot_info *arch_binfo; int i; - multiboot_info_t *mbi_out; + uint32_t ptr; - mbi_out = _p(copy_mem(mbi_in, sizeof(*mbi_out))); + ptr = alloc_mem(sizeof(*binfo)); + zero_mem(ptr, sizeof(*binfo)); + binfo = _p(ptr); - if ( mbi_out->flags & MBI_CMDLINE ) - mbi_out->cmdline = copy_string(mbi_out->cmdline); + ptr = alloc_mem(sizeof(*arch_binfo)); + zero_mem(ptr, sizeof(*arch_binfo)); + binfo->arch = ptr; + arch_binfo = _p(ptr); - if ( mbi_out->flags & MBI_MODULES ) + if ( mbi->flags & MBI_CMDLINE ) + { + ptr = copy_string(mbi->cmdline); + binfo->cmdline = ptr; + arch_binfo->flags |= BOOTINFO_FLAG_X86_CMDLINE; + } + + if ( mbi->flags & MBI_MODULES ) { module_t *mods; + struct boot_module *bi_mods; + struct arch_bootmodule *arch_bi_mods; + + /* + * We have to allocate one more module slot here. At some point + * __start_xen() may put Xen image placement into it. + */ + ptr = alloc_mem((mbi->mods_count + 1) * sizeof(*bi_mods)); + binfo->nr_mods = mbi->mods_count; + binfo->mods = ptr; + bi_mods = _p(ptr); - mbi_out->mods_addr = copy_mem(mbi_out->mods_addr, - mbi_out->mods_count * sizeof(module_t)); + ptr = alloc_mem((mbi->mods_count + 1) * sizeof(*arch_bi_mods)); + arch_bi_mods = _p(ptr); - mods = _p(mbi_out->mods_addr); + /* map the +1 allocated for Xen image */ + bi_mods[mbi->mods_count].arch = _addr(&arch_bi_mods[mbi->mods_count]); - for ( i = 0; i < mbi_out->mods_count; i++ ) + arch_binfo->flags |= BOOTINFO_FLAG_X86_MODULES; + + mods = _p(mbi->mods_addr); + + for ( i = 0; i < mbi->mods_count; i++ ) { + bi_mods[i].start = mods[i].mod_start; + bi_mods[i].size = mods[i].mod_end - mods[i].mod_start; + if ( mods[i].string ) - mods[i].string = copy_string(mods[i].string); + { + int j; + char *c = _p(mods[i].string); + + for ( j = 0; *c != '\0'; j++, c++ ) + bi_mods[i].string.bytes[j] = *c; + + bi_mods[i].string.len = j + 1; + } + + bi_mods[i].arch = _addr(&arch_bi_mods[i]); } } - if ( mbi_out->flags & MBI_MEMMAP ) - mbi_out->mmap_addr = copy_mem(mbi_out->mmap_addr, mbi_out->mmap_length); - - if ( mbi_out->flags & MBI_LOADERNAME ) - mbi_out->boot_loader_name = copy_string(mbi_out->boot_loader_name); + if ( mbi->flags & MBI_MEMMAP ) + { + arch_binfo->mmap_addr = copy_mem(mbi->mmap_addr, mbi->mmap_length); + arch_binfo->mmap_length = mbi->mmap_length; + arch_binfo->flags |= BOOTINFO_FLAG_X86_MEMMAP; + } - /* Mask features we don't understand or don't relocate. */ - mbi_out->flags &= (MBI_MEMLIMITS | - MBI_CMDLINE | - MBI_MODULES | - MBI_MEMMAP | - MBI_LOADERNAME); + if ( mbi->flags & MBI_LOADERNAME ) + { + ptr = copy_string(mbi->boot_loader_name); + arch_binfo->boot_loader_name = ptr; + arch_binfo->flags |= BOOTINFO_FLAG_X86_LOADERNAME; + } - return mbi_out; + return binfo; } -static multiboot_info_t *mbi2_reloc(uint32_t mbi_in, uint32_t video_out) +static struct boot_info *mbi2_reloc(uint32_t mbi_in, uint32_t video_out) { const multiboot2_fixed_t *mbi_fix = _p(mbi_in); const multiboot2_memory_map_t *mmap_src; const multiboot2_tag_t *tag; - module_t *mbi_out_mods = NULL; memory_map_t *mmap_dst; - multiboot_info_t *mbi_out; + struct boot_info *binfo; + struct arch_boot_info *arch_binfo; + struct boot_module *bi_mods; + struct arch_bootmodule *arch_bi_mods; #ifdef CONFIG_VIDEO struct boot_video_info *video = NULL; #endif u32 ptr; unsigned int i, mod_idx = 0; - ptr = alloc_mem(sizeof(*mbi_out)); - mbi_out = _p(ptr); - zero_mem(ptr, sizeof(*mbi_out)); + ptr = alloc_mem(sizeof(*binfo)); + zero_mem(ptr, sizeof(*binfo)); + binfo = _p(ptr); + + ptr = alloc_mem(sizeof(*arch_binfo)); + zero_mem(ptr, sizeof(*arch_binfo)); + binfo->arch = ptr; + arch_binfo = _p(ptr); /* Skip Multiboot2 information fixed part. */ ptr = ALIGN_UP(mbi_in + sizeof(*mbi_fix), MULTIBOOT2_TAG_ALIGN); @@ -206,21 +259,28 @@ static multiboot_info_t *mbi2_reloc(uint32_t mbi_in, uint32_t video_out) tag = _p(ALIGN_UP((u32)tag + tag->size, MULTIBOOT2_TAG_ALIGN)) ) { if ( tag->type == MULTIBOOT2_TAG_TYPE_MODULE ) - ++mbi_out->mods_count; + ++binfo->nr_mods; else if ( tag->type == MULTIBOOT2_TAG_TYPE_END ) break; } - if ( mbi_out->mods_count ) + if ( binfo->nr_mods ) { - mbi_out->flags |= MBI_MODULES; /* * We have to allocate one more module slot here. At some point * __start_xen() may put Xen image placement into it. */ - mbi_out->mods_addr = alloc_mem((mbi_out->mods_count + 1) * - sizeof(*mbi_out_mods)); - mbi_out_mods = _p(mbi_out->mods_addr); + ptr = alloc_mem((binfo->nr_mods + 1) * sizeof(*bi_mods)); + binfo->mods = ptr; + bi_mods = _p(ptr); + + ptr = alloc_mem((binfo->nr_mods + 1) * sizeof(*arch_bi_mods)); + arch_bi_mods = _p(ptr); + + /* map the +1 allocated for Xen image */ + bi_mods[binfo->nr_mods].arch = _addr(&arch_bi_mods[binfo->nr_mods]); + + arch_binfo->flags |= BOOTINFO_FLAG_X86_MODULES; } /* Skip Multiboot2 information fixed part. */ @@ -232,39 +292,42 @@ static multiboot_info_t *mbi2_reloc(uint32_t mbi_in, uint32_t video_out) switch ( tag->type ) { case MULTIBOOT2_TAG_TYPE_BOOT_LOADER_NAME: - mbi_out->flags |= MBI_LOADERNAME; ptr = get_mb2_string(tag, string, string); - mbi_out->boot_loader_name = copy_string(ptr); + arch_binfo->boot_loader_name = copy_string(ptr); + arch_binfo->flags |= BOOTINFO_FLAG_X86_LOADERNAME; break; case MULTIBOOT2_TAG_TYPE_CMDLINE: - mbi_out->flags |= MBI_CMDLINE; ptr = get_mb2_string(tag, string, string); - mbi_out->cmdline = copy_string(ptr); + binfo->cmdline = copy_string(ptr); + arch_binfo->flags |= BOOTINFO_FLAG_X86_CMDLINE; break; case MULTIBOOT2_TAG_TYPE_BASIC_MEMINFO: - mbi_out->flags |= MBI_MEMLIMITS; - mbi_out->mem_lower = get_mb2_data(tag, basic_meminfo, mem_lower); - mbi_out->mem_upper = get_mb2_data(tag, basic_meminfo, mem_upper); + arch_binfo->mem_lower = get_mb2_data(tag, basic_meminfo, + mem_lower); + arch_binfo->mem_upper = get_mb2_data(tag, basic_meminfo, + mem_upper); break; case MULTIBOOT2_TAG_TYPE_MMAP: if ( get_mb2_data(tag, mmap, entry_size) < sizeof(*mmap_src) ) break; - mbi_out->flags |= MBI_MEMMAP; - mbi_out->mmap_length = get_mb2_data(tag, mmap, size); - mbi_out->mmap_length -= sizeof(multiboot2_tag_mmap_t); - mbi_out->mmap_length /= get_mb2_data(tag, mmap, entry_size); - mbi_out->mmap_length *= sizeof(*mmap_dst); + arch_binfo->mmap_length = get_mb2_data(tag, mmap, size); + arch_binfo->mmap_length -= sizeof(multiboot2_tag_mmap_t); + arch_binfo->mmap_length /= get_mb2_data(tag, mmap, entry_size); + arch_binfo->mmap_length *= sizeof(*mmap_dst); - mbi_out->mmap_addr = alloc_mem(mbi_out->mmap_length); + arch_binfo->mmap_addr = alloc_mem(arch_binfo->mmap_length); + arch_binfo->flags |= BOOTINFO_FLAG_X86_MEMMAP; mmap_src = get_mb2_data(tag, mmap, entries); - mmap_dst = _p(mbi_out->mmap_addr); + mmap_dst = _p(arch_binfo->mmap_addr); - for ( i = 0; i < mbi_out->mmap_length / sizeof(*mmap_dst); i++ ) + for ( i = 0; + i < arch_binfo->mmap_length / sizeof(*mmap_dst); + i++ ) { /* Init size member properly. */ mmap_dst[i].size = sizeof(*mmap_dst); @@ -280,14 +343,27 @@ static multiboot_info_t *mbi2_reloc(uint32_t mbi_in, uint32_t video_out) break; case MULTIBOOT2_TAG_TYPE_MODULE: - if ( mod_idx >= mbi_out->mods_count ) + if ( mod_idx >= binfo->nr_mods ) break; - mbi_out_mods[mod_idx].mod_start = get_mb2_data(tag, module, mod_start); - mbi_out_mods[mod_idx].mod_end = get_mb2_data(tag, module, mod_end); + bi_mods[mod_idx].start = get_mb2_data(tag, module, mod_start); + bi_mods[mod_idx].size = get_mb2_data(tag, module, mod_end) + - bi_mods[mod_idx].start; + ptr = get_mb2_string(tag, module, cmdline); - mbi_out_mods[mod_idx].string = copy_string(ptr); - mbi_out_mods[mod_idx].reserved = 0; + if ( ptr ) + { + int i; + char *c = _p(ptr); + + for ( i = 0; *c != '\0'; i++, c++ ) + bi_mods[mod_idx].string.bytes[i] = *c; + + bi_mods[mod_idx].string.len = i + 1; + } + + bi_mods[mod_idx].arch = _addr(&arch_bi_mods[mod_idx]); + ++mod_idx; break; @@ -344,11 +420,11 @@ static multiboot_info_t *mbi2_reloc(uint32_t mbi_in, uint32_t video_out) video->orig_video_isVGA = 0x23; #endif - return mbi_out; + return binfo; } -void *__stdcall reloc(uint32_t magic, uint32_t in, uint32_t trampoline, - uint32_t video_info) +void *__stdcall reloc( + uint32_t magic, uint32_t in, uint32_t trampoline, uint32_t video_info) { alloc = trampoline; diff --git a/xen/arch/x86/efi/efi-boot.h b/xen/arch/x86/efi/efi-boot.h index 64c1a02cf1..c05759b761 100644 --- a/xen/arch/x86/efi/efi-boot.h +++ b/xen/arch/x86/efi/efi-boot.h @@ -11,14 +11,17 @@ #include static struct file __initdata ucode; -static multiboot_info_t __initdata mbi = { - .flags = MBI_MODULES | MBI_LOADERNAME -}; + +static struct boot_info __initdata efi_bi; +static struct arch_boot_info __initdata efi_bi_arch; /* * The array size needs to be one larger than the number of modules we * support - see __start_xen(). */ -static module_t __initdata mb_modules[5]; +static struct boot_module __initdata efi_mods[MAX_NR_BOOTMODS + 1]; +static struct arch_bootmodule __initdata efi_arch_mods[MAX_NR_BOOTMODS + 1]; + +static const char *__initdata efi_loader = "PVH Directboot"; static void __init edd_put_string(u8 *dst, size_t n, const char *src) { @@ -271,20 +274,37 @@ static void __init noreturn efi_arch_post_exit_boot(void) : [cr3] "r" (idle_pg_table), [cs] "i" (__HYPERVISOR_CS), [ds] "r" (__HYPERVISOR_DS), - "D" (&mbi) + "D" (&efi_bi) : "memory" ); unreachable(); } -static void __init efi_arch_cfg_file_early(const EFI_LOADED_IMAGE *image, - EFI_FILE_HANDLE dir_handle, - const char *section) +static struct boot_info __init *efi_arch_bootinfo_init(void) { + int i; + + efi_bi.arch = &efi_bi_arch; + efi_bi.mods = efi_mods; + + for ( i=0; i <= MAX_NR_BOOTMODS; i++ ) + efi_bi.mods[i].arch = &efi_arch_mods[i]; + + efi_bi_arch.boot_loader_name = _p(efi_loader); + + efi_bi_arch.flags = BOOTINFO_FLAG_X86_MODULES | + BOOTINFO_FLAG_X86_LOADERNAME; + return &efi_bi; } -static void __init efi_arch_cfg_file_late(const EFI_LOADED_IMAGE *image, - EFI_FILE_HANDLE dir_handle, - const char *section) +static void __init efi_arch_cfg_file_early( + const EFI_LOADED_IMAGE *image, EFI_FILE_HANDLE dir_handle, + const char *section) +{ +} + +static void __init efi_arch_cfg_file_late( + const EFI_LOADED_IMAGE *image, EFI_FILE_HANDLE dir_handle, + const char *section) { union string name; @@ -296,16 +316,15 @@ static void __init efi_arch_cfg_file_late(const EFI_LOADED_IMAGE *image, name.s = get_value(&cfg, "global", "ucode"); if ( name.s ) { - microcode_set_module(mbi.mods_count); + microcode_set_module(efi_bi.nr_mods); split_string(name.s); read_file(dir_handle, s2w(&name), &ucode, NULL); efi_bs->FreePool(name.w); } } -static void __init efi_arch_handle_cmdline(CHAR16 *image_name, - CHAR16 *cmdline_options, - const char *cfgfile_options) +static void __init efi_arch_handle_cmdline( + CHAR16 *image_name, CHAR16 *cmdline_options, const char *cfgfile_options) { union string name; @@ -313,10 +332,10 @@ static void __init efi_arch_handle_cmdline(CHAR16 *image_name, { name.w = cmdline_options; w2s(&name); - place_string(&mbi.cmdline, name.s); + place_string((uint32_t *)efi_bi.cmdline, name.s); } if ( cfgfile_options ) - place_string(&mbi.cmdline, cfgfile_options); + place_string((uint32_t *)efi_bi.cmdline, cfgfile_options); /* Insert image name last, as it gets prefixed to the other options. */ if ( image_name ) { @@ -325,16 +344,10 @@ static void __init efi_arch_handle_cmdline(CHAR16 *image_name, } else name.s = "xen"; - place_string(&mbi.cmdline, name.s); + place_string((uint32_t *)efi_bi.cmdline, name.s); - if ( mbi.cmdline ) - mbi.flags |= MBI_CMDLINE; - /* - * These must not be initialized statically, since the value must - * not get relocated when processing base relocations later. - */ - mbi.boot_loader_name = (long)"EFI"; - mbi.mods_addr = (long)mb_modules; + if ( efi_bi.cmdline ) + efi_bi_arch.flags |= BOOTINFO_FLAG_X86_CMDLINE; } static void __init efi_arch_edd(void) @@ -704,9 +717,8 @@ static void __init efi_arch_memory_setup(void) #undef l2_4G_offset } -static void __init efi_arch_handle_module(const struct file *file, - const CHAR16 *name, - const char *options) +static void __init efi_arch_handle_module( + const struct file *file, const CHAR16 *name, const char *options) { union string local_name; void *ptr; @@ -724,17 +736,24 @@ static void __init efi_arch_handle_module(const struct file *file, w2s(&local_name); /* - * If options are provided, put them in - * mb_modules[mbi.mods_count].string after the filename, with a space - * separating them. place_string() prepends strings and adds separating - * spaces, so the call order is reversed. + * Set module string to filename and if options are provided, put them in + * after the filename, with a space separating them. */ + strlcpy(efi_bi.mods[efi_bi.nr_mods].string.bytes, local_name.s, + BOOTMOD_STRING_MAX_LEN); if ( options ) - place_string(&mb_modules[mbi.mods_count].string, options); - place_string(&mb_modules[mbi.mods_count].string, local_name.s); - mb_modules[mbi.mods_count].mod_start = file->addr >> PAGE_SHIFT; - mb_modules[mbi.mods_count].mod_end = file->size; - ++mbi.mods_count; + { + strlcat(efi_bi.mods[efi_bi.nr_mods].string.bytes, " ", + BOOTMOD_STRING_MAX_LEN); + strlcat(efi_bi.mods[efi_bi.nr_mods].string.bytes, options, + BOOTMOD_STRING_MAX_LEN); + } + + efi_bi.mods[efi_bi.nr_mods].start = file->addr; + efi_bi.mods[efi_bi.nr_mods].mfn = maddr_to_mfn(file->addr); + efi_bi.mods[efi_bi.nr_mods].size = file->size; + + ++efi_bi.nr_mods; efi_bs->FreePool(ptr); } diff --git a/xen/arch/x86/guest/xen/pvh-boot.c b/xen/arch/x86/guest/xen/pvh-boot.c index 1ed04d035c..dd10a358da 100644 --- a/xen/arch/x86/guest/xen/pvh-boot.c +++ b/xen/arch/x86/guest/xen/pvh-boot.c @@ -6,6 +6,7 @@ * * Copyright (c) 2017 Citrix Systems Ltd. */ +#include #include #include #include @@ -20,12 +21,28 @@ bool __initdata pvh_boot; uint32_t __initdata pvh_start_info_pa; -static multiboot_info_t __initdata pvh_mbi; -static module_t __initdata pvh_mbi_mods[8]; -static const char *__initdata pvh_loader = "PVH Directboot"; +static struct boot_info __initdata pvh_bi; +static struct arch_boot_info __initdata arch_pvh_bi; +static struct boot_module __initdata pvh_mods[MAX_NR_BOOTMODS + 1]; +static struct arch_bootmodule __initdata arch_pvh_mods[MAX_NR_BOOTMODS + 1]; +static char __initdata *pvh_loader = "PVH Directboot"; -static void __init convert_pvh_info(multiboot_info_t **mbi, - module_t **mod) +static struct boot_info __init *init_pvh_info(void) +{ + int i; + + pvh_bi.arch = &arch_pvh_bi; + pvh_bi.mods = pvh_mods; + + for ( i=0; i <= MAX_NR_BOOTMODS; i++ ) + pvh_bi.mods[i].arch = &arch_pvh_mods[i]; + + pvh_bi.arch->boot_loader_name = pvh_loader; + + return &pvh_bi; +} + +static void __init convert_pvh_info(struct boot_info *bi) { const struct hvm_start_info *pvh_info = __va(pvh_start_info_pa); const struct hvm_modlist_entry *entry; @@ -39,23 +56,22 @@ static void __init convert_pvh_info(multiboot_info_t **mbi, * required. The extra element is used to aid relocation. See * arch/x86/setup.c:__start_xen(). */ - if ( ARRAY_SIZE(pvh_mbi_mods) <= pvh_info->nr_modules ) + if ( ARRAY_SIZE(pvh_mods) <= pvh_info->nr_modules ) panic("The module array is too small, size %zu, requested %u\n", - ARRAY_SIZE(pvh_mbi_mods), pvh_info->nr_modules); + ARRAY_SIZE(pvh_mods), pvh_info->nr_modules); /* * Turn hvm_start_info into mbi. Luckily all modules are placed under 4GB * boundary on x86. */ - pvh_mbi.flags = MBI_CMDLINE | MBI_MODULES | MBI_LOADERNAME; + bi->arch->flags = BOOTINFO_FLAG_X86_CMDLINE | BOOTINFO_FLAG_X86_MODULES + | BOOTINFO_FLAG_X86_LOADERNAME; BUG_ON(pvh_info->cmdline_paddr >> 32); - pvh_mbi.cmdline = pvh_info->cmdline_paddr; - pvh_mbi.boot_loader_name = __pa(pvh_loader); + bi->cmdline = _p(__va(pvh_info->cmdline_paddr)); - BUG_ON(pvh_info->nr_modules >= ARRAY_SIZE(pvh_mbi_mods)); - pvh_mbi.mods_count = pvh_info->nr_modules; - pvh_mbi.mods_addr = __pa(pvh_mbi_mods); + BUG_ON(pvh_info->nr_modules >= ARRAY_SIZE(pvh_mods)); + bi->nr_mods = pvh_info->nr_modules; entry = __va(pvh_info->modlist_paddr); for ( i = 0; i < pvh_info->nr_modules; i++ ) @@ -63,15 +79,18 @@ static void __init convert_pvh_info(multiboot_info_t **mbi, BUG_ON(entry[i].paddr >> 32); BUG_ON(entry[i].cmdline_paddr >> 32); - pvh_mbi_mods[i].mod_start = entry[i].paddr; - pvh_mbi_mods[i].mod_end = entry[i].paddr + entry[i].size; - pvh_mbi_mods[i].string = entry[i].cmdline_paddr; + bi->mods[i].start = entry[i].paddr; + bi->mods[i].size = entry[i].size; + if ( entry[i].cmdline_paddr) + { + char *c = _p(__va(entry[i].cmdline_paddr)); + + safe_strcpy(bi->mods[i].string.bytes, c); + bi->mods[i].string.kind = BOOTSTR_CMDLINE; + } } rsdp_hint = pvh_info->rsdp_paddr; - - *mbi = &pvh_mbi; - *mod = pvh_mbi_mods; } static void __init get_memory_map(void) @@ -88,13 +107,16 @@ static void __init get_memory_map(void) sanitize_e820_map(e820_raw.map, &e820_raw.nr_map); } -void __init pvh_init(multiboot_info_t **mbi, module_t **mod) +void __init pvh_init(struct boot_info **bi) { - convert_pvh_info(mbi, mod); + *bi = init_pvh_info(); + convert_pvh_info(*bi); hypervisor_probe(); ASSERT(xen_guest); + (*bi)->arch->xen_guest = xen_guest; + get_memory_map(); } diff --git a/xen/arch/x86/include/asm/bootinfo.h b/xen/arch/x86/include/asm/bootinfo.h index 989fb7a1da..c1ed76fd3e 100644 --- a/xen/arch/x86/include/asm/bootinfo.h +++ b/xen/arch/x86/include/asm/bootinfo.h @@ -1,14 +1,14 @@ #ifndef __ARCH_X86_BOOTINFO_H__ #define __ARCH_X86_BOOTINFO_H__ -struct arch_bootmodule { +struct __packed arch_bootmodule { #define BOOTMOD_FLAG_X86_RELOCATED 1U << 0 uint32_t flags; unsigned headroom; }; DEFINE_STRUCT_PTR_TYPE(arch_bootmodule); -struct arch_boot_info { +struct __packed arch_boot_info { uint32_t flags; #define BOOTINFO_FLAG_X86_CMDLINE 1U << 2 #define BOOTINFO_FLAG_X86_MODULES 1U << 3 @@ -17,6 +17,9 @@ struct arch_boot_info { char_ptr_t boot_loader_name; + uint32_t mem_lower; + uint32_t mem_upper; + uint32_t mmap_length; paddr_t mmap_addr; }; diff --git a/xen/arch/x86/include/asm/guest/pvh-boot.h b/xen/arch/x86/include/asm/guest/pvh-boot.h index 247ba6899e..c820b0bf88 100644 --- a/xen/arch/x86/include/asm/guest/pvh-boot.h +++ b/xen/arch/x86/include/asm/guest/pvh-boot.h @@ -8,13 +8,13 @@ #ifndef __X86_PVH_BOOT_H__ #define __X86_PVH_BOOT_H__ -#include +#include #ifdef CONFIG_PVH_GUEST extern bool pvh_boot; -void pvh_init(multiboot_info_t **mbi, module_t **mod); +void __init pvh_init(struct boot_info **bi); void pvh_print_info(void); #else @@ -23,7 +23,7 @@ void pvh_print_info(void); #define pvh_boot 0 -static inline void pvh_init(multiboot_info_t **mbi, module_t **mod) +static inline void __init pvh_init(struct boot_info **bi) { ASSERT_UNREACHABLE(); } diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 50a1a124b0..05a76a5959 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -13,7 +13,6 @@ #include #include #include -#include #include #include #include @@ -60,9 +59,6 @@ #include #include -/* Max number of boot modules a bootloader can provide in addition to Xen */ -#define MAX_NR_BOOTMODS 63 - /* opt_nosmp: If true, secondary processors are ignored. */ static bool __initdata opt_nosmp; boolean_param("nosmp", opt_nosmp); @@ -275,46 +271,6 @@ custom_param("acpi", parse_acpi_param); static struct boot_info __initdata *boot_info; -static void __init multiboot_to_bootinfo(multiboot_info_t *mbi, module_t *mods) -{ - static struct boot_info __initdata info; - static struct arch_boot_info __initdata arch_info; - static struct boot_module __initdata boot_mods[MAX_NR_BOOTMODS + 1]; - static struct arch_bootmodule __initdata arch_boot_mods[ - MAX_NR_BOOTMODS + 1]; - - int i; - - info.arch = &arch_info; - info.mods = boot_mods; - - info.cmdline = __va(mbi->cmdline); - - /* The BOOTINFO_FLAG_X86_* flags are a 1-1 map to MBI_* */ - arch_info.flags = mbi->flags; - arch_info.mmap_length = mbi->mmap_length; - arch_info.mmap_addr = mbi->mmap_addr; - arch_info.boot_loader_name = __va(mbi->boot_loader_name); - - info.nr_mods = mbi->mods_count; - for ( i = 0; i <= MAX_NR_BOOTMODS; i++ ) - { - boot_mods[i].arch = &arch_boot_mods[i]; - - if ( i < info.nr_mods ) - { - bootmodule_update_start(&boot_mods[i], mods[i].mod_start); - boot_mods[i].size = mods[i].mod_end - mods[i].mod_start; - - boot_mods[i].string.len = strlcpy(boot_mods[i].string.bytes, - __va(mods[i].string), - BOOTMOD_STRING_MAX_LEN); - } - } - - boot_info = &info; -} - unsigned long __init initial_images_nrpages(nodeid_t node) { unsigned long node_start = node_start_pfn(node); @@ -1014,15 +970,13 @@ static struct domain *__init create_dom0(const struct boot_info *bootinfo, /* How much of the directmap is prebuilt at compile time. */ #define PREBUILT_MAP_LIMIT (1 << L2_PAGETABLE_SHIFT) -void __init noreturn __start_xen(unsigned long mbi_p) +void __init noreturn __start_xen(unsigned long bi_p) { char *memmap_type = NULL; char *cmdline, *kextra, *loader; void *bsp_stack; struct cpu_info *info = get_cpu_info(), *bsp_info; unsigned int initrdidx, num_parked = 0; - multiboot_info_t *mbi; - module_t *mod; unsigned long nr_pages, raw_max_page; int i, j, e820_warn = 0, bytes = 0; unsigned long eb_start, eb_end; @@ -1059,16 +1013,29 @@ void __init noreturn __start_xen(unsigned long mbi_p) if ( pvh_boot ) { - ASSERT(mbi_p == 0); - pvh_init(&mbi, &mod); + ASSERT(bi_p == 0); + pvh_init(&boot_info); } else { - mbi = __va(mbi_p); - mod = __va(mbi->mods_addr); - } + /* + * Since addresses were setup before virtual addressing was enabled, + * fixup pointers to virtual addresses for proper dereferencing. + */ + boot_info = __va(bi_p); + boot_info->cmdline = __va(boot_info->cmdline); + boot_info->mods = __va(boot_info->mods); + boot_info->arch = __va(boot_info->arch); + + boot_info->arch->boot_loader_name = + __va(boot_info->arch->boot_loader_name); - multiboot_to_bootinfo(mbi, mod); + for ( i = 0; i <= boot_info->nr_mods; i++ ) + { + boot_info->mods[i].mfn = maddr_to_mfn(boot_info->mods[i].start); + boot_info->mods[i].arch = __va(boot_info->mods[i].arch); + } + } loader = (boot_info->arch->flags & BOOTINFO_FLAG_X86_LOADERNAME) ? boot_info->arch->boot_loader_name : "unknown"; diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c index c5850c26af..09b38b497c 100644 --- a/xen/common/efi/boot.c +++ b/xen/common/efi/boot.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -11,7 +12,6 @@ #include #include #include -#include #include #include #include @@ -1359,6 +1359,8 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) efi_arch_relocate_image(0); + efi_arch_bootinfo_init(); + if ( use_cfg_file ) { EFI_FILE_HANDLE dir_handle; diff --git a/xen/include/xen/bootinfo.h b/xen/include/xen/bootinfo.h index bf5586a76b..6e09be6899 100644 --- a/xen/include/xen/bootinfo.h +++ b/xen/include/xen/bootinfo.h @@ -20,13 +20,16 @@ #define BOOTMOD_GUEST_DTB 7 typedef unsigned int bootmod_type_t; +/* Max number of boot modules a bootloader can provide in addition to Xen */ +#define MAX_NR_BOOTMODS 63 + #define BOOTMOD_STRING_MAX_LEN 1024 -struct boot_string { +struct __packed boot_string { char bytes[BOOTMOD_STRING_MAX_LEN]; size_t len; }; -struct boot_module { +struct __packed boot_module { bootmod_type_t bootmod_type; paddr_t start; mfn_t mfn; @@ -37,7 +40,7 @@ struct boot_module { }; DEFINE_STRUCT_PTR_TYPE(boot_module); -struct boot_info { +struct __packed boot_info { char_ptr_t cmdline; unsigned int nr_mods;