diff mbox

[kvmtool,2/2] virtio: Clean up next_desc

Message ID 20180313113502.21624-2-jean-philippe.brucker@arm.com (mailing list archive)
State New, archived
Headers show

Commit Message

Jean-Philippe Brucker March 13, 2018, 11:35 a.m. UTC
The wmb() in next_desc seems out of place and the comments are
inaccurate. Remove the unnecessary barrier and clean up next_desc().

next_desc() is called by virt_queue__get_head_iov() when filling the iov
with desciptor addresses. It reads the descriptor's flag and next index.
The virt_queue__get_head_iov() only reads the direct and indirect
descriptors, and doesn't write any shared memory except from iov and
cursors that will be read by the caller.

As far as I can see, vhost (the kernel implementation of virtio device)
does well without any barrier here, so I think it might be safe to remove.

Signed-off-by: Jean-Philippe Brucker <jean-philippe.brucker@arm.com>
----
 virtio/core.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
diff mbox

Patch

diff --git a/virtio/core.c b/virtio/core.c
index ddce48bf6ab6..0e2646c61b91 100644
--- a/virtio/core.c
+++ b/virtio/core.c
@@ -75,8 +75,8 @@  static inline bool virt_desc__test_flag(struct virt_queue *vq,
 
 /*
  * Each buffer in the virtqueues is actually a chain of descriptors.  This
- * function returns the next descriptor in the chain, or vq->vring.num if we're
- * at the end.
+ * function returns the next descriptor in the chain, or max if we're at the
+ * end.
  */
 static unsigned next_desc(struct virt_queue *vq, struct vring_desc *desc,
 			  unsigned int i, unsigned int max)
@@ -87,12 +87,10 @@  static unsigned next_desc(struct virt_queue *vq, struct vring_desc *desc,
 	if (!virt_desc__test_flag(vq, &desc[i], VRING_DESC_F_NEXT))
 		return max;
 
-	/* Check they're not leading us off end of descriptors. */
 	next = virtio_guest_to_host_u16(vq, desc[i].next);
-	/* Make sure compiler knows to grab that: we don't want it changing! */
-	wmb();
 
-	return next;
+	/* Ensure they're not leading us off end of descriptors. */
+	return min(next, max);
 }
 
 u16 virt_queue__get_head_iov(struct virt_queue *vq, struct iovec iov[], u16 *out, u16 *in, u16 head, struct kvm *kvm)