Blame SOURCES/kvm-vfio-Fix-vfio-kvm-group-registration.patch

4a2fec
From 8c5380844c8f52663f497609cfb0a833e5f643e0 Mon Sep 17 00:00:00 2001
4a2fec
From: Alex Williamson <alex.williamson@redhat.com>
4a2fec
Date: Thu, 14 Dec 2017 16:30:06 +0100
4a2fec
Subject: [PATCH 6/6] vfio: Fix vfio-kvm group registration
4a2fec
4a2fec
RH-Author: Alex Williamson <alex.williamson@redhat.com>
4a2fec
Message-id: <20171214162725.10938.41443.stgit@gimli.home>
4a2fec
Patchwork-id: 78402
4a2fec
O-Subject: [RHEL-7.5 qemu-kvm-rhev PATCH] vfio: Fix vfio-kvm group registration
4a2fec
Bugzilla: 1520294
4a2fec
RH-Acked-by: Auger Eric <eric.auger@redhat.com>
4a2fec
RH-Acked-by: Peter Xu <peterx@redhat.com>
4a2fec
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
4a2fec
4a2fec
Commit 8c37faa475f3 ("vfio-pci, ppc64/spapr: Reorder group-to-container
4a2fec
attaching") moved registration of groups with the vfio-kvm device from
4a2fec
vfio_get_group() to vfio_connect_container(), but it missed the case
4a2fec
where a group is attached to an existing container and takes an early
4a2fec
exit.  Perhaps this is a less common case on ppc64/spapr, but on x86
4a2fec
(without viommu) all groups are connected to the same container and
4a2fec
thus only the first group gets registered with the vfio-kvm device.
4a2fec
This becomes a problem if we then hot-unplug the devices associated
4a2fec
with that first group and we end up with KVM being misinformed about
4a2fec
any vfio connections that might remain.  Fix by including the call to
4a2fec
vfio_kvm_device_add_group() in this early exit path.
4a2fec
4a2fec
Fixes: 8c37faa475f3 ("vfio-pci, ppc64/spapr: Reorder group-to-container attaching")
4a2fec
Cc: qemu-stable@nongnu.org # qemu-2.10+
4a2fec
Reviewed-by: Alexey Kardashevskiy <aik@ozlabs.ru>
4a2fec
Reviewed-by: Peter Xu <peterx@redhat.com>
4a2fec
Tested-by: Peter Xu <peterx@redhat.com>
4a2fec
Reviewed-by: Eric Auger <eric.auger@redhat.com>
4a2fec
Tested-by: Eric Auger <eric.auger@redhat.com>
4a2fec
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
4a2fec
(cherry picked from commit 2016986aedb6ea2839662eb5f60630f3e231bd1a)
4a2fec
---
4a2fec
4a2fec
Testing: hot unplug Intel 82576 PF which is not the first vfio-pci device
4a2fec
for the VM.  Previous, libvirt log includes:
4a2fec
4a2fec
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
4a2fec
---
4a2fec
 hw/vfio/common.c | 1 +
4a2fec
 1 file changed, 1 insertion(+)
4a2fec
4a2fec
diff --git a/hw/vfio/common.c b/hw/vfio/common.c
4a2fec
index 7b2924c..7007878 100644
4a2fec
--- a/hw/vfio/common.c
4a2fec
+++ b/hw/vfio/common.c
4a2fec
@@ -968,6 +968,7 @@ static int vfio_connect_container(VFIOGroup *group, AddressSpace *as,
4a2fec
         if (!ioctl(group->fd, VFIO_GROUP_SET_CONTAINER, &container->fd)) {
4a2fec
             group->container = container;
4a2fec
             QLIST_INSERT_HEAD(&container->group_list, group, container_next);
4a2fec
+            vfio_kvm_device_add_group(group);
4a2fec
             return 0;
4a2fec
         }
4a2fec
     }
4a2fec
-- 
4a2fec
1.8.3.1
4a2fec