We want to expose the hardware features simply in /proc/cpuinfo as "ibrs",
"ibpb" and "stibp". Since AMD has separate CPUID bits for those, use them
as the user-visible bits.
When the Intel SPEC_CTRL bit is set which indicates both IBRS and IBPB
capability, set those (AMD) bits accordingly. Likewise if the Intel STIBP
bit is set, set the AMD STIBP that's used for the generic hardware
capability.
Hide the rest from /proc/cpuinfo by putting "" in the comments. Including
RETPOLINE and RETPOLINE_AMD which shouldn't be visible there. There are
patches to make the sysfs vulnerabilities information non-readable by
non-root, and the same should apply to all information about which
mitigations are actually in use. Those *shouldn't* appear in /proc/cpuinfo.
The feature bit for whether IBPB is actually used, which is needed for
ALTERNATIVEs, is renamed to X86_FEATURE_USE_IBPB.
Originally-by: Borislav Petkov <bp@suse.de>
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: ak@linux.intel.com
Cc: dave.hansen@intel.com
Cc: karahmed@amazon.de
Cc: arjan@linux.intel.com
Cc: torvalds@linux-foundation.org
Cc: peterz@infradead.org
Cc: bp@alien8.de
Cc: pbonzini@redhat.com
Cc: tim.c.chen@linux.intel.com
Cc: gregkh@linux-foundation.org
Link: https://lkml.kernel.org/r/1517070274-12128-2-git-send-email-dwmw@amazon.co.uk
(cherry picked from commit
2961298efe1ea1b6fc0d7ee8b76018fa6c0bcef2)
Orabug:
27477743
CVE: CVE-2017-5715
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Conflicts:
arch/x86/include/asm/cpufeatures.h
arch/x86/kernel/cpu/bugs.c
arch/x86/kernel/cpu/intel.c
[Backport: The majority of the changes are to make 'retpoline' and friends
not show up. Also fix so that instead of 'spec_ctrl' we have 'ibrs'.
The rest we had already]
Reviewed-by: Pavel Tatashin <pasha.tatashin@oracle.com>
Reviewed-by: Darren Kenny <darren.kenny@oracle.com>
#define X86_FEATURE_HWP_EPP ( 7*32+13) /* Intel HWP_EPP */
#define X86_FEATURE_HWP_PKG_REQ ( 7*32+14) /* Intel HWP_PKG_REQ */
#define X86_FEATURE_INTEL_PT ( 7*32+15) /* Intel Processor Trace */
-#define X86_FEATURE_RSB_CTXSW ( 7*32+19) /* Fill RSB on context switches */
-#define X86_FEATURE_SPEC_CTRL ( 7*32+20) /* Control Speculation Control */
+#define X86_FEATURE_RSB_CTXSW ( 7*32+19) /* "" Fill RSB on context switches */
+#define X86_FEATURE_IBRS ( 7*32+20) /* Control Speculation Control */
#define X86_FEATURE_STIPB ( 7*32+21) /* Single Thread Indirect Branch Predictors */
#define X86_FEATURE_IA32_ARCH_CAPS ( 7*32+22) /* Control Speculation Control */
#define X86_FEATURE_IBRS_ATT ( 7*32+23) /* IBRS all the time */
#define X86_FEATURE_VMEXIT_RSB_FULL (7*32+27) /* "" Whether to stuff the RSB on VMEXIT. */
#define X86_FEATURE_STUFF_RSB (7*32+28) /* "" Whether to stuff the RSB (usually dependent on !SMEP) */
-#define X86_FEATURE_RETPOLINE ( 7*32+29) /* Generic Retpoline mitigation for Spectre variant 2 */
-#define X86_FEATURE_RETPOLINE_AMD ( 7*32+30) /* AMD Retpoline mitigation for Spectre variant 2 */
+#define X86_FEATURE_RETPOLINE ( 7*32+29) /* "" Generic Retpoline mitigation for Spectre variant 2 */
+#define X86_FEATURE_RETPOLINE_AMD ( 7*32+30) /* "" AMD Retpoline mitigation for Spectre variant 2 */
/* Because the ALTERNATIVE scheme is for members of the X86_FEATURE club... */
#define X86_FEATURE_PTI ( 7*32+31) /* CONFIG_PAGE_TABLE_ISOLATION w/o nopti */
.endm
.macro SET_IBPB
-ALTERNATIVE "", __stringify(__ASM_SET_IBPB), X86_FEATURE_SPEC_CTRL
+ALTERNATIVE "", __stringify(__ASM_SET_IBPB), X86_FEATURE_IBRS
.endm
.macro DISABLE_IBRS_CLOBBER
-ALTERNATIVE "", __stringify(__ASM_DISABLE_IBRS_CLOBBER), X86_FEATURE_SPEC_CTRL
+ALTERNATIVE "", __stringify(__ASM_DISABLE_IBRS_CLOBBER), X86_FEATURE_IBRS
.endm
.macro STUFF_RSB
c->x86_virt_bits = (eax >> 8) & 0xff;
c->x86_phys_bits = eax & 0xff;
- /* Only look for X86_FEATURE_{IBPB, SPEC_CTRL, STIBP}. */
+ /* Only look for X86_FEATURE_{IBPB, IBRS, STIBP}. */
if (ebx & BIT(12))
set_cpu_cap(c, X86_FEATURE_IBPB);
if (ebx & BIT(14))
- set_cpu_cap(c, X86_FEATURE_SPEC_CTRL);
+ set_cpu_cap(c, X86_FEATURE_IBRS);
if (ebx & BIT(15))
- set_cpu_cap(c, X86_FEATURE_STIPB);
+ set_cpu_cap(c, X86_FEATURE_STIBP);
}
#ifdef CONFIG_X86_32
else if (cpu_has(c, X86_FEATURE_PAE) || cpu_has(c, X86_FEATURE_PSE36))
rdmsr(MSR_IA32_UCODE_REV, lower_word, c->microcode);
}
- if ((cpu_has(c, X86_FEATURE_SPEC_CTRL) ||
+ if ((cpu_has(c, X86_FEATURE_IBRS) ||
cpu_has(c, X86_FEATURE_STIBP)) && bad_spectre_microcode(c)) {
if (&boot_cpu_data == c)
- pr_warn("Intel Spectre v2 broken microcode detected; disabling SPEC_CTRL\n");
- clear_cpu_cap(c, X86_FEATURE_SPEC_CTRL);
+ pr_warn("Intel Spectre v2 broken microcode detected; disabling SPEC_CTRL/IBRS\n");
+ clear_cpu_cap(c, X86_FEATURE_IBRS);
clear_cpu_cap(c, X86_FEATURE_IBPB);
clear_cpu_cap(c, X86_FEATURE_STIBP);
}
{ X86_FEATURE_HW_PSTATE, CR_EDX, 7, 0x80000007, 0 },
{ X86_FEATURE_CPB, CR_EDX, 9, 0x80000007, 0 },
{ X86_FEATURE_PROC_FEEDBACK, CR_EDX,11, 0x80000007, 0 },
- { X86_FEATURE_SPEC_CTRL, CR_EDX,26, 0x00000007, 0 },
+ { X86_FEATURE_IBRS, CR_EDX,26, 0x00000007, 0 },
{ X86_FEATURE_STIPB, CR_EDX,27, 0x00000007, 0 },
{ X86_FEATURE_IA32_ARCH_CAPS, CR_EDX,29, 0x00000007, 0 },
{ X86_FEATURE_NPT, CR_EDX, 0, 0x8000000a, 0 },
if (xen_pv_domain())
ignore = true;
- if (boot_cpu_has(X86_FEATURE_SPEC_CTRL)) {
+ if (boot_cpu_has(X86_FEATURE_IBRS)) {
printk(KERN_INFO "FEATURE SPEC_CTRL Present%s\n", ignore ? " but ignored (Xen)": "");
if (ignore)
return;
smp_mb(); /* quirk */
}
- if (boot_cpu_has(X86_FEATURE_SPEC_CTRL))
+ if (boot_cpu_has(X86_FEATURE_IBRS))
native_wrmsrl(MSR_IA32_SPEC_CTRL, SPEC_CTRL_FEATURE_DISABLE_IBRS);
__monitor((void *)¤t_thread_info()->flags, 0, 0);
if (!need_resched()) {
__sti_mwait(0, 0);
- if (boot_cpu_has(X86_FEATURE_SPEC_CTRL))
+ if (boot_cpu_has(X86_FEATURE_IBRS))
native_wrmsrl(MSR_IA32_SPEC_CTRL,
SPEC_CTRL_FEATURE_ENABLE_IBRS);
} else {
- if (boot_cpu_has(X86_FEATURE_SPEC_CTRL))
+ if (boot_cpu_has(X86_FEATURE_IBRS))
native_wrmsrl(MSR_IA32_SPEC_CTRL, SPEC_CTRL_FEATURE_ENABLE_IBRS);
local_irq_enable();
}
#define F(x) bit(X86_FEATURE_##x)
/* These are scattered features in cpufeatures.h. */
-#define KVM_CPUID_BIT_SPEC_CTRL 26
+#define KVM_CPUID_BIT_IBRS 26
#define KVM_CPUID_BIT_STIBP 27
const u32 kvm_supported_word10_x86_features =
F(XSAVEOPT) | F(XSAVEC) | F(XGETBV1) | f_xsaves;
- const u32 kvm_cpuid_7_0_edx_x86_features = KF(SPEC_CTRL) | KF(STIBP);
+ const u32 kvm_cpuid_7_0_edx_x86_features = KF(IBRS) | KF(STIBP);
/* cpuid 0x80000008.ebx */
const u32 kvm_cpuid_80000008_ebx_x86_features =
entry->ebx |= F(TSC_ADJUST);
entry->edx &= kvm_cpuid_7_0_edx_x86_features;
/* Aka !ibrs_supported and !ibpb_supported */
- if ( !boot_cpu_has(X86_FEATURE_SPEC_CTRL) )
- entry->edx &= !(1u << KVM_CPUID_BIT_SPEC_CTRL);
+ if ( !boot_cpu_has(X86_FEATURE_IBRS) )
+ entry->edx &= !(1u << KVM_CPUID_BIT_IBRS);
if ( !boot_cpu_has(X86_FEATURE_STIPB) )
entry->edx &= !(1u << KVM_CPUID_BIT_STIBP);
} else {