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 1/2] KVM: arm64: Give the host timer interrupts a separate lockdep class
Date: Mon, 16 Nov 2026 07:13:03 +0000	[thread overview]
Message-ID: <20261116071304.2037895-2-justin.he@arm.com> (raw)
In-Reply-To: <20261116071304.2037895-1-justin.he@arm.com>

With a GICv5 guest, kvm_timer_vcpu_put() clears the active state of the
host timer interrupts with irq_set_irqchip_state(), which takes their
irq_desc lock. On preemption this runs from kvm_sched_out() with the
runqueue lock held:

  &rq->__lock --> &irq_desc_lock_class

By default, all irq descriptors share a single lockdep class, so this
closes a cycle with any interrupt that queues affinity notifier work
under its own descriptor lock (mlx5, for example), as already seen with
the GICv4 vPE doorbells:

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

For the timer interrupts this is a false positive. Nothing that runs
under their descriptor lock leads back to the scheduler:

- They are requested only by KVM, with request_percpu_irq(). Per-CPU
  interrupts are never threaded (irq_set_percpu_devid() sets
  IRQ_NOTHREAD), so there is no irq thread to wake, unlike the vPE
  doorbells with threadirqs.

- Their affinity is fixed and never changed, so no affinity notifier
  work or thread affinity update is triggered.

- The irqchip callbacks reached under the lock (the KVM timer_chip,
  forwarding to the GIC) only access GIC registers.

Give them a separate lockdep class. This is done for all vGIC types, as
none of the above is specific to GICv5. Both timers share the class, so
dependencies between them are still checked.

Fixes: 9491c63b6cd7 ("KVM: arm64: gic-v5: Enlighten arch timer for GICv5")
Signed-off-by: Jia He <justin.he@arm.com>
---
 arch/arm64/kvm/arch_timer.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/arch/arm64/kvm/arch_timer.c b/arch/arm64/kvm/arch_timer.c
index b2c5ba499aa5..1088563d32a3 100644
--- a/arch/arm64/kvm/arch_timer.c
+++ b/arch/arm64/kvm/arch_timer.c
@@ -1362,6 +1362,17 @@ static void kvm_irq_fixup_flags(unsigned int virq, u32 *flags)
 	}
 }
 
+/*
+ * With a GICv5 guest, the timer interrupts' irq_desc lock is taken under
+ * the runqueue lock (kvm_sched_out() -> kvm_timer_vcpu_put()). Give them
+ * their own lockdep class, so that they are not mixed up with interrupts
+ * whose affinity notifier queues work under the irq_desc lock. Nothing
+ * under the timers' own irq_desc lock leads back to the scheduler: they
+ * are per-CPU (never threaded) and their affinity never changes.
+ */
+static struct lock_class_key kvm_timer_irq_lock_class;
+static struct lock_class_key kvm_timer_irq_request_class;
+
 static int kvm_irq_init(struct arch_timer_kvm_info *info)
 {
 	struct irq_domain *domain = NULL;
@@ -1374,6 +1385,8 @@ static int kvm_irq_init(struct arch_timer_kvm_info *info)
 
 	host_vtimer_irq = info->virtual_irq;
 	kvm_irq_fixup_flags(host_vtimer_irq, &host_vtimer_irq_flags);
+	irq_set_lockdep_class(host_vtimer_irq, &kvm_timer_irq_lock_class,
+			      &kvm_timer_irq_request_class);
 
 	if (kvm_vgic_global_state.no_hw_deactivation ||
 	    kvm_vgic_global_state.type == VGIC_V5) {
@@ -1401,6 +1414,8 @@ static int kvm_irq_init(struct arch_timer_kvm_info *info)
 	if (info->physical_irq > 0) {
 		host_ptimer_irq = info->physical_irq;
 		kvm_irq_fixup_flags(host_ptimer_irq, &host_ptimer_irq_flags);
+		irq_set_lockdep_class(host_ptimer_irq, &kvm_timer_irq_lock_class,
+				      &kvm_timer_irq_request_class);
 
 		if (domain)
 			WARN_ON(irq_domain_push_irq(domain, host_ptimer_irq,
-- 
2.34.1


  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 ` Jia He [this message]
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
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-2-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®