Blame SOURCES/kvm-ivshmem-Fix-unplug-of-device-ivshmem-plain.patch

383d26
From 1342ea3b7a14657c3e9f6e38ea3dcc0c2f42939e Mon Sep 17 00:00:00 2001
383d26
From: Markus Armbruster <armbru@redhat.com>
383d26
Date: Mon, 29 Oct 2018 07:01:37 +0100
383d26
Subject: [PATCH 07/22] ivshmem: Fix unplug of device "ivshmem-plain"
383d26
MIME-Version: 1.0
383d26
Content-Type: text/plain; charset=UTF-8
383d26
Content-Transfer-Encoding: 8bit
383d26
383d26
RH-Author: Markus Armbruster <armbru@redhat.com>
383d26
Message-id: <20181029070137.21196-4-armbru@redhat.com>
383d26
Patchwork-id: 82900
383d26
O-Subject: [RHEL-7.6 qemu-kvm-rhev PATCH 3/3] ivshmem: Fix unplug of device "ivshmem-plain"
383d26
Bugzilla: 1620373
383d26
RH-Acked-by: David Hildenbrand <david@redhat.com>
383d26
RH-Acked-by: Igor Mammedov <imammedo@redhat.com>
383d26
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
383d26
RH-Acked-by: Marc-André Lureau <marcandre.lureau@redhat.com>
383d26
383d26
Commit 2aece63c8a "hostmem: detect host backend memory is being used
383d26
properly" fixed "ivshmem-plain" to reject memory backends that are
383d26
already in use, and to block their deletion while in use.  Two bugs
383d26
escaped review:
383d26
383d26
* New ivshmem_plain_exit() fails to call ivshmem_exit().  This breaks
383d26
  unplug.  Reproducer: migration after unplug still fails with
383d26
  "Migration is disabled when using feature 'peer mode' in device
383d26
  'ivshmem'".
383d26
383d26
* It failed to update legacy "ivshmem".  Harmless, because it creates
383d26
  the memory backend itself, and nothing else should use it.
383d26
383d26
Fix by moving the two host_memory_backend_set_mapped() calls into
383d26
ivshmem_common_realize() and ivshmem_exit(), guarded by s->hostmem.
383d26
383d26
Fixes: 2aece63c8a9d2c3a8ff41d2febc4cdeff2633331
383d26
Signed-off-by: Markus Armbruster <armbru@redhat.com>
383d26
Message-Id: <20180926163709.22876-1-armbru@redhat.com>
383d26
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
383d26
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
383d26
(cherry picked from commit b266f1d1123396f9f5df865508f7555ab0c9582a)
383d26
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
383d26
---
383d26
 hw/misc/ivshmem.c | 14 +++++---------
383d26
 1 file changed, 5 insertions(+), 9 deletions(-)
383d26
383d26
diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c
383d26
index 47456b8..28e55d4 100644
383d26
--- a/hw/misc/ivshmem.c
383d26
+++ b/hw/misc/ivshmem.c
383d26
@@ -917,6 +917,7 @@ static void ivshmem_common_realize(PCIDevice *dev, Error **errp)
383d26
         IVSHMEM_DPRINTF("using hostmem\n");
383d26
 
383d26
         s->ivshmem_bar2 = host_memory_backend_get_memory(s->hostmem);
383d26
+        host_memory_backend_set_mapped(s->hostmem, true);
383d26
     } else {
383d26
         Chardev *chr = qemu_chr_fe_get_driver(&s->server_chr);
383d26
         assert(chr);
383d26
@@ -999,6 +1000,10 @@ static void ivshmem_exit(PCIDevice *dev)
383d26
         vmstate_unregister_ram(s->ivshmem_bar2, DEVICE(dev));
383d26
     }
383d26
 
383d26
+    if (s->hostmem) {
383d26
+        host_memory_backend_set_mapped(s->hostmem, false);
383d26
+    }
383d26
+
383d26
     if (s->peers) {
383d26
         for (i = 0; i < s->nb_peers; i++) {
383d26
             close_peer_eventfds(s, i);
383d26
@@ -1107,14 +1112,6 @@ static void ivshmem_plain_realize(PCIDevice *dev, Error **errp)
383d26
     }
383d26
 
383d26
     ivshmem_common_realize(dev, errp);
383d26
-    host_memory_backend_set_mapped(s->hostmem, true);
383d26
-}
383d26
-
383d26
-static void ivshmem_plain_exit(PCIDevice *pci_dev)
383d26
-{
383d26
-    IVShmemState *s = IVSHMEM_COMMON(pci_dev);
383d26
-
383d26
-    host_memory_backend_set_mapped(s->hostmem, false);
383d26
 }
383d26
 
383d26
 static void ivshmem_plain_class_init(ObjectClass *klass, void *data)
383d26
@@ -1123,7 +1120,6 @@ static void ivshmem_plain_class_init(ObjectClass *klass, void *data)
383d26
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
383d26
 
383d26
     k->realize = ivshmem_plain_realize;
383d26
-    k->exit = ivshmem_plain_exit;
383d26
     dc->props = ivshmem_plain_properties;
383d26
     dc->vmsd = &ivshmem_plain_vmsd;
383d26
 }
383d26
-- 
383d26
1.8.3.1
383d26