diff mbox series

[v2] uprobes: Remove unnecessary RCU list traversal in filter_chain()

Message ID 20241111-rcu_probe-v2-1-a091b59b58b6@debian.org (mailing list archive)
State New
Headers show
Series [v2] uprobes: Remove unnecessary RCU list traversal in filter_chain() | expand

Commit Message

Breno Leitao Nov. 11, 2024, 2:30 p.m. UTC
The filter_chain() function was using list_for_each_entry_rcu() to traverse
uprobe->consumers without holding an RCU read lock, causing warnings when
CONFIG_RCU_PROVING is enabled:

    kernel/events/uprobes.c:937 RCU-list traversed without holding the required lock!!
        5 locks held by bench/182758:
        #1: ffff888603aaac90 (&uprobe->register_rwsem){+.+.}-{3:3}, at: uprobe_unregister_nosync+0x28/0xc0
        #4: ffff888603aaad28 (&uprobe->consumer_rwsem){++++}-{3:3}, at: filter_chain+0x20/0xe0

The uprobe->consumers list is actually protected by uprobe->consumer_rwsem,
which is already held when the list traversal begins. This means the RCU
primitive is unnecessary here - the rwsem provides sufficient protection
for the list traversal, as reported by Peterz.

Replace list_for_each_entry_rcu() with list_for_each_entry() since the
RCU read lock is not needed when accessing uprobe->consumers under the
protection of consumer_rwsem.

Signed-off-by: Breno Leitao <leitao@debian.org>
Fixes: cc01bd044e6a ("uprobes: travers uprobe's consumer list locklessly under SRCU protection")
Acked-by: Andrii Nakryiko <andrii@kernel.org>
---
Changelog:
v2:
 * Move away from the RCU primitive (list_for_each_entry_rcu) to the
   non-rcu one, since RCU is not needed here (Peter)

v1:
 * https://lore.kernel.org/all/20241107-rcu_probe-v1-1-0ca8cc2dedfb@debian.org/
---
 kernel/events/uprobes.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)


---
base-commit: 774ca6d3bf24287ff60b7d6dd4171ebb6e47760a
change-id: 20241111-rcu_probe-0b8dfa53a8a1

Best regards,
diff mbox series

Patch

diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
index 4b52cb2ae6d620b2526de7e86291bdc137aa4f49..372fde678cefce72650b6c200ebea0093193ad6a 100644
--- a/kernel/events/uprobes.c
+++ b/kernel/events/uprobes.c
@@ -934,8 +934,7 @@  static bool filter_chain(struct uprobe *uprobe, struct mm_struct *mm)
 	bool ret = false;
 
 	down_read(&uprobe->consumer_rwsem);
-	list_for_each_entry_srcu(uc, &uprobe->consumers, cons_node,
-				 srcu_read_lock_held(&uprobes_srcu)) {
+	list_for_each_entry(uc, &uprobe->consumers, cons_node) {
 		ret = consumer_filter(uc, mm);
 		if (ret)
 			break;