[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220424024044.94749-11-xuanzhuo@linux.alibaba.com>
Date: Sun, 24 Apr 2022 10:40:38 +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 10/16] virtio_ring: packed: introduce vring_virtqueue_detach_packed()
The function vring_virtqueue_detach_packed() is introduced to detach the
vring of the current vq.
Add two new members. last_used_idx is used to record the position where
the current vring desc is used, which can be used to obtain buffers from
the vring in order. Another num_left records how many buffers there are,
which can be used to check the recovery of buffers completed.
Signed-off-by: Xuan Zhuo <xuanzhuo@...ux.alibaba.com>
---
drivers/virtio/virtio_ring.c | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index 436b18184dfe..219e008a4633 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -154,6 +154,10 @@ struct vring_virtqueue_packed {
dma_addr_t device_event_dma_addr;
size_t ring_size_in_bytes;
size_t event_size_in_bytes;
+
+ /* for vring detach */
+ u16 last_used_idx;
+ u32 num_left;
};
struct vring_virtqueue {
@@ -2090,6 +2094,25 @@ static int vring_alloc_state_extra_packed(struct vring_virtqueue_packed *vring)
return -ENOMEM;
}
+static void vring_virtqueue_detach_packed(struct vring_virtqueue *vq,
+ struct vring_virtqueue_packed *vring)
+{
+ vring->vring = vq->packed.vring;
+
+ vring->ring_dma_addr = vq->packed.ring_dma_addr;
+ vring->driver_event_dma_addr = vq->packed.driver_event_dma_addr;
+ vring->device_event_dma_addr = vq->packed.device_event_dma_addr;
+
+ vring->ring_size_in_bytes = vq->packed.ring_size_in_bytes;
+ vring->event_size_in_bytes = vq->packed.event_size_in_bytes;
+
+ vring->desc_state = vq->packed.desc_state;
+ vring->desc_extra = vq->packed.desc_extra;
+
+ vring->last_used_idx = vq->last_used_idx;
+ vring->num_left = vq->packed.vring.num - vq->vq.num_free;
+}
+
static void virtqueue_vring_attach_packed(struct vring_virtqueue *vq,
struct vring_virtqueue_packed *vring)
{
--
2.31.0
Powered by blists - more mailing lists