[PATCH 2/2] DO NOT MERGE: virMutex: Fail loudly

Tim Wiederhake posted 2 patches 3 months, 2 weeks ago
[PATCH 2/2] DO NOT MERGE: virMutex: Fail loudly
Posted by Tim Wiederhake 3 months, 2 weeks ago
This is just to demonstrate that libvirt currently exhibits undefined
behavior due to pthread mutex misuse. With this patch applied, several
libvirt tests fail due to the triggered `abort()` calls:
* cputest
* qemuagenttest
* qemucapabilitiestest
* qemumigparamstest
* qemuhotplugtest
* qemumonitorjsontest
* qemusecuritytest
* qemuxmlconftest

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
---
 src/util/virthread.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/util/virthread.c b/src/util/virthread.c
index 14116a2221..dc51144d48 100644
--- a/src/util/virthread.c
+++ b/src/util/virthread.c
@@ -88,6 +88,7 @@ void virMutexDestroy(virMutex *m)
 {
     if (pthread_mutex_destroy(&m->lock)) {
         VIR_WARN("Failed to destroy mutex=%p", m);
+        abort();
     }
 }
 
@@ -95,6 +96,7 @@ void virMutexLock(virMutex *m)
 {
     if (pthread_mutex_lock(&m->lock)) {
         VIR_WARN("Failed to lock mutex=%p", m);
+        abort();
     }
 }
 
@@ -102,6 +104,7 @@ void virMutexUnlock(virMutex *m)
 {
     if (pthread_mutex_unlock(&m->lock)) {
         VIR_WARN("Failed to unlock mutex=%p", m);
+        abort();
     }
 }
 
-- 
2.43.0
Re: [PATCH 2/2] DO NOT MERGE: virMutex: Fail loudly
Posted by Michal Prívozník 3 months, 2 weeks ago
On 7/3/24 14:44, Tim Wiederhake wrote:
> This is just to demonstrate that libvirt currently exhibits undefined
> behavior due to pthread mutex misuse. With this patch applied, several
> libvirt tests fail due to the triggered `abort()` calls:
> * cputest
> * qemuagenttest
> * qemucapabilitiestest
> * qemumigparamstest
> * qemuhotplugtest
> * qemumonitorjsontest
> * qemusecuritytest
> * qemuxmlconftest
> 

IIUC, the problem is just in tests, not libvirt code itself.

> Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
> ---
>  src/util/virthread.c | 3 +++
>  1 file changed, 3 insertions(+)

Michal