On Sun, Nov 26, 2023 at 10:39:07PM -0800, Yi Liu wrote:

> @@ -168,6 +180,42 @@ void vfio_iommufd_physical_detach_ioas(struct 
> vfio_device *vdev)
>  }
>  EXPORT_SYMBOL_GPL(vfio_iommufd_physical_detach_ioas);
>  
> +int vfio_iommufd_physical_pasid_attach_ioas(struct vfio_device *vdev,
> +                                         u32 pasid, u32 *pt_id)
> +{
> +     void *entry;
> +     int rc;
> +
> +     lockdep_assert_held(&vdev->dev_set->lock);
> +
> +     if (WARN_ON(!vdev->iommufd_device))
> +             return -EINVAL;
> +
> +     entry = xa_load(&vdev->pasid_pts, pasid);
> +     if (xa_is_value(entry))
> +             rc = iommufd_device_pasid_replace(vdev->iommufd_device, pasid, 
> pt_id);
> +     else
> +             rc = iommufd_device_pasid_attach(vdev->iommufd_device, pasid, 
> pt_id);

An ida is a more approriate data structure if the only point is to
keep track if a pasid is in use or not..

Jason

Reply via email to