Re: [PATCH v3 06/12] KVM: x86: Ensure runtime reads of disabled_quirks are resolved once

From: Michael Roth

Date: Wed Jul 01 2026 - 18:52:43 EST


On Tue, Jun 30, 2026 at 03:26:01PM -0700, Sean Christopherson wrote:
> Wrap the sole reader of disabled_quirks with READ_ONCE(), and wrap the
> post-VM-creation write to disabled_quirks with WRITE_ONCE(), to ensure
> checking the status of a quirk doesn't re-read disabled_quirks *if* the
> caller needs such a guarantee. This will allow splitting the "fast" MMU
> zap into front and back halves, without potentially skipping the back
> half if SLOT_ZAP_ALL were concurrently disabled (which would be "fine" in
> the current code base, but far from ideal).
>
> Cc: stable@xxxxxxxxxxxxxxx # 6.12.x
> Signed-off-by: Sean Christopherson <seanjc@xxxxxxxxxx>

Reviewed-by: Michael Roth <michael.roth@xxxxxxx>

> ---
> arch/x86/kvm/x86.c | 3 ++-
> arch/x86/kvm/x86.h | 2 +-
> 2 files changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 74f1d7169218..bc0c3163f4a3 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -3940,7 +3940,8 @@ int kvm_vm_ioctl_enable_cap(struct kvm *kvm,
> fallthrough;
> case KVM_CAP_DISABLE_QUIRKS:
> mutex_lock(&kvm->lock);
> - kvm->arch.disabled_quirks |= cap->args[0] & kvm_caps.supported_quirks;
> + WRITE_ONCE(kvm->arch.disabled_quirks,
> + kvm->arch.disabled_quirks | (cap->args[0] & kvm_caps.supported_quirks));
> mutex_unlock(&kvm->lock);
> r = 0;
> break;
> diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h
> index 8ece468087a8..75f13d88db58 100644
> --- a/arch/x86/kvm/x86.h
> +++ b/arch/x86/kvm/x86.h
> @@ -304,7 +304,7 @@ static inline bool vcpu_match_mmio_gpa(struct kvm_vcpu *vcpu, gpa_t gpa)
>
> static inline bool kvm_check_has_quirk(struct kvm *kvm, u64 quirk)
> {
> - return !(kvm->arch.disabled_quirks & quirk);
> + return !(READ_ONCE(kvm->arch.disabled_quirks) & quirk);
> }
>
> static __always_inline void kvm_request_l1tf_flush_l1d(void)
> --
> 2.55.0.rc0.799.gd6f94ed593-goog
>