mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Huang, Kai" <kai.huang@intel.com>
To: "seanjc@google.com" <seanjc@google.com>
Cc: "kvm@vger.kernel.org" <kvm@vger.kernel.org>,
	"pbonzini@redhat.com" <pbonzini@redhat.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] KVM: x86: Ignore pending PV EOI if the vCPU has since disabled PV EOIs
Date: Mon, 29 Jun 2026 11:23:20 +0000	[thread overview]
Message-ID: <3c0f96a316a968e5e0301f355bc05962c4b975ad.camel@intel.com> (raw)
In-Reply-To: <aj66ZyxVdLjF_0dc@google.com>

On Fri, 2026-06-26 at 10:44 -0700, Sean Christopherson wrote:
> On Thu, Jun 25, 2026, Kai Huang wrote:
> > On Thu, 2026-06-25 at 08:33 -0700, Sean Christopherson wrote:
> > > On Thu, Jun 25, 2026, Kai Huang wrote:
> > > > On Wed, 2026-06-24 at 15:05 -0700, Sean Christopherson wrote:
> > I was kinda thinking whether it's possible that there are two IRQs when
> > vCPU.pv_eoi is active (e.g., one in IRR and one in ISR, with different vector),
> > but from the code right it's not possible:
> > 
> >         if (!pv_eoi_enabled(vcpu) ||                                           
> >             /* IRR set or many bits in ISR: could be nested. */
> >             apic->irr_pending ||
> > 	    ...)) {
> > 		return;
> > 	}
> > 	pv_eoi_set_pending(apic->vcpu);
> > 
> > The reason behind this still eludes me :-(
> 
> The PV EOI stuff is all about eliding the EOIs in the guest in order to avoid
> relatively useless VM-Exits (this pre-dates hardware virtualization of EOIs).
> 
> Instead of having the guest explicitly do EOI, KVM sets two flags: one to note
> to itself that there is/was a pending PV EOI, and another that's shared with the
> vCPU to track whether or not the guest ack'd the pending PV EOI.  On the next
> VM-Exit, KVM checks its internal pending PV EOI flag, and then does an actual
> EOI on behalf of the guest if the shared bit was cleared, i.e. if the PV EOI was
> ack'd by the guest.

Yeah.

> 
> The irr_pending check above effectively disables PV EOI, because PV EOI only has
> a single bit, i.e. can only track a single IRQ, 
> 

Right.

> and because KVM needs to know
> precisely when the pending IRQ is unblocked, i.e. can't lazily wait until the
> next VM-Exit.

Thus KVM needs to make sure guest will actually write EOI to APIC (thus PV EOI
must be disabled)?

> 
> > The CPU cannot execute another vector in ISR until the highest one is EOI-ed,
> > right?
> 
> Nope.  The rules for delivery, i.e. for moving an IRQ from IRR => ISR, are that
> the IRQ's priority must be higher than PPR, the exact IRQ isn't in-progress (i.e.
> its ISR bit isn't set), and that IRQs aren't generally blocked by the core/CPU.
> 
> From "12.8.4 Interrupt Acceptance for Fixed Interrupts"
> 
>   If the local APIC receives an interrupt with an interrupt-priority class higher
>   than that of the interrupt currently in service, and interrupts are enabled in
>   the processor core, the local APIC dispatches the higher priority interrupt to
>   the processor immediately (without waiting for a write to the EOI register).

Ah I see.  I should have checked this more carefully :-)

Thanks for all the info!

  reply	other threads:[~2026-06-29 11:27 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-24 22:05 Sean Christopherson
2026-06-25  7:30 ` Huang, Kai
2026-06-25 15:33   ` Sean Christopherson
2026-06-25 23:44     ` Huang, Kai
2026-06-26 17:44       ` Sean Christopherson
2026-06-29 11:23         ` Huang, Kai [this message]
2026-06-29 12:51           ` Sean Christopherson
2026-06-29 13:03           ` Sean Christopherson
2026-07-14 18:41 ` Sean Christopherson

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=3c0f96a316a968e5e0301f355bc05962c4b975ad.camel@intel.com \
    --to=kai.huang@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    /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

powered by JetHome