yeahuh / rpms / qemu-kvm

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