[PATCH V6 0/9] Refine virtio mapping API

Jason Wang posted 9 patches 1 month, 1 week ago
drivers/net/virtio_net.c                 |  28 +-
drivers/vdpa/Kconfig                     |   8 +-
drivers/vdpa/alibaba/eni_vdpa.c          |   5 +-
drivers/vdpa/ifcvf/ifcvf_main.c          |   5 +-
drivers/vdpa/mlx5/core/mr.c              |   4 +-
drivers/vdpa/mlx5/net/mlx5_vnet.c        |  15 +-
drivers/vdpa/octeon_ep/octep_vdpa_main.c |   6 +-
drivers/vdpa/pds/vdpa_dev.c              |   5 +-
drivers/vdpa/solidrun/snet_main.c        |   8 +-
drivers/vdpa/vdpa.c                      |   5 +-
drivers/vdpa/vdpa_sim/vdpa_sim.c         |   4 +-
drivers/vdpa/vdpa_user/iova_domain.c     |   2 +-
drivers/vdpa/vdpa_user/iova_domain.h     |   2 +-
drivers/vdpa/vdpa_user/vduse_dev.c       |  79 ++--
drivers/vdpa/virtio_pci/vp_vdpa.c        |   5 +-
drivers/vhost/vdpa.c                     |   6 +-
drivers/virtio/virtio_ring.c             | 459 ++++++++++++++---------
drivers/virtio/virtio_vdpa.c             |  20 +-
include/linux/vdpa.h                     |  25 +-
include/linux/virtio.h                   |  46 ++-
include/linux/virtio_config.h            |  72 ++++
include/linux/virtio_ring.h              |   7 +-
22 files changed, 531 insertions(+), 285 deletions(-)
[PATCH V6 0/9] Refine virtio mapping API
Posted by Jason Wang 1 month, 1 week ago
Hi all:

Virtio used to be coupled with DMA API. This works fine for the device
that do real DMA but not the others. For example, VDUSE nees to craft
with DMA API in order to let the virtio-vdpa driver to work.

This series tries to solve this issue by introducing the mapping API
in the virtio core. So transport like vDPA can implement their own
mapping logic without the need to hack with DMA API. The mapping API
are abstracted with a new map operations in order to be re-used by
transprot or device. So device like VDUSE can implement its own
mapping loigc.

For device that uses DMA (for example PCI device), the virtio core
will still call DMA API directly without the need of implementing map
ops per device/transport.

Please review.

Changes since V5:

- Rename mapping_token to virtio_map
- Do not use opaque void * pointer, just use a forward decalration of
  vduse_iova_domain
- Remove unused variable and typo fixes

Changes since V4:

- Rename map_token to mapping_token
- Introduce a union container for opaque token as well as the DMA
  device so we won't lose the type safety
- Do not try to set DMA mask for VDUSE device
- Introduce a new mapper_error op for API completeness

Changes since V3:

- Fix build error of PDS vDPA driver

Changes since V2:

- Drop VDUSE dependenct for HAS_DMA and ARCH_HAS_DMA_OPS

Changes since V1:

- Fix build error of mlx5_vdpa driver


Jason Wang (9):
  virtio_ring: constify virtqueue pointer for DMA helpers
  virtio_ring: switch to use dma_{map|unmap}_page()
  virtio: rename dma helpers
  virtio: introduce virtio_map container union
  virtio_ring: rename dma_handle to map_handle
  virtio: introduce map ops in virtio core
  vdpa: support virtio_map
  vdpa: introduce map ops
  vduse: switch to use virtio map API instead of DMA API

 drivers/net/virtio_net.c                 |  28 +-
 drivers/vdpa/Kconfig                     |   8 +-
 drivers/vdpa/alibaba/eni_vdpa.c          |   5 +-
 drivers/vdpa/ifcvf/ifcvf_main.c          |   5 +-
 drivers/vdpa/mlx5/core/mr.c              |   4 +-
 drivers/vdpa/mlx5/net/mlx5_vnet.c        |  15 +-
 drivers/vdpa/octeon_ep/octep_vdpa_main.c |   6 +-
 drivers/vdpa/pds/vdpa_dev.c              |   5 +-
 drivers/vdpa/solidrun/snet_main.c        |   8 +-
 drivers/vdpa/vdpa.c                      |   5 +-
 drivers/vdpa/vdpa_sim/vdpa_sim.c         |   4 +-
 drivers/vdpa/vdpa_user/iova_domain.c     |   2 +-
 drivers/vdpa/vdpa_user/iova_domain.h     |   2 +-
 drivers/vdpa/vdpa_user/vduse_dev.c       |  79 ++--
 drivers/vdpa/virtio_pci/vp_vdpa.c        |   5 +-
 drivers/vhost/vdpa.c                     |   6 +-
 drivers/virtio/virtio_ring.c             | 459 ++++++++++++++---------
 drivers/virtio/virtio_vdpa.c             |  20 +-
 include/linux/vdpa.h                     |  25 +-
 include/linux/virtio.h                   |  46 ++-
 include/linux/virtio_config.h            |  72 ++++
 include/linux/virtio_ring.h              |   7 +-
 22 files changed, 531 insertions(+), 285 deletions(-)

-- 
2.31.1
Re: [PATCH V6 0/9] Refine virtio mapping API
Posted by Michael S. Tsirkin 1 week, 5 days ago
On Thu, Aug 21, 2025 at 02:46:32PM +0800, Jason Wang wrote:
> Hi all:
> 
> Virtio used to be coupled with DMA API. This works fine for the device
> that do real DMA but not the others. For example, VDUSE nees to craft
> with DMA API in order to let the virtio-vdpa driver to work.
> 
> This series tries to solve this issue by introducing the mapping API
> in the virtio core. So transport like vDPA can implement their own
> mapping logic without the need to hack with DMA API. The mapping API
> are abstracted with a new map operations in order to be re-used by
> transprot or device. So device like VDUSE can implement its own
> mapping loigc.
> 
> For device that uses DMA (for example PCI device), the virtio core
> will still call DMA API directly without the need of implementing map
> ops per device/transport.
> 
> Please review.

I sent some typos i found.
Pls send fixups on top to fix them so testing in linux-next is not invalidated.
Thanks!



> Changes since V5:
> 
> - Rename mapping_token to virtio_map
> - Do not use opaque void * pointer, just use a forward decalration of
>   vduse_iova_domain
> - Remove unused variable and typo fixes
> 
> Changes since V4:
> 
> - Rename map_token to mapping_token
> - Introduce a union container for opaque token as well as the DMA
>   device so we won't lose the type safety
> - Do not try to set DMA mask for VDUSE device
> - Introduce a new mapper_error op for API completeness
> 
> Changes since V3:
> 
> - Fix build error of PDS vDPA driver
> 
> Changes since V2:
> 
> - Drop VDUSE dependenct for HAS_DMA and ARCH_HAS_DMA_OPS
> 
> Changes since V1:
> 
> - Fix build error of mlx5_vdpa driver
> 
> 
> Jason Wang (9):
>   virtio_ring: constify virtqueue pointer for DMA helpers
>   virtio_ring: switch to use dma_{map|unmap}_page()
>   virtio: rename dma helpers
>   virtio: introduce virtio_map container union
>   virtio_ring: rename dma_handle to map_handle
>   virtio: introduce map ops in virtio core
>   vdpa: support virtio_map
>   vdpa: introduce map ops
>   vduse: switch to use virtio map API instead of DMA API
> 
>  drivers/net/virtio_net.c                 |  28 +-
>  drivers/vdpa/Kconfig                     |   8 +-
>  drivers/vdpa/alibaba/eni_vdpa.c          |   5 +-
>  drivers/vdpa/ifcvf/ifcvf_main.c          |   5 +-
>  drivers/vdpa/mlx5/core/mr.c              |   4 +-
>  drivers/vdpa/mlx5/net/mlx5_vnet.c        |  15 +-
>  drivers/vdpa/octeon_ep/octep_vdpa_main.c |   6 +-
>  drivers/vdpa/pds/vdpa_dev.c              |   5 +-
>  drivers/vdpa/solidrun/snet_main.c        |   8 +-
>  drivers/vdpa/vdpa.c                      |   5 +-
>  drivers/vdpa/vdpa_sim/vdpa_sim.c         |   4 +-
>  drivers/vdpa/vdpa_user/iova_domain.c     |   2 +-
>  drivers/vdpa/vdpa_user/iova_domain.h     |   2 +-
>  drivers/vdpa/vdpa_user/vduse_dev.c       |  79 ++--
>  drivers/vdpa/virtio_pci/vp_vdpa.c        |   5 +-
>  drivers/vhost/vdpa.c                     |   6 +-
>  drivers/virtio/virtio_ring.c             | 459 ++++++++++++++---------
>  drivers/virtio/virtio_vdpa.c             |  20 +-
>  include/linux/vdpa.h                     |  25 +-
>  include/linux/virtio.h                   |  46 ++-
>  include/linux/virtio_config.h            |  72 ++++
>  include/linux/virtio_ring.h              |   7 +-
>  22 files changed, 531 insertions(+), 285 deletions(-)
> 
> -- 
> 2.31.1
Re: [PATCH V6 0/9] Refine virtio mapping API
Posted by Jason Wang 1 week, 4 days ago
On Mon, Sep 22, 2025 at 6:15 AM Michael S. Tsirkin <mst@redhat.com> wrote:
>
> On Thu, Aug 21, 2025 at 02:46:32PM +0800, Jason Wang wrote:
> > Hi all:
> >
> > Virtio used to be coupled with DMA API. This works fine for the device
> > that do real DMA but not the others. For example, VDUSE nees to craft
> > with DMA API in order to let the virtio-vdpa driver to work.
> >
> > This series tries to solve this issue by introducing the mapping API
> > in the virtio core. So transport like vDPA can implement their own
> > mapping logic without the need to hack with DMA API. The mapping API
> > are abstracted with a new map operations in order to be re-used by
> > transprot or device. So device like VDUSE can implement its own
> > mapping loigc.
> >
> > For device that uses DMA (for example PCI device), the virtio core
> > will still call DMA API directly without the need of implementing map
> > ops per device/transport.
> >
> > Please review.
>
> I sent some typos i found.
> Pls send fixups on top to fix them so testing in linux-next is not invalidated.
> Thanks!
>

Will do, I see the HEAD in linux-next is

vdpa: support virtio_map

Is this intended? Would you want me to send fixes on top?

Thanks

>
>
> > Changes since V5:
> >
> > - Rename mapping_token to virtio_map
> > - Do not use opaque void * pointer, just use a forward decalration of
> >   vduse_iova_domain
> > - Remove unused variable and typo fixes
> >
> > Changes since V4:
> >
> > - Rename map_token to mapping_token
> > - Introduce a union container for opaque token as well as the DMA
> >   device so we won't lose the type safety
> > - Do not try to set DMA mask for VDUSE device
> > - Introduce a new mapper_error op for API completeness
> >
> > Changes since V3:
> >
> > - Fix build error of PDS vDPA driver
> >
> > Changes since V2:
> >
> > - Drop VDUSE dependenct for HAS_DMA and ARCH_HAS_DMA_OPS
> >
> > Changes since V1:
> >
> > - Fix build error of mlx5_vdpa driver
> >
> >
> > Jason Wang (9):
> >   virtio_ring: constify virtqueue pointer for DMA helpers
> >   virtio_ring: switch to use dma_{map|unmap}_page()
> >   virtio: rename dma helpers
> >   virtio: introduce virtio_map container union
> >   virtio_ring: rename dma_handle to map_handle
> >   virtio: introduce map ops in virtio core
> >   vdpa: support virtio_map
> >   vdpa: introduce map ops
> >   vduse: switch to use virtio map API instead of DMA API
> >
> >  drivers/net/virtio_net.c                 |  28 +-
> >  drivers/vdpa/Kconfig                     |   8 +-
> >  drivers/vdpa/alibaba/eni_vdpa.c          |   5 +-
> >  drivers/vdpa/ifcvf/ifcvf_main.c          |   5 +-
> >  drivers/vdpa/mlx5/core/mr.c              |   4 +-
> >  drivers/vdpa/mlx5/net/mlx5_vnet.c        |  15 +-
> >  drivers/vdpa/octeon_ep/octep_vdpa_main.c |   6 +-
> >  drivers/vdpa/pds/vdpa_dev.c              |   5 +-
> >  drivers/vdpa/solidrun/snet_main.c        |   8 +-
> >  drivers/vdpa/vdpa.c                      |   5 +-
> >  drivers/vdpa/vdpa_sim/vdpa_sim.c         |   4 +-
> >  drivers/vdpa/vdpa_user/iova_domain.c     |   2 +-
> >  drivers/vdpa/vdpa_user/iova_domain.h     |   2 +-
> >  drivers/vdpa/vdpa_user/vduse_dev.c       |  79 ++--
> >  drivers/vdpa/virtio_pci/vp_vdpa.c        |   5 +-
> >  drivers/vhost/vdpa.c                     |   6 +-
> >  drivers/virtio/virtio_ring.c             | 459 ++++++++++++++---------
> >  drivers/virtio/virtio_vdpa.c             |  20 +-
> >  include/linux/vdpa.h                     |  25 +-
> >  include/linux/virtio.h                   |  46 ++-
> >  include/linux/virtio_config.h            |  72 ++++
> >  include/linux/virtio_ring.h              |   7 +-
> >  22 files changed, 531 insertions(+), 285 deletions(-)
> >
> > --
> > 2.31.1
>
Re: [PATCH V6 0/9] Refine virtio mapping API
Posted by Eugenio Perez Martin 1 month, 1 week ago
On Thu, Aug 21, 2025 at 8:46 AM Jason Wang <jasowang@redhat.com> wrote:
>
> Hi all:
>
> Virtio used to be coupled with DMA API. This works fine for the device
> that do real DMA but not the others. For example, VDUSE nees to craft
> with DMA API in order to let the virtio-vdpa driver to work.
>
> This series tries to solve this issue by introducing the mapping API
> in the virtio core. So transport like vDPA can implement their own
> mapping logic without the need to hack with DMA API. The mapping API
> are abstracted with a new map operations in order to be re-used by
> transprot or device. So device like VDUSE can implement its own
> mapping loigc.
>
> For device that uses DMA (for example PCI device), the virtio core
> will still call DMA API directly without the need of implementing map
> ops per device/transport.
>
> Please review.
>
> Changes since V5:
>
> - Rename mapping_token to virtio_map
> - Do not use opaque void * pointer, just use a forward decalration of
>   vduse_iova_domain
> - Remove unused variable and typo fixes
>
> Changes since V4:
>
> - Rename map_token to mapping_token
> - Introduce a union container for opaque token as well as the DMA
>   device so we won't lose the type safety
> - Do not try to set DMA mask for VDUSE device
> - Introduce a new mapper_error op for API completeness
>
> Changes since V3:
>
> - Fix build error of PDS vDPA driver
>
> Changes since V2:
>
> - Drop VDUSE dependenct for HAS_DMA and ARCH_HAS_DMA_OPS
>
> Changes since V1:
>
> - Fix build error of mlx5_vdpa driver
>
>
> Jason Wang (9):
>   virtio_ring: constify virtqueue pointer for DMA helpers
>   virtio_ring: switch to use dma_{map|unmap}_page()
>   virtio: rename dma helpers
>   virtio: introduce virtio_map container union
>   virtio_ring: rename dma_handle to map_handle
>   virtio: introduce map ops in virtio core
>   vdpa: support virtio_map
>   vdpa: introduce map ops
>   vduse: switch to use virtio map API instead of DMA API
>
>  drivers/net/virtio_net.c                 |  28 +-
>  drivers/vdpa/Kconfig                     |   8 +-
>  drivers/vdpa/alibaba/eni_vdpa.c          |   5 +-
>  drivers/vdpa/ifcvf/ifcvf_main.c          |   5 +-
>  drivers/vdpa/mlx5/core/mr.c              |   4 +-
>  drivers/vdpa/mlx5/net/mlx5_vnet.c        |  15 +-
>  drivers/vdpa/octeon_ep/octep_vdpa_main.c |   6 +-
>  drivers/vdpa/pds/vdpa_dev.c              |   5 +-
>  drivers/vdpa/solidrun/snet_main.c        |   8 +-
>  drivers/vdpa/vdpa.c                      |   5 +-
>  drivers/vdpa/vdpa_sim/vdpa_sim.c         |   4 +-
>  drivers/vdpa/vdpa_user/iova_domain.c     |   2 +-
>  drivers/vdpa/vdpa_user/iova_domain.h     |   2 +-
>  drivers/vdpa/vdpa_user/vduse_dev.c       |  79 ++--
>  drivers/vdpa/virtio_pci/vp_vdpa.c        |   5 +-
>  drivers/vhost/vdpa.c                     |   6 +-
>  drivers/virtio/virtio_ring.c             | 459 ++++++++++++++---------
>  drivers/virtio/virtio_vdpa.c             |  20 +-
>  include/linux/vdpa.h                     |  25 +-
>  include/linux/virtio.h                   |  46 ++-
>  include/linux/virtio_config.h            |  72 ++++
>  include/linux/virtio_ring.h              |   7 +-
>  22 files changed, 531 insertions(+), 285 deletions(-)
>
> --
> 2.31.1
>

Reviewed-by: Eugenio Pérez <eperezma@redhat.com>

Thanks!
Re: [PATCH V6 0/9] Refine virtio mapping API
Posted by Lei Yang 1 month, 1 week ago
Tested pass with virtio-net regression tests,everything works fine.

Tested-by: Lei Yang <leiyang@redhat.com>

On Thu, Aug 21, 2025 at 2:50 PM Jason Wang <jasowang@redhat.com> wrote:
>
> Hi all:
>
> Virtio used to be coupled with DMA API. This works fine for the device
> that do real DMA but not the others. For example, VDUSE nees to craft
> with DMA API in order to let the virtio-vdpa driver to work.
>
> This series tries to solve this issue by introducing the mapping API
> in the virtio core. So transport like vDPA can implement their own
> mapping logic without the need to hack with DMA API. The mapping API
> are abstracted with a new map operations in order to be re-used by
> transprot or device. So device like VDUSE can implement its own
> mapping loigc.
>
> For device that uses DMA (for example PCI device), the virtio core
> will still call DMA API directly without the need of implementing map
> ops per device/transport.
>
> Please review.
>
> Changes since V5:
>
> - Rename mapping_token to virtio_map
> - Do not use opaque void * pointer, just use a forward decalration of
>   vduse_iova_domain
> - Remove unused variable and typo fixes
>
> Changes since V4:
>
> - Rename map_token to mapping_token
> - Introduce a union container for opaque token as well as the DMA
>   device so we won't lose the type safety
> - Do not try to set DMA mask for VDUSE device
> - Introduce a new mapper_error op for API completeness
>
> Changes since V3:
>
> - Fix build error of PDS vDPA driver
>
> Changes since V2:
>
> - Drop VDUSE dependenct for HAS_DMA and ARCH_HAS_DMA_OPS
>
> Changes since V1:
>
> - Fix build error of mlx5_vdpa driver
>
>
> Jason Wang (9):
>   virtio_ring: constify virtqueue pointer for DMA helpers
>   virtio_ring: switch to use dma_{map|unmap}_page()
>   virtio: rename dma helpers
>   virtio: introduce virtio_map container union
>   virtio_ring: rename dma_handle to map_handle
>   virtio: introduce map ops in virtio core
>   vdpa: support virtio_map
>   vdpa: introduce map ops
>   vduse: switch to use virtio map API instead of DMA API
>
>  drivers/net/virtio_net.c                 |  28 +-
>  drivers/vdpa/Kconfig                     |   8 +-
>  drivers/vdpa/alibaba/eni_vdpa.c          |   5 +-
>  drivers/vdpa/ifcvf/ifcvf_main.c          |   5 +-
>  drivers/vdpa/mlx5/core/mr.c              |   4 +-
>  drivers/vdpa/mlx5/net/mlx5_vnet.c        |  15 +-
>  drivers/vdpa/octeon_ep/octep_vdpa_main.c |   6 +-
>  drivers/vdpa/pds/vdpa_dev.c              |   5 +-
>  drivers/vdpa/solidrun/snet_main.c        |   8 +-
>  drivers/vdpa/vdpa.c                      |   5 +-
>  drivers/vdpa/vdpa_sim/vdpa_sim.c         |   4 +-
>  drivers/vdpa/vdpa_user/iova_domain.c     |   2 +-
>  drivers/vdpa/vdpa_user/iova_domain.h     |   2 +-
>  drivers/vdpa/vdpa_user/vduse_dev.c       |  79 ++--
>  drivers/vdpa/virtio_pci/vp_vdpa.c        |   5 +-
>  drivers/vhost/vdpa.c                     |   6 +-
>  drivers/virtio/virtio_ring.c             | 459 ++++++++++++++---------
>  drivers/virtio/virtio_vdpa.c             |  20 +-
>  include/linux/vdpa.h                     |  25 +-
>  include/linux/virtio.h                   |  46 ++-
>  include/linux/virtio_config.h            |  72 ++++
>  include/linux/virtio_ring.h              |   7 +-
>  22 files changed, 531 insertions(+), 285 deletions(-)
>
> --
> 2.31.1
>
>