yeahuh / 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

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