All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Oliver Upton <oliver.upton@linux.dev>
Cc: kvmarm@lists.linux.dev, Marc Zyngier <maz@kernel.org>,
	Joey Gouly <joey.gouly@arm.com>,
	 Suzuki K Poulose <suzuki.poulose@arm.com>,
	Zenghui Yu <yuzenghui@huawei.com>
Subject: Re: [PATCH v2 1/4] KVM: arm64: nv: Keep reference on stage-2 MMU when scheduled out
Date: Mon, 7 Oct 2024 12:52:48 -0700	[thread overview]
Message-ID: <ZwQ8EMcZYtUb6wk_@google.com> (raw)
In-Reply-To: <ZwQwCqR11wlADRUA@linux.dev>

On Mon, Oct 07, 2024, Oliver Upton wrote:
> On Mon, Oct 07, 2024 at 11:39:37AM -0700, Sean Christopherson wrote:
> > > @@ -674,10 +681,18 @@ void kvm_vcpu_load_hw_mmu(struct kvm_vcpu *vcpu)
> > >  
> > >  void kvm_vcpu_put_hw_mmu(struct kvm_vcpu *vcpu)
> > >  {
> > > -	if (kvm_is_nested_s2_mmu(vcpu->kvm, vcpu->arch.hw_mmu)) {
> > > +	/*
> > > +	 * Keep a reference on the associated stage-2 MMU if the vCPU is
> > > +	 * scheduling out and not in WFI emulation, suggesting it is likely to
> > > +	 * reuse the MMU sometime soon.
> > > +	 */
> > > +	if (vcpu->scheduled_out && !vcpu_get_flag(vcpu, IN_WFI))
> > > +		return;
> > 
> > Assuming KVM arm64 supports halt-polling, I think it makes more sense to check
> > kvm_vcpu_is_blocking() instead of IN_WFI.  That way, KVM will keep the MMU resident
> > if the vCPU happens to be preempted and halt-polling is successful.
> > 
> > And somewhat of a side topic, calling kvm_vgic_put() from kvm_arch_vcpu_blocking()
> > instead of kvm_vcpu_wfi() would provide the same optimization for the GIC, as KVM
> > would only need to put/reload the vGIC if the vCPU is actually scheduled out.
> 
> That wouldn't be an optimization, it'd render the halt polling loop
> useless.
> 
> The most recent view of the guest's CPU interface is sitting in
> hardware at this point, so we need to synchronize KVM's view of
> the CPUIF with it to determine if a pending interrupt exceeds the
> priority mask.

Hmm, but what happens if the wakeup event arrives before IN_WFI is set?  Ah, IIUC,
GICR_VPENDBASER_PendingLast tracks if there's a pending event, KVM makes sure to
read PendingLast after making vPE non-resident, and hardware is required to ensure
either PendingLast=1 or a doorbell is signaled.

Niave question time: why not query GICR_VPENDBASER_PendingLast directly in
kvm_vgic_vcpu_pending_irq() instead of putting the vGIC?  E.g. if safely querying
PendingLast is "heavy", wouldn't it still make sense to do a slow check of
PendingLast in kvm_vgic_vcpu_pending_irq() if IN_WFI=1?  Or is putting the vGIC
as lightweight as things get when it comes to checking PendingLast?

> On top of that, we need to activate the doorbell IRQ for GICv4 to give
> KVM a kick when something arrives for the vPE.

Right, but KVM needs to "manually" detect pending events to account for events
that arrive before the doorbell is activated, so from a functional perspective,
it shouldn't matter when KVM activates the doorbell (with respect to halt-polling).

  reply	other threads:[~2024-10-07 19:52 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-07 16:42 [PATCH v2 0/4] KVM: arm64: nv: Fixes for stage-2 MMU recycling Oliver Upton
2024-10-07 16:42 ` [PATCH v2 1/4] KVM: arm64: nv: Keep reference on stage-2 MMU when scheduled out Oliver Upton
2024-10-07 18:39   ` Sean Christopherson
2024-10-07 19:01     ` Oliver Upton
2024-10-07 19:52       ` Sean Christopherson [this message]
2024-10-07 21:22         ` Oliver Upton
2024-10-07 22:18           ` Sean Christopherson
2024-10-07 16:42 ` [PATCH v2 2/4] KVM: arm64: nv: Do not block when unmapping stage-2 if disallowed Oliver Upton
2024-10-07 16:42 ` [PATCH v2 3/4] KVM: arm64: nv: Punt stage-2 recycling to a vCPU request Oliver Upton
2024-10-07 19:06   ` Marc Zyngier
2024-10-07 19:16     ` Oliver Upton
2024-10-07 16:42 ` [PATCH v2 4/4] KVM: arm64: nv: Clarify safety of allowing TLBI unmaps to reschedule Oliver Upton
2024-10-07 18:51   ` Sean Christopherson
2024-10-07 19:20     ` Oliver Upton

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=ZwQ8EMcZYtUb6wk_@google.com \
    --to=seanjc@google.com \
    --cc=joey.gouly@arm.com \
    --cc=kvmarm@lists.linux.dev \
    --cc=maz@kernel.org \
    --cc=oliver.upton@linux.dev \
    --cc=suzuki.poulose@arm.com \
    --cc=yuzenghui@huawei.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 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.