thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone
bf143f
From ffdf44cb8b4c743e7ab0ce46d62687d7178f9a49 Mon Sep 17 00:00:00 2001
bf143f
From: Jon Maloy <jmaloy@redhat.com>
bf143f
Date: Fri, 18 Nov 2022 20:26:54 -0500
bf143f
Subject: [PATCH 3/3] ui/vnc.c: Fixed a deadlock bug.
bf143f
MIME-Version: 1.0
bf143f
Content-Type: text/plain; charset=UTF-8
bf143f
Content-Transfer-Encoding: 8bit
bf143f
bf143f
RH-Author: Jon Maloy <jmaloy@redhat.com>
bf143f
RH-MergeRequest: 234: ui/vnc.c: Fixed a deadlock bug.
bf143f
RH-Bugzilla: 2141896
bf143f
RH-Acked-by: Gerd Hoffmann <kraxel@redhat.com>
bf143f
RH-Acked-by: Marc-André Lureau <marcandre.lureau@redhat.com>
bf143f
RH-Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
bf143f
RH-Commit: [1/1] d3d1d28d7b621a8ae8a593a5bd5303fa7951c17c (jmaloy/qemu-kvm)
bf143f
bf143f
BZ: https://bugzilla.redhat.com/show_bug.cgi?id=2141896
bf143f
Upstream: Merged
bf143f
bf143f
commit 1dbbe6f172810026c51dc84ed927a3cc23017949
bf143f
Author: Rao Lei <lei.rao@intel.com>
bf143f
Date:   Wed Jan 5 10:08:08 2022 +0800
bf143f
bf143f
    ui/vnc.c: Fixed a deadlock bug.
bf143f
bf143f
    The GDB statck is as follows:
bf143f
    (gdb) bt
bf143f
    0  __lll_lock_wait (futex=futex@entry=0x56211df20360, private=0) at lowlevellock.c:52
bf143f
    1  0x00007f263caf20a3 in __GI___pthread_mutex_lock (mutex=0x56211df20360) at ../nptl/pthread_mutex_lock.c:80
bf143f
    2  0x000056211a757364 in qemu_mutex_lock_impl (mutex=0x56211df20360, file=0x56211a804857 "../ui/vnc-jobs.h", line=60)
bf143f
        at ../util/qemu-thread-posix.c:80
bf143f
    3  0x000056211a0ef8c7 in vnc_lock_output (vs=0x56211df14200) at ../ui/vnc-jobs.h:60
bf143f
    4  0x000056211a0efcb7 in vnc_clipboard_send (vs=0x56211df14200, count=1, dwords=0x7ffdf1701338) at ../ui/vnc-clipboard.c:138
bf143f
    5  0x000056211a0f0129 in vnc_clipboard_notify (notifier=0x56211df244c8, data=0x56211dd1bbf0) at ../ui/vnc-clipboard.c:209
bf143f
    6  0x000056211a75dde8 in notifier_list_notify (list=0x56211afa17d0 <clipboard_notifiers>, data=0x56211dd1bbf0) at ../util/notify.c:39
bf143f
    7  0x000056211a0bf0e6 in qemu_clipboard_update (info=0x56211dd1bbf0) at ../ui/clipboard.c:50
bf143f
    8  0x000056211a0bf05d in qemu_clipboard_peer_release (peer=0x56211df244c0, selection=QEMU_CLIPBOARD_SELECTION_CLIPBOARD)
bf143f
        at ../ui/clipboard.c:41
bf143f
    9  0x000056211a0bef9b in qemu_clipboard_peer_unregister (peer=0x56211df244c0) at ../ui/clipboard.c:19
bf143f
    10 0x000056211a0d45f3 in vnc_disconnect_finish (vs=0x56211df14200) at ../ui/vnc.c:1358
bf143f
    11 0x000056211a0d4c9d in vnc_client_read (vs=0x56211df14200) at ../ui/vnc.c:1611
bf143f
    12 0x000056211a0d4df8 in vnc_client_io (ioc=0x56211ce70690, condition=G_IO_IN, opaque=0x56211df14200) at ../ui/vnc.c:1649
bf143f
    13 0x000056211a5b976c in qio_channel_fd_source_dispatch
bf143f
        (source=0x56211ce50a00, callback=0x56211a0d4d71 <vnc_client_io>, user_data=0x56211df14200) at ../io/channel-watch.c:84
bf143f
    14 0x00007f263ccede8e in g_main_context_dispatch () at /lib/x86_64-linux-gnu/libglib-2.0.so.0
bf143f
    15 0x000056211a77d4a1 in glib_pollfds_poll () at ../util/main-loop.c:232
bf143f
    16 0x000056211a77d51f in os_host_main_loop_wait (timeout=958545) at ../util/main-loop.c:255
bf143f
    17 0x000056211a77d630 in main_loop_wait (nonblocking=0) at ../util/main-loop.c:531
bf143f
    18 0x000056211a45bc8e in qemu_main_loop () at ../softmmu/runstate.c:726
bf143f
    19 0x000056211a0b45fa in main (argc=69, argv=0x7ffdf1701778, envp=0x7ffdf17019a8) at ../softmmu/main.c:50
bf143f
bf143f
    From the call trace, we can see it is a deadlock bug.
bf143f
    vnc_disconnect_finish will acquire the output_mutex.
bf143f
    But, the output_mutex will be acquired again in vnc_clipboard_send.
bf143f
    Repeated locking will cause deadlock. So, I move
bf143f
    qemu_clipboard_peer_unregister() behind vnc_unlock_output();
bf143f
     Fixes: 0bf41cab93e ("ui/vnc: clipboard support")
bf143f
    Signed-off-by: Lei Rao <lei.rao@intel.com>
bf143f
    Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
bf143f
    Message-Id: <20220105020808.597325-1-lei.rao@intel.com>
bf143f
    Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
bf143f
bf143f
(cherry picked from commit 1dbbe6f172810026c51dc84ed927a3cc23017949)
bf143f
Signed-off-by: Jon Maloy <jmaloy@redhat.com>
bf143f
---
bf143f
 ui/vnc.c | 4 ++--
bf143f
 1 file changed, 2 insertions(+), 2 deletions(-)
bf143f
bf143f
diff --git a/ui/vnc.c b/ui/vnc.c
bf143f
index a14b6861be..76372ca1de 100644
bf143f
--- a/ui/vnc.c
bf143f
+++ b/ui/vnc.c
bf143f
@@ -1354,12 +1354,12 @@ void vnc_disconnect_finish(VncState *vs)
bf143f
         /* last client gone */
bf143f
         vnc_update_server_surface(vs->vd);
bf143f
     }
bf143f
+    vnc_unlock_output(vs);
bf143f
+
bf143f
     if (vs->cbpeer.update.notify) {
bf143f
         qemu_clipboard_peer_unregister(&vs->cbpeer);
bf143f
     }
bf143f
 
bf143f
-    vnc_unlock_output(vs);
bf143f
-
bf143f
     qemu_mutex_destroy(&vs->output_mutex);
bf143f
     if (vs->bh != NULL) {
bf143f
         qemu_bh_delete(vs->bh);
bf143f
-- 
bf143f
2.37.3
bf143f