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 9/9] iommu: Use fault cookie to store iopf_param
Date: Tue, 11 Jul 2023 09:06:42 +0800 [thread overview]
Message-ID: <20230711010642.19707-10-baolu.lu@linux.intel.com> (raw)
In-Reply-To: <20230711010642.19707-1-baolu.lu@linux.intel.com>
Remove the static iopf_param pointer from struct iommu_fault_param to
save memory.
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
---
include/linux/iommu.h | 2 --
drivers/iommu/io-pgfault.c | 47 +++++++++++++++++++++++---------------
2 files changed, 29 insertions(+), 20 deletions(-)
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index ffd6fe1317f4..5fe37a7c5a55 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -551,7 +551,6 @@ struct iommu_fault_param {
* struct dev_iommu - Collection of per-device IOMMU data
*
* @fault_param: IOMMU detected device fault reporting data
- * @iopf_param: I/O Page Fault queue and data
* @fwspec: IOMMU fwspec data
* @iommu_dev: IOMMU device this device is linked to
* @priv: IOMMU Driver private data
@@ -564,7 +563,6 @@ struct iommu_fault_param {
struct dev_iommu {
struct mutex lock;
struct iommu_fault_param *fault_param;
- struct iopf_device_param *iopf_param;
struct iommu_fwspec *fwspec;
struct iommu_device *iommu_dev;
void *priv;
diff --git a/drivers/iommu/io-pgfault.c b/drivers/iommu/io-pgfault.c
index 1749e0869f2e..6a3a4e08e67e 100644
--- a/drivers/iommu/io-pgfault.c
+++ b/drivers/iommu/io-pgfault.c
@@ -158,7 +158,7 @@ int iommu_queue_iopf(struct iommu_fault *fault, struct device *dev)
* As long as we're holding param->lock, the queue can't be unlinked
* from the device and therefore cannot disappear.
*/
- iopf_param = param->iopf_param;
+ iopf_param = iommu_get_device_fault_cookie(dev, 0);
if (!iopf_param)
return -ENODEV;
@@ -235,7 +235,7 @@ int iopf_queue_flush_dev(struct device *dev)
return -ENODEV;
mutex_lock(¶m->lock);
- iopf_param = param->iopf_param;
+ iopf_param = iommu_get_device_fault_cookie(dev, 0);
if (iopf_param)
flush_workqueue(iopf_param->queue->wq);
else
@@ -286,9 +286,9 @@ EXPORT_SYMBOL_GPL(iopf_queue_discard_partial);
*/
int iopf_queue_add_device(struct iopf_queue *queue, struct device *dev)
{
- int ret = -EBUSY;
- struct iopf_device_param *iopf_param;
+ struct iopf_device_param *iopf_param, *curr;
struct dev_iommu *param = dev->iommu;
+ int ret;
if (!param)
return -ENODEV;
@@ -303,16 +303,27 @@ int iopf_queue_add_device(struct iopf_queue *queue, struct device *dev)
mutex_lock(&queue->lock);
mutex_lock(¶m->lock);
- if (!param->iopf_param) {
- list_add(&iopf_param->queue_list, &queue->devices);
- param->iopf_param = iopf_param;
- ret = 0;
+ curr = iommu_set_device_fault_cookie(dev, 0, iopf_param);
+ if (IS_ERR(curr)) {
+ ret = PTR_ERR(curr);
+ goto err_free;
}
+
+ if (curr) {
+ ret = -EBUSY;
+ goto err_restore;
+ }
+ list_add(&iopf_param->queue_list, &queue->devices);
mutex_unlock(¶m->lock);
mutex_unlock(&queue->lock);
- if (ret)
- kfree(iopf_param);
+ return 0;
+err_restore:
+ iommu_set_device_fault_cookie(dev, 0, curr);
+err_free:
+ mutex_unlock(¶m->lock);
+ mutex_unlock(&queue->lock);
+ kfree(iopf_param);
return ret;
}
@@ -329,7 +340,6 @@ EXPORT_SYMBOL_GPL(iopf_queue_add_device);
*/
int iopf_queue_remove_device(struct iopf_queue *queue, struct device *dev)
{
- int ret = -EINVAL;
struct iopf_fault *iopf, *next;
struct iopf_device_param *iopf_param;
struct dev_iommu *param = dev->iommu;
@@ -339,16 +349,17 @@ int iopf_queue_remove_device(struct iopf_queue *queue, struct device *dev)
mutex_lock(&queue->lock);
mutex_lock(¶m->lock);
- iopf_param = param->iopf_param;
- if (iopf_param && iopf_param->queue == queue) {
- list_del(&iopf_param->queue_list);
- param->iopf_param = NULL;
- ret = 0;
+ iopf_param = iommu_get_device_fault_cookie(dev, 0);
+ if (!iopf_param || iopf_param->queue != queue) {
+ mutex_unlock(¶m->lock);
+ mutex_unlock(&queue->lock);
+ return -EINVAL;
}
+
+ list_del(&iopf_param->queue_list);
+ iommu_set_device_fault_cookie(dev, 0, NULL);
mutex_unlock(¶m->lock);
mutex_unlock(&queue->lock);
- if (ret)
- return ret;
/* Just in case some faults are still stuck */
list_for_each_entry_safe(iopf, next, &iopf_param->partial, list)
--
2.34.1
next prev parent reply other threads:[~2023-07-11 1:09 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-11 1:06 [PATCH 0/9] iommu: Prepare to deliver page faults to user space Lu Baolu
2023-07-11 1:06 ` [PATCH 1/9] iommu: Move iommu fault data to linux/iommu.h Lu Baolu
2023-07-11 6:05 ` Tian, Kevin
2023-07-12 2:07 ` Baolu Lu
2023-07-12 9:33 ` Jean-Philippe Brucker
2023-07-13 3:22 ` Tian, Kevin
2023-07-13 3:48 ` Baolu Lu
2023-07-11 1:06 ` [PATCH 2/9] iommu: Add device parameter to iopf handler Lu Baolu
2023-07-11 17:26 ` Jacob Pan
2023-07-12 2:16 ` Baolu Lu
2023-07-12 5:46 ` Jacob Pan
2023-07-11 1:06 ` [PATCH 3/9] iommu: Add common code to handle IO page faults Lu Baolu
2023-07-11 6:12 ` Tian, Kevin
2023-07-12 2:32 ` Baolu Lu
2023-07-12 9:45 ` Jean-Philippe Brucker
2023-07-13 4:02 ` Baolu Lu
2023-07-11 20:50 ` Jacob Pan
2023-07-12 2:37 ` Baolu Lu
2023-07-11 1:06 ` [PATCH 4/9] iommu: Change the return value of dev_iommu_get() Lu Baolu
2023-07-11 21:05 ` Jacob Pan
2023-07-11 1:06 ` [PATCH 5/9] iommu: Make fault_param generic Lu Baolu
2023-07-11 6:14 ` Tian, Kevin
2023-07-12 2:43 ` Baolu Lu
2023-07-11 21:31 ` Jacob Pan
2023-07-12 3:02 ` Baolu Lu
2023-07-11 1:06 ` [PATCH 6/9] iommu: Remove iommu_[un]register_device_fault_handler() Lu Baolu
2023-07-11 1:06 ` [PATCH 7/9] iommu: Add helper to set iopf handler for domain Lu Baolu
2023-07-11 1:06 ` [PATCH 8/9] iommu: Add iommu page fault cookie helpers Lu Baolu
2023-07-11 1:06 ` Lu Baolu [this message]
2023-07-11 6:26 ` [PATCH 9/9] iommu: Use fault cookie to store iopf_param Tian, Kevin
2023-07-12 3:09 ` Baolu Lu
2023-07-11 22:02 ` Jacob Pan
2023-07-12 3:13 ` Baolu Lu
2023-07-13 3:24 ` Tian, Kevin
2023-07-13 3:43 ` Baolu Lu
2023-07-13 8:01 ` Tian, Kevin
2023-07-14 2:49 ` 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=20230711010642.19707-10-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