[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220424024044.94749-9-xuanzhuo@linux.alibaba.com>
Date: Sun, 24 Apr 2022 10:40:36 +0800
From: Xuan Zhuo <xuanzhuo@...ux.alibaba.com>
To: linux-kernel@...r.kernel.org
Cc: "Michael S. Tsirkin" <mst@...hat.com>,
Jason Wang <jasowang@...hat.com>,
virtualization@...ts.linux-foundation.org
Subject: [RFC PATCH 08/16] virtio_ring: packed: extract next_idx()
Separate the logic of idx growth of packed into a function. It is
convenient to share in multiple locations. Subsequent patches will also
use this logic.
Signed-off-by: Xuan Zhuo <xuanzhuo@...ux.alibaba.com>
---
drivers/virtio/virtio_ring.c | 30 +++++++++++++++++-------------
1 file changed, 17 insertions(+), 13 deletions(-)
diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index fa4270e8c009..e3525d92f646 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -1330,6 +1330,18 @@ static int virtqueue_resize_split(struct virtqueue *_vq, u32 num,
* Packed ring specific functions - *_packed().
*/
+static u32 next_idx(struct vring_virtqueue *vq, u32 idx)
+{
+ if ((unlikely(++idx >= vq->packed.vring.num))) {
+ idx = 0;
+ vq->packed.avail_used_flags ^=
+ 1 << VRING_PACKED_DESC_F_AVAIL |
+ 1 << VRING_PACKED_DESC_F_USED;
+ }
+
+ return idx;
+}
+
static void vring_unmap_extra_packed(const struct vring_virtqueue *vq,
struct vring_desc_extra *extra)
{
@@ -1465,14 +1477,11 @@ static int virtqueue_add_indirect_packed(struct vring_virtqueue *vq,
vq->vq.num_free -= 1;
/* Update free pointer */
- n = head + 1;
- if (n >= vq->packed.vring.num) {
- n = 0;
+ n = next_idx(vq, head);
+
+ if (n < head)
vq->packed.avail_wrap_counter ^= 1;
- vq->packed.avail_used_flags ^=
- 1 << VRING_PACKED_DESC_F_AVAIL |
- 1 << VRING_PACKED_DESC_F_USED;
- }
+
vq->packed.next_avail_idx = n;
vq->free_head = vq->packed.desc_extra[id].next;
@@ -1592,12 +1601,7 @@ static inline int virtqueue_add_packed(struct virtqueue *_vq,
prev = curr;
curr = vq->packed.desc_extra[curr].next;
- if ((unlikely(++i >= vq->packed.vring.num))) {
- i = 0;
- vq->packed.avail_used_flags ^=
- 1 << VRING_PACKED_DESC_F_AVAIL |
- 1 << VRING_PACKED_DESC_F_USED;
- }
+ i = next_idx(vq, i);
}
}
--
2.31.0
Powered by blists - more mailing lists