yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-iothread-fix-crash-with-invalid-properties.patch

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