thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 7 months ago
Clone
7f1c5b
From 42818e2bc6fa537fe52f7f0e6b094774a1eb00e1 Mon Sep 17 00:00:00 2001
7f1c5b
From: Cindy Lu <lulu@redhat.com>
7f1c5b
Date: Thu, 22 Dec 2022 15:04:48 +0800
7f1c5b
Subject: [PATCH 07/31] vhost: add support for configure interrupt
7f1c5b
MIME-Version: 1.0
7f1c5b
Content-Type: text/plain; charset=UTF-8
7f1c5b
Content-Transfer-Encoding: 8bit
7f1c5b
7f1c5b
RH-Author: Cindy Lu <lulu@redhat.com>
7f1c5b
RH-MergeRequest: 132: vhost-vdpa: support config interrupt in vhost-vdpa
7f1c5b
RH-Bugzilla: 1905805
7f1c5b
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
7f1c5b
RH-Acked-by: Eugenio PĂ©rez <eperezma@redhat.com>
7f1c5b
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
7f1c5b
RH-Commit: [7/10] d58b439eb093f5dd3b7ca081af0ab75780e42917 (lulu6/qemu-kvm3)
7f1c5b
7f1c5b
https://bugzilla.redhat.com/show_bug.cgi?id=1905805
7f1c5b
Add functions to support configure interrupt.
7f1c5b
The configure interrupt process will start in vhost_dev_start
7f1c5b
and stop in vhost_dev_stop.
7f1c5b
7f1c5b
Also add the functions to support vhost_config_pending and
7f1c5b
vhost_config_mask.
7f1c5b
7f1c5b
Signed-off-by: Cindy Lu <lulu@redhat.com>
7f1c5b
Message-Id: <20221222070451.936503-8-lulu@redhat.com>
7f1c5b
Acked-by: Jason Wang <jasowang@redhat.com>
7f1c5b
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
7f1c5b
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
7f1c5b
(cherry picked from commit f9a09ca3ea69d108d828b7c82f1bd61b2df6fc96)
7f1c5b
Signed-off-by: Cindy Lu <lulu@redhat.com>
7f1c5b
---
7f1c5b
 hw/virtio/vhost.c         | 78 ++++++++++++++++++++++++++++++++++++++-
7f1c5b
 include/hw/virtio/vhost.h |  4 ++
7f1c5b
 2 files changed, 81 insertions(+), 1 deletion(-)
7f1c5b
7f1c5b
diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
7f1c5b
index 7fb008bc9e..84dbb39e07 100644
7f1c5b
--- a/hw/virtio/vhost.c
7f1c5b
+++ b/hw/virtio/vhost.c
7f1c5b
@@ -1596,7 +1596,68 @@ void vhost_virtqueue_mask(struct vhost_dev *hdev, VirtIODevice *vdev, int n,
7f1c5b
     file.index = hdev->vhost_ops->vhost_get_vq_index(hdev, n);
7f1c5b
     r = hdev->vhost_ops->vhost_set_vring_call(hdev, &file;;
7f1c5b
     if (r < 0) {
7f1c5b
-        VHOST_OPS_DEBUG(r, "vhost_set_vring_call failed");
7f1c5b
+        error_report("vhost_set_vring_call failed %d", -r);
7f1c5b
+    }
7f1c5b
+}
7f1c5b
+
7f1c5b
+bool vhost_config_pending(struct vhost_dev *hdev)
7f1c5b
+{
7f1c5b
+    assert(hdev->vhost_ops);
7f1c5b
+    if ((hdev->started == false) ||
7f1c5b
+        (hdev->vhost_ops->vhost_set_config_call == NULL)) {
7f1c5b
+        return false;
7f1c5b
+    }
7f1c5b
+
7f1c5b
+    EventNotifier *notifier =
7f1c5b
+        &hdev->vqs[VHOST_QUEUE_NUM_CONFIG_INR].masked_config_notifier;
7f1c5b
+    return event_notifier_test_and_clear(notifier);
7f1c5b
+}
7f1c5b
+
7f1c5b
+void vhost_config_mask(struct vhost_dev *hdev, VirtIODevice *vdev, bool mask)
7f1c5b
+{
7f1c5b
+    int fd;
7f1c5b
+    int r;
7f1c5b
+    EventNotifier *notifier =
7f1c5b
+        &hdev->vqs[VHOST_QUEUE_NUM_CONFIG_INR].masked_config_notifier;
7f1c5b
+    EventNotifier *config_notifier = &vdev->config_notifier;
7f1c5b
+    assert(hdev->vhost_ops);
7f1c5b
+
7f1c5b
+    if ((hdev->started == false) ||
7f1c5b
+        (hdev->vhost_ops->vhost_set_config_call == NULL)) {
7f1c5b
+        return;
7f1c5b
+    }
7f1c5b
+    if (mask) {
7f1c5b
+        assert(vdev->use_guest_notifier_mask);
7f1c5b
+        fd = event_notifier_get_fd(notifier);
7f1c5b
+    } else {
7f1c5b
+        fd = event_notifier_get_fd(config_notifier);
7f1c5b
+    }
7f1c5b
+    r = hdev->vhost_ops->vhost_set_config_call(hdev, fd);
7f1c5b
+    if (r < 0) {
7f1c5b
+        error_report("vhost_set_config_call failed %d", -r);
7f1c5b
+    }
7f1c5b
+}
7f1c5b
+
7f1c5b
+static void vhost_stop_config_intr(struct vhost_dev *dev)
7f1c5b
+{
7f1c5b
+    int fd = -1;
7f1c5b
+    assert(dev->vhost_ops);
7f1c5b
+    if (dev->vhost_ops->vhost_set_config_call) {
7f1c5b
+        dev->vhost_ops->vhost_set_config_call(dev, fd);
7f1c5b
+    }
7f1c5b
+}
7f1c5b
+
7f1c5b
+static void vhost_start_config_intr(struct vhost_dev *dev)
7f1c5b
+{
7f1c5b
+    int r;
7f1c5b
+
7f1c5b
+    assert(dev->vhost_ops);
7f1c5b
+    int fd = event_notifier_get_fd(&dev->vdev->config_notifier);
7f1c5b
+    if (dev->vhost_ops->vhost_set_config_call) {
7f1c5b
+        r = dev->vhost_ops->vhost_set_config_call(dev, fd);
7f1c5b
+        if (!r) {
7f1c5b
+            event_notifier_set(&dev->vdev->config_notifier);
7f1c5b
+        }
7f1c5b
     }
7f1c5b
 }
7f1c5b
 
7f1c5b
@@ -1836,6 +1897,16 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev, bool vrings)
7f1c5b
         }
7f1c5b
     }
7f1c5b
 
7f1c5b
+    r = event_notifier_init(
7f1c5b
+        &hdev->vqs[VHOST_QUEUE_NUM_CONFIG_INR].masked_config_notifier, 0);
7f1c5b
+    if (r < 0) {
7f1c5b
+        return r;
7f1c5b
+    }
7f1c5b
+    event_notifier_test_and_clear(
7f1c5b
+        &hdev->vqs[VHOST_QUEUE_NUM_CONFIG_INR].masked_config_notifier);
7f1c5b
+    if (!vdev->use_guest_notifier_mask) {
7f1c5b
+        vhost_config_mask(hdev, vdev, true);
7f1c5b
+    }
7f1c5b
     if (hdev->log_enabled) {
7f1c5b
         uint64_t log_base;
7f1c5b
 
7f1c5b
@@ -1874,6 +1945,7 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev, bool vrings)
7f1c5b
             vhost_device_iotlb_miss(hdev, vq->used_phys, true);
7f1c5b
         }
7f1c5b
     }
7f1c5b
+    vhost_start_config_intr(hdev);
7f1c5b
     return 0;
7f1c5b
 fail_start:
7f1c5b
     if (vrings) {
7f1c5b
@@ -1903,6 +1975,9 @@ void vhost_dev_stop(struct vhost_dev *hdev, VirtIODevice *vdev, bool vrings)
7f1c5b
 
7f1c5b
     /* should only be called after backend is connected */
7f1c5b
     assert(hdev->vhost_ops);
7f1c5b
+    event_notifier_test_and_clear(
7f1c5b
+        &hdev->vqs[VHOST_QUEUE_NUM_CONFIG_INR].masked_config_notifier);
7f1c5b
+    event_notifier_test_and_clear(&vdev->config_notifier);
7f1c5b
 
7f1c5b
     trace_vhost_dev_stop(hdev, vdev->name, vrings);
7f1c5b
 
7f1c5b
@@ -1925,6 +2000,7 @@ void vhost_dev_stop(struct vhost_dev *hdev, VirtIODevice *vdev, bool vrings)
7f1c5b
         }
7f1c5b
         memory_listener_unregister(&hdev->iommu_listener);
7f1c5b
     }
7f1c5b
+    vhost_stop_config_intr(hdev);
7f1c5b
     vhost_log_put(hdev, true);
7f1c5b
     hdev->started = false;
7f1c5b
     vdev->vhost_started = false;
7f1c5b
diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h
7f1c5b
index 67a6807fac..05bedb2416 100644
7f1c5b
--- a/include/hw/virtio/vhost.h
7f1c5b
+++ b/include/hw/virtio/vhost.h
7f1c5b
@@ -33,6 +33,7 @@ struct vhost_virtqueue {
7f1c5b
     unsigned used_size;
7f1c5b
     EventNotifier masked_notifier;
7f1c5b
     EventNotifier error_notifier;
7f1c5b
+    EventNotifier masked_config_notifier;
7f1c5b
     struct vhost_dev *dev;
7f1c5b
 };
7f1c5b
 
7f1c5b
@@ -41,6 +42,7 @@ typedef unsigned long vhost_log_chunk_t;
7f1c5b
 #define VHOST_LOG_BITS (8 * sizeof(vhost_log_chunk_t))
7f1c5b
 #define VHOST_LOG_CHUNK (VHOST_LOG_PAGE * VHOST_LOG_BITS)
7f1c5b
 #define VHOST_INVALID_FEATURE_BIT   (0xff)
7f1c5b
+#define VHOST_QUEUE_NUM_CONFIG_INR 0
7f1c5b
 
7f1c5b
 struct vhost_log {
7f1c5b
     unsigned long long size;
7f1c5b
@@ -168,6 +170,8 @@ int vhost_dev_enable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev);
7f1c5b
  * Disable direct notifications to vhost device.
7f1c5b
  */
7f1c5b
 void vhost_dev_disable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev);
7f1c5b
+bool vhost_config_pending(struct vhost_dev *hdev);
7f1c5b
+void vhost_config_mask(struct vhost_dev *hdev, VirtIODevice *vdev, bool mask);
7f1c5b
 
7f1c5b
 /**
7f1c5b
  * vhost_dev_is_started() - report status of vhost device
7f1c5b
-- 
7f1c5b
2.31.1
7f1c5b