aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Philippe Brucker <jean-philippe.brucker@arm.com>2018-03-13 11:35:02 +0000
committerWill Deacon <will.deacon@arm.com>2018-03-19 11:20:11 +0000
commitbbea6c7ad7f6f2dbcebfe21d301f9b1cb9687538 (patch)
treecb8fe8a371db97aa8603af4c4dfd820493150db8
parent15c4e1ef906e2713a7d9f8a12e8c732d74e1479b (diff)
downloadkvmtool-bbea6c7ad7f6f2dbcebfe21d301f9b1cb9687538.tar.gz
virtio: Clean up next_desc
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> Signed-off-by: Will Deacon <will.deacon@arm.com>
-rw-r--r--virtio/core.c10
1 files changed, 4 insertions, 6 deletions
diff --git a/virtio/core.c b/virtio/core.c
index ddce48bf..0e2646c6 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)