[PATCH] rcu: Call drain_call_rcu at exit

Akihiko Odaki posted 1 patch 1 month, 1 week ago
util/rcu.c | 1 +
1 file changed, 1 insertion(+)
[PATCH] rcu: Call drain_call_rcu at exit
Posted by Akihiko Odaki 1 month, 1 week ago
call_rcu() callbacks may have potential memory leaks, but QEMU may
sometimes exit before draining the callbacks and leave the leaks
undetected by LeakSanitizer. For example, PCI devices register a
call_rcu() callback by calling address_space_destroy() and they will
not be freed until it gets drained. This hides memory leaks that
is going to happen when PCI devices loose references to the memory
allocations.

Call drain_call_rcu at exit to expose memory leaks by call_rcu()
callbacks deterministically.

Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
---
 util/rcu.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/util/rcu.c b/util/rcu.c
index fa32c942e4bb..118a974e3438 100644
--- a/util/rcu.c
+++ b/util/rcu.c
@@ -415,6 +415,7 @@ static void rcu_init_complete(void)
     qemu_thread_create(&thread, "call_rcu", call_rcu_thread,
                        NULL, QEMU_THREAD_DETACHED);
 
+    atexit(drain_call_rcu);
     rcu_register_thread();
 }
 

---
base-commit: 31669121a01a14732f57c49400bc239cf9fd505f
change-id: 20241013-rcu-b4864052a103

Best regards,
-- 
Akihiko Odaki <akihiko.odaki@daynix.com>