Skip to content

Commit c157fd8

Browse files
nicolincjgunthorpe
authored andcommitted
vfio: Support IO page table replacement
Now both the physical path and the emulated path can support an IO page table replacement. Call iommufd_device_replace/iommufd_access_replace(), when vdev->iommufd_attached is true. Also update the VFIO_DEVICE_ATTACH_IOMMUFD_PT kdoc in the uAPI header. Link: https://lore.kernel.org/r/b5f01956ff161f76aa52c95b0fa1ad6eaca95c4a.1690523699.git.nicolinc@nvidia.com Reviewed-by: Kevin Tian <kevin.tian@intel.com> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Reviewed-by: Alex Williamson <alex.williamson@redhat.com> Signed-off-by: Nicolin Chen <nicolinc@nvidia.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
1 parent c154660 commit c157fd8

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

drivers/vfio/iommufd.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,9 @@ int vfio_iommufd_physical_attach_ioas(struct vfio_device *vdev, u32 *pt_id)
146146
return -EINVAL;
147147

148148
if (vdev->iommufd_attached)
149-
return -EBUSY;
150-
151-
rc = iommufd_device_attach(vdev->iommufd_device, pt_id);
149+
rc = iommufd_device_replace(vdev->iommufd_device, pt_id);
150+
else
151+
rc = iommufd_device_attach(vdev->iommufd_device, pt_id);
152152
if (rc)
153153
return rc;
154154
vdev->iommufd_attached = true;
@@ -223,8 +223,9 @@ int vfio_iommufd_emulated_attach_ioas(struct vfio_device *vdev, u32 *pt_id)
223223
lockdep_assert_held(&vdev->dev_set->lock);
224224

225225
if (vdev->iommufd_attached)
226-
return -EBUSY;
227-
rc = iommufd_access_attach(vdev->iommufd_access, *pt_id);
226+
rc = iommufd_access_replace(vdev->iommufd_access, *pt_id);
227+
else
228+
rc = iommufd_access_attach(vdev->iommufd_access, *pt_id);
228229
if (rc)
229230
return rc;
230231
vdev->iommufd_attached = true;

include/uapi/linux/vfio.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,12 @@ struct vfio_device_bind_iommufd {
939939
* Undo by VFIO_DEVICE_DETACH_IOMMUFD_PT or device fd close. This is only
940940
* allowed on cdev fds.
941941
*
942+
* If a vfio device is currently attached to a valid hw_pagetable, without doing
943+
* a VFIO_DEVICE_DETACH_IOMMUFD_PT, a second VFIO_DEVICE_ATTACH_IOMMUFD_PT ioctl
944+
* passing in another hw_pagetable (hwpt) id is allowed. This action, also known
945+
* as a hw_pagetable replacement, will replace the device's currently attached
946+
* hw_pagetable with a new hw_pagetable corresponding to the given pt_id.
947+
*
942948
* Return: 0 on success, -errno on failure.
943949
*/
944950
struct vfio_device_attach_iommufd_pt {

0 commit comments

Comments
 (0)