Skip to content

Commit 3893cd0

Browse files
bp3tk0vgregkh
authored andcommitted
x86/bugs: Rename MDS machinery to something more generic
Commit f9af88a3d384c8b55beb5dc5483e5da0135fadbd upstream. It will be used by other x86 mitigations. No functional changes. Signed-off-by: Borislav Petkov (AMD) <[email protected]> Reviewed-by: Pawan Gupta <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 76cf1f3 commit 3893cd0

File tree

7 files changed

+32
-32
lines changed

7 files changed

+32
-32
lines changed

Documentation/admin-guide/hw-vuln/processor_mmio_stale_data.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,7 @@ This is achieved by using the otherwise unused and obsolete VERW instruction in
157157
combination with a microcode update. The microcode clears the affected CPU
158158
buffers when the VERW instruction is executed.
159159

160-
Kernel reuses the MDS function to invoke the buffer clearing:
161-
162-
mds_clear_cpu_buffers()
160+
Kernel does the buffer clearing with x86_clear_cpu_buffers().
163161

164162
On MDS affected CPUs, the kernel already invokes CPU buffer clear on
165163
kernel/userspace, hypervisor/guest and C-state (idle) transitions. No

arch/x86/entry/entry.S

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,20 @@ EXPORT_SYMBOL_GPL(entry_ibpb);
3131

3232
/*
3333
* Define the VERW operand that is disguised as entry code so that
34-
* it can be referenced with KPTI enabled. This ensure VERW can be
34+
* it can be referenced with KPTI enabled. This ensures VERW can be
3535
* used late in exit-to-user path after page tables are switched.
3636
*/
3737
.pushsection .entry.text, "ax"
3838

3939
.align L1_CACHE_BYTES, 0xcc
40-
SYM_CODE_START_NOALIGN(mds_verw_sel)
40+
SYM_CODE_START_NOALIGN(x86_verw_sel)
4141
UNWIND_HINT_EMPTY
4242
ANNOTATE_NOENDBR
4343
.word __KERNEL_DS
4444
.align L1_CACHE_BYTES, 0xcc
45-
SYM_CODE_END(mds_verw_sel);
45+
SYM_CODE_END(x86_verw_sel);
4646
/* For KVM */
47-
EXPORT_SYMBOL_GPL(mds_verw_sel);
47+
EXPORT_SYMBOL_GPL(x86_verw_sel);
4848

4949
.popsection
5050

arch/x86/include/asm/irqflags.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ static __always_inline void native_irq_enable(void)
4747

4848
static inline __cpuidle void native_safe_halt(void)
4949
{
50-
mds_idle_clear_cpu_buffers();
50+
x86_idle_clear_cpu_buffers();
5151
asm volatile("sti; hlt": : :"memory");
5252
}
5353

5454
static inline __cpuidle void native_halt(void)
5555
{
56-
mds_idle_clear_cpu_buffers();
56+
x86_idle_clear_cpu_buffers();
5757
asm volatile("hlt": : :"memory");
5858
}
5959

arch/x86/include/asm/mwait.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ static inline void __monitorx(const void *eax, unsigned long ecx,
4444

4545
static inline void __mwait(unsigned long eax, unsigned long ecx)
4646
{
47-
mds_idle_clear_cpu_buffers();
47+
x86_idle_clear_cpu_buffers();
4848

4949
/* "mwait %eax, %ecx;" */
5050
asm volatile(".byte 0x0f, 0x01, 0xc9;"
@@ -89,7 +89,8 @@ static inline void __mwaitx(unsigned long eax, unsigned long ebx,
8989

9090
static inline void __sti_mwait(unsigned long eax, unsigned long ecx)
9191
{
92-
mds_idle_clear_cpu_buffers();
92+
x86_idle_clear_cpu_buffers();
93+
9394
/* "mwait %eax, %ecx;" */
9495
asm volatile("sti; .byte 0x0f, 0x01, 0xc9;"
9596
:: "a" (eax), "c" (ecx));

arch/x86/include/asm/nospec-branch.h

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -202,23 +202,23 @@
202202
.endm
203203

204204
/*
205-
* Macro to execute VERW instruction that mitigate transient data sampling
206-
* attacks such as MDS. On affected systems a microcode update overloaded VERW
207-
* instruction to also clear the CPU buffers. VERW clobbers CFLAGS.ZF.
208-
*
205+
* Macro to execute VERW insns that mitigate transient data sampling
206+
* attacks such as MDS or TSA. On affected systems a microcode update
207+
* overloaded VERW insns to also clear the CPU buffers. VERW clobbers
208+
* CFLAGS.ZF.
209209
* Note: Only the memory operand variant of VERW clears the CPU buffers.
210210
*/
211211
.macro CLEAR_CPU_BUFFERS
212212
ALTERNATIVE "jmp .Lskip_verw_\@", "", X86_FEATURE_CLEAR_CPU_BUF
213213
#ifdef CONFIG_X86_64
214-
verw mds_verw_sel(%rip)
214+
verw x86_verw_sel(%rip)
215215
#else
216216
/*
217217
* In 32bit mode, the memory operand must be a %cs reference. The data
218218
* segments may not be usable (vm86 mode), and the stack segment may not
219219
* be flat (ESPFIX32).
220220
*/
221-
verw %cs:mds_verw_sel
221+
verw %cs:x86_verw_sel
222222
#endif
223223
.Lskip_verw_\@:
224224
.endm
@@ -427,24 +427,24 @@ DECLARE_STATIC_KEY_FALSE(switch_to_cond_stibp);
427427
DECLARE_STATIC_KEY_FALSE(switch_mm_cond_ibpb);
428428
DECLARE_STATIC_KEY_FALSE(switch_mm_always_ibpb);
429429

430-
DECLARE_STATIC_KEY_FALSE(mds_idle_clear);
430+
DECLARE_STATIC_KEY_FALSE(cpu_buf_idle_clear);
431431

432432
DECLARE_STATIC_KEY_FALSE(switch_mm_cond_l1d_flush);
433433

434434
DECLARE_STATIC_KEY_FALSE(mmio_stale_data_clear);
435435

436-
extern u16 mds_verw_sel;
436+
extern u16 x86_verw_sel;
437437

438438
#include <asm/segment.h>
439439

440440
/**
441-
* mds_clear_cpu_buffers - Mitigation for MDS and TAA vulnerability
441+
* x86_clear_cpu_buffers - Buffer clearing support for different x86 CPU vulns
442442
*
443443
* This uses the otherwise unused and obsolete VERW instruction in
444444
* combination with microcode which triggers a CPU buffer flush when the
445445
* instruction is executed.
446446
*/
447-
static __always_inline void mds_clear_cpu_buffers(void)
447+
static __always_inline void x86_clear_cpu_buffers(void)
448448
{
449449
static const u16 ds = __KERNEL_DS;
450450

@@ -461,14 +461,15 @@ static __always_inline void mds_clear_cpu_buffers(void)
461461
}
462462

463463
/**
464-
* mds_idle_clear_cpu_buffers - Mitigation for MDS vulnerability
464+
* x86_idle_clear_cpu_buffers - Buffer clearing support in idle for the MDS
465+
* vulnerability
465466
*
466467
* Clear CPU buffers if the corresponding static key is enabled
467468
*/
468-
static inline void mds_idle_clear_cpu_buffers(void)
469+
static __always_inline void x86_idle_clear_cpu_buffers(void)
469470
{
470-
if (static_branch_likely(&mds_idle_clear))
471-
mds_clear_cpu_buffers();
471+
if (static_branch_likely(&cpu_buf_idle_clear))
472+
x86_clear_cpu_buffers();
472473
}
473474

474475
#endif /* __ASSEMBLY__ */

arch/x86/kernel/cpu/bugs.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,9 @@ DEFINE_STATIC_KEY_FALSE(switch_mm_cond_ibpb);
121121
/* Control unconditional IBPB in switch_mm() */
122122
DEFINE_STATIC_KEY_FALSE(switch_mm_always_ibpb);
123123

124-
/* Control MDS CPU buffer clear before idling (halt, mwait) */
125-
DEFINE_STATIC_KEY_FALSE(mds_idle_clear);
126-
EXPORT_SYMBOL_GPL(mds_idle_clear);
124+
/* Control CPU buffer clear before idling (halt, mwait) */
125+
DEFINE_STATIC_KEY_FALSE(cpu_buf_idle_clear);
126+
EXPORT_SYMBOL_GPL(cpu_buf_idle_clear);
127127

128128
/*
129129
* Controls whether l1d flush based mitigations are enabled,
@@ -444,7 +444,7 @@ static void __init mmio_select_mitigation(void)
444444
* is required irrespective of SMT state.
445445
*/
446446
if (!(x86_arch_cap_msr & ARCH_CAP_FBSDP_NO))
447-
static_branch_enable(&mds_idle_clear);
447+
static_branch_enable(&cpu_buf_idle_clear);
448448

449449
/*
450450
* Check if the system has the right microcode.
@@ -2028,10 +2028,10 @@ static void update_mds_branch_idle(void)
20282028
return;
20292029

20302030
if (sched_smt_active()) {
2031-
static_branch_enable(&mds_idle_clear);
2031+
static_branch_enable(&cpu_buf_idle_clear);
20322032
} else if (mmio_mitigation == MMIO_MITIGATION_OFF ||
20332033
(x86_arch_cap_msr & ARCH_CAP_FBSDP_NO)) {
2034-
static_branch_disable(&mds_idle_clear);
2034+
static_branch_disable(&cpu_buf_idle_clear);
20352035
}
20362036
}
20372037

arch/x86/kvm/vmx/vmx.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7144,7 +7144,7 @@ static noinstr void vmx_vcpu_enter_exit(struct kvm_vcpu *vcpu,
71447144
vmx_l1d_flush(vcpu);
71457145
else if (static_branch_unlikely(&mmio_stale_data_clear) &&
71467146
kvm_arch_has_assigned_device(vcpu->kvm))
7147-
mds_clear_cpu_buffers();
7147+
x86_clear_cpu_buffers();
71487148

71497149
vmx_disable_fb_clear(vmx);
71507150

0 commit comments

Comments
 (0)