RE: [PATCH 3/9] iommu: Add common code to handle IO page faults

From: Tian, Kevin
Date: Tue Jul 11 2023 - 02:12:22 EST


> From: Lu Baolu <baolu.lu@xxxxxxxxxxxxxxx>
> Sent: Tuesday, July 11, 2023 9:07 AM
>
> +static int iommu_handle_io_pgfault(struct device *dev,
> + struct iommu_fault *fault)
> +{
> + struct iommu_domain *domain;
> +
> + if (fault->type != IOMMU_FAULT_PAGE_REQ)
> + return -EINVAL;
> +
> + if (fault->prm.flags & IOMMU_FAULT_PAGE_REQUEST_PASID_VALID)
> + domain = iommu_get_domain_for_dev_pasid(dev, fault-
> >prm.pasid, 0);
> + else
> + domain = iommu_get_domain_for_dev(dev);
> +
> + if (!domain || !domain->iopf_handler)
> + return -ENODEV;
> +
> + if (domain->iopf_handler == iommu_sva_handle_iopf)
> + return iommu_queue_iopf(fault, dev);

You can avoid the special check by directly making iommu_queue_iopf
as the iopf_handler for sva domain.

> +
> + return domain->iopf_handler(fault, dev, domain->fault_data);
> +}

btw is there value of moving the group handling logic from
iommu_queue_iopf() to this common function?

I wonder whether there is any correctness issue if not forwarding
partial request to iommufd. If not this can also help reduce
notifications to the user until the group is ready.