spice: fix locking
Hi,
This is the current spice patch queue ready for pull. Patches have been posted a few days ago for review. A minor issue (leftover debug bit, spotten by Alon) has been fixed and the patch queue has been rebased to latest master, otherwise it is unmodified.
Please pull.
cheers,
Gerd
The following changes since commit d2d979c628e4b2c4a3cb71a31841875795c79043:
NBD: Avoid leaking a couple of strings when the NBD device is closed (2011-05-03 11:29:21 +0200)
are available in the git repository at:
git://anongit.freedesktop.org/spice/qemu spice.v35
Gerd Hoffmann (3):
spice: don't create updates in spice server context.
spice: don't call displaystate callbacks from spice server context.
spice: drop obsolete iothread locking
Jes Sorensen (1):
Make spice dummy functions inline to fix calls not checking return values
hw/qxl-render.c | 25 ++++++++++----------- hw/qxl.c | 27 +++++++++++------------ ui/qemu-spice.h | 12 ++++++++- ui/spice-display.c | 61 +++++++++++++++++++++++++++++++++------------------ ui/spice-display.h | 24 ++++++++++++++++---- 5 files changed, 93 insertions(+), 56 deletions(-)
PATCH 4/4 spice: drop obsolete iothread locking
We don't use qemu internals from spice server context any more. Thus we don't also need to grab the iothread mutex from spice server context. And we don't have to temporarely release the lock to avoid deadlocks. Drop all the calls.
--- hw/qxl.c | 8 -------- ui/spice-display.c | 6 ------ 2 files changed, 0 insertions(+), 14 deletions(-)
hw/qxl.c +0 -8
@@ -666,10 +666,8 @@ static void qxl_hard_reset(PCIQXLDevice *d, int loadvm)dprint (d,1 ,"%s: start%s\n" , __FUNCTION__, loadvm ?" (loadvm)" :"" ); -qemu_mutex_unlock_iothread (); d->ssd.worker->reset_cursor (d->ssd.worker); d->ssd.worker->reset_image_cache (d->ssd.worker); -qemu_mutex_lock_iothread ();qxl_reset_surfaces (d);qxl_reset_memslots (d);
@@ -799,9 +797,7 @@ static void qxl_reset_surfaces(PCIQXLDevice *d) {dprint (d,1 ,"%s:\n" , __FUNCTION__); d->mode =QXL_MODE_UNDEFINED ; -qemu_mutex_unlock_iothread (); d->ssd.worker->destroy_surfaces (d->ssd.worker); -qemu_mutex_lock_iothread ();memset (&d->guest_surfaces.cmds,0 ,sizeof (d->guest_surfaces.cmds)); }
@@ -870,9 +866,7 @@ static void qxl_destroy_primary(PCIQXLDevice *d)dprint (d,1 ,"%s\n" , __FUNCTION__); d->mode =QXL_MODE_UNDEFINED ; -qemu_mutex_unlock_iothread (); d->ssd.worker->destroy_primary_surface (d->ssd.worker,0 ); -qemu_mutex_lock_iothread (); }static void qxl_set_mode (PCIQXLDevice *d,int modenr,int loadvm)
@@ -942,10 +936,8 @@ static void ioport_write(void *opaque, uint32_t addr, uint32_t val)case QXL_IO_UPDATE_AREA : {QXLRect update = d->ram->update_area; -qemu_mutex_unlock_iothread (); d->ssd.worker->update_area (d->ssd.worker, d->ram->update_surface, &update,NULL ,0 ,0 ); -qemu_mutex_lock_iothread ();break ; }case QXL_IO_NOTIFY_CMD :
ui/spice-display.c +0 -6
@@ -176,18 +176,14 @@ void qemu_spice_create_host_primary(SimpleSpiceDisplay *ssd) surface.mem = (intptr_t )ssd->buf; surface.group_id =MEMSLOT_GROUP_HOST ; -qemu_mutex_unlock_iothread (); ssd->worker->create_primary_surface (ssd->worker,0 , &surface); -qemu_mutex_lock_iothread (); }void qemu_spice_destroy_host_primary (SimpleSpiceDisplay *ssd) {dprint (1 ,"%s:\n" , __FUNCTION__); -qemu_mutex_unlock_iothread (); ssd->worker->destroy_primary_surface (ssd->worker,0 ); -qemu_mutex_lock_iothread (); }void qemu_spice_vm_change_state_handler (void *opaque,int running,int reason)
@@ -197,9 +193,7 @@ void qemu_spice_vm_change_state_handler(void *opaque, int running, int reason)if (running) { ssd->worker->start (ssd->worker); }else { -qemu_mutex_unlock_iothread (); ssd->worker->stop (ssd->worker); -qemu_mutex_lock_iothread (); } ssd->running = running; }
Signature · 1 line
1.7.1
PATCH 3/4 spice: don't call displaystate callbacks from spice server context.
In reply to Gerd HoffmannThis patch moves the displaystate callback calls for setting the cursor and the mouse pointer from spice server to qemu (iothread) context. This allows us to simplify locking.
--- hw/qxl-render.c | 25 ++++++++++++------------- hw/qxl.c | 2 ++ ui/spice-display.c | 12 ++++++++++++ ui/spice-display.h | 3 +++ 4 files changed, 29 insertions(+), 13 deletions(-)
hw/qxl-render.c +12 -13
@@ -185,7 +185,6 @@ void qxl_render_cursor(PCIQXLDevice *qxl, QXLCommandExt *ext)QXLCursorCmd *cmd =qxl_phys2virt (qxl, ext->cmd.data, ext->group_id);QXLCursor *cursor;QEMUCursor *c; -int x =-1 , y =-1 ;if (!qxl->ssd.ds->mouse_set || !qxl->ssd.ds->cursor_define) {return ;
@@ -198,8 +197,6 @@ void qxl_render_cursor(PCIQXLDevice *qxl, QXLCommandExt *ext) }switch (cmd->type) {case QXL_CURSOR_SET : - x = cmd->u.set.position.x; - y = cmd->u.set.position.y; cursor =qxl_phys2virt (qxl, cmd->u.set.shape, ext->group_id);if (cursor->chunk.data_size != cursor->data_size) {fprintf (stderr,"%s: multiple chunks\n" , __FUNCTION__);
@@ -209,18 +206,20 @@ void qxl_render_cursor(PCIQXLDevice *qxl, QXLCommandExt *ext)if (c ==NULL ) { c =cursor_builtin_left_ptr (); } -qemu_mutex_lock_iothread (); - qxl->ssd.ds->cursor_define (c); - qxl->ssd.ds->mouse_set (x, y,1 ); -qemu_mutex_unlock_iothread (); -cursor_put (c); +qemu_mutex_lock (&qxl->ssd.lock); +if (qxl->ssd.cursor) { +cursor_put (qxl->ssd.cursor); + } + qxl->ssd.cursor = c; + qxl->ssd.mouse_x = cmd->u.set.position.x; + qxl->ssd.mouse_y = cmd->u.set.position.y; +qemu_mutex_unlock (&qxl->ssd.lock);break ;case QXL_CURSOR_MOVE : - x = cmd->u.position.x; - y = cmd->u.position.y; -qemu_mutex_lock_iothread (); - qxl->ssd.ds->mouse_set (x, y,1 ); -qemu_mutex_unlock_iothread (); +qemu_mutex_lock (&qxl->ssd.lock); + qxl->ssd.mouse_x = cmd->u.position.x; + qxl->ssd.mouse_y = cmd->u.position.y; +qemu_mutex_unlock (&qxl->ssd.lock);break ; } }
hw/qxl.c +2 -0
@@ -1309,6 +1309,8 @@ static int qxl_init_primary(PCIDevice *dev) qxl_hw_screen_dump, qxl_hw_text_update, qxl); qxl->ssd.ds = vga->ds;qemu_mutex_init (&qxl->ssd.lock); + qxl->ssd.mouse_x =-1 ; + qxl->ssd.mouse_y =-1 ; qxl->ssd.bufsize = (16 *1024 *1024 ); qxl->ssd.buf =qemu_malloc (qxl->ssd.bufsize);
ui/spice-display.c +12 -0
@@ -254,6 +254,16 @@ void qemu_spice_display_refresh(SimpleSpiceDisplay *ssd) ssd->update =qemu_spice_create_update (ssd); ssd->notify++; } +if (ssd->cursor) { + ssd->ds->cursor_define (ssd->cursor); +cursor_put (ssd->cursor); + ssd->cursor =NULL ; + } +if (ssd->mouse_x !=-1 && ssd->mouse_y !=-1 ) { + ssd->ds->mouse_set (ssd->mouse_x, ssd->mouse_y,1 ); + ssd->mouse_x =-1 ; + ssd->mouse_y =-1 ; + }qemu_mutex_unlock (&ssd->lock);if (ssd->notify) {
@@ -409,6 +419,8 @@ void qemu_spice_display_init(DisplayState *ds)assert (sdpy.ds ==NULL ); sdpy.ds = ds;qemu_mutex_init (&sdpy.lock); + sdpy.mouse_x =-1 ; + sdpy.mouse_y =-1 ; sdpy.bufsize = (16 *1024 *1024 ); sdpy.buf =qemu_malloc (sdpy.bufsize);register_displaychangelistener (ds, &display_listener);
ui/spice-display.h +3 -0
@@ -20,6 +20,7 @@#include <spice/qxl_dev.h> #include "qemu-thread.h" +#include "console.h" #include "pflib.h" #define NUM_MEMSLOTS 8
@@ -55,6 +56,8 @@ struct SimpleSpiceDisplay {*/ QemuMutex lock;SimpleSpiceUpdate *update; +QEMUCursor *cursor; +int mouse_x, mouse_y; };struct SimpleSpiceUpdate {
Signature · 1 line
1.7.1
PATCH 2/4 spice: don't create updates in spice server context.
In reply to Gerd HoffmannThis patch moves the creation of spice screen updates from the spice server context to qemu iothread context (display refresh timer to be exact). This way we avoid accessing qemu internals (display surface) from spice thread context which in turn allows us to simplify locking.
--- hw/qxl.c | 17 +++++++++++------ ui/spice-display.c | 43 +++++++++++++++++++++++++++---------------- ui/spice-display.h | 21 ++++++++++++++++----- 3 files changed, 54 insertions(+), 27 deletions(-)
hw/qxl.c +11 -6
@@ -343,18 +343,22 @@ static int interface_get_command(QXLInstance *sin, struct QXLCommandExt *ext)SimpleSpiceUpdate *update;QXLCommandRing *ring;QXLCommand *cmd; -int notify; +int notify, ret;switch (qxl->mode) {case QXL_MODE_VGA :dprint (qxl,2 ,"%s: vga\n" , __FUNCTION__); - update =qemu_spice_create_update (&qxl->ssd); -if (update ==NULL ) { -return false; + ret = false; +qemu_mutex_lock (&qxl->ssd.lock); +if (qxl->ssd.update !=NULL ) { + update = qxl->ssd.update; + qxl->ssd.update =NULL ; + *ext = update->ext; + ret = true; } - *ext = update->ext; +qemu_mutex_unlock (&qxl->ssd.lock);qxl_log_command (qxl,"vga" , ext); -return true; +return ret;case QXL_MODE_COMPAT :case QXL_MODE_NATIVE :case QXL_MODE_UNDEFINED :
@@ -1304,6 +1308,7 @@ static int qxl_init_primary(PCIDevice *dev) vga->ds =graphic_console_init (qxl_hw_update, qxl_hw_invalidate, qxl_hw_screen_dump, qxl_hw_text_update, qxl); qxl->ssd.ds = vga->ds; +qemu_mutex_init (&qxl->ssd.lock); qxl->ssd.bufsize = (16 *1024 *1024 ); qxl->ssd.buf =qemu_malloc (qxl->ssd.bufsize);
ui/spice-display.c +27 -16
89 lines not on this page · raw message
ui/spice-display.h +16 -5
@@ -19,6 +19,7 @@#include <spice/enums.h> #include <spice/qxl_dev.h> +#include "qemu-thread.h" #include "pflib.h" #define NUM_MEMSLOTS 8
@@ -31,7 +32,10 @@#define NUM_SURFACES 1024 -typedef struct SimpleSpiceDisplay { +typedef struct SimpleSpiceDisplay SimpleSpiceDisplay ; +typedef struct SimpleSpiceUpdate SimpleSpiceUpdate ; + +struct SimpleSpiceDisplay {DisplayState *ds;void *buf;int bufsize;
@@ -43,19 +47,26 @@ typedef struct SimpleSpiceDisplay {QXLRect dirty;int notify;int running; -} SimpleSpiceDisplay; -typedef struct SimpleSpiceUpdate { +/* +* All struct members below this comment can be accessed from +* both spice server and qemu (iothread) context and any access +* to them must be protected by the lock. +*/ +QemuMutex lock; +SimpleSpiceUpdate *update; +}; + +struct SimpleSpiceUpdate {QXLDrawable drawable;QXLImage image;QXLCommandExt ext;uint8_t *bitmap; -}SimpleSpiceUpdate ; +};int qemu_spice_rect_is_empty (const QXLRect * r);void qemu_spice_rect_union (QXLRect *dest,const QXLRect *r); -SimpleSpiceUpdate *qemu_spice_create_update (SimpleSpiceDisplay *sdpy);void qemu_spice_destroy_update (SimpleSpiceDisplay *sdpy,SimpleSpiceUpdate *update);void qemu_spice_create_host_memslot (SimpleSpiceDisplay *ssd);void qemu_spice_create_host_primary (SimpleSpiceDisplay *ssd);
Signature · 1 line
1.7.1
PATCH 1/4 Make spice dummy functions inline to fix calls not checking return values
In reply to Gerd HoffmannFrom: Jes Sorensen <[email protected]>
qemu_spice_set_passwd() and qemu_spice_set_pw_expire() dummy functions needs to be inline, in order to handle the case where they are called without checking the return value.
--- ui/qemu-spice.h | 12 ++++++++++-- 1 files changed, 10 insertions(+), 2 deletions(-)
ui/qemu-spice.h +10 -2
@@ -47,8 +47,16 @@ CharDriverState *qemu_chr_open_spice(QemuOpts *opts);#else /* CONFIG_SPICE */ #define using_spice 0 -#define qemu_spice_set_passwd (_p, _f1, _f2) (-1) -#define qemu_spice_set_pw_expire (_e) (-1) +static inline int qemu_spice_set_passwd (const char *passwd, +bool fail_if_connected, +bool disconnect_if_connected) +{ +return -1 ; +} +static inline int qemu_spice_set_pw_expire (time_t expires) +{ +return -1 ; +}static inline int qemu_spice_migrate_info (const char *h,int p,int t,const char *s) {return -1 ; }
Signature · 1 line
1.7.1
Quoted 8 lines · Gerd Hoffmann
Hi,This is the current spice patch queue ready for pull. Patches have been posted a few days ago for review. A minor issue (leftover debug bit, spotten by Alon) has been fixed and the patch queue has been rebased to latest master, otherwise it is unmodified.
Please pull.
Pulled. Thanks.
Regards,
Anthony Liguori
Quoted 26 lines
cheers,
GerdThe following changes since commit
d2d979c628e4b2c4a3cb71a31841875795c79043:NBD: Avoid leaking a couple of strings when the NBD device is closed (2011-05-03 11:29:21 +0200)
are available in the git repository at:
git://anongit.freedesktop.org/spice/qemuspice.v35Gerd Hoffmann (3):
spice: don't create updates in spice server context.
spice: don't call displaystate callbacks from spice server context.
spice: drop obsolete iothread lockingJes Sorensen (1):
Make spice dummy functions inline to fix calls not checking return valueshw/qxl-render.c | 25 ++++++++++----------- hw/qxl.c | 27 +++++++++++------------ ui/qemu-spice.h | 12 ++++++++- ui/spice-display.c | 61 +++++++++++++++++++++++++++++++++------------------ ui/spice-display.h | 24 ++++++++++++++++---- 5 files changed, 93 insertions(+), 56 deletions(-)