From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (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 640C533031C for ; Tue, 30 Jun 2026 22:26:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782858381; cv=none; b=HZyNz9zqhavaxCGw10X+Wl+y3jnU4fnPehx4+j3mt7pjOcyjcwT7CrjIyPHqwufLBh1FKRNXTB4f071bIS1xEhTgKgiGuszYo+4o8/tG6BSiTbNEG9zSlgeeG9azi03vFPG6JXIxN8GbIJ03C+J+UNuh+BcwzToyenfkw3vwqe0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782858381; c=relaxed/simple; bh=HG1feGI5IlRLv1EZldmnpuccydXnewwZEq3J8EOi69E=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=kIgGYPo2x1qQvhMA90z1aO9U0YxK2AQ6vE08hBkedopZw0ASbxMsLvC+K4EITQdq5xKf9FJpwh7Vq/2S0ZF9jx0uZm2JOKhaJNxJAl3WkGAF1nJXB+6iOQu/eXgOpoUZXThoqq95YcHQ1Hz7cq8l9jcBlCaHryiZOp2f5nVQmOE= 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=r3ECMxTO; arc=none smtp.client-ip=209.85.216.74 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="r3ECMxTO" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-37fef645b85so46259a91.1 for ; Tue, 30 Jun 2026 15:26:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1782858374; x=1783463174; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=iXLxXMqbIY8W/T72sN/kWMTgzC1Ya7nU/31VzyXOD5Q=; b=r3ECMxTO5LaYLauUtKIAiUeSNbDx8gXEwSn3RCaWOdlIJLU/Ogix+EordGB2tjJrmZ NHSXXWsXYwxa4nVNChygdpWgkytYHixjt97gax+WBAKyLk/adFGPKzdMa3ODfqy0H1ci RfJ32pZgF4kmSimK53WlNDrgQuco2IHhwAmCbfakLHyaGCAQnQaw6JAa0jCPcpQLgngm aBxnHVjcxchtZc6n3alNrcS9HJ5E07cSbQ9ew3ogpajRkUlH5S+cDnMXCxoqjdUf04Cv flY4jmTq31IBjX1VkaGzyop+tnmwSDFSHyDeKPSsEc8sJiNvK0s2d0Dj8eKY2v1BMT2h sNEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782858374; x=1783463174; h=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; bh=iXLxXMqbIY8W/T72sN/kWMTgzC1Ya7nU/31VzyXOD5Q=; b=pPubBy9iYTgt2Vz7Ek9OP45r5fud2KCyyUPUVEYIWyJpGwy1I12D0NQ4jBZ6MwJ4Xx GhzNkthqOYZ7ciphWWVjZ8SCToTmXf3iSUAWun3QOC5DypqMZ6iPWNggAU2QSOSdbbko /Nz1d144tz1c0juTtWWmEoUtJ6OOJKXIEJZFjqZmHNjG2+t7LkN8nuCgWEp4Ek2oOLJY rd5dRi2FFMNWVQCruuHXhBLYD5xom3W1dxZnB6IUxc/x6kINqF/j911b6z/spgDNHxtx UTIJlSWW+2RvVaTQwRubKGXTvWqdg8RseLO+fY1R62wIoKr1rnYhAiLxPCqhD6eUGyh/ 5Gow== X-Forwarded-Encrypted: i=1; AHgh+RqpKUjWMLJwZf6WCZTjQlJWHrP5nyKVnxzRCWBmcdu6MsIfTkAlfTJ8/m+FYMLiIx2CfDavL5uKwp90Sso=@vger.kernel.org X-Gm-Message-State: AOJu0YwvKAIioRfDiEQhgazcDcDoD780z28Mca3FFDWMvm3CkueVIO6w aD8nISE6veksgcRzE6C6SK8dod/obVOl85iMygmZV0Ac2xpQMnRrfVUugvYE4VLF1r/XCJtbNbe gN+v5eQ== X-Received: from pjbbk24.prod.google.com ([2002:a17:90b:818:b0:380:8669:e33b]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:3f90:b0:37f:9ce1:7369 with SMTP id 98e67ed59e1d1-3805278b7ccmr4252232a91.31.1782858374332; Tue, 30 Jun 2026 15:26:14 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 30 Jun 2026 15:26:00 -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-6-seanjc@google.com> Subject: [PATCH v3 05/12] 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, 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" 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 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 6b9a1b0b1460..74f1d7169218 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.rc0.799.gd6f94ed593-goog