From nobody Wed Nov 25 17:40:01 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795622310; b=qwyMdhd3fLe1py/jZ5P43Q6CBgVLqwo1xRQfrnHIPCHE51NbOPybvilMKUC7ke4gfIzN 573KItnYlzdNJQz4tnX/FITK0yLkeBEi18gYY80WRxQvuQVLIJqolsqEPqTPu2KXCyK9o wqVHoa3NGkpTssVTkVuP0QvdPaMtVUWyzi4DJZfEiCiAk7dvUd6K7dDEAVUSBgocI90mi M64oJBnw3DVJsHQN6YmsUTjvODu6TBmH7Ci+FU+50MQnPxWUiscs6AKVqGON/yjElLtCY Dc1cU47mBXEU7uMSCYesclIF729ViUd3zN+ruyX2zmUWl8YI3/+qlmdXwIpZ3J27weQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795622310; 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=ZuFdpd/9bFTvhmX4/6tvbnSZs7CHjbof44sJaDsyJ2k=; b=tJ0kPRykWHVzGtWsT77tL8CWuzAGDgvHdc5fVzRMdYlKa0hrqeixQK6RV1NzOLV3oZNJ aBh0HSkPaWCGrqv8ZhgTZqX2tXfZye0t9se8Qe8JLHRLT61kiDQ9+sQcKRU42N/HAaWEi F3WP9tHexk0F/xKBA2s+4TaYj6/Yle8+H0Ad3AYo3dgaV0ESU+wj6tGzKpwnxmHpr/anr 0atqmm27KInvKh/Gwh3z7nBc+Z08AdSOqRddTV2VxvJLbiK7TS/cZtp0y9IeqsD8vXYen LXSn332Fe76BWg/BzsHR3fnAv85z2WCeZPUEiLijEVXwWHJg9YEg28XYMfTTSt/6Q5Q== 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=UrykbZ3E; arc=none smtp.remote-ip=170.10.133.124 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.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 91B7A606A338 for ; Wed, 25 Nov 2026 15:58:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 91B7A606A338 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=UrykbZ3E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1795622308; 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=ZuFdpd/9bFTvhmX4/6tvbnSZs7CHjbof44sJaDsyJ2k=; b=UrykbZ3ECOi9prJdb6yyMzg/9b0l+eBP9DraUCYwB2iRWLtftygYxRX8VbNpgheBPKdTRc fr1n3eRtOPBHkLOevhxOs444UxzburTaQAcIUQjkhaP8DuC4P0R3xGeFAJRgMS4WcjnfPS nCRBOKU41kWKadHp/20+d47sK6ibpuQ= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-632-_WCABvs_Od6etVJqPdVOTg-1; Wed, 25 Nov 2026 15:58:23 +0000 X-MC-Unique: _WCABvs_Od6etVJqPdVOTg-1 X-Mimecast-MFC-AGG-ID: _WCABvs_Od6etVJqPdVOTg_1795622302 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 07F791800618; Wed, 25 Nov 2026 15:58:22 +0000 (UTC) Received: from mlevitsk-thinkpadt14gen3.ibmmarkh.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0CA753001DB3; Wed, 25 Nov 2026 15:58:20 +0000 (UTC) From: Maxim Levitsky To: kvm@vger.kernel.org Cc: x86@kernel.org, linux-kernel@vger.kernel.org, Sean Christopherson , Paolo Bonzini , Maxim Levitsky Subject: [PATCH v5 1/5] KVM: nVMX: don't check PID.ON when processing nested posted interrupts Date: Wed, 25 Nov 2026 10:58:15 -0500 Message-ID: <20261125155819.408795-2-mlevitsk@redhat.com> In-Reply-To: <20261125155819.408795-1-mlevitsk@redhat.com> References: <20261125155819.408795-1-mlevitsk@redhat.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Content-Type: text/plain; charset="utf-8" Despite the suggestion to test and set the PID.ON and avoid sending a posted interrupt if it is already set, there is no requirement for this bit to be set for posted interrupt processing to happen when the target CPU receives the posted notification vector. See section 30.6 POSTED-INTERRUPT PROCESSING: "The processor clears the outstanding-notification bit in the posted-interrupt descriptor. This is done atomically so as to leave the remainder of the descriptor unmodified (e.g., with a locked AND operation)." Apparently Windows' implementation of APICv does exactly this: it sets bits in PIR, without bothering to also set the PID.ON. Fixes: 705699a13994 ("KVM: nVMX: Enable nested posted interrupt processing") Signed-off-by: Maxim Levitsky --- arch/x86/kvm/vmx/nested.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index 151873407abd..bff719dce07d 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -4041,8 +4041,16 @@ static int vmx_complete_nested_posted_interrupt(stru= ct kvm_vcpu *vcpu) =20 vmx->nested.pi_pending =3D false; =20 - if (!pi_test_and_clear_on(vmx->nested.pi_desc)) - return 0; + /* + * Don't test the value of PID.ON. + * It is valid to trigger a posted interrupt without setting this bit + */ + pi_clear_on(vmx->nested.pi_desc); + + /* Ensure that guest sees the change to PID.ON before KVM harvest + * the PIR + */ + smp_mb__after_atomic(); =20 max_irr =3D pi_find_highest_vector(vmx->nested.pi_desc); if (max_irr > 0) { @@ -4209,8 +4217,7 @@ static bool vmx_has_nested_events(struct kvm_vcpu *vc= pu, bool for_injection) if ((max_irr & 0xf0) > (vppr & 0xf0)) return true; =20 - if (vmx->nested.pi_pending && vmx->nested.pi_desc && - pi_test_on(vmx->nested.pi_desc)) { + if (vmx->nested.pi_pending && vmx->nested.pi_desc) { max_irr =3D pi_find_highest_vector(vmx->nested.pi_desc); if (max_irr > 0 && (max_irr & 0xf0) > (vppr & 0xf0)) return true; --=20 2.56.1 From nobody Wed Nov 25 17:40:01 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795622309; b=wnikniPFNzpyKU1EE25KhVHg4ps2fzFLaNGbOJm/G70VeWbWXZDM74gOIb8Yi5Pht24I CbE0vZCMMQffmhHlO62JkBckchIsYZcqbX48zSF11LDGHeJMQkCDFA0ipqAJk0WIZpvn7 +PUmnlbLaiA3kQvcW/EHGfXv47V3ZCXFz7LwWkWsyjJYZMtoCu6JS6JCxT1a2J8VnjRAS aS0YsvLlq1eEVGCNHUWysUd21Ia2uLOCUA5Q/f152+vllz7uA7EkN851khkxxmAjSIMGI TKniF0AYZ3kaXwzEJD/DVPekyqsLph1MyCc0O+TIdCzCuNaXU1PgUeUrOsmsltTWKFw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795622309; 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=h52cnjKMjgPAHUO3cUiYoHAJatsTrBmwFnsr03rrh2c=; b=Vu4FLh7pwp2dreDFqsiNHekhdxCqMTJV43OFhV6ezee+4VHVHl4VmuaTPyGb8+JtvRSZ KjQFqqSMiflqWEr7oP1UKHGj97eCoHfxsfbc56V1iSdLkmucM+fjoX8jBxaPm4godUls4 3+OXcDiBmwR+ggQ1yZdz1G1R2x3OOzDTLb8pncRf9FydRWvO4xRa039+eEA2MjGqdm8/c FNKDl3lGayi+uzPiQiiMphBPx3NGPr3xBKpgLWiC/8OpsiZJZrDd+BK3b7BABUlwERZZ3 8V71qtLH3XiXibmFT+PTLAseGHhOT73R8EbLzTRbx4mJbznaMZLuRudk4iWCrveus9g== 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=Pn8iQ5PD; arc=none smtp.remote-ip=170.10.133.124 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.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 32784606A32A for ; Wed, 25 Nov 2026 15:58:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 32784606A32A 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=Pn8iQ5PD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1795622308; 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=h52cnjKMjgPAHUO3cUiYoHAJatsTrBmwFnsr03rrh2c=; b=Pn8iQ5PD02ecBUi+YcgQEk1/tTvb035zrPfYiBxsb/sJNs9+cC+l+m9DTTNA/rcLu9PWJj MNgLbr5JIdSA8uAGphSi4gBiNS+VKs5n86guwNLuqTzDTJGl0DSh/9tZFxaC5OpQT9cJ3B pAw9UyobIJPULNheFjCuP9iZ0fMilMA= 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-680-qRZeX7zAOjqNGPkoEJXMmw-1; Wed, 25 Nov 2026 15:58:24 +0000 X-MC-Unique: qRZeX7zAOjqNGPkoEJXMmw-1 X-Mimecast-MFC-AGG-ID: qRZeX7zAOjqNGPkoEJXMmw_1795622303 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 43AE91955F73; Wed, 25 Nov 2026 15:58:23 +0000 (UTC) Received: from mlevitsk-thinkpadt14gen3.ibmmarkh.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 3D0F33001DB3; Wed, 25 Nov 2026 15:58:22 +0000 (UTC) From: Maxim Levitsky To: kvm@vger.kernel.org Cc: x86@kernel.org, linux-kernel@vger.kernel.org, Sean Christopherson , Paolo Bonzini , Maxim Levitsky Subject: [PATCH v5 2/5] KVM: x86: split vcpu->arch.hflags into nested_guest_state and smm_mode Date: Wed, 25 Nov 2026 10:58:16 -0500 Message-ID: <20261125155819.408795-3-mlevitsk@redhat.com> In-Reply-To: <20261125155819.408795-1-mlevitsk@redhat.com> References: <20261125155819.408795-1-mlevitsk@redhat.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Content-Type: text/plain; charset="utf-8" Split vcpu->arch.hflags into nested_guest_mode and smm_mode to prepare for converting nested_guest_mode into an atomic variable that will contain nested guest state that is exposed locklessly for other vCPUs. No functional change expected. Suggested-by: Paolo Bonzini Signed-off-by: Maxim Levitsky --- arch/x86/include/asm/kvm_host.h | 18 +++++++++++------- arch/x86/kvm/regs.h | 6 +++--- arch/x86/kvm/smm.c | 8 ++++---- arch/x86/kvm/smm.h | 2 +- arch/x86/kvm/x86.c | 13 ++++++++----- 5 files changed, 27 insertions(+), 20 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_hos= t.h index ab30f418e526..226091feb44a 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -738,7 +738,6 @@ struct kvm_vcpu_arch { unsigned long cr8; u32 host_pkru; u32 pkru; - u32 hflags; u64 efer; u64 host_debugctl; u64 apic_base; @@ -758,6 +757,16 @@ struct kvm_vcpu_arch { u64 arch_capabilities; u64 perf_capabilities; =20 +#define KVM_NESTED_IN_GUEST BIT(8) + /* Non zero when the guest is executing a nested guest */ + u16 nested_guest_state; + +#ifdef CONFIG_KVM_SMM +#define SMM_MASK BIT(0) +#define SMM_INSIDE_NMI_MASK BIT(1) + /* Non zero when the guest is in SMM */ + u16 smm_mode; +#endif /* * Paging state of the vcpu * @@ -1875,16 +1884,11 @@ static inline unsigned long read_msr(unsigned long = msr) } #endif =20 -#define HF_GUEST_MASK (1 << 0) /* VCPU is in guest-mode */ - #ifdef CONFIG_KVM_SMM -#define HF_SMM_MASK (1 << 1) -#define HF_SMM_INSIDE_NMI_MASK (1 << 2) - # define KVM_MAX_NR_ADDRESS_SPACES 2 /* SMM is currently unsupported for guests with private memory. */ # define kvm_arch_nr_memslot_as_ids(kvm) (kvm_arch_has_private_mem(kvm) ? = 1 : 2) -# define kvm_arch_vcpu_memslots_id(vcpu) ((vcpu)->arch.hflags & HF_SMM_MAS= K ? 1 : 0) +# define kvm_arch_vcpu_memslots_id(vcpu) ((vcpu)->arch.smm_mode & SMM_MASK= ? 1 : 0) # define kvm_memslots_for_spte_role(kvm, role) __kvm_memslots(kvm, (role).= smm) #else # define kvm_memslots_for_spte_role(kvm, role) __kvm_memslots(kvm, 0) diff --git a/arch/x86/kvm/regs.h b/arch/x86/kvm/regs.h index 447f0ec3e63e..ec9d4a8fbe15 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(str= uct kvm_vcpu *vcpu) =20 static inline void enter_guest_mode(struct kvm_vcpu *vcpu) { - vcpu->arch.hflags |=3D HF_GUEST_MASK; + vcpu->arch.nested_guest_state =3D KVM_NESTED_IN_GUEST; vcpu->stat.guest_mode =3D 1; } =20 static inline void leave_guest_mode(struct kvm_vcpu *vcpu) { - vcpu->arch.hflags &=3D ~HF_GUEST_MASK; + vcpu->arch.nested_guest_state =3D 0; =20 if (vcpu->arch.load_eoi_exitmap_pending) { vcpu->arch.load_eoi_exitmap_pending =3D false; @@ -475,7 +475,7 @@ static inline void leave_guest_mode(struct kvm_vcpu *vc= pu) =20 static inline bool is_guest_mode(struct kvm_vcpu *vcpu) { - return vcpu->arch.hflags & HF_GUEST_MASK; + return vcpu->arch.nested_guest_state & KVM_NESTED_IN_GUEST; } =20 static inline unsigned long kvm_get_segment_base(struct kvm_vcpu *vcpu, in= t seg) diff --git a/arch/x86/kvm/smm.c b/arch/x86/kvm/smm.c index 656a38dad7e7..60af64a6209f 100644 --- a/arch/x86/kvm/smm.c +++ b/arch/x86/kvm/smm.c @@ -114,9 +114,9 @@ void kvm_smm_changed(struct kvm_vcpu *vcpu, bool enteri= ng_smm) trace_kvm_smm_transition(vcpu->vcpu_id, vcpu->arch.smbase, entering_smm); =20 if (entering_smm) { - vcpu->arch.hflags |=3D HF_SMM_MASK; + vcpu->arch.smm_mode |=3D SMM_MASK; } else { - vcpu->arch.hflags &=3D ~(HF_SMM_MASK | HF_SMM_INSIDE_NMI_MASK); + vcpu->arch.smm_mode &=3D ~(SMM_MASK | SMM_INSIDE_NMI_MASK); =20 /* Process a latched INIT or SMI, if any. */ kvm_make_request(KVM_REQ_EVENT, vcpu); @@ -311,7 +311,7 @@ void enter_smm(struct kvm_vcpu *vcpu) goto error; =20 if (kvm_x86_call(get_nmi_mask)(vcpu)) - vcpu->arch.hflags |=3D HF_SMM_INSIDE_NMI_MASK; + vcpu->arch.smm_mode |=3D SMM_INSIDE_NMI_MASK; else kvm_x86_call(set_nmi_mask)(vcpu, true); =20 @@ -584,7 +584,7 @@ int emulator_leave_smm(struct x86_emulate_ctxt *ctxt) if (ret < 0) return X86EMUL_UNHANDLEABLE; =20 - if ((vcpu->arch.hflags & HF_SMM_INSIDE_NMI_MASK) =3D=3D 0) + if ((vcpu->arch.smm_mode & SMM_INSIDE_NMI_MASK) =3D=3D 0) kvm_x86_call(set_nmi_mask)(vcpu, false); =20 kvm_smm_changed(vcpu, false); diff --git a/arch/x86/kvm/smm.h b/arch/x86/kvm/smm.h index db3c88f16138..323c03827d28 100644 --- a/arch/x86/kvm/smm.h +++ b/arch/x86/kvm/smm.h @@ -151,7 +151,7 @@ static inline int kvm_inject_smi(struct kvm_vcpu *vcpu) =20 static inline bool is_smm(struct kvm_vcpu *vcpu) { - return vcpu->arch.hflags & HF_SMM_MASK; + return vcpu->arch.smm_mode & SMM_MASK; } =20 void kvm_smm_changed(struct kvm_vcpu *vcpu, bool in_smm); diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 79468ddfe473..0d8854bcbc4f 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -3013,7 +3013,7 @@ static void kvm_vcpu_ioctl_x86_get_vcpu_events(struct= kvm_vcpu *vcpu, events->smi.smm =3D is_smm(vcpu); events->smi.pending =3D vcpu->arch.smi_pending; events->smi.smm_inside_nmi =3D - !!(vcpu->arch.hflags & HF_SMM_INSIDE_NMI_MASK); + !!(vcpu->arch.smm_mode & SMM_INSIDE_NMI_MASK); #endif events->smi.latched_init =3D kvm_lapic_latched_init(vcpu); =20 @@ -3099,7 +3099,7 @@ static int kvm_vcpu_ioctl_x86_set_vcpu_events(struct = kvm_vcpu *vcpu, =20 if (events->flags & KVM_VCPUEVENT_VALID_SMM) { #ifdef CONFIG_KVM_SMM - if (!!(vcpu->arch.hflags & HF_SMM_MASK) !=3D events->smi.smm) { + if (!!(vcpu->arch.smm_mode & SMM_MASK) !=3D events->smi.smm) { kvm_leave_nested(vcpu); kvm_smm_changed(vcpu, events->smi.smm); } @@ -3108,9 +3108,9 @@ static int kvm_vcpu_ioctl_x86_set_vcpu_events(struct = kvm_vcpu *vcpu, =20 if (events->smi.smm) { if (events->smi.smm_inside_nmi) - vcpu->arch.hflags |=3D HF_SMM_INSIDE_NMI_MASK; + vcpu->arch.smm_mode |=3D SMM_INSIDE_NMI_MASK; else - vcpu->arch.hflags &=3D ~HF_SMM_INSIDE_NMI_MASK; + vcpu->arch.smm_mode &=3D ~SMM_INSIDE_NMI_MASK; } =20 #else @@ -9554,7 +9554,10 @@ void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init= _event) kvm_lapic_reset(vcpu, init_event); =20 WARN_ON_ONCE(is_guest_mode(vcpu) || is_smm(vcpu)); - vcpu->arch.hflags =3D 0; +#ifdef CONFIG_KVM_SMM + vcpu->arch.smm_mode =3D 0; +#endif + vcpu->arch.nested_guest_state =3D 0; =20 vcpu->arch.smi_pending =3D 0; vcpu->arch.smi_count =3D 0; --=20 2.56.1 From nobody Wed Nov 25 17:40:01 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795622312; b=EIU4gDFoQyJulKKRw0heElZF2dMhg/7xFjSoGCA9N9okZ8U9W6vyABVGAJYG4DbqZCat Mfnil30uRZfDw5XV1vYfq89RLRGuDC7/5sNkPNFvn16tXEMSmhw9OE7pcV0FD7GfCZ9pc RHe/mZtY2oyeg9jBWHordm7Djiw//3Ks+rjcqHKH447/Eh8kfPlFbAgYSH4HVDUWyF+x3 X0ud/adUe3p2Upt5HqJzFRgVTgbXVR9RtjpePKSWMbdNTy4OW8YVBXiQ8PgKcouErs5vl of93APN+gklG+rjYvIK2/WWAjxNTCfk/tie2JPMECMgPcEUpXwtg1icj4DpMxIGlhAw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795622312; 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=6RRPwyRDY3ZFd/1JP6q/vLcVe+jZU+U/2khQJLP8SlI=; b=2Ar6yfkaoMTHdanz/Gn7fsJx9bX4wF4DLYlgXqSIh642L6PgktqX3wylP43YZaaoKdjx /4o8v83QV1dY/38xS0fdfVRVv9dl+S+byAG9Ky/Zz3VUdefabemQdpznKdn1lhudW/EDm tpcT1IUFIuDF9rRYlZ3xJOtcBcYw5bi0XqJbndd+c6idhC8ZkK+yFu5CokLywIxE+tYP5 MbnK9EZNXQsT0dO1DBPC4o5tyD3mR+p08A18oL8ujotOXjnJNTqmszjP79M5BpI4wPlC4 pqGJCEqBxb0gW2MblKfSD8LRjjzhgqNnBiYie4WRtev7CxCytEqrZXDcx54V6oJXkkg== 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=PLkTaUfh; arc=none smtp.remote-ip=170.10.133.124 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.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 459BC606A696 for ; Wed, 25 Nov 2026 15:58:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 459BC606A696 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=PLkTaUfh DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1795622310; 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=6RRPwyRDY3ZFd/1JP6q/vLcVe+jZU+U/2khQJLP8SlI=; b=PLkTaUfhryPA19TmNIgijamDrqOpOqgDquT4BnQJCJ1tMSiv5nIDi6kXuZTIakLN1tkyPh 7SVJJXHTFiN+J7o0QBgmN1urTQN9QrPcSJ0YKHmZYyUyhvrpvzatKJMS9T6WHZ1F0dcNxL tR4M66hIlNLBmceqJn90ffEeasLr5/Q= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-688-3a88-N9TMvWoHVexjOtkDQ-1; Wed, 25 Nov 2026 15:58:25 +0000 X-MC-Unique: 3a88-N9TMvWoHVexjOtkDQ-1 X-Mimecast-MFC-AGG-ID: 3a88-N9TMvWoHVexjOtkDQ_1795622304 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 78A5818002C1; Wed, 25 Nov 2026 15:58:24 +0000 (UTC) Received: from mlevitsk-thinkpadt14gen3.ibmmarkh.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7B07E3001DB3; Wed, 25 Nov 2026 15:58:23 +0000 (UTC) From: Maxim Levitsky To: kvm@vger.kernel.org Cc: x86@kernel.org, linux-kernel@vger.kernel.org, Sean Christopherson , Paolo Bonzini , Maxim Levitsky Subject: [PATCH v5 3/5] KVM: x86: convert nested_guest_state into an atomic variable Date: Wed, 25 Nov 2026 10:58:17 -0500 Message-ID: <20261125155819.408795-4-mlevitsk@redhat.com> In-Reply-To: <20261125155819.408795-1-mlevitsk@redhat.com> References: <20261125155819.408795-1-mlevitsk@redhat.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Content-Type: text/plain; charset="utf-8" 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 | 7 ++++--- arch/x86/kvm/x86.c | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_hos= t.h index 226091feb44a..78fcc7fcece7 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 { =20 #define KVM_NESTED_IN_GUEST BIT(8) /* Non zero when the guest is executing a nested guest */ - u16 nested_guest_state; + atomic_t nested_guest_state; =20 #ifdef CONFIG_KVM_SMM #define SMM_MASK BIT(0) diff --git a/arch/x86/kvm/regs.h b/arch/x86/kvm/regs.h index ec9d4a8fbe15..b36254db1b8f 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(str= uct kvm_vcpu *vcpu) =20 static inline void enter_guest_mode(struct kvm_vcpu *vcpu) { - vcpu->arch.nested_guest_state =3D KVM_NESTED_IN_GUEST; + atomic_set(&vcpu->arch.nested_guest_state, KVM_NESTED_IN_GUEST); vcpu->stat.guest_mode =3D 1; } =20 static inline void leave_guest_mode(struct kvm_vcpu *vcpu) { - vcpu->arch.nested_guest_state =3D 0; + atomic_set(&vcpu->arch.nested_guest_state, 0); =20 if (vcpu->arch.load_eoi_exitmap_pending) { vcpu->arch.load_eoi_exitmap_pending =3D false; @@ -475,7 +475,8 @@ static inline void leave_guest_mode(struct kvm_vcpu *vc= pu) =20 static inline bool is_guest_mode(struct kvm_vcpu *vcpu) { - return vcpu->arch.nested_guest_state & KVM_NESTED_IN_GUEST; + return atomic_read(&vcpu->arch.nested_guest_state) & + KVM_NESTED_IN_GUEST; } =20 static inline unsigned long kvm_get_segment_base(struct kvm_vcpu *vcpu, in= t seg) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 0d8854bcbc4f..74c372906ac7 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -9557,7 +9557,7 @@ void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_= event) #ifdef CONFIG_KVM_SMM vcpu->arch.smm_mode =3D 0; #endif - vcpu->arch.nested_guest_state =3D 0; + atomic_set(&vcpu->arch.nested_guest_state, 0); =20 vcpu->arch.smi_pending =3D 0; vcpu->arch.smi_count =3D 0; --=20 2.56.1 From nobody Wed Nov 25 17:40:01 2026 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=1795622311; b=pYq8zA/l6/dHS4K/PnRVl9zM2V9+HTSV2VIGdRHiNdQ65EPJngTM+BKbT5psNMymCLIu u2PoPXz6ELMcYC99wZo7dgBTqFxH4R44hgdtCP5QmTXOy3UubvAn4IkDwM0nt2cIM39zF rAHHv7u6PeLlI1OgWpLRVuN7zH8QLdHnkgprbJQPOJqkA+FFfNWt022Lt8p2JIzA8IEHw IVtVl/2jeXo6k/4HJbralvbZNorWsX3MB9u7k9uwHxMKrTONAh0c4Zxy1lBQb1AJikvZ/ ffsOtepap+nI3iAP8xq6xdc55ctW5ciPtiIVHWtYrotBNNhAQMEnYB3V2z2ktKcJ10w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795622311; 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=yPBfEKahhfYei6glmdPdejVYAgGYQtYkDSj3W5f5X7s=; b=TBInflxTXcZFlI3Z/wyIUCQ2ggx0jmGTBwhtCk9yaxiCZeyzlV8aNx+0ZvyJh0H9zS5s FSvmpzf/+wCC0qhkb8rQAxhCAfxXboiuil0+Ad0qAkM5cEU/sNpBSQt/omqeTraFMG8/q MUctEzKUGJDHRB6h9XCuTUzn1iKaX0TgnQsTppJeRF0WYa8EngP9buDvJ4Ncuny91a2JG 35G0NoTcJfJ/A4Sk1EMmzHfmLWhhuqq5dIcaxFehzOvYiTm4pTqbg72zkXDd2fRAxc/zd 2RpoBxXbJsSvntE/iit63cYTH98AVWZK23W/1X12eKVooxM/EdDc2ZDccGuVMWmEPbw== 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=ZNtafxeg; 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 E8877606A680 for ; Wed, 25 Nov 2026 15:58:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E8877606A680 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=ZNtafxeg DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1795622309; 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=yPBfEKahhfYei6glmdPdejVYAgGYQtYkDSj3W5f5X7s=; b=ZNtafxegWZrZnCgcvJznRRiugSnCMipQjDRzVN4gPlEGDiNiw/7NyGaC4KDPK6fJ00PGIe P56ymgqsoikaAZhTeW1imoI7oE2TuPQbRWWGT5asGsv1sBzfhRn9KcbUrEniyu3d940GkD AT/Z9TkMqVTpeRtnzlYsLI3QcEAXU0M= 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-643-llluhFTaNsSqw3KHF2SPZg-1; Wed, 25 Nov 2026 15:58:26 +0000 X-MC-Unique: llluhFTaNsSqw3KHF2SPZg-1 X-Mimecast-MFC-AGG-ID: llluhFTaNsSqw3KHF2SPZg_1795622305 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 C99F9195604E; Wed, 25 Nov 2026 15:58:25 +0000 (UTC) Received: from mlevitsk-thinkpadt14gen3.ibmmarkh.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id AEE223001DB7; Wed, 25 Nov 2026 15:58:24 +0000 (UTC) From: Maxim Levitsky To: kvm@vger.kernel.org Cc: x86@kernel.org, linux-kernel@vger.kernel.org, Sean Christopherson , Paolo Bonzini , Maxim Levitsky Subject: [PATCH v5 4/5] KVM: x86: nVMX: move nested APICv state to nested_guest_state Date: Wed, 25 Nov 2026 10:58:18 -0500 Message-ID: <20261125155819.408795-5-mlevitsk@redhat.com> In-Reply-To: <20261125155819.408795-1-mlevitsk@redhat.com> References: <20261125155819.408795-1-mlevitsk@redhat.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Content-Type: text/plain; charset="utf-8" Replace vmx->nested.pi_pending,pi_active and posted_intr_nv with KVM_NESTED_PI_VECTOR_MASK,KVM_NESTED_PI_ACTIVE,KVM_NESTED_PI_PENDING flags of nested_guest_state. Since the nested state is cleared as a whole to 0, on each nested VM exit, explicit clearing of vmx->nested.posted_intr_nv and vmx->nested.pi_pending was dropped. Also, since nested entry sets nested_guest_state to KVM_NESTED_IN_GUEST, the publishing of KVM_NESTED_PI_VECTOR_MASK,KVM_NESTED_PI_ACTIVE is delayed to happen after enter_guest_mode(). Suggested-by: Paolo Bonzini Signed-off-by: Maxim Levitsky --- arch/x86/include/asm/kvm_host.h | 5 ++++- arch/x86/kvm/vmx/nested.c | 33 +++++++++++++++++++-------------- arch/x86/kvm/vmx/vmx.c | 7 +++---- arch/x86/kvm/vmx/vmx.h | 2 -- 4 files changed, 26 insertions(+), 21 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_hos= t.h index 78fcc7fcece7..43acc724b8e4 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -757,7 +757,10 @@ struct kvm_vcpu_arch { u64 arch_capabilities; u64 perf_capabilities; =20 -#define KVM_NESTED_IN_GUEST BIT(8) +#define KVM_NESTED_PI_VECTOR_MASK 0xFF +#define KVM_NESTED_IN_GUEST BIT(8) +#define KVM_NESTED_PI_ACTIVE BIT(9) +#define KVM_NESTED_PI_PENDING BIT(10) /* Non zero when the guest is executing a nested guest */ atomic_t nested_guest_state; =20 diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index bff719dce07d..1b4483dd6354 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -351,7 +351,6 @@ static void free_nested(struct kvm_vcpu *vcpu) vmx->nested.smm.vmxon =3D false; vmx->nested.vmxon_ptr =3D INVALID_GPA; free_vpid(vmx->nested.vpid02); - vmx->nested.posted_intr_nv =3D -1; vmx->nested.current_vmptr =3D INVALID_GPA; if (enable_shadow_vmcs) { vmx_disable_shadow_vmcs(vmx); @@ -2445,13 +2444,9 @@ static void prepare_vmcs02_early(struct vcpu_vmx *vm= x, struct loaded_vmcs *vmcs0 ~PIN_BASED_VMX_PREEMPTION_TIMER); =20 /* Posted interrupts setting is only taken from vmcs12. */ - vmx->nested.pi_pending =3D false; - if (nested_cpu_has_posted_intr(vmcs12)) { - vmx->nested.posted_intr_nv =3D vmcs12->posted_intr_nv; - } else { - vmx->nested.posted_intr_nv =3D -1; + if (!nested_cpu_has_posted_intr(vmcs12)) exec_control &=3D ~PIN_BASED_POSTED_INTR; - } + pin_controls_set(vmx, exec_control); =20 /* @@ -3720,6 +3715,9 @@ enum nvmx_vmentry_status nested_vmx_enter_non_root_mo= de(struct kvm_vcpu *vcpu, kvm_make_request(KVM_REQ_GET_NESTED_STATE_PAGES, vcpu); } =20 + if (nested_cpu_has_posted_intr(vmcs12)) + atomic_or(KVM_NESTED_PI_ACTIVE | vmcs12->posted_intr_nv, + &vcpu->arch.nested_guest_state); /* * Re-evaluate pending events if L1 had a pending IRQ/NMI/INIT/SIPI * when it executed VMLAUNCH/VMRESUME, as entering non-root mode can @@ -4033,13 +4031,15 @@ static int vmx_complete_nested_posted_interrupt(str= uct kvm_vcpu *vcpu) void *vapic_page; u16 status; =20 - if (!vmx->nested.pi_pending) + int nested_state =3D atomic_read(&vcpu->arch.nested_guest_state); + + if (!(nested_state & KVM_NESTED_PI_PENDING)) return 0; =20 if (!vmx->nested.pi_desc) goto mmio_needed; =20 - vmx->nested.pi_pending =3D false; + atomic_andnot(KVM_NESTED_PI_PENDING, &vcpu->arch.nested_guest_state); =20 /* * Don't test the value of PID.ON. @@ -4191,6 +4191,8 @@ static bool vmx_has_nested_events(struct kvm_vcpu *vc= pu, bool for_injection) void *vapic =3D vmx->nested.virtual_apic_map.hva; int max_irr, vppr; =20 + int nested_state =3D atomic_read(&vcpu->arch.nested_guest_state); + if (nested_vmx_preemption_timer_pending(vcpu) || vmx->nested.mtf_pending) return true; @@ -4217,7 +4219,7 @@ static bool vmx_has_nested_events(struct kvm_vcpu *vc= pu, bool for_injection) if ((max_irr & 0xf0) > (vppr & 0xf0)) return true; =20 - if (vmx->nested.pi_pending && vmx->nested.pi_desc) { + if ((nested_state & KVM_NESTED_PI_PENDING) && vmx->nested.pi_desc) { max_irr =3D pi_find_highest_vector(vmx->nested.pi_desc); if (max_irr > 0 && (max_irr & 0xf0) > (vppr & 0xf0)) return true; @@ -4448,7 +4450,7 @@ static int vmx_check_nested_events(struct kvm_vcpu *v= cpu) } =20 if (kvm_cpu_has_interrupt(vcpu) && !vmx_interrupt_blocked(vcpu)) { - int irq; + int irq, nested_state; =20 if (!nested_exit_on_intr(vcpu)) { if (block_nested_events) @@ -4481,6 +4483,8 @@ static int vmx_check_nested_events(struct kvm_vcpu *v= cpu) goto no_vmexit; } =20 + nested_state =3D atomic_read(&vcpu->arch.nested_guest_state); + /* * If the IRQ is L2's PI notification vector, process posted * interrupts for L2 instead of injecting VM-Exit, as the @@ -4489,7 +4493,8 @@ static int vmx_check_nested_events(struct kvm_vcpu *v= cpu) * through the local APIC trigger posted interrupt processing, * and enabling posted interrupts requires ACK-on-exit. */ - if (irq =3D=3D vmx->nested.posted_intr_nv) { + if ((nested_state & KVM_NESTED_PI_ACTIVE) && + ((nested_state & KVM_NESTED_PI_VECTOR_MASK) =3D=3D irq)) { /* * Nested posted interrupts are delivered via RVI, i.e. * aren't injected by KVM, and so can be queued even if @@ -4498,7 +4503,8 @@ static int vmx_check_nested_events(struct kvm_vcpu *v= cpu) if (block_non_injected_events) return -EBUSY; =20 - vmx->nested.pi_pending =3D true; + atomic_or(KVM_NESTED_PI_PENDING, &vcpu->arch.nested_guest_state); + kvm_apic_clear_irr(vcpu, irq); goto no_vmexit; } @@ -5587,7 +5593,6 @@ static inline void nested_release_vmcs12(struct kvm_v= cpu *vcpu) copy_shadow_to_vmcs12(vmx); vmx_disable_shadow_vmcs(vmx); } - vmx->nested.posted_intr_nv =3D -1; =20 /* Flush VMCS12 to guest memory */ kvm_vcpu_write_guest_page(vcpu, diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 612ab07d4100..e6dd37a3ac44 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -4370,7 +4370,7 @@ void vmx_recalc_intercepts(struct kvm_vcpu *vcpu) static int vmx_deliver_nested_posted_interrupt(struct kvm_vcpu *vcpu, int vector) { - struct vcpu_vmx *vmx =3D to_vmx(vcpu); + int nested_state =3D atomic_read(&vcpu->arch.nested_guest_state); =20 /* * DO NOT query the vCPU's vmcs12, as vmcs12 is dynamically allocated @@ -4380,12 +4380,12 @@ static int vmx_deliver_nested_posted_interrupt(stru= ct kvm_vcpu *vcpu, * L1 has enabled posted interrupts for L2. */ if (is_guest_mode(vcpu) && - vector =3D=3D vmx->nested.posted_intr_nv) { + vector =3D=3D (nested_state & KVM_NESTED_PI_VECTOR_MASK)) { /* * If a posted intr is not recognized by hardware, * we will accomplish it in the next vmentry. */ - vmx->nested.pi_pending =3D true; + atomic_or(KVM_NESTED_PI_PENDING, &vcpu->arch.nested_guest_state); kvm_make_request(KVM_REQ_EVENT, vcpu); =20 /* @@ -5019,7 +5019,6 @@ static void __vmx_vcpu_reset(struct kvm_vcpu *vcpu) =20 vcpu_setup_sgx_lepubkeyhash(vcpu); =20 - vmx->nested.posted_intr_nv =3D -1; vmx->nested.vmxon_ptr =3D INVALID_GPA; vmx->nested.current_vmptr =3D INVALID_GPA; =20 diff --git a/arch/x86/kvm/vmx/vmx.h b/arch/x86/kvm/vmx/vmx.h index dc8517f15bc4..0632cd8908b3 100644 --- a/arch/x86/kvm/vmx/vmx.h +++ b/arch/x86/kvm/vmx/vmx.h @@ -151,8 +151,6 @@ struct nested_vmx { struct kvm_host_map pi_desc_map; =20 struct pi_desc *pi_desc; - bool pi_pending; - u16 posted_intr_nv; =20 struct hrtimer preemption_timer; u64 preemption_timer_deadline; --=20 2.56.1 From nobody Wed Nov 25 17:40:01 2026 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=1795622314; b=h86JxIroV/oOMDu4ASZJ3ZqzLqPvwnepD5K+JsMnku2iHXFs4v0v7b0+a52O3AV6DRsD XJ4V9sYT7b79rPztme/Uoa2ut5MLjg0GZAkeh6YdylCtSveNlMHPqy3+ynNkFC3mCdDsj SRmoN1qGQ7HUkHUQISOvwC0vVWui9xaFjIiEJW9YNSkkJ2TC1amuej2nzH+pk1N4/x9Pr AuY7h7erdvhmfPlJ+ZHSWx1PAAWqdSGBiqwH19xsQlRp7qDHGi6z02U3xh/uKzabh7uPC GQjNGKLN04gFS74xp0pEsr+ZUVptTdtp885Vi49h+Y3bK/7fdGK2OrEfs2TobgfnCTg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795622314; 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=vx8QxYL7d+TDSakwDw4bpqj3m3BNoGgy5VWbf0qHx0s=; b=AZA+1bcLFoN6OA9b5qzOFc94pg5JN0eaTtYyQE+1WV8UnEHp55+1fsoRCHkhnTMpB/wA 1EAebF2hHlrzqNpx8AgZshaj9Ttf97YuehtMfjQ2ksCw0rdV5HUVwISICXIJ8/zSOvVZH o3akCTNaDSC39pBUpTw4mX67f3Gx/6+gILMBfhOusNys9/hfA2gMq/DXf39AlUHUtMFjg ABncdz7adcjxtB6NZJWiqtsIlLvd6vGl9tL8dfK7PBzw5LJu7QCaUYYknKxzjIcJceXfm XGzN9QecpL4EZHzhhnyixh+3NJv2aP45S49dTNAjLRn4bGWp0WuxhFr29faZ075sLnQ== 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=gaI51KGX; 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 89DD5606A33F for ; Wed, 25 Nov 2026 15:58:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 89DD5606A33F 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=gaI51KGX DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1795622312; 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=vx8QxYL7d+TDSakwDw4bpqj3m3BNoGgy5VWbf0qHx0s=; b=gaI51KGX4h5X2qzMs2+xpjG7bXuxhg94ooXyNiYy99IdzjqfUtwmvxRQTgZrPx/Ek7p2+0 vRFSitRwkbDbfoWrFPMGIpLshkqIK4TPoUbRCoG8tQO5RlIr9ypYLrzUYIxt3RSz2q33eX fmsgZIYjecVmC31qF7cKDcmZFXmAKuM= Received: from mx-prod-mc-03.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-311-f1CKUIIoOY672_CLq3VEhw-1; Wed, 25 Nov 2026 15:58:28 +0000 X-MC-Unique: f1CKUIIoOY672_CLq3VEhw-1 X-Mimecast-MFC-AGG-ID: f1CKUIIoOY672_CLq3VEhw_1795622307 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1BCD91955F10; Wed, 25 Nov 2026 15:58:27 +0000 (UTC) Received: from mlevitsk-thinkpadt14gen3.ibmmarkh.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 08AD03001DBD; Wed, 25 Nov 2026 15:58:25 +0000 (UTC) From: Maxim Levitsky To: kvm@vger.kernel.org Cc: x86@kernel.org, linux-kernel@vger.kernel.org, Sean Christopherson , Paolo Bonzini , Maxim Levitsky Subject: [PATCH v5 5/5] KVM: x86: nVMX: fix races in delivery of nested posted interrupts Date: Wed, 25 Nov 2026 10:58:19 -0500 Message-ID: <20261125155819.408795-6-mlevitsk@redhat.com> In-Reply-To: <20261125155819.408795-1-mlevitsk@redhat.com> References: <20261125155819.408795-1-mlevitsk@redhat.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Content-Type: text/plain; charset="utf-8" If a nested posted interrupt races with a L0 vm exit on a target vCPU, that is reflected to L1, then this nestedf posted interrupt is currently neither processed nor delivered to L1 as a regular interrupt. Since it is not possible to know if APICv hardware has processed the interrupt, opt to always process it a moment before nested VM exit. (call vmx_complete_nested_posted_interrupt) To ensure that vmx_deliver_nested_posted_interrupt and vmx_complete_nested_posted_interrupt don't race do the following: Have a cmpxchg based loop in vmx_deliver_nested_posted_interrupt that atomically checks that target vCPU is in nested mode and has suitable posted interrupt configuration, and then set KVM_NESTED_PI_PENDING. If the above cmpxchg loop succeeds, this means that even if the target vCPU is in process of exiting the nested guest, it will notice this KVM_NESTED_PI_PENDING flag when it reaches its vmx_complete_nested_posted_interrupt, and then it will process it. If it fails, it means that the target vCPU is no longer in the guest mode, and thus it is safe to deliver the interrupt as a normal interrupt. Apply a similar logic on the receiving side: Use xchg to snapshot the old value of guest state in leave_guest_mode, and by using this snapshot, determine if we need to process the posted interrupts. Also delay publish to of the nested posted interrupt state to KVM_REQ_GET_NESTED_STATE_PAGES to avoid dealing with a situation where vm exit causes a L2->L2 vm exit before nested APICv pages were mapped. Fixes: 705699a13994 ("KVM: nVMX: Enable nested posted interrupt processing") Suggested-by: Paolo Bonzini Signed-off-by: Maxim Levitsky --- arch/x86/kvm/regs.h | 5 ++-- arch/x86/kvm/vmx/nested.c | 63 ++++++++++++++++++++++++++------------- arch/x86/kvm/vmx/vmx.c | 60 ++++++++++++++++++------------------- 3 files changed, 76 insertions(+), 52 deletions(-) diff --git a/arch/x86/kvm/regs.h b/arch/x86/kvm/regs.h index b36254db1b8f..4a507e15134b 100644 --- a/arch/x86/kvm/regs.h +++ b/arch/x86/kvm/regs.h @@ -461,9 +461,9 @@ static inline void enter_guest_mode(struct kvm_vcpu *vc= pu) vcpu->stat.guest_mode =3D 1; } =20 -static inline void leave_guest_mode(struct kvm_vcpu *vcpu) +static inline int leave_guest_mode(struct kvm_vcpu *vcpu) { - atomic_set(&vcpu->arch.nested_guest_state, 0); + int old_value =3D atomic_xchg(&vcpu->arch.nested_guest_state, 0); =20 if (vcpu->arch.load_eoi_exitmap_pending) { vcpu->arch.load_eoi_exitmap_pending =3D false; @@ -471,6 +471,7 @@ static inline void leave_guest_mode(struct kvm_vcpu *vc= pu) } =20 vcpu->stat.guest_mode =3D 0; + return old_value; } =20 static inline bool is_guest_mode(struct kvm_vcpu *vcpu) diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index 1b4483dd6354..220ef40d4cb1 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -3434,7 +3434,18 @@ static bool nested_get_evmcs_page(struct kvm_vcpu *v= cpu) } #endif =20 -static bool nested_get_vmcs12_pages(struct kvm_vcpu *vcpu) +static void nested_vmx_enable_posted_interrupts(struct kvm_vcpu *vcpu) +{ + struct vmcs12 *vmcs12 =3D get_vmcs12(vcpu); + + WARN_ON_ONCE(vmcs12->posted_intr_nv & ~KVM_NESTED_PI_VECTOR_MASK); + + atomic_or(KVM_NESTED_PI_ACTIVE | + (vmcs12->posted_intr_nv & KVM_NESTED_PI_VECTOR_MASK), + &vcpu->arch.nested_guest_state); +} + +static bool nested_get_vmcs12_pages(struct kvm_vcpu *vcpu, bool from_vment= ry) { struct vmcs12 *vmcs12 =3D get_vmcs12(vcpu); struct vcpu_vmx *vmx =3D to_vmx(vcpu); @@ -3513,6 +3524,9 @@ static bool nested_get_vmcs12_pages(struct kvm_vcpu *= vcpu) vmx->nested.pi_desc =3D NULL; pin_controls_clearbit(vmx, PIN_BASED_POSTED_INTR); } + + if (!from_vmentry) + nested_vmx_enable_posted_interrupts(vcpu); } if (nested_vmx_prepare_msr_bitmap(vcpu, vmcs12)) exec_controls_setbit(vmx, CPU_BASED_USE_MSR_BITMAPS); @@ -3543,7 +3557,7 @@ static bool vmx_get_nested_state_pages(struct kvm_vcp= u *vcpu) } #endif =20 - if (is_guest_mode(vcpu) && !nested_get_vmcs12_pages(vcpu)) + if (is_guest_mode(vcpu) && !nested_get_vmcs12_pages(vcpu, false)) return false; =20 return true; @@ -3674,7 +3688,7 @@ enum nvmx_vmentry_status nested_vmx_enter_non_root_mo= de(struct kvm_vcpu *vcpu, prepare_vmcs02_early(vmx, &vmx->vmcs01, vmcs12); =20 if (from_vmentry) { - if (unlikely(!nested_get_vmcs12_pages(vcpu))) { + if (unlikely(!nested_get_vmcs12_pages(vcpu, true))) { vmx_switch_vmcs(vcpu, &vmx->vmcs01); return NVMX_VMENTRY_KVM_INTERNAL_ERROR; } @@ -3704,6 +3718,9 @@ enum nvmx_vmentry_status nested_vmx_enter_non_root_mo= de(struct kvm_vcpu *vcpu, vmcs12->exit_qualification =3D failed_index; goto vmentry_fail_vmexit_guest_mode; } + + if (nested_cpu_has_posted_intr(vmcs12)) + nested_vmx_enable_posted_interrupts(vcpu); } else { /* * The MMU is not initialized to point at the right entities yet and @@ -3715,9 +3732,6 @@ enum nvmx_vmentry_status nested_vmx_enter_non_root_mo= de(struct kvm_vcpu *vcpu, kvm_make_request(KVM_REQ_GET_NESTED_STATE_PAGES, vcpu); } =20 - if (nested_cpu_has_posted_intr(vmcs12)) - atomic_or(KVM_NESTED_PI_ACTIVE | vmcs12->posted_intr_nv, - &vcpu->arch.nested_guest_state); /* * Re-evaluate pending events if L1 had a pending IRQ/NMI/INIT/SIPI * when it executed VMLAUNCH/VMRESUME, as entering non-root mode can @@ -4024,22 +4038,15 @@ static void vmcs12_save_pending_event(struct kvm_vc= pu *vcpu, } } =20 -static int vmx_complete_nested_posted_interrupt(struct kvm_vcpu *vcpu) +static int __vmx_complete_nested_posted_interrupt(struct kvm_vcpu *vcpu) { struct vcpu_vmx *vmx =3D to_vmx(vcpu); int max_irr; void *vapic_page; u16 status; =20 - int nested_state =3D atomic_read(&vcpu->arch.nested_guest_state); - - if (!(nested_state & KVM_NESTED_PI_PENDING)) - return 0; - if (!vmx->nested.pi_desc) - goto mmio_needed; - - atomic_andnot(KVM_NESTED_PI_PENDING, &vcpu->arch.nested_guest_state); + return -ENXIO; =20 /* * Don't test the value of PID.ON. @@ -4056,7 +4063,7 @@ static int vmx_complete_nested_posted_interrupt(struc= t kvm_vcpu *vcpu) if (max_irr > 0) { vapic_page =3D vmx->nested.virtual_apic_map.hva; if (!vapic_page) - goto mmio_needed; + return -ENXIO; =20 __kvm_apic_update_irr(vmx->nested.pi_desc->pir, vapic_page, &max_irr); @@ -4071,10 +4078,22 @@ static int vmx_complete_nested_posted_interrupt(str= uct kvm_vcpu *vcpu) kvm_vcpu_map_mark_dirty(vcpu, &vmx->nested.virtual_apic_map); kvm_vcpu_map_mark_dirty(vcpu, &vmx->nested.pi_desc_map); return 0; +} + +static int vmx_complete_nested_posted_interrupt(struct kvm_vcpu *vcpu) +{ + int nested_state =3D atomic_read(&vcpu->arch.nested_guest_state); + int ret; =20 -mmio_needed: - kvm_handle_memory_failure(vcpu, X86EMUL_IO_NEEDED, NULL); - return -ENXIO; + if (!(nested_state & KVM_NESTED_PI_PENDING)) + return 0; + + atomic_andnot(KVM_NESTED_PI_PENDING, &vcpu->arch.nested_guest_state); + + ret =3D __vmx_complete_nested_posted_interrupt(vcpu); + if (ret =3D=3D -ENXIO) + kvm_handle_memory_failure(vcpu, X86EMUL_IO_NEEDED, NULL); + return ret; } =20 static void nested_vmx_inject_exception_vmexit(struct kvm_vcpu *vcpu) @@ -5089,6 +5108,7 @@ void __nested_vmx_vmexit(struct kvm_vcpu *vcpu, u32 v= m_exit_reason, { struct vcpu_vmx *vmx =3D to_vmx(vcpu); struct vmcs12 *vmcs12 =3D get_vmcs12(vcpu); + int old_nested_state; =20 /* Pending MTF traps are discarded on VM-Exit. */ vmx->nested.mtf_pending =3D false; @@ -5120,7 +5140,10 @@ void __nested_vmx_vmexit(struct kvm_vcpu *vcpu, u32 = vm_exit_reason, if (enable_ept && is_pae_paging(vcpu)) vmx_ept_load_pdptrs(vcpu); =20 - leave_guest_mode(vcpu); + old_nested_state =3D leave_guest_mode(vcpu); + + if (old_nested_state & KVM_NESTED_PI_PENDING) + __vmx_complete_nested_posted_interrupt(vcpu); =20 if (nested_cpu_has_preemption_timer(vmcs12)) hrtimer_cancel(&to_vmx(vcpu)->nested.preemption_timer); diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index e6dd37a3ac44..4a5adb1507ce 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -4370,41 +4370,41 @@ void vmx_recalc_intercepts(struct kvm_vcpu *vcpu) static int vmx_deliver_nested_posted_interrupt(struct kvm_vcpu *vcpu, int vector) { - int nested_state =3D atomic_read(&vcpu->arch.nested_guest_state); + int old =3D atomic_read(&vcpu->arch.nested_guest_state); + + while (true) { + if ((old & (KVM_NESTED_PI_ACTIVE | KVM_NESTED_PI_VECTOR_MASK)) !=3D + (KVM_NESTED_PI_ACTIVE | vector)) + return -1; + + WARN_ON_ONCE(!(old & KVM_NESTED_IN_GUEST)); + + if (atomic_try_cmpxchg(&vcpu->arch.nested_guest_state, + &old, old | KVM_NESTED_PI_PENDING)) + break; + } =20 /* - * DO NOT query the vCPU's vmcs12, as vmcs12 is dynamically allocated - * and freed, and must not be accessed outside of vcpu->mutex. The - * vCPU's cached PI NV is valid if and only if posted interrupts - * enabled in its vmcs12, i.e. checking the vector also checks that - * L1 has enabled posted interrupts for L2. + * If a posted intr is not recognized by hardware, + * we will accomplish it in the next vmentry. */ - if (is_guest_mode(vcpu) && - vector =3D=3D (nested_state & KVM_NESTED_PI_VECTOR_MASK)) { - /* - * If a posted intr is not recognized by hardware, - * we will accomplish it in the next vmentry. - */ - atomic_or(KVM_NESTED_PI_PENDING, &vcpu->arch.nested_guest_state); - kvm_make_request(KVM_REQ_EVENT, vcpu); + kvm_make_request(KVM_REQ_EVENT, vcpu); =20 - /* - * This pairs with the smp_mb_*() after setting vcpu->mode in - * vcpu_enter_guest() to guarantee the vCPU sees the event - * request if triggering a posted interrupt "fails" because - * vcpu->mode !=3D IN_GUEST_MODE. The extra barrier is needed as - * the smb_wmb() in kvm_make_request() only ensures everything - * done before making the request is visible when the request - * is visible, it doesn't ensure ordering between the store to - * vcpu->requests and the load from vcpu->mode. - */ - smp_mb__after_atomic(); + /* + * This pairs with the smp_mb_*() after setting vcpu->mode in + * vcpu_enter_guest() to guarantee the vCPU sees the event + * request if triggering a posted interrupt "fails" because + * vcpu->mode !=3D IN_GUEST_MODE. The extra barrier is needed as + * the smb_wmb() in kvm_make_request() only ensures everything + * done before making the request is visible when the request + * is visible, it doesn't ensure ordering between the store to + * vcpu->requests and the load from vcpu->mode. + */ + smp_mb__after_atomic(); =20 - /* the PIR and ON have been set by L1. */ - kvm_vcpu_trigger_posted_interrupt(vcpu, POSTED_INTR_NESTED_VECTOR); - return 0; - } - return -1; + /* the PIR and ON have been set by L1. */ + kvm_vcpu_trigger_posted_interrupt(vcpu, POSTED_INTR_NESTED_VECTOR); + return 0; } /* * Send interrupt to vcpu via posted interrupt way. --=20 2.56.1