Skip to contentSkip to conversation

vhost: Fix aborting if KVM does not support eventfds

PATCH In review Pavel Fedin 3 participants 4 messages Nov 17, 2015 – Nov 25, 2015

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 vhost: Fix aborting if KVM does not support eventfds

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.

---
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(+)
hw/virtio/vhost.c +6 -0
index 1794f0d..50b8171 100644
@@ -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);
Signature · 1 line
1.9.5.msysgit.0
#1 lore raw
Quoted 1 line · Pavel Fedin

If you happen to have a stock kernel of old version, like 3.x,

On ARM

Quoted 36 lines

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.

---
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(+)
hw/virtio/vhost.c +1 -0
index 1794f0d..50b8171 100644
@@ -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;

hw/virtio/vhost.c int vhost_dev_enable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev) · line 1094

Quoted 10 lines
hw/virtio/vhost.c +5 -0
         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.

Quoted 3 lines
Signature · 1 line
1.9.5.msysgit.0
#2 lore raw
Quoted 57 lines · Michael S. Tsirkin
Quoted 1 line · Pavel Fedin

If you happen to have a stock kernel of old version, like 3.x,

On ARM

Quoted 36 lines

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.

---
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(+)
hw/virtio/vhost.c +1 -0
index 1794f0d..50b8171 100644
@@ -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;

hw/virtio/vhost.c int vhost_dev_enable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev) · line 1094

Quoted 10 lines
hw/virtio/vhost.c +5 -0
         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.

Quoted 3 lines

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

#3 lore raw

Hello!

Quoted 5 lines
Quoted 3 lines

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