[PATCH v2 3/3] rcu: Catch rcu_head misuse

Peter Xu posted 3 patches 1 month ago
Maintainers: Paolo Bonzini <pbonzini@redhat.com>
[PATCH v2 3/3] rcu: Catch rcu_head misuse
Posted by Peter Xu 1 month ago
Trap call_rcu1() to make sure it won't be invoked twice for one rcu head by
accident.

Suggested-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Peter Xu <peterx@redhat.com>
---
 util/rcu.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/util/rcu.c b/util/rcu.c
index b703c86f15..fc4b18812b 100644
--- a/util/rcu.c
+++ b/util/rcu.c
@@ -307,6 +307,11 @@ static void *call_rcu_thread(void *opaque)
 
 void call_rcu1(struct rcu_head *node, void (*func)(struct rcu_head *node))
 {
+    /*
+     * Avoid accidental reuse of rcu_head, e.g. enqueuing one node twice
+     * (especially, when the function pointers are different).
+     */
+    assert(node->func == NULL);
     node->func = func;
     enqueue(node);
     qatomic_inc(&rcu_call_count);
-- 
2.50.1