Blob Blame History Raw
From 91c827f000a94908b043b5de68eb0cd4fb6ff83d Mon Sep 17 00:00:00 2001
From: Michael S. Tsirkin <mst@redhat.com>
Date: Wed, 24 Feb 2010 21:09:58 +0200
Subject: [PATCH] vhost: fix used logging size math

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);
 	}
-- 
1.6.6.1