• Jason Gunthorpe's avatar
    iommufd: Data structure to provide IOVA to PFN mapping · 51fe6141
    Jason Gunthorpe authored
    This is the remainder of the IOAS data structure. Provide an object called
    an io_pagetable that is composed of iopt_areas pointing at iopt_pages,
    along with a list of iommu_domains that mirror the IOVA to PFN map.
    
    At the top this is a simple interval tree of iopt_areas indicating the map
    of IOVA to iopt_pages. An xarray keeps track of a list of domains. Based
    on the attached domains there is a minimum alignment for areas (which may
    be smaller than PAGE_SIZE), an interval tree of reserved IOVA that can't
    be mapped and an IOVA of allowed IOVA that can always be mappable.
    
    The concept of an 'access' refers to something like a VFIO mdev that is
    accessing the IOVA and using a 'struct page *' for CPU based access.
    
    Externally an API is provided that matches the requirements of the IOCTL
    interface for map/unmap and domain attachment.
    
    The API provides a 'copy' primitive to establish a new IOVA map in a
    different IOAS from an existing mapping by re-using the iopt_pages. This
    is the basic mechanism to provide single pinning.
    
    This is designed to support a pre-registration flow where userspace would
    setup an dummy IOAS with no domains, map in memory and then establish an
    access to pin all PFNs into the xarray.
    
    Copy can then be used to create new IOVA mappings in a different IOAS,
    with iommu_domains attached. Upon copy the PFNs will be read out of the
    xarray and mapped into the iommu_domains, avoiding any pin_user_pages()
    overheads.
    
    Link: https://lore.kernel.org/r/10-v6-a196d26f289e+11787-iommufd_jgg@nvidia.comTested-by: default avatarNicolin Chen <nicolinc@nvidia.com>
    Tested-by: default avatarYi Liu <yi.l.liu@intel.com>
    Tested-by: default avatarLixiao Yang <lixiao.yang@intel.com>
    Tested-by: default avatarMatthew Rosato <mjrosato@linux.ibm.com>
    Reviewed-by: default avatarKevin Tian <kevin.tian@intel.com>
    Signed-off-by: default avatarYi Liu <yi.l.liu@intel.com>
    Signed-off-by: default avatarNicolin Chen <nicolinc@nvidia.com>
    Signed-off-by: default avatarJason Gunthorpe <jgg@nvidia.com>
    51fe6141
iommufd_private.h 6.3 KB