Skip to contentSkip to conversation

vhost-vdpa: add support for configure interrupt

PATCH Superseded Cindy Lu 3 participants 16 messages Jan 26, 2021 – Jan 27, 2021

v3 of 21 Superseded Latest is v21 →

lore
Share & tools
lore

Cindy Lu

author
#0 lore raw

v3 cover vhost-vdpa: add support for configure interrupt

These code are all tested in vp-vdpa (support configure interrupt) vdpa_sim (not support configure interrupt)

test in virtio-pci bus and virtio-mmio bus

change in v2:
Add support fot virtio-mmio bus
active the notifier wihle the backend support configure intterrput misc fixes form v1

change in v3
fix the coding style problems

Cindy Lu (5):
virtio: add support for configure interrupt
vhost_net: enable configure interrupt when vhost_net start
virtio-pci: add support for configure interrupt
virtio-mmio: add support for configure interrupt
vhost-vdpa: add callback function for configure interrupt

 hw/net/vhost_net.c                | 19 ++++++-
 hw/virtio/trace-events            |  2 +
 hw/virtio/vhost-vdpa.c            | 37 ++++++++++++-
 hw/virtio/virtio-mmio.c           | 16 ++++++
 hw/virtio/virtio-pci.c            | 92 +++++++++++++++++++++++++------
 hw/virtio/virtio.c                | 26 +++++++++
 include/hw/virtio/vhost-backend.h |  4 ++
 include/hw/virtio/virtio-bus.h    |  2 +
 include/hw/virtio/virtio.h        |  6 ++
 9 files changed, 185 insertions(+), 19 deletions(-)
Signature · 1 line
2.21.3
author
#1 lore raw

PATCH v3 1/5 virtio: add support for configure interrupt

Add configure notifier and virtio_set_config_notifier_fd_handler in virtio

---
 hw/virtio/virtio.c             | 26 ++++++++++++++++++++++++++
 include/hw/virtio/virtio-bus.h |  2 ++
 include/hw/virtio/virtio.h     |  6 ++++++
 3 files changed, 34 insertions(+)
hw/virtio/virtio.c +26 -0
index ceb58fda6c..25e164cf8a 100644
@@ -3502,6 +3502,16 @@ static void virtio_queue_guest_notifier_read(EventNotifier *n)
     }
 }
 
+static void virtio_config_read(EventNotifier *n)
+{
+    VirtIODevice *vdev = container_of(n, VirtIODevice, config_notifier);
+    if (!vdev->use_config_notifier) {
+        return;
+    }
+    if (event_notifier_test_and_clear(n)) {
+        virtio_notify_config(vdev);
+    }
+}
 void virtio_queue_set_guest_notifier_fd_handler(VirtQueue *vq, bool assign,
                                                 bool with_irqfd)
 {
@@ -3518,6 +3528,17 @@ void virtio_queue_set_guest_notifier_fd_handler(VirtQueue *vq, bool assign,
     }
 }
 
+void virtio_set_config_notifier_fd_handler(VirtIODevice *vdev, bool assign,
+                                                bool with_irqfd)
+{
+    if (assign && !with_irqfd) {
+        event_notifier_set_handler(&vdev->config_notifier,
+                                   virtio_config_read);
+    } else {
+       event_notifier_set_handler(&vdev->config_notifier, NULL);
+    }
+}
+
 EventNotifier *virtio_queue_get_guest_notifier(VirtQueue *vq)
 {
     return &vq->guest_notifier;
@@ -3591,6 +3612,11 @@ EventNotifier *virtio_queue_get_host_notifier(VirtQueue *vq)
     return &vq->host_notifier;
 }
 
+EventNotifier *virtio_get_config_notifier(VirtIODevice *vdev)
+{
+    return &vdev->config_notifier;
+
+}
 void virtio_queue_set_host_notifier_enabled(VirtQueue *vq, bool enabled)
 {
     vq->host_notifier_enabled = enabled;
include/hw/virtio/virtio-bus.h +2 -0
index ef8abe49c5..97e13ec484 100644
@@ -93,6 +93,8 @@ struct VirtioBusClass {
      */
     bool has_variable_vring_alignment;
     AddressSpace *(*get_dma_as)(DeviceState *d);
+    int (*set_config_notifiers)(DeviceState *d, bool assign);
+
 };
 
 struct VirtioBusState {
include/hw/virtio/virtio.h +6 -0
index b7ece7a6a8..79f2f78625 100644
@@ -108,6 +108,8 @@ struct VirtIODevice
     bool use_guest_notifier_mask;
     AddressSpace *dma_as;
     QLIST_HEAD(, VirtQueue) *vector_queues;
+    EventNotifier config_notifier;
+    bool use_config_notifier;
 };
 
 struct VirtioDeviceClass {
@@ -310,11 +312,15 @@ uint16_t virtio_get_queue_index(VirtQueue *vq);
 EventNotifier *virtio_queue_get_guest_notifier(VirtQueue *vq);
 void virtio_queue_set_guest_notifier_fd_handler(VirtQueue *vq, bool assign,
                                                 bool with_irqfd);
+void virtio_set_config_notifier_fd_handler(VirtIODevice *vdev, bool assign,
+                                                bool with_irqfd);
+
 int virtio_device_start_ioeventfd(VirtIODevice *vdev);
 int virtio_device_grab_ioeventfd(VirtIODevice *vdev);
 void virtio_device_release_ioeventfd(VirtIODevice *vdev);
 bool virtio_device_ioeventfd_enabled(VirtIODevice *vdev);
 EventNotifier *virtio_queue_get_host_notifier(VirtQueue *vq);
+EventNotifier *virtio_get_config_notifier(VirtIODevice *vdev);
 void virtio_queue_set_host_notifier_enabled(VirtQueue *vq, bool enabled);
 void virtio_queue_host_notifier_read(EventNotifier *n);
 void virtio_queue_aio_set_host_notifier_handler(VirtQueue *vq, AioContext *ctx,
Signature · 1 line
2.21.3
#2 lore raw

Re: [PATCH v3 1/5] virtio: add support for configure interrupt

Quoted 2 lines · Cindy Lu

Add configure notifier and virtio_set_config_notifier_fd_handler in virtio

The title and commit log is kind of misleading.

I think we should use "virtio: add guest notifier for config interrupt"

Quoted 77 lines
---
  hw/virtio/virtio.c             | 26 ++++++++++++++++++++++++++
  include/hw/virtio/virtio-bus.h |  2 ++
  include/hw/virtio/virtio.h     |  6 ++++++
  3 files changed, 34 insertions(+)
hw/virtio/virtio.c +26 -0
index ceb58fda6c..25e164cf8a 100644
@@ -3502,6 +3502,16 @@ static void virtio_queue_guest_notifier_read(EventNotifier *n)
      }
  }
 
+static void virtio_config_read(EventNotifier *n)
+{
+    VirtIODevice *vdev = container_of(n, VirtIODevice, config_notifier);
+    if (!vdev->use_config_notifier) {
+        return;
+    }
+    if (event_notifier_test_and_clear(n)) {
+        virtio_notify_config(vdev);
+    }
+}
  void virtio_queue_set_guest_notifier_fd_handler(VirtQueue *vq, bool assign,
                                                  bool with_irqfd)
  {
@@ -3518,6 +3528,17 @@ void virtio_queue_set_guest_notifier_fd_handler(VirtQueue *vq, bool assign,
      }
  }
 
+void virtio_set_config_notifier_fd_handler(VirtIODevice *vdev, bool assign,
+                                                bool with_irqfd)
+{
+    if (assign && !with_irqfd) {
+        event_notifier_set_handler(&vdev->config_notifier,
+                                   virtio_config_read);
+    } else {
+       event_notifier_set_handler(&vdev->config_notifier, NULL);
+    }
+}
+
  EventNotifier *virtio_queue_get_guest_notifier(VirtQueue *vq)
  {
      return &vq->guest_notifier;
@@ -3591,6 +3612,11 @@ EventNotifier *virtio_queue_get_host_notifier(VirtQueue *vq)
      return &vq->host_notifier;
  }
 
+EventNotifier *virtio_get_config_notifier(VirtIODevice *vdev)
+{
+    return &vdev->config_notifier;
+
+}
  void virtio_queue_set_host_notifier_enabled(VirtQueue *vq, bool enabled)
  {
      vq->host_notifier_enabled = enabled;
include/hw/virtio/virtio-bus.h +2 -0
index ef8abe49c5..97e13ec484 100644
@@ -93,6 +93,8 @@ struct VirtioBusClass {
       */
      bool has_variable_vring_alignment;
      AddressSpace *(*get_dma_as)(DeviceState *d);
+    int (*set_config_notifiers)(DeviceState *d, bool assign);
+
  };
 
  struct VirtioBusState {
include/hw/virtio/virtio.h +0 -0
index b7ece7a6a8..79f2f78625 100644

include/hw/virtio/virtio.h struct VirtIODevice · line 112

Quoted 5 lines
include/hw/virtio/virtio.h +2 -0
@@ -108,6 +108,8 @@ struct VirtIODevice
      bool use_guest_notifier_mask;
      AddressSpace *dma_as;
      QLIST_HEAD(, VirtQueue) *vector_queues;
+    EventNotifier config_notifier;
+    bool use_config_notifier;

Let's document those two fields.

Thanks

Quoted 19 lines
include/hw/virtio/virtio.h +4 -0
  };
 
  struct VirtioDeviceClass {
@@ -310,11 +312,15 @@ uint16_t virtio_get_queue_index(VirtQueue *vq);
  EventNotifier *virtio_queue_get_guest_notifier(VirtQueue *vq);
  void virtio_queue_set_guest_notifier_fd_handler(VirtQueue *vq, bool assign,
                                                  bool with_irqfd);
+void virtio_set_config_notifier_fd_handler(VirtIODevice *vdev, bool assign,
+                                                bool with_irqfd);
+
  int virtio_device_start_ioeventfd(VirtIODevice *vdev);
  int virtio_device_grab_ioeventfd(VirtIODevice *vdev);
  void virtio_device_release_ioeventfd(VirtIODevice *vdev);
  bool virtio_device_ioeventfd_enabled(VirtIODevice *vdev);
  EventNotifier *virtio_queue_get_host_notifier(VirtQueue *vq);
+EventNotifier *virtio_get_config_notifier(VirtIODevice *vdev);
  void virtio_queue_set_host_notifier_enabled(VirtQueue *vq, bool enabled);
  void virtio_queue_host_notifier_read(EventNotifier *n);
  void virtio_queue_aio_set_host_notifier_handler(VirtQueue *vq, AioContext *ctx,
author
#3 lore raw

PATCH v3 2/5 vhost_net: enable configure interrupt when vhost_net start

In reply to Cindy Lu

While peer is vhost vdpa, setup the configure interrupt function vhost_net_start and release the resource when vhost_net_stop

---
 hw/net/vhost_net.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
hw/net/vhost_net.c +18 -1
index 24d555e764..0660da474a 100644
@@ -345,6 +345,15 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs,
         error_report("Error binding guest notifier: %d", -r);
         goto err;
     }
+    if (ncs->peer && ncs->peer->info->type == NET_CLIENT_DRIVER_VHOST_VDPA) {
+        if (k->set_config_notifiers) {
+            r = k->set_config_notifiers(qbus->parent, true);
+            if (r < 0) {
+                error_report("Error binding config notifier: %d", -r);
+                goto err;
+            }
+       }
+    }
 
     for (i = 0; i < total_queues; i++) {
         peer = qemu_get_peer(ncs, i);
@@ -391,7 +400,15 @@ void vhost_net_stop(VirtIODevice *dev, NetClientState *ncs,
     for (i = 0; i < total_queues; i++) {
         vhost_net_stop_one(get_vhost_net(ncs[i].peer), dev);
     }
-
+   if (ncs->peer && ncs->peer->info->type == NET_CLIENT_DRIVER_VHOST_VDPA) {
+        if (k->set_config_notifiers) {
+            r = k->set_config_notifiers(qbus->parent, false);
+            if (r < 0) {
+                error_report("Error unbinding config notifier: %d", -r);
+            }
+           assert(r >= 0);
+        }
+    }
     r = k->set_guest_notifiers(qbus->parent, total_queues * 2, false);
     if (r < 0) {
         fprintf(stderr, "vhost guest notifier cleanup failed: %d\n", r);
Signature · 1 line
2.21.3
#4 lore raw

Re: [PATCH v3 2/5] vhost_net: enable configure interrupt when vhost_net start

Quoted 29 lines · Cindy Lu

While peer is vhost vdpa, setup the configure interrupt function vhost_net_start and release the resource when vhost_net_stop

---
  hw/net/vhost_net.c | 19 ++++++++++++++++++-
  1 file changed, 18 insertions(+), 1 deletion(-)
hw/net/vhost_net.c +9 -0
index 24d555e764..0660da474a 100644
@@ -345,6 +345,15 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs,
          error_report("Error binding guest notifier: %d", -r);
          goto err;
      }
+    if (ncs->peer && ncs->peer->info->type == NET_CLIENT_DRIVER_VHOST_VDPA) {
+        if (k->set_config_notifiers) {
+            r = k->set_config_notifiers(qbus->parent, true);
+            if (r < 0) {
+                error_report("Error binding config notifier: %d", -r);
+                goto err;
+            }
+       }
+    }
 
      for (i = 0; i < total_queues; i++) {
          peer = qemu_get_peer(ncs, i);

hw/net/vhost_net.c void vhost_net_stop(VirtIODevice *dev, NetClientState *ncs, · line 404

Quoted 6 lines
hw/net/vhost_net.c +2 -1
@@ -391,7 +400,15 @@ void vhost_net_stop(VirtIODevice *dev, NetClientState *ncs,
      for (i = 0; i < total_queues; i++) {
          vhost_net_stop_one(get_vhost_net(ncs[i].peer), dev);
      }
-
+   if (ncs->peer && ncs->peer->info->type == NET_CLIENT_DRIVER_VHOST_VDPA) {
+        if (k->set_config_notifiers) {

It looks to me that checking k->set_config_notifier is sufficient here.

Thanks

Quoted 10 lines
hw/net/vhost_net.c +7 -0
+            r = k->set_config_notifiers(qbus->parent, false);
+            if (r < 0) {
+                error_report("Error unbinding config notifier: %d", -r);
+            }
+           assert(r >= 0);
+        }
+    }
      r = k->set_guest_notifiers(qbus->parent, total_queues * 2, false);
      if (r < 0) {
          fprintf(stderr, "vhost guest notifier cleanup failed: %d\n", r);
author
#5 lore raw

Re: [PATCH v3 2/5] vhost_net: enable configure interrupt when vhost_net start

Quoted 42 lines · Jason Wang
Quoted 29 lines · Cindy Lu

While peer is vhost vdpa, setup the configure interrupt function vhost_net_start and release the resource when vhost_net_stop

---
  hw/net/vhost_net.c | 19 ++++++++++++++++++-
  1 file changed, 18 insertions(+), 1 deletion(-)
hw/net/vhost_net.c +9 -0
index 24d555e764..0660da474a 100644
@@ -345,6 +345,15 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs,
          error_report("Error binding guest notifier: %d", -r);
          goto err;
      }
+    if (ncs->peer && ncs->peer->info->type == NET_CLIENT_DRIVER_VHOST_VDPA) {
+        if (k->set_config_notifiers) {
+            r = k->set_config_notifiers(qbus->parent, true);
+            if (r < 0) {
+                error_report("Error binding config notifier: %d", -r);
+                goto err;
+            }
+       }
+    }
 
      for (i = 0; i < total_queues; i++) {
          peer = qemu_get_peer(ncs, i);

hw/net/vhost_net.c void vhost_net_stop(VirtIODevice *dev, NetClientState *ncs, · line 404

Quoted 6 lines
hw/net/vhost_net.c +2 -1
@@ -391,7 +400,15 @@ void vhost_net_stop(VirtIODevice *dev, NetClientState *ncs,
      for (i = 0; i < total_queues; i++) {
          vhost_net_stop_one(get_vhost_net(ncs[i].peer), dev);
      }
-
+   if (ncs->peer && ncs->peer->info->type == NET_CLIENT_DRIVER_VHOST_VDPA) {
+        if (k->set_config_notifiers) {

It looks to me that checking k->set_config_notifier is sufficient here.

Quoted 3 lines

Thanks

sure will fix this

Quoted 11 lines
Quoted 10 lines
hw/net/vhost_net.c +7 -0
+            r = k->set_config_notifiers(qbus->parent, false);
+            if (r < 0) {
+                error_report("Error unbinding config notifier: %d", -r);
+            }
+           assert(r >= 0);
+        }
+    }
      r = k->set_guest_notifiers(qbus->parent, total_queues * 2, false);
      if (r < 0) {
          fprintf(stderr, "vhost guest notifier cleanup failed: %d\n", r);
author
#6 lore raw

PATCH v3 3/5 virtio-pci: add support for configure interrupt

In reply to Cindy Lu

Add support for configure interrupt, use kvm_irqfd_assign and set the gsi to kernel. When the configure notifier was eventfd_signal by host kernel, this will finally inject an msix interrupt to guest

---
 hw/virtio/virtio-pci.c | 92 ++++++++++++++++++++++++++++++++++--------
 1 file changed, 75 insertions(+), 17 deletions(-)
hw/virtio/virtio-pci.c +75 -17
index 36524a5728..8e192600b8 100644
@@ -664,7 +664,6 @@ static uint32_t virtio_read_config(PCIDevice *pci_dev,
 }
 
 static int kvm_virtio_pci_vq_vector_use(VirtIOPCIProxy *proxy,
-                                        unsigned int queue_no,
                                         unsigned int vector)
 {
     VirtIOIRQFD *irqfd = &proxy->vector_irqfd[vector];
@@ -691,23 +690,17 @@ static void kvm_virtio_pci_vq_vector_release(VirtIOPCIProxy *proxy,
 }
 
 static int kvm_virtio_pci_irqfd_use(VirtIOPCIProxy *proxy,
-                                 unsigned int queue_no,
+                                 EventNotifier *n,
                                  unsigned int vector)
 {
     VirtIOIRQFD *irqfd = &proxy->vector_irqfd[vector];
-    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
-    VirtQueue *vq = virtio_get_queue(vdev, queue_no);
-    EventNotifier *n = virtio_queue_get_guest_notifier(vq);
     return kvm_irqchip_add_irqfd_notifier_gsi(kvm_state, n, NULL, irqfd->virq);
 }
 
 static void kvm_virtio_pci_irqfd_release(VirtIOPCIProxy *proxy,
-                                      unsigned int queue_no,
+                                      EventNotifier *n ,
                                       unsigned int vector)
 {
-    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
-    VirtQueue *vq = virtio_get_queue(vdev, queue_no);
-    EventNotifier *n = virtio_queue_get_guest_notifier(vq);
     VirtIOIRQFD *irqfd = &proxy->vector_irqfd[vector];
     int ret;
 
@@ -722,7 +715,8 @@ static int kvm_virtio_pci_vector_use(VirtIOPCIProxy *proxy, int nvqs)
     VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
     unsigned int vector;
     int ret, queue_no;
-
+    VirtQueue *vq;
+    EventNotifier *n;
     for (queue_no = 0; queue_no < nvqs; queue_no++) {
         if (!virtio_queue_get_num(vdev, queue_no)) {
             break;
@@ -731,7 +725,7 @@ static int kvm_virtio_pci_vector_use(VirtIOPCIProxy *proxy, int nvqs)
         if (vector >= msix_nr_vectors_allocated(dev)) {
             continue;
         }
-        ret = kvm_virtio_pci_vq_vector_use(proxy, queue_no, vector);
+        ret = kvm_virtio_pci_vq_vector_use(proxy,  vector);
         if (ret < 0) {
             goto undo;
         }
@@ -739,7 +733,9 @@ static int kvm_virtio_pci_vector_use(VirtIOPCIProxy *proxy, int nvqs)
          * Otherwise, delay until unmasked in the frontend.
          */
         if (vdev->use_guest_notifier_mask && k->guest_notifier_mask) {
-            ret = kvm_virtio_pci_irqfd_use(proxy, queue_no, vector);
+            vq = virtio_get_queue(vdev, queue_no);
+            n = virtio_queue_get_guest_notifier(vq);
+            ret = kvm_virtio_pci_irqfd_use(proxy, n, vector);
             if (ret < 0) {
                 kvm_virtio_pci_vq_vector_release(proxy, vector);
                 goto undo;
@@ -755,13 +751,69 @@ undo:
             continue;
         }
         if (vdev->use_guest_notifier_mask && k->guest_notifier_mask) {
-            kvm_virtio_pci_irqfd_release(proxy, queue_no, vector);
+            vq = virtio_get_queue(vdev, queue_no);
+            n = virtio_queue_get_guest_notifier(vq);
+            kvm_virtio_pci_irqfd_release(proxy, n, vector);
         }
         kvm_virtio_pci_vq_vector_release(proxy, vector);
     }
     return ret;
 }
 
+static int kvm_virtio_pci_vector_config_use(VirtIOPCIProxy *proxy)
+{
+
+    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
+    unsigned int vector;
+    int ret;
+    EventNotifier *n = virtio_get_config_notifier(vdev);
+
+    vector = vdev->config_vector ;
+    ret = kvm_virtio_pci_vq_vector_use(proxy, vector);
+    if (ret < 0) {
+        goto undo;
+    }
+    ret = kvm_virtio_pci_irqfd_use(proxy,  n, vector);
+    if (ret < 0) {
+        goto undo;
+    }
+    return 0;
+undo:
+    kvm_virtio_pci_irqfd_release(proxy, n, vector);
+    return ret;
+}
+static void kvm_virtio_pci_vector_config_release(VirtIOPCIProxy *proxy)
+{
+    PCIDevice *dev = &proxy->pci_dev;
+    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
+    unsigned int vector;
+    EventNotifier *n = virtio_get_config_notifier(vdev);
+    vector = vdev->config_vector ;
+    if (vector >= msix_nr_vectors_allocated(dev)) {
+        return;
+    }
+    kvm_virtio_pci_irqfd_release(proxy, n, vector);
+    kvm_virtio_pci_vq_vector_release(proxy, vector);
+}
+
+static int virtio_pci_set_config_notifier(DeviceState *d,  bool assign)
+{
+    VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d);
+    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
+    EventNotifier *notifier = virtio_get_config_notifier(vdev);
+    int r = 0;
+    if (assign) {
+        r = event_notifier_init(notifier, 0);
+        virtio_set_config_notifier_fd_handler(vdev, true, true);
+        kvm_virtio_pci_vector_config_use(proxy);
+    } else {
+        virtio_set_config_notifier_fd_handler(vdev, false, true);
+        kvm_virtio_pci_vector_config_release(proxy);
+        event_notifier_cleanup(notifier);
+    }
+    return r;
+}
+
 static void kvm_virtio_pci_vector_release(VirtIOPCIProxy *proxy, int nvqs)
 {
     PCIDevice *dev = &proxy->pci_dev;
@@ -769,7 +821,8 @@ static void kvm_virtio_pci_vector_release(VirtIOPCIProxy *proxy, int nvqs)
     unsigned int vector;
     int queue_no;
     VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
-
+    VirtQueue *vq;
+    EventNotifier *n;
     for (queue_no = 0; queue_no < nvqs; queue_no++) {
         if (!virtio_queue_get_num(vdev, queue_no)) {
             break;
@@ -782,7 +835,9 @@ static void kvm_virtio_pci_vector_release(VirtIOPCIProxy *proxy, int nvqs)
          * Otherwise, it was cleaned when masked in the frontend.
          */
         if (vdev->use_guest_notifier_mask && k->guest_notifier_mask) {
-            kvm_virtio_pci_irqfd_release(proxy, queue_no, vector);
+            vq = virtio_get_queue(vdev, queue_no);
+            n = virtio_queue_get_guest_notifier(vq);
+            kvm_virtio_pci_irqfd_release(proxy, n, vector);
         }
         kvm_virtio_pci_vq_vector_release(proxy, vector);
     }
@@ -823,7 +878,7 @@ static int virtio_pci_vq_vector_unmask(VirtIOPCIProxy *proxy,
             event_notifier_set(n);
         }
     } else {
-        ret = kvm_virtio_pci_irqfd_use(proxy, queue_no, vector);
+        ret = kvm_virtio_pci_irqfd_use(proxy, n, vector);
     }
     return ret;
 }
@@ -835,13 +890,15 @@ static void virtio_pci_vq_vector_mask(VirtIOPCIProxy *proxy,
     VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
     VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
 
+    VirtQueue *vq = virtio_get_queue(vdev, queue_no);
+    EventNotifier *n = virtio_queue_get_guest_notifier(vq);
     /* If guest supports masking, keep irqfd but mask it.
      * Otherwise, clean it up now.
      */ 
     if (vdev->use_guest_notifier_mask && k->guest_notifier_mask) {
         k->guest_notifier_mask(vdev, queue_no, true);
     } else {
-        kvm_virtio_pci_irqfd_release(proxy, queue_no, vector);
+        kvm_virtio_pci_irqfd_release(proxy, n, vector);
     }
 }
 
@@ -2137,6 +2194,7 @@ static void virtio_pci_bus_class_init(ObjectClass *klass, void *data)
     k->ioeventfd_assign = virtio_pci_ioeventfd_assign;
     k->get_dma_as = virtio_pci_get_dma_as;
     k->queue_enabled = virtio_pci_queue_enabled;
+    k->set_config_notifiers = virtio_pci_set_config_notifier;
 }
 
 static const TypeInfo virtio_pci_bus_info = {
Signature · 1 line
2.21.3
#7 lore raw

Re: [PATCH v3 3/5] virtio-pci: add support for configure interrupt

Quoted 48 lines · Cindy Lu

Add support for configure interrupt, use kvm_irqfd_assign and set the gsi to kernel. When the configure notifier was eventfd_signal by host kernel, this will finally inject an msix interrupt to guest

---
  hw/virtio/virtio-pci.c | 92 ++++++++++++++++++++++++++++++++++--------
  1 file changed, 75 insertions(+), 17 deletions(-)
hw/virtio/virtio-pci.c +2 -9
index 36524a5728..8e192600b8 100644
@@ -664,7 +664,6 @@ static uint32_t virtio_read_config(PCIDevice *pci_dev,
  }
 
  static int kvm_virtio_pci_vq_vector_use(VirtIOPCIProxy *proxy,
-                                        unsigned int queue_no,
                                          unsigned int vector)
  {
      VirtIOIRQFD *irqfd = &proxy->vector_irqfd[vector];
@@ -691,23 +690,17 @@ static void kvm_virtio_pci_vq_vector_release(VirtIOPCIProxy *proxy,
  }
 
  static int kvm_virtio_pci_irqfd_use(VirtIOPCIProxy *proxy,
-                                 unsigned int queue_no,
+                                 EventNotifier *n,
                                   unsigned int vector)
  {
      VirtIOIRQFD *irqfd = &proxy->vector_irqfd[vector];
-    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
-    VirtQueue *vq = virtio_get_queue(vdev, queue_no);
-    EventNotifier *n = virtio_queue_get_guest_notifier(vq);
      return kvm_irqchip_add_irqfd_notifier_gsi(kvm_state, n, NULL, irqfd->virq);
  }
 
  static void kvm_virtio_pci_irqfd_release(VirtIOPCIProxy *proxy,
-                                      unsigned int queue_no,
+                                      EventNotifier *n ,
                                        unsigned int vector)
  {
-    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
-    VirtQueue *vq = virtio_get_queue(vdev, queue_no);
-    EventNotifier *n = virtio_queue_get_guest_notifier(vq);
      VirtIOIRQFD *irqfd = &proxy->vector_irqfd[vector];
      int ret;
 

hw/virtio/virtio-pci.c static int kvm_virtio_pci_vector_use(VirtIOPCIProxy *proxy, int nvqs) · line 719

Quoted 6 lines
hw/virtio/virtio-pci.c +2 -1
@@ -722,7 +715,8 @@ static int kvm_virtio_pci_vector_use(VirtIOPCIProxy *proxy, int nvqs)
      VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
      unsigned int vector;
      int ret, queue_no;
-
+    VirtQueue *vq;
+    EventNotifier *n;

new line is needed.

Quoted 49 lines
hw/virtio/virtio-pci.c +19 -3
      for (queue_no = 0; queue_no < nvqs; queue_no++) {
          if (!virtio_queue_get_num(vdev, queue_no)) {
              break;
@@ -731,7 +725,7 @@ static int kvm_virtio_pci_vector_use(VirtIOPCIProxy *proxy, int nvqs)
          if (vector >= msix_nr_vectors_allocated(dev)) {
              continue;
          }
-        ret = kvm_virtio_pci_vq_vector_use(proxy, queue_no, vector);
+        ret = kvm_virtio_pci_vq_vector_use(proxy,  vector);
          if (ret < 0) {
              goto undo;
          }
@@ -739,7 +733,9 @@ static int kvm_virtio_pci_vector_use(VirtIOPCIProxy *proxy, int nvqs)
           * Otherwise, delay until unmasked in the frontend.
           */
          if (vdev->use_guest_notifier_mask && k->guest_notifier_mask) {
-            ret = kvm_virtio_pci_irqfd_use(proxy, queue_no, vector);
+            vq = virtio_get_queue(vdev, queue_no);
+            n = virtio_queue_get_guest_notifier(vq);
+            ret = kvm_virtio_pci_irqfd_use(proxy, n, vector);
              if (ret < 0) {
                  kvm_virtio_pci_vq_vector_release(proxy, vector);
                  goto undo;
@@ -755,13 +751,69 @@ undo:
              continue;
          }
          if (vdev->use_guest_notifier_mask && k->guest_notifier_mask) {
-            kvm_virtio_pci_irqfd_release(proxy, queue_no, vector);
+            vq = virtio_get_queue(vdev, queue_no);
+            n = virtio_queue_get_guest_notifier(vq);
+            kvm_virtio_pci_irqfd_release(proxy, n, vector);
          }
          kvm_virtio_pci_vq_vector_release(proxy, vector);
      }
      return ret;
  }
 
+static int kvm_virtio_pci_vector_config_use(VirtIOPCIProxy *proxy)
+{
+
+    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
+    unsigned int vector;
+    int ret;
+    EventNotifier *n = virtio_get_config_notifier(vdev);
+
+    vector = vdev->config_vector ;
+    ret = kvm_virtio_pci_vq_vector_use(proxy, vector);
+    if (ret < 0) {
+        goto undo;

hw/virtio/virtio-pci.c undo: · line 784

Quoted 10 lines
hw/virtio/virtio-pci.c +10 -0
+    }
+    ret = kvm_virtio_pci_irqfd_use(proxy,  n, vector);
+    if (ret < 0) {
+        goto undo;
+    }
+    return 0;
+undo:
+    kvm_virtio_pci_irqfd_release(proxy, n, vector);
+    return ret;
+}

newline is needed.

Quoted 21 lines
hw/virtio/virtio-pci.c +21 -0
+static void kvm_virtio_pci_vector_config_release(VirtIOPCIProxy *proxy)
+{
+    PCIDevice *dev = &proxy->pci_dev;
+    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
+    unsigned int vector;
+    EventNotifier *n = virtio_get_config_notifier(vdev);
+    vector = vdev->config_vector ;
+    if (vector >= msix_nr_vectors_allocated(dev)) {
+        return;
+    }
+    kvm_virtio_pci_irqfd_release(proxy, n, vector);
+    kvm_virtio_pci_vq_vector_release(proxy, vector);
+}
+
+static int virtio_pci_set_config_notifier(DeviceState *d,  bool assign)
+{
+    VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d);
+    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
+    EventNotifier *notifier = virtio_get_config_notifier(vdev);
+    int r = 0;
+    if (assign) {

hw/virtio/virtio-pci.c undo: · line 815

Quoted 10 lines
hw/virtio/virtio-pci.c +10 -0
+        r = event_notifier_init(notifier, 0);
+        virtio_set_config_notifier_fd_handler(vdev, true, true);
+        kvm_virtio_pci_vector_config_use(proxy);
+    } else {
+        virtio_set_config_notifier_fd_handler(vdev, false, true);
+        kvm_virtio_pci_vector_config_release(proxy);
+        event_notifier_cleanup(notifier);
+    }
+    return r;
+}

Two questions, don't we need to check whether or not MSIX is enalbed in this case? Instead of introducing new helpers that is easy to be buggy I still prefer to re-use virtio_pci_set_guest_notifier:

We can switch to use accepts EventNotifier instead of virtqueue index. And we need also convert virtqueue_set_guest_notifier_fd_handler() to accept EventNotifier.

hw/virtio/virtio-pci.c static void kvm_virtio_pci_vector_release(VirtIOPCIProxy *proxy, int nvqs) · line 825

Quoted 11 lines
hw/virtio/virtio-pci.c +3 -1
+
  static void kvm_virtio_pci_vector_release(VirtIOPCIProxy *proxy, int nvqs)
  {
      PCIDevice *dev = &proxy->pci_dev;
@@ -769,7 +821,8 @@ static void kvm_virtio_pci_vector_release(VirtIOPCIProxy *proxy, int nvqs)
      unsigned int vector;
      int queue_no;
      VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
-
+    VirtQueue *vq;
+    EventNotifier *n;

newline is needed.

Thanks

Quoted 48 lines
hw/virtio/virtio-pci.c +8 -3
      for (queue_no = 0; queue_no < nvqs; queue_no++) {
          if (!virtio_queue_get_num(vdev, queue_no)) {
              break;
@@ -782,7 +835,9 @@ static void kvm_virtio_pci_vector_release(VirtIOPCIProxy *proxy, int nvqs)
           * Otherwise, it was cleaned when masked in the frontend.
           */
          if (vdev->use_guest_notifier_mask && k->guest_notifier_mask) {
-            kvm_virtio_pci_irqfd_release(proxy, queue_no, vector);
+            vq = virtio_get_queue(vdev, queue_no);
+            n = virtio_queue_get_guest_notifier(vq);
+            kvm_virtio_pci_irqfd_release(proxy, n, vector);
          }
          kvm_virtio_pci_vq_vector_release(proxy, vector);
      }
@@ -823,7 +878,7 @@ static int virtio_pci_vq_vector_unmask(VirtIOPCIProxy *proxy,
              event_notifier_set(n);
          }
      } else {
-        ret = kvm_virtio_pci_irqfd_use(proxy, queue_no, vector);
+        ret = kvm_virtio_pci_irqfd_use(proxy, n, vector);
      }
      return ret;
  }
@@ -835,13 +890,15 @@ static void virtio_pci_vq_vector_mask(VirtIOPCIProxy *proxy,
      VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
      VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
 
+    VirtQueue *vq = virtio_get_queue(vdev, queue_no);
+    EventNotifier *n = virtio_queue_get_guest_notifier(vq);
      /* If guest supports masking, keep irqfd but mask it.
       * Otherwise, clean it up now.
       */
      if (vdev->use_guest_notifier_mask && k->guest_notifier_mask) {
          k->guest_notifier_mask(vdev, queue_no, true);
      } else {
-        kvm_virtio_pci_irqfd_release(proxy, queue_no, vector);
+        kvm_virtio_pci_irqfd_release(proxy, n, vector);
      }
  }
 
@@ -2137,6 +2194,7 @@ static void virtio_pci_bus_class_init(ObjectClass *klass, void *data)
      k->ioeventfd_assign = virtio_pci_ioeventfd_assign;
      k->get_dma_as = virtio_pci_get_dma_as;
      k->queue_enabled = virtio_pci_queue_enabled;
+    k->set_config_notifiers = virtio_pci_set_config_notifier;
  }
 
  static const TypeInfo virtio_pci_bus_info = {
author
#8 lore raw

Re: [PATCH v3 3/5] virtio-pci: add support for configure interrupt

Quoted 50 lines · Jason Wang
Quoted 47 lines · Cindy Lu

Add support for configure interrupt, use kvm_irqfd_assign and set the gsi to kernel. When the configure notifier was eventfd_signal by host kernel, this will finally inject an msix interrupt to guest

---
  hw/virtio/virtio-pci.c | 92 ++++++++++++++++++++++++++++++++++--------
  1 file changed, 75 insertions(+), 17 deletions(-)
hw/virtio/virtio-pci.c +2 -9
index 36524a5728..8e192600b8 100644
@@ -664,7 +664,6 @@ static uint32_t virtio_read_config(PCIDevice *pci_dev,
  }
 
  static int kvm_virtio_pci_vq_vector_use(VirtIOPCIProxy *proxy,
-                                        unsigned int queue_no,
                                          unsigned int vector)
  {
      VirtIOIRQFD *irqfd = &proxy->vector_irqfd[vector];
@@ -691,23 +690,17 @@ static void kvm_virtio_pci_vq_vector_release(VirtIOPCIProxy *proxy,
  }
 
  static int kvm_virtio_pci_irqfd_use(VirtIOPCIProxy *proxy,
-                                 unsigned int queue_no,
+                                 EventNotifier *n,
                                   unsigned int vector)
  {
      VirtIOIRQFD *irqfd = &proxy->vector_irqfd[vector];
-    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
-    VirtQueue *vq = virtio_get_queue(vdev, queue_no);
-    EventNotifier *n = virtio_queue_get_guest_notifier(vq);
      return kvm_irqchip_add_irqfd_notifier_gsi(kvm_state, n, NULL, irqfd->virq);
  }
 
  static void kvm_virtio_pci_irqfd_release(VirtIOPCIProxy *proxy,
-                                      unsigned int queue_no,
+                                      EventNotifier *n ,
                                        unsigned int vector)
  {
-    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
-    VirtQueue *vq = virtio_get_queue(vdev, queue_no);
-    EventNotifier *n = virtio_queue_get_guest_notifier(vq);
      VirtIOIRQFD *irqfd = &proxy->vector_irqfd[vector];
      int ret;
 
Quoted 11 lines

hw/virtio/virtio-pci.c static int kvm_virtio_pci_vector_use(VirtIOPCIProxy *proxy, int nvqs) · line 719

Quoted 7 lines
hw/virtio/virtio-pci.c +2 -1
@@ -722,7 +715,8 @@ static int kvm_virtio_pci_vector_use(VirtIOPCIProxy *proxy, int nvqs)
      VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
      unsigned int vector;
      int ret, queue_no;
-
+    VirtQueue *vq;
+    EventNotifier *n;

new line is needed.

will fix this

Quoted 55 lines
Quoted 55 lines
hw/virtio/virtio-pci.c +24 -3
      for (queue_no = 0; queue_no < nvqs; queue_no++) {
          if (!virtio_queue_get_num(vdev, queue_no)) {
              break;
@@ -731,7 +725,7 @@ static int kvm_virtio_pci_vector_use(VirtIOPCIProxy *proxy, int nvqs)
          if (vector >= msix_nr_vectors_allocated(dev)) {
              continue;
          }
-        ret = kvm_virtio_pci_vq_vector_use(proxy, queue_no, vector);
+        ret = kvm_virtio_pci_vq_vector_use(proxy,  vector);
          if (ret < 0) {
              goto undo;
          }
@@ -739,7 +733,9 @@ static int kvm_virtio_pci_vector_use(VirtIOPCIProxy *proxy, int nvqs)
           * Otherwise, delay until unmasked in the frontend.
           */
          if (vdev->use_guest_notifier_mask && k->guest_notifier_mask) {
-            ret = kvm_virtio_pci_irqfd_use(proxy, queue_no, vector);
+            vq = virtio_get_queue(vdev, queue_no);
+            n = virtio_queue_get_guest_notifier(vq);
+            ret = kvm_virtio_pci_irqfd_use(proxy, n, vector);
              if (ret < 0) {
                  kvm_virtio_pci_vq_vector_release(proxy, vector);
                  goto undo;
@@ -755,13 +751,69 @@ undo:
              continue;
          }
          if (vdev->use_guest_notifier_mask && k->guest_notifier_mask) {
-            kvm_virtio_pci_irqfd_release(proxy, queue_no, vector);
+            vq = virtio_get_queue(vdev, queue_no);
+            n = virtio_queue_get_guest_notifier(vq);
+            kvm_virtio_pci_irqfd_release(proxy, n, vector);
          }
          kvm_virtio_pci_vq_vector_release(proxy, vector);
      }
      return ret;
  }
 
+static int kvm_virtio_pci_vector_config_use(VirtIOPCIProxy *proxy)
+{
+
+    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
+    unsigned int vector;
+    int ret;
+    EventNotifier *n = virtio_get_config_notifier(vdev);
+
+    vector = vdev->config_vector ;
+    ret = kvm_virtio_pci_vq_vector_use(proxy, vector);
+    if (ret < 0) {
+        goto undo;
+    }
+    ret = kvm_virtio_pci_irqfd_use(proxy,  n, vector);
+    if (ret < 0) {
+        goto undo;
+    }
Quoted 9 lines

hw/virtio/virtio-pci.c undo: · line 784

Quoted 5 lines
hw/virtio/virtio-pci.c +5 -0
+    return 0;
+undo:
+    kvm_virtio_pci_irqfd_release(proxy, n, vector);
+    return ret;
+}

newline is needed.

will fix this

Quoted 38 lines
Quoted 22 lines
hw/virtio/virtio-pci.c +21 -0
+static void kvm_virtio_pci_vector_config_release(VirtIOPCIProxy *proxy)
+{
+    PCIDevice *dev = &proxy->pci_dev;
+    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
+    unsigned int vector;
+    EventNotifier *n = virtio_get_config_notifier(vdev);
+    vector = vdev->config_vector ;
+    if (vector >= msix_nr_vectors_allocated(dev)) {
+        return;
+    }
+    kvm_virtio_pci_irqfd_release(proxy, n, vector);
+    kvm_virtio_pci_vq_vector_release(proxy, vector);
+}
+
+static int virtio_pci_set_config_notifier(DeviceState *d,  bool assign)
+{
+    VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d);
+    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
+    EventNotifier *notifier = virtio_get_config_notifier(vdev);
+    int r = 0;
+    if (assign) {

hw/virtio/virtio-pci.c undo: · line 815

Quoted 10 lines
hw/virtio/virtio-pci.c +10 -0
+        r = event_notifier_init(notifier, 0);
+        virtio_set_config_notifier_fd_handler(vdev, true, true);
+        kvm_virtio_pci_vector_config_use(proxy);
+    } else {
+        virtio_set_config_notifier_fd_handler(vdev, false, true);
+        kvm_virtio_pci_vector_config_release(proxy);
+        event_notifier_cleanup(notifier);
+    }
+    return r;
+}

Two questions, don't we need to check whether or not MSIX is enalbed in this case? Instead of introducing new helpers that is easy to be buggy I still prefer to re-use virtio_pci_set_guest_notifier:

Quoted 4 lines

We can switch to use accepts EventNotifier instead of virtqueue index. And we need also convert virtqueue_set_guest_notifier_fd_handler() to accept EventNotifier.

sure, I will fix this

Quoted 68 lines

hw/virtio/virtio-pci.c static void kvm_virtio_pci_vector_release(VirtIOPCIProxy *proxy, int nvqs) · line 825

Quoted 12 lines
hw/virtio/virtio-pci.c +3 -1
+
  static void kvm_virtio_pci_vector_release(VirtIOPCIProxy *proxy, int nvqs)
  {
      PCIDevice *dev = &proxy->pci_dev;
@@ -769,7 +821,8 @@ static void kvm_virtio_pci_vector_release(VirtIOPCIProxy *proxy, int nvqs)
      unsigned int vector;
      int queue_no;
      VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
-
+    VirtQueue *vq;
+    EventNotifier *n;

newline is needed.

Thanks

Quoted 48 lines
hw/virtio/virtio-pci.c +8 -3
      for (queue_no = 0; queue_no < nvqs; queue_no++) {
          if (!virtio_queue_get_num(vdev, queue_no)) {
              break;
@@ -782,7 +835,9 @@ static void kvm_virtio_pci_vector_release(VirtIOPCIProxy *proxy, int nvqs)
           * Otherwise, it was cleaned when masked in the frontend.
           */
          if (vdev->use_guest_notifier_mask && k->guest_notifier_mask) {
-            kvm_virtio_pci_irqfd_release(proxy, queue_no, vector);
+            vq = virtio_get_queue(vdev, queue_no);
+            n = virtio_queue_get_guest_notifier(vq);
+            kvm_virtio_pci_irqfd_release(proxy, n, vector);
          }
          kvm_virtio_pci_vq_vector_release(proxy, vector);
      }
@@ -823,7 +878,7 @@ static int virtio_pci_vq_vector_unmask(VirtIOPCIProxy *proxy,
              event_notifier_set(n);
          }
      } else {
-        ret = kvm_virtio_pci_irqfd_use(proxy, queue_no, vector);
+        ret = kvm_virtio_pci_irqfd_use(proxy, n, vector);
      }
      return ret;
  }
@@ -835,13 +890,15 @@ static void virtio_pci_vq_vector_mask(VirtIOPCIProxy *proxy,
      VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
      VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
 
+    VirtQueue *vq = virtio_get_queue(vdev, queue_no);
+    EventNotifier *n = virtio_queue_get_guest_notifier(vq);
      /* If guest supports masking, keep irqfd but mask it.
       * Otherwise, clean it up now.
       */
      if (vdev->use_guest_notifier_mask && k->guest_notifier_mask) {
          k->guest_notifier_mask(vdev, queue_no, true);
      } else {
-        kvm_virtio_pci_irqfd_release(proxy, queue_no, vector);
+        kvm_virtio_pci_irqfd_release(proxy, n, vector);
      }
  }
 
@@ -2137,6 +2194,7 @@ static void virtio_pci_bus_class_init(ObjectClass *klass, void *data)
      k->ioeventfd_assign = virtio_pci_ioeventfd_assign;
      k->get_dma_as = virtio_pci_get_dma_as;
      k->queue_enabled = virtio_pci_queue_enabled;
+    k->set_config_notifiers = virtio_pci_set_config_notifier;
  }
 
  static const TypeInfo virtio_pci_bus_info = {
author
#9 lore raw

PATCH v3 4/5 virtio-mmio: add support for configure interrupt

In reply to Cindy Lu

add configure interrupt support for virtio-mmio bus. This interrupt will working while backend is vhost-vdpa

---
 hw/virtio/virtio-mmio.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
hw/virtio/virtio-mmio.c +16 -0
index e1b5c3b81e..d580f1ea9a 100644
@@ -666,6 +666,21 @@ assign_error:
     return r;
 }
 
+static int virtio_mmio_set_config_notifier(DeviceState *d,  bool assign)
+{
+    VirtIOMMIOProxy *proxy = VIRTIO_MMIO(d);
+    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
+    EventNotifier *notifier = virtio_get_config_notifier(vdev);
+    int r = 0;
+    if (assign) {
+        r = event_notifier_init(notifier, 0);
+        virtio_set_config_notifier_fd_handler(vdev, true, false);
+    } else {
+        virtio_set_config_notifier_fd_handler(vdev, false, false);
+        event_notifier_cleanup(notifier);
+    }
+    return r;
+}
 static void virtio_mmio_pre_plugged(DeviceState *d, Error **errp)
 {
     VirtIOMMIOProxy *proxy = VIRTIO_MMIO(d);
@@ -780,6 +795,7 @@ static void virtio_mmio_bus_class_init(ObjectClass *klass, void *data)
     k->ioeventfd_assign = virtio_mmio_ioeventfd_assign;
     k->pre_plugged = virtio_mmio_pre_plugged;
     k->has_variable_vring_alignment = true;
+    k->set_config_notifiers = virtio_mmio_set_config_notifier;
     bus_class->max_dev = 1;
     bus_class->get_dev_path = virtio_mmio_bus_get_dev_path;
 }
Signature · 1 line
2.21.3
author
#10 lore raw

PATCH v3 5/5 vhost-vdpa: add callback function for configure interrupt

In reply to Cindy Lu

Add call back function for configure interrupt. Set the notifier's fd to the kernel driver when vdpa start. also set -1 while vdpa stop. then the kernel will release the related resource

---
 hw/virtio/trace-events            |  2 ++
 hw/virtio/vhost-vdpa.c            | 37 ++++++++++++++++++++++++++++++-
 include/hw/virtio/vhost-backend.h |  4 ++++
 3 files changed, 42 insertions(+), 1 deletion(-)
hw/virtio/trace-events +2 -0
index 2060a144a2..6710835b46 100644
@@ -52,6 +52,8 @@ vhost_vdpa_set_vring_call(void *dev, unsigned int index, int fd) "dev: %p index:
 vhost_vdpa_get_features(void *dev, uint64_t features) "dev: %p features: 0x%"PRIx64
 vhost_vdpa_set_owner(void *dev) "dev: %p"
 vhost_vdpa_vq_get_addr(void *dev, void *vq, uint64_t desc_user_addr, uint64_t avail_user_addr, uint64_t used_user_addr) "dev: %p vq: %p desc_user_addr: 0x%"PRIx64" avail_user_addr: 0x%"PRIx64" used_user_addr: 0x%"PRIx64
+vhost_vdpa_set_config_call(void *dev, int *fd)"dev: %p fd: %p"
+
 
 # virtio.c
 virtqueue_alloc_element(void *elem, size_t sz, unsigned in_num, unsigned out_num) "elem %p size %zd in_num %u out_num %u"
hw/virtio/vhost-vdpa.c +36 -1
index 01d2101d09..cc1d39d663 100644
@@ -467,20 +467,47 @@ static int vhost_vdpa_get_config(struct vhost_dev *dev, uint8_t *config,
     }
     return ret;
  }
+static void vhost_vdpa_config_notify_start(struct vhost_dev *dev,
+                                struct VirtIODevice *vdev, bool start)
+{
+    int fd, r;
+    if (start) {
+        fd = event_notifier_get_fd(&vdev->config_notifier);
+        vdev->use_config_notifier = true;
+     } else {
+        fd = -1;
+        vdev->use_config_notifier = false;
+     }
+     /*set the fd call back to vdpa driver*/
+    r = dev->vhost_ops->vhost_set_config_call(dev, &fd);
+    if (r) {
+        vdev->use_config_notifier = false;
+        info_report("vhost_vdpa_config_notify not started!");
+    }
+    /*active the config_notifier when vdev->use_config_notifier is true*/
+    if ((vdev->use_config_notifier) && (start)) {
+        event_notifier_set(&vdev->config_notifier);
+    }
+    return;
 
+}
 static int vhost_vdpa_dev_start(struct vhost_dev *dev, bool started)
 {
     struct vhost_vdpa *v = dev->opaque;
     trace_vhost_vdpa_dev_start(dev, started);
+    VirtIODevice *vdev = dev->vdev;
+
     if (started) {
         uint8_t status = 0;
         memory_listener_register(&v->listener, &address_space_memory);
         vhost_vdpa_set_vring_ready(dev);
         vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_DRIVER_OK);
         vhost_vdpa_call(dev, VHOST_VDPA_GET_STATUS, &status);
-
+        /*set the configure interrupt call back*/
+        vhost_vdpa_config_notify_start(dev, vdev, true);
         return !(status & VIRTIO_CONFIG_S_DRIVER_OK);
     } else {
+        vhost_vdpa_config_notify_start(dev, vdev, false);
         vhost_vdpa_reset_device(dev);
         vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_ACKNOWLEDGE |
                                    VIRTIO_CONFIG_S_DRIVER);
@@ -546,6 +573,13 @@ static int vhost_vdpa_set_vring_call(struct vhost_dev *dev,
     return vhost_vdpa_call(dev, VHOST_SET_VRING_CALL, file);
 }
 
+static int vhost_vdpa_set_config_call(struct vhost_dev *dev,
+                                       int *fd)
+{
+    trace_vhost_vdpa_set_config_call(dev, fd);
+    return vhost_vdpa_call(dev, VHOST_VDPA_SET_CONFIG_CALL, fd);
+}
+
 static int vhost_vdpa_get_features(struct vhost_dev *dev,
                                      uint64_t *features)
 {
@@ -611,4 +645,5 @@ const VhostOps vdpa_ops = {
         .vhost_get_device_id = vhost_vdpa_get_device_id,
         .vhost_vq_get_addr = vhost_vdpa_vq_get_addr,
         .vhost_force_iommu = vhost_vdpa_force_iommu,
+        .vhost_set_config_call = vhost_vdpa_set_config_call,
 };
include/hw/virtio/vhost-backend.h +4 -0
index 8a6f8e2a7a..1a2fee8994 100644
@@ -125,6 +125,9 @@ typedef int (*vhost_get_device_id_op)(struct vhost_dev *dev, uint32_t *dev_id);
 
 typedef bool (*vhost_force_iommu_op)(struct vhost_dev *dev);
 
+typedef int (*vhost_set_config_call_op)(struct vhost_dev *dev,
+                                       int *fd);
+
 typedef struct VhostOps {
     VhostBackendType backend_type;
     vhost_backend_init vhost_backend_init;
@@ -170,6 +173,7 @@ typedef struct VhostOps {
     vhost_vq_get_addr_op  vhost_vq_get_addr;
     vhost_get_device_id_op vhost_get_device_id;
     vhost_force_iommu_op vhost_force_iommu;
+    vhost_set_config_call_op vhost_set_config_call;
 } VhostOps;
 
 extern const VhostOps user_ops;
Signature · 1 line
2.21.3
#11 lore raw

Re: [PATCH v3 5/5] vhost-vdpa: add callback function for configure interrupt

Quoted 31 lines · Cindy Lu

Add call back function for configure interrupt. Set the notifier's fd to the kernel driver when vdpa start. also set -1 while vdpa stop. then the kernel will release the related resource

---

hw/virtio/trace-events            |  2 ++
hw/virtio/vhost-vdpa.c            | 37 ++++++++++++++++++++++++++++++-
include/hw/virtio/vhost-backend.h |  4 ++++
3 files changed, 42 insertions(+), 1 deletion(-)
hw/virtio/trace-events +0 -0
index 2060a144a2..6710835b46 100644
@@ -52,6 +52,8 @@ vhost_vdpa_set_vring_call(void *dev, unsigned int index, int fd) "dev: %p index:

vhost_vdpa_get_features(void *dev, uint64_t features) "dev: %p features: 0x%"PRIx64
vhost_vdpa_set_owner(void *dev) "dev: %p"
vhost_vdpa_vq_get_addr(void *dev, void *vq, uint64_t desc_user_addr, uint64_t avail_user_addr, uint64_t used_user_addr) "dev: %p vq: %p desc_user_addr: 0x%"PRIx64" avail_user_addr: 0x%"PRIx64" used_user_addr: 0x%"PRIx64

hw/virtio/trace-events +2 -0
+vhost_vdpa_set_config_call(void *dev, int *fd)"dev: %p fd: %p"
+
# virtio.c
virtqueue_alloc_element(void *elem, size_t sz, unsigned in_num, unsigned out_num) "elem %p size %zd in_num %u out_num %u"
hw/virtio/vhost-vdpa.c +0 -0
index 01d2101d09..cc1d39d663 100644
@@ -467,20 +467,47 @@ static int vhost_vdpa_get_config(struct vhost_dev *dev, uint8_t *config,
    }

hw/virtio/vhost-vdpa.c static int vhost_vdpa_get_config(struct vhost_dev *dev, uint8_t *config, · line 477

Quoted 10 lines
hw/virtio/vhost-vdpa.c +8 -0
    return ret;
 }
+static void vhost_vdpa_config_notify_start(struct vhost_dev *dev,
+                                struct VirtIODevice *vdev, bool start)
+{
+    int fd, r;
+    if (start) {
+        fd = event_notifier_get_fd(&vdev->config_notifier);
+        vdev->use_config_notifier = true;
+     } else {
      ^

hw/virtio/vhost-vdpa.c static int vhost_vdpa_get_config(struct vhost_dev *dev, uint8_t *config, · line 480

Quoted 3 lines
hw/virtio/vhost-vdpa.c +3 -0
+        fd = -1;
+        vdev->use_config_notifier = false;
+     }
      ^

hw/virtio/vhost-vdpa.c static int vhost_vdpa_get_config(struct vhost_dev *dev, uint8_t *config, · line 481

Quoted 1 line
hw/virtio/vhost-vdpa.c +1 -0
+     /*set the fd call back to vdpa driver*/

^
It seems to me that there is an extra space in these places.

hw/virtio/vhost-vdpa.c static int vhost_vdpa_get_config(struct vhost_dev *dev, uint8_t *config, · line 493

Quoted 12 lines
hw/virtio/vhost-vdpa.c +11 -0
+    r = dev->vhost_ops->vhost_set_config_call(dev, &fd);
+    if (r) {
+        vdev->use_config_notifier = false;
+        info_report("vhost_vdpa_config_notify not started!");
+    }
+    /*active the config_notifier when vdev->use_config_notifier is true*/
+    if ((vdev->use_config_notifier) && (start)) {
+        event_notifier_set(&vdev->config_notifier);
+    }
+    return;
 
+}

Here and also in other patches I would leave a new line between two functions.

Quoted 46 lines
hw/virtio/vhost-vdpa.c +13 -1
 static int vhost_vdpa_dev_start(struct vhost_dev *dev, bool started)
 {
    struct vhost_vdpa *v = dev->opaque;
    trace_vhost_vdpa_dev_start(dev, started);
+    VirtIODevice *vdev = dev->vdev;
+
    if (started) {
        uint8_t status = 0;
        memory_listener_register(&v->listener, &address_space_memory);
        vhost_vdpa_set_vring_ready(dev);
        vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_DRIVER_OK);
        vhost_vdpa_call(dev, VHOST_VDPA_GET_STATUS, &status);
-
+        /*set the configure interrupt call back*/
+        vhost_vdpa_config_notify_start(dev, vdev, true);
        return !(status & VIRTIO_CONFIG_S_DRIVER_OK);
    } else {
+        vhost_vdpa_config_notify_start(dev, vdev, false);
        vhost_vdpa_reset_device(dev);
        vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_ACKNOWLEDGE |
                                   VIRTIO_CONFIG_S_DRIVER);
@@ -546,6 +573,13 @@ static int vhost_vdpa_set_vring_call(struct vhost_dev *dev,
    return vhost_vdpa_call(dev, VHOST_SET_VRING_CALL, file);
 }
 
+static int vhost_vdpa_set_config_call(struct vhost_dev *dev,
+                                       int *fd)
+{
+    trace_vhost_vdpa_set_config_call(dev, fd);
+    return vhost_vdpa_call(dev, VHOST_VDPA_SET_CONFIG_CALL, fd);
+}
+
 static int vhost_vdpa_get_features(struct vhost_dev *dev,
                                     uint64_t *features)
 {
@@ -611,4 +645,5 @@ const VhostOps vdpa_ops = {
        .vhost_get_device_id = vhost_vdpa_get_device_id,
        .vhost_vq_get_addr = vhost_vdpa_vq_get_addr,
        .vhost_force_iommu = vhost_vdpa_force_iommu,
+        .vhost_set_config_call = vhost_vdpa_set_config_call,
 };
include/hw/virtio/vhost-backend.h +0 -0
index 8a6f8e2a7a..1a2fee8994 100644

include/hw/virtio/vhost-backend.h typedef int (*vhost_get_device_id_op)(struct vhost_dev *dev, uint32_t *dev_id); · line 129

Quoted 5 lines
include/hw/virtio/vhost-backend.h +2 -0
@@ -125,6 +125,9 @@ typedef int (*vhost_get_device_id_op)(struct vhost_dev *dev, uint32_t *dev_id);
 
 typedef bool (*vhost_force_iommu_op)(struct vhost_dev *dev);
 
+typedef int (*vhost_set_config_call_op)(struct vhost_dev *dev,
+                                       int *fd);

^
One more space :-)

Thanks,
Stefano

author
#12 lore raw

Re: [PATCH v3 5/5] vhost-vdpa: add callback function for configure interrupt

Quoted 44 lines · Stefano Garzarella
Quoted 31 lines · Cindy Lu

Add call back function for configure interrupt. Set the notifier's fd to the kernel driver when vdpa start. also set -1 while vdpa stop. then the kernel will release the related resource

---

hw/virtio/trace-events            |  2 ++
hw/virtio/vhost-vdpa.c            | 37 ++++++++++++++++++++++++++++++-
include/hw/virtio/vhost-backend.h |  4 ++++
3 files changed, 42 insertions(+), 1 deletion(-)
hw/virtio/trace-events +0 -0
index 2060a144a2..6710835b46 100644
@@ -52,6 +52,8 @@ vhost_vdpa_set_vring_call(void *dev, unsigned int index, int fd) "dev: %p index:

vhost_vdpa_get_features(void *dev, uint64_t features) "dev: %p features: 0x%"PRIx64
vhost_vdpa_set_owner(void *dev) "dev: %p"
vhost_vdpa_vq_get_addr(void *dev, void *vq, uint64_t desc_user_addr, uint64_t avail_user_addr, uint64_t used_user_addr) "dev: %p vq: %p desc_user_addr: 0x%"PRIx64" avail_user_addr: 0x%"PRIx64" used_user_addr: 0x%"PRIx64

hw/virtio/trace-events +2 -0
+vhost_vdpa_set_config_call(void *dev, int *fd)"dev: %p fd: %p"
+
# virtio.c
virtqueue_alloc_element(void *elem, size_t sz, unsigned in_num, unsigned out_num) "elem %p size %zd in_num %u out_num %u"
hw/virtio/vhost-vdpa.c +0 -0
index 01d2101d09..cc1d39d663 100644
@@ -467,20 +467,47 @@ static int vhost_vdpa_get_config(struct vhost_dev *dev, uint8_t *config,
    }

hw/virtio/vhost-vdpa.c static int vhost_vdpa_get_config(struct vhost_dev *dev, uint8_t *config, · line 477

Quoted 10 lines
hw/virtio/vhost-vdpa.c +8 -0
    return ret;
 }
+static void vhost_vdpa_config_notify_start(struct vhost_dev *dev,
+                                struct VirtIODevice *vdev, bool start)
+{
+    int fd, r;
+    if (start) {
+        fd = event_notifier_get_fd(&vdev->config_notifier);
+        vdev->use_config_notifier = true;
+     } else {
       ^
Quoted 8 lines

hw/virtio/vhost-vdpa.c static int vhost_vdpa_get_config(struct vhost_dev *dev, uint8_t *config, · line 480

Quoted 3 lines
hw/virtio/vhost-vdpa.c +3 -0
+        fd = -1;
+        vdev->use_config_notifier = false;
+     }
       ^

hw/virtio/vhost-vdpa.c static int vhost_vdpa_get_config(struct vhost_dev *dev, uint8_t *config, · line 481

Quoted 1 line
hw/virtio/vhost-vdpa.c +1 -0
+     /*set the fd call back to vdpa driver*/

^
It seems to me that there is an extra space in these places.

sure, I will fix this

Quoted 11 lines
Quoted 11 lines
hw/virtio/vhost-vdpa.c +10 -0
+    r = dev->vhost_ops->vhost_set_config_call(dev, &fd);
+    if (r) {
+        vdev->use_config_notifier = false;
+        info_report("vhost_vdpa_config_notify not started!");
+    }
+    /*active the config_notifier when vdev->use_config_notifier is true*/
+    if ((vdev->use_config_notifier) && (start)) {
+        event_notifier_set(&vdev->config_notifier);
+    }
+    return;
 
Quoted 5 lines

hw/virtio/vhost-vdpa.c static int vhost_vdpa_get_config(struct vhost_dev *dev, uint8_t *config, · line 493

Quoted 1 line
hw/virtio/vhost-vdpa.c +1 -0
+}

Here and also in other patches I would leave a new line between two functions.

sure. will fix this

Quoted 47 lines
Quoted 47 lines
hw/virtio/vhost-vdpa.c +13 -1
 static int vhost_vdpa_dev_start(struct vhost_dev *dev, bool started)
 {
    struct vhost_vdpa *v = dev->opaque;
    trace_vhost_vdpa_dev_start(dev, started);
+    VirtIODevice *vdev = dev->vdev;
+
    if (started) {
        uint8_t status = 0;
        memory_listener_register(&v->listener, &address_space_memory);
        vhost_vdpa_set_vring_ready(dev);
        vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_DRIVER_OK);
        vhost_vdpa_call(dev, VHOST_VDPA_GET_STATUS, &status);
-
+        /*set the configure interrupt call back*/
+        vhost_vdpa_config_notify_start(dev, vdev, true);
        return !(status & VIRTIO_CONFIG_S_DRIVER_OK);
    } else {
+        vhost_vdpa_config_notify_start(dev, vdev, false);
        vhost_vdpa_reset_device(dev);
        vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_ACKNOWLEDGE |
                                   VIRTIO_CONFIG_S_DRIVER);
@@ -546,6 +573,13 @@ static int vhost_vdpa_set_vring_call(struct vhost_dev *dev,
    return vhost_vdpa_call(dev, VHOST_SET_VRING_CALL, file);
 }
 
+static int vhost_vdpa_set_config_call(struct vhost_dev *dev,
+                                       int *fd)
+{
+    trace_vhost_vdpa_set_config_call(dev, fd);
+    return vhost_vdpa_call(dev, VHOST_VDPA_SET_CONFIG_CALL, fd);
+}
+
 static int vhost_vdpa_get_features(struct vhost_dev *dev,
                                     uint64_t *features)
 {
@@ -611,4 +645,5 @@ const VhostOps vdpa_ops = {
        .vhost_get_device_id = vhost_vdpa_get_device_id,
        .vhost_vq_get_addr = vhost_vdpa_vq_get_addr,
        .vhost_force_iommu = vhost_vdpa_force_iommu,
+        .vhost_set_config_call = vhost_vdpa_set_config_call,
 };
include/hw/virtio/vhost-backend.h +0 -0
index 8a6f8e2a7a..1a2fee8994 100644
@@ -125,6 +125,9 @@ typedef int (*vhost_get_device_id_op)(struct vhost_dev *dev, uint32_t *dev_id);
 
Quoted 7 lines

include/hw/virtio/vhost-backend.h typedef int (*vhost_get_device_id_op)(struct vhost_dev *dev, uint32_t *dev_id); · line 129

Quoted 4 lines
include/hw/virtio/vhost-backend.h +2 -0
 typedef bool (*vhost_force_iommu_op)(struct vhost_dev *dev);
 
+typedef int (*vhost_set_config_call_op)(struct vhost_dev *dev,
+                                       int *fd);

^
One more space :-)

Thanks Stefano , will fix this

Quoted 3 lines

Thanks,
Stefano

#13 lore raw

Re: [PATCH v3 5/5] vhost-vdpa: add callback function for configure interrupt

In reply to Cindy Lu
Quoted 35 lines · Cindy Lu

Add call back function for configure interrupt. Set the notifier's fd to the kernel driver when vdpa start. also set -1 while vdpa stop. then the kernel will release the related resource

---
  hw/virtio/trace-events            |  2 ++
  hw/virtio/vhost-vdpa.c            | 37 ++++++++++++++++++++++++++++++-
  include/hw/virtio/vhost-backend.h |  4 ++++
  3 files changed, 42 insertions(+), 1 deletion(-)
hw/virtio/trace-events +2 -0
index 2060a144a2..6710835b46 100644
@@ -52,6 +52,8 @@ vhost_vdpa_set_vring_call(void *dev, unsigned int index, int fd) "dev: %p index:
  vhost_vdpa_get_features(void *dev, uint64_t features) "dev: %p features: 0x%"PRIx64
  vhost_vdpa_set_owner(void *dev) "dev: %p"
  vhost_vdpa_vq_get_addr(void *dev, void *vq, uint64_t desc_user_addr, uint64_t avail_user_addr, uint64_t used_user_addr) "dev: %p vq: %p desc_user_addr: 0x%"PRIx64" avail_user_addr: 0x%"PRIx64" used_user_addr: 0x%"PRIx64
+vhost_vdpa_set_config_call(void *dev, int *fd)"dev: %p fd: %p"
+
 
  # virtio.c
  virtqueue_alloc_element(void *elem, size_t sz, unsigned in_num, unsigned out_num) "elem %p size %zd in_num %u out_num %u"
hw/virtio/vhost-vdpa.c +2 -0
index 01d2101d09..cc1d39d663 100644
@@ -467,20 +467,47 @@ static int vhost_vdpa_get_config(struct vhost_dev *dev, uint8_t *config,
      }
      return ret;
   }
+static void vhost_vdpa_config_notify_start(struct vhost_dev *dev,
+                                struct VirtIODevice *vdev, bool start)

hw/virtio/vhost-vdpa.c static int vhost_vdpa_get_config(struct vhost_dev *dev, uint8_t *config, · line 481

Quoted 10 lines
hw/virtio/vhost-vdpa.c +10 -0
+{
+    int fd, r;
+    if (start) {
+        fd = event_notifier_get_fd(&vdev->config_notifier);
+        vdev->use_config_notifier = true;
+     } else {
+        fd = -1;
+        vdev->use_config_notifier = false;
+     }
+     /*set the fd call back to vdpa driver*/

I guess checkpatch.pl might warn here. Please try to silent checkpath.pl before submitting patches.

hw/virtio/vhost-vdpa.c static int vhost_vdpa_get_config(struct vhost_dev *dev, uint8_t *config, · line 485

Quoted 4 lines
hw/virtio/vhost-vdpa.c +4 -0
+    r = dev->vhost_ops->vhost_set_config_call(dev, &fd);
+    if (r) {
+        vdev->use_config_notifier = false;
+        info_report("vhost_vdpa_config_notify not started!");

This looks kind of fragile. Do we need some workaround here like:

1) filter out the features that depends on config interrupt

or

2) A timer to watch the change of config space

Thanks

Quoted 71 lines
hw/virtio/vhost-vdpa.c +20 -1
+    }
+    /*active the config_notifier when vdev->use_config_notifier is true*/
+    if ((vdev->use_config_notifier) && (start)) {
+        event_notifier_set(&vdev->config_notifier);
+    }
+    return;
 
+}
  static int vhost_vdpa_dev_start(struct vhost_dev *dev, bool started)
  {
      struct vhost_vdpa *v = dev->opaque;
      trace_vhost_vdpa_dev_start(dev, started);
+    VirtIODevice *vdev = dev->vdev;
+
      if (started) {
          uint8_t status = 0;
          memory_listener_register(&v->listener, &address_space_memory);
          vhost_vdpa_set_vring_ready(dev);
          vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_DRIVER_OK);
          vhost_vdpa_call(dev, VHOST_VDPA_GET_STATUS, &status);
-
+        /*set the configure interrupt call back*/
+        vhost_vdpa_config_notify_start(dev, vdev, true);
          return !(status & VIRTIO_CONFIG_S_DRIVER_OK);
      } else {
+        vhost_vdpa_config_notify_start(dev, vdev, false);
          vhost_vdpa_reset_device(dev);
          vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_ACKNOWLEDGE |
                                     VIRTIO_CONFIG_S_DRIVER);
@@ -546,6 +573,13 @@ static int vhost_vdpa_set_vring_call(struct vhost_dev *dev,
      return vhost_vdpa_call(dev, VHOST_SET_VRING_CALL, file);
  }
 
+static int vhost_vdpa_set_config_call(struct vhost_dev *dev,
+                                       int *fd)
+{
+    trace_vhost_vdpa_set_config_call(dev, fd);
+    return vhost_vdpa_call(dev, VHOST_VDPA_SET_CONFIG_CALL, fd);
+}
+
  static int vhost_vdpa_get_features(struct vhost_dev *dev,
                                       uint64_t *features)
  {
@@ -611,4 +645,5 @@ const VhostOps vdpa_ops = {
          .vhost_get_device_id = vhost_vdpa_get_device_id,
          .vhost_vq_get_addr = vhost_vdpa_vq_get_addr,
          .vhost_force_iommu = vhost_vdpa_force_iommu,
+        .vhost_set_config_call = vhost_vdpa_set_config_call,
  };
include/hw/virtio/vhost-backend.h +4 -0
index 8a6f8e2a7a..1a2fee8994 100644
@@ -125,6 +125,9 @@ typedef int (*vhost_get_device_id_op)(struct vhost_dev *dev, uint32_t *dev_id);
 
  typedef bool (*vhost_force_iommu_op)(struct vhost_dev *dev);
 
+typedef int (*vhost_set_config_call_op)(struct vhost_dev *dev,
+                                       int *fd);
+
  typedef struct VhostOps {
      VhostBackendType backend_type;
      vhost_backend_init vhost_backend_init;
@@ -170,6 +173,7 @@ typedef struct VhostOps {
      vhost_vq_get_addr_op  vhost_vq_get_addr;
      vhost_get_device_id_op vhost_get_device_id;
      vhost_force_iommu_op vhost_force_iommu;
+    vhost_set_config_call_op vhost_set_config_call;
  } VhostOps;
 
  extern const VhostOps user_ops;
author
#14 lore raw

Re: [PATCH v3 5/5] vhost-vdpa: add callback function for configure interrupt

Quoted 44 lines · Jason Wang
Quoted 41 lines · Cindy Lu

Add call back function for configure interrupt. Set the notifier's fd to the kernel driver when vdpa start. also set -1 while vdpa stop. then the kernel will release the related resource

---
  hw/virtio/trace-events            |  2 ++
  hw/virtio/vhost-vdpa.c            | 37 ++++++++++++++++++++++++++++++-
  include/hw/virtio/vhost-backend.h |  4 ++++
  3 files changed, 42 insertions(+), 1 deletion(-)
hw/virtio/trace-events +2 -0
index 2060a144a2..6710835b46 100644
@@ -52,6 +52,8 @@ vhost_vdpa_set_vring_call(void *dev, unsigned int index, int fd) "dev: %p index:
  vhost_vdpa_get_features(void *dev, uint64_t features) "dev: %p features: 0x%"PRIx64
  vhost_vdpa_set_owner(void *dev) "dev: %p"
  vhost_vdpa_vq_get_addr(void *dev, void *vq, uint64_t desc_user_addr, uint64_t avail_user_addr, uint64_t used_user_addr) "dev: %p vq: %p desc_user_addr: 0x%"PRIx64" avail_user_addr: 0x%"PRIx64" used_user_addr: 0x%"PRIx64
+vhost_vdpa_set_config_call(void *dev, int *fd)"dev: %p fd: %p"
+
 
  # virtio.c
  virtqueue_alloc_element(void *elem, size_t sz, unsigned in_num, unsigned out_num) "elem %p size %zd in_num %u out_num %u"
hw/virtio/vhost-vdpa.c +8 -0
index 01d2101d09..cc1d39d663 100644
@@ -467,20 +467,47 @@ static int vhost_vdpa_get_config(struct vhost_dev *dev, uint8_t *config,
      }
      return ret;
   }
+static void vhost_vdpa_config_notify_start(struct vhost_dev *dev,
+                                struct VirtIODevice *vdev, bool start)
+{
+    int fd, r;
+    if (start) {
+        fd = event_notifier_get_fd(&vdev->config_notifier);
+        vdev->use_config_notifier = true;
+     } else {
Quoted 9 lines

hw/virtio/vhost-vdpa.c static int vhost_vdpa_get_config(struct vhost_dev *dev, uint8_t *config, · line 481

Quoted 4 lines
hw/virtio/vhost-vdpa.c +4 -0
+        fd = -1;
+        vdev->use_config_notifier = false;
+     }
+     /*set the fd call back to vdpa driver*/

I guess checkpatch.pl might warn here. Please try to silent checkpath.pl before submitting patches.

Actually I do have run this script, but seems not warned here. I will pay attention next time

Quoted 9 lines

hw/virtio/vhost-vdpa.c static int vhost_vdpa_get_config(struct vhost_dev *dev, uint8_t *config, · line 485

Quoted 5 lines
hw/virtio/vhost-vdpa.c +4 -0
+    r = dev->vhost_ops->vhost_set_config_call(dev, &fd);
+    if (r) {
+        vdev->use_config_notifier = false;
+        info_report("vhost_vdpa_config_notify not started!");

This looks kind of fragile. Do we need some workaround here like:

Quoted 8 lines

1) filter out the features that depends on config interrupt

or

2) A timer to watch the change of config space

Thanks

sure I will add this check

Quoted 73 lines
Quoted 72 lines
hw/virtio/vhost-vdpa.c +20 -1
+    }
+    /*active the config_notifier when vdev->use_config_notifier is true*/
+    if ((vdev->use_config_notifier) && (start)) {
+        event_notifier_set(&vdev->config_notifier);
+    }
+    return;
 
+}
  static int vhost_vdpa_dev_start(struct vhost_dev *dev, bool started)
  {
      struct vhost_vdpa *v = dev->opaque;
      trace_vhost_vdpa_dev_start(dev, started);
+    VirtIODevice *vdev = dev->vdev;
+
      if (started) {
          uint8_t status = 0;
          memory_listener_register(&v->listener, &address_space_memory);
          vhost_vdpa_set_vring_ready(dev);
          vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_DRIVER_OK);
          vhost_vdpa_call(dev, VHOST_VDPA_GET_STATUS, &status);
-
+        /*set the configure interrupt call back*/
+        vhost_vdpa_config_notify_start(dev, vdev, true);
          return !(status & VIRTIO_CONFIG_S_DRIVER_OK);
      } else {
+        vhost_vdpa_config_notify_start(dev, vdev, false);
          vhost_vdpa_reset_device(dev);
          vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_ACKNOWLEDGE |
                                     VIRTIO_CONFIG_S_DRIVER);
@@ -546,6 +573,13 @@ static int vhost_vdpa_set_vring_call(struct vhost_dev *dev,
      return vhost_vdpa_call(dev, VHOST_SET_VRING_CALL, file);
  }
 
+static int vhost_vdpa_set_config_call(struct vhost_dev *dev,
+                                       int *fd)
+{
+    trace_vhost_vdpa_set_config_call(dev, fd);
+    return vhost_vdpa_call(dev, VHOST_VDPA_SET_CONFIG_CALL, fd);
+}
+
  static int vhost_vdpa_get_features(struct vhost_dev *dev,
                                       uint64_t *features)
  {
@@ -611,4 +645,5 @@ const VhostOps vdpa_ops = {
          .vhost_get_device_id = vhost_vdpa_get_device_id,
          .vhost_vq_get_addr = vhost_vdpa_vq_get_addr,
          .vhost_force_iommu = vhost_vdpa_force_iommu,
+        .vhost_set_config_call = vhost_vdpa_set_config_call,
  };
include/hw/virtio/vhost-backend.h +4 -0
index 8a6f8e2a7a..1a2fee8994 100644
@@ -125,6 +125,9 @@ typedef int (*vhost_get_device_id_op)(struct vhost_dev *dev, uint32_t *dev_id);
 
  typedef bool (*vhost_force_iommu_op)(struct vhost_dev *dev);
 
+typedef int (*vhost_set_config_call_op)(struct vhost_dev *dev,
+                                       int *fd);
+
  typedef struct VhostOps {
      VhostBackendType backend_type;
      vhost_backend_init vhost_backend_init;
@@ -170,6 +173,7 @@ typedef struct VhostOps {
      vhost_vq_get_addr_op  vhost_vq_get_addr;
      vhost_get_device_id_op vhost_get_device_id;
      vhost_force_iommu_op vhost_force_iommu;
+    vhost_set_config_call_op vhost_set_config_call;
  } VhostOps;
 
  extern const VhostOps user_ops;
#15 lore raw

Re: [PATCH v3 5/5] vhost-vdpa: add callback function for configure interrupt

Quoted 6 lines · Cindy Lu
Quoted 4 lines
Quoted 1 line

+ /*set the fd call back to vdpa driver*/

I guess checkpatch.pl might warn here. Please try to silent checkpath.pl before submitting patches.

Actually I do have run this script, but seems not warned here. I will pay attention next time

Oh right, I remember kernel checkpath did the check but I don't know if the qemu one check the comment sytle.

Thanks