Re: [PATCH v2 01/12] virtio_ring: remove the unused map sync API
From: Eugenio Perez Martin
Date: Wed Aug 26 2026 - 04:33:04 EST
On Tue, Aug 18, 2026 at 11:14 PM Alexander Graf <graf@xxxxxxxxxx> wrote:
>
> virtqueue_map_need_sync(), virtqueue_map_sync_single_range_for_cpu() and
> virtqueue_map_sync_single_range_for_device() are exported, but no driver
> in the tree calls them. They are the only path into the sync members of
> struct virtio_map_ops, so whoever implements that struct next has to
> decide what those members do with no caller to learn it from.
>
> Remove the three functions, their prototypes and their exports, and the
> DMA sync shims that the virtio userspace harness kept for them. With
> this, virtio_ring no longer exports a way to sync a mapping.
>
> Suggested-by: Michael S. Tsirkin <mst@xxxxxxxxxx>
Acked-by: Eugenio Pérez <eperezma@xxxxxxxxxx>
Thanks!
> Assisted-by: Kiro:claude-opus-5 checkpatch
> Signed-off-by: Alexander Graf <graf@xxxxxxxxxx>
> ---
> drivers/virtio/virtio_ring.c | 89 --------------------------------
> include/linux/virtio.h | 8 ---
> tools/virtio/linux/dma-mapping.h | 7 ---
> 3 files changed, 104 deletions(-)
>
> diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
> index b438dc2ce1b8..ea8e774b6d8e 100644
> --- a/drivers/virtio/virtio_ring.c
> +++ b/drivers/virtio/virtio_ring.c
> @@ -3890,94 +3890,5 @@ int virtqueue_map_mapping_error(const struct virtqueue *_vq, dma_addr_t addr)
> }
> EXPORT_SYMBOL_GPL(virtqueue_map_mapping_error);
>
> -/**
> - * virtqueue_map_need_sync - check a dma address needs sync
> - * @_vq: the struct virtqueue we're talking about.
> - * @addr: DMA address
> - *
> - * Check if the dma address mapped by the virtqueue_map_* APIs needs to be
> - * synchronized
> - *
> - * return bool
> - */
> -bool virtqueue_map_need_sync(const struct virtqueue *_vq, dma_addr_t addr)
> -{
> - const struct vring_virtqueue *vq = to_vvq(_vq);
> - struct virtio_device *vdev = _vq->vdev;
> -
> - if (!vq->use_map_api)
> - return false;
> -
> - if (vdev->map)
> - return vdev->map->need_sync(vq->map, addr);
> - else
> - return dma_need_sync(vring_dma_dev(vq), addr);
> -}
> -EXPORT_SYMBOL_GPL(virtqueue_map_need_sync);
> -
> -/**
> - * virtqueue_map_sync_single_range_for_cpu - map sync for cpu
> - * @_vq: the struct virtqueue we're talking about.
> - * @addr: DMA address
> - * @offset: DMA address offset
> - * @size: buf size for sync
> - * @dir: DMA direction
> - *
> - * Before calling this function, use virtqueue_map_need_sync() to confirm that
> - * the DMA address really needs to be synchronized
> - *
> - */
> -void virtqueue_map_sync_single_range_for_cpu(const struct virtqueue *_vq,
> - dma_addr_t addr,
> - unsigned long offset, size_t size,
> - enum dma_data_direction dir)
> -{
> - const struct vring_virtqueue *vq = to_vvq(_vq);
> - struct virtio_device *vdev = _vq->vdev;
> -
> - if (!vq->use_map_api)
> - return;
> -
> - if (vdev->map)
> - vdev->map->sync_single_for_cpu(vq->map,
> - addr + offset, size, dir);
> - else
> - dma_sync_single_range_for_cpu(vring_dma_dev(vq),
> - addr, offset, size, dir);
> -}
> -EXPORT_SYMBOL_GPL(virtqueue_map_sync_single_range_for_cpu);
> -
> -/**
> - * virtqueue_map_sync_single_range_for_device - map sync for device
> - * @_vq: the struct virtqueue we're talking about.
> - * @addr: DMA address
> - * @offset: DMA address offset
> - * @size: buf size for sync
> - * @dir: DMA direction
> - *
> - * Before calling this function, use virtqueue_map_need_sync() to confirm that
> - * the DMA address really needs to be synchronized
> - */
> -void virtqueue_map_sync_single_range_for_device(const struct virtqueue *_vq,
> - dma_addr_t addr,
> - unsigned long offset, size_t size,
> - enum dma_data_direction dir)
> -{
> - const struct vring_virtqueue *vq = to_vvq(_vq);
> - struct virtio_device *vdev = _vq->vdev;
> -
> - if (!vq->use_map_api)
> - return;
> -
> - if (vdev->map)
> - vdev->map->sync_single_for_device(vq->map,
> - addr + offset,
> - size, dir);
> - else
> - dma_sync_single_range_for_device(vring_dma_dev(vq), addr,
> - offset, size, dir);
> -}
> -EXPORT_SYMBOL_GPL(virtqueue_map_sync_single_range_for_device);
> -
> MODULE_DESCRIPTION("Virtio ring implementation");
> MODULE_LICENSE("GPL");
> diff --git a/include/linux/virtio.h b/include/linux/virtio.h
> index 93e573c56563..3122fc52a7c3 100644
> --- a/include/linux/virtio.h
> +++ b/include/linux/virtio.h
> @@ -312,14 +312,6 @@ void virtqueue_unmap_single_attrs(const struct virtqueue *_vq, dma_addr_t addr,
> unsigned long attrs);
> int virtqueue_map_mapping_error(const struct virtqueue *_vq, dma_addr_t addr);
>
> -bool virtqueue_map_need_sync(const struct virtqueue *_vq, dma_addr_t addr);
> -void virtqueue_map_sync_single_range_for_cpu(const struct virtqueue *_vq, dma_addr_t addr,
> - unsigned long offset, size_t size,
> - enum dma_data_direction dir);
> -void virtqueue_map_sync_single_range_for_device(const struct virtqueue *_vq, dma_addr_t addr,
> - unsigned long offset, size_t size,
> - enum dma_data_direction dir);
> -
> #ifdef CONFIG_VIRTIO_DEBUG
> void virtio_debug_device_init(struct virtio_device *dev);
> void virtio_debug_device_exit(struct virtio_device *dev);
> diff --git a/tools/virtio/linux/dma-mapping.h b/tools/virtio/linux/dma-mapping.h
> index b9fc5e8338e3..eae160ce7142 100644
> --- a/tools/virtio/linux/dma-mapping.h
> +++ b/tools/virtio/linux/dma-mapping.h
> @@ -36,16 +36,9 @@ enum dma_data_direction {
>
> #define sg_dma_address(sg) (0)
> #define sg_dma_len(sg) (0)
> -#define dma_need_sync(v, a) (0)
> #define dma_unmap_single_attrs(d, a, s, r, t) do { \
> (void)(d); (void)(a); (void)(s); (void)(r); (void)(t); \
> } while (0)
> -#define dma_sync_single_range_for_cpu(d, a, o, s, r) do { \
> - (void)(d); (void)(a); (void)(o); (void)(s); (void)(r); \
> -} while (0)
> -#define dma_sync_single_range_for_device(d, a, o, s, r) do { \
> - (void)(d); (void)(a); (void)(o); (void)(s); (void)(r); \
> -} while (0)
> #define dma_max_mapping_size(...) SIZE_MAX
>
> /*
>