On Mon, Mar 22, 2021 at 02:54:30PM +0100, Paolo Bonzini wrote:
> On 22/03/21 11:47, Keqian Zhu wrote:
> > > +    qemu_mutex_init(&kml_slots_lock);
> > As you said, x86 has two address spaces, is it a problem that we may have 
> > multi initialization for kml_slots_lock?
> 
> Agreed, the lock can be initialized (if only for cleanliness) in kvm_init.

Definitely, I'm surprised why I didn't see this... :) Paolo, do you want me to
add another patch (as attached)?

-- 
Peter Xu
>From 0cb7124d111426f255113814cb8395620276cc1f Mon Sep 17 00:00:00 2001
From: Peter Xu <pet...@redhat.com>
Date: Mon, 22 Mar 2021 12:25:18 -0400
Subject: [PATCH] qemu-thread: Assert and check mutex re-initialize

qemu_mutex_post_init() sets mutex->initialized but not check it yet.  Add it,
so as to detect re-initialization of mutexes.

Signed-off-by: Peter Xu <pet...@redhat.com>
---
 util/qemu-thread-common.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/util/qemu-thread-common.h b/util/qemu-thread-common.h
index 2af6b120853..e02059845d8 100644
--- a/util/qemu-thread-common.h
+++ b/util/qemu-thread-common.h
@@ -15,6 +15,7 @@
 
 #include "qemu/thread.h"
 #include "trace.h"
+#include <assert.h>
 
 static inline void qemu_mutex_post_init(QemuMutex *mutex)
 {
@@ -22,6 +23,7 @@ static inline void qemu_mutex_post_init(QemuMutex *mutex)
     mutex->file = NULL;
     mutex->line = 0;
 #endif
+    assert(!mutex->initialized);
     mutex->initialized = true;
 }
 
-- 
2.26.2

Reply via email to