Blame 0017-qxl-error-handling-fixes-and-cleanups.patch

Justin M. Forbes fc5c27
>From 4b61f7ca2ed63deb1d35c17150b53a1661f395f7 Mon Sep 17 00:00:00 2001
Justin M. Forbes 13f703
From: Gerd Hoffmann <kraxel@redhat.com>
Justin M. Forbes 13f703
Date: Thu, 30 Jun 2011 10:41:36 +0200
Justin M. Forbes fc5c27
Subject: [PATCH 17/28] qxl: error handling fixes and cleanups.
Justin M. Forbes 13f703
Justin M. Forbes 13f703
Add qxl_guest_bug() function which is supposed to be called in case
Justin M. Forbes 13f703
sanity checks of guest requests fail.  It raises an error IRQ and
Justin M. Forbes 13f703
logs a message in case guest debugging is enabled.
Justin M. Forbes 13f703
Justin M. Forbes 13f703
Make PANIC_ON() abort instead of exit.  That macro should be used
Justin M. Forbes 13f703
for qemu bugs only, any guest-triggerable stuff should use the new
Justin M. Forbes 13f703
qxl_guest_bug() function instead.
Justin M. Forbes 13f703
Justin M. Forbes 13f703
Convert a few easy cases from PANIC_ON() to qxl_guest_bug() to
Justin M. Forbes 13f703
show intended usage.
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 |   34 ++++++++++++++++++++++++++++++----
Justin M. Forbes 13f703
 hw/qxl.h |    3 ++-
Justin M. Forbes 13f703
 2 files changed, 32 insertions(+), 5 deletions(-)
Justin M. Forbes 13f703
Justin M. Forbes 13f703
diff --git a/hw/qxl.c b/hw/qxl.c
Justin M. Forbes 13f703
index 6e66021..28c8b5d 100644
Justin M. Forbes 13f703
--- a/hw/qxl.c
Justin M. Forbes 13f703
+++ b/hw/qxl.c
Justin M. Forbes 13f703
@@ -125,6 +125,16 @@ static void qxl_reset_memslots(PCIQXLDevice *d);
Justin M. Forbes 13f703
 static void qxl_reset_surfaces(PCIQXLDevice *d);
Justin M. Forbes 13f703
 static void qxl_ring_set_dirty(PCIQXLDevice *qxl);
Justin M. Forbes 13f703
 
Justin M. Forbes 13f703
+void qxl_guest_bug(PCIQXLDevice *qxl, const char *msg)
Justin M. Forbes 13f703
+{
Justin M. Forbes 13f703
+#if SPICE_INTERFACE_QXL_MINOR >= 1
Justin M. Forbes 13f703
+    qxl_send_events(qxl, QXL_INTERRUPT_ERROR);
Justin M. Forbes 13f703
+#endif
Justin M. Forbes 13f703
+    if (qxl->guestdebug) {
Justin M. Forbes 13f703
+        fprintf(stderr, "qxl-%d: guest bug: %s\n", qxl->id, msg);
Justin M. Forbes 13f703
+    }
Justin M. Forbes 13f703
+}
Justin M. Forbes 13f703
+
Justin M. Forbes 13f703
 
Justin M. Forbes 13f703
 void qxl_spice_update_area(PCIQXLDevice *qxl, uint32_t surface_id,
Justin M. Forbes 13f703
                            struct QXLRect *area, struct QXLRect *dirty_rects,
Justin M. Forbes 13f703
@@ -1091,22 +1101,38 @@ static void ioport_write(void *opaque, uint32_t addr, uint32_t val)
Justin M. Forbes 13f703
         qxl_hard_reset(d, 0);
Justin M. Forbes 13f703
         break;
Justin M. Forbes 13f703
     case QXL_IO_MEMSLOT_ADD:
Justin M. Forbes 13f703
-        PANIC_ON(val >= NUM_MEMSLOTS);
Justin M. Forbes 13f703
-        PANIC_ON(d->guest_slots[val].active);
Justin M. Forbes 13f703
+        if (val >= NUM_MEMSLOTS) {
Justin M. Forbes 13f703
+            qxl_guest_bug(d, "QXL_IO_MEMSLOT_ADD: val out of range");
Justin M. Forbes 13f703
+            break;
Justin M. Forbes 13f703
+        }
Justin M. Forbes 13f703
+        if (d->guest_slots[val].active) {
Justin M. Forbes 13f703
+            qxl_guest_bug(d, "QXL_IO_MEMSLOT_ADD: memory slot already active");
Justin M. Forbes 13f703
+            break;
Justin M. Forbes 13f703
+        }
Justin M. Forbes 13f703
         d->guest_slots[val].slot = d->ram->mem_slot;
Justin M. Forbes 13f703
         qxl_add_memslot(d, val, 0);
Justin M. Forbes 13f703
         break;
Justin M. Forbes 13f703
     case QXL_IO_MEMSLOT_DEL:
Justin M. Forbes 13f703
+        if (val >= NUM_MEMSLOTS) {
Justin M. Forbes 13f703
+            qxl_guest_bug(d, "QXL_IO_MEMSLOT_DEL: val out of range");
Justin M. Forbes 13f703
+            break;
Justin M. Forbes 13f703
+        }
Justin M. Forbes 13f703
         qxl_del_memslot(d, val);
Justin M. Forbes 13f703
         break;
Justin M. Forbes 13f703
     case QXL_IO_CREATE_PRIMARY:
Justin M. Forbes 13f703
-        PANIC_ON(val != 0);
Justin M. Forbes 13f703
+        if (val != 0) {
Justin M. Forbes 13f703
+            qxl_guest_bug(d, "QXL_IO_CREATE_PRIMARY: val != 0");
Justin M. Forbes 13f703
+            break;
Justin M. Forbes 13f703
+        }
Justin M. Forbes 13f703
         dprint(d, 1, "QXL_IO_CREATE_PRIMARY\n");
Justin M. Forbes 13f703
         d->guest_primary.surface = d->ram->create_surface;
Justin M. Forbes 13f703
         qxl_create_guest_primary(d, 0);
Justin M. Forbes 13f703
         break;
Justin M. Forbes 13f703
     case QXL_IO_DESTROY_PRIMARY:
Justin M. Forbes 13f703
-        PANIC_ON(val != 0);
Justin M. Forbes 13f703
+        if (val != 0) {
Justin M. Forbes 13f703
+            qxl_guest_bug(d, "QXL_IO_DESTROY_PRIMARY: val != 0");
Justin M. Forbes 13f703
+            break;
Justin M. Forbes 13f703
+        }
Justin M. Forbes 13f703
         dprint(d, 1, "QXL_IO_DESTROY_PRIMARY (%s)\n", qxl_mode_to_string(d->mode));
Justin M. Forbes 13f703
         qxl_destroy_primary(d);
Justin M. Forbes 13f703
         break;
Justin M. Forbes 13f703
diff --git a/hw/qxl.h b/hw/qxl.h
Justin M. Forbes 13f703
index 5d0e85e..5db9aae 100644
Justin M. Forbes 13f703
--- a/hw/qxl.h
Justin M. Forbes 13f703
+++ b/hw/qxl.h
Justin M. Forbes 13f703
@@ -86,7 +86,7 @@ typedef struct PCIQXLDevice {
Justin M. Forbes 13f703
 
Justin M. Forbes 13f703
 #define PANIC_ON(x) if ((x)) {                         \
Justin M. Forbes 13f703
     printf("%s: PANIC %s failed\n", __FUNCTION__, #x); \
Justin M. Forbes 13f703
-    exit(-1);                                          \
Justin M. Forbes 13f703
+    abort();                                           \
Justin M. Forbes 13f703
 }
Justin M. Forbes 13f703
 
Justin M. Forbes 13f703
 #define dprint(_qxl, _level, _fmt, ...)                                 \
Justin M. Forbes 13f703
@@ -99,6 +99,7 @@ typedef struct PCIQXLDevice {
Justin M. Forbes 13f703
 
Justin M. Forbes 13f703
 /* qxl.c */
Justin M. Forbes 13f703
 void *qxl_phys2virt(PCIQXLDevice *qxl, QXLPHYSICAL phys, int group_id);
Justin M. Forbes 13f703
+void qxl_guest_bug(PCIQXLDevice *qxl, const char *msg);
Justin M. Forbes 13f703
 
Justin M. Forbes 13f703
 void qxl_spice_update_area(PCIQXLDevice *qxl, uint32_t surface_id,
Justin M. Forbes 13f703
                            struct QXLRect *area, struct QXLRect *dirty_rects,
Justin M. Forbes 13f703
-- 
Justin M. Forbes 13f703
1.7.5.1
Justin M. Forbes 13f703