thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone
7f1c5b
From e04c76339580effae41617b690b58a6605e0f40b Mon Sep 17 00:00:00 2001
7f1c5b
From: Cindy Lu <lulu@redhat.com>
7f1c5b
Date: Thu, 22 Dec 2022 15:04:47 +0800
7f1c5b
Subject: [PATCH 06/31] virtio: 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: [6/10] 7048eb488b732578686d451684babaf17b582b05 (lulu6/qemu-kvm3)
7f1c5b
7f1c5b
https://bugzilla.redhat.com/show_bug.cgi?id=1905805
7f1c5b
Add the functions to support the configure interrupt in virtio
7f1c5b
The function virtio_config_guest_notifier_read will notify the
7f1c5b
guest if there is an configure interrupt.
7f1c5b
The function virtio_config_set_guest_notifier_fd_handler is
7f1c5b
to set the fd hander for the notifier
7f1c5b
7f1c5b
Signed-off-by: Cindy Lu <lulu@redhat.com>
7f1c5b
Message-Id: <20221222070451.936503-7-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 7d847d0c9b93b91160f40d69a65c904d76f1edd8)
7f1c5b
Signed-off-by: Cindy Lu <lulu@redhat.com>
7f1c5b
---
7f1c5b
 hw/virtio/virtio.c         | 29 +++++++++++++++++++++++++++++
7f1c5b
 include/hw/virtio/virtio.h |  4 ++++
7f1c5b
 2 files changed, 33 insertions(+)
7f1c5b
7f1c5b
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
7f1c5b
index eb6347ab5d..34e9c5d141 100644
7f1c5b
--- a/hw/virtio/virtio.c
7f1c5b
+++ b/hw/virtio/virtio.c
7f1c5b
@@ -4012,7 +4012,14 @@ static void virtio_queue_guest_notifier_read(EventNotifier *n)
7f1c5b
         virtio_irq(vq);
7f1c5b
     }
7f1c5b
 }
7f1c5b
+static void virtio_config_guest_notifier_read(EventNotifier *n)
7f1c5b
+{
7f1c5b
+    VirtIODevice *vdev = container_of(n, VirtIODevice, config_notifier);
7f1c5b
 
7f1c5b
+    if (event_notifier_test_and_clear(n)) {
7f1c5b
+        virtio_notify_config(vdev);
7f1c5b
+    }
7f1c5b
+}
7f1c5b
 void virtio_queue_set_guest_notifier_fd_handler(VirtQueue *vq, bool assign,
7f1c5b
                                                 bool with_irqfd)
7f1c5b
 {
7f1c5b
@@ -4029,6 +4036,23 @@ void virtio_queue_set_guest_notifier_fd_handler(VirtQueue *vq, bool assign,
7f1c5b
     }
7f1c5b
 }
7f1c5b
 
7f1c5b
+void virtio_config_set_guest_notifier_fd_handler(VirtIODevice *vdev,
7f1c5b
+                                                 bool assign, bool with_irqfd)
7f1c5b
+{
7f1c5b
+    EventNotifier *n;
7f1c5b
+    n = &vdev->config_notifier;
7f1c5b
+    if (assign && !with_irqfd) {
7f1c5b
+        event_notifier_set_handler(n, virtio_config_guest_notifier_read);
7f1c5b
+    } else {
7f1c5b
+        event_notifier_set_handler(n, NULL);
7f1c5b
+    }
7f1c5b
+    if (!assign) {
7f1c5b
+        /* Test and clear notifier before closing it,*/
7f1c5b
+        /* in case poll callback didn't have time to run. */
7f1c5b
+        virtio_config_guest_notifier_read(n);
7f1c5b
+    }
7f1c5b
+}
7f1c5b
+
7f1c5b
 EventNotifier *virtio_queue_get_guest_notifier(VirtQueue *vq)
7f1c5b
 {
7f1c5b
     return &vq->guest_notifier;
7f1c5b
@@ -4109,6 +4133,11 @@ EventNotifier *virtio_queue_get_host_notifier(VirtQueue *vq)
7f1c5b
     return &vq->host_notifier;
7f1c5b
 }
7f1c5b
 
7f1c5b
+EventNotifier *virtio_config_get_guest_notifier(VirtIODevice *vdev)
7f1c5b
+{
7f1c5b
+    return &vdev->config_notifier;
7f1c5b
+}
7f1c5b
+
7f1c5b
 void virtio_queue_set_host_notifier_enabled(VirtQueue *vq, bool enabled)
7f1c5b
 {
7f1c5b
     vq->host_notifier_enabled = enabled;
7f1c5b
diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
7f1c5b
index 1f4a41b958..9c3a4642f2 100644
7f1c5b
--- a/include/hw/virtio/virtio.h
7f1c5b
+++ b/include/hw/virtio/virtio.h
7f1c5b
@@ -138,6 +138,7 @@ struct VirtIODevice
7f1c5b
     AddressSpace *dma_as;
7f1c5b
     QLIST_HEAD(, VirtQueue) *vector_queues;
7f1c5b
     QTAILQ_ENTRY(VirtIODevice) next;
7f1c5b
+    EventNotifier config_notifier;
7f1c5b
 };
7f1c5b
 
7f1c5b
 struct VirtioDeviceClass {
7f1c5b
@@ -360,6 +361,9 @@ void virtio_queue_aio_attach_host_notifier_no_poll(VirtQueue *vq, AioContext *ct
7f1c5b
 void virtio_queue_aio_detach_host_notifier(VirtQueue *vq, AioContext *ctx);
7f1c5b
 VirtQueue *virtio_vector_first_queue(VirtIODevice *vdev, uint16_t vector);
7f1c5b
 VirtQueue *virtio_vector_next_queue(VirtQueue *vq);
7f1c5b
+EventNotifier *virtio_config_get_guest_notifier(VirtIODevice *vdev);
7f1c5b
+void virtio_config_set_guest_notifier_fd_handler(VirtIODevice *vdev,
7f1c5b
+                                                 bool assign, bool with_irqfd);
7f1c5b
 
7f1c5b
 static inline void virtio_add_feature(uint64_t *features, unsigned int fbit)
7f1c5b
 {
7f1c5b
-- 
7f1c5b
2.31.1
7f1c5b