From: Marc Zyngier <maz@kernel.org>
To: Fuad Tabba <fuad.tabba@linux.dev>
Cc: Oliver Upton <oupton@kernel.org>, Joey Gouly <joey.gouly@arm.com>,
Steffen Eiden <seiden@linux.ibm.com>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Zenghui Yu <yuzenghui@huawei.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Andre Przywara <andre.przywara@arm.com>,
linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 0/2] KVM: arm64: vgic-its: Fix LPI double mapping and DISCARD
Date: Tue, 13 Oct 2026 14:25:09 +0100 [thread overview]
Message-ID: <86tsmp20ne.wl-maz@kernel.org> (raw)
In-Reply-To: <CA+EHjTyZA6VL6EjhkB2bf9fDk4fUWpc=iXsu+sR1B+_YbR-nOQ@mail.gmail.com>
On Tue, 13 Oct 2026 13:59:22 +0100,
Fuad Tabba <fuad.tabba@linux.dev> wrote:
>
> Hi Marc,
>
> On Tue, 13 Oct 2026 12:16:09 +0100, Marc Zyngier <maz@kernel.org> wrote:
> [...]
> > > A vCPU on its way into the guest does the same: it loads its LRs in
> > > kvm_vgic_flush_hwstate() while it's still OUTSIDE_GUEST_MODE, so
> > > kvm_arm_halt_guest() doesn't wait for it. With the delay after the
> > > flush instead, on v2 plus your 1/7 and 2/7 [2] and both changes from
> > > your reply to 1/7 [3], the guest takes it in 9 of 20 runs.
> >
> > Does this mean we still need OUTSIDE_GUEST_MODE to be a store-release
> > past the point where we resync the state?
>
> Not for the 9 of 20: that run already had the release. The halt reads
> the OUTSIDE_GUEST_MODE the vCPU published at its previous exit, so it
> doesn't wait for the early exit that folds the LPI back.
>
> We do still need it for the window after the exit: with the delay
> there and the same patches applied, the guest takes it in none of 20
> runs, against 13 of 20 on v2.
I don't understand what these probabilities represent. Either it works
or it doesn't. And given that I have no idea what you are testing
with, I can't really make head or tail of the above.
>
> > > Once DISCARD waits for irq->on_lr to clear before clearing
> > > pending_latch, the guest takes it in none of 20 runs in either case.
> > > I'll add that to v3, unless the single-vcpu stunning already waits for
> > > it.
> >
> > Polling for on_lr feels very dodgy, and I'd like to avoid this. If the
> > OUTSIDE_GUEST release addresses it, I'd rather do that.
>
> I'd rather avoid the polling too, but the release alone doesn't close
> this one. The vCPU would also need to store IN_GUEST_MODE and check
> its requests before kvm_vgic_flush_hwstate(), so that it never loads
> its LRs while it's OUTSIDE_GUEST_MODE. The existing check after the
> flush would still be needed, for the KVM_REQ_GUEST_HYP_IRQ_PENDING
> request kvm_vgic_flush_hwstate() makes in a nested state. With that
> and the release, the guest takes it in none of 20 runs with the delay
> after the flush, and herd7 finds no LKMM execution that leaves it
> pending.
If you have a herd litmus test, how about posting it? It would really
avoid a lot of that back and forth where the S/N ratio is pretty poor.
> The IN_GUEST_MODE change would also cover vgic_mmio_change_active(),
> which depends on the same halt (the comment above
> vgic_access_active_prepare()). Would you be OK folding it into your
> series, on top of your OUTSIDE_GUEST_MODE changes? Patch 2 then
> wouldn't need the on_lr wait.
Is the hack below what you are asking for? I can't tell. If it isn't,
please post your own version.
Thanks,
M.
diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
index 0576c2022ef57..f1449b08531eb 100644
--- a/arch/arm64/kvm/arm.c
+++ b/arch/arm64/kvm/arm.c
@@ -1321,10 +1321,6 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
local_irq_disable();
- kvm_vgic_flush_hwstate(vcpu);
-
- kvm_pmu_update_vcpu_events(vcpu);
-
/*
* Ensure we set mode to IN_GUEST_MODE after we disable
* interrupts and before the final VCPU requests check.
@@ -1333,14 +1329,18 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
*/
smp_store_mb(vcpu->mode, IN_GUEST_MODE);
+ kvm_vgic_flush_hwstate(vcpu);
+
+ kvm_pmu_update_vcpu_events(vcpu);
+
if (ret <= 0 || kvm_vcpu_exit_request(vcpu, &ret)) {
- vcpu->mode = OUTSIDE_GUEST_MODE;
isb(); /* Ensure work in x_flush_hwstate is committed */
if (kvm_vcpu_has_pmu(vcpu))
kvm_pmu_sync_hwstate(vcpu);
if (unlikely(!irqchip_in_kernel(vcpu->kvm)))
kvm_timer_sync_user(vcpu);
kvm_vgic_sync_hwstate(vcpu);
+ smp_store_release(&vcpu->mode, OUTSIDE_GUEST_MODE);
local_irq_enable();
preempt_enable();
continue;
@@ -1356,7 +1356,6 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
ret = kvm_arm_vcpu_enter_exit(vcpu);
- vcpu->mode = OUTSIDE_GUEST_MODE;
vcpu->stat.exits++;
/*
* Back from guest
@@ -1390,6 +1389,12 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
kvm_arch_vcpu_ctxsync_fp(vcpu);
+ /*
+ * All the state has been synchronised, let advertise
+ * we're outside of the guest.
+ */
+ smp_store_release(&vcpu->mode, OUTSIDE_GUEST_MODE);
+
/*
* We must ensure that any pending interrupts are taken before
* we exit guest timing so that timer ticks are accounted as
--
Without deviation from the norm, progress is not possible.
next prev parent reply other threads:[~2026-10-13 13:25 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-13 8:16 [PATCH v2 0/2] KVM: arm64: vgic-its: Fix LPI double mapping and DISCARD Fuad Tabba
2026-10-13 8:16 ` [PATCH v2 1/2] KVM: arm64: vgic-its: Don't map an LPI from more than one event Fuad Tabba
2026-10-13 8:16 ` [PATCH v2 2/2] KVM: arm64: vgic-its: Remove the pending state of a discarded LPI Fuad Tabba
2026-10-13 9:51 ` [PATCH v2 0/2] KVM: arm64: vgic-its: Fix LPI double mapping and DISCARD Oliver Upton
2026-10-13 10:01 ` Marc Zyngier
2026-10-13 10:50 ` Fuad Tabba
2026-10-13 11:16 ` Marc Zyngier
2026-10-13 12:59 ` Fuad Tabba
2026-10-13 13:25 ` Marc Zyngier [this message]
2026-10-13 14:33 ` Fuad Tabba
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=86tsmp20ne.wl-maz@kernel.org \
--to=maz@kernel.org \
--cc=andre.przywara@arm.com \
--cc=catalin.marinas@arm.com \
--cc=fuad.tabba@linux.dev \
--cc=joey.gouly@arm.com \
--cc=kvmarm@lists.linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=oupton@kernel.org \
--cc=seiden@linux.ibm.com \
--cc=suzuki.poulose@arm.com \
--cc=will@kernel.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox