cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
4ec855
From 287d819f015a624f321d34491e30b62a05912298 Mon Sep 17 00:00:00 2001
4ec855
From: Stefan Hajnoczi <stefanha@redhat.com>
4ec855
Date: Thu, 15 Aug 2019 13:23:10 +0100
4ec855
Subject: [PATCH 08/10] iothread: fix crash with invalid properties
4ec855
MIME-Version: 1.0
4ec855
Content-Type: text/plain; charset=UTF-8
4ec855
Content-Transfer-Encoding: 8bit
4ec855
4ec855
RH-Author: Stefan Hajnoczi <stefanha@redhat.com>
4ec855
Message-id: <20190815132311.22027-2-stefanha@redhat.com>
4ec855
Patchwork-id: 89995
4ec855
O-Subject: [RHEL-8.1.0 qemu-kvm PATCH v2 1/2] iothread: fix crash with invalid properties
4ec855
Bugzilla: 1687541
4ec855
RH-Acked-by: Peter Xu <peterx@redhat.com>
4ec855
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
4ec855
RH-Acked-by: John Snow <jsnow@redhat.com>
4ec855
RH-Acked-by: Markus Armbruster <armbru@redhat.com>
4ec855
4ec855
From: Marc-André Lureau <marcandre.lureau@redhat.com>
4ec855
4ec855
-object iothread,id=foo,? will crash qemu:
4ec855
4ec855
qemu-system-x86_64:qemu-thread-posix.c:128: qemu_cond_destroy: Assertion `cond->initialized' failed.
4ec855
4ec855
Use thread_id != -1 to check if iothread_complete() finished
4ec855
successfully and the mutex/cond have been initialized.
4ec855
4ec855
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
4ec855
Message-Id: <20180821100716.13803-1-marcandre.lureau@redhat.com>
4ec855
Signed-off-by: Fam Zheng <famz@redhat.com>
4ec855
(cherry picked from commit 14a2d11825ddc37d6547a80704ae6450e9e376c7)
4ec855
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
4ec855
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
4ec855
---
4ec855
 iothread.c | 9 ++++++---
4ec855
 1 file changed, 6 insertions(+), 3 deletions(-)
4ec855
4ec855
diff --git a/iothread.c b/iothread.c
4ec855
index aff1281..2fb1cdf 100644
4ec855
--- a/iothread.c
4ec855
+++ b/iothread.c
4ec855
@@ -110,6 +110,7 @@ static void iothread_instance_init(Object *obj)
4ec855
     IOThread *iothread = IOTHREAD(obj);
4ec855
 
4ec855
     iothread->poll_max_ns = IOTHREAD_POLL_MAX_NS_DEFAULT;
4ec855
+    iothread->thread_id = -1;
4ec855
 }
4ec855
 
4ec855
 static void iothread_instance_finalize(Object *obj)
4ec855
@@ -117,6 +118,11 @@ static void iothread_instance_finalize(Object *obj)
4ec855
     IOThread *iothread = IOTHREAD(obj);
4ec855
 
4ec855
     iothread_stop(iothread);
4ec855
+
4ec855
+    if (iothread->thread_id != -1) {
4ec855
+        qemu_cond_destroy(&iothread->init_done_cond);
4ec855
+        qemu_mutex_destroy(&iothread->init_done_lock);
4ec855
+    }
4ec855
     /*
4ec855
      * Before glib2 2.33.10, there is a glib2 bug that GSource context
4ec855
      * pointer may not be cleared even if the context has already been
4ec855
@@ -135,8 +141,6 @@ static void iothread_instance_finalize(Object *obj)
4ec855
         g_main_context_unref(iothread->worker_context);
4ec855
         iothread->worker_context = NULL;
4ec855
     }
4ec855
-    qemu_cond_destroy(&iothread->init_done_cond);
4ec855
-    qemu_mutex_destroy(&iothread->init_done_lock);
4ec855
 }
4ec855
 
4ec855
 static void iothread_complete(UserCreatable *obj, Error **errp)
4ec855
@@ -147,7 +151,6 @@ static void iothread_complete(UserCreatable *obj, Error **errp)
4ec855
 
4ec855
     iothread->stopping = false;
4ec855
     iothread->running = true;
4ec855
-    iothread->thread_id = -1;
4ec855
     iothread->ctx = aio_context_new(&local_error);
4ec855
     if (!iothread->ctx) {
4ec855
         error_propagate(errp, local_error);
4ec855
-- 
4ec855
1.8.3.1
4ec855