Patch 4
Subsystems (4)
PATCH 4/6 Patch 4
L1TF core kernel workarounds are cheap and generally always disabled. However we still want to report in sysfs if the system is vulnerable or mitigated. Add the necessary checks.
- We use the same checks as Meltdown to determine if the system is vulnerable. This excludes some Atom CPUs which don't have this problem.
- We check for the (very unlikely) memory > MAX_PA/2 case
- We check for 32bit PAE and warn
Note this patch will likely conflict with some other workaround patches floating around, but should be straight forward to fix.
Signed-off-by Andi Kleen <[email protected]>
--- arch/x86/include/asm/cpufeatures.h | 2 ++ arch/x86/kernel/cpu/bugs.c | 11 +++++++++++ arch/x86/kernel/cpu/common.c | 8 +++++++- drivers/base/cpu.c | 8 ++++++++ include/linux/cpu.h | 2 ++ 5 files changed, 30 insertions(+), 1 deletion(-)
arch/x86/include/asm/cpufeatures.h +2 -0
@@ -214,6 +214,7 @@#define X86_FEATURE_USE_IBPB ( 7*32+21)/* "" Indirect Branch Prediction Barrier enabled */ #define X86_FEATURE_USE_IBRS_FW ( 7*32+22)/* "" Use IBRS during runtime firmware calls */ +#define X86_FEATURE_NO_L1TF_FIX ( 7*32+23)/* "" L1TF workaround needed, but disabled */ /* Virtualization flags: Linux defined, word 8 */ #define X86_FEATURE_TPR_SHADOW ( 8*32+ 0)/* Intel TPR Shadow */
@@ -362,5 +363,6 @@#define X86_BUG_CPU_MELTDOWN X86_BUG(14)/* CPU is affected by meltdown attack and needs kernel page table isolation */ #define X86_BUG_SPECTRE_V1 X86_BUG(15)/* CPU is affected by Spectre variant 1 attack with conditional branches */ #define X86_BUG_SPECTRE_V2 X86_BUG(16)/* CPU is affected by Spectre variant 2 attack with indirect branches */ +#define X86_BUG_L1TF X86_BUG(17)/* CPU is affected by L1 Terminal Fault */ #endif /* _ASM_X86_CPUFEATURES_H */
arch/x86/kernel/cpu/bugs.c +11 -0
@@ -340,4 +340,15 @@ ssize_t cpu_show_spectre_v2(struct device *dev, struct device_attribute *attr, cboot_cpu_has (X86_FEATURE_USE_IBRS_FW ) ?", IBRS_FW" :"" , spectre_v2_module_string()); } + +ssize_t cpu_show_l1tf (struct device *dev,struct device_attribute *attr,char *buf) +{ +if (!boot_cpu_has_bug (X86_BUG_L1TF )) +return sprintf (buf,"Not affected\n" ); + +if (boot_cpu_has (X86_FEATURE_NO_L1TF_FIX )) +return sprintf (buf,"Mitigation Unavailable\n" ); + +return sprintf (buf,"Mitigated\n" ); +}#endif
arch/x86/kernel/cpu/common.c +7 -1
@@ -989,8 +989,14 @@ static void __init early_identify_cpu(struct cpuinfo_x86 *c)setup_force_cpu_cap (X86_FEATURE_ALWAYS );if (!x86_match_cpu (cpu_no_speculation)) { -if (cpu_vulnerable_to_meltdown (c)) +if (cpu_vulnerable_to_meltdown (c)) {setup_force_cpu_bug (X86_BUG_CPU_MELTDOWN ); +setup_force_cpu_bug (X86_BUG_L1TF ); +#if CONFIG_PGTABLE_LEVELS ==2 +pr_warn ("Kernel not compiled for PAE. No workaround for L1TF\n" ); +setup_force_cpu_bug (X86_FEATURE_NO_L1TF_FIX ); +#endif + }setup_force_cpu_bug (X86_BUG_SPECTRE_V1 );setup_force_cpu_bug (X86_BUG_SPECTRE_V2 ); }
drivers/base/cpu.c +8 -0
@@ -534,14 +534,22 @@ ssize_t __weak cpu_show_spectre_v2(struct device *dev,return sprintf (buf,"Not affected\n" ); } +ssize_t __weak cpu_show_l1tf (struct device *dev, +struct device_attribute *attr,char *buf) +{ +return sprintf (buf,"Not affected\n" ); +} + static DEVICE_ATTR(meltdown, 0444, cpu_show_meltdown, NULL); static DEVICE_ATTR(spectre_v1, 0444, cpu_show_spectre_v1, NULL); static DEVICE_ATTR(spectre_v2, 0444, cpu_show_spectre_v2, NULL); +static DEVICE_ATTR(l1tf, 0444, cpu_show_l1tf, NULL);static struct attribute *cpu_root_vulnerabilities_attrs[] = { &dev_attr_meltdown.attr, &dev_attr_spectre_v1.attr, &dev_attr_spectre_v2.attr, + &dev_attr_l1tf.attr,NULL };
include/linux/cpu.h +2 -0
@@ -53,6 +53,8 @@ extern ssize_t cpu_show_spectre_v1(struct device *dev, struct device_attribute *attr, char *buf);extern ssize_t cpu_show_spectre_v2 (struct device *dev,struct device_attribute *attr,char *buf); +extern ssize_t cpu_show_l1tf (struct device *dev, +struct device_attribute *attr,char *buf); extern __printf(4, 5) struct device *cpu_device_create(struct device *parent, void *drvdata,
Signature · 1 line
2.15.0
[MODERATED] Re: ***UNCHECKED*** [PATCH 4/6] Patch 4
Quoted 1 line · speck for Andi Kleen
L1TF core kernel workarounds are cheap and generally always disabled.
s/disabled/enabled/ right?