From: Jean-Philippe Brucker <jean-philippe.brucker@arm.com>
To: iommu@lists.linux-foundation.org
Cc: joro@8bytes.org, linux-pci@vger.kernel.org,
jcrouse@codeaurora.org, alex.williamson@redhat.com,
Jonathan.Cameron@huawei.com, jacob.jun.pan@linux.intel.com,
christian.koenig@amd.com, eric.auger@redhat.com,
kevin.tian@intel.com, yi.l.liu@intel.com, andrew.murray@arm.com,
will.deacon@arm.com, robin.murphy@arm.com, ashok.raj@intel.com,
baolu.lu@linux.intel.com, xuzaibo@huawei.com,
liguozhu@hisilicon.com, okaya@codeaurora.org,
bharatku@xilinx.com, ilias.apalodimas@linaro.org,
shunyong.yang@hxt-semitech.com
Subject: [PATCH v3 04/10] iommu/sva: Add a mm_exit callback for device drivers
Date: Thu, 20 Sep 2018 18:00:40 +0100 [thread overview]
Message-ID: <20180920170046.20154-5-jean-philippe.brucker@arm.com> (raw)
In-Reply-To: <20180920170046.20154-1-jean-philippe.brucker@arm.com>
When an mm exits, devices that were bound to it must stop performing DMA
on its PASID. Let device drivers register a callback to be notified on mm
exit. Add the callback to the sva_param structure attached to struct
device.
Signed-off-by: Jean-Philippe Brucker <jean-philippe.brucker@arm.com>
---
drivers/iommu/iommu-sva.c | 10 +++++++++-
include/linux/iommu.h | 8 ++++++--
2 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/drivers/iommu/iommu-sva.c b/drivers/iommu/iommu-sva.c
index a486bc947335..08da479dad68 100644
--- a/drivers/iommu/iommu-sva.c
+++ b/drivers/iommu/iommu-sva.c
@@ -436,6 +436,7 @@ EXPORT_SYMBOL_GPL(iommu_sva_unbind_device_all);
* @features: bitmask of features that need to be initialized
* @min_pasid: min PASID value supported by the device
* @max_pasid: max PASID value supported by the device
+ * @mm_exit: callback for process address space release
*
* Users of the bind()/unbind() API must call this function to initialize all
* features required for SVA.
@@ -447,13 +448,19 @@ EXPORT_SYMBOL_GPL(iommu_sva_unbind_device_all);
* overrides it. Similarly, @min_pasid overrides the lower PASID limit supported
* by the IOMMU.
*
+ * @mm_exit is called when an address space bound to the device is about to be
+ * torn down by exit_mmap. After @mm_exit returns, the device must not issue any
+ * more transaction with the PASID given as argument. The handler gets an opaque
+ * pointer corresponding to the drvdata passed as argument to bind().
+ *
* The device should not be performing any DMA while this function is running,
* otherwise the behavior is undefined.
*
* Return 0 if initialization succeeded, or an error.
*/
int iommu_sva_init_device(struct device *dev, unsigned long features,
- unsigned int min_pasid, unsigned int max_pasid)
+ unsigned int min_pasid, unsigned int max_pasid,
+ iommu_mm_exit_handler_t mm_exit)
{
int ret;
struct iommu_sva_param *param;
@@ -472,6 +479,7 @@ int iommu_sva_init_device(struct device *dev, unsigned long features,
param->features = features;
param->min_pasid = min_pasid;
param->max_pasid = max_pasid;
+ param->mm_exit = mm_exit;
INIT_LIST_HEAD(¶m->mm_list);
mutex_lock(&dev->iommu_param->sva_lock);
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index 6a3ced6a5aa1..c95ff714ea66 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -60,6 +60,7 @@ struct iommu_fault_event;
typedef int (*iommu_fault_handler_t)(struct iommu_domain *,
struct device *, unsigned long, int, void *);
typedef int (*iommu_dev_fault_handler_t)(struct iommu_fault_event *, void *);
+typedef int (*iommu_mm_exit_handler_t)(struct device *dev, int pasid, void *);
struct iommu_domain_geometry {
dma_addr_t aperture_start; /* First address that can be mapped */
@@ -216,6 +217,7 @@ struct iommu_sva_param {
unsigned int min_pasid;
unsigned int max_pasid;
struct list_head mm_list;
+ iommu_mm_exit_handler_t mm_exit;
};
/**
@@ -967,7 +969,8 @@ static inline void iommu_debugfs_setup(void) {}
#ifdef CONFIG_IOMMU_SVA
extern int iommu_sva_init_device(struct device *dev, unsigned long features,
unsigned int min_pasid,
- unsigned int max_pasid);
+ unsigned int max_pasid,
+ iommu_mm_exit_handler_t mm_exit);
extern void iommu_sva_shutdown_device(struct device *dev);
extern int __iommu_sva_bind_device(struct device *dev, struct mm_struct *mm,
int *pasid, unsigned long flags,
@@ -978,7 +981,8 @@ extern void iommu_sva_unbind_device_all(struct device *dev);
static inline int iommu_sva_init_device(struct device *dev,
unsigned long features,
unsigned int min_pasid,
- unsigned int max_pasid)
+ unsigned int max_pasid,
+ iommu_mm_exit_handler_t mm_exit)
{
return -ENODEV;
}
--
2.18.0
next prev parent reply other threads:[~2018-09-20 17:25 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-20 17:00 [PATCH v3 00/10] Shared Virtual Addressing for the IOMMU Jean-Philippe Brucker
2018-09-20 17:00 ` [PATCH v3 01/10] iommu: Introduce Shared Virtual Addressing API Jean-Philippe Brucker
[not found] ` <f406bcf7-4e54-9f1b-88eb-03fc642ffede@linux.intel.com>
2018-09-24 12:07 ` Jean-Philippe Brucker
2018-09-25 13:16 ` Joerg Roedel
2018-09-25 22:46 ` Jacob Pan
2018-09-26 10:14 ` Jean-Philippe Brucker
2018-09-26 12:48 ` Joerg Roedel
2018-09-20 17:00 ` [PATCH v3 02/10] iommu/sva: Bind process address spaces to devices Jean-Philippe Brucker
2018-09-23 3:05 ` Lu Baolu
2018-09-24 12:07 ` Jean-Philippe Brucker
2018-09-26 18:01 ` Jacob Pan
2018-09-27 15:06 ` Jean-Philippe Brucker
2018-09-28 1:14 ` Tian, Kevin
2018-09-20 17:00 ` [PATCH v3 03/10] iommu/sva: Manage process address spaces Jean-Philippe Brucker
2018-09-25 3:15 ` Lu Baolu
2018-09-25 10:32 ` Jean-Philippe Brucker
2018-09-26 3:12 ` Lu Baolu
2018-09-25 13:26 ` Joerg Roedel
2018-09-25 23:33 ` Lu Baolu
2018-09-26 10:20 ` Jean-Philippe Brucker
2018-09-26 12:45 ` Joerg Roedel
2018-09-26 13:50 ` Jean-Philippe Brucker
2018-09-27 3:22 ` Liu, Yi L
2018-09-27 13:37 ` Jean-Philippe Brucker
2018-10-08 8:29 ` Liu, Yi L
2018-09-26 22:58 ` Jacob Pan
2018-09-26 22:35 ` Jacob Pan
2018-10-03 17:52 ` Jean-Philippe Brucker
2018-10-15 20:53 ` Jacob Pan
2018-09-20 17:00 ` Jean-Philippe Brucker [this message]
2018-09-20 17:00 ` [PATCH v3 05/10] iommu/sva: Track mm changes with an MMU notifier Jean-Philippe Brucker
2018-09-20 17:00 ` [PATCH v3 06/10] iommu/sva: Search mm by PASID Jean-Philippe Brucker
2018-09-25 4:59 ` Lu Baolu
2018-09-20 17:00 ` [PATCH v3 07/10] iommu: Add a page fault handler Jean-Philippe Brucker
2018-09-27 20:37 ` Jacob Pan
2018-10-03 17:46 ` Jean-Philippe Brucker
2018-09-20 17:00 ` [PATCH v3 08/10] iommu/iopf: Handle mm faults Jean-Philippe Brucker
2018-09-20 17:00 ` [PATCH v3 09/10] iommu/sva: Register page fault handler Jean-Philippe Brucker
2018-09-20 17:00 ` [RFC PATCH v3 10/10] iommu/sva: Add support for private PASIDs Jean-Philippe Brucker
2018-10-12 14:32 ` Jordan Crouse
2018-10-17 14:21 ` Jean-Philippe Brucker
2018-10-17 14:24 ` Jean-Philippe Brucker
2018-10-17 15:07 ` Jordan Crouse
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=20180920170046.20154-5-jean-philippe.brucker@arm.com \
--to=jean-philippe.brucker@arm.com \
--cc=Jonathan.Cameron@huawei.com \
--cc=alex.williamson@redhat.com \
--cc=andrew.murray@arm.com \
--cc=ashok.raj@intel.com \
--cc=baolu.lu@linux.intel.com \
--cc=bharatku@xilinx.com \
--cc=christian.koenig@amd.com \
--cc=eric.auger@redhat.com \
--cc=ilias.apalodimas@linaro.org \
--cc=iommu@lists.linux-foundation.org \
--cc=jacob.jun.pan@linux.intel.com \
--cc=jcrouse@codeaurora.org \
--cc=joro@8bytes.org \
--cc=kevin.tian@intel.com \
--cc=liguozhu@hisilicon.com \
--cc=linux-pci@vger.kernel.org \
--cc=okaya@codeaurora.org \
--cc=robin.murphy@arm.com \
--cc=shunyong.yang@hxt-semitech.com \
--cc=will.deacon@arm.com \
--cc=xuzaibo@huawei.com \
--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;
as well as URLs for NNTP newsgroup(s).