iommu: Handle iommu faults for a bad iopf setup
Subsystems (2)
PATCH v4 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.
--- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 2 +- drivers/iommu/io-pgfault.c | 121 ++++++++++++++------ include/linux/iommu.h | 5 +- 3 files changed, 87 insertions(+), 41 deletions(-)
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +1 -1
@@ -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 +83 -38
164 lines not on this page · raw message
include/linux/iommu.h +3 -2
@@ -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
Quoted 26 lines · Pranjal Shrivastava
The
iommu_report_device_faultfunction was updated to return void while assuming that drivers only need to calliommu_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_paramis NULL, theops->page_responseis NOT called causing the device to stall in case the fault type wasPAGE_REQ.2. The
arm_smmu_v3driver relies on the returned value to log errors returning void fromiommu_report_device_faultcauses these events to be missed while logging.Modify the
iommu_report_device_faultfunction to return-EINVALfor cases where no fault capable domain is attached oriopf_paramwas NULL and calls back to the driver (ops->page_response) in case the fault type wasIOMMU_FAULT_PAGE_REQ. The returned value can be used by the drivers to log the fault/event as needed.Reported-by Kunkun Jiang <[email protected]>Fixes 3dfa64aecbaf ("iommu: Make iommu_report_device_fault() return void")Signed-off-by Jason Gunthorpe <[email protected]>Signed-off-by Pranjal Shrivastava <[email protected]>Reviewed-by Jason Gunthorpe <[email protected]>Reviewed-by Lu Baolu <[email protected]>
Quoted 5 lines
--- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 2 +- drivers/iommu/io-pgfault.c | 121 ++++++++++++++------ include/linux/iommu.h | 5 +- 3 files changed, 87 insertions(+), 41 deletions(-)
Applied, thanks.