[PATCH v4 08/23] virtio: move common part of _set_guest_notifier to generic code

Vladimir Sementsov-Ogievskiy posted 23 patches 3 weeks ago
Maintainers: "Michael S. Tsirkin" <mst@redhat.com>, Stefano Garzarella <sgarzare@redhat.com>, "Gonglei (Arei)" <arei.gonglei@huawei.com>, zhenwei pi <zhenwei.pi@linux.dev>, Kevin Wolf <kwolf@redhat.com>, Hanna Reitz <hreitz@redhat.com>, Raphael Norwitz <raphael@enfabrica.net>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, Jason Wang <jasowang@redhat.com>, Cornelia Huck <cohuck@redhat.com>, Halil Pasic <pasic@linux.ibm.com>, Eric Farman <farman@linux.ibm.com>, Richard Henderson <richard.henderson@linaro.org>, Ilya Leoshkevich <iii@linux.ibm.com>, David Hildenbrand <david@kernel.org>, Christian Borntraeger <borntraeger@linux.ibm.com>, Matthew Rosato <mjrosato@linux.ibm.com>, Thomas Huth <thuth@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, Fam Zheng <fam@euphon.net>, "Alex Bennée" <alex.bennee@linaro.org>, Eric Blake <eblake@redhat.com>, Markus Armbruster <armbru@redhat.com>
There is a newer version of this series
[PATCH v4 08/23] virtio: move common part of _set_guest_notifier to generic code
Posted by Vladimir Sementsov-Ogievskiy 3 weeks ago
virtio-pci, virtio-mmio and virtio-ccw handle config notifier equally
but with different code (mmio adds a separate function, when pci use
common function). Let's chose the more compact way (pci) and reuse it
for mmio.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
---
 hw/s390x/virtio-ccw.c          | 35 ++++++++++++-------------
 hw/virtio/virtio-mmio.c        | 41 +++++------------------------
 hw/virtio/virtio-pci.c         | 34 +++---------------------
 hw/virtio/virtio.c             | 48 +++++++++++++++++++++++++++++++---
 include/hw/virtio/virtio-pci.h |  3 ---
 include/hw/virtio/virtio.h     | 16 +++++++++---
 6 files changed, 84 insertions(+), 93 deletions(-)

diff --git a/hw/s390x/virtio-ccw.c b/hw/s390x/virtio-ccw.c
index ba55bf4fe9..f99d1e7cd8 100644
--- a/hw/s390x/virtio-ccw.c
+++ b/hw/s390x/virtio-ccw.c
@@ -1025,20 +1025,27 @@ static int virtio_ccw_set_guest_notifier(VirtioCcwDevice *dev, int n,
     VirtQueue *vq = virtio_get_queue(vdev, n);
     EventNotifier *notifier = virtio_queue_get_guest_notifier(vq);
     VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
+    int r;
 
-    if (assign) {
-        int r = event_notifier_init(notifier, 0);
-
-        if (r < 0) {
-            return r;
+    if (!assign) {
+        if (k->guest_notifier_mask && vdev->use_guest_notifier_mask) {
+            k->guest_notifier_mask(vdev, n, true);
         }
-        virtio_queue_set_guest_notifier_fd_handler(vq, true, with_irqfd);
+        if (with_irqfd) {
+            virtio_ccw_remove_irqfd(dev, n);
+        }
+    }
+
+    r = virtio_queue_set_guest_notifier(vdev, n, assign, with_irqfd);
+    if (r < 0) {
+        return r;
+    }
+
+    if (assign) {
         if (with_irqfd) {
             r = virtio_ccw_add_irqfd(dev, n);
             if (r) {
-                virtio_queue_set_guest_notifier_fd_handler(vq, false,
-                                                           with_irqfd);
-                event_notifier_cleanup(notifier);
+                virtio_queue_set_guest_notifier(vdev, n, false, with_irqfd);
                 return r;
             }
         }
@@ -1054,16 +1061,8 @@ static int virtio_ccw_set_guest_notifier(VirtioCcwDevice *dev, int n,
             k->guest_notifier_pending(vdev, n)) {
             event_notifier_set(notifier);
         }
-    } else {
-        if (k->guest_notifier_mask && vdev->use_guest_notifier_mask) {
-            k->guest_notifier_mask(vdev, n, true);
-        }
-        if (with_irqfd) {
-            virtio_ccw_remove_irqfd(dev, n);
-        }
-        virtio_queue_set_guest_notifier_fd_handler(vq, false, with_irqfd);
-        event_notifier_cleanup(notifier);
     }
+
     return 0;
 }
 
diff --git a/hw/virtio/virtio-mmio.c b/hw/virtio/virtio-mmio.c
index 0b0412b22f..b41c3614be 100644
--- a/hw/virtio/virtio-mmio.c
+++ b/hw/virtio/virtio-mmio.c
@@ -670,18 +670,11 @@ static int virtio_mmio_set_guest_notifier(DeviceState *d, int n, bool assign,
     VirtIOMMIOProxy *proxy = VIRTIO_MMIO(d);
     VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
     VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(vdev);
-    VirtQueue *vq = virtio_get_queue(vdev, n);
-    EventNotifier *notifier = virtio_queue_get_guest_notifier(vq);
+    int r;
 
-    if (assign) {
-        int r = event_notifier_init(notifier, 0);
-        if (r < 0) {
-            return r;
-        }
-        virtio_queue_set_guest_notifier_fd_handler(vq, true, with_irqfd);
-    } else {
-        virtio_queue_set_guest_notifier_fd_handler(vq, false, with_irqfd);
-        event_notifier_cleanup(notifier);
+    r = virtio_queue_set_guest_notifier(vdev, n, assign, with_irqfd);
+    if (r < 0) {
+        return r;
     }
 
     if (vdc->guest_notifier_mask && vdev->use_guest_notifier_mask) {
@@ -690,30 +683,7 @@ static int virtio_mmio_set_guest_notifier(DeviceState *d, int n, bool assign,
 
     return 0;
 }
-static int virtio_mmio_set_config_guest_notifier(DeviceState *d, bool assign,
-                                                 bool with_irqfd)
-{
-    VirtIOMMIOProxy *proxy = VIRTIO_MMIO(d);
-    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
-    VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(vdev);
-    EventNotifier *notifier = virtio_config_get_guest_notifier(vdev);
-    int r = 0;
 
-    if (assign) {
-        r = event_notifier_init(notifier, 0);
-        if (r < 0) {
-            return r;
-        }
-        virtio_config_set_guest_notifier_fd_handler(vdev, assign, with_irqfd);
-    } else {
-        virtio_config_set_guest_notifier_fd_handler(vdev, assign, with_irqfd);
-        event_notifier_cleanup(notifier);
-    }
-    if (vdc->guest_notifier_mask && vdev->use_guest_notifier_mask) {
-        vdc->guest_notifier_mask(vdev, VIRTIO_CONFIG_IRQ_IDX, !assign);
-    }
-    return r;
-}
 static int virtio_mmio_set_guest_notifiers(DeviceState *d, int nvqs,
                                            bool assign)
 {
@@ -735,7 +705,8 @@ static int virtio_mmio_set_guest_notifiers(DeviceState *d, int nvqs,
             goto assign_error;
         }
     }
-    r = virtio_mmio_set_config_guest_notifier(d, assign, with_irqfd);
+    r = virtio_mmio_set_guest_notifier(d, VIRTIO_CONFIG_IRQ_IDX, assign,
+                                       with_irqfd);
     if (r < 0) {
         goto assign_error;
     }
diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index b273eb2691..e7d5e19b32 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -1208,43 +1208,17 @@ static void virtio_pci_vector_poll(PCIDevice *dev,
     }
 }
 
-void virtio_pci_set_guest_notifier_fd_handler(VirtIODevice *vdev, VirtQueue *vq,
-                                              int n, bool assign,
-                                              bool with_irqfd)
-{
-    if (n == VIRTIO_CONFIG_IRQ_IDX) {
-        virtio_config_set_guest_notifier_fd_handler(vdev, assign, with_irqfd);
-    } else {
-        virtio_queue_set_guest_notifier_fd_handler(vq, assign, with_irqfd);
-    }
-}
-
 static int virtio_pci_set_guest_notifier(DeviceState *d, int n, bool assign,
                                          bool with_irqfd)
 {
     VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d);
     VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
     VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(vdev);
-    VirtQueue *vq = NULL;
-    EventNotifier *notifier = NULL;
+    int r;
 
-    if (n == VIRTIO_CONFIG_IRQ_IDX) {
-        notifier = virtio_config_get_guest_notifier(vdev);
-    } else {
-        vq = virtio_get_queue(vdev, n);
-        notifier = virtio_queue_get_guest_notifier(vq);
-    }
-
-    if (assign) {
-        int r = event_notifier_init(notifier, 0);
-        if (r < 0) {
-            return r;
-        }
-        virtio_pci_set_guest_notifier_fd_handler(vdev, vq, n, true, with_irqfd);
-    } else {
-        virtio_pci_set_guest_notifier_fd_handler(vdev, vq, n, false,
-                                                 with_irqfd);
-        event_notifier_cleanup(notifier);
+    r = virtio_queue_set_guest_notifier(vdev, n, assign, with_irqfd);
+    if (r < 0) {
+        return r;
     }
 
     if (!msix_enabled(&proxy->pci_dev) &&
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index 3dc9423eae..ea43ea620c 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -3828,8 +3828,10 @@ static void virtio_config_guest_notifier_read(EventNotifier *n)
         virtio_notify_config(vdev);
     }
 }
-void virtio_queue_set_guest_notifier_fd_handler(VirtQueue *vq, bool assign,
-                                                bool with_irqfd)
+
+static void virtio_queue_set_guest_notifier_fd_handler(VirtQueue *vq,
+                                                       bool assign,
+                                                       bool with_irqfd)
 {
     if (assign && !with_irqfd) {
         event_notifier_set_handler(&vq->guest_notifier,
@@ -3844,7 +3846,7 @@ void virtio_queue_set_guest_notifier_fd_handler(VirtQueue *vq, bool assign,
     }
 }
 
-void virtio_config_set_guest_notifier_fd_handler(VirtIODevice *vdev,
+static void virtio_config_set_guest_notifier_fd_handler(VirtIODevice *vdev,
                                                  bool assign, bool with_irqfd)
 {
     EventNotifier *n;
@@ -3861,6 +3863,46 @@ void virtio_config_set_guest_notifier_fd_handler(VirtIODevice *vdev,
     }
 }
 
+static void virtio_pci_set_guest_notifier_fd_handler(VirtIODevice *vdev,
+                                                     VirtQueue *vq,
+                                                     int n, bool assign,
+                                                     bool with_irqfd)
+{
+    if (n == VIRTIO_CONFIG_IRQ_IDX) {
+        virtio_config_set_guest_notifier_fd_handler(vdev, assign, with_irqfd);
+    } else {
+        virtio_queue_set_guest_notifier_fd_handler(vq, assign, with_irqfd);
+    }
+}
+
+int virtio_queue_set_guest_notifier(VirtIODevice *vdev, int n, bool assign,
+                                    bool with_irqfd)
+{
+    VirtQueue *vq = NULL;
+    EventNotifier *notifier = NULL;
+
+    if (n == VIRTIO_CONFIG_IRQ_IDX) {
+        notifier = virtio_config_get_guest_notifier(vdev);
+    } else {
+        vq = virtio_get_queue(vdev, n);
+        notifier = virtio_queue_get_guest_notifier(vq);
+    }
+
+    if (assign) {
+        int r = event_notifier_init(notifier, 0);
+        if (r < 0) {
+            return r;
+        }
+        virtio_pci_set_guest_notifier_fd_handler(vdev, vq, n, true, with_irqfd);
+    } else {
+        virtio_pci_set_guest_notifier_fd_handler(vdev, vq, n, false,
+                                                 with_irqfd);
+        event_notifier_cleanup(notifier);
+    }
+
+    return 0;
+}
+
 EventNotifier *virtio_queue_get_guest_notifier(VirtQueue *vq)
 {
     return &vq->guest_notifier;
diff --git a/include/hw/virtio/virtio-pci.h b/include/hw/virtio/virtio-pci.h
index 639752977e..2a5b65f374 100644
--- a/include/hw/virtio/virtio-pci.h
+++ b/include/hw/virtio/virtio-pci.h
@@ -263,9 +263,6 @@ void virtio_pci_types_register(const VirtioPCIDeviceTypeInfo *t);
  * @fixed_queues.
  */
 unsigned virtio_pci_optimal_num_queues(unsigned fixed_queues);
-void virtio_pci_set_guest_notifier_fd_handler(VirtIODevice *vdev, VirtQueue *vq,
-                                              int n, bool assign,
-                                              bool with_irqfd);
 
 int virtio_pci_add_shm_cap(VirtIOPCIProxy *proxy, uint8_t bar, uint64_t offset,
                            uint64_t length, uint8_t id);
diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
index 27cd98d2fe..25ef7c9dff 100644
--- a/include/hw/virtio/virtio.h
+++ b/include/hw/virtio/virtio.h
@@ -420,8 +420,6 @@ void virtio_queue_update_used_idx(VirtIODevice *vdev, int n);
 VirtQueue *virtio_get_queue(VirtIODevice *vdev, int n);
 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);
 int virtio_device_start_ioeventfd(VirtIODevice *vdev);
 int virtio_device_grab_ioeventfd(VirtIODevice *vdev);
 void virtio_device_release_ioeventfd(VirtIODevice *vdev);
@@ -435,8 +433,18 @@ void virtio_queue_aio_detach_host_notifier(VirtQueue *vq, AioContext *ctx);
 VirtQueue *virtio_vector_first_queue(VirtIODevice *vdev, uint16_t vector);
 VirtQueue *virtio_vector_next_queue(VirtQueue *vq);
 EventNotifier *virtio_config_get_guest_notifier(VirtIODevice *vdev);
-void virtio_config_set_guest_notifier_fd_handler(VirtIODevice *vdev,
-                                                 bool assign, bool with_irqfd);
+
+/**
+ * virtio_queue_set_guest_notifier - set/unset queue or config guest
+ *     notifier
+ *
+ * @vdev: the VirtIO device
+ * @n: queue number, or VIRTIO_CONFIG_IRQ_IDX to set config notifer
+ * @assign: true to set notifier, false to unset
+ * @with_irqfd: irqfd enabled
+ */
+int virtio_queue_set_guest_notifier(VirtIODevice *vdev, int n, bool assign,
+                                    bool with_irqfd);
 
 static inline void virtio_add_feature(uint64_t *features, unsigned int fbit)
 {
-- 
2.52.0
Re: [PATCH v4 08/23] virtio: move common part of _set_guest_notifier to generic code
Posted by Halil Pasic 2 weeks, 3 days ago
On Mon, 19 Jan 2026 21:52:12 +0300
Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru> wrote:

> virtio-pci, virtio-mmio and virtio-ccw handle config notifier equally
> but with different code (mmio adds a separate function, when pci use
> common function). Let's chose the more compact way (pci) and reuse it
> for mmio.
> 
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>

Ultimately is up to Michael to decide, but I'm not sure patch makes
things cleaner. I would even say, its current form, it does not.

I do like the idea of getting rid of duplicated logic though.


> ---
>  hw/s390x/virtio-ccw.c          | 35 ++++++++++++-------------
>  hw/virtio/virtio-mmio.c        | 41 +++++------------------------
>  hw/virtio/virtio-pci.c         | 34 +++---------------------
>  hw/virtio/virtio.c             | 48 +++++++++++++++++++++++++++++++---
>  include/hw/virtio/virtio-pci.h |  3 ---
>  include/hw/virtio/virtio.h     | 16 +++++++++---
>  6 files changed, 84 insertions(+), 93 deletions(-)
[..]
> diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
> index 3dc9423eae..ea43ea620c 100644
> --- a/hw/virtio/virtio.c
> +++ b/hw/virtio/virtio.c
[..]
> +static void virtio_pci_set_guest_notifier_fd_handler(VirtIODevice *vdev,

Function name says 'pci' but it actually is not PCI specific.

> +                                                     VirtQueue *vq,
> +                                                     int n, bool assign,
> +                                                     bool with_irqfd)
> +{
> +    if (n == VIRTIO_CONFIG_IRQ_IDX) {
> +        virtio_config_set_guest_notifier_fd_handler(vdev, assign, with_irqfd);
> +    } else {
> +        virtio_queue_set_guest_notifier_fd_handler(vq, assign, with_irqfd);
> +    }
> +}
> +
[..]
> diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
> index 27cd98d2fe..25ef7c9dff 100644
> --- a/include/hw/virtio/virtio.h
> +++ b/include/hw/virtio/virtio.h
> @@ -420,8 +420,6 @@ void virtio_queue_update_used_idx(VirtIODevice *vdev, int n);
>  VirtQueue *virtio_get_queue(VirtIODevice *vdev, int n);
>  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);
>  int virtio_device_start_ioeventfd(VirtIODevice *vdev);
>  int virtio_device_grab_ioeventfd(VirtIODevice *vdev);
>  void virtio_device_release_ioeventfd(VirtIODevice *vdev);
> @@ -435,8 +433,18 @@ void virtio_queue_aio_detach_host_notifier(VirtQueue *vq, AioContext *ctx);
>  VirtQueue *virtio_vector_first_queue(VirtIODevice *vdev, uint16_t vector);
>  VirtQueue *virtio_vector_next_queue(VirtQueue *vq);
>  EventNotifier *virtio_config_get_guest_notifier(VirtIODevice *vdev);
> -void virtio_config_set_guest_notifier_fd_handler(VirtIODevice *vdev,
> -                                                 bool assign, bool with_irqfd);
> +
> +/**
> + * virtio_queue_set_guest_notifier - set/unset queue or config guest
> + *     notifier
> + *
> + * @vdev: the VirtIO device
> + * @n: queue number, or VIRTIO_CONFIG_IRQ_IDX to set config notifer

Semantically are mixing queue numbers and interrupt indexes here.

> + * @assign: true to set notifier, false to unset
> + * @with_irqfd: irqfd enabled
> + */
> +int virtio_queue_set_guest_notifier(VirtIODevice *vdev, int n, bool assign,
> +                                    bool with_irqfd);

The name says 'queue' but it is not always queue any more.

Regards,
Halil
Re: [PATCH v4 08/23] virtio: move common part of _set_guest_notifier to generic code
Posted by Vladimir Sementsov-Ogievskiy 2 weeks ago
On 24.01.26 02:06, Halil Pasic wrote:
> On Mon, 19 Jan 2026 21:52:12 +0300
> Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru> wrote:
> 
>> virtio-pci, virtio-mmio and virtio-ccw handle config notifier equally
>> but with different code (mmio adds a separate function, when pci use
>> common function). Let's chose the more compact way (pci) and reuse it
>> for mmio.
>>
>> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
> 
> Ultimately is up to Michael to decide, but I'm not sure patch makes
> things cleaner. I would even say, its current form, it does not.
> 
> I do like the idea of getting rid of duplicated logic though.
> 
> 
>> ---
>>   hw/s390x/virtio-ccw.c          | 35 ++++++++++++-------------
>>   hw/virtio/virtio-mmio.c        | 41 +++++------------------------
>>   hw/virtio/virtio-pci.c         | 34 +++---------------------
>>   hw/virtio/virtio.c             | 48 +++++++++++++++++++++++++++++++---
>>   include/hw/virtio/virtio-pci.h |  3 ---
>>   include/hw/virtio/virtio.h     | 16 +++++++++---
>>   6 files changed, 84 insertions(+), 93 deletions(-)
> [..]
>> diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
>> index 3dc9423eae..ea43ea620c 100644
>> --- a/hw/virtio/virtio.c
>> +++ b/hw/virtio/virtio.c
> [..]
>> +static void virtio_pci_set_guest_notifier_fd_handler(VirtIODevice *vdev,
> 
> Function name says 'pci' but it actually is not PCI specific.

Agree. Is "virtio_set_guest_notifier_fd_handler()" OK?

> 
>> +                                                     VirtQueue *vq,
>> +                                                     int n, bool assign,
>> +                                                     bool with_irqfd)
>> +{
>> +    if (n == VIRTIO_CONFIG_IRQ_IDX) {
>> +        virtio_config_set_guest_notifier_fd_handler(vdev, assign, with_irqfd);
>> +    } else {
>> +        virtio_queue_set_guest_notifier_fd_handler(vq, assign, with_irqfd);
>> +    }
>> +}
>> +
> [..]
>> diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
>> index 27cd98d2fe..25ef7c9dff 100644
>> --- a/include/hw/virtio/virtio.h
>> +++ b/include/hw/virtio/virtio.h
>> @@ -420,8 +420,6 @@ void virtio_queue_update_used_idx(VirtIODevice *vdev, int n);
>>   VirtQueue *virtio_get_queue(VirtIODevice *vdev, int n);
>>   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);
>>   int virtio_device_start_ioeventfd(VirtIODevice *vdev);
>>   int virtio_device_grab_ioeventfd(VirtIODevice *vdev);
>>   void virtio_device_release_ioeventfd(VirtIODevice *vdev);
>> @@ -435,8 +433,18 @@ void virtio_queue_aio_detach_host_notifier(VirtQueue *vq, AioContext *ctx);
>>   VirtQueue *virtio_vector_first_queue(VirtIODevice *vdev, uint16_t vector);
>>   VirtQueue *virtio_vector_next_queue(VirtQueue *vq);
>>   EventNotifier *virtio_config_get_guest_notifier(VirtIODevice *vdev);
>> -void virtio_config_set_guest_notifier_fd_handler(VirtIODevice *vdev,
>> -                                                 bool assign, bool with_irqfd);
>> +
>> +/**
>> + * virtio_queue_set_guest_notifier - set/unset queue or config guest
>> + *     notifier
>> + *
>> + * @vdev: the VirtIO device
>> + * @n: queue number, or VIRTIO_CONFIG_IRQ_IDX to set config notifer
> 
> Semantically are mixing queue numbers and interrupt indexes here.

That's preexisting logic in virtio_pci_set_guest_notifier_fd_handler().

But, you are right, that's doesn't answer the question, is it good to share
the logic with mmio and ccw.

Is config notifier only pci specific, or similar feature may appear in future
for mmio and/or ccw?

I can try to keep config-notifier logic only in pci code.

Michael, what's better?

> 
>> + * @assign: true to set notifier, false to unset
>> + * @with_irqfd: irqfd enabled
>> + */
>> +int virtio_queue_set_guest_notifier(VirtIODevice *vdev, int n, bool assign,
>> +                                    bool with_irqfd);
> 
> The name says 'queue' but it is not always queue any more.

Agree, should be "virtio_set_guest_notifier()" if we go that way.

> 
> Regards,
> Halil

Thanks for reviewing!

-- 
Best regards,
Vladimir
Re: [PATCH v4 08/23] virtio: move common part of _set_guest_notifier to generic code
Posted by Halil Pasic 2 weeks ago
On Mon, 26 Jan 2026 19:40:09 +0300
Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru> wrote:

> >> +/**
> >> + * virtio_queue_set_guest_notifier - set/unset queue or config guest
> >> + *     notifier
> >> + *
> >> + * @vdev: the VirtIO device
> >> + * @n: queue number, or VIRTIO_CONFIG_IRQ_IDX to set config notifer  
> > 
> > Semantically are mixing queue numbers and interrupt indexes here.  
> 
> That's preexisting logic in virtio_pci_set_guest_notifier_fd_handler().
> 
> But, you are right, that's doesn't answer the question, is it good to share
> the logic with mmio and ccw.
> 
> Is config notifier only pci specific, or similar feature may appear in future
> for mmio and/or ccw?

AFAIR there is no  notifier for ccw. A possible explanation for
that is, that AFAIK that config space notifications (device -> driver)
are always classic I/O interrupts while queue indicators can be so called
adapter I/O interrupts and irqfd is only available for adapter I/O
interrupts. 

If you like you can have a look at 
"4.3.2.6 Setting Up Indicators" in
https://docs.oasis-open.org/virtio/virtio/v1.3/csd01/virtio-v1.3-csd01.html#x1-1940003

I see no reason why virtio_config_guest_notifier_read() based, i.e
!irqfd virtio config notifier should not exist or would not work. And I
guess it is needed for certain vhost things. But nevertheless, I can't
find the place where a virtio-ccw config notifier is set up.

Eric, what is your opinion on this? My current thinking is that
virtio-ccw not having a config notifier is basically a bug.

Regards,
Halil
Re: [PATCH v4 08/23] virtio: move common part of _set_guest_notifier to generic code
Posted by Eric Farman 1 week, 3 days ago
On Mon, 2026-01-26 at 23:00 +0100, Halil Pasic wrote:
> On Mon, 26 Jan 2026 19:40:09 +0300
> Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru> wrote:
> 
> > > > +/**
> > > > + * virtio_queue_set_guest_notifier - set/unset queue or config guest
> > > > + *     notifier
> > > > + *
> > > > + * @vdev: the VirtIO device
> > > > + * @n: queue number, or VIRTIO_CONFIG_IRQ_IDX to set config notifer  
> > > 
> > > Semantically are mixing queue numbers and interrupt indexes here.  
> > 
> > That's preexisting logic in virtio_pci_set_guest_notifier_fd_handler().
> > 
> > But, you are right, that's doesn't answer the question, is it good to share
> > the logic with mmio and ccw.
> > 
> > Is config notifier only pci specific, or similar feature may appear in future
> > for mmio and/or ccw?
> 
> AFAIR there is no  notifier for ccw. A possible explanation for
> that is, that AFAIK that config space notifications (device -> driver)
> are always classic I/O interrupts while queue indicators can be so called
> adapter I/O interrupts and irqfd is only available for adapter I/O
> interrupts. 
> 
> If you like you can have a look at 
> "4.3.2.6 Setting Up Indicators" in
> https://docs.oasis-open.org/virtio/virtio/v1.3/csd01/virtio-v1.3-csd01.html#x1-1940003
> 
> I see no reason why virtio_config_guest_notifier_read() based, i.e
> !irqfd virtio config notifier should not exist or would not work. And I
> guess it is needed for certain vhost things. But nevertheless, I can't
> find the place where a virtio-ccw config notifier is set up.
> 
> Eric, what is your opinion on this? My current thinking is that
> virtio-ccw not having a config notifier is basically a bug.

(Sorry that I missed this; thanks for the ping, Halil)

Yeah, we don't have have such a config notifier and I don't recall the history behind it.
But I don't know that it's a bug; spec points out config notifications for ccw come as unsolicited
interrupts versus config notifier, so not having one is fine by me as far as this refactoring goes.
I'll add it to a list of things to play around with, though.

Thanks, Eric
Re: [PATCH v4 08/23] virtio: move common part of _set_guest_notifier to generic code
Posted by Cornelia Huck 1 week, 3 days ago
On Fri, Jan 30 2026, Eric Farman <farman@linux.ibm.com> wrote:

> On Mon, 2026-01-26 at 23:00 +0100, Halil Pasic wrote:
>> On Mon, 26 Jan 2026 19:40:09 +0300
>> Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru> wrote:
>> 
>> > > > +/**
>> > > > + * virtio_queue_set_guest_notifier - set/unset queue or config guest
>> > > > + *     notifier
>> > > > + *
>> > > > + * @vdev: the VirtIO device
>> > > > + * @n: queue number, or VIRTIO_CONFIG_IRQ_IDX to set config notifer  
>> > > 
>> > > Semantically are mixing queue numbers and interrupt indexes here.  
>> > 
>> > That's preexisting logic in virtio_pci_set_guest_notifier_fd_handler().
>> > 
>> > But, you are right, that's doesn't answer the question, is it good to share
>> > the logic with mmio and ccw.
>> > 
>> > Is config notifier only pci specific, or similar feature may appear in future
>> > for mmio and/or ccw?
>> 
>> AFAIR there is no  notifier for ccw. A possible explanation for
>> that is, that AFAIK that config space notifications (device -> driver)
>> are always classic I/O interrupts while queue indicators can be so called
>> adapter I/O interrupts and irqfd is only available for adapter I/O
>> interrupts. 
>> 
>> If you like you can have a look at 
>> "4.3.2.6 Setting Up Indicators" in
>> https://docs.oasis-open.org/virtio/virtio/v1.3/csd01/virtio-v1.3-csd01.html#x1-1940003
>> 
>> I see no reason why virtio_config_guest_notifier_read() based, i.e
>> !irqfd virtio config notifier should not exist or would not work. And I
>> guess it is needed for certain vhost things. But nevertheless, I can't
>> find the place where a virtio-ccw config notifier is set up.
>> 
>> Eric, what is your opinion on this? My current thinking is that
>> virtio-ccw not having a config notifier is basically a bug.
>
> (Sorry that I missed this; thanks for the ping, Halil)
>
> Yeah, we don't have have such a config notifier and I don't recall the history behind it.

Adapter interrupts were not a thing for virtio-ccw in the beginning (we
only added the airq infrastructure later IIRC, so all interrupts were
"classic" subchannel-based interrupts.)

> But I don't know that it's a bug; spec points out config notifications for ccw come as unsolicited
> interrupts versus config notifier, so not having one is fine by me as far as this refactoring goes.
> I'll add it to a list of things to play around with, though.

I think I agree.

(Although my brain is already more than halfway into the weekend...)
Re: [PATCH v4 08/23] virtio: move common part of _set_guest_notifier to generic code
Posted by Eric Farman 2 weeks, 6 days ago
On Mon, 2026-01-19 at 21:52 +0300, Vladimir Sementsov-Ogievskiy wrote:
> virtio-pci, virtio-mmio and virtio-ccw handle config notifier equally
> but with different code (mmio adds a separate function, when pci use
> common function). Let's chose the more compact way (pci) and reuse it
> for mmio.
> 
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
> ---
>  hw/s390x/virtio-ccw.c          | 35 ++++++++++++-------------
>  hw/virtio/virtio-mmio.c        | 41 +++++------------------------
>  hw/virtio/virtio-pci.c         | 34 +++---------------------
>  hw/virtio/virtio.c             | 48 +++++++++++++++++++++++++++++++---
>  include/hw/virtio/virtio-pci.h |  3 ---
>  include/hw/virtio/virtio.h     | 16 +++++++++---
>  6 files changed, 84 insertions(+), 93 deletions(-)

Acked-by: Eric Farman <farman@linux.ibm.com>  # s390