All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 1/4] virtio-mmio: introduce set_host_notifier()
@ 2015-05-06  7:52 Pavel Fedin
  2015-05-06 14:52 ` Eric Blake
  0 siblings, 1 reply; 6+ messages in thread
From: Pavel Fedin @ 2015-05-06  7:52 UTC (permalink / raw)
  To: qemu-devel

set_host_notifier() is introduced into virtio-mmio now. Most of codes came
from virtio-pci.

Signed-off-by: Ying-Shiuan Pan <address@hidden>
Signed-off-by: Pavel Fedin <p.fedin@samsung.com>
---
 hw/virtio/virtio-mmio.c | 70
+++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 70 insertions(+)

diff --git a/hw/virtio/virtio-mmio.c b/hw/virtio/virtio-mmio.c
index 10123f3..32bf240 100644
--- a/hw/virtio/virtio-mmio.c
+++ b/hw/virtio/virtio-mmio.c
@@ -23,6 +23,7 @@
 #include "hw/virtio/virtio.h"
 #include "qemu/host-utils.h"
 #include "hw/virtio/virtio-bus.h"
+#include "qemu/error-report.h"
 
 /* #define DEBUG_VIRTIO_MMIO */
 
@@ -87,8 +88,58 @@ typedef struct {
     uint32_t guest_page_shift;
     /* virtio-bus */
     VirtioBusState bus;
+    bool ioeventfd_disabled;
+    bool ioeventfd_started;
 } VirtIOMMIOProxy;
 
+static int virtio_mmio_set_host_notifier_internal(VirtIOMMIOProxy *proxy,
+                                                  int n, bool assign, bool
set_handler)
+{
+    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
+    VirtQueue *vq = virtio_get_queue(vdev, n);
+    EventNotifier *notifier = virtio_queue_get_host_notifier(vq);
+    int r = 0;
+ 
+    if (assign) {
+        r = event_notifier_init(notifier, 1);
+        if (r < 0) {
+            error_report("%s: unable to init event notifier: %d",
+                         __func__, r);
+            return r;
+        }
+        virtio_queue_set_host_notifier_fd_handler(vq, true, set_handler);
+        memory_region_add_eventfd(&proxy->iomem, VIRTIO_MMIO_QUEUENOTIFY,
4,
+                                  true, n, notifier);
+    } else {
+        memory_region_del_eventfd(&proxy->iomem, VIRTIO_MMIO_QUEUENOTIFY,
4,
+                                  true, n, notifier);
+        virtio_queue_set_host_notifier_fd_handler(vq, false, false);
+        event_notifier_cleanup(notifier);
+    }
+    return r;
+}
+ 
+static void virtio_mmio_stop_ioeventfd(VirtIOMMIOProxy *proxy)
+{
+    int r;
+    int n;
+    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
+
+    if (!proxy->ioeventfd_started) {
+        return;
+    }
+
+    for (n = 0; n < VIRTIO_PCI_QUEUE_MAX; n++) {
+        if (!virtio_queue_get_num(vdev, n)) {
+            continue;
+        }
+
+        r = virtio_mmio_set_host_notifier_internal(proxy, n, false, false);
+        assert(r >= 0);
+    }
+    proxy->ioeventfd_started = false;
+}
+
 static uint64_t virtio_mmio_read(void *opaque, hwaddr offset, unsigned
size)
 {
     VirtIOMMIOProxy *proxy = (VirtIOMMIOProxy *)opaque;
@@ -342,6 +393,24 @@ static void virtio_mmio_reset(DeviceState *d)
     proxy->guest_page_shift = 0;
 }
 
+static int virtio_mmio_set_host_notifier(DeviceState *opaque, int n, bool
assign)
+{
+    VirtIOMMIOProxy *proxy = VIRTIO_MMIO(opaque);
+
+    /* Stop using ioeventfd for virtqueue kick if the device starts using
host
+     * notifiers.  This makes it easy to avoid stepping on each others'
toes.
+     */
+    proxy->ioeventfd_disabled = assign;
+    if (assign) {
+        virtio_mmio_stop_ioeventfd(proxy);
+    }
+    /* We don't need to start here: it's not needed because backend
+     * currently only stops on status change away from ok,
+     * reset, vmstop and such. If we do add code to start here,
+     * need to check vmstate, device state etc. */
+    return virtio_mmio_set_host_notifier_internal(proxy, n, assign, false);
+}
+
 /* virtio-mmio device */
 
 /* This is called by virtio-bus just after the device is plugged. */
@@ -399,6 +468,7 @@ static void virtio_mmio_bus_class_init(ObjectClass
*klass, void *data)
     k->notify = virtio_mmio_update_irq;
     k->save_config = virtio_mmio_save_config;
     k->load_config = virtio_mmio_load_config;
+    k->set_host_notifier = virtio_mmio_set_host_notifier;
     k->get_features = virtio_mmio_get_features;
     k->device_plugged = virtio_mmio_device_plugged;
     k->has_variable_vring_alignment = true;
-- 
1.9.5.msysgit.0

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [PATCH 1/4] virtio-mmio: introduce set_host_notifier()
  2015-05-06  7:52 [Qemu-devel] [PATCH 1/4] virtio-mmio: introduce set_host_notifier() Pavel Fedin
@ 2015-05-06 14:52 ` Eric Blake
  0 siblings, 0 replies; 6+ messages in thread
From: Eric Blake @ 2015-05-06 14:52 UTC (permalink / raw)
  To: Pavel Fedin, qemu-devel

[-- Attachment #1: Type: text/plain, Size: 948 bytes --]

On 05/06/2015 01:52 AM, Pavel Fedin wrote:

[meta-comment]

> set_host_notifier() is introduced into virtio-mmio now. Most of codes came
> from virtio-pci.
> 

Missing an 'In-Reply-To: <000501d087d0$39c1bd90$ad4538b0$@samsung.com>'
header, which makes your series unthreaded (every message appeared as
its own thread).  It makes review easier if everything is properly
threaded to the cover letter, so you may want to send a series to
yourself first as a test case of your setup before sending to the list.

Other submission hints at: http://wiki.qemu.org/Contribute/SubmitAPatch

>  
> +static int virtio_mmio_set_host_notifier_internal(VirtIOMMIOProxy *proxy,
> +                                                  int n, bool assign, bool
> set_handler)

Long line, you might want to wrap it to fit in 80 columns.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [PATCH 1/4] virtio-mmio: introduce set_host_notifier()
  2014-11-19  7:47   ` Fam Zheng
@ 2014-11-20 12:41     ` Shannon Zhao
  0 siblings, 0 replies; 6+ messages in thread
From: Shannon Zhao @ 2014-11-20 12:41 UTC (permalink / raw)
  To: Fam Zheng
  Cc: peter.maydell, hangaohuai, yingshiuan.pan, mst, john.liuli,
	qemu-devel, n.nikolaev, peter.huangpeng

On 2014/11/19 15:47, Fam Zheng wrote:
> On Tue, 11/04 20:47, Shannon Zhao wrote:
>> set_host_notifier() is introduced into virtio-mmio now. Most of codes came
>> from virtio-pci.
>>
>> Signed-off-by: Ying-Shiuan Pan <yingshiuan.pan@gmail.com>
>> Signed-off-by: Li Liu <john.liuli@huawei.com>
>> Signed-off-by: Shannon Zhao <zhaoshenglong@huawei.com>
>> ---
>>  hw/virtio/virtio-mmio.c |   70 +++++++++++++++++++++++++++++++++++++++++++++++
>>  1 files changed, 70 insertions(+), 0 deletions(-)
>>
>> diff --git a/hw/virtio/virtio-mmio.c b/hw/virtio/virtio-mmio.c
>> index 2450c13..d8ec2d1 100644
>> --- a/hw/virtio/virtio-mmio.c
>> +++ b/hw/virtio/virtio-mmio.c
>> @@ -23,6 +23,7 @@
>>  #include "hw/virtio/virtio.h"
>>  #include "qemu/host-utils.h"
>>  #include "hw/virtio/virtio-bus.h"
>> +#include "qemu/error-report.h"
>>  
>>  /* #define DEBUG_VIRTIO_MMIO */
>>  
>> @@ -87,8 +88,58 @@ typedef struct {
>>      uint32_t guest_page_shift;
>>      /* virtio-bus */
>>      VirtioBusState bus;
>> +    bool ioeventfd_disabled;
>> +    bool ioeventfd_started;
>>  } VirtIOMMIOProxy;
>>  
>> +static int virtio_mmio_set_host_notifier_internal(VirtIOMMIOProxy *proxy,
>> +                                                 int n, bool assign, bool set_handler)
> 
> I didn't review the code, but checkpatch.pl noticed this line and one more
> below [*] is too long (over 80 columes).
> 
>> +{
>> +    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
>> +    VirtQueue *vq = virtio_get_queue(vdev, n);
>> +    EventNotifier *notifier = virtio_queue_get_host_notifier(vq);
>> +    int r = 0;
>> +
>> +    if (assign) {
>> +        r = event_notifier_init(notifier, 1);
>> +        if (r < 0) {
>> +            error_report("%s: unable to init event notifier: %d",
>> +                         __func__, r);
>> +            return r;
>> +        }
>> +        virtio_queue_set_host_notifier_fd_handler(vq, true, set_handler);
>> +        memory_region_add_eventfd(&proxy->iomem, VIRTIO_MMIO_QUEUENOTIFY, 4,
>> +                                  true, n, notifier);
>> +    } else {
>> +        memory_region_del_eventfd(&proxy->iomem, VIRTIO_MMIO_QUEUENOTIFY, 4,
>> +                                  true, n, notifier);
>> +        virtio_queue_set_host_notifier_fd_handler(vq, false, false);
>> +        event_notifier_cleanup(notifier);
>> +    }
>> +    return r;
>> +}
>> +
>> +static void virtio_mmio_stop_ioeventfd(VirtIOMMIOProxy *proxy)
>> +{
>> +    int r;
>> +    int n;
>> +    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
>> +
>> +    if (!proxy->ioeventfd_started) {
>> +        return;
>> +    }
>> +
>> +    for (n = 0; n < VIRTIO_PCI_QUEUE_MAX; n++) {
>> +        if (!virtio_queue_get_num(vdev, n)) {
>> +            continue;
>> +        }
>> +
>> +        r = virtio_mmio_set_host_notifier_internal(proxy, n, false, false);
>> +        assert(r >= 0);
>> +    }
>> +    proxy->ioeventfd_started = false;
>> +}
>> +
>>  static uint64_t virtio_mmio_read(void *opaque, hwaddr offset, unsigned size)
>>  {
>>      VirtIOMMIOProxy *proxy = (VirtIOMMIOProxy *)opaque;
>> @@ -342,6 +393,24 @@ static void virtio_mmio_reset(DeviceState *d)
>>      proxy->guest_page_shift = 0;
>>  }
>>  
>> +static int virtio_mmio_set_host_notifier(DeviceState *opaque, int n, bool assign)
> 
> [*]
> 
> No need to respin yet just for this. Please wait for a serious review.
> 

Ok,thanks,
Shannon

> Thanks,
> 
> Fam
> 
> .
> 


-- 
Shannon

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [PATCH 1/4] virtio-mmio: introduce set_host_notifier()
  2014-11-04 12:47 ` [Qemu-devel] [PATCH 1/4] virtio-mmio: introduce set_host_notifier() Shannon Zhao
@ 2014-11-19  7:47   ` Fam Zheng
  2014-11-20 12:41     ` Shannon Zhao
  0 siblings, 1 reply; 6+ messages in thread
From: Fam Zheng @ 2014-11-19  7:47 UTC (permalink / raw)
  To: Shannon Zhao
  Cc: peter.maydell, hangaohuai, yingshiuan.pan, mst, john.liuli,
	qemu-devel, n.nikolaev, peter.huangpeng

On Tue, 11/04 20:47, Shannon Zhao wrote:
> set_host_notifier() is introduced into virtio-mmio now. Most of codes came
> from virtio-pci.
> 
> Signed-off-by: Ying-Shiuan Pan <yingshiuan.pan@gmail.com>
> Signed-off-by: Li Liu <john.liuli@huawei.com>
> Signed-off-by: Shannon Zhao <zhaoshenglong@huawei.com>
> ---
>  hw/virtio/virtio-mmio.c |   70 +++++++++++++++++++++++++++++++++++++++++++++++
>  1 files changed, 70 insertions(+), 0 deletions(-)
> 
> diff --git a/hw/virtio/virtio-mmio.c b/hw/virtio/virtio-mmio.c
> index 2450c13..d8ec2d1 100644
> --- a/hw/virtio/virtio-mmio.c
> +++ b/hw/virtio/virtio-mmio.c
> @@ -23,6 +23,7 @@
>  #include "hw/virtio/virtio.h"
>  #include "qemu/host-utils.h"
>  #include "hw/virtio/virtio-bus.h"
> +#include "qemu/error-report.h"
>  
>  /* #define DEBUG_VIRTIO_MMIO */
>  
> @@ -87,8 +88,58 @@ typedef struct {
>      uint32_t guest_page_shift;
>      /* virtio-bus */
>      VirtioBusState bus;
> +    bool ioeventfd_disabled;
> +    bool ioeventfd_started;
>  } VirtIOMMIOProxy;
>  
> +static int virtio_mmio_set_host_notifier_internal(VirtIOMMIOProxy *proxy,
> +                                                 int n, bool assign, bool set_handler)

I didn't review the code, but checkpatch.pl noticed this line and one more
below [*] is too long (over 80 columes).

> +{
> +    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
> +    VirtQueue *vq = virtio_get_queue(vdev, n);
> +    EventNotifier *notifier = virtio_queue_get_host_notifier(vq);
> +    int r = 0;
> +
> +    if (assign) {
> +        r = event_notifier_init(notifier, 1);
> +        if (r < 0) {
> +            error_report("%s: unable to init event notifier: %d",
> +                         __func__, r);
> +            return r;
> +        }
> +        virtio_queue_set_host_notifier_fd_handler(vq, true, set_handler);
> +        memory_region_add_eventfd(&proxy->iomem, VIRTIO_MMIO_QUEUENOTIFY, 4,
> +                                  true, n, notifier);
> +    } else {
> +        memory_region_del_eventfd(&proxy->iomem, VIRTIO_MMIO_QUEUENOTIFY, 4,
> +                                  true, n, notifier);
> +        virtio_queue_set_host_notifier_fd_handler(vq, false, false);
> +        event_notifier_cleanup(notifier);
> +    }
> +    return r;
> +}
> +
> +static void virtio_mmio_stop_ioeventfd(VirtIOMMIOProxy *proxy)
> +{
> +    int r;
> +    int n;
> +    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
> +
> +    if (!proxy->ioeventfd_started) {
> +        return;
> +    }
> +
> +    for (n = 0; n < VIRTIO_PCI_QUEUE_MAX; n++) {
> +        if (!virtio_queue_get_num(vdev, n)) {
> +            continue;
> +        }
> +
> +        r = virtio_mmio_set_host_notifier_internal(proxy, n, false, false);
> +        assert(r >= 0);
> +    }
> +    proxy->ioeventfd_started = false;
> +}
> +
>  static uint64_t virtio_mmio_read(void *opaque, hwaddr offset, unsigned size)
>  {
>      VirtIOMMIOProxy *proxy = (VirtIOMMIOProxy *)opaque;
> @@ -342,6 +393,24 @@ static void virtio_mmio_reset(DeviceState *d)
>      proxy->guest_page_shift = 0;
>  }
>  
> +static int virtio_mmio_set_host_notifier(DeviceState *opaque, int n, bool assign)

[*]

No need to respin yet just for this. Please wait for a serious review.

Thanks,

Fam

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Qemu-devel] [PATCH 1/4] virtio-mmio: introduce set_host_notifier()
  2014-11-04 12:47 [Qemu-devel] [PATCH 0/4] ioeventfd support for virtio-mmio Shannon Zhao
@ 2014-11-04 12:47 ` Shannon Zhao
  2014-11-19  7:47   ` Fam Zheng
  0 siblings, 1 reply; 6+ messages in thread
From: Shannon Zhao @ 2014-11-04 12:47 UTC (permalink / raw)
  To: qemu-devel
  Cc: peter.maydell, hangaohuai, yingshiuan.pan, mst, john.liuli,
	peter.huangpeng, n.nikolaev

set_host_notifier() is introduced into virtio-mmio now. Most of codes came
from virtio-pci.

Signed-off-by: Ying-Shiuan Pan <yingshiuan.pan@gmail.com>
Signed-off-by: Li Liu <john.liuli@huawei.com>
Signed-off-by: Shannon Zhao <zhaoshenglong@huawei.com>
---
 hw/virtio/virtio-mmio.c |   70 +++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 70 insertions(+), 0 deletions(-)

diff --git a/hw/virtio/virtio-mmio.c b/hw/virtio/virtio-mmio.c
index 2450c13..d8ec2d1 100644
--- a/hw/virtio/virtio-mmio.c
+++ b/hw/virtio/virtio-mmio.c
@@ -23,6 +23,7 @@
 #include "hw/virtio/virtio.h"
 #include "qemu/host-utils.h"
 #include "hw/virtio/virtio-bus.h"
+#include "qemu/error-report.h"
 
 /* #define DEBUG_VIRTIO_MMIO */
 
@@ -87,8 +88,58 @@ typedef struct {
     uint32_t guest_page_shift;
     /* virtio-bus */
     VirtioBusState bus;
+    bool ioeventfd_disabled;
+    bool ioeventfd_started;
 } VirtIOMMIOProxy;
 
+static int virtio_mmio_set_host_notifier_internal(VirtIOMMIOProxy *proxy,
+                                                 int n, bool assign, bool set_handler)
+{
+    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
+    VirtQueue *vq = virtio_get_queue(vdev, n);
+    EventNotifier *notifier = virtio_queue_get_host_notifier(vq);
+    int r = 0;
+
+    if (assign) {
+        r = event_notifier_init(notifier, 1);
+        if (r < 0) {
+            error_report("%s: unable to init event notifier: %d",
+                         __func__, r);
+            return r;
+        }
+        virtio_queue_set_host_notifier_fd_handler(vq, true, set_handler);
+        memory_region_add_eventfd(&proxy->iomem, VIRTIO_MMIO_QUEUENOTIFY, 4,
+                                  true, n, notifier);
+    } else {
+        memory_region_del_eventfd(&proxy->iomem, VIRTIO_MMIO_QUEUENOTIFY, 4,
+                                  true, n, notifier);
+        virtio_queue_set_host_notifier_fd_handler(vq, false, false);
+        event_notifier_cleanup(notifier);
+    }
+    return r;
+}
+
+static void virtio_mmio_stop_ioeventfd(VirtIOMMIOProxy *proxy)
+{
+    int r;
+    int n;
+    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
+
+    if (!proxy->ioeventfd_started) {
+        return;
+    }
+
+    for (n = 0; n < VIRTIO_PCI_QUEUE_MAX; n++) {
+        if (!virtio_queue_get_num(vdev, n)) {
+            continue;
+        }
+
+        r = virtio_mmio_set_host_notifier_internal(proxy, n, false, false);
+        assert(r >= 0);
+    }
+    proxy->ioeventfd_started = false;
+}
+
 static uint64_t virtio_mmio_read(void *opaque, hwaddr offset, unsigned size)
 {
     VirtIOMMIOProxy *proxy = (VirtIOMMIOProxy *)opaque;
@@ -342,6 +393,24 @@ static void virtio_mmio_reset(DeviceState *d)
     proxy->guest_page_shift = 0;
 }
 
+static int virtio_mmio_set_host_notifier(DeviceState *opaque, int n, bool assign)
+{
+    VirtIOMMIOProxy *proxy = VIRTIO_MMIO(opaque);
+
+    /* Stop using ioeventfd for virtqueue kick if the device starts using host
+     * notifiers.  This makes it easy to avoid stepping on each others' toes.
+     */
+    proxy->ioeventfd_disabled = assign;
+    if (assign) {
+        virtio_mmio_stop_ioeventfd(proxy);
+    }
+    /* We don't need to start here: it's not needed because backend
+     * currently only stops on status change away from ok,
+     * reset, vmstop and such. If we do add code to start here,
+     * need to check vmstate, device state etc. */
+    return virtio_mmio_set_host_notifier_internal(proxy, n, assign, false);
+}
+
 /* virtio-mmio device */
 
 /* This is called by virtio-bus just after the device is plugged. */
@@ -399,6 +468,7 @@ static void virtio_mmio_bus_class_init(ObjectClass *klass, void *data)
     k->notify = virtio_mmio_update_irq;
     k->save_config = virtio_mmio_save_config;
     k->load_config = virtio_mmio_load_config;
+    k->set_host_notifier = virtio_mmio_set_host_notifier;
     k->get_features = virtio_mmio_get_features;
     k->device_plugged = virtio_mmio_device_plugged;
     k->has_variable_vring_alignment = true;
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [Qemu-devel] [PATCH 1/4] virtio-mmio: introduce set_host_notifier()
  2014-02-05 17:03 [Qemu-devel] [PATCH 0/4] ioeventfd support for virtio-mmio Ying-Shiuan Pan
@ 2014-02-05 17:03 ` Ying-Shiuan Pan
  0 siblings, 0 replies; 6+ messages in thread
From: Ying-Shiuan Pan @ 2014-02-05 17:03 UTC (permalink / raw)
  To: qemu-devel; +Cc: wbarak, Ying-Shiuan Pan, yspan

set_host_notifier() is introduced into virtio-mmio now. Most of codes came
from virtio-pci.

Signed-off-by: Ying-Shiuan Pan <yspan@itri.org.tw>
---
 hw/virtio/virtio-mmio.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 70 insertions(+)

diff --git a/hw/virtio/virtio-mmio.c b/hw/virtio/virtio-mmio.c
index 8829eb0..558fd2f 100644
--- a/hw/virtio/virtio-mmio.c
+++ b/hw/virtio/virtio-mmio.c
@@ -23,6 +23,7 @@
 #include "hw/virtio/virtio.h"
 #include "qemu/host-utils.h"
 #include "hw/virtio/virtio-bus.h"
+#include "qemu/error-report.h"
 
 /* #define DEBUG_VIRTIO_MMIO */
 
@@ -87,11 +88,61 @@ typedef struct {
     uint32_t guest_page_shift;
     /* virtio-bus */
     VirtioBusState bus;
+    bool ioeventfd_disabled;
+    bool ioeventfd_started;
 } VirtIOMMIOProxy;
 
 static void virtio_mmio_bus_new(VirtioBusState *bus, size_t bus_size,
                                 VirtIOMMIOProxy *dev);
 
+static int virtio_mmio_set_host_notifier_internal(VirtIOMMIOProxy *proxy,
+                                                 int n, bool assign, bool set_handler)
+{
+    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
+    VirtQueue *vq = virtio_get_queue(vdev, n);
+    EventNotifier *notifier = virtio_queue_get_host_notifier(vq);
+    int r = 0;
+
+    if (assign) {
+        r = event_notifier_init(notifier, 1);
+        if (r < 0) {
+            error_report("%s: unable to init event notifier: %d",
+                         __func__, r);
+            return r;
+        }
+        virtio_queue_set_host_notifier_fd_handler(vq, true, set_handler);
+        memory_region_add_eventfd(&proxy->iomem, VIRTIO_MMIO_QUEUENOTIFY, 4,
+                                  true, n, notifier);
+    } else {
+        memory_region_del_eventfd(&proxy->iomem, VIRTIO_MMIO_QUEUENOTIFY, 4,
+                                  true, n, notifier);
+        virtio_queue_set_host_notifier_fd_handler(vq, false, false);
+        event_notifier_cleanup(notifier);
+    }
+    return r;
+}
+
+static void virtio_mmio_stop_ioeventfd(VirtIOMMIOProxy *proxy)
+{
+    int r;
+    int n;
+    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
+
+    if (!proxy->ioeventfd_started) {
+        return;
+    }
+
+    for (n = 0; n < VIRTIO_PCI_QUEUE_MAX; n++) {
+        if (!virtio_queue_get_num(vdev, n)) {
+            continue;
+        }
+
+        r = virtio_mmio_set_host_notifier_internal(proxy, n, false, false);
+        assert(r >= 0);
+    }
+    proxy->ioeventfd_started = false;
+}
+
 static uint64_t virtio_mmio_read(void *opaque, hwaddr offset, unsigned size)
 {
     VirtIOMMIOProxy *proxy = (VirtIOMMIOProxy *)opaque;
@@ -345,6 +396,24 @@ static void virtio_mmio_reset(DeviceState *d)
     proxy->guest_page_shift = 0;
 }
 
+static int virtio_mmio_set_host_notifier(DeviceState *opaque, int n, bool assign)
+{
+    VirtIOMMIOProxy *proxy = VIRTIO_MMIO(opaque);
+
+    /* Stop using ioeventfd for virtqueue kick if the device starts using host
+     * notifiers.  This makes it easy to avoid stepping on each others' toes.
+     */
+    proxy->ioeventfd_disabled = assign;
+    if (assign) {
+        virtio_mmio_stop_ioeventfd(proxy);
+    }
+    /* We don't need to start here: it's not needed because backend
+     * currently only stops on status change away from ok,
+     * reset, vmstop and such. If we do add code to start here,
+     * need to check vmstate, device state etc. */
+    return virtio_mmio_set_host_notifier_internal(proxy, n, assign, false);
+}
+
 /* virtio-mmio device */
 
 /* This is called by virtio-bus just after the device is plugged. */
@@ -406,6 +475,7 @@ static void virtio_mmio_bus_class_init(ObjectClass *klass, void *data)
     k->notify = virtio_mmio_update_irq;
     k->save_config = virtio_mmio_save_config;
     k->load_config = virtio_mmio_load_config;
+    k->set_host_notifier = virtio_mmio_set_host_notifier;
     k->get_features = virtio_mmio_get_features;
     k->device_plugged = virtio_mmio_device_plugged;
     k->has_variable_vring_alignment = true;
-- 
1.8.1.2

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-05-06 14:52 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-06  7:52 [Qemu-devel] [PATCH 1/4] virtio-mmio: introduce set_host_notifier() Pavel Fedin
2015-05-06 14:52 ` Eric Blake
  -- strict thread matches above, loose matches on Subject: below --
2014-11-04 12:47 [Qemu-devel] [PATCH 0/4] ioeventfd support for virtio-mmio Shannon Zhao
2014-11-04 12:47 ` [Qemu-devel] [PATCH 1/4] virtio-mmio: introduce set_host_notifier() Shannon Zhao
2014-11-19  7:47   ` Fam Zheng
2014-11-20 12:41     ` Shannon Zhao
2014-02-05 17:03 [Qemu-devel] [PATCH 0/4] ioeventfd support for virtio-mmio Ying-Shiuan Pan
2014-02-05 17:03 ` [Qemu-devel] [PATCH 1/4] virtio-mmio: introduce set_host_notifier() Ying-Shiuan Pan

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.