Blame 0015-qxl-fix-surface-tracking-locking.patch

Justin M. Forbes fc5c27
>From b2b956cfda5fb144d9faa10b7c5894833feb7d30 Mon Sep 17 00:00:00 2001
Justin M. Forbes 13f703
From: Gerd Hoffmann <kraxel@redhat.com>
Justin M. Forbes 13f703
Date: Wed, 29 Jun 2011 10:24:05 +0200
Justin M. Forbes fc5c27
Subject: [PATCH 15/28] qxl: fix surface tracking & locking
Justin M. Forbes 13f703
Justin M. Forbes 13f703
Surface tracking needs proper locking since it is used from vcpu and spice
Justin M. Forbes 13f703
worker threads, add it.  Also reset the surface counter when zapping all
Justin M. Forbes 13f703
surfaces.
Justin M. Forbes 13f703
Justin M. Forbes 13f703
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Justin M. Forbes 13f703
---
Justin M. Forbes 13f703
 hw/qxl.c |   13 ++++++++++++-
Justin M. Forbes 13f703
 hw/qxl.h |    2 ++
Justin M. Forbes 13f703
 2 files changed, 14 insertions(+), 1 deletions(-)
Justin M. Forbes 13f703
Justin M. Forbes 13f703
diff --git a/hw/qxl.c b/hw/qxl.c
Justin M. Forbes 13f703
index 803a364..416bd48 100644
Justin M. Forbes 13f703
--- a/hw/qxl.c
Justin M. Forbes 13f703
+++ b/hw/qxl.c
Justin M. Forbes 13f703
@@ -137,7 +137,12 @@ void qxl_spice_update_area(PCIQXLDevice *qxl, uint32_t surface_id,
Justin M. Forbes 13f703
 
Justin M. Forbes 13f703
 void qxl_spice_destroy_surface_wait(PCIQXLDevice *qxl, uint32_t id)
Justin M. Forbes 13f703
 {
Justin M. Forbes 13f703
+    qemu_mutex_lock(&qxl->track_lock);
Justin M. Forbes 13f703
+    PANIC_ON(id >= NUM_SURFACES);
Justin M. Forbes 13f703
     qxl->ssd.worker->destroy_surface_wait(qxl->ssd.worker, id);
Justin M. Forbes 13f703
+    qxl->guest_surfaces.cmds[id] = 0;
Justin M. Forbes 13f703
+    qxl->guest_surfaces.count--;
Justin M. Forbes 13f703
+    qemu_mutex_unlock(&qxl->track_lock);
Justin M. Forbes 13f703
 }
Justin M. Forbes 13f703
 
Justin M. Forbes 13f703
 void qxl_spice_loadvm_commands(PCIQXLDevice *qxl, struct QXLCommandExt *ext,
Justin M. Forbes 13f703
@@ -158,7 +163,11 @@ void qxl_spice_reset_memslots(PCIQXLDevice *qxl)
Justin M. Forbes 13f703
 
Justin M. Forbes 13f703
 void qxl_spice_destroy_surfaces(PCIQXLDevice *qxl)
Justin M. Forbes 13f703
 {
Justin M. Forbes 13f703
+    qemu_mutex_lock(&qxl->track_lock);
Justin M. Forbes 13f703
     qxl->ssd.worker->destroy_surfaces(qxl->ssd.worker);
Justin M. Forbes 13f703
+    memset(&qxl->guest_surfaces.cmds, 0, sizeof(qxl->guest_surfaces.cmds));
Justin M. Forbes 13f703
+    qxl->guest_surfaces.count = 0;
Justin M. Forbes 13f703
+    qemu_mutex_unlock(&qxl->track_lock);
Justin M. Forbes 13f703
 }
Justin M. Forbes 13f703
 
Justin M. Forbes 13f703
 void qxl_spice_reset_image_cache(PCIQXLDevice *qxl)
Justin M. Forbes 13f703
@@ -317,6 +326,7 @@ static void qxl_track_command(PCIQXLDevice *qxl, struct QXLCommandExt *ext)
Justin M. Forbes 13f703
         QXLSurfaceCmd *cmd = qxl_phys2virt(qxl, ext->cmd.data, ext->group_id);
Justin M. Forbes 13f703
         uint32_t id = le32_to_cpu(cmd->surface_id);
Justin M. Forbes 13f703
         PANIC_ON(id >= NUM_SURFACES);
Justin M. Forbes 13f703
+        qemu_mutex_lock(&qxl->track_lock);
Justin M. Forbes 13f703
         if (cmd->type == QXL_SURFACE_CMD_CREATE) {
Justin M. Forbes 13f703
             qxl->guest_surfaces.cmds[id] = ext->cmd.data;
Justin M. Forbes 13f703
             qxl->guest_surfaces.count++;
Justin M. Forbes 13f703
@@ -327,6 +337,7 @@ static void qxl_track_command(PCIQXLDevice *qxl, struct QXLCommandExt *ext)
Justin M. Forbes 13f703
             qxl->guest_surfaces.cmds[id] = 0;
Justin M. Forbes 13f703
             qxl->guest_surfaces.count--;
Justin M. Forbes 13f703
         }
Justin M. Forbes 13f703
+        qemu_mutex_unlock(&qxl->track_lock);
Justin M. Forbes 13f703
         break;
Justin M. Forbes 13f703
     }
Justin M. Forbes 13f703
     case QXL_CMD_CURSOR:
Justin M. Forbes 13f703
@@ -863,7 +874,6 @@ static void qxl_reset_surfaces(PCIQXLDevice *d)
Justin M. Forbes 13f703
     dprint(d, 1, "%s:\n", __FUNCTION__);
Justin M. Forbes 13f703
     d->mode = QXL_MODE_UNDEFINED;
Justin M. Forbes 13f703
     qxl_spice_destroy_surfaces(d);
Justin M. Forbes 13f703
-    memset(&d->guest_surfaces.cmds, 0, sizeof(d->guest_surfaces.cmds));
Justin M. Forbes 13f703
 }
Justin M. Forbes 13f703
 
Justin M. Forbes 13f703
 /* called from spice server thread context only */
Justin M. Forbes 13f703
@@ -1283,6 +1293,7 @@ static int qxl_init_common(PCIQXLDevice *qxl)
Justin M. Forbes 13f703
     qxl->generation = 1;
Justin M. Forbes 13f703
     qxl->num_memslots = NUM_MEMSLOTS;
Justin M. Forbes 13f703
     qxl->num_surfaces = NUM_SURFACES;
Justin M. Forbes 13f703
+    qemu_mutex_init(&qxl->track_lock);
Justin M. Forbes 13f703
 
Justin M. Forbes 13f703
     switch (qxl->revision) {
Justin M. Forbes 13f703
     case 1: /* spice 0.4 -- qxl-1 */
Justin M. Forbes 13f703
diff --git a/hw/qxl.h b/hw/qxl.h
Justin M. Forbes 13f703
index e62b9d0..5d0e85e 100644
Justin M. Forbes 13f703
--- a/hw/qxl.h
Justin M. Forbes 13f703
+++ b/hw/qxl.h
Justin M. Forbes 13f703
@@ -55,6 +55,8 @@ typedef struct PCIQXLDevice {
Justin M. Forbes 13f703
     } guest_surfaces;
Justin M. Forbes 13f703
     QXLPHYSICAL        guest_cursor;
Justin M. Forbes 13f703
 
Justin M. Forbes 13f703
+    QemuMutex          track_lock;
Justin M. Forbes 13f703
+
Justin M. Forbes 13f703
     /* thread signaling */
Justin M. Forbes 13f703
     pthread_t          main;
Justin M. Forbes 13f703
     int                pipe[2];
Justin M. Forbes 13f703
-- 
Justin M. Forbes 13f703
1.7.5.1
Justin M. Forbes 13f703