From nobody Sun Feb 8 05:19:48 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1688171547; cv=none; d=zohomail.com; s=zohoarc; b=TKCAGYEq4yGfkSnUwRMT7TMfJj1pd02qpN47wfAqIlOZk2NLYdaGQQMyp+d/e8NhnTm/gTSbt1Lh2UvQCHAoCTKIV+FZ3C56otYaH8bxltdsIa7wqpYUFSKpayS394g85Pe0KjiIv5Vq6nO+Vfsc8CTxqr5eGzXxQ8w4awmbz0w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1688171547; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=tNP8VdblK4Rt8e2FoRKT44HjkzeP53PPJ4jpSpNQaUw=; b=WT75EX+Mm69BMx6gV8+Ly1DyqliTvkm77T7gktBnz7hlfJpa0A9O00ZUDNdPgwiIIx2dI2ZT3U709qoDh8Uzzlmzi42v9YV0jCAE9RwuTROgItICXatnPxjtREhC6BU5bH45rg27Ccb7y2cmmkthagaYXol+llK4HL1avI145eo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1688171547356758.0363219371051; Fri, 30 Jun 2023 17:32:27 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.557672.871272 (Exim 4.92) (envelope-from ) id 1qFOWn-000193-Nt; Sat, 01 Jul 2023 00:31:53 +0000 Received: by outflank-mailman (output) from mailman id 557672.871272; Sat, 01 Jul 2023 00:31:53 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qFOWn-00017y-Gt; Sat, 01 Jul 2023 00:31:53 +0000 Received: by outflank-mailman (input) for mailman id 557672; Sat, 01 Jul 2023 00:31:51 +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 1qFOWl-0007yM-CS for xen-devel@lists.xenproject.org; Sat, 01 Jul 2023 00:31:51 +0000 Received: from mail-qk1-x731.google.com (mail-qk1-x731.google.com [2607:f8b0:4864:20::731]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id aa5d7fcc-17a6-11ee-8611-37d641c3527e; Sat, 01 Jul 2023 02:31:49 +0200 (CEST) Received: by mail-qk1-x731.google.com with SMTP id af79cd13be357-76728ae3162so224236785a.3 for ; Fri, 30 Jun 2023 17:31:49 -0700 (PDT) Received: from cog-dev.home ([70.103.208.83]) by smtp.gmail.com with ESMTPSA id s68-20020a632c47000000b0055b61cd99a1sm1824296pgs.81.2023.06.30.17.31.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jun 2023 17:31:46 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list X-Inumbo-ID: aa5d7fcc-17a6-11ee-8611-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1688171507; x=1690763507; 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=tNP8VdblK4Rt8e2FoRKT44HjkzeP53PPJ4jpSpNQaUw=; b=dZsj6vciSfnMLCMaU0cMPpVzsvTf2cA6H5rK4dqitVEHa7PIl9bqnNbVX3YCmArVSD IMEXc7JXp9i0n/PGdZX9qMeKuVaEdqi1JfQcIbGoD4A3Tg/fYHZ5qWS5LnG8xrnN8FH1 Qri/PoGiBRsUxe8lInpy/Y3tNDsK+N/06FDCG77bszgiEqbDDNt1ISOCF7hrbk0zEJZF u3xEDplqMMf5QyYIZXM+igxM68XL6fyrQU/HlA+q/V8iig/rjo8PHvxFVZnmdcg9lZsV 5KpUfri4831gj2h32ooplKW5XrDdfAHBoQV/NLL9yEaAH4ZJQQM+UxajHNgk+edO/lhN CM9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688171507; x=1690763507; 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=tNP8VdblK4Rt8e2FoRKT44HjkzeP53PPJ4jpSpNQaUw=; b=OzBtmcktinPgWc4XhtkaIz/SXeaJ6nzCQuxZxTc2JMoAV2ZcCRLdjcX+gt+dJcGZKY A6IzBRT5MOmL5RBHqkdqyRD4PR4clvF+tD583EyrF+YdyOfAUuylU1Cg3BQEIi4g1SjI OvuG/96KKedmGW08c1W8twytVnn3Z4IZpNGIGldqXFu1T6hQHnrUL8gQZDRU6aAH+w1h uDrAevlVcDerI55VGHvTwEQ640xI9B1QjbD8QQoEVSJ/XhKgBFcr4RHmGZRggjQyyNA4 Y9f0KegaY0Pgq1kn560TCPt0rE2xrEWFotxKeIJf2QUS4dpbS74EmzR33hdzSKUHaHUP RpKg== X-Gm-Message-State: ABy/qLawIMHRzXLb3UaViZv69lx9jqBV9Ddkd89tCgnFNahEBlioCNmd uhRiyZjbQweGuNo9EAqK8cFOjEtlfxw= X-Google-Smtp-Source: APBJJlHXadhO0zI3fny7/VsDSq54jA5+/G/AaPurjt0vF6Vo+E7TEPOAcjmOGo6hXLaSNWVGV0iNyg== X-Received: by 2002:a05:620a:29d2:b0:767:3999:5277 with SMTP id s18-20020a05620a29d200b0076739995277mr5531547qkp.70.1688171507611; Fri, 30 Jun 2023 17:31:47 -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/11] x86 setup, microcode: switch to the new bootinfo structures Date: Fri, 30 Jun 2023 17:31:27 -0700 Message-Id: <20230701003132.2210306-7-christopher.w.clark@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230701003132.2210306-1-christopher.w.clark@gmail.com> References: <20230701003132.2210306-1-christopher.w.clark@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1688171548973100009 Content-Type: text/plain; charset="utf-8" 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 foun= d. 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 changes since v1: - an incremental subset of patch 3 - added the drop of the temporary bootstrap map --- 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 e720a89167..c674ccf88c 100644 --- a/xen/arch/x86/cpu/microcode/core.c +++ b/xen/arch/x86/cpu/microcode/core.c @@ -22,12 +22,12 @@ */ =20 #include +#include #include #include #include #include #include -#include #include #include #include @@ -57,7 +57,6 @@ */ #define MICROCODE_UPDATE_TIMEOUT_US 1000000 =20 -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); =20 -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 =3D (module_t *)__va(mbi->mods_addr); uint64_t *_blob_start; unsigned long _blob_size; - struct cpio_data cd; + struct cpio_data cd =3D { NULL, 0 }; long offset; const char *p =3D NULL; - int i; - - ucode_blob.size =3D 0; - if ( !ucode_scan ) - return; =20 if ( boot_cpu_data.x86_vendor =3D=3D X86_VENDOR_AMD ) p =3D "kernel/x86/microcode/AuthenticAMD.bin"; else if ( boot_cpu_data.x86_vendor =3D=3D X86_VENDOR_INTEL ) p =3D "kernel/x86/microcode/GenuineIntel.bin"; else + return -EFAULT; + + _blob_start =3D bootstrap_map(mod); + _blob_size =3D 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 =3D find_cpio_data(p, _blob_start, _blob_size, &offset /* ignore */= ); + + if ( cd.data ) + { + ucode_blob.size =3D cd.size; + ucode_blob.data =3D cd.data; + + mod->bootmod_type =3D 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; =20 - /* - * Try all modules and see whichever could be the microcode blob. - */ - for ( i =3D 1 /* Ignore dom0 kernel */; i < mbi->mods_count; i++ ) + i =3D bootmodule_index(bootinfo, BOOTMOD_UNKNOWN, 0); + while ( i < bootinfo->nr_mods ) { - if ( !test_bit(i, module_map) ) - continue; + int ret =3D microcode_check_module(&bootinfo->mods[i]); =20 - _blob_start =3D bootstrap_map_multiboot(&mod[i]); - _blob_size =3D 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 =3D bootmodule_index(bootinfo, BOOTMOD_UNKNOWN, ++i); continue; + default: + printk("%s: (err: %d) unable to check microcode\n", + __func__, ret); + return; } - cd.data =3D NULL; - cd.size =3D 0; - cd =3D find_cpio_data(p, _blob_start, _blob_size, &offset /* ignor= e */); - if ( cd.data ) - { - ucode_blob.size =3D cd.size; - ucode_blob.data =3D cd.data; - break; - } - bootstrap_map(NULL); } } =20 -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 =3D (module_t *)__va(mbi->mods_addr); + ucode_blob.size =3D 0; =20 if ( ucode_mod_idx < 0 ) - ucode_mod_idx +=3D mbi->mods_count; - if ( ucode_mod_idx <=3D 0 || ucode_mod_idx >=3D mbi->mods_count || - !__test_and_clear_bit(ucode_mod_idx, module_map) ) - goto scan; - ucode_mod =3D mod[ucode_mod_idx]; -scan: + ucode_mod_idx +=3D bootinfo->nr_mods; + if ( ucode_mod_idx >=3D 0 && ucode_mod_idx <=3D bootinfo->nr_mods && + bootinfo->mods[ucode_mod_idx].bootmod_type =3D=3D BOOTMOD_UNKNOWN= ) + { + int ret =3D 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); } =20 +/* Undefining as they are not needed anymore */ +#undef MICROCODE_MODULE_MATCH +#undef MICROCODE_MODULE_NONMATCH + static struct microcode_ops __ro_after_init ucode_ops; =20 static DEFINE_SPINLOCK(microcode_mutex); @@ -737,11 +770,6 @@ static int __init cf_check microcode_init(void) ucode_blob.size =3D 0; ucode_blob.data =3D NULL; } - else if ( ucode_mod.mod_end ) - { - bootstrap_map(NULL); - ucode_mod.mod_end =3D 0; - } =20 return 0; } @@ -785,19 +813,15 @@ static int __init early_update_cache(const void *data= , size_t len) return rc; } =20 -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 =3D 0; =20 if ( ucode_scan ) /* Need to rescan the modules because they might have been relocat= ed */ - microcode_scan_module(module_map, mbi); + microcode_scan_module(bootinfo); =20 - if ( ucode_mod.mod_end ) - rc =3D early_update_cache(bootstrap_map_multiboot(&ucode_mod), - ucode_mod.mod_end); - else if ( ucode_blob.size ) + if ( ucode_blob.size ) rc =3D early_update_cache(ucode_blob.data, ucode_blob.size); =20 return rc; @@ -815,11 +839,6 @@ static int __init early_microcode_update_cpu(void) len =3D ucode_blob.size; data =3D ucode_blob.data; } - else if ( ucode_mod.mod_end ) - { - len =3D ucode_mod.mod_end; - data =3D bootstrap_map_multiboot(&ucode_mod); - } =20 if ( !data ) return -ENOMEM; @@ -838,8 +857,7 @@ static int __init early_microcode_update_cpu(void) return microcode_update_cpu(patch); } =20 -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 =3D &boot_cpu_data; int rc =3D 0; @@ -863,11 +881,11 @@ int __init early_microcode_init(unsigned long *module= _map, return -ENODEV; } =20 - microcode_grab_module(module_map, mbi); + microcode_grab_module(bootinfo); =20 ucode_ops.collect_cpu_info(); =20 - if ( ucode_mod.mod_end || ucode_blob.size ) + if ( ucode_blob.size ) rc =3D early_microcode_update_cpu(); =20 return rc; diff --git a/xen/arch/x86/include/asm/boot.h b/xen/arch/x86/include/asm/boo= t.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 @@ =20 #include =20 -static inline void *bootstrap_map_multiboot(const module_t *mod) -{ - struct boot_module bm; - - if ( !mod ) - return bootstrap_map(NULL); - - bm.start =3D mod->mod_start << PAGE_SHIFT; - bm.size =3D 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/as= m/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 =20 +#include #include #include =20 @@ -23,10 +24,8 @@ DECLARE_PER_CPU(struct cpu_signature, cpu_sig); =20 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); =20 #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 =3D 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 =3D 0, bytes =3D 0; unsigned long eb_start, eb_end; bool acpi_boot_table_init_done =3D false, relocated =3D false; @@ -1190,8 +1190,6 @@ void __init noreturn __start_xen(unsigned long mbi_p) } =20 /* 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 =3D BOOTMOD_KERNEL; =20 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); =20 if ( xen_phys_start ) { @@ -1906,7 +1904,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) =20 timer_init(); =20 - microcode_init_cache(module_map, mbi); /* Needs xmalloc() */ + microcode_init_cache(boot_info); /* Needs xmalloc() */ =20 tsx_init(); /* Needs microcode. May change HLE/RTM feature bits. */ =20 --=20 2.25.1