* [PATCH] KVM: VMX: Don't disable FB_CLEAR when doing the MMIO Stale Data VERW
@ 2026-11-24 18:06 Amirmohammad Eftekhar
0 siblings, 0 replies; only message in thread
From: Amirmohammad Eftekhar @ 2026-11-24 18:06 UTC (permalink / raw)
To: seanjc, pbonzini
Cc: pawan.kumar.gupta, brendan.jackman, tglx, mingo, bp, dave.hansen,
x86, hpa, kvm, linux-kernel, amirmohammad.eftekhar,
amirmohammadeftekhar
Don't set FB_CLEAR_DIS for a VM-Enter that does the MMIO Stale Data VERW.
VERW doesn't overwrite the fill buffers while FB_CLEAR_DIS is set, so the
buffer clear that is meant to protect the host from a guest with access
to host MMIO currently does nothing. Keep using FB_CLEAR_DIS for vCPUs
that can't access host MMIO, which are the guests it was added for.
Commit e6ff1d61de51 ("KVM: VMX: Handle MMIO Stale Data in VM-Enter
assembly via ALTERNATIVES_2") moved the MMIO Stale Data VERW from
vmx_vcpu_enter_exit(), where it ran before vmx_disable_fb_clear(), into
__vmx_vcpu_run(), which is called after it. When commit 43fb862de8f6
("KVM/VMX: Move VERW closer to VMentry for MDS mitigation") moved the
unconditional VERW into the asm, vmx_update_fb_clear_dis() was taught to
leave FB_CLEAR alone if X86_FEATURE_CLEAR_CPU_BUF is set, but there is no
such check for X86_FEATURE_CLEAR_CPU_BUF_VM_MMIO.
Both end up enabled on the same hosts. A CPU that is affected by MMIO
Stale Data but not by MDS or TAA mitigates it with
X86_FEATURE_CLEAR_CPU_BUF_VM_MMIO (unless another VERW based mitigation,
such as the one for RFDS, is enabled), and if the CPU enumerates
FB_CLEAR_CTRL, KVM disables FB_CLEAR for vCPUs whose ARCH_CAPABILITIES
enumerate neither FB_CLEAR nor immunity, e.g. QEMU CPU models that expose
arch-capabilities without fb-clear. On those hosts, every VM-Enter of
such a vCPU with host MMIO mapped does the VERW with FB_CLEAR_DIS=1, while
sysfs still reports "Mitigation: Clear CPU buffers".
Fixes: e6ff1d61de51 ("KVM: VMX: Handle MMIO Stale Data in VM-Enter assembly via ALTERNATIVES_2")
Cc: stable@vger.kernel.org
Signed-off-by: Amirmohammad Eftekhar <amirmohammad.eftekhar@cispa.de>
---
I don't have access to a CPU that enumerates FB_CLEAR_CTRL, so this isn't
tested on affected hardware. Instead I ran it as L1 on a vCPU that looks
like an MMIO Stale Data affected Ice Lake-SP (MDS_NO, TAA_NO, FB_CLEAR and
FB_CLEAR_CTRL), with an L2 guest that has a PCI BAR in a memslot and
ARCH_CAPABILITIES without FB_CLEAR. L1's MCU_OPT_CTRL writes #GP, but L0
still sees the values L1 tries to write, and a watchpoint on L1's
x86_verw_sel shows where the VERW happens. Without the patch, all 2576
MMIO VERWs came right after the write that sets FB_CLEAR_DIS; with the
patch, none of the 4478 did, and a guest without host MMIO still gets
FB_CLEAR_DIS on every entry. Same result with QEMU running the L2 guest
with -cpu Icelake-Server-v5.
KVM selftests and kvm-unit-tests (including the vmx tests) gave the same
results with and without the patch in that setup (a few fail or time out
there either way), and it builds cleanly with KVM_INTEL=m, KVM_AMD=m and
KVM_WERROR=y. I can share the test scripts if that helps.
6.19.y to 7.1.y still call the flag VMX_RUN_CLEAR_CPU_BUFFERS_FOR_MMIO,
so the backport needs that rename.
arch/x86/kvm/vmx/vmx.c | 26 ++++++++++++++++++++------
1 file changed, 20 insertions(+), 6 deletions(-)
diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index 68fa251dda60..490cad070c13 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -482,11 +482,24 @@ static const struct kernel_param_ops vmentry_l1d_flush_ops = {
};
module_param_cb(vmentry_l1d_flush, &vmentry_l1d_flush_ops, NULL, 0644);
-static __always_inline void vmx_disable_fb_clear(struct vcpu_vmx *vmx)
+/*
+ * VERW doesn't overwrite the fill buffers if FB_CLEAR_DIS is set, so leave
+ * FB_CLEAR enabled for a VM-Enter that does the MMIO Stale Data VERW. The
+ * unconditional VERW is already handled by vmx_update_fb_clear_dis().
+ */
+static __always_inline bool vmx_should_disable_fb_clear(struct vcpu_vmx *vmx,
+ unsigned int flags)
+{
+ return vmx->disable_fb_clear &&
+ !(flags & KVM_ENTER_CLEAR_CPU_BUFFERS_FOR_MMIO);
+}
+
+static __always_inline void vmx_disable_fb_clear(struct vcpu_vmx *vmx,
+ unsigned int flags)
{
u64 msr;
- if (!vmx->disable_fb_clear)
+ if (!vmx_should_disable_fb_clear(vmx, flags))
return;
msr = native_rdmsrq(MSR_IA32_MCU_OPT_CTRL);
@@ -496,9 +509,10 @@ static __always_inline void vmx_disable_fb_clear(struct vcpu_vmx *vmx)
vmx->msr_ia32_mcu_opt_ctrl = msr;
}
-static __always_inline void vmx_enable_fb_clear(struct vcpu_vmx *vmx)
+static __always_inline void vmx_enable_fb_clear(struct vcpu_vmx *vmx,
+ unsigned int flags)
{
- if (!vmx->disable_fb_clear)
+ if (!vmx_should_disable_fb_clear(vmx, flags))
return;
vmx->msr_ia32_mcu_opt_ctrl &= ~FB_CLEAR_DIS;
@@ -7323,7 +7337,7 @@ static noinstr void vmx_vcpu_enter_exit(struct kvm_vcpu *vcpu,
vmx_l1d_flush(vcpu);
- vmx_disable_fb_clear(vmx);
+ vmx_disable_fb_clear(vmx, flags);
if (vcpu->arch.cr2 != native_read_cr2())
native_write_cr2(vcpu->arch.cr2);
@@ -7335,7 +7349,7 @@ static noinstr void vmx_vcpu_enter_exit(struct kvm_vcpu *vcpu,
vmx->idt_vectoring_info = 0;
- vmx_enable_fb_clear(vmx);
+ vmx_enable_fb_clear(vmx, flags);
if (unlikely(vmx->fail)) {
vmx->vt.exit_reason.full = EXIT_REASON_UNDEFINED;
base-commit: cbe54fc3462b3949ab27b9ae81fb9ddb509040c7
--
2.34.1
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-24 18:06 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-24 18:06 [PATCH] KVM: VMX: Don't disable FB_CLEAR when doing the MMIO Stale Data VERW Amirmohammad Eftekhar
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®