[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v6 10/33] vhost: fix calling vhost_dev_cleanup() aft
From: |
marcandre . lureau |
Subject: |
[Qemu-devel] [PATCH v6 10/33] vhost: fix calling vhost_dev_cleanup() after vhost_dev_init() |
Date: |
Wed, 27 Jul 2016 01:15:04 +0400 |
From: Marc-André Lureau <address@hidden>
vhost_net_init() calls vhost_dev_init() and in case of failure, calls
vhost_dev_cleanup() directly. However, the structure is already
partially cleaned on error. Calling vhost_dev_cleanup() again will call
vhost_virtqueue_cleanup() on already clean queues, and causing potential
double-close. Instead, adjust dev->nvqs and simplify vhost_dev_init()
code to not call vhost_virtqueue_cleanup() but vhost_dev_cleanup()
instead.
Signed-off-by: Marc-André Lureau <address@hidden>
Signed-off-by: Ilya Maximets <address@hidden>
---
hw/virtio/vhost.c | 17 ++++++-----------
1 file changed, 6 insertions(+), 11 deletions(-)
diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
index 9400b47..e3091d1 100644
--- a/hw/virtio/vhost.c
+++ b/hw/virtio/vhost.c
@@ -1015,7 +1015,7 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaque,
VhostBackendType backend_type, uint32_t busyloop_timeout)
{
uint64_t features;
- int i, r;
+ int i, r, n_initialized_vqs = 0;
hdev->migration_blocker = NULL;
@@ -1044,10 +1044,10 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaque,
goto fail;
}
- for (i = 0; i < hdev->nvqs; ++i) {
+ for (i = 0; i < hdev->nvqs; ++i, ++n_initialized_vqs) {
r = vhost_virtqueue_init(hdev, hdev->vqs + i, hdev->vq_index + i);
if (r < 0) {
- goto fail_vq;
+ goto fail;
}
}
@@ -1104,19 +1104,14 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaque,
memory_listener_register(&hdev->memory_listener, &address_space_memory);
QLIST_INSERT_HEAD(&vhost_devices, hdev, entry);
return 0;
+
fail_busyloop:
while (--i >= 0) {
vhost_virtqueue_set_busyloop_timeout(hdev, hdev->vq_index + i, 0);
}
- i = hdev->nvqs;
-fail_vq:
- while (--i >= 0) {
- vhost_virtqueue_cleanup(hdev->vqs + i);
- }
fail:
- r = -errno;
- hdev->vhost_ops->vhost_backend_cleanup(hdev);
- QLIST_REMOVE(hdev, entry);
+ hdev->nvqs = n_initialized_vqs;
+ vhost_dev_cleanup(hdev);
return r;
}
--
2.9.0
- [Qemu-devel] [PATCH v6 00/33] vhost-user reconnect fixes, marcandre . lureau, 2016/07/26
- [Qemu-devel] [PATCH v6 01/33] misc: indentation, marcandre . lureau, 2016/07/26
- [Qemu-devel] [PATCH v6 02/33] vhost-user: minor simplification, marcandre . lureau, 2016/07/26
- [Qemu-devel] [PATCH v6 03/33] vhost-user: disconnect on HUP, marcandre . lureau, 2016/07/26
- [Qemu-devel] [PATCH v6 04/33] vhost: don't assume opaque is a fd, use backend cleanup, marcandre . lureau, 2016/07/26
- [Qemu-devel] [PATCH v6 05/33] vhost: make vhost_log_put() idempotent, marcandre . lureau, 2016/07/26
- [Qemu-devel] [PATCH v6 06/33] vhost: assert the log was cleaned up, marcandre . lureau, 2016/07/26
- [Qemu-devel] [PATCH v6 07/33] vhost: fix cleanup on not fully initialized device, marcandre . lureau, 2016/07/26
- [Qemu-devel] [PATCH v6 08/33] vhost: make vhost_dev_cleanup() idempotent, marcandre . lureau, 2016/07/26
- [Qemu-devel] [PATCH v6 09/33] vhost-net: always call vhost_dev_cleanup() on failure, marcandre . lureau, 2016/07/26
- [Qemu-devel] [PATCH v6 10/33] vhost: fix calling vhost_dev_cleanup() after vhost_dev_init(),
marcandre . lureau <=
- [Qemu-devel] [PATCH v6 11/33] vhost: do not assert() on vhost_ops failure, marcandre . lureau, 2016/07/26
- [Qemu-devel] [PATCH v6 12/33] vhost: add missing VHOST_OPS_DEBUG, marcandre . lureau, 2016/07/26
- [Qemu-devel] [PATCH v6 14/33] qemu-char: fix qemu_chr_fe_set_msgfds() crash when disconnected, marcandre . lureau, 2016/07/26
- [Qemu-devel] [PATCH v6 13/33] vhost: use error_report() instead of fprintf(stderr, ...), marcandre . lureau, 2016/07/26
- [Qemu-devel] [PATCH v6 15/33] vhost-user: call set_msgfds unconditionally, marcandre . lureau, 2016/07/26
- [Qemu-devel] [PATCH v6 16/33] vhost-user: check qemu_chr_fe_set_msgfds() return value, marcandre . lureau, 2016/07/26
- [Qemu-devel] [PATCH v6 17/33] vhost-user: check vhost_user_{read, write}() return value, marcandre . lureau, 2016/07/26
- [Qemu-devel] [PATCH v6 18/33] vhost-user: keep vhost_net after a disconnection, marcandre . lureau, 2016/07/26
- [Qemu-devel] [PATCH v6 19/33] vhost-user: add get_vhost_net() assertions, marcandre . lureau, 2016/07/26
- [Qemu-devel] [PATCH v6 20/33] Revert "vhost-net: do not crash if backend is not present", marcandre . lureau, 2016/07/26