OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

virtio-dev message

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]


Subject: [PATCH 05/16] virtio_ring: store mask, rather than calculating it based on num.


From: Rusty Russell <rusty@rustcorp.com.au>

This matters when num needs endian conversion.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
---
 drivers/virtio/virtio_ring.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index 6fe2d08..45653c7 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -80,6 +80,9 @@ struct vring_virtqueue
 	/* Last used index we've seen. */
 	u16 last_used_idx;
 
+	/* Mask to apply to ring indices. */
+	u16 ring_mask;
+
 	/* How to notify other side. FIXME: commonalize hcalls! */
 	void (*notify)(struct virtqueue *vq);
 
@@ -226,7 +229,7 @@ static inline int virtqueue_add(struct virtqueue *_vq,
 			goto add_head;
 	}
 
-	BUG_ON(total_sg > vq->vring.num);
+	BUG_ON(total_sg >= vq->ring_mask);
 	BUG_ON(total_sg == 0);
 
 	if (vq->vq.num_free < total_sg) {
@@ -275,7 +278,7 @@ add_head:
 
 	/* Put entry in available array (but don't update avail->idx until they
 	 * do sync). */
-	avail = (vq->vring.avail->idx & (vq->vring.num-1));
+	avail = (vq->vring.avail->idx & vq->ring_mask);
 	vq->vring.avail->ring[avail] = head;
 
 	/* Descriptors and available array need to be set before we expose the
@@ -524,11 +527,11 @@ void *virtqueue_get_buf(struct virtqueue *_vq, unsigned int *len)
 	/* Only get used array entries after they have been exposed by host. */
 	virtio_rmb(vq->weak_barriers);
 
-	last_used = (vq->last_used_idx & (vq->vring.num - 1));
+	last_used = (vq->last_used_idx & vq->ring_mask);
 	i = vq->vring.used->ring[last_used].id;
 	*len = vq->vring.used->ring[last_used].len;
 
-	if (unlikely(i >= vq->vring.num)) {
+	if (unlikely(i > vq->ring_mask)) {
 		BAD_RING(vq, "id %u out of range\n", i);
 		return NULL;
 	}
@@ -698,7 +701,7 @@ void *virtqueue_detach_unused_buf(struct virtqueue *_vq)
 
 	START_USE(vq);
 
-	for (i = 0; i < vq->vring.num; i++) {
+	for (i = 0; i <= vq->ring_mask; i++) {
 		if (!vq->data[i])
 			continue;
 		/* detach_buf clears data, so grab it now. */
@@ -769,6 +772,7 @@ struct virtqueue *vring_new_virtqueue(unsigned int index,
 	vq->weak_barriers = weak_barriers;
 	vq->broken = false;
 	vq->last_used_idx = 0;
+	vq->ring_mask = num - 1;
 	vq->num_added = 0;
 	list_add_tail(&vq->vq.list, &vdev->vqs);
 #ifdef DEBUG
@@ -833,7 +837,7 @@ unsigned int virtqueue_get_vring_size(struct virtqueue *_vq)
 
 	struct vring_virtqueue *vq = to_vvq(_vq);
 
-	return vq->vring.num;
+	return (unsigned)vq->ring_mask + 1;
 }
 EXPORT_SYMBOL_GPL(virtqueue_get_vring_size);
 
-- 
1.8.1.2



[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]