qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v2] vhost: Fix aborting if KVM does not support eventfds
@ 2015-11-17  7:17 Pavel Fedin
  2015-11-18 21:25 ` Michael S. Tsirkin
  0 siblings, 1 reply; 4+ messages in thread
From: Pavel Fedin @ 2015-11-17  7:17 UTC (permalink / raw)
  To: qemu-devel; +Cc: 'Christian Borntraeger', 'Michael S. Tsirkin'

If you happen to have a stock kernel of old version, like 3.x, and you
attempt to enable vhost by setting vhost=on, qemu aborts with error:

kvm_mem_ioeventfd_add: error adding ioeventfd: Function not implemented

This patch adds capability check, so that vhost gets disabled instead. A
warning is displayed, explaining the reason:

2015-11-13T08:43:51.146802Z qemu-system-aarch64: KVM does not support eventfd binding
2015-11-13T08:43:51.146915Z qemu-system-aarch64: unable to start vhost net: 38: falling back on userspace virtio

This problem can be observed with libvirt, which checks for /dev/vhost-net
availability and just inserts "vhost=on" automatically in this case.

Signed-off-by: Pavel Fedin <p.fedin@samsung.com>
---
v1 => v2:
- Removed "MMIO" from warning message, because it applies not only to MMIO
- Add note about warning to the commit message
---
 hw/virtio/vhost.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
index 1794f0d..50b8171 100644
--- a/hw/virtio/vhost.c
+++ b/hw/virtio/vhost.c
@@ -24,6 +24,7 @@
 #include "hw/virtio/virtio-bus.h"
 #include "hw/virtio/virtio-access.h"
 #include "migration/migration.h"
+#include "sysemu/kvm.h"
 
 static struct vhost_log *vhost_log;
 static struct vhost_log *vhost_log_shm;
@@ -1083,6 +1084,11 @@ int vhost_dev_enable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev)
         r = -ENOSYS;
         goto fail;
     }
+    if (!kvm_eventfds_enabled()) {
+        error_report("KVM does not support eventfd binding");
+        r = -ENOSYS;
+        goto fail;
+    }
 
     for (i = 0; i < hdev->nvqs; ++i) {
         r = k->set_host_notifier(qbus->parent, hdev->vq_index + i, true);
-- 
1.9.5.msysgit.0

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

* Re: [Qemu-devel] [PATCH v2] vhost: Fix aborting if KVM does not support eventfds
  2015-11-17  7:17 [Qemu-devel] [PATCH v2] vhost: Fix aborting if KVM does not support eventfds Pavel Fedin
@ 2015-11-18 21:25 ` Michael S. Tsirkin
  2015-11-25  9:10   ` Stefan Hajnoczi
  0 siblings, 1 reply; 4+ messages in thread
From: Michael S. Tsirkin @ 2015-11-18 21:25 UTC (permalink / raw)
  To: Pavel Fedin; +Cc: 'Christian Borntraeger', qemu-devel

On Tue, Nov 17, 2015 at 10:17:37AM +0300, Pavel Fedin wrote:
> If you happen to have a stock kernel of old version, like 3.x,

On ARM

> and you
> attempt to enable vhost by setting vhost=on, qemu aborts with error:
> kvm_mem_ioeventfd_add: error adding ioeventfd: Function not implemented
> 
> This patch adds capability check, so that vhost gets disabled instead. A
> warning is displayed, explaining the reason:
> 
> 2015-11-13T08:43:51.146802Z qemu-system-aarch64: KVM does not support eventfd binding
> 2015-11-13T08:43:51.146915Z qemu-system-aarch64: unable to start vhost net: 38: falling back on userspace virtio
> 
> This problem can be observed with libvirt, which checks for /dev/vhost-net
> availability and just inserts "vhost=on" automatically in this case.
> 
> Signed-off-by: Pavel Fedin <p.fedin@samsung.com>
> ---
> v1 => v2:
> - Removed "MMIO" from warning message, because it applies not only to MMIO
> - Add note about warning to the commit message
> ---
>  hw/virtio/vhost.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
> index 1794f0d..50b8171 100644
> --- a/hw/virtio/vhost.c
> +++ b/hw/virtio/vhost.c
> @@ -24,6 +24,7 @@
>  #include "hw/virtio/virtio-bus.h"
>  #include "hw/virtio/virtio-access.h"
>  #include "migration/migration.h"
> +#include "sysemu/kvm.h"
>  
>  static struct vhost_log *vhost_log;
>  static struct vhost_log *vhost_log_shm;
> @@ -1083,6 +1084,11 @@ int vhost_dev_enable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev)
>          r = -ENOSYS;
>          goto fail;
>      }
> +    if (!kvm_eventfds_enabled()) {
> +        error_report("KVM does not support eventfd binding");
> +        r = -ENOSYS;
> +        goto fail;
> +    }
>  
>      for (i = 0; i < hdev->nvqs; ++i) {
>          r = k->set_host_notifier(qbus->parent, hdev->vq_index + i, true);

That's a wrong thing for vhost to do - we don't want it
poking at kvm because it does not work with either kvm or
eventfd.  It uses host notifiers, there should be an
API to check for that.

Or better yet, actually implement host notifiers
in userspace - should not be that hard to do, just
do write into eventfd.

> -- 
> 1.9.5.msysgit.0
> 

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

* Re: [Qemu-devel] [PATCH v2] vhost: Fix aborting if KVM does not support eventfds
  2015-11-18 21:25 ` Michael S. Tsirkin
@ 2015-11-25  9:10   ` Stefan Hajnoczi
  2015-11-25 10:13     ` Pavel Fedin
  0 siblings, 1 reply; 4+ messages in thread
From: Stefan Hajnoczi @ 2015-11-25  9:10 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: 'Christian Borntraeger', Pavel Fedin, qemu-devel

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

On Wed, Nov 18, 2015 at 11:25:32PM +0200, Michael S. Tsirkin wrote:
> On Tue, Nov 17, 2015 at 10:17:37AM +0300, Pavel Fedin wrote:
> > If you happen to have a stock kernel of old version, like 3.x,
> 
> On ARM
> 
> > and you
> > attempt to enable vhost by setting vhost=on, qemu aborts with error:
> > kvm_mem_ioeventfd_add: error adding ioeventfd: Function not implemented
> > 
> > This patch adds capability check, so that vhost gets disabled instead. A
> > warning is displayed, explaining the reason:
> > 
> > 2015-11-13T08:43:51.146802Z qemu-system-aarch64: KVM does not support eventfd binding
> > 2015-11-13T08:43:51.146915Z qemu-system-aarch64: unable to start vhost net: 38: falling back on userspace virtio
> > 
> > This problem can be observed with libvirt, which checks for /dev/vhost-net
> > availability and just inserts "vhost=on" automatically in this case.
> > 
> > Signed-off-by: Pavel Fedin <p.fedin@samsung.com>
> > ---
> > v1 => v2:
> > - Removed "MMIO" from warning message, because it applies not only to MMIO
> > - Add note about warning to the commit message
> > ---
> >  hw/virtio/vhost.c | 6 ++++++
> >  1 file changed, 6 insertions(+)
> > 
> > diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
> > index 1794f0d..50b8171 100644
> > --- a/hw/virtio/vhost.c
> > +++ b/hw/virtio/vhost.c
> > @@ -24,6 +24,7 @@
> >  #include "hw/virtio/virtio-bus.h"
> >  #include "hw/virtio/virtio-access.h"
> >  #include "migration/migration.h"
> > +#include "sysemu/kvm.h"
> >  
> >  static struct vhost_log *vhost_log;
> >  static struct vhost_log *vhost_log_shm;
> > @@ -1083,6 +1084,11 @@ int vhost_dev_enable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev)
> >          r = -ENOSYS;
> >          goto fail;
> >      }
> > +    if (!kvm_eventfds_enabled()) {
> > +        error_report("KVM does not support eventfd binding");
> > +        r = -ENOSYS;
> > +        goto fail;
> > +    }
> >  
> >      for (i = 0; i < hdev->nvqs; ++i) {
> >          r = k->set_host_notifier(qbus->parent, hdev->vq_index + i, true);
> 
> That's a wrong thing for vhost to do - we don't want it
> poking at kvm because it does not work with either kvm or
> eventfd.  It uses host notifiers, there should be an
> API to check for that.
> 
> Or better yet, actually implement host notifiers
> in userspace - should not be that hard to do, just
> do write into eventfd.

I sent this RFC patch a while back:
https://lists.nongnu.org/archive/html/qemu-devel/2015-07/msg04710.html

My intent was to write a qtest for a vhost device but I didn't complete
the work.  Anyway, this patch might be useful.

Stefan

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

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

* Re: [Qemu-devel] [PATCH v2] vhost: Fix aborting if KVM does not support eventfds
  2015-11-25  9:10   ` Stefan Hajnoczi
@ 2015-11-25 10:13     ` Pavel Fedin
  0 siblings, 0 replies; 4+ messages in thread
From: Pavel Fedin @ 2015-11-25 10:13 UTC (permalink / raw)
  To: 'Stefan Hajnoczi', 'Michael S. Tsirkin'
  Cc: 'Christian Borntraeger', qemu-devel

 Hello!

> > Or better yet, actually implement host notifiers
> > in userspace - should not be that hard to do, just
> > do write into eventfd.
> 
> I sent this RFC patch a while back:

 Thank you very much, but Paolo already pointed it out for me, and i have picked it up:
https://lists.gnu.org/archive/html/qemu-devel/2015-11/msg04626.html

Kind regards,
Pavel Fedin
Expert Engineer
Samsung Electronics Research center Russia

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

end of thread, other threads:[~2015-11-25 10:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-17  7:17 [Qemu-devel] [PATCH v2] vhost: Fix aborting if KVM does not support eventfds Pavel Fedin
2015-11-18 21:25 ` Michael S. Tsirkin
2015-11-25  9:10   ` Stefan Hajnoczi
2015-11-25 10:13     ` Pavel Fedin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).