This allows 'peer' ivshmem guests to detach from shared memory before migration
and re-attach after migration is complete.

Signed-off-by: Cam Macdonell <c...@cs.ualberta.ca>
---
 hw/ivshmem.c |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/hw/ivshmem.c b/hw/ivshmem.c
index 06dce70..9254fad 100644
--- a/hw/ivshmem.c
+++ b/hw/ivshmem.c
@@ -68,6 +68,7 @@ typedef struct IVShmemState {
     int nb_peers; /* how many guests we have space for */
     int max_peer; /* maximum numbered peer */
 
+    void *shm_ptr;
     int vm_id;
     uint32_t vectors;
     uint32_t features;
@@ -365,14 +366,13 @@ static int check_shm_size(IVShmemState *s, int fd) {
  * create the BAR and map the memory immediately */
 static void create_shared_memory_BAR(IVShmemState *s, int fd) {
 
-    void * ptr;
-
     s->shm_fd = fd;
 
-    ptr = mmap(0, s->ivshmem_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
+    s->shm_ptr = mmap(0, s->ivshmem_size, PROT_READ|PROT_WRITE,
+                                                            MAP_SHARED, fd, 0);
 
     s->ivshmem_offset = qemu_ram_alloc_from_ptr(&s->dev.qdev, "ivshmem.bar2",
-                                                        s->ivshmem_size, ptr);
+                                                s->ivshmem_size, s->shm_ptr);
 
     /* region for shared memory */
     pci_register_bar(&s->dev, 2, s->ivshmem_size,
@@ -797,6 +797,10 @@ static int pci_ivshmem_uninit(PCIDevice *dev)
 {
     IVShmemState *s = DO_UPCAST(IVShmemState, dev, dev);
 
+    cpu_register_physical_memory(s->shm_pci_addr, s->ivshmem_size,
+                                                        IO_MEM_UNASSIGNED);
+    qemu_ram_free_from_ptr(s->ivshmem_offset);
+    munmap(s->shm_ptr, s->ivshmem_size);
     cpu_unregister_io_memory(s->ivshmem_mmio_io_addr);
     unregister_savevm(&dev->qdev, "ivshmem", s);
 
-- 
1.7.0.4


Reply via email to