Skip to content

Commit b9e62a2

Browse files
committed
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
2 parents ac814cb + 5214a9f commit b9e62a2

File tree

6 files changed

+41
-32
lines changed

6 files changed

+41
-32
lines changed

arch/x86/include/asm/microcode.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ struct ucode_cpu_info {
1717
void load_ucode_bsp(void);
1818
void load_ucode_ap(void);
1919
void microcode_bsp_resume(void);
20+
bool __init microcode_loader_disabled(void);
2021
#else
2122
static inline void load_ucode_bsp(void) { }
2223
static inline void load_ucode_ap(void) { }
2324
static inline void microcode_bsp_resume(void) { }
25+
static inline bool __init microcode_loader_disabled(void) { return false; }
2426
#endif
2527

2628
extern unsigned long initrd_start_early;

arch/x86/kernel/cpu/microcode/amd.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,15 +1098,17 @@ static enum ucode_state load_microcode_amd(u8 family, const u8 *data, size_t siz
10981098

10991099
static int __init save_microcode_in_initrd(void)
11001100
{
1101-
unsigned int cpuid_1_eax = native_cpuid_eax(1);
11021101
struct cpuinfo_x86 *c = &boot_cpu_data;
11031102
struct cont_desc desc = { 0 };
1103+
unsigned int cpuid_1_eax;
11041104
enum ucode_state ret;
11051105
struct cpio_data cp;
11061106

1107-
if (dis_ucode_ldr || c->x86_vendor != X86_VENDOR_AMD || c->x86 < 0x10)
1107+
if (microcode_loader_disabled() || c->x86_vendor != X86_VENDOR_AMD || c->x86 < 0x10)
11081108
return 0;
11091109

1110+
cpuid_1_eax = native_cpuid_eax(1);
1111+
11101112
if (!find_blobs_in_containers(&cp))
11111113
return -EINVAL;
11121114

arch/x86/kernel/cpu/microcode/core.c

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141

4242
#include "internal.h"
4343

44-
static struct microcode_ops *microcode_ops;
45-
bool dis_ucode_ldr = true;
44+
static struct microcode_ops *microcode_ops;
45+
static bool dis_ucode_ldr = false;
4646

4747
bool force_minrev = IS_ENABLED(CONFIG_MICROCODE_LATE_FORCE_MINREV);
4848
module_param(force_minrev, bool, S_IRUSR | S_IWUSR);
@@ -84,6 +84,9 @@ static bool amd_check_current_patch_level(void)
8484
u32 lvl, dummy, i;
8585
u32 *levels;
8686

87+
if (x86_cpuid_vendor() != X86_VENDOR_AMD)
88+
return false;
89+
8790
native_rdmsr(MSR_AMD64_PATCH_LEVEL, lvl, dummy);
8891

8992
levels = final_levels;
@@ -95,27 +98,29 @@ static bool amd_check_current_patch_level(void)
9598
return false;
9699
}
97100

98-
static bool __init check_loader_disabled_bsp(void)
101+
bool __init microcode_loader_disabled(void)
99102
{
100-
static const char *__dis_opt_str = "dis_ucode_ldr";
101-
const char *cmdline = boot_command_line;
102-
const char *option = __dis_opt_str;
103+
if (dis_ucode_ldr)
104+
return true;
103105

104106
/*
105-
* CPUID(1).ECX[31]: reserved for hypervisor use. This is still not
106-
* completely accurate as xen pv guests don't see that CPUID bit set but
107-
* that's good enough as they don't land on the BSP path anyway.
107+
* Disable when:
108+
*
109+
* 1) The CPU does not support CPUID.
110+
*
111+
* 2) Bit 31 in CPUID[1]:ECX is clear
112+
* The bit is reserved for hypervisor use. This is still not
113+
* completely accurate as XEN PV guests don't see that CPUID bit
114+
* set, but that's good enough as they don't land on the BSP
115+
* path anyway.
116+
*
117+
* 3) Certain AMD patch levels are not allowed to be
118+
* overwritten.
108119
*/
109-
if (native_cpuid_ecx(1) & BIT(31))
110-
return true;
111-
112-
if (x86_cpuid_vendor() == X86_VENDOR_AMD) {
113-
if (amd_check_current_patch_level())
114-
return true;
115-
}
116-
117-
if (cmdline_find_option_bool(cmdline, option) <= 0)
118-
dis_ucode_ldr = false;
120+
if (!have_cpuid_p() ||
121+
native_cpuid_ecx(1) & BIT(31) ||
122+
amd_check_current_patch_level())
123+
dis_ucode_ldr = true;
119124

120125
return dis_ucode_ldr;
121126
}
@@ -125,7 +130,10 @@ void __init load_ucode_bsp(void)
125130
unsigned int cpuid_1_eax;
126131
bool intel = true;
127132

128-
if (!have_cpuid_p())
133+
if (cmdline_find_option_bool(boot_command_line, "dis_ucode_ldr") > 0)
134+
dis_ucode_ldr = true;
135+
136+
if (microcode_loader_disabled())
129137
return;
130138

131139
cpuid_1_eax = native_cpuid_eax(1);
@@ -146,9 +154,6 @@ void __init load_ucode_bsp(void)
146154
return;
147155
}
148156

149-
if (check_loader_disabled_bsp())
150-
return;
151-
152157
if (intel)
153158
load_ucode_intel_bsp(&early_data);
154159
else
@@ -159,6 +164,11 @@ void load_ucode_ap(void)
159164
{
160165
unsigned int cpuid_1_eax;
161166

167+
/*
168+
* Can't use microcode_loader_disabled() here - .init section
169+
* hell. It doesn't have to either - the BSP variant must've
170+
* parsed cmdline already anyway.
171+
*/
162172
if (dis_ucode_ldr)
163173
return;
164174

@@ -810,7 +820,7 @@ static int __init microcode_init(void)
810820
struct cpuinfo_x86 *c = &boot_cpu_data;
811821
int error;
812822

813-
if (dis_ucode_ldr)
823+
if (microcode_loader_disabled())
814824
return -EINVAL;
815825

816826
if (c->x86_vendor == X86_VENDOR_INTEL)

arch/x86/kernel/cpu/microcode/intel.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ static int __init save_builtin_microcode(void)
389389
if (xchg(&ucode_patch_va, NULL) != UCODE_BSP_LOADED)
390390
return 0;
391391

392-
if (dis_ucode_ldr || boot_cpu_data.x86_vendor != X86_VENDOR_INTEL)
392+
if (microcode_loader_disabled() || boot_cpu_data.x86_vendor != X86_VENDOR_INTEL)
393393
return 0;
394394

395395
uci.mc = get_microcode_blob(&uci, true);

arch/x86/kernel/cpu/microcode/internal.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ static inline unsigned int x86_cpuid_family(void)
9494
return x86_family(eax);
9595
}
9696

97-
extern bool dis_ucode_ldr;
9897
extern bool force_minrev;
9998

10099
#ifdef CONFIG_CPU_SUP_AMD

arch/x86/kernel/head32.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,6 @@ void __init __no_stack_protector mk_early_pgtbl_32(void)
145145
*ptr = (unsigned long)ptep + PAGE_OFFSET;
146146

147147
#ifdef CONFIG_MICROCODE_INITRD32
148-
/* Running on a hypervisor? */
149-
if (native_cpuid_ecx(1) & BIT(31))
150-
return;
151-
152148
params = (struct boot_params *)__pa_nodebug(&boot_params);
153149
if (!params->hdr.ramdisk_size || !params->hdr.ramdisk_image)
154150
return;

0 commit comments

Comments
 (0)