From: "mlevitsk@redhat.com" <mlevitsk@redhat.com>
To: kvm@vger.kernel.org
Cc: x86@kernel.org, Sean Christopherson <seanjc@google.com>,
Paolo Bonzini <pbonzini@redhat.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] KVM: nVMX: avoid losing the posted notification interrupt when exiting L2
Date: Sat, 10 Oct 2026 13:00:55 -0400 [thread overview]
Message-ID: <898b1b8ba85284a4f4094ce0453ea59d094c1c3b.camel@redhat.com> (raw)
In-Reply-To: <20261009205036.672523-3-mlevitsk@redhat.com>
On Fri, 2026-10-09 at 16:50 -0400, Maxim Levitsky wrote:
> While delivering a nested posted interrupt notification
> (see vmx_deliver_nested_posted_interrupt), KVM assumes that,
> as long as the target vCPU is in the guest mode, KVM can send the
> special POSTED_INTR_NESTED_VECTOR, which will either trigger APICv ucode
> to inject all interrupts into L2 or cause a VM exit, after which
> vmx_complete_nested_posted_interrupt is supposed to finish the job.
>
> However, a third case is possible: if the target vCPU is about to exit
> to L1, the posted notification interrupt must be instead injected
> to L1' APIC, but KVM doesn't do this.
>
> Detect this case in the nested VM exit path and act accordingly.
>
> Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
> ---
> arch/x86/kvm/vmx/nested.c | 10 +++++++++-
> 1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
> index 2142e25c9b6c..4d8bb7f7fcd4 100644
> --- a/arch/x86/kvm/vmx/nested.c
> +++ b/arch/x86/kvm/vmx/nested.c
> @@ -2445,7 +2445,7 @@ static void prepare_vmcs02_early(struct vcpu_vmx *vmx, struct loaded_vmcs *vmcs0
> ~PIN_BASED_VMX_PREEMPTION_TIMER);
>
> /* Posted interrupts setting is only taken from vmcs12. */
> - vmx->nested.pi_pending = false;
> + WARN_ON_ONCE(vmx->nested.pi_pending);
> if (nested_cpu_has_posted_intr(vmcs12)) {
> vmx->nested.posted_intr_nv = vmcs12->posted_intr_nv;
> } else {
> @@ -5162,6 +5162,14 @@ void __nested_vmx_vmexit(struct kvm_vcpu *vcpu, u32 vm_exit_reason,
> kvm_clear_exception_queue(vcpu);
> kvm_clear_interrupt_queue(vcpu);
>
> + if (lapic_in_kernel(vcpu) && vmx->nested.pi_pending) {
> + vmx->nested.pi_pending = 0;
> + if (!WARN_ON_ONCE(vmx->nested.posted_intr_nv == -1)) {
> + kvm_lapic_set_irr(vmx->nested.posted_intr_nv, vcpu->arch.apic);
> + kvm_make_request(KVM_REQ_EVENT, vcpu);
> + }
> + }
> +
Hi!
After giving this a bit more of thought, I see that this will introduce spurious interrupts to L1,
if the posted interrupt was actually served by APICv.
ON can't be trusted, so I only can add scan of PIR here to reduce chances of this happening, but I am not sure
that this can be completely avoided.
I think that a spurious interrupt is better though that no interrupt because the guest can depend on it, and might
not even enter the L2, until it receives this posted interrupt.
What do you think?
Best regards,
Maxim Levitsky
> vmx_switch_vmcs(vcpu, &vmx->vmcs01);
>
> kvm_nested_vmexit_handle_ibrs(vcpu);
prev parent reply other threads:[~2026-10-10 17:01 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-09 20:50 [PATCH 0/2] KVM: nVMX: fix nested APICv emulation for windows guests Maxim Levitsky
2026-10-09 20:50 ` [PATCH 1/2] KVM: nVMX: don't check PIR.ON when processing nested posted interrupts Maxim Levitsky
2026-10-09 20:50 ` [PATCH 2/2] KVM: nVMX: avoid losing the posted notification interrupt when exiting L2 Maxim Levitsky
2026-10-10 13:21 ` kernel test robot
2026-10-10 17:00 ` mlevitsk [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=898b1b8ba85284a4f4094ce0453ea59d094c1c3b.camel@redhat.com \
--to=mlevitsk@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=x86@kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®