mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jia He <justin.he@arm.com>
To: maz@kernel.org, oupton@kernel.org
Cc: fuad.tabba@linux.dev, joey.gouly@arm.com, seiden@linux.ibm.com,
	suzuki.poulose@arm.com, yuzenghui@huawei.com,
	bigeasy@linutronix.de, linux-arm-kernel@lists.infradead.org,
	kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org,
	linux-rt-devel@lists.linux.dev, Jia He <justin.he@arm.com>
Subject: [PATCH 2/2] KVM: arm64: gic-v5: Don't move the vPE doorbell from kvm_sched_out()
Date: Mon, 16 Nov 2026 07:13:04 +0000	[thread overview]
Message-ID: <20261116071304.2037895-3-justin.he@arm.com> (raw)
In-Reply-To: <20261116071304.2037895-1-justin.he@arm.com>

vgic_v5_put() makes the vPE doorbell affine to the current CPU when the
vcpu enters WFI. This is meant for the explicit put from kvm_vcpu_wfi(),
but the same code also runs from kvm_sched_out() whenever the vPE is
resident with IN_WFI set.

That happens when the vcpu thread is scheduled back in while halting:
unlike vgic_v4_load(), vgic_v5_load() does not bail out on IN_WFI and
makes the vPE resident again, so the next sched-out, from
kvm_vcpu_block() or from a preemption during halt polling, goes through
vgic_v5_put() with IN_WFI still set. If the thread moved to another
CPU in between, irq_set_affinity() is called with the runqueue lock
held:

  irq_set_affinity+0x38/0x88
  vgic_v5_put+0xf0/0x2b8
  kvm_vgic_put+0x64/0xb0
  vhe_vcpu_put+0x40/0xa0
  kvm_arch_vcpu_put+0x28/0x98
  kvm_sched_out+0x4c/0x70
  prepare_task_switch+0x1b0/0x388
  __schedule+0x234/0x958
  schedule+0x58/0x138
  kvm_vcpu_block+0x88/0x130
  kvm_vcpu_halt+0x120/0x468
  kvm_vcpu_wfi+0x80/0x190

irq_set_affinity() takes the doorbell's irq_desc lock and, when the
doorbell is force-threaded (threadirqs, PREEMPT_RT), wakes its irq
thread:

  &rq->__lock --> &irq_desc_lock_class --> &p->pi_lock --> &rq->__lock

Moving the doorbell is only an optimisation: the doorbell handler kicks
the vcpu from any CPU, and the next WFI entry moves it again. Skip it
when vcpu->scheduled_out is set, which kvm_vcpu_put_hw_mmu() also uses
to tell a sched-out from an explicit put.

Fixes: 2111261ac1c8 ("KVM: arm64: gic-v5: Request doorbells when VPEs enter WFI")
Signed-off-by: Jia He <justin.he@arm.com>
---
 arch/arm64/kvm/vgic/vgic-v5.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/kvm/vgic/vgic-v5.c b/arch/arm64/kvm/vgic/vgic-v5.c
index 91810fbd99af..5824b00bb50d 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));
-- 
2.34.1


  parent reply	other threads:[~2026-11-16  7:13 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 ` Jia He [this message]
2026-11-16  8:07   ` [PATCH 2/2] KVM: arm64: gic-v5: Don't move the vPE doorbell from kvm_sched_out() sashiko-bot
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=20261116071304.2037895-3-justin.he@arm.com \
    --to=justin.he@arm.com \
    --cc=bigeasy@linutronix.de \
    --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=linux-rt-devel@lists.linux.dev \
    --cc=maz@kernel.org \
    --cc=oupton@kernel.org \
    --cc=seiden@linux.ibm.com \
    --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 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®