From 2016986aedb6ea2839662eb5f60630f3e231bd1a Mon Sep 17 00:00:00 2001 From: Alex Williamson Date: Wed, 13 Dec 2017 10:19:32 -0700 Subject: vfio: Fix vfio-kvm group registration Commit 8c37faa475f3 ("vfio-pci, ppc64/spapr: Reorder group-to-container attaching") moved registration of groups with the vfio-kvm device from vfio_get_group() to vfio_connect_container(), but it missed the case where a group is attached to an existing container and takes an early exit. Perhaps this is a less common case on ppc64/spapr, but on x86 (without viommu) all groups are connected to the same container and thus only the first group gets registered with the vfio-kvm device. This becomes a problem if we then hot-unplug the devices associated with that first group and we end up with KVM being misinformed about any vfio connections that might remain. Fix by including the call to vfio_kvm_device_add_group() in this early exit path. Fixes: 8c37faa475f3 ("vfio-pci, ppc64/spapr: Reorder group-to-container attaching") Cc: qemu-stable@nongnu.org # qemu-2.10+ Reviewed-by: Alexey Kardashevskiy Reviewed-by: Peter Xu Tested-by: Peter Xu Reviewed-by: Eric Auger Tested-by: Eric Auger Signed-off-by: Alex Williamson --- hw/vfio/common.c | 1 + 1 file changed, 1 insertion(+) (limited to 'hw') diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 7b2924c..7007878 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -968,6 +968,7 @@ static int vfio_connect_container(VFIOGroup *group, AddressSpace *as, if (!ioctl(group->fd, VFIO_GROUP_SET_CONTAINER, &container->fd)) { group->container = container; QLIST_INSERT_HEAD(&container->group_list, group, container_next); + vfio_kvm_device_add_group(group); return 0; } } -- cgit v1.1 From f7f9c7b23243fef21296d04d03df1477d12c5c19 Mon Sep 17 00:00:00 2001 From: "Liu, Yi L" Date: Wed, 13 Dec 2017 10:19:33 -0700 Subject: vfio/common: init giommu_list and hostwin_list of vfio container The init of giommu_list and hostwin_list is missed during container initialization. Signed-off-by: Liu, Yi L Signed-off-by: Alex Williamson --- hw/vfio/common.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'hw') diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 7007878..216eec6 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -991,6 +991,8 @@ static int vfio_connect_container(VFIOGroup *group, AddressSpace *as, container = g_malloc0(sizeof(*container)); container->space = space; container->fd = fd; + QLIST_INIT(&container->giommu_list); + QLIST_INIT(&container->hostwin_list); if (ioctl(fd, VFIO_CHECK_EXTENSION, VFIO_TYPE1_IOMMU) || ioctl(fd, VFIO_CHECK_EXTENSION, VFIO_TYPE1v2_IOMMU)) { bool v2 = !!ioctl(fd, VFIO_CHECK_EXTENSION, VFIO_TYPE1v2_IOMMU); -- cgit v1.1 From c6e7958eb76ed267f7254b97f89773874df50e48 Mon Sep 17 00:00:00 2001 From: Alexey Kardashevskiy Date: Wed, 13 Dec 2017 10:19:33 -0700 Subject: vfio/spapr: Allow fallback to SPAPR TCE IOMMU v1 The vfio_iommu_spapr_tce driver advertises kernel's support for v1 and v2 IOMMU support, however it is not always possible to use the requested IOMMU type. For example, a pseries host platform does not support dynamic DMA windows so v2 cannot initialize and QEMU fails to start. This adds a fallback to the v1 IOMMU if v2 cannot be used. Fixes: 318f67ce1371 ("vfio: spapr: Add DMA memory preregistering (SPAPR IOMMU v2)") Signed-off-by: Alexey Kardashevskiy Signed-off-by: Alex Williamson --- hw/vfio/common.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'hw') diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 216eec6..b77be3a 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -1043,6 +1043,11 @@ static int vfio_connect_container(VFIOGroup *group, AddressSpace *as, v2 ? VFIO_SPAPR_TCE_v2_IOMMU : VFIO_SPAPR_TCE_IOMMU; ret = ioctl(fd, VFIO_SET_IOMMU, container->iommu_type); if (ret) { + container->iommu_type = VFIO_SPAPR_TCE_IOMMU; + v2 = false; + ret = ioctl(fd, VFIO_SET_IOMMU, container->iommu_type); + } + if (ret) { error_setg_errno(errp, errno, "failed to set iommu for container"); ret = -errno; goto free_container_exit; -- cgit v1.1 From 2fb9636ebf24e695617bf407bf0a345aa223d1ac Mon Sep 17 00:00:00 2001 From: Alexey Kardashevskiy Date: Wed, 13 Dec 2017 10:19:34 -0700 Subject: vfio-pci: Remove unused fields from VFIOMSIXInfo When support for multiple mappings per a region were added, this was left behind, let's finish and remove unused bits. Fixes: db0da029a185 ("vfio: Generalize region support") Signed-off-by: Alexey Kardashevskiy Signed-off-by: Alex Williamson --- hw/vfio/pci.h | 2 -- 1 file changed, 2 deletions(-) (limited to 'hw') diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h index 502a575..a8fb3b3 100644 --- a/hw/vfio/pci.h +++ b/hw/vfio/pci.h @@ -93,8 +93,6 @@ typedef struct VFIOMSIXInfo { uint16_t entries; uint32_t table_offset; uint32_t pba_offset; - MemoryRegion mmap_mem; - void *mmap; unsigned long *pending; } VFIOMSIXInfo; -- cgit v1.1