Fix a boot regression on very old x86 CPUs without CPUID support.

Signed-off-by: Ingo Molnar <mingo@kernel.org>
 -----BEGIN PGP SIGNATURE-----
 
 iQJFBAABCgAvFiEEBpT5eoXrXCwVQwEKEnMQ0APhK1gFAmggVx8RHG1pbmdvQGtl
 cm5lbC5vcmcACgkQEnMQ0APhK1gCsg/+LsBbk+wJyQpVADyYKyuYRx12mVY6Pb2F
 Oee+/ivaFeE92Su30nIfzDPyXe3PYCNFW9D26/y8wfgRNhMic5AWW2I2PRy/iV1V
 EjyTdP6ign8HUzHfrlZNPJOsextTYqU7uDhwRocgrPBKlgmK8Z9WUfgK+TnhvvMo
 fotb6HF96rfGIOww/kqCbGItKCzZ4app8tnzTWlj07qoYkCgrq+J57Jaj2cvYJYI
 vhmIsbaG/qrt+3Q9MYiA5HIkxxv6mvpd/MS18dhlaON070TCmhlQxgN0wD6JAfR9
 5lkeqhMq50cK5/cr15KAbzAPuqyK0d8DY+6cmEXmNMe0GwOeyoVZPM+Ul3f3l/ku
 93M1qd0r1oIJ0ltzFh1Pfw8c8EDMmHz0opiqJ40efaJYUPUsi3jrwmn3hI5GNXdE
 gISlPow9EY8MQe4dH4E20zHOTApEOvgJzhgkrR5jzh8JlEdbmFEezfF6fwf5tKfC
 m1HNeX0SkjumtUkvka7v++hgpD28UVBA0dau+nhfoRXtUBuithPapLvoacVhum/j
 9QxlGMP6VqBmg3GP6AmiccuTcWNsfFBbIUIJ+KT2GI5E3wvPxb9Q9qJTr+mKtoJ9
 n6krAi++WUqfInkd4tx0uEk+x8W2mk4gOS/xV/qV8So4R8cyioO1XLHn/r+kwx6a
 wLbdafPaJzY=
 =ibsn
 -----END PGP SIGNATURE-----

Merge tag 'x86-urgent-2025-05-11' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip

Pull x86 fix from Ingo Molnar:
 "Fix a boot regression on very old x86 CPUs without CPUID support"

* tag 'x86-urgent-2025-05-11' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
  x86/microcode: Consolidate the loader enablement checking
This commit is contained in:
Linus Torvalds 2025-05-11 11:08:55 -07:00
commit b9e62a2b8f
6 changed files with 42 additions and 33 deletions

View File

@ -17,10 +17,12 @@ struct ucode_cpu_info {
void load_ucode_bsp(void); void load_ucode_bsp(void);
void load_ucode_ap(void); void load_ucode_ap(void);
void microcode_bsp_resume(void); void microcode_bsp_resume(void);
bool __init microcode_loader_disabled(void);
#else #else
static inline void load_ucode_bsp(void) { } static inline void load_ucode_bsp(void) { }
static inline void load_ucode_ap(void) { } static inline void load_ucode_ap(void) { }
static inline void microcode_bsp_resume(void) { } static inline void microcode_bsp_resume(void) { }
static inline bool __init microcode_loader_disabled(void) { return false; }
#endif #endif
extern unsigned long initrd_start_early; extern unsigned long initrd_start_early;

View File

@ -1098,15 +1098,17 @@ static enum ucode_state load_microcode_amd(u8 family, const u8 *data, size_t siz
static int __init save_microcode_in_initrd(void) static int __init save_microcode_in_initrd(void)
{ {
unsigned int cpuid_1_eax = native_cpuid_eax(1);
struct cpuinfo_x86 *c = &boot_cpu_data; struct cpuinfo_x86 *c = &boot_cpu_data;
struct cont_desc desc = { 0 }; struct cont_desc desc = { 0 };
unsigned int cpuid_1_eax;
enum ucode_state ret; enum ucode_state ret;
struct cpio_data cp; struct cpio_data cp;
if (dis_ucode_ldr || c->x86_vendor != X86_VENDOR_AMD || c->x86 < 0x10) if (microcode_loader_disabled() || c->x86_vendor != X86_VENDOR_AMD || c->x86 < 0x10)
return 0; return 0;
cpuid_1_eax = native_cpuid_eax(1);
if (!find_blobs_in_containers(&cp)) if (!find_blobs_in_containers(&cp))
return -EINVAL; return -EINVAL;

View File

@ -42,7 +42,7 @@
#include "internal.h" #include "internal.h"
static struct microcode_ops *microcode_ops; static struct microcode_ops *microcode_ops;
bool dis_ucode_ldr = true; static bool dis_ucode_ldr = false;
bool force_minrev = IS_ENABLED(CONFIG_MICROCODE_LATE_FORCE_MINREV); bool force_minrev = IS_ENABLED(CONFIG_MICROCODE_LATE_FORCE_MINREV);
module_param(force_minrev, bool, S_IRUSR | S_IWUSR); module_param(force_minrev, bool, S_IRUSR | S_IWUSR);
@ -84,6 +84,9 @@ static bool amd_check_current_patch_level(void)
u32 lvl, dummy, i; u32 lvl, dummy, i;
u32 *levels; u32 *levels;
if (x86_cpuid_vendor() != X86_VENDOR_AMD)
return false;
native_rdmsr(MSR_AMD64_PATCH_LEVEL, lvl, dummy); native_rdmsr(MSR_AMD64_PATCH_LEVEL, lvl, dummy);
levels = final_levels; levels = final_levels;
@ -95,27 +98,29 @@ static bool amd_check_current_patch_level(void)
return false; return false;
} }
static bool __init check_loader_disabled_bsp(void) bool __init microcode_loader_disabled(void)
{ {
static const char *__dis_opt_str = "dis_ucode_ldr"; if (dis_ucode_ldr)
const char *cmdline = boot_command_line; return true;
const char *option = __dis_opt_str;
/* /*
* CPUID(1).ECX[31]: reserved for hypervisor use. This is still not * Disable when:
* completely accurate as xen pv guests don't see that CPUID bit set but *
* that's good enough as they don't land on the BSP path anyway. * 1) The CPU does not support CPUID.
*
* 2) Bit 31 in CPUID[1]:ECX is clear
* The bit is reserved for hypervisor use. This is still not
* completely accurate as XEN PV guests don't see that CPUID bit
* set, but that's good enough as they don't land on the BSP
* path anyway.
*
* 3) Certain AMD patch levels are not allowed to be
* overwritten.
*/ */
if (native_cpuid_ecx(1) & BIT(31)) if (!have_cpuid_p() ||
return true; native_cpuid_ecx(1) & BIT(31) ||
amd_check_current_patch_level())
if (x86_cpuid_vendor() == X86_VENDOR_AMD) { dis_ucode_ldr = true;
if (amd_check_current_patch_level())
return true;
}
if (cmdline_find_option_bool(cmdline, option) <= 0)
dis_ucode_ldr = false;
return dis_ucode_ldr; return dis_ucode_ldr;
} }
@ -125,7 +130,10 @@ void __init load_ucode_bsp(void)
unsigned int cpuid_1_eax; unsigned int cpuid_1_eax;
bool intel = true; bool intel = true;
if (!have_cpuid_p()) if (cmdline_find_option_bool(boot_command_line, "dis_ucode_ldr") > 0)
dis_ucode_ldr = true;
if (microcode_loader_disabled())
return; return;
cpuid_1_eax = native_cpuid_eax(1); cpuid_1_eax = native_cpuid_eax(1);
@ -146,9 +154,6 @@ void __init load_ucode_bsp(void)
return; return;
} }
if (check_loader_disabled_bsp())
return;
if (intel) if (intel)
load_ucode_intel_bsp(&early_data); load_ucode_intel_bsp(&early_data);
else else
@ -159,6 +164,11 @@ void load_ucode_ap(void)
{ {
unsigned int cpuid_1_eax; unsigned int cpuid_1_eax;
/*
* Can't use microcode_loader_disabled() here - .init section
* hell. It doesn't have to either - the BSP variant must've
* parsed cmdline already anyway.
*/
if (dis_ucode_ldr) if (dis_ucode_ldr)
return; return;
@ -810,7 +820,7 @@ static int __init microcode_init(void)
struct cpuinfo_x86 *c = &boot_cpu_data; struct cpuinfo_x86 *c = &boot_cpu_data;
int error; int error;
if (dis_ucode_ldr) if (microcode_loader_disabled())
return -EINVAL; return -EINVAL;
if (c->x86_vendor == X86_VENDOR_INTEL) if (c->x86_vendor == X86_VENDOR_INTEL)

View File

@ -389,7 +389,7 @@ static int __init save_builtin_microcode(void)
if (xchg(&ucode_patch_va, NULL) != UCODE_BSP_LOADED) if (xchg(&ucode_patch_va, NULL) != UCODE_BSP_LOADED)
return 0; return 0;
if (dis_ucode_ldr || boot_cpu_data.x86_vendor != X86_VENDOR_INTEL) if (microcode_loader_disabled() || boot_cpu_data.x86_vendor != X86_VENDOR_INTEL)
return 0; return 0;
uci.mc = get_microcode_blob(&uci, true); uci.mc = get_microcode_blob(&uci, true);

View File

@ -94,7 +94,6 @@ static inline unsigned int x86_cpuid_family(void)
return x86_family(eax); return x86_family(eax);
} }
extern bool dis_ucode_ldr;
extern bool force_minrev; extern bool force_minrev;
#ifdef CONFIG_CPU_SUP_AMD #ifdef CONFIG_CPU_SUP_AMD

View File

@ -145,10 +145,6 @@ void __init __no_stack_protector mk_early_pgtbl_32(void)
*ptr = (unsigned long)ptep + PAGE_OFFSET; *ptr = (unsigned long)ptep + PAGE_OFFSET;
#ifdef CONFIG_MICROCODE_INITRD32 #ifdef CONFIG_MICROCODE_INITRD32
/* Running on a hypervisor? */
if (native_cpuid_ecx(1) & BIT(31))
return;
params = (struct boot_params *)__pa_nodebug(&boot_params); params = (struct boot_params *)__pa_nodebug(&boot_params);
if (!params->hdr.ramdisk_size || !params->hdr.ramdisk_image) if (!params->hdr.ramdisk_size || !params->hdr.ramdisk_image)
return; return;