cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-s390x-pci-Add-routine-to-get-the-vfio-dma-available-.patch

c687bc
From 3927f54a56e29003b84e0e3726d3a0170681128b Mon Sep 17 00:00:00 2001
c687bc
From: Cornelia Huck <cohuck@redhat.com>
c687bc
Date: Tue, 19 Jan 2021 12:50:44 -0500
c687bc
Subject: [PATCH 5/7] s390x/pci: Add routine to get the vfio dma available
c687bc
 count
c687bc
c687bc
RH-Author: Cornelia Huck <cohuck@redhat.com>
c687bc
Message-id: <20210119125046.472811-6-cohuck@redhat.com>
c687bc
Patchwork-id: 100679
c687bc
O-Subject: [RHEL-8.4.0 qemu-kvm PATCH 5/7] s390x/pci: Add routine to get the vfio dma available count
c687bc
Bugzilla: 1905391
c687bc
RH-Acked-by: David Hildenbrand <david@redhat.com>
c687bc
RH-Acked-by: Auger Eric <eric.auger@redhat.com>
c687bc
RH-Acked-by: Thomas Huth <thuth@redhat.com>
c687bc
c687bc
From: Matthew Rosato <mjrosato@linux.ibm.com>
c687bc
c687bc
Create new files for separating out vfio-specific work for s390
c687bc
pci. Add the first such routine, which issues VFIO_IOMMU_GET_INFO
c687bc
ioctl to collect the current dma available count.
c687bc
c687bc
Signed-off-by: Matthew Rosato <mjrosato@linux.ibm.com>
c687bc
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
c687bc
[aw: Fix non-Linux build with CONFIG_LINUX]
c687bc
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
c687bc
(cherry picked from commit cd7498d07fbb20fa04790ff7ee168a8a8d01cb30)
c687bc
Signed-off-by: Cornelia Huck <cohuck@redhat.com>
c687bc
c687bc
 Conflicts:
c687bc
	hw/s390x/meson.build
c687bc
        --> added the file in hw/s390x/Makefile.objs instead,
c687bc
            since we do not use Meson yet
c687bc
        hw/s390x/s390-pci-vfio.c
c687bc
        --> NULL-initialize "info" to avoid a downstream-only
c687bc
            compiler warning
c687bc
c687bc
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
c687bc
---
c687bc
 hw/s390x/Makefile.objs           |  1 +
c687bc
 hw/s390x/s390-pci-vfio.c         | 54 ++++++++++++++++++++++++++++++++
c687bc
 include/hw/s390x/s390-pci-vfio.h | 24 ++++++++++++++
c687bc
 3 files changed, 79 insertions(+)
c687bc
 create mode 100644 hw/s390x/s390-pci-vfio.c
c687bc
 create mode 100644 include/hw/s390x/s390-pci-vfio.h
c687bc
c687bc
diff --git a/hw/s390x/Makefile.objs b/hw/s390x/Makefile.objs
c687bc
index c4086ec3171..43756c9437d 100644
c687bc
--- a/hw/s390x/Makefile.objs
c687bc
+++ b/hw/s390x/Makefile.objs
c687bc
@@ -7,6 +7,7 @@ obj-y += ipl.o
c687bc
 obj-y += css.o
c687bc
 obj-$(CONFIG_S390_CCW_VIRTIO) += s390-virtio-ccw.o
c687bc
 obj-$(CONFIG_TERMINAL3270) += 3270-ccw.o
c687bc
+obj-$(CONFIG_LINUX) += s390-pci-vfio.o
c687bc
 ifeq ($(CONFIG_VIRTIO_CCW),y)
c687bc
 obj-y += virtio-ccw.o
c687bc
 obj-$(CONFIG_VIRTIO_SERIAL) += virtio-ccw-serial.o
c687bc
diff --git a/hw/s390x/s390-pci-vfio.c b/hw/s390x/s390-pci-vfio.c
c687bc
new file mode 100644
c687bc
index 00000000000..0eb22ffec4c
c687bc
--- /dev/null
c687bc
+++ b/hw/s390x/s390-pci-vfio.c
c687bc
@@ -0,0 +1,54 @@
c687bc
+/*
c687bc
+ * s390 vfio-pci interfaces
c687bc
+ *
c687bc
+ * Copyright 2020 IBM Corp.
c687bc
+ * Author(s): Matthew Rosato <mjrosato@linux.ibm.com>
c687bc
+ *
c687bc
+ * This work is licensed under the terms of the GNU GPL, version 2 or (at
c687bc
+ * your option) any later version. See the COPYING file in the top-level
c687bc
+ * directory.
c687bc
+ */
c687bc
+
c687bc
+#include <sys/ioctl.h>
c687bc
+
c687bc
+#include "qemu/osdep.h"
c687bc
+#include "hw/s390x/s390-pci-vfio.h"
c687bc
+#include "hw/vfio/vfio-common.h"
c687bc
+
c687bc
+/*
c687bc
+ * Get the current DMA available count from vfio.  Returns true if vfio is
c687bc
+ * limiting DMA requests, false otherwise.  The current available count read
c687bc
+ * from vfio is returned in avail.
c687bc
+ */
c687bc
+bool s390_pci_update_dma_avail(int fd, unsigned int *avail)
c687bc
+{
c687bc
+    g_autofree struct vfio_iommu_type1_info *info = NULL;
c687bc
+    uint32_t argsz;
c687bc
+
c687bc
+    assert(avail);
c687bc
+
c687bc
+    argsz = sizeof(struct vfio_iommu_type1_info);
c687bc
+    info = g_malloc0(argsz);
c687bc
+
c687bc
+    /*
c687bc
+     * If the specified argsz is not large enough to contain all capabilities
c687bc
+     * it will be updated upon return from the ioctl.  Retry until we have
c687bc
+     * a big enough buffer to hold the entire capability chain.
c687bc
+     */
c687bc
+retry:
c687bc
+    info->argsz = argsz;
c687bc
+
c687bc
+    if (ioctl(fd, VFIO_IOMMU_GET_INFO, info)) {
c687bc
+        return false;
c687bc
+    }
c687bc
+
c687bc
+    if (info->argsz > argsz) {
c687bc
+        argsz = info->argsz;
c687bc
+        info = g_realloc(info, argsz);
c687bc
+        goto retry;
c687bc
+    }
c687bc
+
c687bc
+    /* If the capability exists, update with the current value */
c687bc
+    return vfio_get_info_dma_avail(info, avail);
c687bc
+}
c687bc
+
c687bc
diff --git a/include/hw/s390x/s390-pci-vfio.h b/include/hw/s390x/s390-pci-vfio.h
c687bc
new file mode 100644
c687bc
index 00000000000..1727292e9b5
c687bc
--- /dev/null
c687bc
+++ b/include/hw/s390x/s390-pci-vfio.h
c687bc
@@ -0,0 +1,24 @@
c687bc
+/*
c687bc
+ * s390 vfio-pci interfaces
c687bc
+ *
c687bc
+ * Copyright 2020 IBM Corp.
c687bc
+ * Author(s): Matthew Rosato <mjrosato@linux.ibm.com>
c687bc
+ *
c687bc
+ * This work is licensed under the terms of the GNU GPL, version 2 or (at
c687bc
+ * your option) any later version. See the COPYING file in the top-level
c687bc
+ * directory.
c687bc
+ */
c687bc
+
c687bc
+#ifndef HW_S390_PCI_VFIO_H
c687bc
+#define HW_S390_PCI_VFIO_H
c687bc
+
c687bc
+#ifdef CONFIG_LINUX
c687bc
+bool s390_pci_update_dma_avail(int fd, unsigned int *avail);
c687bc
+#else
c687bc
+static inline bool s390_pci_update_dma_avail(int fd, unsigned int *avail)
c687bc
+{
c687bc
+    return false;
c687bc
+}
c687bc
+#endif
c687bc
+
c687bc
+#endif
c687bc
-- 
c687bc
2.27.0
c687bc