thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone

Blame SOURCES/kvm-vfio-ccw-Add-support-for-the-CRW-region-and-IRQ.patch

77c23f
From 58edd0fba4d9e98edfeb16139467d6035a1f4e61 Mon Sep 17 00:00:00 2001
77c23f
From: Cornelia Huck <cohuck@redhat.com>
77c23f
Date: Tue, 23 Jun 2020 09:25:42 -0400
77c23f
Subject: [PATCH 08/12] vfio-ccw: Add support for the CRW region and IRQ
77c23f
77c23f
RH-Author: Cornelia Huck <cohuck@redhat.com>
77c23f
Message-id: <20200623092543.358315-9-cohuck@redhat.com>
77c23f
Patchwork-id: 97698
77c23f
O-Subject: [RHEL-8.3.0 qemu-kvm PATCH 8/9] vfio-ccw: Add support for the CRW region and IRQ
77c23f
Bugzilla: 1660916
77c23f
RH-Acked-by: Claudio Imbrenda <cimbrend@redhat.com>
77c23f
RH-Acked-by: David Hildenbrand <david@redhat.com>
77c23f
RH-Acked-by: Thomas Huth <thuth@redhat.com>
77c23f
77c23f
From: Farhan Ali <alifm@linux.ibm.com>
77c23f
77c23f
The crw region can be used to obtain information about
77c23f
Channel Report Words (CRW) from vfio-ccw driver.
77c23f
77c23f
Currently only channel-path related CRWs are passed to
77c23f
QEMU from vfio-ccw driver.
77c23f
77c23f
Signed-off-by: Farhan Ali <alifm@linux.ibm.com>
77c23f
Signed-off-by: Eric Farman <farman@linux.ibm.com>
77c23f
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
77c23f
Message-Id: <20200505125757.98209-7-farman@linux.ibm.com>
77c23f
Signed-off-by: Cornelia Huck <cohuck@redhat.com>
77c23f
(cherry picked from commit f030532f2ad6eeb200034915e9c6357cce81b538)
77c23f
Signed-off-by: Cornelia Huck <cohuck@redhat.com>
77c23f
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
77c23f
---
77c23f
 hw/vfio/ccw.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++
77c23f
 1 file changed, 73 insertions(+)
77c23f
77c23f
diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c
77c23f
index 94a0d9840d..b72a505893 100644
77c23f
--- a/hw/vfio/ccw.c
77c23f
+++ b/hw/vfio/ccw.c
77c23f
@@ -44,7 +44,11 @@ struct VFIOCCWDevice {
77c23f
     uint64_t schib_region_size;
77c23f
     uint64_t schib_region_offset;
77c23f
     struct ccw_schib_region *schib_region;
77c23f
+    uint64_t crw_region_size;
77c23f
+    uint64_t crw_region_offset;
77c23f
+    struct ccw_crw_region *crw_region;
77c23f
     EventNotifier io_notifier;
77c23f
+    EventNotifier crw_notifier;
77c23f
     bool force_orb_pfch;
77c23f
     bool warned_orb_pfch;
77c23f
 };
77c23f
@@ -254,6 +258,44 @@ static void vfio_ccw_reset(DeviceState *dev)
77c23f
     ioctl(vcdev->vdev.fd, VFIO_DEVICE_RESET);
77c23f
 }
77c23f
 
77c23f
+static void vfio_ccw_crw_read(VFIOCCWDevice *vcdev)
77c23f
+{
77c23f
+    struct ccw_crw_region *region = vcdev->crw_region;
77c23f
+    CRW crw;
77c23f
+    int size;
77c23f
+
77c23f
+    /* Keep reading CRWs as long as data is returned */
77c23f
+    do {
77c23f
+        memset(region, 0, sizeof(*region));
77c23f
+        size = pread(vcdev->vdev.fd, region, vcdev->crw_region_size,
77c23f
+                     vcdev->crw_region_offset);
77c23f
+
77c23f
+        if (size == -1) {
77c23f
+            error_report("vfio-ccw: Read crw region failed with errno=%d",
77c23f
+                         errno);
77c23f
+            break;
77c23f
+        }
77c23f
+
77c23f
+        if (region->crw == 0) {
77c23f
+            /* No more CRWs to queue */
77c23f
+            break;
77c23f
+        }
77c23f
+
77c23f
+        memcpy(&crw, &region->crw, sizeof(CRW));
77c23f
+
77c23f
+        css_crw_add_to_queue(crw);
77c23f
+    } while (1);
77c23f
+}
77c23f
+
77c23f
+static void vfio_ccw_crw_notifier_handler(void *opaque)
77c23f
+{
77c23f
+    VFIOCCWDevice *vcdev = opaque;
77c23f
+
77c23f
+    while (event_notifier_test_and_clear(&vcdev->crw_notifier)) {
77c23f
+        vfio_ccw_crw_read(vcdev);
77c23f
+    }
77c23f
+}
77c23f
+
77c23f
 static void vfio_ccw_io_notifier_handler(void *opaque)
77c23f
 {
77c23f
     VFIOCCWDevice *vcdev = opaque;
77c23f
@@ -340,6 +382,10 @@ static void vfio_ccw_register_irq_notifier(VFIOCCWDevice *vcdev,
77c23f
         notifier = &vcdev->io_notifier;
77c23f
         fd_read = vfio_ccw_io_notifier_handler;
77c23f
         break;
77c23f
+    case VFIO_CCW_CRW_IRQ_INDEX:
77c23f
+        notifier = &vcdev->crw_notifier;
77c23f
+        fd_read = vfio_ccw_crw_notifier_handler;
77c23f
+        break;
77c23f
     default:
77c23f
         error_setg(errp, "vfio: Unsupported device irq(%d)", irq);
77c23f
         return;
77c23f
@@ -391,6 +437,9 @@ static void vfio_ccw_unregister_irq_notifier(VFIOCCWDevice *vcdev,
77c23f
     case VFIO_CCW_IO_IRQ_INDEX:
77c23f
         notifier = &vcdev->io_notifier;
77c23f
         break;
77c23f
+    case VFIO_CCW_CRW_IRQ_INDEX:
77c23f
+        notifier = &vcdev->crw_notifier;
77c23f
+        break;
77c23f
     default:
77c23f
         error_report("vfio: Unsupported device irq(%d)", irq);
77c23f
         return;
77c23f
@@ -468,10 +517,24 @@ static void vfio_ccw_get_region(VFIOCCWDevice *vcdev, Error **errp)
77c23f
         vcdev->schib_region = g_malloc(info->size);
77c23f
     }
77c23f
 
77c23f
+    ret = vfio_get_dev_region_info(vdev, VFIO_REGION_TYPE_CCW,
77c23f
+                                   VFIO_REGION_SUBTYPE_CCW_CRW, &info;;
77c23f
+
77c23f
+    if (!ret) {
77c23f
+        vcdev->crw_region_size = info->size;
77c23f
+        if (sizeof(*vcdev->crw_region) != vcdev->crw_region_size) {
77c23f
+            error_setg(errp, "vfio: Unexpected size of the CRW region");
77c23f
+            goto out_err;
77c23f
+        }
77c23f
+        vcdev->crw_region_offset = info->offset;
77c23f
+        vcdev->crw_region = g_malloc(info->size);
77c23f
+    }
77c23f
+
77c23f
     g_free(info);
77c23f
     return;
77c23f
 
77c23f
 out_err:
77c23f
+    g_free(vcdev->crw_region);
77c23f
     g_free(vcdev->schib_region);
77c23f
     g_free(vcdev->async_cmd_region);
77c23f
     g_free(vcdev->io_region);
77c23f
@@ -481,6 +544,7 @@ out_err:
77c23f
 
77c23f
 static void vfio_ccw_put_region(VFIOCCWDevice *vcdev)
77c23f
 {
77c23f
+    g_free(vcdev->crw_region);
77c23f
     g_free(vcdev->schib_region);
77c23f
     g_free(vcdev->async_cmd_region);
77c23f
     g_free(vcdev->io_region);
77c23f
@@ -596,6 +660,14 @@ static void vfio_ccw_realize(DeviceState *dev, Error **errp)
77c23f
         goto out_notifier_err;
77c23f
     }
77c23f
 
77c23f
+    if (vcdev->crw_region) {
77c23f
+        vfio_ccw_register_irq_notifier(vcdev, VFIO_CCW_CRW_IRQ_INDEX, &err;;
77c23f
+        if (err) {
77c23f
+            vfio_ccw_unregister_irq_notifier(vcdev, VFIO_CCW_IO_IRQ_INDEX);
77c23f
+            goto out_notifier_err;
77c23f
+        }
77c23f
+    }
77c23f
+
77c23f
     return;
77c23f
 
77c23f
 out_notifier_err:
77c23f
@@ -620,6 +692,7 @@ static void vfio_ccw_unrealize(DeviceState *dev, Error **errp)
77c23f
     S390CCWDeviceClass *cdc = S390_CCW_DEVICE_GET_CLASS(cdev);
77c23f
     VFIOGroup *group = vcdev->vdev.group;
77c23f
 
77c23f
+    vfio_ccw_unregister_irq_notifier(vcdev, VFIO_CCW_CRW_IRQ_INDEX);
77c23f
     vfio_ccw_unregister_irq_notifier(vcdev, VFIO_CCW_IO_IRQ_INDEX);
77c23f
     vfio_ccw_put_region(vcdev);
77c23f
     vfio_ccw_put_device(vcdev);
77c23f
-- 
77c23f
2.27.0
77c23f