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

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