From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5A6CB33A005 for ; Tue, 30 Jun 2026 22:26:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782858377; cv=none; b=TTrI50CJ1o5QEqtLWUiFWWoNSNWEigZH3qNfmARWkQ1gWwT8UCjmrLGe+a4ib6QJVP99DBBEHSCHahEakK2V8nzkcIRnU6KUrQi8ErnFC/SIMlDhrK+IDJpFF7Nhr47Uh0UQN0Ep/m44cmR4GopiBUMtQ2b+YqQUQ/9nN4wwvi8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782858377; c=relaxed/simple; bh=RwpYBpcGDK0P48KUDsM77pgrtpeX5obZ2rf5Lhy2ofs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=g2TtDcLGOwixLWQXtSS/sJ1guweoHTDnqkxE9pE9P/v21MAXaM2LnkJIvvnHbLYtBZeDuAYWTLOF9z3+qG/E/Qzc2C4XOmudsESe8nS2ZCkzb84Z6dyyy3/Z6LjtnI01/ushLBdO7Jy/EL2cEb+UCO3Nr6nUyokgsX9g0FHTuy0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Xmio4t3/; arc=none smtp.client-ip=209.85.215.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Xmio4t3/" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-c8894570b58so2118250a12.3 for ; Tue, 30 Jun 2026 15:26:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1782858375; x=1783463175; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:reply-to:from:to:cc:subject:date:message-id :reply-to:content-type; bh=zBuQFsLI7VP5AM9G5y6t2gjs4kfKXwW3Z1IvuFsYReo=; b=Xmio4t3/7BX6HgWnTFD16mIYF4wdcKICwVg8nLPdjU0GQJK4fjI9OPUj/iQn7+RYbO fTOSjppZVrCfN7tYtIw6CIJntO517ycou++SAAtZZh53sEgy/Apql2nDXQxuiEf3HQ5m vrBnKg+O+OP0ILep2x9MvYcuZ/54HcYrl+c8QcflunmcuXmbqLchOGuXhRHAoNwPiHWr cKX+RqNJQIJ9J5BxDXTbRU/LeRN4pBytOxJ0yU8zENPr7akX/wjWQaDDBTLwE9Pat27V 21YC76pS30yzen7YPw+3rC2b3g3h7LzKeJRp2CLDqueTRSJGVDhx4xa2CXgNyGYlh555 PqyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782858375; x=1783463175; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:reply-to:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to:content-type; bh=zBuQFsLI7VP5AM9G5y6t2gjs4kfKXwW3Z1IvuFsYReo=; b=f+RoN66Vq+CelHc4UKQzNL8Q3YKQvpO9vmqoDnEFI+P/7sbSWjTuXuN8YkrpR0FUO4 etviBn1IEdjYEdSqrCn9KMdp01M6kcLD2bCt5d1GcJ0ZSDegIHyojexh+ptz3HvvX4Rf KgRouG2a+m6daa0mtu7P6roZAhU8RntPlz4NTBvetUaLqyWxHNmgC86uDLFaBa+luTfj RdkY9u95OIEHjF9dPPxFBCmc6eiPAZp1RnIjEG1QhW8XTZdo17qnL4rPu9V8ZHuzBNkV moxab7g3z1K8JZjp/52wlpk1/h6T0q3fE58kKaAQvBnqz/shlYDuhReT3Vw4cRSWcXAz CVyg== X-Forwarded-Encrypted: i=1; AFNElJ9QBIjkdL0MfmHRy+kKmmTDuvlG8vW0h6K6SdVf0GDGtfBbCago2bMEhFOwh9IU+JJ02vH/V9xUaPGru4g=@vger.kernel.org X-Gm-Message-State: AOJu0Yzmh5fsQs+m/Lzhmn6fsAtfgGAiJk9ML+9mw8+FpZHfQh+O1Iaz 9M5CdW49Hkxp7Q/AZ76e2+csX99ygn9eFjJd7uEw7gGFpQzyG1q/8hZY2wrV7o8YDqwDZM5+kRv UkUgl0Q== X-Received: from pgg2.prod.google.com ([2002:a05:6a02:4d82:b0:c9a:37aa:b17d]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:493:b0:3bf:a11c:176e with SMTP id adf61e73a8af0-3bfc53362c7mr4743781637.57.1782858375420; Tue, 30 Jun 2026 15:26:15 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 30 Jun 2026 15:26:01 -0700 In-Reply-To: <20260630222607.497895-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260630222607.497895-1-seanjc@google.com> X-Mailer: git-send-email 2.55.0.rc0.799.gd6f94ed593-goog Message-ID: <20260630222607.497895-7-seanjc@google.com> Subject: [PATCH v3 06/12] KVM: x86: Ensure runtime reads of disabled_quirks are resolved once From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Ackerley Tng , Hyunwoo Kim , Tom Lendacky , Michael Roth , "=?UTF-8?q?J=C3=B6rg=20R=C3=B6del?=" , Fuad Tabba Content-Type: text/plain; charset="UTF-8" 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@vger.kernel.org # 6.12.x Signed-off-by: Sean Christopherson --- 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