aboutsummaryrefslogtreecommitdiff
path: root/hw
diff options
context:
space:
mode:
authorStefano Garzarella <sgarzare@redhat.com>2020-10-29 15:48:49 +0100
committerMichael S. Tsirkin <mst@redhat.com>2020-10-30 04:29:13 -0400
commit384c2561bddfa00cd3eaf9edbc1af6c7c120511f (patch)
tree6fcafd9ac0c4202e1d5877072f1f8b6bdf631465 /hw
parent9aa47edd4ee69fa0628c5f9adb52d5050a5bce6a (diff)
downloadqemu-384c2561bddfa00cd3eaf9edbc1af6c7c120511f.zip
qemu-384c2561bddfa00cd3eaf9edbc1af6c7c120511f.tar.gz
qemu-384c2561bddfa00cd3eaf9edbc1af6c7c120511f.tar.bz2
vhost-vsock: set vhostfd to non-blocking mode
vhost IOTLB API uses read()/write() to exchange iotlb messages with the kernel module. The QEMU implementation expects a non-blocking fd, indeed commit c471ad0e9b ("vhost_net: device IOTLB support") set it for vhost-net. Without this patch, if we enable iommu for the vhost-vsock device, QEMU can hang when exchanging IOTLB messages. As commit 894022e616 ("net: check if the file descriptor is valid before using it") did for tap, let's use qemu_try_set_nonblock() when fd is provided by the user. Signed-off-by: Stefano Garzarella <sgarzare@redhat.com> Message-Id: <20201029144849.70958-1-sgarzare@redhat.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Diffstat (limited to 'hw')
-rw-r--r--hw/virtio/vhost-vsock.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/hw/virtio/vhost-vsock.c b/hw/virtio/vhost-vsock.c
index f9db4be..8ddfb9a 100644
--- a/hw/virtio/vhost-vsock.c
+++ b/hw/virtio/vhost-vsock.c
@@ -16,6 +16,7 @@
#include "qapi/error.h"
#include "hw/virtio/virtio-access.h"
#include "qemu/error-report.h"
+#include "qemu/sockets.h"
#include "hw/qdev-properties.h"
#include "hw/virtio/vhost-vsock.h"
#include "monitor/monitor.h"
@@ -148,6 +149,13 @@ static void vhost_vsock_device_realize(DeviceState *dev, Error **errp)
error_prepend(errp, "vhost-vsock: unable to parse vhostfd: ");
return;
}
+
+ ret = qemu_try_set_nonblock(vhostfd);
+ if (ret < 0) {
+ error_setg_errno(errp, -ret,
+ "vhost-vsock: unable to set non-blocking mode");
+ return;
+ }
} else {
vhostfd = open("/dev/vhost-vsock", O_RDWR);
if (vhostfd < 0) {
@@ -155,6 +163,8 @@ static void vhost_vsock_device_realize(DeviceState *dev, Error **errp)
"vhost-vsock: failed to open vhost device");
return;
}
+
+ qemu_set_nonblock(vhostfd);
}
vhost_vsock_common_realize(vdev, "vhost-vsock");