[PATCH 0/9] Refine virtio mapping API

Jason Wang posted 9 patches 3 months, 1 week ago
There is a newer version of this series
drivers/net/virtio_net.c                 |  32 +-
drivers/vdpa/alibaba/eni_vdpa.c          |   5 +-
drivers/vdpa/ifcvf/ifcvf_main.c          |   5 +-
drivers/vdpa/octeon_ep/octep_vdpa_main.c |   6 +-
drivers/vdpa/pds/vdpa_dev.c              |   3 +-
drivers/vdpa/solidrun/snet_main.c        |   4 +-
drivers/vdpa/vdpa.c                      |   5 +-
drivers/vdpa/vdpa_sim/vdpa_sim.c         |   4 +-
drivers/vdpa/vdpa_user/iova_domain.c     |   8 +-
drivers/vdpa/vdpa_user/iova_domain.h     |   5 +-
drivers/vdpa/vdpa_user/vduse_dev.c       |  34 +-
drivers/vdpa/virtio_pci/vp_vdpa.c        |   5 +-
drivers/vhost/vdpa.c                     |  11 +-
drivers/virtio/virtio_ring.c             | 440 ++++++++++++++---------
drivers/virtio/virtio_vdpa.c             |  15 +-
include/linux/vdpa.h                     |  22 +-
include/linux/virtio.h                   |  36 +-
include/linux/virtio_config.h            |  68 ++++
include/linux/virtio_ring.h              |   6 +-
19 files changed, 476 insertions(+), 238 deletions(-)
[PATCH 0/9] Refine virtio mapping API
Posted by Jason Wang 3 months, 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.

Please review.

Thanks

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: rename dma_dev to map_token
  virtio_ring: rename dma_handle to map_handle
  virtio: introduce map ops in virtio core
  vdpa: rename dma_dev to map_token
  vdpa: introduce map ops
  vduse: switch to use virtio map API instead of DMA API

 drivers/net/virtio_net.c                 |  32 +-
 drivers/vdpa/alibaba/eni_vdpa.c          |   5 +-
 drivers/vdpa/ifcvf/ifcvf_main.c          |   5 +-
 drivers/vdpa/octeon_ep/octep_vdpa_main.c |   6 +-
 drivers/vdpa/pds/vdpa_dev.c              |   3 +-
 drivers/vdpa/solidrun/snet_main.c        |   4 +-
 drivers/vdpa/vdpa.c                      |   5 +-
 drivers/vdpa/vdpa_sim/vdpa_sim.c         |   4 +-
 drivers/vdpa/vdpa_user/iova_domain.c     |   8 +-
 drivers/vdpa/vdpa_user/iova_domain.h     |   5 +-
 drivers/vdpa/vdpa_user/vduse_dev.c       |  34 +-
 drivers/vdpa/virtio_pci/vp_vdpa.c        |   5 +-
 drivers/vhost/vdpa.c                     |  11 +-
 drivers/virtio/virtio_ring.c             | 440 ++++++++++++++---------
 drivers/virtio/virtio_vdpa.c             |  15 +-
 include/linux/vdpa.h                     |  22 +-
 include/linux/virtio.h                   |  36 +-
 include/linux/virtio_config.h            |  68 ++++
 include/linux/virtio_ring.h              |   6 +-
 19 files changed, 476 insertions(+), 238 deletions(-)

-- 
2.34.1
Re: [PATCH 0/9] Refine virtio mapping API
Posted by Michael S. Tsirkin 3 months, 1 week ago
On Tue, Jul 01, 2025 at 09:13:52AM +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.
> 
> Please review.
> 
> Thanks

Cost of all this extra indirection? Especially on systems with
software spectre mitigations/retpoline enabled.

> 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: rename dma_dev to map_token
>   virtio_ring: rename dma_handle to map_handle
>   virtio: introduce map ops in virtio core
>   vdpa: rename dma_dev to map_token
>   vdpa: introduce map ops
>   vduse: switch to use virtio map API instead of DMA API
> 
>  drivers/net/virtio_net.c                 |  32 +-
>  drivers/vdpa/alibaba/eni_vdpa.c          |   5 +-
>  drivers/vdpa/ifcvf/ifcvf_main.c          |   5 +-
>  drivers/vdpa/octeon_ep/octep_vdpa_main.c |   6 +-
>  drivers/vdpa/pds/vdpa_dev.c              |   3 +-
>  drivers/vdpa/solidrun/snet_main.c        |   4 +-
>  drivers/vdpa/vdpa.c                      |   5 +-
>  drivers/vdpa/vdpa_sim/vdpa_sim.c         |   4 +-
>  drivers/vdpa/vdpa_user/iova_domain.c     |   8 +-
>  drivers/vdpa/vdpa_user/iova_domain.h     |   5 +-
>  drivers/vdpa/vdpa_user/vduse_dev.c       |  34 +-
>  drivers/vdpa/virtio_pci/vp_vdpa.c        |   5 +-
>  drivers/vhost/vdpa.c                     |  11 +-
>  drivers/virtio/virtio_ring.c             | 440 ++++++++++++++---------
>  drivers/virtio/virtio_vdpa.c             |  15 +-
>  include/linux/vdpa.h                     |  22 +-
>  include/linux/virtio.h                   |  36 +-
>  include/linux/virtio_config.h            |  68 ++++
>  include/linux/virtio_ring.h              |   6 +-
>  19 files changed, 476 insertions(+), 238 deletions(-)
> 
> -- 
> 2.34.1
Re: [PATCH 0/9] Refine virtio mapping API
Posted by Jason Wang 3 months, 1 week ago
On Tue, Jul 1, 2025 at 3:04 PM Michael S. Tsirkin <mst@redhat.com> wrote:
>
> On Tue, Jul 01, 2025 at 09:13:52AM +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.
> >
> > Please review.
> >
> > Thanks
>
> Cost of all this extra indirection? Especially on systems with
> software spectre mitigations/retpoline enabled.

Actually not, it doesn't change how things work for the device that
does DMA already like:

If device has its specific mapping ops
        go for device specific mapping ops
else
        go for DMA API

VDUSE is the only user now, and extra indirection has been used for
VDUSE even without this series (via abusing DMA API). This series
switch from:

virtio core -> DMA API -> VDUSE DMA API -> iova domain ops

to

virtio core -> virtio map ops -> VDUSE map ops -> iova domain ops

Thanks



>
> > 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: rename dma_dev to map_token
> >   virtio_ring: rename dma_handle to map_handle
> >   virtio: introduce map ops in virtio core
> >   vdpa: rename dma_dev to map_token
> >   vdpa: introduce map ops
> >   vduse: switch to use virtio map API instead of DMA API
> >
> >  drivers/net/virtio_net.c                 |  32 +-
> >  drivers/vdpa/alibaba/eni_vdpa.c          |   5 +-
> >  drivers/vdpa/ifcvf/ifcvf_main.c          |   5 +-
> >  drivers/vdpa/octeon_ep/octep_vdpa_main.c |   6 +-
> >  drivers/vdpa/pds/vdpa_dev.c              |   3 +-
> >  drivers/vdpa/solidrun/snet_main.c        |   4 +-
> >  drivers/vdpa/vdpa.c                      |   5 +-
> >  drivers/vdpa/vdpa_sim/vdpa_sim.c         |   4 +-
> >  drivers/vdpa/vdpa_user/iova_domain.c     |   8 +-
> >  drivers/vdpa/vdpa_user/iova_domain.h     |   5 +-
> >  drivers/vdpa/vdpa_user/vduse_dev.c       |  34 +-
> >  drivers/vdpa/virtio_pci/vp_vdpa.c        |   5 +-
> >  drivers/vhost/vdpa.c                     |  11 +-
> >  drivers/virtio/virtio_ring.c             | 440 ++++++++++++++---------
> >  drivers/virtio/virtio_vdpa.c             |  15 +-
> >  include/linux/vdpa.h                     |  22 +-
> >  include/linux/virtio.h                   |  36 +-
> >  include/linux/virtio_config.h            |  68 ++++
> >  include/linux/virtio_ring.h              |   6 +-
> >  19 files changed, 476 insertions(+), 238 deletions(-)
> >
> > --
> > 2.34.1
>
Re: [PATCH 0/9] Refine virtio mapping API
Posted by Christoph Hellwig 3 months ago
On Tue, Jul 01, 2025 at 04:00:31PM +0800, Jason Wang wrote:
> Actually not, it doesn't change how things work for the device that
> does DMA already like:
> 
> If device has its specific mapping ops
>         go for device specific mapping ops
> else
>         go for DMA API
> 
> VDUSE is the only user now, and extra indirection has been used for
> VDUSE even without this series (via abusing DMA API). This series
> switch from:
> 
> virtio core -> DMA API -> VDUSE DMA API -> iova domain ops
> 
> to
> 
> virtio core -> virtio map ops -> VDUSE map ops -> iova domain ops

And that's exaxctly how it should be done.

Thanks for doing the work!  I'll go through if I find some nitpicks,
but the concept is the only right one here.