mbox series

[v3,0/6] vfio: Make emulated devices prepared for vfio device cdev

Message ID 20230327093351.44505-1-yi.l.liu@intel.com (mailing list archive)
Headers show
Series vfio: Make emulated devices prepared for vfio device cdev | expand

Message

Yi Liu March 27, 2023, 9:33 a.m. UTC
The .bind_iommufd op of vfio emulated devices are either empty or does
nothing. This is different with the vfio physical devices, to add vfio
device cdev, need to make them act the same.

This series first makes the .bind_iommufd op of vfio emulated devices
to create iommufd_access, this introduces a new iommufd API. Then let
the driver that does not provide .bind_iommufd op to use the vfio emulated
iommufd op set. This makes all vfio device drivers have consistent iommufd
operations, which is good for adding new device uAPIs in the device cdev
series.

Change log:

v3:
 - Use iommufd_get_ioas() for ioas get, hence patch 01 is added to modify
   the input parameter of iommufd_get_ioas(). (Jason)
 - Add r-b from Jason and Kevin
 - Add t-b from Terrence Xu

v2: https://lore.kernel.org/kvm/20230316121526.5644-1-yi.l.liu@intel.com/
 - Add r-b from Kevin and Jason
 - Refine patch 01 per comments from Jason and Kevin

v1: https://lore.kernel.org/kvm/20230308131340.459224-1-yi.l.liu@intel.com/

Thanks,
        Yi Liu
    
Nicolin Chen (1):
  iommufd: Create access in vfio_iommufd_emulated_bind()

Yi Liu (5):
  iommu/iommufd: Pass iommufd_ctx pointer in iommufd_get_ioas()
  vfio-iommufd: No need to record iommufd_ctx in vfio_device
  vfio-iommufd: Make vfio_iommufd_emulated_bind() return iommufd_access
    ID
  vfio/mdev: Uses the vfio emulated iommufd ops set in the mdev sample
    drivers
  vfio: Check the presence for iommufd callbacks in
    __vfio_register_dev()

 drivers/iommu/iommufd/device.c          | 55 +++++++++++++++----------
 drivers/iommu/iommufd/ioas.c            | 14 +++----
 drivers/iommu/iommufd/iommufd_private.h |  4 +-
 drivers/iommu/iommufd/selftest.c        | 14 ++++---
 drivers/iommu/iommufd/vfio_compat.c     |  2 +-
 drivers/vfio/iommufd.c                  | 37 ++++++++---------
 drivers/vfio/vfio_main.c                |  5 ++-
 include/linux/iommufd.h                 |  5 ++-
 include/linux/vfio.h                    |  1 -
 samples/vfio-mdev/mbochs.c              |  3 ++
 samples/vfio-mdev/mdpy.c                |  3 ++
 samples/vfio-mdev/mtty.c                |  3 ++
 12 files changed, 85 insertions(+), 61 deletions(-)

Comments

Nicolin Chen March 27, 2023, 5:47 p.m. UTC | #1
On Mon, Mar 27, 2023 at 02:33:45AM -0700, Yi Liu wrote:
> External email: Use caution opening links or attachments
> 
> 
> The .bind_iommufd op of vfio emulated devices are either empty or does
> nothing. This is different with the vfio physical devices, to add vfio
> device cdev, need to make them act the same.
> 
> This series first makes the .bind_iommufd op of vfio emulated devices
> to create iommufd_access, this introduces a new iommufd API. Then let
> the driver that does not provide .bind_iommufd op to use the vfio emulated
> iommufd op set. This makes all vfio device drivers have consistent iommufd
> operations, which is good for adding new device uAPIs in the device cdev
> series.
> 
> Change log:
> 
> v3:
>  - Use iommufd_get_ioas() for ioas get, hence patch 01 is added to modify
>    the input parameter of iommufd_get_ioas(). (Jason)
>  - Add r-b from Jason and Kevin
>  - Add t-b from Terrence Xu

This runs well with iommufd selftest on x86 and QEMU sanity on
ARM64, applying nesting series on top of this and cdev series:
https://github.com/nicolinc/iommufd/commits/wip/iommufd_nesting-03272023

Tested-by: Nicolin Chen <nicolinc@nvidia.com>
Jason Gunthorpe March 29, 2023, 7:47 p.m. UTC | #2
On Mon, Mar 27, 2023 at 02:33:45AM -0700, Yi Liu wrote:
> Nicolin Chen (1):
>   iommufd: Create access in vfio_iommufd_emulated_bind()
> 
> Yi Liu (5):
>   iommu/iommufd: Pass iommufd_ctx pointer in iommufd_get_ioas()
>   vfio-iommufd: No need to record iommufd_ctx in vfio_device
>   vfio-iommufd: Make vfio_iommufd_emulated_bind() return iommufd_access
>     ID
>   vfio/mdev: Uses the vfio emulated iommufd ops set in the mdev sample
>     drivers
>   vfio: Check the presence for iommufd callbacks in
>     __vfio_register_dev()
> 
>  drivers/iommu/iommufd/device.c          | 55 +++++++++++++++----------
>  drivers/iommu/iommufd/ioas.c            | 14 +++----
>  drivers/iommu/iommufd/iommufd_private.h |  4 +-
>  drivers/iommu/iommufd/selftest.c        | 14 ++++---
>  drivers/iommu/iommufd/vfio_compat.c     |  2 +-
>  drivers/vfio/iommufd.c                  | 37 ++++++++---------
>  drivers/vfio/vfio_main.c                |  5 ++-
>  include/linux/iommufd.h                 |  5 ++-
>  include/linux/vfio.h                    |  1 -
>  samples/vfio-mdev/mbochs.c              |  3 ++
>  samples/vfio-mdev/mdpy.c                |  3 ++
>  samples/vfio-mdev/mtty.c                |  3 ++
>  12 files changed, 85 insertions(+), 61 deletions(-)

It looks like most of this is iommufd so I will take it - Ok Alex?

The following cdev patch needs it so I'll stick it on its own branch
and we can sort it out after the reset series is done

Thanls,
Jason
Alex Williamson March 30, 2023, 7:21 p.m. UTC | #3
On Wed, 29 Mar 2023 16:47:39 -0300
Jason Gunthorpe <jgg@nvidia.com> wrote:

> On Mon, Mar 27, 2023 at 02:33:45AM -0700, Yi Liu wrote:
> > Nicolin Chen (1):
> >   iommufd: Create access in vfio_iommufd_emulated_bind()
> > 
> > Yi Liu (5):
> >   iommu/iommufd: Pass iommufd_ctx pointer in iommufd_get_ioas()
> >   vfio-iommufd: No need to record iommufd_ctx in vfio_device
> >   vfio-iommufd: Make vfio_iommufd_emulated_bind() return iommufd_access
> >     ID
> >   vfio/mdev: Uses the vfio emulated iommufd ops set in the mdev sample
> >     drivers
> >   vfio: Check the presence for iommufd callbacks in
> >     __vfio_register_dev()
> > 
> >  drivers/iommu/iommufd/device.c          | 55 +++++++++++++++----------
> >  drivers/iommu/iommufd/ioas.c            | 14 +++----
> >  drivers/iommu/iommufd/iommufd_private.h |  4 +-
> >  drivers/iommu/iommufd/selftest.c        | 14 ++++---
> >  drivers/iommu/iommufd/vfio_compat.c     |  2 +-
> >  drivers/vfio/iommufd.c                  | 37 ++++++++---------
> >  drivers/vfio/vfio_main.c                |  5 ++-
> >  include/linux/iommufd.h                 |  5 ++-
> >  include/linux/vfio.h                    |  1 -
> >  samples/vfio-mdev/mbochs.c              |  3 ++
> >  samples/vfio-mdev/mdpy.c                |  3 ++
> >  samples/vfio-mdev/mtty.c                |  3 ++
> >  12 files changed, 85 insertions(+), 61 deletions(-)  
> 
> It looks like most of this is iommufd so I will take it - Ok Alex?
> 
> The following cdev patch needs it so I'll stick it on its own branch
> and we can sort it out after the reset series is done

Ok

Acked-by: Alex Williamson <alex.williamson@redhat.com>
Jiang, Yanting March 31, 2023, 3:13 a.m. UTC | #4
>
> The .bind_iommufd op of vfio emulated devices are either empty or does
> nothing. This is different with the vfio physical devices, to add vfio device cdev,
> need to make them act the same.
> 
> This series first makes the .bind_iommufd op of vfio emulated devices to create
> iommufd_access, this introduces a new iommufd API. Then let the driver that
> does not provide .bind_iommufd op to use the vfio emulated iommufd op set.
> This makes all vfio device drivers have consistent iommufd operations, which is
> good for adding new device uAPIs in the device cdev series.
> 

Tested NIC passthrough on Intel platform.
Result looks good hence, 
Tested by: Jiang, Yanting <yanting.jiang@intel.com>

Thanks,
Yanting
Jiang, Yanting March 31, 2023, 4:57 a.m. UTC | #5
> The .bind_iommufd op of vfio emulated devices are either empty or does
> nothing. This is different with the vfio physical devices, to add vfio device cdev,
> need to make them act the same.
> 
> This series first makes the .bind_iommufd op of vfio emulated devices to create
> iommufd_access, this introduces a new iommufd API. Then let the driver that
> does not provide .bind_iommufd op to use the vfio emulated iommufd op set.
> This makes all vfio device drivers have consistent iommufd operations, which is
> good for adding new device uAPIs in the device cdev series.
> 

Tested-by: Yanting Jiang <yanting.jiang@intel.com>

Thanks,
Yanting