All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jason Wang <jasowang@redhat.com>
To: Xuan Zhuo <xuanzhuo@linux.alibaba.com>,
	virtualization@lists.linux-foundation.org
Cc: "Michael S. Tsirkin" <mst@redhat.com>
Subject: Re: [PATCH 4/6] virtio: split: virtqueue_add_split() support dma address
Date: Mon, 10 Jan 2022 14:45:42 +0800	[thread overview]
Message-ID: <768a05cc-16f7-b374-04a6-48fecfe1768b@redhat.com> (raw)
In-Reply-To: <20220107063306.23240-5-xuanzhuo@linux.alibaba.com>


在 2022/1/7 下午2:33, Xuan Zhuo 写道:
> virtqueue_add_split() only supports virtual addresses, dma is completed
> in virtqueue_add_split().
>
> In some scenarios (such as the AF_XDP scenario), the memory is allocated
> and DMA is completed in advance, so it is necessary for us to support
> passing the DMA address to virtqueue_add_split().
>
> This patch stipulates that if sg->dma_address is not NULL, use this
> address as the DMA address. And record this information in extra->flags,
> which can be skipped when executing dma unmap.
>
>      extra->flags |= VRING_DESC_F_PREDMA;


I think we need another name other than the VRING_DESC_F prefix since 
it's for the flag defined in the spec. May VIRTIO_DESC_F_PREDMA.

Thanks


>
> This relies on the previous patch, in the indirect scenario, for each
> desc allocated, an extra is allocated at the same time.
>
> Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
> ---
>   drivers/virtio/virtio_ring.c | 28 ++++++++++++++++++++++++----
>   1 file changed, 24 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
> index 7420741cb750..add8430d9678 100644
> --- a/drivers/virtio/virtio_ring.c
> +++ b/drivers/virtio/virtio_ring.c
> @@ -66,6 +66,9 @@
>   #define LAST_ADD_TIME_INVALID(vq)
>   #endif
>   
> +/* This means the buffer dma is pre-alloc. Just used by vring_desc_extra */
> +#define VRING_DESC_F_PREDMA	(1 << 15)
> +
>   struct vring_desc_extra {
>   	dma_addr_t addr;		/* Descriptor DMA addr. */
>   	u32 len;			/* Descriptor length. */
> @@ -336,11 +339,19 @@ static inline struct device *vring_dma_dev(const struct vring_virtqueue *vq)
>   	return vq->vq.vdev->dev.parent;
>   }
>   
> +static inline bool sg_is_predma(struct scatterlist *sg)
> +{
> +	return !!sg->dma_address;
> +}
> +
>   /* Map one sg entry. */
>   static dma_addr_t vring_map_one_sg(const struct vring_virtqueue *vq,
>   				   struct scatterlist *sg,
>   				   enum dma_data_direction direction)
>   {
> +	if (sg_is_predma(sg))
> +		return sg_dma_address(sg);
> +
>   	if (!vq->use_dma_api)
>   		return (dma_addr_t)sg_phys(sg);
>   
> @@ -396,6 +407,9 @@ static unsigned int vring_unmap_one_split(const struct vring_virtqueue *vq,
>   				 (flags & VRING_DESC_F_WRITE) ?
>   				 DMA_FROM_DEVICE : DMA_TO_DEVICE);
>   	} else {
> +		if (flags & VRING_DESC_F_PREDMA)
> +			goto out;
> +
>   		dma_unmap_page(vring_dma_dev(vq),
>   			       extra->addr,
>   			       extra->len,
> @@ -441,7 +455,8 @@ static inline unsigned int virtqueue_add_desc_split(struct virtqueue *vq,
>   						    unsigned int i,
>   						    dma_addr_t addr,
>   						    unsigned int len,
> -						    u16 flags)
> +						    u16 flags,
> +						    bool predma)
>   {
>   	struct vring_virtqueue *vring = to_vvq(vq);
>   	struct vring_desc_extra *extra;
> @@ -468,6 +483,9 @@ static inline unsigned int virtqueue_add_desc_split(struct virtqueue *vq,
>   	extra->len = len;
>   	extra->flags = flags;
>   
> +	if (predma)
> +		extra->flags |= VRING_DESC_F_PREDMA;
> +
>   	return next;
>   }
>   
> @@ -547,7 +565,8 @@ static inline int virtqueue_add_split(struct virtqueue *_vq,
>   			 * table since it use stream DMA mapping.
>   			 */
>   			i = virtqueue_add_desc_split(_vq, in, i, addr, sg->length,
> -						     VRING_DESC_F_NEXT);
> +						     VRING_DESC_F_NEXT,
> +						     sg_is_predma(sg));
>   		}
>   	}
>   	for (; n < (out_sgs + in_sgs); n++) {
> @@ -563,7 +582,8 @@ static inline int virtqueue_add_split(struct virtqueue *_vq,
>   			i = virtqueue_add_desc_split(_vq, in, i, addr,
>   						     sg->length,
>   						     VRING_DESC_F_NEXT |
> -						     VRING_DESC_F_WRITE);
> +						     VRING_DESC_F_WRITE,
> +						     sg_is_predma(sg));
>   		}
>   	}
>   	/* Last one doesn't continue. */
> @@ -582,7 +602,7 @@ static inline int virtqueue_add_split(struct virtqueue *_vq,
>   
>   		virtqueue_add_desc_split(_vq, NULL, head, addr,
>   					 total_sg * sizeof(struct vring_desc),
> -					 VRING_DESC_F_INDIRECT);
> +					 VRING_DESC_F_INDIRECT, false);
>   	}
>   
>   	/* We're using some buffers from the free list. */

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

  reply	other threads:[~2022-01-10  6:45 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-07  6:33 [PATCH 0/6] virtio: support advance DMA Xuan Zhuo
2022-01-07  6:33 ` [PATCH 1/6] virtio: rename vring_unmap_state_packed() to vring_unmap_extra_packed() Xuan Zhuo
2022-01-10  6:19   ` Jason Wang
2022-01-07  6:33 ` [PATCH 2/6] virtio: split: alloc indirect desc with extra Xuan Zhuo
2022-01-10  6:43   ` Jason Wang
2022-01-10  7:19     ` Xuan Zhuo
2022-01-10  7:41       ` Jason Wang
2022-01-10  7:52         ` Xuan Zhuo
2022-01-10  8:54           ` Jason Wang
2022-01-10  9:23             ` Xuan Zhuo
2022-01-10  9:49               ` Michael S. Tsirkin
2022-01-10  9:58                 ` Xuan Zhuo
2022-01-10 10:06                   ` Michael S. Tsirkin
2022-01-11  2:44               ` Jason Wang
2022-01-11  5:57                 ` Xuan Zhuo
2022-01-07  6:33 ` [PATCH 3/6] virtio: packed: " Xuan Zhuo
2022-01-07  6:33 ` [PATCH 4/6] virtio: split: virtqueue_add_split() support dma address Xuan Zhuo
2022-01-10  6:45   ` Jason Wang [this message]
2022-01-10  7:24     ` Xuan Zhuo
2022-01-07  6:33 ` [PATCH 5/6] virtio: packed: virtqueue_add_packed() " Xuan Zhuo
2022-01-07  6:33 ` [PATCH 6/6] virtio: add api virtio_dma_map() for advance dma Xuan Zhuo
2022-01-10  7:12   ` Michael S. Tsirkin
2022-01-10  7:24     ` Xuan Zhuo
2022-01-10  9:59 ` [PATCH 0/6] virtio: support advance DMA Michael S. Tsirkin
2022-01-11  2:54   ` Jason Wang
2022-01-11  6:17     ` Xuan Zhuo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=768a05cc-16f7-b374-04a6-48fecfe1768b@redhat.com \
    --to=jasowang@redhat.com \
    --cc=mst@redhat.com \
    --cc=virtualization@lists.linux-foundation.org \
    --cc=xuanzhuo@linux.alibaba.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.