yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
8fced6
From e6147c5a23a75361b1374bfb4b96403d243b5c38 Mon Sep 17 00:00:00 2001
8fced6
From: Cornelia Huck <cohuck@redhat.com>
8fced6
Date: Tue, 19 Jan 2021 12:50:43 -0500
8fced6
Subject: [PATCH 4/7] vfio: Find DMA available capability
8fced6
8fced6
RH-Author: Cornelia Huck <cohuck@redhat.com>
8fced6
Message-id: <20210119125046.472811-5-cohuck@redhat.com>
8fced6
Patchwork-id: 100677
8fced6
O-Subject: [RHEL-8.4.0 qemu-kvm PATCH 4/7] vfio: Find DMA available capability
8fced6
Bugzilla: 1905391
8fced6
RH-Acked-by: David Hildenbrand <david@redhat.com>
8fced6
RH-Acked-by: Auger Eric <eric.auger@redhat.com>
8fced6
RH-Acked-by: Thomas Huth <thuth@redhat.com>
8fced6
8fced6
From: Matthew Rosato <mjrosato@linux.ibm.com>
8fced6
8fced6
The underlying host may be limiting the number of outstanding DMA
8fced6
requests for type 1 IOMMU.  Add helper functions to check for the
8fced6
DMA available capability and retrieve the current number of DMA
8fced6
mappings allowed.
8fced6
8fced6
Signed-off-by: Matthew Rosato <mjrosato@linux.ibm.com>
8fced6
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
8fced6
[aw: vfio_get_info_dma_avail moved inside CONFIG_LINUX]
8fced6
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
8fced6
(cherry picked from commit 7486a62845b1e12011dd99973e4739f69d57cd38)
8fced6
Signed-off-by: Cornelia Huck <cohuck@redhat.com>
8fced6
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
8fced6
---
8fced6
 hw/vfio/common.c              | 31 +++++++++++++++++++++++++++++++
8fced6
 include/hw/vfio/vfio-common.h |  2 ++
8fced6
 2 files changed, 33 insertions(+)
8fced6
8fced6
diff --git a/hw/vfio/common.c b/hw/vfio/common.c
8fced6
index 77d62d2dcdf..23efdfadebd 100644
8fced6
--- a/hw/vfio/common.c
8fced6
+++ b/hw/vfio/common.c
8fced6
@@ -850,6 +850,37 @@ vfio_get_region_info_cap(struct vfio_region_info *info, uint16_t id)
8fced6
     return vfio_get_cap((void *)info, info->cap_offset, id);
8fced6
 }
8fced6
 
8fced6
+static struct vfio_info_cap_header *
8fced6
+vfio_get_iommu_type1_info_cap(struct vfio_iommu_type1_info *info, uint16_t id)
8fced6
+{
8fced6
+    if (!(info->flags & VFIO_IOMMU_INFO_CAPS)) {
8fced6
+        return NULL;
8fced6
+    }
8fced6
+
8fced6
+    return vfio_get_cap((void *)info, info->cap_offset, id);
8fced6
+}
8fced6
+
8fced6
+bool vfio_get_info_dma_avail(struct vfio_iommu_type1_info *info,
8fced6
+                             unsigned int *avail)
8fced6
+{
8fced6
+    struct vfio_info_cap_header *hdr;
8fced6
+    struct vfio_iommu_type1_info_dma_avail *cap;
8fced6
+
8fced6
+    /* If the capability cannot be found, assume no DMA limiting */
8fced6
+    hdr = vfio_get_iommu_type1_info_cap(info,
8fced6
+                                        VFIO_IOMMU_TYPE1_INFO_DMA_AVAIL);
8fced6
+    if (hdr == NULL) {
8fced6
+        return false;
8fced6
+    }
8fced6
+
8fced6
+    if (avail != NULL) {
8fced6
+        cap = (void *) hdr;
8fced6
+        *avail = cap->avail;
8fced6
+    }
8fced6
+
8fced6
+    return true;
8fced6
+}
8fced6
+
8fced6
 static int vfio_setup_region_sparse_mmaps(VFIORegion *region,
8fced6
                                           struct vfio_region_info *info)
8fced6
 {
8fced6
diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
8fced6
index fd564209ac7..aa6cbe4a998 100644
8fced6
--- a/include/hw/vfio/vfio-common.h
8fced6
+++ b/include/hw/vfio/vfio-common.h
8fced6
@@ -191,6 +191,8 @@ int vfio_get_dev_region_info(VFIODevice *vbasedev, uint32_t type,
8fced6
 bool vfio_has_region_cap(VFIODevice *vbasedev, int region, uint16_t cap_type);
8fced6
 struct vfio_info_cap_header *
8fced6
 vfio_get_region_info_cap(struct vfio_region_info *info, uint16_t id);
8fced6
+bool vfio_get_info_dma_avail(struct vfio_iommu_type1_info *info,
8fced6
+                             unsigned int *avail);
8fced6
 #endif
8fced6
 extern const MemoryListener vfio_prereg_listener;
8fced6
 
8fced6
-- 
8fced6
2.27.0
8fced6