[PATCH v1 4/4] iommu: Notify requesters of IOMMU fault failures

Sergey Temerkhanov posted 4 patches 2 months, 4 weeks ago
[PATCH v1 4/4] iommu: Notify requesters of IOMMU fault failures
Posted by Sergey Temerkhanov 2 months, 4 weeks ago
Call the notifier callbacks installed by the device drivers when
failing IOMMU page faults occur during the SVA mode operation.

Signed-off-by: Sergey Temerkhanov <sergey.temerkhanov@intel.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/iommu/iommu-sva.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/drivers/iommu/iommu-sva.c b/drivers/iommu/iommu-sva.c
index 1a51cfd82808..18b6d9b02899 100644
--- a/drivers/iommu/iommu-sva.c
+++ b/drivers/iommu/iommu-sva.c
@@ -256,11 +256,19 @@ iommu_sva_handle_mm(struct iommu_fault *fault, struct mm_struct *mm)
 	return status;
 }
 
+static struct iommu_rid_notifier *iommu_get_rid_notifier(struct device *dev, u32 rid)
+{
+	struct dev_iommu *param = dev->iommu;
+
+	return xa_load(&param->rid_notifiers, rid);
+}
+
 static void iommu_sva_handle_iopf(struct work_struct *work)
 {
 	struct iopf_fault *iopf;
 	struct iopf_group *group;
 	enum iommu_page_response_code status = IOMMU_PAGE_RESP_SUCCESS;
+	struct iommu_rid_notifier *rid_notifier;
 
 	group = container_of(work, struct iopf_group, work);
 	list_for_each_entry(iopf, &group->faults, list) {
@@ -268,8 +276,17 @@ static void iommu_sva_handle_iopf(struct work_struct *work)
 		 * For the moment, errors are sticky: don't handle subsequent
 		 * faults in the group if there is an error.
 		 */
-		if (status != IOMMU_PAGE_RESP_SUCCESS)
+		if (status != IOMMU_PAGE_RESP_SUCCESS) {
+			/* Notify the requester of a failure. */
+			rid_notifier = iommu_get_rid_notifier(group->fault_param->dev,
+							      iopf->fault.prm.rid);
+
+			if (rid_notifier && rid_notifier->notifier)
+				rid_notifier->notifier(rid_notifier->dev, &iopf->fault,
+						       status, rid_notifier->data);
+
 			break;
+		}
 
 		status = iommu_sva_handle_mm(&iopf->fault,
 					     group->attach_handle->domain->mm);
-- 
2.43.0
Re: [PATCH v1 4/4] iommu: Notify requesters of IOMMU fault failures
Posted by Jason Gunthorpe 2 months, 3 weeks ago
On Thu, Jul 10, 2025 at 01:42:15PM +0000, Sergey Temerkhanov wrote:
> Call the notifier callbacks installed by the device drivers when
> failing IOMMU page faults occur during the SVA mode operation.
> 
> Signed-off-by: Sergey Temerkhanov <sergey.temerkhanov@intel.com>
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/iommu/iommu-sva.c | 19 ++++++++++++++++++-
>  1 file changed, 18 insertions(+), 1 deletion(-)

It doesn't seem to me like any of this is really needed..

Look at how iommufd already associates faults back to its own struct
device structure side-structure.

I think all you want for this problem is a way to hook the fault
callback chain on a domain, and that should be local to the domain not
global to the device..

Jason
RE: [PATCH v1 4/4] iommu: Notify requesters of IOMMU fault failures
Posted by Temerkhanov, Sergey 2 months, 3 weeks ago
> Look at how iommufd already associates faults back to its own struct device
> structure side-structure.
> 
> I think all you want for this problem is a way to hook the fault callback chain
> on a domain, and that should be local to the domain not global to the device..
> 

Moving this to a domain sounds reasonable, however the main goal is to reuse the kernel
SVA IOPF handling code to the maximum extent and only provide "feedback" when
iommu_sva_handle_iopf() returns an error for some reason.

Regards,
Sergey