Blame SOURCES/kvm-qxl-store-memory-region-and-offset-instead-of-pointe.patch

34b321
From 8f25ff7e1496ce8a26edacfa01c64f3a98c564a0 Mon Sep 17 00:00:00 2001
34b321
From: Gerd Hoffmann <kraxel@redhat.com>
34b321
Date: Fri, 22 Jul 2016 09:34:39 +0200
34b321
Subject: [PATCH 2/4] qxl: store memory region and offset instead of pointer
34b321
 for guest slots
34b321
34b321
RH-Author: Gerd Hoffmann <kraxel@redhat.com>
34b321
Message-id: <1469180081-28522-3-git-send-email-kraxel@redhat.com>
34b321
Patchwork-id: 71314
34b321
O-Subject: [RHEL-7.3 qemu-kvm PATCH v2 2/4] qxl: store memory region and offset instead of pointer for guest slots
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
Store MemoryRegion and offset instead of a pointer for each qxl memory
34b321
slot, so we can easily figure in which memory region an qxl object
34b321
stored.
34b321
34b321
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
34b321
Message-id: 1466597244-5938-2-git-send-email-kraxel@redhat.com
34b321
(cherry picked from commit 3cb5158f15604a9f50287f2f06777d5835ff4c15)
34b321
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
34b321
---
34b321
 hw/display/qxl.c | 15 +++++++++++----
34b321
 hw/display/qxl.h |  3 ++-
34b321
 2 files changed, 13 insertions(+), 5 deletions(-)
34b321
34b321
diff --git a/hw/display/qxl.c b/hw/display/qxl.c
34b321
index 5e1ecd8..de5770e 100644
34b321
--- a/hw/display/qxl.c
34b321
+++ b/hw/display/qxl.c
34b321
@@ -1232,6 +1232,7 @@ static int qxl_add_memslot(PCIQXLDevice *d, uint32_t slot_id, uint64_t delta,
34b321
     int pci_region;
34b321
     pcibus_t pci_start;
34b321
     pcibus_t pci_end;
34b321
+    MemoryRegion *mr;
34b321
     intptr_t virt_start;
34b321
     QXLDevMemSlot memslot;
34b321
     int i;
34b321
@@ -1278,11 +1279,11 @@ static int qxl_add_memslot(PCIQXLDevice *d, uint32_t slot_id, uint64_t delta,
34b321
 
34b321
     switch (pci_region) {
34b321
     case QXL_RAM_RANGE_INDEX:
34b321
-        virt_start = (intptr_t)memory_region_get_ram_ptr(&d->vga.vram);
34b321
+        mr = &d->vga.vram;
34b321
         break;
34b321
     case QXL_VRAM_RANGE_INDEX:
34b321
     case 4 /* vram 64bit */:
34b321
-        virt_start = (intptr_t)memory_region_get_ram_ptr(&d->vram_bar);
34b321
+        mr = &d->vram_bar;
34b321
         break;
34b321
     default:
34b321
         /* should not happen */
34b321
@@ -1290,6 +1291,7 @@ static int qxl_add_memslot(PCIQXLDevice *d, uint32_t slot_id, uint64_t delta,
34b321
         return 1;
34b321
     }
34b321
 
34b321
+    virt_start = (intptr_t)memory_region_get_ram_ptr(mr);
34b321
     memslot.slot_id = slot_id;
34b321
     memslot.slot_group_id = MEMSLOT_GROUP_GUEST; /* guest group */
34b321
     memslot.virt_start = virt_start + (guest_start - pci_start);
34b321
@@ -1299,7 +1301,8 @@ static int qxl_add_memslot(PCIQXLDevice *d, uint32_t slot_id, uint64_t delta,
34b321
     qxl_rom_set_dirty(d);
34b321
 
34b321
     qemu_spice_add_memslot(&d->ssd, &memslot, async);
34b321
-    d->guest_slots[slot_id].ptr = (void*)memslot.virt_start;
34b321
+    d->guest_slots[slot_id].mr = mr;
34b321
+    d->guest_slots[slot_id].offset = memslot.virt_start - virt_start;
34b321
     d->guest_slots[slot_id].size = memslot.virt_end - memslot.virt_start;
34b321
     d->guest_slots[slot_id].delta = delta;
34b321
     d->guest_slots[slot_id].active = 1;
34b321
@@ -1366,6 +1369,7 @@ void *qxl_phys2virt(PCIQXLDevice *qxl, QXLPHYSICAL pqxl, int group_id)
34b321
 {
34b321
     uint64_t offset;
34b321
     uint32_t slot;
34b321
+    void *ptr;
34b321
 
34b321
     switch (group_id) {
34b321
     case MEMSLOT_GROUP_HOST:
34b321
@@ -1375,7 +1379,10 @@ void *qxl_phys2virt(PCIQXLDevice *qxl, QXLPHYSICAL pqxl, int group_id)
34b321
         if (!qxl_get_check_slot_offset(qxl, pqxl, &slot, &offset)) {
34b321
             return NULL;
34b321
         }
34b321
-        return qxl->guest_slots[slot].ptr + offset;
34b321
+        ptr = memory_region_get_ram_ptr(qxl->guest_slots[slot].mr);
34b321
+        ptr += qxl->guest_slots[slot].offset;
34b321
+        ptr += offset;
34b321
+        return ptr;
34b321
     }
34b321
     return NULL;
34b321
 }
34b321
diff --git a/hw/display/qxl.h b/hw/display/qxl.h
34b321
index 5247ce9..f3f51e2 100644
34b321
--- a/hw/display/qxl.h
34b321
+++ b/hw/display/qxl.h
34b321
@@ -49,7 +49,8 @@ typedef struct PCIQXLDevice {
34b321
 
34b321
     struct guest_slots {
34b321
         QXLMemSlot     slot;
34b321
-        void           *ptr;
34b321
+        MemoryRegion   *mr;
34b321
+        uint64_t       offset;
34b321
         uint64_t       size;
34b321
         uint64_t       delta;
34b321
         uint32_t       active;
34b321
-- 
34b321
1.8.3.1
34b321