From: sashiko-bot@kernel.org
To: "Jia He" <justin.he@arm.com>
Cc: kvmarm@lists.linux.dev, linux-rt-devel@lists.linux.dev,
"Oliver Upton" <oupton@kernel.org>,
"Marc Zyngier" <maz@kernel.org>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] KVM: arm64: gic-v5: Don't move the vPE doorbell from kvm_sched_out()
Date: Mon, 16 Nov 2026 08:07:18 +0000 [thread overview]
Message-ID: <sashiko-outbox-216506@kernel.org> (raw)
In-Reply-To: <20261116071304.2037895-3-justin.he@arm.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] KVM: arm64: gic-v5: vgic_v5_load() in WFI disarms doorbells
and loses wakeups
--
commit 36844cdbda4df2b177b6c013c2074287d75ff5f3
Author: Jia He <justin.he@arm.com>
KVM: arm64: gic-v5: Don't move the vPE doorbell from kvm_sched_out()
This commit skips calling irq_set_affinity() in vgic_v5_put() when
vcpu->scheduled_out is set, avoiding acquiring irq_desc and pi_lock under the
runqueue lock during kvm_sched_out().
> diff --git a/arch/arm64/kvm/vgic/vgic-v5.c b/arch/arm64/kvm/vgic/vgic-v5.c
> index 91810fbd99afa..5824b00bb50df 100644
> --- a/arch/arm64/kvm/vgic/vgic-v5.c
> +++ b/arch/arm64/kvm/vgic/vgic-v5.c
> @@ -1248,8 +1248,14 @@ void vgic_v5_put(struct kvm_vcpu *vcpu)
> * Make the doorbell affine to this CPU, if it isn't
> * already. Actively check the cpumask first as it is
> * cheaper than changing the affinity every time.
> + *
> + * Don't do it from kvm_sched_out(), which holds the
> + * runqueue lock: irq_set_affinity() takes the
> + * doorbell's irq_desc lock and may wake its irq
> + * thread. The doorbell works from any CPU, and the
> + * next WFI entry moves it.
> */
> - if (!cpumask_test_cpu(cpu, aff)) {
> + if (!vcpu->scheduled_out && !cpumask_test_cpu(cpu, aff)) {
> int ret;
>
> ret = irq_set_affinity(db_irq, cpumask_of(cpu));
[Severity: Medium]
Should vgic_v5_load() bail out when IN_WFI is set instead of only skipping
irq_set_affinity() here?
Because vgic_v5_load() does not check vcpu_get_flag(vcpu, IN_WFI), any
kvm_sched_in() while the vCPU is halting in kvm_vcpu_halt() calls
__vgic_v5_make_resident(), setting gicv5_vpe.resident = true and clearing
ICH_CONTEXTR_EL2_DB in hardware.
If the vPE doorbell fires while blocked in kvm_vcpu_block(), db_handler()
sets gicv5_vpe.db_fired = true and wakes the vCPU thread. When the thread
schedules in, vgic_v5_load() makes the vPE resident before schedule() returns
to the loop in kvm_vcpu_block(). If the vCPU thread is preempted again before
kvm_vcpu_check_block() consumes db_fired, kvm_sched_out() -> vgic_v5_put()
still calls __vgic_v5_make_non_resident():
arch/arm64/kvm/hyp/vgic-v5-sr.c:__vgic_v5_make_non_resident() {
...
WRITE_ONCE(cpu_if->gicv5_vpe.db_fired, false);
cpu_if->gicv5_vpe.resident = false;
}
When the thread schedules back in, kvm_vcpu_check_block() ->
kvm_vgic_vcpu_pending_irq() sees db_fired == false and goes back to sleep in
schedule(), losing the wakeup.
Making the vPE resident on schedule-in during halt-polling also disarms the
hardware doorbell for the rest of the poll window, so newly pending SPIs and
LPIs do not set db_fired, and a subsequent kvm_sched_out() still runs the EL2
residency hypercalls and vgic_v5_sync_ppi_priorities() under the runqueue
lock. Returning early from vgic_v5_load() when IN_WFI is set keeps
gicv5_vpe.resident false throughout kvm_vcpu_halt(), so kvm_sched_out()
returns immediately in vgic_v5_put().
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261116071304.2037895-1-justin.he@arm.com?part=2
next prev parent reply other threads:[~2026-11-16 8:07 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 7:13 [PATCH 0/2] KVM: arm64: gic-v5: Fix irq_desc locks taken under the runqueue lock Jia He
2026-11-16 7:13 ` [PATCH 1/2] KVM: arm64: Give the host timer interrupts a separate lockdep class Jia He
2026-11-16 7:13 ` [PATCH 2/2] KVM: arm64: gic-v5: Don't move the vPE doorbell from kvm_sched_out() Jia He
2026-11-16 8:07 ` sashiko-bot [this message]
2026-11-16 9:37 ` Justin He
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-216506@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=justin.he@arm.com \
--cc=kvmarm@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rt-devel@lists.linux.dev \
--cc=maz@kernel.org \
--cc=oupton@kernel.org \
--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.