From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) (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 154983E0C6F for ; Thu, 9 Jul 2026 20:49:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783630199; cv=none; b=TizXYL/uL9T8En+jKx7t2Uw6OUwpXHhCaPCKIICyrf4/tyraEIzafX+xrhvDgMz0ZlAFQtqzn2irkZ/2aPWmQGydKF4JNCobKaPkLUYOJHIKXw28OBJ8Y2Cn8WFtdvcmmb83lG94ngzrkNhWP28WcCa4bWUsJ0/7+TpJiqnOCYY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783630199; c=relaxed/simple; bh=p2C2myNclAnCkdNxxGMPC/IAWyTxuYnNNaDW8Jc4LB4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=X/bobeOxDwR1d8mJ+I1e3Mg6mnLZ0RNW1OO2/idcYcZVx4UZE4XFC6bKSNY0fEm59+z3E605RD9i1WBTdHyfAUa+PBEBFurp3ErTbKBqvgZJZClYxscX5f43gC+vqWiTjMybEC9k2Sh2yRsmwmeoX/cBLkpUFa1aDvVzt8H08jM= 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=f5ZZlGFB; arc=none smtp.client-ip=209.85.214.202 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="f5ZZlGFB" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-2ccb6823efcso1459135ad.0 for ; Thu, 09 Jul 2026 13:49:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1783630196; x=1784234996; 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=dg5PWIk+xBZVNHWepnr9z90JNF1w4XrYnESjPtGEmak=; b=f5ZZlGFB5aqL2pMdOzh8up1tNLvGmv+mKbPr2ep99oIYvZa6a8RmjoGid5Bx0DNzmf rR0wdxZ6jaQ6H/JI2dDCDoC+9Ixsb+0f94s4iOmgaguCkaDkx47Qy1CoIv0wPZtsmOds YbZvalqZ0dzhjFZCT199jn5Hw2vN9WZMxyb/qQYUnSwaZd7nRNm75t/A66QUq8hijD1o xajE+pQhDdiHefNgBgtF6V7315Aswk5DU0VEdJb4IdfIt80y0CBLrG4dgzoUtuuYmrc5 Pt6misTErfOZx05+UB6gsTsh/TCu2D0usEmNzX/br6xayrjotVBO35sSCotYVl6h28nu j5fA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783630196; x=1784234996; 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=dg5PWIk+xBZVNHWepnr9z90JNF1w4XrYnESjPtGEmak=; b=L9M3n53DVDUpCTT2zWKF7Du/EQybUoDp87y5Nax1fEJeIzNJug9y7AbnNtDSxBAoS+ 9za317HkVcesKXUuV6KzD22le+QFB6v2tm9zUXOVVnc02y7ujpBclOTqFjZVB3R+S3LE hMmb/p/09XctkFD/+OpwVbA/ANVGjBPqnApORKktyKll0Bi9A96e7QsyAoMZ44em+zEk SDM6Y/DwJX9V/33qfjvjsHJ3uAAArQwzLu4T2QGM/S6MKiBloji8IfdOytWIuO+92O9Q dlXz3Lyuho6TwbJdgGtzv8rsKypQ8wUAMS3FSW3EhveefoYdwIGI25a2tH9589W2+eN0 2kgQ== X-Forwarded-Encrypted: i=1; AHgh+RpAFn3r2ScrixMlHyyo7/dx4vu2rgLVvkYXkgpzJ5oEXRQXadUkhlD8CBl7fC7xfAHhaRwpjqsDHJKXlOo=@vger.kernel.org X-Gm-Message-State: AOJu0Yxt2EV+AAmzjP8ygvmYvgoGlRVk6dCoKmJBOD3sVkF0RjNZMGcW 17MfQU1oeTCbghmqbc36klJtu3SuxQf1kVFu08WNFbHhSGUC9NCs11tkNu66GiYapFDrINRz7An 9Nj1rZA== X-Received: from plbjw12.prod.google.com ([2002:a17:903:278c:b0:2cc:77e3:3ef0]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:1a2f:b0:2c9:d8c6:1dc3 with SMTP id d9443c01a7336-2ccea287d5amr82275195ad.0.1783630196281; Thu, 09 Jul 2026 13:49:56 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 9 Jul 2026 13:49:35 -0700 In-Reply-To: <20260709204948.1988414-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: <20260709204948.1988414-1-seanjc@google.com> X-Mailer: git-send-email 2.55.0.795.g602f6c329a-goog Message-ID: <20260709204948.1988414-6-seanjc@google.com> Subject: [PATCH v4 05/18] KVM: x86: Serialize writes to disabled_quirks using kvm->lock From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Michael Roth , Hyunwoo Kim , Tom Lendacky , "=?UTF-8?q?J=C3=B6rg=20R=C3=B6del?=" , Fuad Tabba , Ackerley Tng Content-Type: text/plain; charset="UTF-8" Protect writes to disabled_quirks with kvm->lock to ensure KVM doesn't clobber state in the unlikely scenario that userspace disables disparate quirks from multiple tasks. More importantly, this will allow wrapping accesses with {READ,WRITE}_ONCE without "needing" to also guard the writer with a useless and confusing READ_ONCE (since the RMW wouldn't be atomic anyways). Ideally, KVM would disallow disabling quirks once quirks are "live", but that would be a potentially breaking userspace ABI change, and while all existing quirks are fully live only after vCPUs have been created, several MMU-related quirks, IGNORE_GUEST_PAT and SLOT_ZAP_ALL, are partially live at all times. Because populating MMUs requires a vCPU, the guest-visible behavior of IGNORE_GUEST_PAT and SLOT_ZAP_ALL requires a vCPU, but for KVM itself, processing the quirk (or not) has functional impact, i.e. for all intents and purposes, KVM can't prevent those quirks from being disabled after they've been consumed. Cc: stable@vger.kernel.org # 6.12.x Reviewed-by: Michael Roth Signed-off-by: Sean Christopherson --- arch/x86/kvm/x86.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 0626e835e9eb..226c6cfe8062 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -3939,7 +3939,9 @@ int kvm_vm_ioctl_enable_cap(struct kvm *kvm, break; fallthrough; case KVM_CAP_DISABLE_QUIRKS: + mutex_lock(&kvm->lock); kvm->arch.disabled_quirks |= cap->args[0] & kvm_caps.supported_quirks; + mutex_unlock(&kvm->lock); r = 0; break; case KVM_CAP_SPLIT_IRQCHIP: { -- 2.55.0.795.g602f6c329a-goog