From: Igor Mammedov Date: Tue, 6 Oct 2015 08:37:29 +0000 (+0200) Subject: vhost: fail backend intialization early X-Git-Tag: qemu-xen-4.8.0-rc1~743^2~31 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=aebf81680bf49c5953d7ae9ebb7b98c0f4dad8f3;p=qemu-xen.git vhost: fail backend intialization early Don't initialize vhost backend if memslots number exceeds the supported limit. This prevents failures down the road when backend is actually started. [MST: rewrite commit log] Signed-off-by: Igor Mammedov Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index a3b4f9e8ea..f14a5c5133 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -933,6 +933,12 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaque, return -errno; } + if (used_memslots > hdev->vhost_ops->vhost_backend_memslots_limit(hdev)) { + fprintf(stderr, "vhost backend memory slots limit is less" + " than current number of present memory slots\n"); + close((uintptr_t)opaque); + return -1; + } QLIST_INSERT_HEAD(&vhost_devices, hdev, entry); r = hdev->vhost_ops->vhost_call(hdev, VHOST_SET_OWNER, NULL);