[v2,09/12] iommu: Move iopf_handler() to iommu-sva.c
Commit Message
The iopf_handler() function handles a fault_group for a SVA domain. Move
it to the right place.
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
---
drivers/iommu/iommu-sva.h | 17 +++++++++++++
drivers/iommu/io-pgfault.c | 50 +++-----------------------------------
drivers/iommu/iommu-sva.c | 49 +++++++++++++++++++++++++++++++++++++
3 files changed, 69 insertions(+), 47 deletions(-)
Comments
> From: Lu Baolu <baolu.lu@linux.intel.com>
> Sent: Thursday, July 27, 2023 1:49 PM
>
> @@ -219,3 +219,52 @@ void mm_pasid_drop(struct mm_struct *mm)
>
> ida_free(&iommu_global_pasid_ida, mm->pasid);
> }
> +
> +static int iopf_complete_group(struct device *dev, struct iopf_fault *iopf,
> + enum iommu_page_response_code status)
iommu_sva_complete_iopf()
> +
> +static void iopf_handler(struct work_struct *work)
> +{
iommu_sva_iopf_handler()
On 2023/8/3 16:21, Tian, Kevin wrote:
>> From: Lu Baolu <baolu.lu@linux.intel.com>
>> Sent: Thursday, July 27, 2023 1:49 PM
>>
>> @@ -219,3 +219,52 @@ void mm_pasid_drop(struct mm_struct *mm)
>>
>> ida_free(&iommu_global_pasid_ida, mm->pasid);
>> }
>> +
>> +static int iopf_complete_group(struct device *dev, struct iopf_fault *iopf,
>> + enum iommu_page_response_code status)
>
> iommu_sva_complete_iopf()
>
>> +
>> +static void iopf_handler(struct work_struct *work)
>> +{
>
> iommu_sva_iopf_handler()
>
Ack to both.
Best regards,
baolu
On Thu, Jul 27, 2023 at 01:48:34PM +0800, Lu Baolu wrote:
> The iopf_handler() function handles a fault_group for a SVA domain. Move
> it to the right place.
>
> Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
> ---
> drivers/iommu/iommu-sva.h | 17 +++++++++++++
> drivers/iommu/io-pgfault.c | 50 +++-----------------------------------
> drivers/iommu/iommu-sva.c | 49 +++++++++++++++++++++++++++++++++++++
> 3 files changed, 69 insertions(+), 47 deletions(-)
> diff --git a/drivers/iommu/iommu-sva.c b/drivers/iommu/iommu-sva.c
> index 05c0fb2acbc4..ab42cfdd7636 100644
> --- a/drivers/iommu/iommu-sva.c
> +++ b/drivers/iommu/iommu-sva.c
> @@ -219,3 +219,52 @@ void mm_pasid_drop(struct mm_struct *mm)
> +static void iopf_handler(struct work_struct *work)
> +{
> + struct iopf_fault *iopf;
> + struct iopf_group *group;
> + struct iommu_domain *domain;
> + enum iommu_page_response_code status = IOMMU_PAGE_RESP_SUCCESS;
> +
> + group = container_of(work, struct iopf_group, work);
> + domain = iommu_get_domain_for_dev_pasid(group->dev,
> + group->last_fault.fault.prm.pasid, 0);
> + if (!domain || !domain->iopf_handler)
> + status = IOMMU_PAGE_RESP_INVALID;
> +
> + list_for_each_entry(iopf, &group->faults, list) {
> + /*
> + * 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)
> + status = domain->iopf_handler(&iopf->fault,
> + domain->fault_data);
> + }
> +
> + iopf_complete_group(group->dev, &group->last_fault, status);
> + iopf_free_group(group);
> +}
Routing faults to domains is generic code, not SVA code.
SVA starts at domain->iopf_handler
Jason
On 2023/8/11 3:02, Jason Gunthorpe wrote:
> On Thu, Jul 27, 2023 at 01:48:34PM +0800, Lu Baolu wrote:
>> The iopf_handler() function handles a fault_group for a SVA domain. Move
>> it to the right place.
>>
>> Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
>> ---
>> drivers/iommu/iommu-sva.h | 17 +++++++++++++
>> drivers/iommu/io-pgfault.c | 50 +++-----------------------------------
>> drivers/iommu/iommu-sva.c | 49 +++++++++++++++++++++++++++++++++++++
>> 3 files changed, 69 insertions(+), 47 deletions(-)
>> diff --git a/drivers/iommu/iommu-sva.c b/drivers/iommu/iommu-sva.c
>> index 05c0fb2acbc4..ab42cfdd7636 100644
>> --- a/drivers/iommu/iommu-sva.c
>> +++ b/drivers/iommu/iommu-sva.c
>> @@ -219,3 +219,52 @@ void mm_pasid_drop(struct mm_struct *mm)
>
>> +static void iopf_handler(struct work_struct *work)
>> +{
>> + struct iopf_fault *iopf;
>> + struct iopf_group *group;
>> + struct iommu_domain *domain;
>> + enum iommu_page_response_code status = IOMMU_PAGE_RESP_SUCCESS;
>> +
>> + group = container_of(work, struct iopf_group, work);
>> + domain = iommu_get_domain_for_dev_pasid(group->dev,
>> + group->last_fault.fault.prm.pasid, 0);
>> + if (!domain || !domain->iopf_handler)
>> + status = IOMMU_PAGE_RESP_INVALID;
>> +
>> + list_for_each_entry(iopf, &group->faults, list) {
>> + /*
>> + * 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)
>> + status = domain->iopf_handler(&iopf->fault,
>> + domain->fault_data);
>> + }
>> +
>> + iopf_complete_group(group->dev, &group->last_fault, status);
>> + iopf_free_group(group);
>> +}
>
> Routing faults to domains is generic code, not SVA code.
You are right. This happens in the latter patch.
> SVA starts at domain->iopf_handler
>
> Jason
>
Best regards,
baolu
@@ -24,6 +24,9 @@ void iopf_queue_free(struct iopf_queue *queue);
int iopf_queue_discard_partial(struct iopf_queue *queue);
enum iommu_page_response_code
iommu_sva_handle_iopf(struct iommu_fault *fault, void *data);
+void iopf_free_group(struct iopf_group *group);
+int iopf_queue_work(struct iopf_group *group, work_func_t func);
+int iommu_sva_handle_iopf_group(struct iopf_group *group);
#else /* CONFIG_IOMMU_SVA */
static inline int iommu_queue_iopf(struct iommu_fault *fault, struct device *dev)
@@ -67,5 +70,19 @@ iommu_sva_handle_iopf(struct iommu_fault *fault, void *data)
{
return IOMMU_PAGE_RESP_INVALID;
}
+
+static inline void iopf_free_group(struct iopf_group *group)
+{
+}
+
+static inline int iopf_queue_work(struct iopf_group *group, work_func_t func)
+{
+ return -ENODEV;
+}
+
+static inline int iommu_sva_handle_iopf_group(struct iopf_group *group)
+{
+ return -ENODEV;
+}
#endif /* CONFIG_IOMMU_SVA */
#endif /* _IOMMU_SVA_H */
@@ -40,7 +40,7 @@ struct iopf_device_param {
struct list_head partial;
};
-static void iopf_free_group(struct iopf_group *group)
+void iopf_free_group(struct iopf_group *group)
{
struct iopf_fault *iopf, *next;
@@ -52,51 +52,7 @@ static void iopf_free_group(struct iopf_group *group)
kfree(group);
}
-static int iopf_complete_group(struct device *dev, struct iopf_fault *iopf,
- enum iommu_page_response_code status)
-{
- struct iommu_page_response resp = {
- .version = IOMMU_PAGE_RESP_VERSION_1,
- .pasid = iopf->fault.prm.pasid,
- .grpid = iopf->fault.prm.grpid,
- .code = status,
- };
-
- if ((iopf->fault.prm.flags & IOMMU_FAULT_PAGE_REQUEST_PASID_VALID) &&
- (iopf->fault.prm.flags & IOMMU_FAULT_PAGE_RESPONSE_NEEDS_PASID))
- resp.flags = IOMMU_PAGE_RESP_PASID_VALID;
-
- return iommu_page_response(dev, &resp);
-}
-
-static void iopf_handler(struct work_struct *work)
-{
- struct iopf_fault *iopf;
- struct iopf_group *group;
- struct iommu_domain *domain;
- enum iommu_page_response_code status = IOMMU_PAGE_RESP_SUCCESS;
-
- group = container_of(work, struct iopf_group, work);
- domain = iommu_get_domain_for_dev_pasid(group->dev,
- group->last_fault.fault.prm.pasid, 0);
- if (!domain || !domain->iopf_handler)
- status = IOMMU_PAGE_RESP_INVALID;
-
- list_for_each_entry(iopf, &group->faults, list) {
- /*
- * 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)
- status = domain->iopf_handler(&iopf->fault,
- domain->fault_data);
- }
-
- iopf_complete_group(group->dev, &group->last_fault, status);
- iopf_free_group(group);
-}
-
-static int iopf_queue_work(struct iopf_group *group, work_func_t func)
+int iopf_queue_work(struct iopf_group *group, work_func_t func)
{
struct iopf_device_param *iopf_param = group->dev->iommu->iopf_param;
@@ -204,7 +160,7 @@ int iommu_queue_iopf(struct iommu_fault *fault, struct device *dev)
list_move(&iopf->list, &group->faults);
}
- ret = iopf_queue_work(group, iopf_handler);
+ ret = iommu_sva_handle_iopf_group(group);
if (ret)
iopf_free_group(group);
@@ -219,3 +219,52 @@ void mm_pasid_drop(struct mm_struct *mm)
ida_free(&iommu_global_pasid_ida, mm->pasid);
}
+
+static int iopf_complete_group(struct device *dev, struct iopf_fault *iopf,
+ enum iommu_page_response_code status)
+{
+ struct iommu_page_response resp = {
+ .version = IOMMU_PAGE_RESP_VERSION_1,
+ .pasid = iopf->fault.prm.pasid,
+ .grpid = iopf->fault.prm.grpid,
+ .code = status,
+ };
+
+ if ((iopf->fault.prm.flags & IOMMU_FAULT_PAGE_REQUEST_PASID_VALID) &&
+ (iopf->fault.prm.flags & IOMMU_FAULT_PAGE_RESPONSE_NEEDS_PASID))
+ resp.flags = IOMMU_PAGE_RESP_PASID_VALID;
+
+ return iommu_page_response(dev, &resp);
+}
+
+static void iopf_handler(struct work_struct *work)
+{
+ struct iopf_fault *iopf;
+ struct iopf_group *group;
+ struct iommu_domain *domain;
+ enum iommu_page_response_code status = IOMMU_PAGE_RESP_SUCCESS;
+
+ group = container_of(work, struct iopf_group, work);
+ domain = iommu_get_domain_for_dev_pasid(group->dev,
+ group->last_fault.fault.prm.pasid, 0);
+ if (!domain || !domain->iopf_handler)
+ status = IOMMU_PAGE_RESP_INVALID;
+
+ list_for_each_entry(iopf, &group->faults, list) {
+ /*
+ * 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)
+ status = domain->iopf_handler(&iopf->fault,
+ domain->fault_data);
+ }
+
+ iopf_complete_group(group->dev, &group->last_fault, status);
+ iopf_free_group(group);
+}
+
+int iommu_sva_handle_iopf_group(struct iopf_group *group)
+{
+ return iopf_queue_work(group, iopf_handler);
+}