thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone
1072c8
From db6a782f8b9ba062f195ff504b4d2f93e471fecc Mon Sep 17 00:00:00 2001
1072c8
From: Thomas Huth <thuth@redhat.com>
1072c8
Date: Tue, 11 May 2021 11:24:05 -0400
1072c8
Subject: [PATCH 2/5] vfio-ccw: Connect the device request notifier
1072c8
1072c8
RH-Author: Thomas Huth <thuth@redhat.com>
1072c8
Message-id: <20210511112405.297037-3-thuth@redhat.com>
1072c8
Patchwork-id: 101536
1072c8
O-Subject: [RHEL-8.5.0 qemu-kvm PATCH 2/2] vfio-ccw: Connect the device request notifier
1072c8
Bugzilla: 1940450
1072c8
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
1072c8
RH-Acked-by: Cornelia Huck <cohuck@redhat.com>
1072c8
RH-Acked-by: David Hildenbrand <david@redhat.com>
1072c8
1072c8
Now that the vfio-ccw code has a notifier interface to request that
1072c8
a device be unplugged, let's wire that together.
1072c8
1072c8
Signed-off-by: Eric Farman <farman@linux.ibm.com>
1072c8
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
1072c8
Message-Id: <20210104202057.48048-4-farman@linux.ibm.com>
1072c8
Signed-off-by: Cornelia Huck <cohuck@redhat.com>
1072c8
(cherry picked from commit b2f96f9e4f5fbc8f2770a436191cb328da4d5350)
1072c8
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1940450
1072c8
Signed-off-by: Thomas Huth <thuth@redhat.com>
1072c8
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
1072c8
---
1072c8
 hw/vfio/ccw.c | 40 ++++++++++++++++++++++++++++++++++++----
1072c8
 1 file changed, 36 insertions(+), 4 deletions(-)
1072c8
1072c8
diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c
1072c8
index b72a505893..3d450fe1c9 100644
1072c8
--- a/hw/vfio/ccw.c
1072c8
+++ b/hw/vfio/ccw.c
1072c8
@@ -49,6 +49,7 @@ struct VFIOCCWDevice {
1072c8
     struct ccw_crw_region *crw_region;
1072c8
     EventNotifier io_notifier;
1072c8
     EventNotifier crw_notifier;
1072c8
+    EventNotifier req_notifier;
1072c8
     bool force_orb_pfch;
1072c8
     bool warned_orb_pfch;
1072c8
 };
1072c8
@@ -287,6 +288,21 @@ static void vfio_ccw_crw_read(VFIOCCWDevice *vcdev)
1072c8
     } while (1);
1072c8
 }
1072c8
 
1072c8
+static void vfio_ccw_req_notifier_handler(void *opaque)
1072c8
+{
1072c8
+    VFIOCCWDevice *vcdev = opaque;
1072c8
+    Error *err = NULL;
1072c8
+
1072c8
+    if (!event_notifier_test_and_clear(&vcdev->req_notifier)) {
1072c8
+        return;
1072c8
+    }
1072c8
+
1072c8
+    qdev_unplug(DEVICE(vcdev), &err;;
1072c8
+    if (err) {
1072c8
+        warn_reportf_err(err, VFIO_MSG_PREFIX, vcdev->vdev.name);
1072c8
+    }
1072c8
+}
1072c8
+
1072c8
 static void vfio_ccw_crw_notifier_handler(void *opaque)
1072c8
 {
1072c8
     VFIOCCWDevice *vcdev = opaque;
1072c8
@@ -386,6 +402,10 @@ static void vfio_ccw_register_irq_notifier(VFIOCCWDevice *vcdev,
1072c8
         notifier = &vcdev->crw_notifier;
1072c8
         fd_read = vfio_ccw_crw_notifier_handler;
1072c8
         break;
1072c8
+    case VFIO_CCW_REQ_IRQ_INDEX:
1072c8
+        notifier = &vcdev->req_notifier;
1072c8
+        fd_read = vfio_ccw_req_notifier_handler;
1072c8
+        break;
1072c8
     default:
1072c8
         error_setg(errp, "vfio: Unsupported device irq(%d)", irq);
1072c8
         return;
1072c8
@@ -440,6 +460,9 @@ static void vfio_ccw_unregister_irq_notifier(VFIOCCWDevice *vcdev,
1072c8
     case VFIO_CCW_CRW_IRQ_INDEX:
1072c8
         notifier = &vcdev->crw_notifier;
1072c8
         break;
1072c8
+    case VFIO_CCW_REQ_IRQ_INDEX:
1072c8
+        notifier = &vcdev->req_notifier;
1072c8
+        break;
1072c8
     default:
1072c8
         error_report("vfio: Unsupported device irq(%d)", irq);
1072c8
         return;
1072c8
@@ -657,20 +680,28 @@ static void vfio_ccw_realize(DeviceState *dev, Error **errp)
1072c8
 
1072c8
     vfio_ccw_register_irq_notifier(vcdev, VFIO_CCW_IO_IRQ_INDEX, &err;;
1072c8
     if (err) {
1072c8
-        goto out_notifier_err;
1072c8
+        goto out_io_notifier_err;
1072c8
     }
1072c8
 
1072c8
     if (vcdev->crw_region) {
1072c8
         vfio_ccw_register_irq_notifier(vcdev, VFIO_CCW_CRW_IRQ_INDEX, &err;;
1072c8
         if (err) {
1072c8
-            vfio_ccw_unregister_irq_notifier(vcdev, VFIO_CCW_IO_IRQ_INDEX);
1072c8
-            goto out_notifier_err;
1072c8
+            goto out_crw_notifier_err;
1072c8
         }
1072c8
     }
1072c8
 
1072c8
+    vfio_ccw_register_irq_notifier(vcdev, VFIO_CCW_REQ_IRQ_INDEX, &err;;
1072c8
+    if (err) {
1072c8
+        goto out_req_notifier_err;
1072c8
+    }
1072c8
+
1072c8
     return;
1072c8
 
1072c8
-out_notifier_err:
1072c8
+out_req_notifier_err:
1072c8
+    vfio_ccw_unregister_irq_notifier(vcdev, VFIO_CCW_CRW_IRQ_INDEX);
1072c8
+out_crw_notifier_err:
1072c8
+    vfio_ccw_unregister_irq_notifier(vcdev, VFIO_CCW_IO_IRQ_INDEX);
1072c8
+out_io_notifier_err:
1072c8
     vfio_ccw_put_region(vcdev);
1072c8
 out_region_err:
1072c8
     vfio_ccw_put_device(vcdev);
1072c8
@@ -692,6 +723,7 @@ static void vfio_ccw_unrealize(DeviceState *dev, Error **errp)
1072c8
     S390CCWDeviceClass *cdc = S390_CCW_DEVICE_GET_CLASS(cdev);
1072c8
     VFIOGroup *group = vcdev->vdev.group;
1072c8
 
1072c8
+    vfio_ccw_unregister_irq_notifier(vcdev, VFIO_CCW_REQ_IRQ_INDEX);
1072c8
     vfio_ccw_unregister_irq_notifier(vcdev, VFIO_CCW_CRW_IRQ_INDEX);
1072c8
     vfio_ccw_unregister_irq_notifier(vcdev, VFIO_CCW_IO_IRQ_INDEX);
1072c8
     vfio_ccw_put_region(vcdev);
1072c8
-- 
1072c8
2.27.0
1072c8