From: Lu Baolu <baolu.lu@linux.intel.com>
To: Joerg Roedel <joro@8bytes.org>, Will Deacon <will@kernel.org>,
Robin Murphy <robin.murphy@arm.com>,
Jason Gunthorpe <jgg@ziepe.ca>, Kevin Tian <kevin.tian@intel.com>,
Jean-Philippe Brucker <jean-philippe@linaro.org>,
Nicolin Chen <nicolinc@nvidia.com>
Cc: Yi Liu <yi.l.liu@intel.com>,
Jacob Pan <jacob.jun.pan@linux.intel.com>,
iommu@lists.linux.dev, kvm@vger.kernel.org,
linux-kernel@vger.kernel.org, Lu Baolu <baolu.lu@linux.intel.com>
Subject: [PATCH v3 07/11] iommu: Prepare for separating SVA and IOPF
Date: Fri, 18 Aug 2023 07:40:43 +0800 [thread overview]
Message-ID: <20230817234047.195194-8-baolu.lu@linux.intel.com> (raw)
In-Reply-To: <20230817234047.195194-1-baolu.lu@linux.intel.com>
Move iopf_group data structure to iommu.h. This is being done to make it
a minimal set of faults that a domain's page fault handler should handle.
Add two new helpers for the domain's page fault handler:
- iopf_free_group: free a fault group after all faults in the group are
handled.
- iopf_queue_work: queue a given work item for a fault group.
This will simplify the sequential patches.
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
---
include/linux/iommu.h | 12 ++++++++++
drivers/iommu/io-pgfault.c | 49 ++++++++++++++++++++++----------------
2 files changed, 41 insertions(+), 20 deletions(-)
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index 8243d72098ea..ff292eea9d31 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -516,6 +516,18 @@ struct dev_iommu {
u32 require_direct:1;
};
+struct iopf_fault {
+ struct iommu_fault fault;
+ struct list_head list;
+};
+
+struct iopf_group {
+ struct iopf_fault last_fault;
+ struct list_head faults;
+ struct work_struct work;
+ struct device *dev;
+};
+
int iommu_device_register(struct iommu_device *iommu,
const struct iommu_ops *ops,
struct device *hwdev);
diff --git a/drivers/iommu/io-pgfault.c b/drivers/iommu/io-pgfault.c
index 31832aeacdba..d07586cd37fd 100644
--- a/drivers/iommu/io-pgfault.c
+++ b/drivers/iommu/io-pgfault.c
@@ -25,17 +25,17 @@ struct iopf_queue {
struct mutex lock;
};
-struct iopf_fault {
- struct iommu_fault fault;
- struct list_head list;
-};
+static void iopf_free_group(struct iopf_group *group)
+{
+ struct iopf_fault *iopf, *next;
-struct iopf_group {
- struct iopf_fault last_fault;
- struct list_head faults;
- struct work_struct work;
- struct device *dev;
-};
+ list_for_each_entry_safe(iopf, next, &group->faults, list) {
+ if (!(iopf->fault.prm.flags & IOMMU_FAULT_PAGE_REQUEST_LAST_PAGE))
+ kfree(iopf);
+ }
+
+ kfree(group);
+}
static int iopf_complete_group(struct device *dev, struct iopf_fault *iopf,
enum iommu_page_response_code status)
@@ -55,9 +55,9 @@ static int iopf_complete_group(struct device *dev, struct iopf_fault *iopf,
static void iopf_handler(struct work_struct *work)
{
+ struct iopf_fault *iopf;
struct iopf_group *group;
struct iommu_domain *domain;
- struct iopf_fault *iopf, *next;
enum iommu_page_response_code status = IOMMU_PAGE_RESP_SUCCESS;
group = container_of(work, struct iopf_group, work);
@@ -66,7 +66,7 @@ static void iopf_handler(struct work_struct *work)
if (!domain || !domain->iopf_handler)
status = IOMMU_PAGE_RESP_INVALID;
- list_for_each_entry_safe(iopf, next, &group->faults, list) {
+ 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.
@@ -74,14 +74,21 @@ static void iopf_handler(struct work_struct *work)
if (status == IOMMU_PAGE_RESP_SUCCESS)
status = domain->iopf_handler(&iopf->fault,
domain->fault_data);
-
- if (!(iopf->fault.prm.flags &
- IOMMU_FAULT_PAGE_REQUEST_LAST_PAGE))
- kfree(iopf);
}
iopf_complete_group(group->dev, &group->last_fault, status);
- kfree(group);
+ iopf_free_group(group);
+}
+
+static int iopf_queue_work(struct iopf_group *group, work_func_t func)
+{
+ struct iommu_fault_param *fault_param = group->dev->iommu->fault_param;
+
+ INIT_WORK(&group->work, func);
+ if (!queue_work(fault_param->queue->wq, &group->work))
+ return -EBUSY;
+
+ return 0;
}
/**
@@ -174,7 +181,6 @@ int iommu_queue_iopf(struct iommu_fault *fault, struct device *dev)
group->last_fault.fault = *fault;
INIT_LIST_HEAD(&group->faults);
list_add(&group->last_fault.list, &group->faults);
- INIT_WORK(&group->work, iopf_handler);
/* See if we have partial faults for this group */
list_for_each_entry_safe(iopf, next, &iopf_param->partial, list) {
@@ -183,8 +189,11 @@ int iommu_queue_iopf(struct iommu_fault *fault, struct device *dev)
list_move(&iopf->list, &group->faults);
}
- queue_work(iopf_param->queue->wq, &group->work);
- return 0;
+ ret = iopf_queue_work(group, iopf_handler);
+ if (ret)
+ iopf_free_group(group);
+
+ return ret;
cleanup_partial:
list_for_each_entry_safe(iopf, next, &iopf_param->partial, list) {
--
2.34.1
next prev parent reply other threads:[~2023-08-17 23:44 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-17 23:40 [PATCH v3 00/11] iommu: Prepare to deliver page faults to user space Lu Baolu
2023-08-17 23:40 ` [PATCH v3 01/11] iommu: Move iommu fault data to linux/iommu.h Lu Baolu
2023-08-17 23:40 ` [PATCH v3 02/11] iommu/arm-smmu-v3: Remove unrecoverable faults reporting Lu Baolu
2023-08-17 23:40 ` [PATCH v3 03/11] iommu: Remove unrecoverable fault data Lu Baolu
2023-08-17 23:40 ` [PATCH v3 04/11] iommu: Cleanup iopf data structure definitions Lu Baolu
2023-08-21 17:01 ` Jason Gunthorpe
2023-08-17 23:40 ` [PATCH v3 05/11] iommu: Merge iopf_device_param into iommu_fault_param Lu Baolu
2023-08-21 17:04 ` Jason Gunthorpe
2023-08-22 7:42 ` Baolu Lu
2023-08-17 23:40 ` [PATCH v3 06/11] iommu: Remove iommu_[un]register_device_fault_handler() Lu Baolu
2023-08-17 23:40 ` Lu Baolu [this message]
2023-08-21 17:06 ` [PATCH v3 07/11] iommu: Prepare for separating SVA and IOPF Jason Gunthorpe
2023-08-17 23:40 ` [PATCH v3 08/11] iommu: Move iopf_handler() to iommu-sva.c Lu Baolu
2023-08-17 23:40 ` [PATCH v3 09/11] iommu: Make iommu_queue_iopf() more generic Lu Baolu
2023-08-21 17:11 ` Jason Gunthorpe
2023-08-22 8:47 ` Baolu Lu
2023-08-17 23:40 ` [PATCH v3 10/11] iommu: Add debugging on domain lifetime for iopf Lu Baolu
2023-08-17 23:40 ` [PATCH v3 11/11] iommu: Separate SVA and IOPF in Makefile and Kconfig Lu Baolu
2023-08-21 18:31 ` [PATCH v3 00/11] iommu: Prepare to deliver page faults to user space Jason Gunthorpe
2023-08-23 1:24 ` Baolu Lu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230817234047.195194-8-baolu.lu@linux.intel.com \
--to=baolu.lu@linux.intel.com \
--cc=iommu@lists.linux.dev \
--cc=jacob.jun.pan@linux.intel.com \
--cc=jean-philippe@linaro.org \
--cc=jgg@ziepe.ca \
--cc=joro@8bytes.org \
--cc=kevin.tian@intel.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nicolinc@nvidia.com \
--cc=robin.murphy@arm.com \
--cc=will@kernel.org \
--cc=yi.l.liu@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox