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