diff mbox

[4/4] hw/qxl-render: drop cursor locks, add TODO's.

Message ID 1300220228-27423-5-git-send-email-alevy@redhat.com
State New
Headers show

Commit Message

Alon Levy March 15, 2011, 8:17 p.m. UTC
Dropping the locks prevents a deadlock when running with -sdl or -vnc
in addition to -spice.

When server calls get_cursor_command, and we have an active ds
cursor related callback in non vga mode, we need to lock to prevent
the iothread (via sdl/vnc gui_update timer) from touching the ds as well.

Currently (-sdl/-vnc) + -spice seems to work, due to dropping the locking in
qxl-render.c:qxl_render_cursor, but this is just waiting to break because of
touching the cursor from two threads without any locking.
---
 hw/qxl-render.c |   13 +++++++++----
 1 files changed, 9 insertions(+), 4 deletions(-)

Comments

Hans de Goede March 16, 2011, 9:22 a.m. UTC | #1
Hi,

As discussed on irc I think we need to look into this and see
if we can fix it properly while at it.

IOW to be continued...

Regards,

Hans


On 03/15/2011 09:17 PM, Alon Levy wrote:
> Dropping the locks prevents a deadlock when running with -sdl or -vnc
> in addition to -spice.
>
> When server calls get_cursor_command, and we have an active ds
> cursor related callback in non vga mode, we need to lock to prevent
> the iothread (via sdl/vnc gui_update timer) from touching the ds as well.
>
> Currently (-sdl/-vnc) + -spice seems to work, due to dropping the locking in
> qxl-render.c:qxl_render_cursor, but this is just waiting to break because of
> touching the cursor from two threads without any locking.
> ---
>   hw/qxl-render.c |   13 +++++++++----
>   1 files changed, 9 insertions(+), 4 deletions(-)
>
> diff --git a/hw/qxl-render.c b/hw/qxl-render.c
> index 58965e0..1065388 100644
> --- a/hw/qxl-render.c
> +++ b/hw/qxl-render.c
> @@ -209,18 +209,23 @@ void qxl_render_cursor(PCIQXLDevice *qxl, QXLCommandExt *ext)
>           if (c == NULL) {
>               c = cursor_builtin_left_ptr();
>           }
> -        qemu_mutex_lock_iothread();
> +        /* TODO: move this operation to iothread via pipe
> +         * we can't use the global lock here without dropping it
> +         * in gui_update (vl.c), or we get a dead lock (gui_update
> +         * calls dispatcher, waiting on pipe read, and spice server calls
> +         * this function, waiting on the lock that iothread is holding).
> +         * But when used with sdl this calls sdl.c:sdl_mouse_define, which
> +         * afaict must be locked or called from iothread. Moving to iothread
> +         * seems easiest from correctness pov. */
>           qxl->ssd.ds->cursor_define(c);
>           qxl->ssd.ds->mouse_set(x, y, 1);
> -        qemu_mutex_unlock_iothread();
>           cursor_put(c);
>           break;
>       case QXL_CURSOR_MOVE:
>           x = cmd->u.position.x;
>           y = cmd->u.position.y;
> -        qemu_mutex_lock_iothread();
> +        /* TODO: move this operation to iothread via pipe. See comment above */
>           qxl->ssd.ds->mouse_set(x, y, 1);
> -        qemu_mutex_unlock_iothread();
>           break;
>       }
>   }
diff mbox

Patch

diff --git a/hw/qxl-render.c b/hw/qxl-render.c
index 58965e0..1065388 100644
--- a/hw/qxl-render.c
+++ b/hw/qxl-render.c
@@ -209,18 +209,23 @@  void qxl_render_cursor(PCIQXLDevice *qxl, QXLCommandExt *ext)
         if (c == NULL) {
             c = cursor_builtin_left_ptr();
         }
-        qemu_mutex_lock_iothread();
+        /* TODO: move this operation to iothread via pipe
+         * we can't use the global lock here without dropping it
+         * in gui_update (vl.c), or we get a dead lock (gui_update
+         * calls dispatcher, waiting on pipe read, and spice server calls
+         * this function, waiting on the lock that iothread is holding).
+         * But when used with sdl this calls sdl.c:sdl_mouse_define, which
+         * afaict must be locked or called from iothread. Moving to iothread
+         * seems easiest from correctness pov. */
         qxl->ssd.ds->cursor_define(c);
         qxl->ssd.ds->mouse_set(x, y, 1);
-        qemu_mutex_unlock_iothread();
         cursor_put(c);
         break;
     case QXL_CURSOR_MOVE:
         x = cmd->u.position.x;
         y = cmd->u.position.y;
-        qemu_mutex_lock_iothread();
+        /* TODO: move this operation to iothread via pipe. See comment above */
         qxl->ssd.ds->mouse_set(x, y, 1);
-        qemu_mutex_unlock_iothread();
         break;
     }
 }