Skip to content

Commit fec9434

Browse files
dwmw2KAGA-KOKO
authored andcommitted
x86/pti: Do not enable PTI on CPUs which are not vulnerable to Meltdown
Also, for CPUs which don't speculate at all, don't report that they're vulnerable to the Spectre variants either. Leave the cpu_no_meltdown[] match table with just X86_VENDOR_AMD in it for now, even though that could be done with a simple comparison, on the assumption that we'll have more to add. Based on suggestions from Dave Hansen and Alan Cox. Signed-off-by: David Woodhouse <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Reviewed-by: Greg Kroah-Hartman <[email protected]> Reviewed-by: Borislav Petkov <[email protected]> Acked-by: Dave Hansen <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Link: https://lkml.kernel.org/r/[email protected]
1 parent 1e340c6 commit fec9434

File tree

1 file changed

+43
-5
lines changed

1 file changed

+43
-5
lines changed

arch/x86/kernel/cpu/common.c

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
#include <asm/pat.h>
4848
#include <asm/microcode.h>
4949
#include <asm/microcode_intel.h>
50+
#include <asm/intel-family.h>
51+
#include <asm/cpu_device_id.h>
5052

5153
#ifdef CONFIG_X86_LOCAL_APIC
5254
#include <asm/uv/uv.h>
@@ -853,6 +855,41 @@ static void identify_cpu_without_cpuid(struct cpuinfo_x86 *c)
853855
#endif
854856
}
855857

858+
static const __initdata struct x86_cpu_id cpu_no_speculation[] = {
859+
{ X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_CEDARVIEW, X86_FEATURE_ANY },
860+
{ X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_CLOVERVIEW, X86_FEATURE_ANY },
861+
{ X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_LINCROFT, X86_FEATURE_ANY },
862+
{ X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_PENWELL, X86_FEATURE_ANY },
863+
{ X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_PINEVIEW, X86_FEATURE_ANY },
864+
{ X86_VENDOR_CENTAUR, 5 },
865+
{ X86_VENDOR_INTEL, 5 },
866+
{ X86_VENDOR_NSC, 5 },
867+
{ X86_VENDOR_ANY, 4 },
868+
{}
869+
};
870+
871+
static const __initdata struct x86_cpu_id cpu_no_meltdown[] = {
872+
{ X86_VENDOR_AMD },
873+
{}
874+
};
875+
876+
static bool __init cpu_vulnerable_to_meltdown(struct cpuinfo_x86 *c)
877+
{
878+
u64 ia32_cap = 0;
879+
880+
if (x86_match_cpu(cpu_no_meltdown))
881+
return false;
882+
883+
if (cpu_has(c, X86_FEATURE_ARCH_CAPABILITIES))
884+
rdmsrl(MSR_IA32_ARCH_CAPABILITIES, ia32_cap);
885+
886+
/* Rogue Data Cache Load? No! */
887+
if (ia32_cap & ARCH_CAP_RDCL_NO)
888+
return false;
889+
890+
return true;
891+
}
892+
856893
/*
857894
* Do minimum CPU detection early.
858895
* Fields really needed: vendor, cpuid_level, family, model, mask,
@@ -900,11 +937,12 @@ static void __init early_identify_cpu(struct cpuinfo_x86 *c)
900937

901938
setup_force_cpu_cap(X86_FEATURE_ALWAYS);
902939

903-
if (c->x86_vendor != X86_VENDOR_AMD)
904-
setup_force_cpu_bug(X86_BUG_CPU_MELTDOWN);
905-
906-
setup_force_cpu_bug(X86_BUG_SPECTRE_V1);
907-
setup_force_cpu_bug(X86_BUG_SPECTRE_V2);
940+
if (!x86_match_cpu(cpu_no_speculation)) {
941+
if (cpu_vulnerable_to_meltdown(c))
942+
setup_force_cpu_bug(X86_BUG_CPU_MELTDOWN);
943+
setup_force_cpu_bug(X86_BUG_SPECTRE_V1);
944+
setup_force_cpu_bug(X86_BUG_SPECTRE_V2);
945+
}
908946

909947
fpu__init_system(c);
910948

0 commit comments

Comments
 (0)