Re: [PATCH v11 05/40] virtio_ring: split vring_virtqueue

Jason Wang
2022-06-30T06:40:26Z

On Wed, Jun 29, 2022 at 2:57 PM Xuan Zhuo <xuanzhuo@linux.alibaba.com> wrote:
>
> Separate the two inline structures(split and packed) from the structure
> vring_virtqueue.
>
> In this way, we can use these two structures later to pass parameters
> and retain temporary variables.
>
> Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>

Acked-by: Jason Wang <jasowang@redhat.com>

> ---
> drivers/virtio/virtio_ring.c | 116 ++++++++++++++++++-----------------
> 1 file changed, 60 insertions(+), 56 deletions(-)
>
> diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
> index bb4e8ae09c9b..2806e033a651 100644
> --- a/drivers/virtio/virtio_ring.c
> +++ b/drivers/virtio/virtio_ring.c
> @@ -85,6 +85,64 @@ struct vring_desc_extra {
> u16 next; /* The next desc state in a list. */
> };
>
> +struct vring_virtqueue_split {
> + /* Actual memory layout for this queue. */
> + struct vring vring;
> +
> + /* Last written value to avail->flags */
> + u16 avail_flags_shadow;
> +
> + /*
> + * Last written value to avail->idx in
> + * guest byte order.
> + */
> + u16 avail_idx_shadow;
> +
> + /* Per-descriptor state. */
> + struct vring_desc_state_split *desc_state;
> + struct vring_desc_extra *desc_extra;
> +
> + /* DMA address and size information */
> + dma_addr_t queue_dma_addr;
> + size_t queue_size_in_bytes;
> +};
> +
> +struct vring_virtqueue_packed {
> + /* Actual memory layout for this queue. */
> + struct {
> + unsigned int num;
> + struct vring_packed_desc *desc;
> + struct vring_packed_desc_event *driver;
> + struct vring_packed_desc_event *device;
> + } vring;
> +
> + /* Driver ring wrap counter. */
> + bool avail_wrap_counter;
> +
> + /* Avail used flags. */
> + u16 avail_used_flags;
> +
> + /* Index of the next avail descriptor. */
> + u16 next_avail_idx;
> +
> + /*
> + * Last written value to driver->flags in
> + * guest byte order.
> + */
> + u16 event_flags_shadow;
> +
> + /* Per-descriptor state. */
> + struct vring_desc_state_packed *desc_state;
> + struct vring_desc_extra *desc_extra;
> +
> + /* DMA address and size information */
> + dma_addr_t ring_dma_addr;
> + dma_addr_t driver_event_dma_addr;
> + dma_addr_t device_event_dma_addr;
> + size_t ring_size_in_bytes;
> + size_t event_size_in_bytes;
> +};
> +
> struct vring_virtqueue {
> struct virtqueue vq;
>
> @@ -124,64 +182,10 @@ struct vring_virtqueue {
>
> union {
> /* Available for split ring */
> - struct {
> - /* Actual memory layout for this queue. */
> - struct vring vring;
> -
> - /* Last written value to avail->flags */
> - u16 avail_flags_shadow;
> -
> - /*
> - * Last written value to avail->idx in
> - * guest byte order.
> - */
> - u16 avail_idx_shadow;
> -
> - /* Per-descriptor state. */
> - struct vring_desc_state_split *desc_state;
> - struct vring_desc_extra *desc_extra;
> -
> - /* DMA address and size information */
> - dma_addr_t queue_dma_addr;
> - size_t queue_size_in_bytes;
> - } split;
> + struct vring_virtqueue_split split;
>
> /* Available for packed ring */
> - struct {
> - /* Actual memory layout for this queue. */
> - struct {
> - unsigned int num;
> - struct vring_packed_desc *desc;
> - struct vring_packed_desc_event *driver;
> - struct vring_packed_desc_event *device;
> - } vring;
> -
> - /* Driver ring wrap counter. */
> - bool avail_wrap_counter;
> -
> - /* Avail used flags. */
> - u16 avail_used_flags;
> -
> - /* Index of the next avail descriptor. */
> - u16 next_avail_idx;
> -
> - /*
> - * Last written value to driver->flags in
> - * guest byte order.
> - */
> - u16 event_flags_shadow;
> -
> - /* Per-descriptor state. */
> - struct vring_desc_state_packed *desc_state;
> - struct vring_desc_extra *desc_extra;
> -
> - /* DMA address and size information */
> - dma_addr_t ring_dma_addr;
> - dma_addr_t driver_event_dma_addr;
> - dma_addr_t device_event_dma_addr;
> - size_t ring_size_in_bytes;
> - size_t event_size_in_bytes;
> - } packed;
> + struct vring_virtqueue_packed packed;
> };
>
> /* How to notify other side. FIXME: commonalize hcalls! */
> --
> 2.31.0
>