diff mbox series

[vhost,v6,08/10] virtio_ring: export premapped to driver by struct virtqueue

Message ID 20240327111430.108787-9-xuanzhuo@linux.alibaba.com (mailing list archive)
State Not Applicable
Headers show
Series virtio: drivers maintain dma info for premapped vq | expand

Checks

Context Check Description
netdev/tree_selection success Guessing tree name failed - patch did not apply

Commit Message

Xuan Zhuo March 27, 2024, 11:14 a.m. UTC
Export the premapped to drivers, then drivers can check
the vq premapped mode after the find_vqs().
Because the find_vqs() just try to enable the vq premapped mode,
the driver must check that after find_vqs().

Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
---
 drivers/virtio/virtio_ring.c | 13 +++++--------
 include/linux/virtio.h       |  1 +
 2 files changed, 6 insertions(+), 8 deletions(-)

Comments

Jason Wang March 28, 2024, 7:58 a.m. UTC | #1
On Wed, Mar 27, 2024 at 7:14 PM Xuan Zhuo <xuanzhuo@linux.alibaba.com> wrote:
>
> Export the premapped to drivers, then drivers can check
> the vq premapped mode after the find_vqs().
> Because the find_vqs() just try to enable the vq premapped mode,
> the driver must check that after find_vqs().

What's the reason for this? For example, we never export use_dma_api.

Thanks

>
> Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
> ---
>  drivers/virtio/virtio_ring.c | 13 +++++--------
>  include/linux/virtio.h       |  1 +
>  2 files changed, 6 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
> index bbdeab3a9648..543204e26c5a 100644
> --- a/drivers/virtio/virtio_ring.c
> +++ b/drivers/virtio/virtio_ring.c
> @@ -177,9 +177,6 @@ struct vring_virtqueue {
>         /* Host publishes avail event idx */
>         bool event;
>
> -       /* Do DMA mapping by driver */
> -       bool premapped;
> -
>         /* Head of free buffer list. */
>         unsigned int free_head;
>         /* Number we've added since last sync. */
> @@ -297,7 +294,7 @@ static bool vring_use_dma_api(const struct virtio_device *vdev)
>
>  static bool vring_need_unmap_buffer(const struct vring_virtqueue *vring)
>  {
> -       return vring->use_dma_api && !vring->premapped;
> +       return vring->use_dma_api && !vring->vq.premapped;
>  }
>
>  size_t virtio_max_dma_size(const struct virtio_device *vdev)
> @@ -369,7 +366,7 @@ static struct device *vring_dma_dev(const struct vring_virtqueue *vq)
>  static int vring_map_one_sg(const struct vring_virtqueue *vq, struct scatterlist *sg,
>                             enum dma_data_direction direction, dma_addr_t *addr)
>  {
> -       if (vq->premapped) {
> +       if (vq->vq.premapped) {
>                 *addr = sg_dma_address(sg);
>                 return 0;
>         }
> @@ -2148,7 +2145,7 @@ static struct virtqueue *vring_create_virtqueue_packed(struct virtio_device *vde
>         vq->packed_ring = true;
>         vq->dma_dev = dma_dev;
>         vq->use_dma_api = vring_use_dma_api(vdev);
> -       vq->premapped = vq->use_dma_api && cfg_vq_get(cfg, vq, premapped);
> +       vq->vq.premapped = vq->use_dma_api && cfg_vq_get(cfg, vq, premapped);
>
>         vq->indirect = virtio_has_feature(vdev, VIRTIO_RING_F_INDIRECT_DESC) &&
>                 !cfg_vq_get(cfg, vq, ctx);
> @@ -2696,7 +2693,7 @@ static struct virtqueue *__vring_new_virtqueue(struct virtio_device *vdev,
>  #endif
>         vq->dma_dev = tp_cfg->dma_dev;
>         vq->use_dma_api = vring_use_dma_api(vdev);
> -       vq->premapped = vq->use_dma_api && cfg_vq_get(cfg, vq, premapped);
> +       vq->vq.premapped = vq->use_dma_api && cfg_vq_get(cfg, vq, premapped);
>
>         vq->indirect = virtio_has_feature(vdev, VIRTIO_RING_F_INDIRECT_DESC) &&
>                 !cfg_vq_get(cfg, vq, ctx);
> @@ -2832,7 +2829,7 @@ int virtqueue_set_dma_premapped(struct virtqueue *_vq)
>                 return -EINVAL;
>         }
>
> -       vq->premapped = true;
> +       vq->vq.premapped = true;
>
>         if (vq->packed_ring) {
>                 kfree(vq->packed.desc_dma);
> diff --git a/include/linux/virtio.h b/include/linux/virtio.h
> index b0201747a263..407277d5a16b 100644
> --- a/include/linux/virtio.h
> +++ b/include/linux/virtio.h
> @@ -36,6 +36,7 @@ struct virtqueue {
>         unsigned int num_free;
>         unsigned int num_max;
>         bool reset;
> +       bool premapped;
>         void *priv;
>  };
>
> --
> 2.32.0.3.g01195cf9f
>
diff mbox series

Patch

diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index bbdeab3a9648..543204e26c5a 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -177,9 +177,6 @@  struct vring_virtqueue {
 	/* Host publishes avail event idx */
 	bool event;
 
-	/* Do DMA mapping by driver */
-	bool premapped;
-
 	/* Head of free buffer list. */
 	unsigned int free_head;
 	/* Number we've added since last sync. */
@@ -297,7 +294,7 @@  static bool vring_use_dma_api(const struct virtio_device *vdev)
 
 static bool vring_need_unmap_buffer(const struct vring_virtqueue *vring)
 {
-	return vring->use_dma_api && !vring->premapped;
+	return vring->use_dma_api && !vring->vq.premapped;
 }
 
 size_t virtio_max_dma_size(const struct virtio_device *vdev)
@@ -369,7 +366,7 @@  static struct device *vring_dma_dev(const struct vring_virtqueue *vq)
 static int vring_map_one_sg(const struct vring_virtqueue *vq, struct scatterlist *sg,
 			    enum dma_data_direction direction, dma_addr_t *addr)
 {
-	if (vq->premapped) {
+	if (vq->vq.premapped) {
 		*addr = sg_dma_address(sg);
 		return 0;
 	}
@@ -2148,7 +2145,7 @@  static struct virtqueue *vring_create_virtqueue_packed(struct virtio_device *vde
 	vq->packed_ring = true;
 	vq->dma_dev = dma_dev;
 	vq->use_dma_api = vring_use_dma_api(vdev);
-	vq->premapped = vq->use_dma_api && cfg_vq_get(cfg, vq, premapped);
+	vq->vq.premapped = vq->use_dma_api && cfg_vq_get(cfg, vq, premapped);
 
 	vq->indirect = virtio_has_feature(vdev, VIRTIO_RING_F_INDIRECT_DESC) &&
 		!cfg_vq_get(cfg, vq, ctx);
@@ -2696,7 +2693,7 @@  static struct virtqueue *__vring_new_virtqueue(struct virtio_device *vdev,
 #endif
 	vq->dma_dev = tp_cfg->dma_dev;
 	vq->use_dma_api = vring_use_dma_api(vdev);
-	vq->premapped = vq->use_dma_api && cfg_vq_get(cfg, vq, premapped);
+	vq->vq.premapped = vq->use_dma_api && cfg_vq_get(cfg, vq, premapped);
 
 	vq->indirect = virtio_has_feature(vdev, VIRTIO_RING_F_INDIRECT_DESC) &&
 		!cfg_vq_get(cfg, vq, ctx);
@@ -2832,7 +2829,7 @@  int virtqueue_set_dma_premapped(struct virtqueue *_vq)
 		return -EINVAL;
 	}
 
-	vq->premapped = true;
+	vq->vq.premapped = true;
 
 	if (vq->packed_ring) {
 		kfree(vq->packed.desc_dma);
diff --git a/include/linux/virtio.h b/include/linux/virtio.h
index b0201747a263..407277d5a16b 100644
--- a/include/linux/virtio.h
+++ b/include/linux/virtio.h
@@ -36,6 +36,7 @@  struct virtqueue {
 	unsigned int num_free;
 	unsigned int num_max;
 	bool reset;
+	bool premapped;
 	void *priv;
 };