Skip to content

Commit f6106d4

Browse files
committed
x86/bugs: Use an x86 feature to track the MMIO Stale Data mitigation
Convert the MMIO Stale Data mitigation tracking from a static branch into an x86 feature flag so that it can be used via ALTERNATIVE_2 in KVM. No functional change intended. Reviewed-by: Pawan Gupta <pawan.kumar.gupta@linux.intel.com> Reviewed-by: Brendan Jackman <jackmanb@google.com> Link: https://patch.msgid.link/20251113233746.1703361-5-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent afb99ff commit f6106d4

File tree

5 files changed

+9
-15
lines changed

5 files changed

+9
-15
lines changed

arch/x86/include/asm/cpufeatures.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,11 @@
499499
#define X86_FEATURE_IBPB_EXIT_TO_USER (21*32+14) /* Use IBPB on exit-to-userspace, see VMSCAPE bug */
500500
#define X86_FEATURE_ABMC (21*32+15) /* Assignable Bandwidth Monitoring Counters */
501501
#define X86_FEATURE_MSR_IMM (21*32+16) /* MSR immediate form instructions */
502+
#define X86_FEATURE_CLEAR_CPU_BUF_VM_MMIO (21*32+17) /*
503+
* Clear CPU buffers before VM-Enter if the vCPU
504+
* can access host MMIO (ignored for all intents
505+
* and purposes if CLEAR_CPU_BUF_VM is set).
506+
*/
502507

503508
/*
504509
* BUG word(s)

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -585,8 +585,6 @@ DECLARE_STATIC_KEY_FALSE(cpu_buf_idle_clear);
585585

586586
DECLARE_STATIC_KEY_FALSE(switch_mm_cond_l1d_flush);
587587

588-
DECLARE_STATIC_KEY_FALSE(cpu_buf_vm_clear);
589-
590588
extern u16 x86_verw_sel;
591589

592590
#include <asm/segment.h>

arch/x86/kernel/cpu/bugs.c

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -192,14 +192,6 @@ EXPORT_SYMBOL_GPL(cpu_buf_idle_clear);
192192
*/
193193
DEFINE_STATIC_KEY_FALSE(switch_mm_cond_l1d_flush);
194194

195-
/*
196-
* Controls CPU Fill buffer clear before VMenter. This is a subset of
197-
* X86_FEATURE_CLEAR_CPU_BUF_VM, and should only be enabled when KVM-only
198-
* mitigation is required.
199-
*/
200-
DEFINE_STATIC_KEY_FALSE(cpu_buf_vm_clear);
201-
EXPORT_SYMBOL_GPL(cpu_buf_vm_clear);
202-
203195
#undef pr_fmt
204196
#define pr_fmt(fmt) "mitigations: " fmt
205197

@@ -751,9 +743,8 @@ static void __init mmio_apply_mitigation(void)
751743
if (verw_clear_cpu_buf_mitigation_selected) {
752744
setup_force_cpu_cap(X86_FEATURE_CLEAR_CPU_BUF);
753745
setup_force_cpu_cap(X86_FEATURE_CLEAR_CPU_BUF_VM);
754-
static_branch_disable(&cpu_buf_vm_clear);
755746
} else {
756-
static_branch_enable(&cpu_buf_vm_clear);
747+
setup_force_cpu_cap(X86_FEATURE_CLEAR_CPU_BUF_VM_MMIO);
757748
}
758749

759750
/*

arch/x86/kvm/mmu/spte.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ bool make_spte(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp,
292292
mark_page_dirty_in_slot(vcpu->kvm, slot, gfn);
293293
}
294294

295-
if (static_branch_unlikely(&cpu_buf_vm_clear) &&
295+
if (cpu_feature_enabled(X86_FEATURE_CLEAR_CPU_BUF_VM_MMIO) &&
296296
!kvm_vcpu_can_access_host_mmio(vcpu) &&
297297
kvm_is_mmio_pfn(pfn, &is_host_mmio))
298298
kvm_track_host_mmio_mapping(vcpu);

arch/x86/kvm/vmx/vmx.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,7 @@ unsigned int __vmx_vcpu_run_flags(struct vcpu_vmx *vmx)
903903
if (!msr_write_intercepted(vmx, MSR_IA32_SPEC_CTRL))
904904
flags |= VMX_RUN_SAVE_SPEC_CTRL;
905905

906-
if (static_branch_unlikely(&cpu_buf_vm_clear) &&
906+
if (cpu_feature_enabled(X86_FEATURE_CLEAR_CPU_BUF_VM_MMIO) &&
907907
kvm_vcpu_can_access_host_mmio(&vmx->vcpu))
908908
flags |= VMX_RUN_CLEAR_CPU_BUFFERS_FOR_MMIO;
909909

@@ -7325,7 +7325,7 @@ static noinstr void vmx_vcpu_enter_exit(struct kvm_vcpu *vcpu,
73257325
*/
73267326
if (static_branch_unlikely(&vmx_l1d_should_flush))
73277327
vmx_l1d_flush(vcpu);
7328-
else if (static_branch_unlikely(&cpu_buf_vm_clear) &&
7328+
else if (cpu_feature_enabled(X86_FEATURE_CLEAR_CPU_BUF_VM_MMIO) &&
73297329
(flags & VMX_RUN_CLEAR_CPU_BUFFERS_FOR_MMIO))
73307330
x86_clear_cpu_buffers();
73317331

0 commit comments

Comments
 (0)