All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Maxim Levitsky" <mlevitsk@redhat.com>, kvm@vger.kernel.org
Subject: Re: [PATCH v5 5/5] KVM: x86: nVMX: fix races in delivery of nested posted interrupts
Date: Wed, 25 Nov 2026 16:50:29 +0000	[thread overview]
Message-ID: <sashiko-outbox-233779@kernel.org> (raw)
In-Reply-To: <20261125155819.408795-6-mlevitsk@redhat.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] KVM: nVMX: delayed KVM_NESTED_PI_ACTIVE misdelivers PI to
  halted/restored L2
--

commit 1837fd79b0a3f7ab8c9981e92e02daa94e796f28
Author: Maxim Levitsky <mlevitsk@redhat.com>

KVM: x86: nVMX: fix races in delivery of nested posted interrupts

This commit synchronizes nested posted interrupt delivery with nested VM
exits using atomic operations on vcpu->arch.nested_guest_state and delays
enabling nested posted interrupts until KVM_REQ_GET_NESTED_STATE_PAGES is
processed when entering non-root mode outside of a VM-Entry.

> diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
> index eb33528619c2f..d2f092fa076a6 100644
> --- a/arch/x86/kvm/vmx/nested.c
> +++ b/arch/x86/kvm/vmx/nested.c
[ ... ]
> @@ -3701,6 +3715,9 @@ enum nvmx_vmentry_status nested_vmx_enter_non_root_mode(struct kvm_vcpu *vcpu,
>  			vmcs12->exit_qualification = 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
> @@ -3712,9 +3729,6 @@ enum nvmx_vmentry_status nested_vmx_enter_non_root_mode(struct kvm_vcpu *vcpu,
>  		kvm_make_request(KVM_REQ_GET_NESTED_STATE_PAGES, vcpu);
>  	}
>  
> -	if (nested_cpu_has_posted_intr(vmcs12))
> -		atomic_or(KVM_NESTED_PI_ACTIVE | vmcs12->posted_intr_nv,
> -			  &vcpu->arch.nested_guest_state);

[Severity: High]
Does deferring nested_vmx_enable_posted_interrupts() until
KVM_REQ_GET_NESTED_STATE_PAGES cause nested posted interrupts to be
misdelivered as L1 external-interrupt VM-Exits when an L2 vCPU is restored
in a halted state?

When nested_vmx_enter_non_root_mode() runs with from_vmentry == false
(such as during KVM_SET_NESTED_STATE), KVM_NESTED_PI_ACTIVE remains clear
until vcpu_enter_guest() processes KVM_REQ_GET_NESTED_STATE_PAGES.  If the
restored L2 vCPU is in KVM_MP_STATE_HALTED, vcpu_run() enters vcpu_block()
instead of vcpu_enter_guest().

When a nested posted interrupt arrives to wake the halted L2 vCPU,
vmx_deliver_nested_posted_interrupt() sees KVM_NESTED_PI_ACTIVE == 0,
returns -1, and queues L2's posted_intr_nv into L1's LAPIC IRR.
vcpu_block() then calls kvm_check_nested_events() ->
vmx_check_nested_events() before KVM_REQ_GET_NESTED_STATE_PAGES is
serviced:

arch/x86/kvm/vmx/nested.c:vmx_check_nested_events() {
    ...
		if ((nested_state & KVM_NESTED_PI_ACTIVE) &&
			((nested_state & KVM_NESTED_PI_VECTOR_MASK) == irq)) {
			if (block_non_injected_events)
				return -EBUSY;

			atomic_or(KVM_NESTED_PI_PENDING, &vcpu->arch.nested_guest_state);

			kvm_apic_clear_irr(vcpu, irq);
			goto no_vmexit;
		}

		if (block_nested_events)
			return -EBUSY;

		nested_vmx_vmexit(vcpu, EXIT_REASON_EXTERNAL_INTERRUPT,
    ...
}

Because KVM_NESTED_PI_ACTIVE is still clear, vmx_check_nested_events()
does not recognize irq as L2's posted-interrupt notification vector and
injects an EXIT_REASON_EXTERNAL_INTERRUPT VM-Exit into L1 instead of
processing L2's posted interrupt descriptor.

Similarly, if the restored L2 vCPU is runnable and receives a nested
posted interrupt before vcpu_enter_guest() runs, the vector is placed in
L1's LAPIC IRR without setting KVM_NESTED_PI_PENDING, so any higher
priority nested VM-Exit (or a masked L1 PPR) causes __nested_vmx_vmexit()
to miss __vmx_complete_nested_posted_interrupt().

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261125155819.408795-1-mlevitsk@redhat.com?part=5

      reply	other threads:[~2026-11-25 16:50 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 15:58 [PATCH v5 0/5] KVM: nVMX: fix nested APICv emulation for windows guests Maxim Levitsky
2026-11-25 15:58 ` [PATCH v5 1/5] KVM: nVMX: don't check PID.ON when processing nested posted interrupts Maxim Levitsky
2026-11-25 15:58 ` [PATCH v5 2/5] KVM: x86: split vcpu->arch.hflags into nested_guest_state and smm_mode Maxim Levitsky
2026-11-25 15:58 ` [PATCH v5 3/5] KVM: x86: convert nested_guest_state into an atomic variable Maxim Levitsky
2026-11-25 15:58 ` [PATCH v5 4/5] KVM: x86: nVMX: move nested APICv state to nested_guest_state Maxim Levitsky
2026-11-25 15:58 ` [PATCH v5 5/5] KVM: x86: nVMX: fix races in delivery of nested posted interrupts Maxim Levitsky
2026-11-25 16:50   ` sashiko-bot [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-233779@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=mlevitsk@redhat.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.