[PATCH 0/2] KVM: arm64: gic-v5: Fix irq_desc locks taken under the runqueue lock

Jia He justin.he at arm.com
Sun Nov 15 23:13:02 PST 2026


With a GICv5 guest, kvm_sched_out() takes irq_desc locks with the
runqueue lock held in two places. Lockdep reports both as a circular
dependency with any interrupt that queues affinity notifier work under
its own descriptor lock:

- kvm_timer_vcpu_put() clears the active state of the host timer
  interrupts. These are per-CPU and never threaded, so this one is a
  false positive. Patch 1 gives them a separate lockdep class, as
  commit 7100185bdc11 ("irqchip/gic-v4: Use a separate lockdep class for
  vPE doorbell IRQs") in kvmarm/fixes does for the GICv4 vPE doorbells.

- vgic_v5_put() can move the vPE doorbell with irq_set_affinity() when
  the vcpu thread is scheduled out in the middle of WFI. This came up in
  the review of "KVM: arm64: gic-v5: Request doorbells when VPEs enter
  WFI", where the resident check was expected to make it unreachable.
  It is reachable, because vgic_v5_load() makes the vPE resident again
  when the halting vcpu thread is scheduled back in. As the doorbell can
  be force-threaded, this can wake its irq thread under the runqueue
  lock, so patch 2 stops moving the doorbell from kvm_sched_out()
  rather than hiding it from lockdep.

Tested on the Arm FVP Base RevC AEMvA GICv5 model (11.31.28, 8 CPUs,
VHE) with PROVE_LOCKING, on top of eedaa7d61f1e.

Lockdep reproduction: to provide the other half of the cycle, a test
module registers an affinity notifier on the UART interrupt and changes
its affinity a few times.

- Patch 1: the vgic_v5 selftest pinned to CPU0 next to a busy loop.
  Without the patch, lockdep reports the cycle through
  kvm_timer_vcpu_put(). With it there is no report, and &rq->__lock
  depends on the new class instead of &irq_desc_lock_class.

- Patch 2: a vcpu executing WFI in a loop, woken by an SPI every 5ms,
  with halt_poll_ns at 50ms and the vcpu thread moved to another CPU
  every 1ms. A kprobe on irq_set_affinity() saw 11 calls from
  kvm_sched_out() without the patch, together with the lockdep report
  quoted in the commit message, and none with it. The doorbell is still
  moved from kvm_vcpu_wfi() itself (51 and 61 calls).

PREEMPT_RT reproduction: PREEMPT_RT force-threads the vPE doorbell, so
patch 2 also fixes a real inversion. Without the patch, and without the
test module, the same WFI test makes lockdep report the cycle closed by
the doorbell's own irq thread: irq_set_affinity() from kvm_vcpu_wfi()
wakes the thread under the descriptor lock, while kvm_sched_out() takes
the descriptor lock under the runqueue lock. The model stops making
progress right after the report. With patch 2 there is no report and the
test completes. (Booting PREEMPT_RT on the GICv5 model also needs
"arm64: smp: Don't force-thread the GICv5 IPIs", posted separately.)

Jia He (2):
  KVM: arm64: Give the host timer interrupts a separate lockdep class
  KVM: arm64: gic-v5: Don't move the vPE doorbell from kvm_sched_out()

 arch/arm64/kvm/arch_timer.c   | 15 +++++++++++++++
 arch/arm64/kvm/vgic/vgic-v5.c |  8 +++++++-
 2 files changed, 22 insertions(+), 1 deletion(-)


base-commit: eedaa7d61f1ec8ae053a9ece0d553785350ac486
-- 
2.34.1




More information about the linux-arm-kernel mailing list