Skip to content

Commit 29ba89f

Browse files
committed
x86/CPU/AMD: Improve the erratum 1386 workaround
Disable XSAVES only on machines which haven't loaded the microcode revision containing the erratum fix. This will come in handy when running archaic OSes as guests. OSes whose brilliant programmers thought that CPUID is overrated and one should not query it but use features directly, ala shoot first, ask questions later... but only if you're alive after the shooting. Signed-off-by: Borislav Petkov (AMD) <[email protected]> Tested-by: "Maciej S. Szmigiero" <[email protected]> Cc: Boris Ostrovsky <[email protected]> Link: https://lore.kernel.org/r/20240324200525.GBZgCHhYFsBj12PrKv@fat_crate.local
1 parent 63edbaa commit 29ba89f

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

arch/x86/include/asm/cpu_device_id.h

+8
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,14 @@ struct x86_cpu_desc {
190190
.x86_microcode_rev = (revision), \
191191
}
192192

193+
#define AMD_CPU_DESC(fam, model, stepping, revision) { \
194+
.x86_family = (fam), \
195+
.x86_vendor = X86_VENDOR_AMD, \
196+
.x86_model = (model), \
197+
.x86_stepping = (stepping), \
198+
.x86_microcode_rev = (revision), \
199+
}
200+
193201
extern const struct x86_cpu_id *x86_match_cpu(const struct x86_cpu_id *match);
194202
extern bool x86_cpu_has_min_microcode_rev(const struct x86_cpu_desc *table);
195203

arch/x86/kernel/cpu/amd.c

+12
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <asm/apic.h>
1414
#include <asm/cacheinfo.h>
1515
#include <asm/cpu.h>
16+
#include <asm/cpu_device_id.h>
1617
#include <asm/spec-ctrl.h>
1718
#include <asm/smp.h>
1819
#include <asm/numa.h>
@@ -802,6 +803,11 @@ static void init_amd_bd(struct cpuinfo_x86 *c)
802803
clear_rdrand_cpuid_bit(c);
803804
}
804805

806+
static const struct x86_cpu_desc erratum_1386_microcode[] = {
807+
AMD_CPU_DESC(0x17, 0x1, 0x2, 0x0800126e),
808+
AMD_CPU_DESC(0x17, 0x31, 0x0, 0x08301052),
809+
};
810+
805811
static void fix_erratum_1386(struct cpuinfo_x86 *c)
806812
{
807813
/*
@@ -811,7 +817,13 @@ static void fix_erratum_1386(struct cpuinfo_x86 *c)
811817
*
812818
* Affected parts all have no supervisor XSAVE states, meaning that
813819
* the XSAVEC instruction (which works fine) is equivalent.
820+
*
821+
* Clear the feature flag only on microcode revisions which
822+
* don't have the fix.
814823
*/
824+
if (x86_cpu_has_min_microcode_rev(erratum_1386_microcode))
825+
return;
826+
815827
clear_cpu_cap(c, X86_FEATURE_XSAVES);
816828
}
817829

0 commit comments

Comments
 (0)