]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
iommufd/fault: Remove iommufd_fault_domain_attach/detach/replace_dev()
authorNicolin Chen <nicolinc@nvidia.com>
Tue, 4 Feb 2025 05:00:55 +0000 (21:00 -0800)
committerJason Gunthorpe <jgg@nvidia.com>
Tue, 11 Feb 2025 18:21:03 +0000 (14:21 -0400)
There are new attach/detach/replace helpers in device.c taking care of both
the attach_handle and the fault specific routines for iopf_enable/disable()
and auto response.

Clean up these redundant functions in the fault.c file.

Link: https://patch.msgid.link/r/3ca94625e9d78270d9a715fa0809414fddd57e58.1738645017.git.nicolinc@nvidia.com
Signed-off-by: Nicolin Chen <nicolinc@nvidia.com>
Reviewed-by: Yi Liu <yi.l.liu@intel.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
drivers/iommu/iommufd/fault.c
drivers/iommu/iommufd/iommufd_private.h

index cb844e6799d4f8434589d8679bff40807cb672cf..931a3fbe6e32cadc7d0886be41a7749f51c4da60 100644 (file)
@@ -60,44 +60,6 @@ void iommufd_fault_iopf_disable(struct iommufd_device *idev)
        mutex_unlock(&idev->iopf_lock);
 }
 
-static int __fault_domain_attach_dev(struct iommufd_hw_pagetable *hwpt,
-                                    struct iommufd_device *idev)
-{
-       struct iommufd_attach_handle *handle;
-       int ret;
-
-       handle = kzalloc(sizeof(*handle), GFP_KERNEL);
-       if (!handle)
-               return -ENOMEM;
-
-       handle->idev = idev;
-       ret = iommu_attach_group_handle(hwpt->domain, idev->igroup->group,
-                                       &handle->handle);
-       if (ret)
-               kfree(handle);
-
-       return ret;
-}
-
-int iommufd_fault_domain_attach_dev(struct iommufd_hw_pagetable *hwpt,
-                                   struct iommufd_device *idev)
-{
-       int ret;
-
-       if (!hwpt->fault)
-               return -EINVAL;
-
-       ret = iommufd_fault_iopf_enable(idev);
-       if (ret)
-               return ret;
-
-       ret = __fault_domain_attach_dev(hwpt, idev);
-       if (ret)
-               iommufd_fault_iopf_disable(idev);
-
-       return ret;
-}
-
 void iommufd_auto_response_faults(struct iommufd_hw_pagetable *hwpt,
                                  struct iommufd_attach_handle *handle)
 {
@@ -135,88 +97,6 @@ void iommufd_auto_response_faults(struct iommufd_hw_pagetable *hwpt,
        mutex_unlock(&fault->mutex);
 }
 
-static struct iommufd_attach_handle *
-iommufd_device_get_attach_handle(struct iommufd_device *idev)
-{
-       struct iommu_attach_handle *handle;
-
-       handle = iommu_attach_handle_get(idev->igroup->group, IOMMU_NO_PASID, 0);
-       if (IS_ERR(handle))
-               return NULL;
-
-       return to_iommufd_handle(handle);
-}
-
-void iommufd_fault_domain_detach_dev(struct iommufd_hw_pagetable *hwpt,
-                                    struct iommufd_device *idev)
-{
-       struct iommufd_attach_handle *handle;
-
-       handle = iommufd_device_get_attach_handle(idev);
-       iommu_detach_group_handle(hwpt->domain, idev->igroup->group);
-       iommufd_auto_response_faults(hwpt, handle);
-       iommufd_fault_iopf_disable(idev);
-       kfree(handle);
-}
-
-static int __fault_domain_replace_dev(struct iommufd_device *idev,
-                                     struct iommufd_hw_pagetable *hwpt,
-                                     struct iommufd_hw_pagetable *old)
-{
-       struct iommufd_attach_handle *handle, *curr = NULL;
-       int ret;
-
-       if (old->fault)
-               curr = iommufd_device_get_attach_handle(idev);
-
-       if (hwpt->fault) {
-               handle = kzalloc(sizeof(*handle), GFP_KERNEL);
-               if (!handle)
-                       return -ENOMEM;
-
-               handle->idev = idev;
-               ret = iommu_replace_group_handle(idev->igroup->group,
-                                                hwpt->domain, &handle->handle);
-       } else {
-               ret = iommu_replace_group_handle(idev->igroup->group,
-                                                hwpt->domain, NULL);
-       }
-
-       if (!ret && curr) {
-               iommufd_auto_response_faults(old, curr);
-               kfree(curr);
-       }
-
-       return ret;
-}
-
-int iommufd_fault_domain_replace_dev(struct iommufd_device *idev,
-                                    struct iommufd_hw_pagetable *hwpt,
-                                    struct iommufd_hw_pagetable *old)
-{
-       bool iopf_off = !hwpt->fault && old->fault;
-       bool iopf_on = hwpt->fault && !old->fault;
-       int ret;
-
-       if (iopf_on) {
-               ret = iommufd_fault_iopf_enable(idev);
-               if (ret)
-                       return ret;
-       }
-
-       ret = __fault_domain_replace_dev(idev, hwpt, old);
-       if (ret) {
-               if (iopf_on)
-                       iommufd_fault_iopf_disable(idev);
-               return ret;
-       }
-
-       if (iopf_off)
-               iommufd_fault_iopf_disable(idev);
-
-       return 0;
-}
-
 void iommufd_fault_destroy(struct iommufd_object *obj)
 {
        struct iommufd_fault *fault = container_of(obj, struct iommufd_fault, obj);
index 02fe1ada97cc79a07df5b89c773bbf861c105c8c..8e0e3ab64747692469b2e7ae03e8059bcfcf35f8 100644 (file)
@@ -496,14 +496,6 @@ int iommufd_fault_alloc(struct iommufd_ucmd *ucmd);
 void iommufd_fault_destroy(struct iommufd_object *obj);
 int iommufd_fault_iopf_handler(struct iopf_group *group);
 
-int iommufd_fault_domain_attach_dev(struct iommufd_hw_pagetable *hwpt,
-                                   struct iommufd_device *idev);
-void iommufd_fault_domain_detach_dev(struct iommufd_hw_pagetable *hwpt,
-                                    struct iommufd_device *idev);
-int iommufd_fault_domain_replace_dev(struct iommufd_device *idev,
-                                    struct iommufd_hw_pagetable *hwpt,
-                                    struct iommufd_hw_pagetable *old);
-
 int iommufd_fault_iopf_enable(struct iommufd_device *idev);
 void iommufd_fault_iopf_disable(struct iommufd_device *idev);
 void iommufd_auto_response_faults(struct iommufd_hw_pagetable *hwpt,