34b321
From 24a604e857d2797c3da9852bcbea75f2f9e6961c Mon Sep 17 00:00:00 2001
34b321
From: Gerd Hoffmann <kraxel@redhat.com>
34b321
Date: Fri, 22 Jul 2016 09:34:38 +0200
34b321
Subject: [PATCH 1/4] qxl: factor out qxl_get_check_slot_offset
34b321
34b321
RH-Author: Gerd Hoffmann <kraxel@redhat.com>
34b321
Message-id: <1469180081-28522-2-git-send-email-kraxel@redhat.com>
34b321
Patchwork-id: 71317
34b321
O-Subject: [RHEL-7.3 qemu-kvm PATCH v2 1/4] qxl: factor out qxl_get_check_slot_offset
34b321
Bugzilla: 1355730
34b321
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
34b321
RH-Acked-by: John Snow <jsnow@redhat.com>
34b321
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
34b321
34b321
New helper function which translates a qxl physical address into
34b321
memory slot and offset.  Also applies sanity checks.  Factored out
34b321
from qxl_phys2virt.  No functional change.
34b321
34b321
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
34b321
Message-id: 1466597244-5938-1-git-send-email-kraxel@redhat.com
34b321
(cherry picked from commit 726bdf653aca9b87e28c9a56dd94c4667ddfacbc)
34b321
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
34b321
---
34b321
 hw/display/qxl.c | 59 ++++++++++++++++++++++++++++++++++++--------------------
34b321
 1 file changed, 38 insertions(+), 21 deletions(-)
34b321
34b321
diff --git a/hw/display/qxl.c b/hw/display/qxl.c
34b321
index 748dfce..5e1ecd8 100644
34b321
--- a/hw/display/qxl.c
34b321
+++ b/hw/display/qxl.c
34b321
@@ -1326,36 +1326,53 @@ static void qxl_reset_surfaces(PCIQXLDevice *d)
34b321
 }
34b321
 
34b321
 /* can be also called from spice server thread context */
34b321
-void *qxl_phys2virt(PCIQXLDevice *qxl, QXLPHYSICAL pqxl, int group_id)
34b321
+static bool qxl_get_check_slot_offset(PCIQXLDevice *qxl, QXLPHYSICAL pqxl,
34b321
+                                      uint32_t *s, uint64_t *o)
34b321
 {
34b321
     uint64_t phys   = le64_to_cpu(pqxl);
34b321
     uint32_t slot   = (phys >> (64 -  8)) & 0xff;
34b321
     uint64_t offset = phys & 0xffffffffffff;
34b321
 
34b321
-    switch (group_id) {
34b321
-    case MEMSLOT_GROUP_HOST:
34b321
-        return (void *)(intptr_t)offset;
34b321
-    case MEMSLOT_GROUP_GUEST:
34b321
-        if (slot >= NUM_MEMSLOTS) {
34b321
-            qxl_set_guest_bug(qxl, "slot too large %d >= %d", slot,
34b321
-                              NUM_MEMSLOTS);
34b321
-            return NULL;
34b321
-        }
34b321
-        if (!qxl->guest_slots[slot].active) {
34b321
-            qxl_set_guest_bug(qxl, "inactive slot %d\n", slot);
34b321
-            return NULL;
34b321
-        }
34b321
-        if (offset < qxl->guest_slots[slot].delta) {
34b321
-            qxl_set_guest_bug(qxl,
34b321
+    if (slot >= NUM_MEMSLOTS) {
34b321
+        qxl_set_guest_bug(qxl, "slot too large %d >= %d", slot,
34b321
+                          NUM_MEMSLOTS);
34b321
+        return false;
34b321
+    }
34b321
+    if (!qxl->guest_slots[slot].active) {
34b321
+        qxl_set_guest_bug(qxl, "inactive slot %d\n", slot);
34b321
+        return false;
34b321
+    }
34b321
+    if (offset < qxl->guest_slots[slot].delta) {
34b321
+        qxl_set_guest_bug(qxl,
34b321
                           "slot %d offset %"PRIu64" < delta %"PRIu64"\n",
34b321
                           slot, offset, qxl->guest_slots[slot].delta);
34b321
-            return NULL;
34b321
-        }
34b321
-        offset -= qxl->guest_slots[slot].delta;
34b321
-        if (offset > qxl->guest_slots[slot].size) {
34b321
-            qxl_set_guest_bug(qxl,
34b321
+        return false;
34b321
+    }
34b321
+    offset -= qxl->guest_slots[slot].delta;
34b321
+    if (offset > qxl->guest_slots[slot].size) {
34b321
+        qxl_set_guest_bug(qxl,
34b321
                           "slot %d offset %"PRIu64" > size %"PRIu64"\n",
34b321
                           slot, offset, qxl->guest_slots[slot].size);
34b321
+        return false;
34b321
+    }
34b321
+
34b321
+    *s = slot;
34b321
+    *o = offset;
34b321
+    return true;
34b321
+}
34b321
+
34b321
+/* can be also called from spice server thread context */
34b321
+void *qxl_phys2virt(PCIQXLDevice *qxl, QXLPHYSICAL pqxl, int group_id)
34b321
+{
34b321
+    uint64_t offset;
34b321
+    uint32_t slot;
34b321
+
34b321
+    switch (group_id) {
34b321
+    case MEMSLOT_GROUP_HOST:
34b321
+        offset = le64_to_cpu(pqxl) & 0xffffffffffff;
34b321
+        return (void *)(intptr_t)offset;
34b321
+    case MEMSLOT_GROUP_GUEST:
34b321
+        if (!qxl_get_check_slot_offset(qxl, pqxl, &slot, &offset)) {
34b321
             return NULL;
34b321
         }
34b321
         return qxl->guest_slots[slot].ptr + offset;
34b321
-- 
34b321
1.8.3.1
34b321