KVM: x86: Fix SRCU list traversal in kvm_fire_mask_notifiers()
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
@@ -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
Quoted 10 lines · lirongqing
The
mask_notifier_listis protected bykvm->irq_srcu, but the traversal inkvm_fire_mask_notifiers()incorrectly useshlist_for_each_entry_rcu(). This leads to lockdep warnings because the standard RCU iterator expects to be underrcu_read_lock(), not SRCU.Replace the RCU variant with
hlist_for_each_entry_srcu()and provide the propersrcu_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