Skip to contentSkip to conversation

KVM: x86: Fix SRCU list traversal in kvm_fire_mask_notifiers()

PATCH Applied lirongqing 2 participants 2 messages Feb 4 – Mar 5

Subsystems (3)
lore
Share & tools
lore

lirongqing

author
#0 lore raw

PATCH 1/1 KVM: x86: Fix SRCU list traversal in kvm_fire_mask_notifiers()

From: Li RongQing <[email protected]>

The mask_notifier_list is protected by kvm->irq_srcu, but the traversal in kvm_fire_mask_notifiers() incorrectly uses hlist_for_each_entry_rcu(). This leads to lockdep warnings because the standard RCU iterator expects to be under rcu_read_lock(), not SRCU.

Replace the RCU variant with hlist_for_each_entry_srcu() and provide the proper srcu_read_lock_held() annotation to ensure correct synchronization and silence lockdep.

---
 arch/x86/kvm/ioapic.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/kvm/ioapic.c +2 -1
index 2c27832..793c9db 100644
@@ -327,7 +327,8 @@ void kvm_fire_mask_notifiers(struct kvm *kvm, unsigned irqchip, unsigned pin,
 	idx = srcu_read_lock(&kvm->irq_srcu);
 	gsi = kvm_irq_map_chip_pin(kvm, irqchip, pin);
 	if (gsi != -1)
-		hlist_for_each_entry_rcu(kimn, &ioapic->mask_notifier_list, link)
+		hlist_for_each_entry_srcu(kimn, &ioapic->mask_notifier_list, link,
+				srcu_read_lock_held(&kvm->irq_srcu))
 			if (kimn->irq == gsi)
 				kimn->func(kimn, mask);
 	srcu_read_unlock(&kvm->irq_srcu, idx);
Signature · 1 line
2.9.4
maintainer Applied
#1 lore raw
Quoted 10 lines · lirongqing

The mask_notifier_list is protected by kvm->irq_srcu, but the traversal in kvm_fire_mask_notifiers() incorrectly uses hlist_for_each_entry_rcu(). This leads to lockdep warnings because the standard RCU iterator expects to be under rcu_read_lock(), not SRCU.

Replace the RCU variant with hlist_for_each_entry_srcu() and provide the proper srcu_read_lock_held() annotation to ensure correct synchronization and silence lockdep.

[...]

Applied to kvm-x86 fixes, thanks!

[1/1] KVM: x86: Fix SRCU list traversal in kvm_fire_mask_notifiers()

      https://github.com/kvm-x86/linux/commit/68c0526d8c07

--
https://github.com/kvm-x86/linux/tree/next