vhost: Release memory references on cleanup
commitee4c112846a0f2ac4fe5601918b0a2642ac8e2ed
authorAlex Williamson <alex.williamson@redhat.com>
Thu, 7 Sep 2017 20:27:09 +0000 (7 14:27 -0600)
committerMichael S. Tsirkin <mst@redhat.com>
Fri, 8 Sep 2017 13:15:17 +0000 (8 16:15 +0300)
tree07a82636a734e5670317749eecc02770b962e38a
parent74bbfe024da80a50dbe51fbb17f219d2f3e4d2dd
vhost: Release memory references on cleanup

vhost registers a MemoryListener where it adds and removes references
to MemoryRegions as the MemoryRegionSections pass through.  The
region_add callback is invoked for each existing section when the
MemoryListener is registered, but unregistering the MemoryListener
performs no reciprocal region_del callback.  It's therefore the
owner of the MemoryListener's responsibility to cleanup any persistent
changes, such as these memory references, after unregistering.

The consequence of this bug is that if we have both a vhost device
and a vfio device, the vhost device will reference any mmap'd MMIO of
the vfio device via this MemoryListener.  If the vhost device is then
removed, those references remain outstanding.  If we then attempt to
remove the vfio device, it never gets finalized and the only way to
release the kernel file descriptors is to terminate the QEMU process.

Fixes: dfde4e6e1a86 ("memory: add ref/unref calls")
Cc: Michael S. Tsirkin <mst@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: qemu-stable@nongnu.org # v1.6.0+
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
hw/virtio/vhost.c