Blame SOURCES/kvm-vhost-Release-memory-references-on-cleanup.patch

4a2fec
From f221643835f73976adf07ebe355176b09decb558 Mon Sep 17 00:00:00 2001
4a2fec
From: Alex Williamson <alex.williamson@redhat.com>
4a2fec
Date: Mon, 11 Sep 2017 20:43:08 +0200
4a2fec
Subject: [PATCH 01/34] vhost: Release memory references on cleanup
4a2fec
4a2fec
RH-Author: Alex Williamson <alex.williamson@redhat.com>
4a2fec
Message-id: <20170911204254.12489.22036.stgit@redhat.home>
4a2fec
Patchwork-id: 76307
4a2fec
O-Subject: [RHEL-7.5 qemu-kvm-rhev PATCH 1/1] vhost: Release memory references on cleanup
4a2fec
Bugzilla: 1489670
4a2fec
RH-Acked-by: John Snow <jsnow@redhat.com>
4a2fec
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
4a2fec
RH-Acked-by: Auger Eric <eric.auger@redhat.com>
4a2fec
4a2fec
vhost registers a MemoryListener where it adds and removes references
4a2fec
to MemoryRegions as the MemoryRegionSections pass through.  The
4a2fec
region_add callback is invoked for each existing section when the
4a2fec
MemoryListener is registered, but unregistering the MemoryListener
4a2fec
performs no reciprocal region_del callback.  It's therefore the
4a2fec
owner of the MemoryListener's responsibility to cleanup any persistent
4a2fec
changes, such as these memory references, after unregistering.
4a2fec
4a2fec
The consequence of this bug is that if we have both a vhost device
4a2fec
and a vfio device, the vhost device will reference any mmap'd MMIO of
4a2fec
the vfio device via this MemoryListener.  If the vhost device is then
4a2fec
removed, those references remain outstanding.  If we then attempt to
4a2fec
remove the vfio device, it never gets finalized and the only way to
4a2fec
release the kernel file descriptors is to terminate the QEMU process.
4a2fec
4a2fec
Fixes: dfde4e6e1a86 ("memory: add ref/unref calls")
4a2fec
Cc: Michael S. Tsirkin <mst@redhat.com>
4a2fec
Cc: Paolo Bonzini <pbonzini@redhat.com>
4a2fec
Cc: qemu-stable@nongnu.org # v1.6.0+
4a2fec
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
4a2fec
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
4a2fec
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
4a2fec
(cherry picked from commit ee4c112846a0f2ac4fe5601918b0a2642ac8e2ed)
4a2fec
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
4a2fec
---
4a2fec
 hw/virtio/vhost.c | 4 ++++
4a2fec
 1 file changed, 4 insertions(+)
4a2fec
4a2fec
diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
4a2fec
index 6eddb09..b737ca9 100644
4a2fec
--- a/hw/virtio/vhost.c
4a2fec
+++ b/hw/virtio/vhost.c
4a2fec
@@ -1356,6 +1356,10 @@ void vhost_dev_cleanup(struct vhost_dev *hdev)
4a2fec
     if (hdev->mem) {
4a2fec
         /* those are only safe after successful init */
4a2fec
         memory_listener_unregister(&hdev->memory_listener);
4a2fec
+        for (i = 0; i < hdev->n_mem_sections; ++i) {
4a2fec
+            MemoryRegionSection *section = &hdev->mem_sections[i];
4a2fec
+            memory_region_unref(section->mr);
4a2fec
+        }
4a2fec
         QLIST_REMOVE(hdev, entry);
4a2fec
     }
4a2fec
     if (hdev->migration_blocker) {
4a2fec
-- 
4a2fec
1.8.3.1
4a2fec