[PATCH] kvm: Fix false-positive RCU list related warnings

From: madhuparnabhowmik10
Date: Thu Apr 30 2020 - 13:36:32 EST


From: Madhuparna Bhowmik <madhuparnabhowmik10@xxxxxxxxx>

This patch fixes the following warning and other usage of
RCU list in eventfd.c

[29179.937976][T75781] WARNING: suspicious RCU usage
[29179.942789][T75781] 5.7.0-rc3-next-20200429 #1 Tainted: G O L
[29179.949752][T75781] -----------------------------
[29179.954498][T75781] arch/x86/kvm/../../../virt/kvm/eventfd.c:472 RCU-list traversed in non-reader section!!

Pass srcu_read_lock_held() as cond to list_for_each_entry_rcu().

Reported-by: Qian Cai <cai@xxxxxx>
Signed-off-by: Madhuparna Bhowmik <madhuparnabhowmik10@xxxxxxxxx>
---
virt/kvm/eventfd.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/virt/kvm/eventfd.c b/virt/kvm/eventfd.c
index 67b6fc153e9c..a23787693127 100644
--- a/virt/kvm/eventfd.c
+++ b/virt/kvm/eventfd.c
@@ -77,7 +77,8 @@ irqfd_resampler_ack(struct kvm_irq_ack_notifier *kian)

idx = srcu_read_lock(&kvm->irq_srcu);

- list_for_each_entry_rcu(irqfd, &resampler->list, resampler_link)
+ list_for_each_entry_rcu(irqfd, &resampler->list, resampler_link,
+ srcu_read_lock_held(&kvm->irq_srcu))
eventfd_signal(irqfd->resamplefd, 1);

srcu_read_unlock(&kvm->irq_srcu, idx);
@@ -452,7 +453,7 @@ bool kvm_irq_has_notifier(struct kvm *kvm, unsigned irqchip, unsigned pin)
gsi = kvm_irq_map_chip_pin(kvm, irqchip, pin);
if (gsi != -1)
hlist_for_each_entry_rcu(kian, &kvm->irq_ack_notifier_list,
- link)
+ link, srcu_read_lock_held(&kvm->irq_srcu))
if (kian->gsi == gsi) {
srcu_read_unlock(&kvm->irq_srcu, idx);
return true;
@@ -469,7 +470,7 @@ void kvm_notify_acked_gsi(struct kvm *kvm, int gsi)
struct kvm_irq_ack_notifier *kian;

hlist_for_each_entry_rcu(kian, &kvm->irq_ack_notifier_list,
- link)
+ link, srcu_read_lock_held(&kvm->irq_srcu))
if (kian->gsi == gsi)
kian->irq_acked(kian);
}
@@ -960,3 +961,4 @@ kvm_ioeventfd(struct kvm *kvm, struct kvm_ioeventfd *args)

return kvm_assign_ioeventfd(kvm, args);
}
+
--
2.17.1