All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: libvir-list@redhat.com, Gerd Hoffmann <kraxel@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>
Subject: [Qemu-devel] [PULL 08/12] spice-display: fix qemu_spice_cursor_refresh_bh locking
Date: Tue, 21 Aug 2018 09:45:05 +0200	[thread overview]
Message-ID: <20180821074509.22688-9-kraxel@redhat.com> (raw)
In-Reply-To: <20180821074509.22688-1-kraxel@redhat.com>

From: Paolo Bonzini <pbonzini@redhat.com>

spice-display should not call the ui/console.c functions dpy_cursor_define
and dpy_moues_set with the SimpleSpiceDisplay lock taken.  That will cause
a deadlock, because the DisplayChangeListener callbacks will take the lock
again.  It is also in general a bad idea to invoke generic callbacks with a
lock taken, because it can cause AB-BA deadlocks in the long run.  The only
thing that requires care is that the cursor may disappear as soon as the
mutex is released, so you need an extra cursor_get/cursor_put pair.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-id: 20180720063109.4631-3-pbonzini@redhat.com
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 ui/spice-display.c | 28 +++++++++++++++++-----------
 1 file changed, 17 insertions(+), 11 deletions(-)

diff --git a/ui/spice-display.c b/ui/spice-display.c
index 46df673cd7..f1d341091a 100644
--- a/ui/spice-display.c
+++ b/ui/spice-display.c
@@ -450,29 +450,35 @@ void qemu_spice_display_switch(SimpleSpiceDisplay *ssd,
     qemu_mutex_unlock(&ssd->lock);
 }
 
-static void qemu_spice_cursor_refresh_unlocked(SimpleSpiceDisplay *ssd)
+void qemu_spice_cursor_refresh_bh(void *opaque)
 {
+    SimpleSpiceDisplay *ssd = opaque;
+
+    qemu_mutex_lock(&ssd->lock);
     if (ssd->cursor) {
+        QEMUCursor *c = ssd->cursor;
         assert(ssd->dcl.con);
+        cursor_get(c);
+        qemu_mutex_unlock(&ssd->lock);
         dpy_cursor_define(ssd->dcl.con, ssd->cursor);
+        qemu_mutex_lock(&ssd->lock);
+        cursor_put(c);
     }
+
     if (ssd->mouse_x != -1 && ssd->mouse_y != -1) {
+        int x, y;
         assert(ssd->dcl.con);
-        dpy_mouse_set(ssd->dcl.con, ssd->mouse_x, ssd->mouse_y, 1);
+        x = ssd->mouse_x;
+        y = ssd->mouse_y;
         ssd->mouse_x = -1;
         ssd->mouse_y = -1;
+        qemu_mutex_unlock(&ssd->lock);
+        dpy_mouse_set(ssd->dcl.con, x, y, 1);
+    } else {
+        qemu_mutex_unlock(&ssd->lock);
     }
 }
 
-void qemu_spice_cursor_refresh_bh(void *opaque)
-{
-    SimpleSpiceDisplay *ssd = opaque;
-
-    qemu_mutex_lock(&ssd->lock);
-    qemu_spice_cursor_refresh_unlocked(ssd);
-    qemu_mutex_unlock(&ssd->lock);
-}
-
 void qemu_spice_display_refresh(SimpleSpiceDisplay *ssd)
 {
     graphic_hw_update(ssd->dcl.con);
-- 
2.9.3

  parent reply	other threads:[~2018-08-21  7:45 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-21  7:44 [Qemu-devel] [PULL 00/12] Ui 20180821 patches Gerd Hoffmann
2018-08-21  7:44 ` [Qemu-devel] [PULL 01/12] ui/sdl2: Remove the obsolete SDL_INIT_NOPARACHUTE flag Gerd Hoffmann
2018-08-21  7:44 ` [Qemu-devel] [PULL 02/12] vnc: fix memleak of the "vnc-worker-output" name Gerd Hoffmann
2018-08-21  7:45 ` [Qemu-devel] [PULL 03/12] ui: use enum to string helpers Gerd Hoffmann
2018-08-21  7:45 ` [Qemu-devel] [PULL 04/12] sdl2: redraw correctly when scanout_mode enabled Gerd Hoffmann
2018-08-21  7:45 ` [Qemu-devel] [PULL 05/12] doc: switch to modern syntax for VNC TLS setup Gerd Hoffmann
2018-08-21  7:45 ` [Qemu-devel] [PULL 06/12] vnc: remove support for deprecated tls, x509, x509verify options Gerd Hoffmann
2018-08-21  7:45 ` [Qemu-devel] [PULL 07/12] spice-display: access ptr_x/ptr_y under Mutex Gerd Hoffmann
2018-08-21  7:45 ` Gerd Hoffmann [this message]
2018-08-21  9:45   ` [Qemu-devel] [PULL 08/12] spice-display: fix qemu_spice_cursor_refresh_bh locking Paolo Bonzini
2018-08-21 12:06     ` Gerd Hoffmann
2018-08-21  7:45 ` [Qemu-devel] [PULL 09/12] ui/sdl2: Fix broken -full-screen CLI option Gerd Hoffmann
2018-08-21  7:45 ` [Qemu-devel] [PULL 10/12] ui/vnc: Remove useless parenthesis around DIV_ROUND_UP macro Gerd Hoffmann
2018-08-21  7:45 ` [Qemu-devel] [PULL 11/12] dmabuf: add y0_top, pass it to spice Gerd Hoffmann
2018-08-21  7:45 ` [Qemu-devel] [PULL 12/12] util: promote qemu_egl_rendernode_open() to libqemuutil Gerd Hoffmann
2018-08-21 12:05 [Qemu-devel] [PULL 00/12] Ui 20180821 v2 patches Gerd Hoffmann
2018-08-21 12:05 ` [Qemu-devel] [PULL 08/12] spice-display: fix qemu_spice_cursor_refresh_bh locking Gerd Hoffmann
2018-08-23  9:56 [Qemu-devel] [PULL 00/12] Ui 20180823 v3 patches Gerd Hoffmann
2018-08-23  9:56 ` [Qemu-devel] [PULL 08/12] spice-display: fix qemu_spice_cursor_refresh_bh locking Gerd Hoffmann
2018-08-27  8:53 [Qemu-devel] [PULL 00/12] Ui 20180827 v4 patches Gerd Hoffmann
2018-08-27  8:53 ` [Qemu-devel] [PULL 08/12] spice-display: fix qemu_spice_cursor_refresh_bh locking Gerd Hoffmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180821074509.22688-9-kraxel@redhat.com \
    --to=kraxel@redhat.com \
    --cc=libvir-list@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.