> From: Liu, Yi L <yi.l.liu@xxxxxxxxx> > Sent: Friday, April 12, 2024 4:21 PM > > void vfio_iommufd_physical_unbind(struct vfio_device *vdev) > { > + int pasid = 0; > + > lockdep_assert_held(&vdev->dev_set->lock); > > + while (!ida_is_empty(&vdev->pasids)) { > + pasid = ida_get_lowest(&vdev->pasids, pasid, INT_MAX); > + if (pasid < 0) > + break; WARN_ON as this shouldn't happen when ida is not empty. > > +int vfio_iommufd_physical_pasid_attach_ioas(struct vfio_device *vdev, > + u32 pasid, u32 *pt_id) the name is too long. What about removing 'physical' as there is no plan (unlikely) to support pasid on mdev? > +{ > + int rc; > + > + lockdep_assert_held(&vdev->dev_set->lock); > + > + if (WARN_ON(!vdev->iommufd_device)) > + return -EINVAL; > + > + rc = ida_get_lowest(&vdev->pasids, pasid, pasid); > + if (rc == pasid) > + return iommufd_device_pasid_replace(vdev- > >iommufd_device, > + pasid, pt_id); > + > + rc = iommufd_device_pasid_attach(vdev->iommufd_device, pasid, > pt_id); > + if (rc) > + return rc; > + > + rc = ida_alloc_range(&vdev->pasids, pasid, pasid, GFP_KERNEL); > + if (rc < 0) { > + iommufd_device_pasid_detach(vdev->iommufd_device, > pasid); > + return rc; > + } I'd do simple operation (ida_alloc_range()) first before doing attach.