Skip to contentSkip to conversation

iommu: Handle iommu faults for a bad iopf setup

PATCH Superseded Pranjal Shrivastava 3 participants 4 messages Aug 15, 2024 – Aug 16, 2024

Subsystems (2)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 iommu: Handle iommu faults for a bad iopf setup

The iommu_report_device_fault function was updated to return void while assuming that drivers only need to call iommu_report_device_fault() for reporting an iopf. This implementation causes following problems:

1. The drivers rely on the core code to call it's page_reponse, however, when a fault is received and no fault capable domain is attached / iopf_param is NULL, the ops->page_response is NOT called causing the device to stall in case the fault type was PAGE_REQ.

2. The arm_smmu_v3 driver relies on the returned value to log errors returning void from iommu_report_device_fault causes these events to be missed while logging.

Modify the iommu_report_device_fault function to return -EINVAL for cases where no fault capable domain is attached or iopf_param was NULL and calls back to the driver (ops->page_response) in case the fault type was IOMMU_FAULT_PAGE_REQ. The returned value can be used by the drivers to log the fault/event as needed.

Fixes 3dfa64aecbaf ("iommu: Make iommu_report_device_fault() return void")
---
 drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c |   2 +-
 drivers/iommu/io-pgfault.c                  | 116 +++++++++++++-------
 include/linux/iommu.h                       |   5 +-
 3 files changed, 83 insertions(+), 40 deletions(-)
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +1 -1
index 9bc50bded5af..8a6cd0adfcf2 100644
@@ -1777,7 +1777,7 @@ static int arm_smmu_handle_evt(struct arm_smmu_device *smmu, u64 *evt)
 		goto out_unlock;
 	}
 
-	iommu_report_device_fault(master->dev, &fault_evt);
+	ret = iommu_report_device_fault(master->dev, &fault_evt);
 out_unlock:
 	mutex_unlock(&smmu->streams_mutex);
 	return ret;
drivers/iommu/io-pgfault.c +79 -37

158 lines not on this page · raw message

include/linux/iommu.h +3 -2
index 04cbdae0052e..bd722f473635 100644
@@ -1563,7 +1563,7 @@ struct iopf_queue *iopf_queue_alloc(const char *name);
 void iopf_queue_free(struct iopf_queue *queue);
 int iopf_queue_discard_partial(struct iopf_queue *queue);
 void iopf_free_group(struct iopf_group *group);
-void iommu_report_device_fault(struct device *dev, struct iopf_fault *evt);
+int iommu_report_device_fault(struct device *dev, struct iopf_fault *evt);
 void iopf_group_response(struct iopf_group *group,
 			 enum iommu_page_response_code status);
 #else
@@ -1601,9 +1601,10 @@ static inline void iopf_free_group(struct iopf_group *group)
 {
 }
 
-static inline void
+static inline int
 iommu_report_device_fault(struct device *dev, struct iopf_fault *evt)
 {
+	return -ENODEV;
 }
 
 static inline void iopf_group_response(struct iopf_group *group,
Signature · 1 line
2.46.0.184.g6999bdac58-goog
Reviewed-by on v3 1/1
#1 lore raw
Quoted 24 lines · Pranjal Shrivastava

The iommu_report_device_fault function was updated to return void while assuming that drivers only need to call iommu_report_device_fault() for reporting an iopf. This implementation causes following problems:

1. The drivers rely on the core code to call it's page_reponse, however, when a fault is received and no fault capable domain is attached / iopf_param is NULL, the ops->page_response is NOT called causing the device to stall in case the fault type was PAGE_REQ.

2. The arm_smmu_v3 driver relies on the returned value to log errors returning void from iommu_report_device_fault causes these events to be missed while logging.

Modify the iommu_report_device_fault function to return -EINVAL for cases where no fault capable domain is attached or iopf_param was NULL and calls back to the driver (ops->page_response) in case the fault type was IOMMU_FAULT_PAGE_REQ. The returned value can be used by the drivers to log the fault/event as needed.

Fixes 3dfa64aecbaf ("iommu: Make iommu_report_device_fault() return void")
Quoted 5 lines
---
 drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c |   2 +-
 drivers/iommu/io-pgfault.c                  | 116 +++++++++++++-------
 include/linux/iommu.h                       |   5 +-
 3 files changed, 83 insertions(+), 40 deletions(-)

You can keep tags for minor changes like this:

Jason

Reviewed-by on v3 1/1
#2 lore raw
In reply to Pranjal Shrivastava
Quoted 24 lines · Pranjal Shrivastava

The iommu_report_device_fault function was updated to return void while assuming that drivers only need to call iommu_report_device_fault() for reporting an iopf. This implementation causes following problems:

1. The drivers rely on the core code to call it's page_reponse, however, when a fault is received and no fault capable domain is attached / iopf_param is NULL, the ops->page_response is NOT called causing the device to stall in case the fault type was PAGE_REQ.

2. The arm_smmu_v3 driver relies on the returned value to log errors returning void from iommu_report_device_fault causes these events to be missed while logging.

Modify the iommu_report_device_fault function to return -EINVAL for cases where no fault capable domain is attached or iopf_param was NULL and calls back to the driver (ops->page_response) in case the fault type was IOMMU_FAULT_PAGE_REQ. The returned value can be used by the drivers to log the fault/event as needed.

Fixes 3dfa64aecbaf ("iommu: Make iommu_report_device_fault() return void")
Quoted 5 lines
---
  drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c |   2 +-
  drivers/iommu/io-pgfault.c                  | 116 +++++++++++++-------
  include/linux/iommu.h                       |   5 +-
  3 files changed, 83 insertions(+), 40 deletions(-)

Nit: can you please add some words to the comments of iommu_report_device_fault() to explain what it returns? Right now, it looks like the return value only matters for certain iommu drivers, so it would be helpful to add a clear explanation.

Others look good to me,

Thanks,
baolu

#3 lore raw
Quoted 31 lines · Baolu Lu
Quoted 24 lines · Pranjal Shrivastava

The iommu_report_device_fault function was updated to return void while assuming that drivers only need to call iommu_report_device_fault() for reporting an iopf. This implementation causes following problems:

1. The drivers rely on the core code to call it's page_reponse, however, when a fault is received and no fault capable domain is attached / iopf_param is NULL, the ops->page_response is NOT called causing the device to stall in case the fault type was PAGE_REQ.

2. The arm_smmu_v3 driver relies on the returned value to log errors returning void from iommu_report_device_fault causes these events to be missed while logging.

Modify the iommu_report_device_fault function to return -EINVAL for cases where no fault capable domain is attached or iopf_param was NULL and calls back to the driver (ops->page_response) in case the fault type was IOMMU_FAULT_PAGE_REQ. The returned value can be used by the drivers to log the fault/event as needed.

Fixes 3dfa64aecbaf ("iommu: Make iommu_report_device_fault() return void")
Quoted 5 lines
---
  drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c |   2 +-
  drivers/iommu/io-pgfault.c                  | 116 +++++++++++++-------
  include/linux/iommu.h                       |   5 +-
  3 files changed, 83 insertions(+), 40 deletions(-)
Quoted 4 lines

Nit: can you please add some words to the comments of iommu_report_device_fault() to explain what it returns? Right now, it looks like the return value only matters for certain iommu drivers, so it would be helpful to add a clear explanation.

Alright, will update the comments in v4.

Quoted 9 lines

Others look good to me,

Thanks,
baolu

Thanks,
Pranjal