iommufd: Reorganize iommufd_device_attach into iommufd_device_change_pt
authorJason Gunthorpe <jgg@nvidia.com>
Mon, 17 Jul 2023 18:12:08 +0000 (15:12 -0300)
committerJason Gunthorpe <jgg@nvidia.com>
Wed, 26 Jul 2023 13:20:06 +0000 (10:20 -0300)
commitea2d6124b52389aa837403f5debf73620d3f441f
treedca9b008395dc718b4d958510f1c7e068d93e64d
parent31422dff187b243c58f3a97d16bbe9e9ada639fe
iommufd: Reorganize iommufd_device_attach into iommufd_device_change_pt

The code flow for first time attaching a PT and replacing a PT is very
similar except for the lowest do_attach step.

Reorganize this so that the do_attach step is a function pointer.

Replace requires destroying the old HWPT once it is replaced. This
destruction cannot be done under all the locks that are held in the
function pointer, so the signature allows returning a HWPT which will be
destroyed by the caller after everything is unlocked.

Link: https://lore.kernel.org/r/12-v8-6659224517ea+532-iommufd_alloc_jgg@nvidia.com
Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Tested-by: Nicolin Chen <nicolinc@nvidia.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
drivers/iommu/iommufd/device.c