Skip to content

Commit ac44a11

Browse files
committed
x86/microcode/AMD: Allow loader debugging to be enabled on baremetal too
Debugging the loader on baremetal does make sense, so enable it there too. Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Link: https://patch.msgid.link/20260108165028.27417-1-bp@kernel.org
1 parent 9ace475 commit ac44a11

4 files changed

Lines changed: 20 additions & 9 deletions

File tree

arch/x86/Kconfig

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,10 +1366,12 @@ config MICROCODE_DBG
13661366
default n
13671367
depends on MICROCODE
13681368
help
1369-
Enable code which allows for debugging the microcode loader in
1370-
a guest. Meaning the patch loading is simulated but everything else
1369+
Enable code which allows to debug the microcode loader. When running
1370+
in a guest the patch loading is simulated but everything else
13711371
related to patch parsing and handling is done as on baremetal with
1372-
the purpose of debugging solely the software side of things.
1372+
the purpose of debugging solely the software side of things. On
1373+
baremetal, it simply dumps additional debugging information during
1374+
normal operation.
13731375

13741376
You almost certainly want to say n here.
13751377

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ static u32 get_patch_level(void)
322322
{
323323
u32 rev, dummy __always_unused;
324324

325-
if (IS_ENABLED(CONFIG_MICROCODE_DBG)) {
325+
if (IS_ENABLED(CONFIG_MICROCODE_DBG) && hypervisor_present) {
326326
int cpu = smp_processor_id();
327327

328328
if (!microcode_rev[cpu]) {
@@ -714,7 +714,7 @@ static bool __apply_microcode_amd(struct microcode_amd *mc, u32 *cur_rev,
714714
invlpg(p_addr_end);
715715
}
716716

717-
if (IS_ENABLED(CONFIG_MICROCODE_DBG))
717+
if (IS_ENABLED(CONFIG_MICROCODE_DBG) && hypervisor_present)
718718
microcode_rev[smp_processor_id()] = mc->hdr.patch_id;
719719

720720
/* verify patch application was successful */

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ bool force_minrev = IS_ENABLED(CONFIG_MICROCODE_LATE_FORCE_MINREV);
5757
u32 base_rev;
5858
u32 microcode_rev[NR_CPUS] = {};
5959

60+
bool hypervisor_present;
61+
6062
/*
6163
* Synchronization.
6264
*
@@ -117,7 +119,13 @@ bool __init microcode_loader_disabled(void)
117119
* Disable when:
118120
*
119121
* 1) The CPU does not support CPUID.
120-
*
122+
*/
123+
if (!cpuid_feature()) {
124+
dis_ucode_ldr = true;
125+
return dis_ucode_ldr;
126+
}
127+
128+
/*
121129
* 2) Bit 31 in CPUID[1]:ECX is clear
122130
* The bit is reserved for hypervisor use. This is still not
123131
* completely accurate as XEN PV guests don't see that CPUID bit
@@ -127,9 +135,9 @@ bool __init microcode_loader_disabled(void)
127135
* 3) Certain AMD patch levels are not allowed to be
128136
* overwritten.
129137
*/
130-
if (!cpuid_feature() ||
131-
((native_cpuid_ecx(1) & BIT(31)) &&
132-
!IS_ENABLED(CONFIG_MICROCODE_DBG)) ||
138+
hypervisor_present = native_cpuid_ecx(1) & BIT(31);
139+
140+
if ((hypervisor_present && !IS_ENABLED(CONFIG_MICROCODE_DBG)) ||
133141
amd_check_current_patch_level())
134142
dis_ucode_ldr = true;
135143

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ extern struct early_load_data early_data;
4848
extern struct ucode_cpu_info ucode_cpu_info[];
4949
extern u32 microcode_rev[NR_CPUS];
5050
extern u32 base_rev;
51+
extern bool hypervisor_present;
5152

5253
struct cpio_data find_microcode_in_initrd(const char *path);
5354

0 commit comments

Comments
 (0)