Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795456523; b=hror5jroXtv32hp4gmsSZc9za1un23fWvy7jSOWAJyFCpHW65LTFpjDcN+qLicRC3vGx rft8yp++UhGa09qeCbALvBghZkyLVAT3+qe2o3yDZhPCTZj4PjwpQmyrQVkaDBx+fRuCy 0uH5Jvx0dfmLo3gvQOKENiMUiiZ7TcwHf0YdUdTJB6hw3pR4bXyRCKFzlxuzYc/Dm6n5t rxYTllyajw5yW626/RHZfo0QUiQD27bbg2ckkXYQU+ragzPHX0trqB1kqthtd1NEPC7AX S5Iyb3V1JcfK1ZMVpzO+phy7Nt/TP7oa8eTxOZUJK+0YaLPrCfyNPdLhW7YnjjQ+fSw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795456523; h=DMARC-Filter:DKIM-Signature:Received:X-MC-Unique: X-Mimecast-MFC-AGG-ID:Received:Received:From:To:Cc:Subject:Date: Message-ID:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-Scanned-By; bh=AvbPEA9l7W79/1/VkKdgWAu8lNSuKE2jTD92O8O0l2I=; b=Xd43pxo/kHTwxo724sM/GRBIGnecdrXqkSxSUShv1jzFy0lBcUQbHBPnqb7PHqz31rIW fg0Tt5FLMUWmIvSJjACqTRPPNVkMTwrpQm/VsBspT1NTX4XmHzAYHil0sKraL+tm7jrmZ qH8c+ZM/ViC/adWZf5QjONGm9TavsvmD83uaNX5XjEfQ35VA8sF9kJWQWHlGDqgcG7UYv R7NC4ye/jFcOFbbxoXAD730he08hKGYe8gSw04iiON8D+b4sJAPw3d2XWHm7mSl93Jsr5 /VdWN3PdZxUwwWqVyNPaA1R25qIjynB5bDL1Y3+TFuyiJ4d+93y70vtBLvfdKTqK5mg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=dZviYqpu; arc=none smtp.remote-ip=170.10.129.124 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BF452606A33B for ; Mon, 23 Nov 2026 17:55:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org BF452606A33B Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=dZviYqpu DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1795456521; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AvbPEA9l7W79/1/VkKdgWAu8lNSuKE2jTD92O8O0l2I=; b=dZviYqpuBAEHQfqq27Bua96TX3VWNKoMD6Q/Hsjyy5M8tl7hCee9ApcR72WRTLZO5NXRCw ueJBBbB6BDatlBrljm3zzMygGzXAI/+M//EYyhX7PpQANbdZlM1jjwfGpa90whgaHBjKkx B+8GpdjsjS5YOmitatrayIxrT6zcOeE= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-479-73L7DWHFNbWcvMU0nG-8bQ-1; Mon, 23 Nov 2026 17:55:20 +0000 X-MC-Unique: 73L7DWHFNbWcvMU0nG-8bQ-1 X-Mimecast-MFC-AGG-ID: 73L7DWHFNbWcvMU0nG-8bQ_1795456518 Received: from mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.95]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6B1D51954ADD; Mon, 23 Nov 2026 17:55:18 +0000 (UTC) Received: from mlevitsk-thinkpadt14gen3.ibmmarkh.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 6BB16421; Mon, 23 Nov 2026 17:55:17 +0000 (UTC) From: Maxim Levitsky To: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Paolo Bonzini , x86@kernel.org, Sean Christopherson , Maxim Levitsky Subject: [PATCH v3 3/5] KVM: x86: convert nested_guest_state into an atomic variable Date: Mon, 23 Nov 2026 12:55:10 -0500 Message-ID: <20261123175512.80438-4-mlevitsk@redhat.com> In-Reply-To: <20261123175512.80438-1-mlevitsk@redhat.com> References: <20261123175512.80438-1-mlevitsk@redhat.com> X-Mailing-List: kvm@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.6 on 10.30.177.95 Convert nested_guest_state into an atomic variable, to prepare to fix nested APICv delivery races. No functional change expected. Suggested-by: Paolo Bonzini Signed-off-by: Maxim Levitsky --- arch/x86/include/asm/kvm_host.h | 2 +- arch/x86/kvm/regs.h | 6 +++--- arch/x86/kvm/x86.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index d891dc678e9b..562042d5589b 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -759,7 +759,7 @@ struct kvm_vcpu_arch { #define KVM_NESTED_IN_GUEST BIT(8) /* Non zero when the guest is executing another guest */ - u16 nested_guest_state; + atomic_t nested_guest_state; #ifdef CONFIG_KVM_SMM #define SMM_MASK BIT(0) diff --git a/arch/x86/kvm/regs.h b/arch/x86/kvm/regs.h index 6114a099d177..58950f7d4713 100644 --- a/arch/x86/kvm/regs.h +++ b/arch/x86/kvm/regs.h @@ -457,13 +457,13 @@ static inline unsigned long kvm_get_effective_dr7(struct kvm_vcpu *vcpu) static inline void enter_guest_mode(struct kvm_vcpu *vcpu) { - vcpu->arch.nested_guest_state = KVM_NESTED_IN_GUEST; + atomic_set(&vcpu->arch.nested_guest_state, KVM_NESTED_IN_GUEST); vcpu->stat.guest_mode = 1; } static inline void leave_guest_mode(struct kvm_vcpu *vcpu) { - vcpu->arch.nested_guest_state = 0; + atomic_set(&vcpu->arch.nested_guest_state, 0); if (vcpu->arch.load_eoi_exitmap_pending) { vcpu->arch.load_eoi_exitmap_pending = false; @@ -475,7 +475,7 @@ static inline void leave_guest_mode(struct kvm_vcpu *vcpu) static inline bool is_guest_mode(struct kvm_vcpu *vcpu) { - return vcpu->arch.nested_guest_state != 0; + return atomic_read(&vcpu->arch.nested_guest_state) != 0; } static inline unsigned long kvm_get_segment_base(struct kvm_vcpu *vcpu, int seg) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 821411291f48..a28d263e936a 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -9555,7 +9555,7 @@ void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event) WARN_ON_ONCE(is_guest_mode(vcpu) || is_smm(vcpu)); vcpu->arch.smm_mode = 0; - vcpu->arch.nested_guest_state = 0; + atomic_set(&vcpu->arch.nested_guest_state, 0); vcpu->arch.smi_pending = 0; vcpu->arch.smi_count = 0; -- 2.56.1