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