Skip to content

Commit 8cbd0d2

Browse files
committed
Merge tag 'x86_microcode_for_v7.0_rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86 microcode loader update from Borislav Petkov: - Since debugging the microcode loader makes sense on baremetal too (it was used in a guest only until now), extend it to be able to do that too * tag 'x86_microcode_for_v7.0_rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86/microcode/AMD: Allow loader debugging to be enabled on baremetal too
2 parents 9fbb481 + ac44a11 commit 8cbd0d2

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
@@ -1380,10 +1380,12 @@ config MICROCODE_DBG
13801380
default n
13811381
depends on MICROCODE
13821382
help
1383-
Enable code which allows for debugging the microcode loader in
1384-
a guest. Meaning the patch loading is simulated but everything else
1383+
Enable code which allows to debug the microcode loader. When running
1384+
in a guest the patch loading is simulated but everything else
13851385
related to patch parsing and handling is done as on baremetal with
1386-
the purpose of debugging solely the software side of things.
1386+
the purpose of debugging solely the software side of things. On
1387+
baremetal, it simply dumps additional debugging information during
1388+
normal operation.
13871389

13881390
You almost certainly want to say n here.
13891391

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)