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 v3 5/5] KVM: x86: nVMX: fix races in delivery of nested posted interrupts
Date: Mon, 23 Nov 2026 18:19:11 +0000	[thread overview]
Message-ID: <sashiko-outbox-229799@kernel.org> (raw)
In-Reply-To: <20261123175512.80438-6-mlevitsk@redhat.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] KVM: nVMX: unhandled error and unmapped state in
  __nested_vmx_vmexit() PI completion
--

commit daa28df8cd412bbb1c1a76b22827fb7d30241474
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-Exit using atomic operations on vcpu->arch.nested_guest_state and
processes pending nested posted interrupts in __nested_vmx_vmexit().

> diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
> index 61f50175ecb79..845825c018bf5 100644
> --- a/arch/x86/kvm/vmx/nested.c
> +++ b/arch/x86/kvm/vmx/nested.c
[ ... ]
> @@ -5122,7 +5128,13 @@ void __nested_vmx_vmexit(struct kvm_vcpu *vcpu, u32 vm_exit_reason,
>  	if (enable_ept && is_pae_paging(vcpu))
>  		vmx_ept_load_pdptrs(vcpu);
>  
> -	leave_guest_mode(vcpu);
> +	old_nested_state = leave_guest_mode(vcpu);
> +
> +	/* pairs with implicit memory barrier in vmx_deliver_nested_posted_interrupt */
> +	smp_mb__after_atomic();
> +
> +	if (old_nested_state & KVM_NESTED_PI_PENDING)
> +		__vmx_complete_nested_posted_interrupt(vcpu);
>  
>  	if (nested_cpu_has_preemption_timer(vmcs12))
>  		hrtimer_cancel(&to_vmx(vcpu)->nested.preemption_timer);

[Severity: High]
What happens when __vmx_complete_nested_posted_interrupt() fails or runs
before vmcs12 pages are mapped?

If L1 configures an unbacked or MMIO GPA for posted_intr_desc_addr or
virtual_apic_page_addr, vmx->nested.pi_desc or virtual_apic_map.hva is NULL.
__vmx_complete_nested_posted_interrupt() then calls
kvm_handle_memory_failure(), setting vcpu->run->exit_reason to
KVM_EXIT_INTERNAL_ERROR and returning -ENXIO.  Because __nested_vmx_vmexit()
ignores the return value, callers such as nested_vmx_reflect_vmexit() and
vmx_check_nested_events() continue running L1 in-kernel instead of exiting
to userspace, while non-KVM_RUN callers via vmx_leave_nested() clobber
vcpu->run->exit_reason.

In addition, when entering L2 with from_vmentry == false (KVM_SET_NESTED_STATE
or RSM), nested_vmx_enter_non_root_mode() defers nested_get_vmcs12_pages()
via KVM_REQ_GET_NESTED_STATE_PAGES while publishing KVM_NESTED_PI_ACTIVE in
vcpu->arch.nested_guest_state.  If a nested posted interrupt arrives and an
L2->L1 exit happens before the first L2 entry, __nested_vmx_vmexit() clears
KVM_REQ_GET_NESTED_STATE_PAGES without mapping pi_desc, so
__vmx_complete_nested_posted_interrupt() drops the interrupt and triggers a
spurious KVM_EXIT_INTERNAL_ERROR.

Finally, running __vmx_complete_nested_posted_interrupt() when vmx->fail is
true clears pi_desc->on and writes max_irr into vmcs02 GUEST_INTR_STATUS,
which is then lost because sync_vmcs02_to_vmcs12() is skipped on vmx->fail.

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

  reply	other threads:[~2026-11-23 18:19 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23 17:55 [PATCH v3 0/5] KVM: nVMX: fix nested APICv emulation for windows guests Maxim Levitsky
2026-11-23 17:55 ` [PATCH v3 1/5] KVM: nVMX: don't check PIR.ON when processing nested posted interrupts Maxim Levitsky
2026-11-23 18:02   ` sashiko-bot
2026-11-24 17:31     ` mlevitsk
2026-11-23 17:55 ` [PATCH v3 2/5] KVM: x86: split vcpu->arch.hflags into nested_guest_mode and smm_mode Maxim Levitsky
2026-11-23 18:03   ` sashiko-bot
2026-11-24 17:32     ` mlevitsk
2026-11-24  2:59   ` kernel test robot
2026-11-23 17:55 ` [PATCH v3 3/5] KVM: x86: convert nested_guest_state into an atomic variable Maxim Levitsky
2026-11-23 17:55 ` [PATCH v3 4/5] KVM: x86: nVMX: move nested APICv state to nested_guest_state Maxim Levitsky
2026-11-23 17:55 ` [PATCH v3 5/5] KVM: x86: nVMX: fix races in delivery of nested posted interrupts Maxim Levitsky
2026-11-23 18:19   ` sashiko-bot [this message]
2026-11-24 18:00     ` mlevitsk

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-229799@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.