virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
Cc: virtualization@lists.linux-foundation.org
Subject: Re: [PATCH 6/6] virtio: add api virtio_dma_map() for advance dma
Date: Mon, 10 Jan 2022 02:12:23 -0500	[thread overview]
Message-ID: <20220110020739-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <20220107063306.23240-7-xuanzhuo@linux.alibaba.com>

On Fri, Jan 07, 2022 at 02:33:06PM +0800, Xuan Zhuo wrote:
> Added virtio_dma_map() to map DMA addresses for virtual memory in
> advance. The purpose of adding this function is to check
> vring_use_dma_api() for virtio dma operation and get vdev->dev.parent as
> the parameter of dma_map_page().
> 
> Added virtio_dma_unmap() for unmap DMA address.
> 
> Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>


OK but where are the users for this new API?


> ---
>  drivers/virtio/virtio_ring.c | 47 ++++++++++++++++++++++++++++++++++++
>  include/linux/virtio.h       |  9 +++++++
>  2 files changed, 56 insertions(+)
> 
> diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
> index e165bc2e1344..f4a0fb85df27 100644
> --- a/drivers/virtio/virtio_ring.c
> +++ b/drivers/virtio/virtio_ring.c
> @@ -2472,4 +2472,51 @@ const struct vring *virtqueue_get_vring(struct virtqueue *vq)
>  }
>  EXPORT_SYMBOL_GPL(virtqueue_get_vring);
>  
> +/**
> + * virtio_dma_map - get the DMA addr of the memory for virtio device
> + * @vdev: virtio device
> + * @page: the page of the memory to DMA
> + * @offset: the offset of the memory inside page
> + * @length: memory length
> + * @dir: DMA direction
> + *
> + * Returns the DMA addr. Zero means error.

Should not drivers use a variant of dma_mapping_error to check?

> + */
> +dma_addr_t virtio_dma_map(struct virtio_device *vdev,
> +			  struct page *page, size_t offset,
> +			  unsigned int length,
> +			  enum dma_data_direction dir)
> +{
> +	dma_addr_t addr;
> +
> +	if (!vring_use_dma_api(vdev))
> +		return page_to_phys(page) + offset;
> +
> +	addr = dma_map_page(vdev->dev.parent, page, offset, length, dir);
> +
> +	if (dma_mapping_error(vdev->dev.parent, addr))
> +		return 0;
> +
> +	return addr;
> +}
> +EXPORT_SYMBOL_GPL(virtio_dma_map);


Yes it's 0, but you should really use DMA_MAPPING_ERROR.

> +
> +/**
> + * virtio_dma_unmap - unmap DMA addr
> + * @vdev: virtio device
> + * @dma: DMA address
> + * @length: memory length
> + * @dir: DMA direction
> + */
> +void virtio_dma_unmap(struct virtio_device *vdev,
> +		      dma_addr_t dma, unsigned int length,
> +		      enum dma_data_direction dir)
> +{
> +	if (!vring_use_dma_api(vdev))
> +		return;
> +
> +	dma_unmap_page(vdev->dev.parent, dma, length, dir);
> +}
> +EXPORT_SYMBOL_GPL(virtio_dma_unmap);
> +
>  MODULE_LICENSE("GPL");
> diff --git a/include/linux/virtio.h b/include/linux/virtio.h
> index 41edbc01ffa4..6e6c6e18ecf8 100644
> --- a/include/linux/virtio.h
> +++ b/include/linux/virtio.h
> @@ -9,6 +9,7 @@
>  #include <linux/device.h>
>  #include <linux/mod_devicetable.h>
>  #include <linux/gfp.h>
> +#include <linux/dma-mapping.h>
>  
>  /**
>   * virtqueue - a queue to register buffers for sending or receiving.
> @@ -195,4 +196,12 @@ void unregister_virtio_driver(struct virtio_driver *drv);
>  #define module_virtio_driver(__virtio_driver) \
>  	module_driver(__virtio_driver, register_virtio_driver, \
>  			unregister_virtio_driver)
> +
> +dma_addr_t virtio_dma_map(struct virtio_device *vdev,
> +			  struct page *page, size_t offset,
> +			  unsigned int length,
> +			  enum dma_data_direction dir);
> +void virtio_dma_unmap(struct virtio_device *vdev,
> +		      dma_addr_t dma, unsigned int length,
> +		      enum dma_data_direction dir);
>  #endif /* _LINUX_VIRTIO_H */
> -- 
> 2.31.0

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

  reply	other threads:[~2022-01-10  7:13 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
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 [this message]
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=20220110020739-mutt-send-email-mst@kernel.org \
    --to=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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).