[PATCH 1/3] vhost: logging math fix

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Michael S. Tsirkin
Date: Tuesday, February 23, 2010 - 9:57 am

vhost was dong some complex math to get
offset to log at, and got it wrong by a couple of bytes,
while in fact it's simple: get address where we write,
subtract start of buffer, add log base.

Do it this way.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 drivers/vhost/vhost.c |   10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
index 6eb1525..c767279 100644
--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -1004,10 +1004,12 @@ int vhost_add_used(struct vhost_virtqueue *vq, unsigned int head, int len)
 	if (unlikely(vq->log_used)) {
 		/* Make sure data is seen before log. */
 		smp_wmb();
-		log_write(vq->log_base, vq->log_addr + sizeof *vq->used->ring *
-			  (vq->last_used_idx % vq->num),
-			  sizeof *vq->used->ring);
-		log_write(vq->log_base, vq->log_addr, sizeof *vq->used->ring);
+		log_write(vq->log_base,
+			  vq->log_addr + ((void *)used - (void *)vq->used),
+			  sizeof *used);
+		log_write(vq->log_base,
+			  vq->log_addr + offsetof(struct vring_used, idx),
+			  sizeof vq->used->idx);
 		if (vq->log_ctx)
 			eventfd_signal(vq->log_ctx, 1);
 	}
-- 
1.7.0.18.g0d53a5

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 0/3] vhost: logging fixes, Michael S. Tsirkin, (Tue Feb 23, 9:57 am)
[PATCH 1/3] vhost: logging math fix, Michael S. Tsirkin, (Tue Feb 23, 9:57 am)
[PATCH 2/3] vhost: initialize log eventfd context pointer, Michael S. Tsirkin, (Tue Feb 23, 9:57 am)
[PATCH 3/3] vhost: fix get_user_pages_fast error handling, Michael S. Tsirkin, (Tue Feb 23, 9:57 am)
Re: [PATCH 3/3] vhost: fix get_user_pages_fast error handling, Michael S. Tsirkin, (Tue Feb 23, 10:32 am)
Re: [PATCH 3/3] vhost: fix get_user_pages_fast error handling, Michael S. Tsirkin, (Tue Feb 23, 10:39 am)
Re: [PATCH 1/3] vhost: logging math fix, Juan Quintela, (Tue Feb 23, 12:26 pm)
Re: [PATCH 3/3] vhost: fix get_user_pages_fast error handling, Michael S. Tsirkin, (Tue Feb 23, 10:37 pm)
Re: [PATCH 3/3] vhost: fix get_user_pages_fast error handling, Michael S. Tsirkin, (Wed Feb 24, 12:34 am)