Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Nicolin Chen and committed by
Jason Gunthorpe
c157fd88 c154660b

+12 -5
+6 -5
drivers/vfio/iommufd.c
··· 146 146 return -EINVAL; 147 147 148 148 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); 152 152 if (rc) 153 153 return rc; 154 154 vdev->iommufd_attached = true; ··· 223 223 lockdep_assert_held(&vdev->dev_set->lock); 224 224 225 225 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); 228 229 if (rc) 229 230 return rc; 230 231 vdev->iommufd_attached = true;
+6
include/uapi/linux/vfio.h
··· 939 939 * Undo by VFIO_DEVICE_DETACH_IOMMUFD_PT or device fd close. This is only 940 940 * allowed on cdev fds. 941 941 * 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 + * 942 948 * Return: 0 on success, -errno on failure. 943 949 */ 944 950 struct vfio_device_attach_iommufd_pt {