The following patches fix guest restart and migration issues with vhost, bringing it up to date with latest vhost bits.
After applying these patches, I get seamless live migration while running netperf TCP stream.
Please consider them for F-13.
Michael S. Tsirkin (7): msix: migration fix vhost: logging thinko fix vhost: move vhost_set_vq_addr vhost: used addr migration fix vhost: fix used logging size math vhost: logging mistake enable, not disable log vhost: fix log base
hw/msix.c | 16 +++++++++-- hw/vhost.c | 80 ++++++++++++++++++++++++++++++++++++++++------------------- 2 files changed, 67 insertions(+), 29 deletions(-)
Be careful to match mask/unmask callbacks from msix. Fixes crash during migration.
Signed-off-by: Michael S. Tsirkin mst@redhat.com --- hw/msix.c | 16 +++++++++++++--- 1 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/hw/msix.c b/hw/msix.c index 31a61c6..97ce301 100644 --- a/hw/msix.c +++ b/hw/msix.c @@ -614,9 +614,19 @@ int msix_set_mask_notifier(PCIDevice *dev, unsigned vector, void *opaque) if (vector >= dev->msix_entries_nr || !dev->msix_entry_used[vector]) return 0;
- if (dev->msix_mask_notifier) - r = dev->msix_mask_notifier(dev, vector, opaque, - msix_is_masked(dev, vector)); + if (dev->msix_mask_notifier && !msix_is_masked(dev, vector)) { + /* Mask previous notifier if any */ + if (dev->msix_mask_notifier_opaque[vector]) { + r = dev->msix_mask_notifier(dev, vector, + dev->msix_mask_notifier_opaque[vector], + 1); + assert(r >= 0); + } + /* Unmask new notifier, assumed to be masked at start */ + if (opaque) { + r = dev->msix_mask_notifier(dev, vector, opaque, 0); + } + } if (r >= 0) dev->msix_mask_notifier_opaque[vector] = opaque; return r;
Fix logging: set it to requested value.
Signed-off-by: Michael S. Tsirkin mst@redhat.com --- hw/vhost.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/hw/vhost.c b/hw/vhost.c index e5c1ead..3c54596 100644 --- a/hw/vhost.c +++ b/hw/vhost.c @@ -310,7 +310,7 @@ static int vhost_dev_set_log(struct vhost_dev *dev, bool enable_log) { uint64_t features = dev->acked_features; int r; - if (dev->log_enabled) { + if (enable_log) { features |= 0x1 << VHOST_F_LOG_ALL; } r = ioctl(dev->control, VHOST_SET_FEATURES, &features);
Move function in file: we'll add another call site in the following patch.
Signed-off-by: Michael S. Tsirkin mst@redhat.com --- hw/vhost.c | 38 +++++++++++++++++++------------------- 1 files changed, 19 insertions(+), 19 deletions(-)
diff --git a/hw/vhost.c b/hw/vhost.c index 3c54596..54386e1 100644 --- a/hw/vhost.c +++ b/hw/vhost.c @@ -306,6 +306,25 @@ static void vhost_client_set_memory(CPUPhysMemoryClient *client, } }
+static int vhost_virtqueue_set_addr(struct vhost_dev *dev, + struct vhost_virtqueue *vq, + unsigned idx, bool enable_log) +{ + struct vhost_vring_addr addr = { + .index = idx, + .desc_user_addr = (u_int64_t)(unsigned long)vq->desc, + .avail_user_addr = (u_int64_t)(unsigned long)vq->avail, + .used_user_addr = (u_int64_t)(unsigned long)vq->used, + .log_guest_addr = vq->used_phys, + .flags = enable_log ? (1 << VHOST_VRING_F_LOG) : 0, + }; + int r = ioctl(dev->control, VHOST_SET_VRING_ADDR, &addr); + if (r < 0) { + return -errno; + } + return 0; +} + static int vhost_dev_set_log(struct vhost_dev *dev, bool enable_log) { uint64_t features = dev->acked_features; @@ -350,25 +369,6 @@ static int vhost_client_migration_log(struct CPUPhysMemoryClient *client, return 0; }
-static int vhost_virtqueue_set_addr(struct vhost_dev *dev, - struct vhost_virtqueue *vq, - unsigned idx, bool enable_log) -{ - struct vhost_vring_addr addr = { - .index = idx, - .desc_user_addr = (u_int64_t)(unsigned long)vq->desc, - .avail_user_addr = (u_int64_t)(unsigned long)vq->avail, - .used_user_addr = (u_int64_t)(unsigned long)vq->used, - .log_guest_addr = vq->used_phys, - .flags = enable_log ? (1 << VHOST_VRING_F_LOG) : 0, - }; - int r = ioctl(dev->control, VHOST_SET_VRING_ADDR, &addr); - if (r < 0) { - return -errno; - } - return 0; -} - static int vhost_virtqueue_init(struct vhost_dev *dev, struct VirtIODevice *vdev, struct vhost_virtqueue *vq,
Enable used buffer logging when migration starts. Fixed 'id XX is not a head' message after migration.
Signed-off-by: Michael S. Tsirkin mst@redhat.com --- hw/vhost.c | 29 +++++++++++++++++++++++++++-- 1 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/hw/vhost.c b/hw/vhost.c index 54386e1..48034ba 100644 --- a/hw/vhost.c +++ b/hw/vhost.c @@ -325,7 +325,7 @@ static int vhost_virtqueue_set_addr(struct vhost_dev *dev, return 0; }
-static int vhost_dev_set_log(struct vhost_dev *dev, bool enable_log) +static int vhost_dev_set_features(struct vhost_dev *dev, bool enable_log) { uint64_t features = dev->acked_features; int r; @@ -336,6 +336,31 @@ static int vhost_dev_set_log(struct vhost_dev *dev, bool enable_log) return r < 0 ? -errno : 0; }
+static int vhost_dev_set_log(struct vhost_dev *dev, bool enable_log) +{ + int r, t, i; + r = vhost_dev_set_features(dev, enable_log); + if (r < 0) + goto err_features; + for (i = 0; i < dev->nvqs; ++i) { + r = vhost_virtqueue_set_addr(dev, dev->vqs + i, i, + enable_log); + if (r < 0) + goto err_vq; + } + return 0; +err_vq: + for (; i >= 0; --i) { + t = vhost_virtqueue_set_addr(dev, dev->vqs + i, i, + dev->log_enabled); + assert(t >= 0); + } + t = vhost_dev_set_features(dev, dev->log_enabled); + assert(t >= 0); +err_features: + return r; +} + static int vhost_client_migration_log(struct CPUPhysMemoryClient *client, int enable) { @@ -544,7 +569,7 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev) { int i, r;
- r = vhost_dev_set_log(hdev, hdev->log_enabled); + r = vhost_dev_set_features(hdev, hdev->log_enabled); if (r < 0) goto fail; r = ioctl(hdev->control, VHOST_SET_MEM_TABLE, hdev->mem);
Must include used header as well, not only ring
Signed-off-by: Michael S. Tsirkin mst@redhat.com --- hw/vhost.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/hw/vhost.c b/hw/vhost.c index 48034ba..7391bd1 100644 --- a/hw/vhost.c +++ b/hw/vhost.c @@ -62,7 +62,8 @@ static int vhost_client_sync_dirty_bitmap(struct CPUPhysMemoryClient *client, } for (i = 0; i < dev->nvqs; ++i) { struct vhost_virtqueue *vq = dev->vqs + i; - unsigned size = sizeof(struct vring_used_elem) * vq->num; + unsigned size = offsetof(struct vring_used, ring) + + sizeof(struct vring_used_elem) * vq->num; vhost_dev_sync_region(dev, start_addr, end_addr, vq->used_phys, range_get_last(vq->used_phys, size)); } @@ -230,6 +231,7 @@ static uint64_t vhost_get_log_size(struct vhost_dev *dev) for (i = 0; i < dev->nvqs; ++i) { struct vhost_virtqueue *vq = dev->vqs + i; uint64_t last = vq->used_phys + + offsetof(struct vring_used, ring) + sizeof(struct vring_used_elem) * vq->num - 1; log_size = MAX(log_size, last / VHOST_LOG_CHUNK + 1); }
Correctly pass log enable value from memory client to vhost device.
--- hw/vhost.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/hw/vhost.c b/hw/vhost.c index 7391bd1..019afc2 100644 --- a/hw/vhost.c +++ b/hw/vhost.c @@ -387,7 +387,7 @@ static int vhost_client_migration_log(struct CPUPhysMemoryClient *client, dev->log_size = 0; } else { vhost_dev_log_resize(dev, vhost_get_log_size(dev)); - r = vhost_dev_set_log(dev, false); + r = vhost_dev_set_log(dev, true); if (r < 0) { return r; }
LOG_BASE ioctl gets a pointer to a 64 bit value, not a pointer cast to 64 bit value.
Signed-off-by: Michael S. Tsirkin mst@redhat.com --- hw/vhost.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/hw/vhost.c b/hw/vhost.c index 019afc2..b63eafa 100644 --- a/hw/vhost.c +++ b/hw/vhost.c @@ -241,14 +241,15 @@ static uint64_t vhost_get_log_size(struct vhost_dev *dev) static inline void vhost_dev_log_resize(struct vhost_dev* dev, uint64_t size) { vhost_log_chunk_t *log; + uint64_t log_base; int r; if (size) { log = qemu_mallocz(size * sizeof *log); } else { log = NULL; } - r = ioctl(dev->control, VHOST_SET_LOG_BASE, - (uint64_t)(unsigned long)log); + log_base = (uint64_t)(unsigned long)log; + r = ioctl(dev->control, VHOST_SET_LOG_BASE, &log_base); assert(r >= 0); vhost_client_sync_dirty_bitmap(&dev->client, 0, (target_phys_addr_t)~0x0ull);
On Wed, Feb 24, 2010 at 09:09:40PM +0200, Michael S. Tsirkin wrote:
The following patches fix guest restart and migration issues with vhost, bringing it up to date with latest vhost bits.
After applying these patches, I get seamless live migration while running netperf TCP stream.
Please consider them for F-13.
Thanks, applied to F-13 git, and they will be in the next F-13 qemu package.
Justin