Skip to contentSkip to conversation

async + suspend reworked

PATCH Superseded Alon Levy 2 participants 26 messages Jul 14, 2011 – Jul 15, 2011

v5 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
author
#2 lore raw

PATCH v5 2/12 spice: add qemu_spice_display_init_common

In reply to Alon Levy

From: Gerd Hoffmann <[email protected]>

Factor out SimpleSpiceDisplay initialization into
qemu_spice_display_init_common() and call it from
both qxl.c (for vga mode) and spice-display.c

---
 hw/qxl.c           |    7 +------
 ui/spice-display.c |   17 +++++++++++------
 ui/spice-display.h |    1 +
 3 files changed, 13 insertions(+), 12 deletions(-)
hw/qxl.c +1 -6
index 545074d..2d46814 100644
@@ -1321,12 +1321,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.mouse_x = -1;
-    qxl->ssd.mouse_y = -1;
-    qxl->ssd.bufsize = (16 * 1024 * 1024);
-    qxl->ssd.buf = qemu_malloc(qxl->ssd.bufsize);
+    qemu_spice_display_init_common(&qxl->ssd, vga->ds);
 
     qxl0 = qxl;
     register_displaychangelistener(vga->ds, &display_listener);
ui/spice-display.c +11 -6
index 1e6a38f..93e25bf 100644
@@ -286,6 +286,16 @@ void qemu_spice_vm_change_state_handler(void *opaque, int running, int reason)
     ssd->running = running;
 }
 
+void qemu_spice_display_init_common(SimpleSpiceDisplay *ssd, DisplayState *ds)
+{
+    ssd->ds = ds;
+    qemu_mutex_init(&ssd->lock);
+    ssd->mouse_x = -1;
+    ssd->mouse_y = -1;
+    ssd->bufsize = (16 * 1024 * 1024);
+    ssd->buf = qemu_malloc(ssd->bufsize);
+}
+
 /* display listener callbacks */
 
 void qemu_spice_display_update(SimpleSpiceDisplay *ssd,
@@ -499,12 +509,7 @@ static DisplayChangeListener display_listener = {
 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);
+    qemu_spice_display_init_common(&sdpy, ds);
     register_displaychangelistener(ds, &display_listener);
 
     sdpy.qxl.base.sif = &dpy_interface.base;
ui/spice-display.h +1 -0
index 5b06b11..eb7a573 100644
@@ -75,6 +75,7 @@ void qemu_spice_create_host_memslot(SimpleSpiceDisplay *ssd);
 void qemu_spice_create_host_primary(SimpleSpiceDisplay *ssd);
 void qemu_spice_destroy_host_primary(SimpleSpiceDisplay *ssd);
 void qemu_spice_vm_change_state_handler(void *opaque, int running, int reason);
+void qemu_spice_display_init_common(SimpleSpiceDisplay *ssd, DisplayState *ds);
 
 void qemu_spice_display_update(SimpleSpiceDisplay *ssd,
                                int x, int y, int w, int h);
Signature · 1 line
1.7.6
author
#1 lore raw

PATCH v5 1/12 spice: add worker wrapper functions.

In reply to Alon Levy

From: Gerd Hoffmann <[email protected]>

Add wrapper functions for all spice worker calls.

---
 hw/qxl-render.c    |    4 +-
 hw/qxl.c           |   32 +++++++++---------
 ui/spice-display.c |   95 ++++++++++++++++++++++++++++++++++++++++++++++++---
 ui/spice-display.h |   22 ++++++++++++
 4 files changed, 129 insertions(+), 24 deletions(-)
hw/qxl-render.c +2 -2
index 1316066..bef5f14 100644
@@ -124,8 +124,8 @@ void qxl_render_update(PCIQXLDevice *qxl)
     update.bottom = qxl->guest_primary.surface.height;
 
     memset(dirty, 0, sizeof(dirty));
-    qxl->ssd.worker->update_area(qxl->ssd.worker, 0, &update,
-                                 dirty, ARRAY_SIZE(dirty), 1);
+    qemu_spice_update_area(&qxl->ssd, 0, &update,
+                           dirty, ARRAY_SIZE(dirty), 1);
 
     for (i = 0; i < ARRAY_SIZE(dirty); i++) {
         if (qemu_spice_rect_is_empty(dirty+i)) {
hw/qxl.c +16 -16
index 919ec91..545074d 100644
@@ -690,8 +690,8 @@ static void qxl_hard_reset(PCIQXLDevice *d, int loadvm)
     dprint(d, 1, "%s: start%s\n", __FUNCTION__,
            loadvm ? " (loadvm)" : "");
 
-    d->ssd.worker->reset_cursor(d->ssd.worker);
-    d->ssd.worker->reset_image_cache(d->ssd.worker);
+    qemu_spice_reset_cursor(&d->ssd);
+    qemu_spice_reset_image_cache(&d->ssd);
     qxl_reset_surfaces(d);
     qxl_reset_memslots(d);
 
@@ -796,7 +796,7 @@ static void qxl_add_memslot(PCIQXLDevice *d, uint32_t slot_id, uint64_t delta)
            __FUNCTION__, memslot.slot_id,
            memslot.virt_start, memslot.virt_end);
 
-    d->ssd.worker->add_memslot(d->ssd.worker, &memslot);
+    qemu_spice_add_memslot(&d->ssd, &memslot);
     d->guest_slots[slot_id].ptr = (void*)memslot.virt_start;
     d->guest_slots[slot_id].size = memslot.virt_end - memslot.virt_start;
     d->guest_slots[slot_id].delta = delta;
@@ -806,14 +806,14 @@ static void qxl_add_memslot(PCIQXLDevice *d, uint32_t slot_id, uint64_t delta)
 static void qxl_del_memslot(PCIQXLDevice *d, uint32_t slot_id)
 {
     dprint(d, 1, "%s: slot %d\n", __FUNCTION__, slot_id);
-    d->ssd.worker->del_memslot(d->ssd.worker, MEMSLOT_GROUP_HOST, slot_id);
+    qemu_spice_del_memslot(&d->ssd, MEMSLOT_GROUP_HOST, slot_id);
     d->guest_slots[slot_id].active = 0;
 }
 
 static void qxl_reset_memslots(PCIQXLDevice *d)
 {
     dprint(d, 1, "%s:\n", __FUNCTION__);
-    d->ssd.worker->reset_memslots(d->ssd.worker);
+    qemu_spice_reset_memslots(&d->ssd);
     memset(&d->guest_slots, 0, sizeof(d->guest_slots));
 }
 
@@ -821,7 +821,7 @@ static void qxl_reset_surfaces(PCIQXLDevice *d)
 {
     dprint(d, 1, "%s:\n", __FUNCTION__);
     d->mode = QXL_MODE_UNDEFINED;
-    d->ssd.worker->destroy_surfaces(d->ssd.worker);
+    qemu_spice_destroy_surfaces(&d->ssd);
     memset(&d->guest_surfaces.cmds, 0, sizeof(d->guest_surfaces.cmds));
 }
 
@@ -875,7 +875,7 @@ static void qxl_create_guest_primary(PCIQXLDevice *qxl, int loadvm)
 
     qxl->mode = QXL_MODE_NATIVE;
     qxl->cmdflags = 0;
-    qxl->ssd.worker->create_primary_surface(qxl->ssd.worker, 0, &surface);
+    qemu_spice_create_primary_surface(&qxl->ssd, 0, &surface);
 
     /* for local rendering */
     qxl_render_resize(qxl);
@@ -890,7 +890,7 @@ static void qxl_destroy_primary(PCIQXLDevice *d)
     dprint(d, 1, "%s\n", __FUNCTION__);
 
     d->mode = QXL_MODE_UNDEFINED;
-    d->ssd.worker->destroy_primary_surface(d->ssd.worker, 0);
+    qemu_spice_destroy_primary_surface(&d->ssd, 0);
 }
 
 static void qxl_set_mode(PCIQXLDevice *d, int modenr, int loadvm)
@@ -962,15 +962,15 @@ static void ioport_write(void *opaque, uint32_t addr, uint32_t val)
     case QXL_IO_UPDATE_AREA:
     {
         QXLRect update = d->ram->update_area;
-        d->ssd.worker->update_area(d->ssd.worker, d->ram->update_surface,
-                                   &update, NULL, 0, 0);
+        qemu_spice_update_area(&d->ssd, d->ram->update_surface,
+                               &update, NULL, 0, 0);
         break;
     }
     case QXL_IO_NOTIFY_CMD:
-        d->ssd.worker->wakeup(d->ssd.worker);
+        qemu_spice_wakeup(&d->ssd);
         break;
     case QXL_IO_NOTIFY_CURSOR:
-        d->ssd.worker->wakeup(d->ssd.worker);
+        qemu_spice_wakeup(&d->ssd);
         break;
     case QXL_IO_UPDATE_IRQ:
         qxl_set_irq(d);
@@ -984,7 +984,7 @@ static void ioport_write(void *opaque, uint32_t addr, uint32_t val)
             break;
         }
         d->oom_running = 1;
-        d->ssd.worker->oom(d->ssd.worker);
+        qemu_spice_oom(&d->ssd);
         d->oom_running = 0;
         break;
     case QXL_IO_SET_MODE:
@@ -1022,10 +1022,10 @@ static void ioport_write(void *opaque, uint32_t addr, uint32_t val)
         qxl_destroy_primary(d);
         break;
     case QXL_IO_DESTROY_SURFACE_WAIT:
-        d->ssd.worker->destroy_surface_wait(d->ssd.worker, val);
+        qemu_spice_destroy_surface_wait(&d->ssd, val);
         break;
     case QXL_IO_DESTROY_ALL_SURFACES:
-        d->ssd.worker->destroy_surfaces(d->ssd.worker);
+        qemu_spice_destroy_surfaces(&d->ssd);
         break;
     default:
         fprintf(stderr, "%s: ioport=0x%x, abort()\n", __FUNCTION__, io_port);
@@ -1430,7 +1430,7 @@ static int qxl_post_load(void *opaque, int version)
         cmds[out].cmd.type = QXL_CMD_CURSOR;
         cmds[out].group_id = MEMSLOT_GROUP_GUEST;
         out++;
-        d->ssd.worker->loadvm_commands(d->ssd.worker, cmds, out);
+        qemu_spice_loadvm_commands(&d->ssd, cmds, out);
         qemu_free(cmds);
 
         break;
ui/spice-display.c +89 -6

132 lines not on this page · raw message

ui/spice-display.h +22 -0
index 2f95f68..5b06b11 100644
@@ -80,3 +80,25 @@ void qemu_spice_display_update(SimpleSpiceDisplay *ssd,
                                int x, int y, int w, int h);
 void qemu_spice_display_resize(SimpleSpiceDisplay *ssd);
 void qemu_spice_display_refresh(SimpleSpiceDisplay *ssd);
+
+void qemu_spice_update_area(SimpleSpiceDisplay *ssd, uint32_t surface_id,
+                            struct QXLRect *area, struct QXLRect *dirty_rects,
+                            uint32_t num_dirty_rects,
+                            uint32_t clear_dirty_region);
+void qemu_spice_add_memslot(SimpleSpiceDisplay *ssd, QXLDevMemSlot *memslot);
+void qemu_spice_del_memslot(SimpleSpiceDisplay *ssd, uint32_t gid,
+                            uint32_t sid);
+void qemu_spice_create_primary_surface(SimpleSpiceDisplay *ssd, uint32_t id,
+                                       QXLDevSurfaceCreate *surface);
+void qemu_spice_destroy_primary_surface(SimpleSpiceDisplay *ssd, uint32_t id);
+void qemu_spice_destroy_surface_wait(SimpleSpiceDisplay *ssd, uint32_t id);
+void qemu_spice_loadvm_commands(SimpleSpiceDisplay *ssd,
+                                struct QXLCommandExt *ext, uint32_t count);
+void qemu_spice_wakeup(SimpleSpiceDisplay *ssd);
+void qemu_spice_oom(SimpleSpiceDisplay *ssd);
+void qemu_spice_start(SimpleSpiceDisplay *ssd);
+void qemu_spice_stop(SimpleSpiceDisplay *ssd);
+void qemu_spice_reset_memslots(SimpleSpiceDisplay *ssd);
+void qemu_spice_destroy_surfaces(SimpleSpiceDisplay *ssd);
+void qemu_spice_reset_image_cache(SimpleSpiceDisplay *ssd);
+void qemu_spice_reset_cursor(SimpleSpiceDisplay *ssd);
Signature · 1 line
1.7.6

Alon Levy

author
#0 lore raw

v5 cover async + suspend reworked

v4->v5:
* build with SPICE_INTERFACE_QXL_MINOR in {0,1}
* particularily, I've taken Gerd's suggestion:
* spice 0.8.2 (or the next with QXL_MINOR 1) will depend on spice-protocol 0.8.1 (or the next with the IO_*_ASYNC)
* qemu continues to check only spice version, and still >= 0.6.0
* spice-devel will drag in the right spice-protocol-devel, hence assuring qemu (which actually depends on qxl_dev.h having been updated between 0.8.0 and 0.8.1 in spice-protocol) will build with the right combo:

SPICE_INTERFACE_ | spice-protocol | qxl_dev.h with
QXL_MINOR | | QXL_IO_*_ASYNC &
| | new INTERRUPT_
-----------------------------------------------------
0 current no
1 current+0.1 yes

- this unfortunately resulted in a lot of code churn.
* dropped patch removing qxl_destroy_primary
* returned implicit "\n" to qxl_guest_bug
* rewrote add io_port_to_string
* dropped QXL_COOKIE_VGA since we don't use async in qxl-render right now

Git trees:
git://anongit.freedesktop.org/~alon/qemu async_and_s3.v5

git://anongit.freedesktop.org/~alon/spice async_and_s3.v5
* +version bump 0.8.1
* still need to fix reversed order of dispatcher locals change on async calls (yonit)

git://anongit.freedesktop.org/~alon/spice-protocol s3.v3
* +version bump 0.8.1
git://anongit.freedesktop.org/~alon/qxl s3.v3.async.v4
* some problems here. but they seem to be driver only. wip.. see last patch.

Alon Levy (6):
qxl: add io_port_to_string
qxl: make qxl_guest_bug take variable arguments
qxl: only disallow specific io's in vga mode
qxl: async io support using new spice api
qxl: add QXL_IO_FLUSH_{SURFACES,RELEASE} for guest S3&S4 support
qxl: use QXL_REVISION_*

Gerd Hoffmann (6):
spice: add worker wrapper functions.
spice: add qemu_spice_display_init_common
spice/qxl: move worker wrappers
qxl: fix surface tracking & locking
qxl: error handling fixes and cleanups.
qxl: bump pci rev

 hw/qxl-render.c    |    4 +-
 hw/qxl.c           |  474 +++++++++++++++++++++++++++++++++++++++++++++-------
 hw/qxl.h           |   36 ++++-
 ui/spice-display.c |   93 +++++++++--
 ui/spice-display.h |   28 +++
 5 files changed, 559 insertions(+), 76 deletions(-)
Signature · 1 line
1.7.6
author
#4 lore raw

PATCH v5 4/12 qxl: fix surface tracking & locking

From: Gerd Hoffmann <[email protected]>

Surface tracking needs proper locking since it is used from vcpu and spice worker threads, add it. Also reset the surface counter when zapping all surfaces.

---
 hw/qxl.c |   13 ++++++++++++-
 hw/qxl.h |    2 ++
 2 files changed, 14 insertions(+), 1 deletions(-)
hw/qxl.c +12 -1
index 29094a9..e832d00 100644
@@ -137,7 +137,12 @@ void qxl_spice_update_area(PCIQXLDevice *qxl, uint32_t surface_id,
 
 void qxl_spice_destroy_surface_wait(PCIQXLDevice *qxl, uint32_t id)
 {
+    qemu_mutex_lock(&qxl->track_lock);
+    PANIC_ON(id >= NUM_SURFACES);
     qxl->ssd.worker->destroy_surface_wait(qxl->ssd.worker, id);
+    qxl->guest_surfaces.cmds[id] = 0;
+    qxl->guest_surfaces.count--;
+    qemu_mutex_unlock(&qxl->track_lock);
 }
 
 void qxl_spice_loadvm_commands(PCIQXLDevice *qxl, struct QXLCommandExt *ext,
@@ -158,7 +163,11 @@ void qxl_spice_reset_memslots(PCIQXLDevice *qxl)
 
 void qxl_spice_destroy_surfaces(PCIQXLDevice *qxl)
 {
+    qemu_mutex_lock(&qxl->track_lock);
     qxl->ssd.worker->destroy_surfaces(qxl->ssd.worker);
+    memset(&qxl->guest_surfaces.cmds, 0, sizeof(qxl->guest_surfaces.cmds));
+    qxl->guest_surfaces.count = 0;
+    qemu_mutex_unlock(&qxl->track_lock);
 }
 
 void qxl_spice_reset_image_cache(PCIQXLDevice *qxl)
@@ -317,6 +326,7 @@ static void qxl_track_command(PCIQXLDevice *qxl, struct QXLCommandExt *ext)
         QXLSurfaceCmd *cmd = qxl_phys2virt(qxl, ext->cmd.data, ext->group_id);
         uint32_t id = le32_to_cpu(cmd->surface_id);
         PANIC_ON(id >= NUM_SURFACES);
+        qemu_mutex_lock(&qxl->track_lock);
         if (cmd->type == QXL_SURFACE_CMD_CREATE) {
             qxl->guest_surfaces.cmds[id] = ext->cmd.data;
             qxl->guest_surfaces.count++;
@@ -327,6 +337,7 @@ static void qxl_track_command(PCIQXLDevice *qxl, struct QXLCommandExt *ext)
             qxl->guest_surfaces.cmds[id] = 0;
             qxl->guest_surfaces.count--;
         }
+        qemu_mutex_unlock(&qxl->track_lock);
         break;
     }
     case QXL_CMD_CURSOR:
@@ -869,7 +880,6 @@ static void qxl_reset_surfaces(PCIQXLDevice *d)
     dprint(d, 1, "%s:\n", __FUNCTION__);
     d->mode = QXL_MODE_UNDEFINED;
     qxl_spice_destroy_surfaces(d);
-    memset(&d->guest_surfaces.cmds, 0, sizeof(d->guest_surfaces.cmds));
 }
 
 /* called from spice server thread context only */
@@ -1289,6 +1299,7 @@ static int qxl_init_common(PCIQXLDevice *qxl)
     qxl->generation = 1;
     qxl->num_memslots = NUM_MEMSLOTS;
     qxl->num_surfaces = NUM_SURFACES;
+    qemu_mutex_init(&qxl->track_lock);
 
     switch (qxl->revision) {
     case 1: /* spice 0.4 -- qxl-1 */
hw/qxl.h +2 -0
index e62b9d0..5d0e85e 100644
@@ -55,6 +55,8 @@ typedef struct PCIQXLDevice {
     } guest_surfaces;
     QXLPHYSICAL        guest_cursor;
 
+    QemuMutex          track_lock;
+
     /* thread signaling */
     pthread_t          main;
     int                pipe[2];
Signature · 1 line
1.7.6
author
#5 lore raw

PATCH v5 5/12 qxl: add io_port_to_string

In reply to Alon Levy
---
 hw/qxl.c |   63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 62 insertions(+), 1 deletions(-)
hw/qxl.c +62 -1
index e832d00..c998e9b 100644
@@ -409,6 +409,66 @@ static const char *qxl_mode_to_string(int mode)
     return "INVALID";
 }
 
+static const char *io_port_to_string(uint32_t io_port)
+{
+    if (io_port >= QXL_IO_RANGE_SIZE) {
+        return "out of range";
+    }
+    switch (io_port) {
+    case QXL_IO_NOTIFY_CMD:
+        return "QXL_IO_NOTIFY_CMD";
+    case QXL_IO_NOTIFY_CURSOR:
+        return "QXL_IO_NOTIFY_CURSOR";
+    case QXL_IO_UPDATE_AREA:
+        return "QXL_IO_UPDATE_AREA";
+    case QXL_IO_UPDATE_IRQ:
+        return "QXL_IO_UPDATE_IRQ";
+    case QXL_IO_NOTIFY_OOM:
+        return "QXL_IO_NOTIFY_OOM";
+    case QXL_IO_RESET:
+        return "QXL_IO_RESET";
+    case QXL_IO_SET_MODE:
+        return "QXL_IO_SET_MODE";
+    case QXL_IO_LOG:
+        return "QXL_IO_LOG";
+    case QXL_IO_MEMSLOT_ADD:
+        return "QXL_IO_MEMSLOT_ADD";
+    case QXL_IO_MEMSLOT_DEL:
+        return "QXL_IO_MEMSLOT_DEL";
+    case QXL_IO_DETACH_PRIMARY:
+        return "QXL_IO_DETACH_PRIMARY";
+    case QXL_IO_ATTACH_PRIMARY:
+        return "QXL_IO_ATTACH_PRIMARY";
+    case QXL_IO_CREATE_PRIMARY:
+        return "QXL_IO_CREATE_PRIMARY";
+    case QXL_IO_DESTROY_PRIMARY:
+        return "QXL_IO_DESTROY_PRIMARY";
+    case QXL_IO_DESTROY_SURFACE_WAIT:
+        return "QXL_IO_DESTROY_SURFACE_WAIT";
+    case QXL_IO_DESTROY_ALL_SURFACES:
+        return "QXL_IO_DESTROY_ALL_SURFACES";
+#if SPICE_INTERFACE_QXL_MINOR >= 1
+    case QXL_IO_UPDATE_AREA_ASYNC:
+        return "QXL_IO_UPDATE_AREA_ASYNC";
+    case QXL_IO_MEMSLOT_ADD_ASYNC:
+        return "QXL_IO_MEMSLOT_ADD_ASYNC";
+    case QXL_IO_CREATE_PRIMARY_ASYNC:
+        return "QXL_IO_CREATE_PRIMARY_ASYNC";
+    case QXL_IO_DESTROY_PRIMARY_ASYNC:
+        return "QXL_IO_DESTROY_PRIMARY_ASYNC";
+    case QXL_IO_DESTROY_SURFACE_ASYNC:
+        return "QXL_IO_DESTROY_SURFACE_ASYNC";
+    case QXL_IO_DESTROY_ALL_SURFACES_ASYNC:
+        return "QXL_IO_DESTROY_ALL_SURFACES_ASYNC";
+    case QXL_IO_FLUSH_SURFACES_ASYNC:
+        return "QXL_IO_FLUSH_SURFACES_ASYNC";
+    case QXL_IO_FLUSH_RELEASE:
+        return "QXL_IO_FLUSH_RELEASE";
+#endif
+    }
+    return "error in io_port_to_string";
+}
+
 /* called from spice server thread context only */
 static int interface_get_command(QXLInstance *sin, struct QXLCommandExt *ext)
 {
@@ -1011,7 +1071,8 @@ static void ioport_write(void *opaque, uint32_t addr, uint32_t val)
     default:
         if (d->mode == QXL_MODE_NATIVE || d->mode == QXL_MODE_COMPAT)
             break;
-        dprint(d, 1, "%s: unexpected port 0x%x in vga mode\n", __FUNCTION__, io_port);
+        dprint(d, 1, "%s: unexpected port 0x%x (%s) in vga mode\n",
+            __func__, io_port, io_port_to_string(io_port));
         return;
     }
 
Signature · 1 line
1.7.6
author
#3 lore raw

PATCH v5 3/12 spice/qxl: move worker wrappers

In reply to Alon Levy

From: Gerd Hoffmann <[email protected]>

Move the wrapper functions which are used by qxl only to qxl.c. Rename them from qemu_spice_* to qxl_spice_*. Also pass in a qxl state pointer instead of a SimpleSpiceDisplay pointer.

---
 hw/qxl-render.c    |    4 +-
 hw/qxl.c           |   67 ++++++++++++++++++++++++++++++++++++++++++++-------
 hw/qxl.h           |   13 ++++++++++
 ui/spice-display.c |   46 -----------------------------------
 ui/spice-display.h |   12 ---------
 5 files changed, 72 insertions(+), 70 deletions(-)
hw/qxl-render.c +2 -2
index bef5f14..60b822d 100644
@@ -124,8 +124,8 @@ void qxl_render_update(PCIQXLDevice *qxl)
     update.bottom = qxl->guest_primary.surface.height;
 
     memset(dirty, 0, sizeof(dirty));
-    qemu_spice_update_area(&qxl->ssd, 0, &update,
-                           dirty, ARRAY_SIZE(dirty), 1);
+    qxl_spice_update_area(qxl, 0, &update,
+                          dirty, ARRAY_SIZE(dirty), 1);
 
     for (i = 0; i < ARRAY_SIZE(dirty); i++) {
         if (qemu_spice_rect_is_empty(dirty+i)) {
hw/qxl.c +57 -10

117 lines not on this page · raw message

hw/qxl.h +13 -0
index f6c450d..e62b9d0 100644
@@ -98,6 +98,19 @@ typedef struct PCIQXLDevice {
 /* qxl.c */
 void *qxl_phys2virt(PCIQXLDevice *qxl, QXLPHYSICAL phys, int group_id);
 
+void qxl_spice_update_area(PCIQXLDevice *qxl, uint32_t surface_id,
+                           struct QXLRect *area, struct QXLRect *dirty_rects,
+                           uint32_t num_dirty_rects,
+                           uint32_t clear_dirty_region);
+void qxl_spice_destroy_surface_wait(PCIQXLDevice *qxl, uint32_t id);
+void qxl_spice_loadvm_commands(PCIQXLDevice *qxl, struct QXLCommandExt *ext,
+                               uint32_t count);
+void qxl_spice_oom(PCIQXLDevice *qxl);
+void qxl_spice_reset_memslots(PCIQXLDevice *qxl);
+void qxl_spice_destroy_surfaces(PCIQXLDevice *qxl);
+void qxl_spice_reset_image_cache(PCIQXLDevice *qxl);
+void qxl_spice_reset_cursor(PCIQXLDevice *qxl);
+
 /* qxl-logger.c */
 void qxl_log_cmd_cursor(PCIQXLDevice *qxl, QXLCursorCmd *cmd, int group_id);
 void qxl_log_command(PCIQXLDevice *qxl, const char *ring, QXLCommandExt *ext);
ui/spice-display.c +0 -46

69 lines not on this page · raw message

ui/spice-display.h +0 -12
index eb7a573..abe99c7 100644
@@ -82,24 +82,12 @@ void qemu_spice_display_update(SimpleSpiceDisplay *ssd,
 void qemu_spice_display_resize(SimpleSpiceDisplay *ssd);
 void qemu_spice_display_refresh(SimpleSpiceDisplay *ssd);
 
-void qemu_spice_update_area(SimpleSpiceDisplay *ssd, uint32_t surface_id,
-                            struct QXLRect *area, struct QXLRect *dirty_rects,
-                            uint32_t num_dirty_rects,
-                            uint32_t clear_dirty_region);
 void qemu_spice_add_memslot(SimpleSpiceDisplay *ssd, QXLDevMemSlot *memslot);
 void qemu_spice_del_memslot(SimpleSpiceDisplay *ssd, uint32_t gid,
                             uint32_t sid);
 void qemu_spice_create_primary_surface(SimpleSpiceDisplay *ssd, uint32_t id,
                                        QXLDevSurfaceCreate *surface);
 void qemu_spice_destroy_primary_surface(SimpleSpiceDisplay *ssd, uint32_t id);
-void qemu_spice_destroy_surface_wait(SimpleSpiceDisplay *ssd, uint32_t id);
-void qemu_spice_loadvm_commands(SimpleSpiceDisplay *ssd,
-                                struct QXLCommandExt *ext, uint32_t count);
 void qemu_spice_wakeup(SimpleSpiceDisplay *ssd);
-void qemu_spice_oom(SimpleSpiceDisplay *ssd);
 void qemu_spice_start(SimpleSpiceDisplay *ssd);
 void qemu_spice_stop(SimpleSpiceDisplay *ssd);
-void qemu_spice_reset_memslots(SimpleSpiceDisplay *ssd);
-void qemu_spice_destroy_surfaces(SimpleSpiceDisplay *ssd);
-void qemu_spice_reset_image_cache(SimpleSpiceDisplay *ssd);
-void qemu_spice_reset_cursor(SimpleSpiceDisplay *ssd);
Signature · 1 line
1.7.6
author
#8 lore raw

PATCH v5 6/12 qxl: error handling fixes and cleanups.

In reply to Alon Levy

From: Gerd Hoffmann <[email protected]>

Add qxl_guest_bug() function which is supposed to be called in case sanity checks of guest requests fail. It raises an error IRQ and logs a message in case guest debugging is enabled.

Make PANIC_ON() abort instead of exit. That macro should be used for qemu bugs only, any guest-triggerable stuff should use the new qxl_guest_bug() function instead.

Convert a few easy cases from PANIC_ON() to qxl_guest_bug() to show intended usage.

---
 hw/qxl.c |   34 ++++++++++++++++++++++++++++++----
 hw/qxl.h |    3 ++-
 2 files changed, 32 insertions(+), 5 deletions(-)
hw/qxl.c +30 -4
index c998e9b..e51851a5 100644
@@ -125,6 +125,16 @@ static void qxl_reset_memslots(PCIQXLDevice *d);
 static void qxl_reset_surfaces(PCIQXLDevice *d);
 static void qxl_ring_set_dirty(PCIQXLDevice *qxl);
 
+void qxl_guest_bug(PCIQXLDevice *qxl, const char *msg)
+{
+#if SPICE_INTERFACE_QXL_MINOR >= 1
+    qxl_send_events(qxl, QXL_INTERRUPT_ERROR);
+#endif
+    if (qxl->guestdebug) {
+        fprintf(stderr, "qxl-%d: guest bug: %s\n", qxl->id, msg);
+    }
+}
+
 
 void qxl_spice_update_area(PCIQXLDevice *qxl, uint32_t surface_id,
                            struct QXLRect *area, struct QXLRect *dirty_rects,
@@ -1120,22 +1130,38 @@ static void ioport_write(void *opaque, uint32_t addr, uint32_t val)
         qxl_hard_reset(d, 0);
         break;
     case QXL_IO_MEMSLOT_ADD:
-        PANIC_ON(val >= NUM_MEMSLOTS);
-        PANIC_ON(d->guest_slots[val].active);
+        if (val >= NUM_MEMSLOTS) {
+            qxl_guest_bug(d, "QXL_IO_MEMSLOT_ADD: val out of range");
+            break;
+        }
+        if (d->guest_slots[val].active) {
+            qxl_guest_bug(d, "QXL_IO_MEMSLOT_ADD: memory slot already active");
+            break;
+        }
         d->guest_slots[val].slot = d->ram->mem_slot;
         qxl_add_memslot(d, val, 0);
         break;
     case QXL_IO_MEMSLOT_DEL:
+        if (val >= NUM_MEMSLOTS) {
+            qxl_guest_bug(d, "QXL_IO_MEMSLOT_DEL: val out of range");
+            break;
+        }
         qxl_del_memslot(d, val);
         break;
     case QXL_IO_CREATE_PRIMARY:
-        PANIC_ON(val != 0);
+        if (val != 0) {
+            qxl_guest_bug(d, "QXL_IO_CREATE_PRIMARY: val != 0");
+            break;
+        }
         dprint(d, 1, "QXL_IO_CREATE_PRIMARY\n");
         d->guest_primary.surface = d->ram->create_surface;
         qxl_create_guest_primary(d, 0);
         break;
     case QXL_IO_DESTROY_PRIMARY:
-        PANIC_ON(val != 0);
+        if (val != 0) {
+            qxl_guest_bug(d, "QXL_IO_DESTROY_PRIMARY: val != 0");
+            break;
+        }
         dprint(d, 1, "QXL_IO_DESTROY_PRIMARY (%s)\n", qxl_mode_to_string(d->mode));
         qxl_destroy_primary(d);
         break;
hw/qxl.h +2 -1
index 5d0e85e..5db9aae 100644
@@ -86,7 +86,7 @@ typedef struct PCIQXLDevice {
 
 #define PANIC_ON(x) if ((x)) {                         \
     printf("%s: PANIC %s failed\n", __FUNCTION__, #x); \
-    exit(-1);                                          \
+    abort();                                           \
 }
 
 #define dprint(_qxl, _level, _fmt, ...)                                 \
@@ -99,6 +99,7 @@ typedef struct PCIQXLDevice {
 
 /* qxl.c */
 void *qxl_phys2virt(PCIQXLDevice *qxl, QXLPHYSICAL phys, int group_id);
+void qxl_guest_bug(PCIQXLDevice *qxl, const char *msg);
 
 void qxl_spice_update_area(PCIQXLDevice *qxl, uint32_t surface_id,
                            struct QXLRect *area, struct QXLRect *dirty_rects,
Signature · 1 line
1.7.6
author
#9 lore raw

PATCH v5 7/12 qxl: make qxl_guest_bug take variable arguments

In reply to Alon Levy
---
 hw/qxl.c |    9 +++++++--
 hw/qxl.h |    2 +-
 2 files changed, 8 insertions(+), 3 deletions(-)
hw/qxl.c +7 -2
index e51851a5..09382f5 100644
@@ -125,13 +125,18 @@ static void qxl_reset_memslots(PCIQXLDevice *d);
 static void qxl_reset_surfaces(PCIQXLDevice *d);
 static void qxl_ring_set_dirty(PCIQXLDevice *qxl);
 
-void qxl_guest_bug(PCIQXLDevice *qxl, const char *msg)
+void qxl_guest_bug(PCIQXLDevice *qxl, const char *msg, ...)
 {
 #if SPICE_INTERFACE_QXL_MINOR >= 1
     qxl_send_events(qxl, QXL_INTERRUPT_ERROR);
 #endif
     if (qxl->guestdebug) {
-        fprintf(stderr, "qxl-%d: guest bug: %s\n", qxl->id, msg);
+        va_list ap;
+        va_start(ap, msg);
+        fprintf(stderr, "qxl-%d: guest bug: ", qxl->id);
+        vfprintf(stderr, msg, ap);
+        fprintf(stderr, "\n");
+        va_end(ap);
     }
 }
 
hw/qxl.h +1 -1
index 5db9aae..32ca5a0 100644
@@ -99,7 +99,7 @@ typedef struct PCIQXLDevice {
 
 /* qxl.c */
 void *qxl_phys2virt(PCIQXLDevice *qxl, QXLPHYSICAL phys, int group_id);
-void qxl_guest_bug(PCIQXLDevice *qxl, const char *msg);
+void qxl_guest_bug(PCIQXLDevice *qxl, const char *msg, ...);
 
 void qxl_spice_update_area(PCIQXLDevice *qxl, uint32_t surface_id,
                            struct QXLRect *area, struct QXLRect *dirty_rects,
Signature · 1 line
1.7.6
author
#10 lore raw

PATCH v5 8/12 qxl: only disallow specific io's in vga mode

In reply to Alon Levy

Since the driver is still in operation even after moving to UNDEFINED, i.e. by destroying primary in any way.

---
 hw/qxl.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
hw/qxl.c +2 -1
index 09382f5..27eee4b 100644
@@ -1084,8 +1084,9 @@ static void ioport_write(void *opaque, uint32_t addr, uint32_t val)
     case QXL_IO_LOG:
         break;
     default:
-        if (d->mode == QXL_MODE_NATIVE || d->mode == QXL_MODE_COMPAT)
+        if (d->mode != QXL_MODE_VGA) {
             break;
+        }
         dprint(d, 1, "%s: unexpected port 0x%x (%s) in vga mode\n",
             __func__, io_port, io_port_to_string(io_port));
         return;
Signature · 1 line
1.7.6
author
#11 lore raw

PATCH v5 9/12 qxl: async io support using new spice api

In reply to Alon Levy

Some of the QXL port i/o commands are waiting for the spice server to complete certain actions. Add async versions for these commands, so we don't block the vcpu while the spice server processses the command. Instead the qxl device will raise an IRQ when done.

The async command processing relies on an added QXLInterface::async_complete and added QXLWorker::*_async additions, in spice server qxl >= 3.1

---
 hw/qxl-render.c    |    2 +-
 hw/qxl.c           |  236 ++++++++++++++++++++++++++++++++++++++++++++--------
 hw/qxl.h           |   18 ++++-
 ui/spice-display.c |   47 ++++++++--
 ui/spice-display.h |   23 +++++-
 5 files changed, 273 insertions(+), 53 deletions(-)
hw/qxl-render.c +1 -1
index 60b822d..643ff2d 100644
@@ -125,7 +125,7 @@ void qxl_render_update(PCIQXLDevice *qxl)
 
     memset(dirty, 0, sizeof(dirty));
     qxl_spice_update_area(qxl, 0, &update,
-                          dirty, ARRAY_SIZE(dirty), 1);
+                          dirty, ARRAY_SIZE(dirty), 1, QXL_SYNC);
 
     for (i = 0; i < ARRAY_SIZE(dirty); i++) {
         if (qemu_spice_rect_is_empty(dirty+i)) {
hw/qxl.c +200 -36

401 lines not on this page · raw message

hw/qxl.h +15 -3
index 32ca5a0..41f0311 100644
@@ -15,6 +15,8 @@ enum qxl_mode {
     QXL_MODE_NATIVE,
 };
 
+#define QXL_UNDEFINED_IO UINT32_MAX
+
 typedef struct PCIQXLDevice {
     PCIDevice          pci;
     SimpleSpiceDisplay ssd;
@@ -30,6 +32,11 @@ typedef struct PCIQXLDevice {
     int32_t            num_memslots;
     int32_t            num_surfaces;
 
+#if SPICE_INTERFACE_QXL_MINOR >= 1
+    uint32_t           current_async;
+    QemuMutex          async_lock;
+#endif
+
     struct guest_slots {
         QXLMemSlot     slot;
         void           *ptr;
@@ -104,13 +111,12 @@ void qxl_guest_bug(PCIQXLDevice *qxl, const char *msg, ...);
 void qxl_spice_update_area(PCIQXLDevice *qxl, uint32_t surface_id,
                            struct QXLRect *area, struct QXLRect *dirty_rects,
                            uint32_t num_dirty_rects,
-                           uint32_t clear_dirty_region);
-void qxl_spice_destroy_surface_wait(PCIQXLDevice *qxl, uint32_t id);
+                           uint32_t clear_dirty_region,
+                           qxl_async_io async);
 void qxl_spice_loadvm_commands(PCIQXLDevice *qxl, struct QXLCommandExt *ext,
                                uint32_t count);
 void qxl_spice_oom(PCIQXLDevice *qxl);
 void qxl_spice_reset_memslots(PCIQXLDevice *qxl);
-void qxl_spice_destroy_surfaces(PCIQXLDevice *qxl);
 void qxl_spice_reset_image_cache(PCIQXLDevice *qxl);
 void qxl_spice_reset_cursor(PCIQXLDevice *qxl);
 
@@ -122,3 +128,9 @@ void qxl_log_command(PCIQXLDevice *qxl, const char *ring, QXLCommandExt *ext);
 void qxl_render_resize(PCIQXLDevice *qxl);
 void qxl_render_update(PCIQXLDevice *qxl);
 void qxl_render_cursor(PCIQXLDevice *qxl, QXLCommandExt *ext);
+#if SPICE_INTERFACE_QXL_MINOR >= 1
+void qxl_spice_update_area_async(PCIQXLDevice *qxl, uint32_t surface_id,
+                                 struct QXLRect *area,
+                                 uint32_t clear_dirty_region,
+                                 int is_vga);
+#endif
ui/spice-display.c +39 -12

84 lines not on this page · raw message

ui/spice-display.h +20 -3
index abe99c7..1388641 100644
@@ -33,6 +33,20 @@
 
 #define NUM_SURFACES 1024
 
+/*
+ * Internal enum to differenciate between options for
+ * io calls that have a sync (old) version and an _async (new)
+ * version:
+ *  QXL_SYNC: use the old version
+ *  QXL_ASYNC: use the new version and make sure there are no two
+ *   happening at the same time. This is used for guest initiated
+ *   calls
+ */
+typedef enum qxl_async_io {
+    QXL_SYNC,
+    QXL_ASYNC,
+} qxl_async_io;
+
 typedef struct SimpleSpiceDisplay SimpleSpiceDisplay;
 typedef struct SimpleSpiceUpdate SimpleSpiceUpdate;
 
@@ -82,12 +96,15 @@ void qemu_spice_display_update(SimpleSpiceDisplay *ssd,
 void qemu_spice_display_resize(SimpleSpiceDisplay *ssd);
 void qemu_spice_display_refresh(SimpleSpiceDisplay *ssd);
 
-void qemu_spice_add_memslot(SimpleSpiceDisplay *ssd, QXLDevMemSlot *memslot);
+void qemu_spice_add_memslot(SimpleSpiceDisplay *ssd, QXLDevMemSlot *memslot,
+                            qxl_async_io async);
 void qemu_spice_del_memslot(SimpleSpiceDisplay *ssd, uint32_t gid,
                             uint32_t sid);
 void qemu_spice_create_primary_surface(SimpleSpiceDisplay *ssd, uint32_t id,
-                                       QXLDevSurfaceCreate *surface);
-void qemu_spice_destroy_primary_surface(SimpleSpiceDisplay *ssd, uint32_t id);
+                                       QXLDevSurfaceCreate *surface,
+                                       qxl_async_io async);
+void qemu_spice_destroy_primary_surface(SimpleSpiceDisplay *ssd,
+                                        uint32_t id, qxl_async_io async);
 void qemu_spice_wakeup(SimpleSpiceDisplay *ssd);
 void qemu_spice_start(SimpleSpiceDisplay *ssd);
 void qemu_spice_stop(SimpleSpiceDisplay *ssd);
Signature · 1 line
1.7.6
author
#20 lore raw

PATCH v5 11/12 qxl: bump pci rev

In reply to Alon Levy

From: Gerd Hoffmann <[email protected]>

Inform guest drivers about the new features I/O commands we have now (async commands, S3 support) if building with newer spice, i.e. if SPICE_INTERFACE_QXL_MINOR >= 1.

---
 hw/qxl.c |   25 ++++++++++++++++++-------
 hw/qxl.h |    6 ++++++
 2 files changed, 24 insertions(+), 7 deletions(-)
hw/qxl.c +18 -7
index 77f9ec4..5052206 100644
@@ -1593,9 +1593,14 @@ static int qxl_init_common(PCIQXLDevice *qxl)
         pci_device_rev = QXL_REVISION_STABLE_V04;
         break;
     case 2: /* spice 0.6 -- qxl-2 */
-    default:
         pci_device_rev = QXL_REVISION_STABLE_V06;
         break;
+#if SPICE_INTERFACE_QXL_MINOR >= 1
+    case 3: /* qxl-3 */
+#endif
+    default:
+        pci_device_rev = QXL_DEFAULT_REVISION;
+        break;
     }
 
     pci_set_byte(&config[PCI_REVISION_ID], pci_device_rev);
@@ -1857,9 +1862,12 @@ static PCIDeviceInfo qxl_info_primary = {
     .device_id    = QXL_DEVICE_ID_STABLE,
     .class_id     = PCI_CLASS_DISPLAY_VGA,
     .qdev.props = (Property[]) {
-        DEFINE_PROP_UINT32("ram_size", PCIQXLDevice, vga.vram_size, 64 * 1024 * 1024),
-        DEFINE_PROP_UINT32("vram_size", PCIQXLDevice, vram_size, 64 * 1024 * 1024),
-        DEFINE_PROP_UINT32("revision", PCIQXLDevice, revision, 2),
+        DEFINE_PROP_UINT32("ram_size", PCIQXLDevice, vga.vram_size,
+                           64 * 1024 * 1024),
+        DEFINE_PROP_UINT32("vram_size", PCIQXLDevice, vram_size,
+                           64 * 1024 * 1024),
+        DEFINE_PROP_UINT32("revision", PCIQXLDevice, revision,
+                           QXL_DEFAULT_REVISION),
         DEFINE_PROP_UINT32("debug", PCIQXLDevice, debug, 0),
         DEFINE_PROP_UINT32("guestdebug", PCIQXLDevice, guestdebug, 0),
         DEFINE_PROP_UINT32("cmdlog", PCIQXLDevice, cmdlog, 0),
@@ -1878,9 +1886,12 @@ static PCIDeviceInfo qxl_info_secondary = {
     .device_id    = QXL_DEVICE_ID_STABLE,
     .class_id     = PCI_CLASS_DISPLAY_OTHER,
     .qdev.props = (Property[]) {
-        DEFINE_PROP_UINT32("ram_size", PCIQXLDevice, vga.vram_size, 64 * 1024 * 1024),
-        DEFINE_PROP_UINT32("vram_size", PCIQXLDevice, vram_size, 64 * 1024 * 1024),
-        DEFINE_PROP_UINT32("revision", PCIQXLDevice, revision, 2),
+        DEFINE_PROP_UINT32("ram_size", PCIQXLDevice, vga.vram_size,
+                           64 * 1024 * 1024),
+        DEFINE_PROP_UINT32("vram_size", PCIQXLDevice, vram_size,
+                           64 * 1024 * 1024),
+        DEFINE_PROP_UINT32("revision", PCIQXLDevice, revision,
+                           QXL_DEFAULT_REVISION),
         DEFINE_PROP_UINT32("debug", PCIQXLDevice, debug, 0),
         DEFINE_PROP_UINT32("guestdebug", PCIQXLDevice, guestdebug, 0),
         DEFINE_PROP_UINT32("cmdlog", PCIQXLDevice, cmdlog, 0),
hw/qxl.h +6 -0
index 41f0311..b1af1d2 100644
@@ -104,6 +104,12 @@ typedef struct PCIQXLDevice {
         }                                                               \
     } while (0)
 
+#if SPICE_INTERFACE_QXL_MINOR >= 1
+#define QXL_DEFAULT_REVISION QXL_REVISION_STABLE_V10
+#else
+#define QXL_DEFAULT_REVISION QXL_REVISION_STABLE_V06
+#endif
+
 /* qxl.c */
 void *qxl_phys2virt(PCIQXLDevice *qxl, QXLPHYSICAL phys, int group_id);
 void qxl_guest_bug(PCIQXLDevice *qxl, const char *msg, ...);
Signature · 1 line
1.7.6
author
#17 lore raw

PATCH v5 10/12 qxl: add QXL_IO_FLUSH_{SURFACES, RELEASE} for guest S3&S4 support

In reply to Alon Levy

Add two new IOs.
QXL_IO_FLUSH_SURFACES - equivalent to update area for all surfaces, used
to reduce vmexits from NumSurfaces to 1 on guest S3, S4 and resolution change (windows driver implementation is such that this is done on each of those occasions).
QXL_IO_FLUSH_RELEASE - used to ensure anything on last_release is put on the release ring
for the client to free.

Cc Yonit Halperin <[email protected]>
---
 hw/qxl.c |   30 ++++++++++++++++++++++++++++++
 1 files changed, 30 insertions(+), 0 deletions(-)
hw/qxl.c +30 -0
index 6f784e6..77f9ec4 100644
@@ -185,6 +185,13 @@ static void qxl_spice_destroy_surface_wait(PCIQXLDevice *qxl, uint32_t id,
     }
 }
 
+#if SPICE_INTERFACE_QXL_MINOR >= 1
+static void qxl_spice_flush_surfaces_async(PCIQXLDevice *qxl)
+{
+    qxl->ssd.worker->flush_surfaces_async(qxl->ssd.worker, 0);
+}
+#endif
+
 void qxl_spice_loadvm_commands(PCIQXLDevice *qxl, struct QXLCommandExt *ext,
                                uint32_t count)
 {
@@ -1210,6 +1217,8 @@ static void ioport_write(void *opaque, uint32_t addr, uint32_t val)
         goto async_common;
     case QXL_IO_DESTROY_ALL_SURFACES_ASYNC:
         io_port = QXL_IO_DESTROY_ALL_SURFACES;
+        goto async_common;
+    case QXL_IO_FLUSH_SURFACES_ASYNC:
     async_common:
         async = QXL_ASYNC;
         qemu_mutex_lock(&d->async_lock);
@@ -1326,6 +1335,27 @@ static void ioport_write(void *opaque, uint32_t addr, uint32_t val)
         }
         qxl_spice_destroy_surface_wait(d, val, async);
         break;
+#if SPICE_INTERFACE_QXL_MINOR >= 1
+    case QXL_IO_FLUSH_RELEASE: {
+        QXLReleaseRing *ring = &d->ram->release_ring;
+        if (ring->prod - ring->cons + 1 == ring->num_items) {
+            fprintf(stderr,
+                "ERROR: no flush, full release ring [p%d,%dc]\n",
+                ring->prod, ring->cons);
+        }
+        qxl_push_free_res(d, 1 /* flush */);
+        dprint(d, 1, "QXL_IO_FLUSH_RELEASE exit (%s, s#=%d, res#=%d,%p)\n",
+            qxl_mode_to_string(d->mode), d->guest_surfaces.count,
+            d->num_free_res, d->last_release);
+        break;
+    }
+    case QXL_IO_FLUSH_SURFACES_ASYNC:
+        dprint(d, 1, "QXL_IO_FLUSH_SURFACES_ASYNC (%d) (%s, s#=%d, res#=%d)\n",
+               val, qxl_mode_to_string(d->mode), d->guest_surfaces.count,
+               d->num_free_res);
+        qxl_spice_flush_surfaces_async(d);
+#endif
+        break;
     case QXL_IO_DESTROY_ALL_SURFACES:
         d->mode = QXL_MODE_UNDEFINED;
         qxl_spice_destroy_surfaces(d, async);
Signature · 1 line
1.7.6
author
#23 lore raw

PATCH v5 12/12 qxl: use QXL_REVISION_*

In reply to Alon Levy
---
 hw/qxl.c |   27 ++++++++++++++-------------
 1 files changed, 14 insertions(+), 13 deletions(-)
hw/qxl.c +14 -13
index 5052206..b9d27b9 100644
@@ -1579,7 +1579,6 @@ static DisplayChangeListener display_listener = {
 static int qxl_init_common(PCIQXLDevice *qxl)
 {
     uint8_t* config = qxl->pci.config;
-    uint32_t pci_device_rev;
     uint32_t io_size;
 
     qxl->mode = QXL_MODE_UNDEFINED;
@@ -1587,23 +1586,25 @@ static int qxl_init_common(PCIQXLDevice *qxl)
     qxl->num_memslots = NUM_MEMSLOTS;
     qxl->num_surfaces = NUM_SURFACES;
     qemu_mutex_init(&qxl->track_lock);
-
+#if SPICE_INTERFACE_QXL_MINOR >= 1
+    qemu_mutex_init(&qxl->async_lock);
+    qxl->current_async = QXL_UNDEFINED_IO;
+#endif
     switch (qxl->revision) {
-    case 1: /* spice 0.4 -- qxl-1 */
-        pci_device_rev = QXL_REVISION_STABLE_V04;
-        break;
-    case 2: /* spice 0.6 -- qxl-2 */
-        pci_device_rev = QXL_REVISION_STABLE_V06;
-        break;
+    case QXL_REVISION_STABLE_V04: /* spice 0.4 -- qxl-1 */
+    case QXL_REVISION_STABLE_V06: /* spice 0.6 -- qxl-2 */
 #if SPICE_INTERFACE_QXL_MINOR >= 1
-    case 3: /* qxl-3 */
+    case QXL_REVISION_STABLE_V10: /* spice 0.10? -- qxl-3 */
+        break;
 #endif
     default:
-        pci_device_rev = QXL_DEFAULT_REVISION;
+        fprintf(stderr, "invalid revision %d, resetting to %d\n", qxl->revision,
+            QXL_DEFAULT_REVISION);
+        qxl->revision = QXL_DEFAULT_REVISION;
         break;
     }
 
-    pci_set_byte(&config[PCI_REVISION_ID], pci_device_rev);
+    pci_set_byte(&config[PCI_REVISION_ID], qxl->revision);
     pci_set_byte(&config[PCI_INTERRUPT_PIN], 1);
 
     qxl->rom_size = qxl_rom_size();
@@ -1614,14 +1615,14 @@ static int qxl_init_common(PCIQXLDevice *qxl)
     if (qxl->vram_size < 16 * 1024 * 1024) {
         qxl->vram_size = 16 * 1024 * 1024;
     }
-    if (qxl->revision == 1) {
+    if (qxl->revision == QXL_REVISION_STABLE_V04) {
         qxl->vram_size = 4096;
     }
     qxl->vram_size = msb_mask(qxl->vram_size * 2 - 1);
     qxl->vram_offset = qemu_ram_alloc(&qxl->pci.qdev, "qxl.vram", qxl->vram_size);
 
     io_size = msb_mask(QXL_IO_RANGE_SIZE * 2 - 1);
-    if (qxl->revision == 1) {
+    if (qxl->revision == QXL_REVISION_STABLE_V04) {
         io_size = 8;
     }
 
Signature · 1 line
1.7.6
#6 lore raw

Re: [Qemu-devel] [PATCHv5 05/12] qxl: add io_port_to_string

In reply to Alon Levy

Hi,

hw/qxl.c static const char *qxl_mode_to_string(int mode) · line 419

Quoted 3 lines
hw/qxl.c +3 -0
+    switch (io_port) {
+    case QXL_IO_NOTIFY_CMD:
+        return "QXL_IO_NOTIFY_CMD";

Wasn't the plan to make this an array?

cheers,
Gerd

#12 lore raw

Re: [Qemu-devel] [PATCHv5 09/12] qxl: async io support using new spice api

In reply to Alon Levy
Quoted 8 lines
      case QXL_IO_DESTROY_PRIMARY:
          if (val != 0) {
hw/qxl.c +4 -2
-            qxl_guest_bug(d, "QXL_IO_DESTROY_PRIMARY: val != 0");
-            break;
+            qxl_guest_bug(d, "QXL_IO_DESTROY_PRIMARY (async=%d): val != 0",
+                          async);
+            goto cancel_async;
+        }

hw/qxl.c static void ioport_write(void *opaque, uint32_t addr, uint32_t val) · line 1318

Quoted 10 lines
hw/qxl.c +9 -0
+        dprint(d, 1, "QXL_IO_DESTROY_PRIMARY (async=%d) (%s)\n", async,
+               qxl_mode_to_string(d->mode));
+        qxl_destroy_primary(d, async);
+#if SPICE_INTERFACE_QXL_MINOR>= 1
+        if (d->mode == QXL_MODE_UNDEFINED&&  async == QXL_ASYNC) {
+            dprint(d, 1, "QXL_IO_DESTROY_PRIMARY_ASYNC in %s, ignored\n",
+                    qxl_mode_to_string(d->mode));
+            qxl_send_events(d, QXL_INTERRUPT_IO_CMD);
+            goto cancel_async;
          }

Hmm? Why this is needed?

hw/qxl.c static void ioport_write(void *opaque, uint32_t addr, uint32_t val) · line 1343

Quoted 11 lines
      default:
          fprintf(stderr, "%s: ioport=0x%x, abort()\n", __FUNCTION__, io_port);
          abort();
      }
hw/qxl.c +7 -0
+    return;
+cancel_async:
+#if SPICE_INTERFACE_QXL_MINOR>= 1
+    if (async) {
+        qemu_mutex_lock(&d->async_lock);
+        d->current_async = QXL_UNDEFINED_IO;
+        qemu_mutex_unlock(&d->async_lock);

Add "qxl_send_events(d, QXL_INTERRUPT_IO_CMD)" here?

hw/qxl.h typedef struct PCIQXLDevice { · line 38

Quoted 11 lines
  typedef struct PCIQXLDevice {
      PCIDevice          pci;
      SimpleSpiceDisplay ssd;
hw/qxl.h +4 -0
@@ -30,6 +32,11 @@ typedef struct PCIQXLDevice {
      int32_t            num_memslots;
      int32_t            num_surfaces;
 
+#if SPICE_INTERFACE_QXL_MINOR>= 1
+    uint32_t           current_async;
+    QemuMutex          async_lock;
+#endif

No need to ifdef this.

cheers,
Gerd

#18 lore raw

Re: [Qemu-devel] [PATCHv5 10/12] qxl: add QXL_IO_FLUSH_{SURFACES, RELEASE} for guest S3&S4 support

In reply to Alon Levy
Quoted 11 lines
hw/qxl.c +11 -0
+#if SPICE_INTERFACE_QXL_MINOR>= 1
+    case QXL_IO_FLUSH_RELEASE: {
+        QXLReleaseRing *ring =&d->ram->release_ring;
+        if (ring->prod - ring->cons + 1 == ring->num_items) {
+            fprintf(stderr,
+                "ERROR: no flush, full release ring [p%d,%dc]\n",
+                ring->prod, ring->cons);
+        }
+        qxl_push_free_res(d, 1 /* flush */);
+        dprint(d, 1, "QXL_IO_FLUSH_RELEASE exit (%s, s#=%d, res#=%d,%p)\n",
+            qxl_mode_to_string(d->mode), d->guest_surfaces.count,

hw/qxl.c static void ioport_write(void *opaque, uint32_t addr, uint32_t val) · line 1358

Quoted 10 lines
hw/qxl.c +10 -0
+            d->num_free_res, d->last_release);
+        break;
+    }
+    case QXL_IO_FLUSH_SURFACES_ASYNC:
+        dprint(d, 1, "QXL_IO_FLUSH_SURFACES_ASYNC (%d) (%s, s#=%d, res#=%d)\n",
+               val, qxl_mode_to_string(d->mode), d->guest_surfaces.count,
+               d->num_free_res);
+        qxl_spice_flush_surfaces_async(d);
+#endif
+        break;

The last two lines should be swapped I guess.
Doesn't harm, but looks a bit odd ...

cheers,
Gerd

#15 lore raw

Re: [Qemu-devel] [PATCHv5 09/12] qxl: async io support using new spice api

In reply to Alon Levy
Quoted 7 lines · Alon Levy

Some of the QXL port i/o commands are waiting for the spice server to complete certain actions. Add async versions for these commands, so we don't block the vcpu while the spice server processses the command. Instead the qxl device will raise an IRQ when done.

The async command processing relies on an added QXLInterface::async_complete and added QXLWorker::*_async additions, in spice server qxl>= 3.1

Applying: qxl: async io support using new spice api === checkpatch complains ===
WARNING: labels should not be indented #320: FILE: hw/qxl.c:1207:
+ async_common:

total: 0 errors, 1 warnings, 574 lines checked

cheers,
Gerd

#21 lore raw

Re: [Qemu-devel] [PATCHv5 11/12] qxl: bump pci rev

In reply to Alon Levy

hw/qxl.h typedef struct PCIQXLDevice { · line 111

Quoted 5 lines
hw/qxl.h +5 -0
+#if SPICE_INTERFACE_QXL_MINOR>= 1
+#define QXL_DEFAULT_REVISION QXL_REVISION_STABLE_V10
+#else
+#define QXL_DEFAULT_REVISION QXL_REVISION_STABLE_V06
+#endif

Does that actually build with old spice-protocol? I don't think so ...

cheers,
Gerd

#24 lore raw

Re: [Qemu-devel] [PATCHv5 12/12] qxl: use QXL_REVISION_*

In reply to Alon Levy

Hi,

hw/qxl.c static int qxl_init_common(PCIQXLDevice *qxl) · line 1592

Quoted 4 lines
hw/qxl.c +4 -0
+#if SPICE_INTERFACE_QXL_MINOR>= 1
+    qemu_mutex_init(&qxl->async_lock);
+    qxl->current_async = QXL_UNDEFINED_IO;
+#endif

That surely belongs into another patch ...

hw/qxl.c static int qxl_init_common(PCIQXLDevice *qxl) · line 1595

Quoted 2 lines
hw/qxl.c +2 -0
+    case QXL_REVISION_STABLE_V04: /* spice 0.4 -- qxl-1 */
+    case QXL_REVISION_STABLE_V06: /* spice 0.6 -- qxl-2 */

I think we should just not use these defines for now.

In a year or so when the new bits are in widespread use we can raise the minimum required spice-server+spice-protocol versions, cleanup the ifdef mess and also use QXL_REVISION_STABLE_V04.

cheers,
Gerd

author
#7 lore raw

Re: [Qemu-devel] [PATCHv5 05/12] qxl: add io_port_to_string

In reply to Gerd Hoffmann
Quoted 8 lines · Gerd Hoffmann

Hi,

hw/qxl.c static const char *qxl_mode_to_string(int mode) · line 419

Quoted 3 lines
hw/qxl.c +3 -0
+    switch (io_port) {
+    case QXL_IO_NOTIFY_CMD:
+        return "QXL_IO_NOTIFY_CMD";

Wasn't the plan to make this an array?

yes. Somehow I sent the wrong patch. No idea how I managed to do that.

Quoted 3 lines

cheers,
Gerd

author
#13 lore raw

Re: [Qemu-devel] [PATCHv5 09/12] qxl: async io support using new spice api

In reply to Gerd Hoffmann
Quoted 19 lines · Gerd Hoffmann
Quoted 8 lines
     case QXL_IO_DESTROY_PRIMARY:
         if (val != 0) {
hw/qxl.c +4 -2
-            qxl_guest_bug(d, "QXL_IO_DESTROY_PRIMARY: val != 0");
-            break;
+            qxl_guest_bug(d, "QXL_IO_DESTROY_PRIMARY (async=%d): val != 0",
+                          async);
+            goto cancel_async;
+        }

hw/qxl.c static void ioport_write(void *opaque, uint32_t addr, uint32_t val) · line 1318

Quoted 10 lines
hw/qxl.c +9 -0
+        dprint(d, 1, "QXL_IO_DESTROY_PRIMARY (async=%d) (%s)\n", async,
+               qxl_mode_to_string(d->mode));
+        qxl_destroy_primary(d, async);
+#if SPICE_INTERFACE_QXL_MINOR>= 1
+        if (d->mode == QXL_MODE_UNDEFINED&&  async == QXL_ASYNC) {
+            dprint(d, 1, "QXL_IO_DESTROY_PRIMARY_ASYNC in %s, ignored\n",
+                    qxl_mode_to_string(d->mode));
+            qxl_send_events(d, QXL_INTERRUPT_IO_CMD);
+            goto cancel_async;
         }
Quoted 1 line

Hmm? Why this is needed?

In this case we don't do any operation (i.e. qxl_destroy_primary is a nop, it checkes d->mode == QXL_MODE_UNDEFINED too) so there will never be an async_complete, so there will never be a qxl_send_events, so we need to send it now.

Quoted 14 lines

hw/qxl.c static void ioport_write(void *opaque, uint32_t addr, uint32_t val) · line 1343

Quoted 12 lines
     default:
         fprintf(stderr, "%s: ioport=0x%x, abort()\n", __FUNCTION__, io_port);
         abort();
     }
hw/qxl.c +7 -0
+    return;
+cancel_async:
+#if SPICE_INTERFACE_QXL_MINOR>= 1
+    if (async) {
+        qemu_mutex_lock(&d->async_lock);
+        d->current_async = QXL_UNDEFINED_IO;
+        qemu_mutex_unlock(&d->async_lock);

Add "qxl_send_events(d, QXL_INTERRUPT_IO_CMD)" here?

no, we want that wen the command is actually complete, on async_complete, where it is already done.

Quoted 8 lines
Quoted 8 lines
 typedef struct PCIQXLDevice {
     PCIDevice          pci;
     SimpleSpiceDisplay ssd;
hw/qxl.h +0 -0
@@ -30,6 +32,11 @@ typedef struct PCIQXLDevice {
     int32_t            num_memslots;
     int32_t            num_surfaces;
 
Quoted 7 lines

hw/qxl.h typedef struct PCIQXLDevice { · line 38

Quoted 4 lines
hw/qxl.h +4 -0
+#if SPICE_INTERFACE_QXL_MINOR>= 1
+    uint32_t           current_async;
+    QemuMutex          async_lock;
+#endif

No need to ifdef this.

missed it.

Quoted 2 lines

cheers,
Gerd

author
#16 lore raw

Re: [Qemu-devel] [PATCHv5 09/12] qxl: async io support using new spice api

In reply to Gerd Hoffmann
Quoted 6 lines · Gerd Hoffmann
Quoted 5 lines · Alon Levy

Some of the QXL port i/o commands are waiting for the spice server to complete certain actions. Add async versions for these commands, so we don't block the vcpu while the spice server processses the command. Instead the qxl device will raise an IRQ when done.

Quoted 9 lines
Quoted 2 lines

The async command processing relies on an added QXLInterface::async_complete and added QXLWorker::*_async additions, in spice server qxl>= 3.1

Applying: qxl: async io support using new spice api === checkpatch complains ===
WARNING: labels should not be indented #320: FILE: hw/qxl.c:1207:
+ async_common:

thanks, my bad, did this after the checkpatch (obviously). I'll go add it to the commit hook.

Quoted 4 lines

total: 0 errors, 1 warnings, 574 lines checked

cheers,
Gerd

author
#19 lore raw

Re: [Qemu-devel] [PATCHv5 10/12] qxl: add QXL_IO_FLUSH_{SURFACES, RELEASE} for guest S3&S4 support

In reply to Gerd Hoffmann
Quoted 16 lines · Gerd Hoffmann
Quoted 16 lines
hw/qxl.c +16 -0
+#if SPICE_INTERFACE_QXL_MINOR>= 1
+    case QXL_IO_FLUSH_RELEASE: {
+        QXLReleaseRing *ring =&d->ram->release_ring;
+        if (ring->prod - ring->cons + 1 == ring->num_items) {
+            fprintf(stderr,
+                "ERROR: no flush, full release ring [p%d,%dc]\n",
+                ring->prod, ring->cons);
+        }
+        qxl_push_free_res(d, 1 /* flush */);
+        dprint(d, 1, "QXL_IO_FLUSH_RELEASE exit (%s, s#=%d, res#=%d,%p)\n",
+            qxl_mode_to_string(d->mode), d->guest_surfaces.count,
+            d->num_free_res, d->last_release);
+        break;
+    }
+    case QXL_IO_FLUSH_SURFACES_ASYNC:
+        dprint(d, 1, "QXL_IO_FLUSH_SURFACES_ASYNC (%d) (%s, s#=%d, res#=%d)\n",
Quoted 8 lines

hw/qxl.c static void ioport_write(void *opaque, uint32_t addr, uint32_t val) · line 1358

Quoted 5 lines
hw/qxl.c +5 -0
+               val, qxl_mode_to_string(d->mode), d->guest_surfaces.count,
+               d->num_free_res);
+        qxl_spice_flush_surfaces_async(d);
+#endif
+        break;

The last two lines should be swapped I guess.
Doesn't harm, but looks a bit odd ...

yep. thanks, will fix.

Quoted 4 lines

cheers,
Gerd

author
#22 lore raw

Re: [Qemu-devel] [PATCHv5 11/12] qxl: bump pci rev

In reply to Gerd Hoffmann
Quoted 8 lines · Gerd Hoffmann

hw/qxl.h typedef struct PCIQXLDevice { · line 111

Quoted 5 lines
hw/qxl.h +5 -0
+#if SPICE_INTERFACE_QXL_MINOR>= 1
+#define QXL_DEFAULT_REVISION QXL_REVISION_STABLE_V10
+#else
+#define QXL_DEFAULT_REVISION QXL_REVISION_STABLE_V06
+#endif

Does that actually build with old spice-protocol? I don't think so ...

no, it won't. /me wonders how I did the compilations. I'll use 2 and 3.

Quoted 3 lines

cheers,
Gerd

author
#25 lore raw

Re: [Qemu-devel] [PATCHv5 12/12] qxl: use QXL_REVISION_*

In reply to Gerd Hoffmann
Quoted 8 lines · Gerd Hoffmann

Hi,

hw/qxl.c static int qxl_init_common(PCIQXLDevice *qxl) · line 1592

Quoted 4 lines
hw/qxl.c +4 -0
+#if SPICE_INTERFACE_QXL_MINOR>= 1
+    qemu_mutex_init(&qxl->async_lock);
+    qxl->current_async = QXL_UNDEFINED_IO;
+#endif

That surely belongs into another patch ...

yes.

Quoted 10 lines

hw/qxl.c static int qxl_init_common(PCIQXLDevice *qxl) · line 1595

Quoted 3 lines
hw/qxl.c +2 -0
+    case QXL_REVISION_STABLE_V04: /* spice 0.4 -- qxl-1 */
+    case QXL_REVISION_STABLE_V06: /* spice 0.6 -- qxl-2 */

I think we should just not use these defines for now.

In a year or so when the new bits are in widespread use we can raise the minimum required spice-server+spice-protocol versions, cleanup the ifdef mess and also use QXL_REVISION_STABLE_V04.

ok. I'll drop this patch (at least the bits fitting the patch header).

Quoted 3 lines

cheers,
Gerd

#14 lore raw

Re: [Qemu-devel] [PATCHv5 09/12] qxl: async io support using new spice api

In reply to Alon Levy

Hi,

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
hw/qxl.c +7 -0
+        qxl_destroy_primary(d, async);
+#if SPICE_INTERFACE_QXL_MINOR>= 1
+        if (d->mode == QXL_MODE_UNDEFINED&&   async == QXL_ASYNC) {
+            dprint(d, 1, "QXL_IO_DESTROY_PRIMARY_ASYNC in %s, ignored\n",
+                    qxl_mode_to_string(d->mode));
+            qxl_send_events(d, QXL_INTERRUPT_IO_CMD);
+            goto cancel_async;
          }
Quoted 4 lines
Quoted 1 line

Hmm? Why this is needed?

In this case we don't do any operation (i.e. qxl_destroy_primary is a nop, it checkes d->mode == QXL_MODE_UNDEFINED too) so there will never be an async_complete, so there will never be a qxl_send_events, so we need to send it now.

Ok. Maybe make qxl_destroy_primary return an error in case there is no primary to destroy, then catch this here? Makes more clear what is going on here.

Quoted 15 lines
Quoted 14 lines

hw/qxl.c static void ioport_write(void *opaque, uint32_t addr, uint32_t val) · line 1343

Quoted 12 lines
      default:
          fprintf(stderr, "%s: ioport=0x%x, abort()\n", __FUNCTION__, io_port);
          abort();
      }
hw/qxl.c +7 -0
+    return;
+cancel_async:
+#if SPICE_INTERFACE_QXL_MINOR>= 1
+    if (async) {
+        qemu_mutex_lock(&d->async_lock);
+        d->current_async = QXL_UNDEFINED_IO;
+        qemu_mutex_unlock(&d->async_lock);

Add "qxl_send_events(d, QXL_INTERRUPT_IO_CMD)" here?

Quoted 2 lines

no, we want that wen the command is actually complete, on async_complete, where it is already done.

That is the cancel code path, i.e. the guest did a async request but we don't submit one to the spice-server because some sanity check failed, so we never get a complete callback. Thats why I think we should raise the QXL_INTERRUPT_IO_CMD interrupt here instead.

cheers,
Gerd