iommu: Remove iommu_sva_ops::mm_exit()
Subsystems (3)
v2 cover iommu: Remove iommu_sva_ops::mm_exit()
The IOMMU SVA API currently requires device drivers to implement an mm_exit() callback, which stops device jobs that do DMA. This function is called in the release() MMU notifier, when an address space that is shared with a device exits.
It has been noted several time during discussions about SVA that cancelling DMA jobs can be slow and complex, and doing it in the release() notifier might cause synchronization issues. Device drivers must in any case call unbind() to remove their bond, after stopping DMA from a more favorable context (release of a file descriptor).
Patch 1 removes the mm_exit() callback from the uacce module, and patch 2 removes it from the IOMMU API. Since v1 [1] I fixed the uacce unbind reported by Zhangfei and added details in the commit message of patch 2.
Jean-Philippe Brucker (2):
uacce: Remove mm_exit() op
iommu: Remove iommu_sva_ops::mm_exit()
include/linux/iommu.h | 30 ------- include/linux/uacce.h | 34 ++------ drivers/iommu/iommu.c | 11 --- drivers/misc/uacce/uacce.c | 172 +++++++++---------------------------- 4 files changed, 51 insertions(+), 196 deletions(-)
Signature · 6 lines
2.26.0 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
PATCH v2 1/2 uacce: Remove mm_exit() op
The mm_exit() op will be removed from the SVA API. When a process dies and its mm goes away, the IOMMU driver won't notify device drivers anymore. Drivers should expect to handle a lot more aborted DMA. On the upside, it does greatly simplify the queue management.
The uacce_mm struct, that tracks all queues bound to an mm, was only used by the mm_exit() callback. Remove it.
---v1->v2: clear q->handle after unbind
--- include/linux/uacce.h | 34 ++------ drivers/misc/uacce/uacce.c | 172 +++++++++---------------------------- 2 files changed, 51 insertions(+), 155 deletions(-)
include/linux/uacce.h +9 -25
@@ -68,19 +68,21 @@ enum uacce_q_state {* @uacce: pointer to uacce * @priv: private pointer * @wait: wait queue head -* @list: index into uacce_mm -* @uacce_mm: the corresponding mm +* @list: index into uacce queues list * @qfrs: pointer of qfr regions * @state: queue state machine +* @pasid: pasid associated to the mm +* @handle: iommu_sva handle returned by iommu_sva_bind_device() */ struct uacce_queue {struct uacce_device *uacce;void *priv;wait_queue_head_t wait;struct list_head list; -struct uacce_mm *uacce_mm;struct uacce_qfile_region *qfrs[UACCE_MAX_REGION ];enum uacce_q_state state; +int pasid; +struct iommu_sva *handle; };/**
@@ -96,8 +98,8 @@ struct uacce_queue {* @cdev: cdev of the uacce * @dev: dev of the uacce * @priv: private pointer of the uacce -* @mm_list: list head of uacce_mm->list -* @mm_lock: lock for mm_list +* @queues: list of queues +* @queues_lock: lock for queues list * @inode: core vfs */ struct uacce_device {
@@ -112,27 +114,9 @@ struct uacce_device {struct cdev *cdev;struct device dev;void *priv; -struct list_head mm_list; -struct mutex mm_lock; -struct inode *inode; -}; - -/** -* struct uacce_mm - keep track of queues bound to a process -* @list: index into uacce_device -* @queues: list of queues -* @mm: the mm struct -* @lock: protects the list of queues -* @pasid: pasid of the uacce_mm -* @handle: iommu_sva handle return from iommu_sva_bind_device -*/ -struct uacce_mm { -struct list_head list;struct list_head queues; -struct mm_struct *mm; -struct mutex lock; -int pasid; -struct iommu_sva *handle; +struct mutex queues_lock; +struct inode *inode; };#if IS_ENABLED (CONFIG_UACCE )
drivers/misc/uacce/uacce.c +42 -130
238 lines not on this page · raw message
Signature · 6 lines
2.26.0 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
Re: [PATCH v2 1/2] uacce: Remove mm_exit() op
Quoted 9 lines · Jean-Philippe Brucker
The
mm_exit()op will be removed from the SVA API. When a process dies and its mm goes away, the IOMMU driver won't notify device drivers anymore. Drivers should expect to handle a lot more aborted DMA. On the upside, it does greatly simplify the queue management.The
uacce_mmstruct, that tracks all queues bound to an mm, was only used by themm_exit()callback. Remove it.Signed-off-by Jean-Philippe Brucker <[email protected]>
Thanks Jean
Quoted 2 lines
---
v1->v2: clearq->handleafter unbind
Thanks
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
PATCH v2 2/2 iommu: Remove iommu_sva_ops::mm_exit()
In reply to Jean-Philippe BruckerAfter binding a device to an mm, device drivers currently need to register a mm_exit handler. This function is called when the mm exits, to gracefully stop DMA targeting the address space and flush page faults to the IOMMU.
This is deemed too complex for the MMU release() notifier, which may be triggered by any mmput() invocation, from about 120 callsites [1]. The upcoming SVA module has an example of such complexity: the I/O Page Fault handler would need to call mmput_async() instead of mmput() after handling an IOPF, to avoid triggering the release() notifier which would in turn drain the IOPF queue and lock up.
Another concern is the DMA stop function taking too long, up to several minutes [2]. For some mmput() callers this may disturb other users. For example, if the OOM killer picks the mm bound to a device as the victim and that mm's memory is locked, if the release() takes too long, it might choose additional innocent victims to kill.
To simplify the MMU release notifier, don't forward the notification to device drivers. Since they don't stop DMA on mm exit anymore, the PASID lifetime is extended:
(1) The device driver calls bind(). A PASID is allocated.
Here any DMA fault is handled by mm, and on error we don't print anything to dmesg. Userspace can easily trigger errors by issuing DMA on unmapped buffers.
(2) exit_mmap(), for example the process took a SIGKILL. This step doesn't happen during normal operations. Remove the pgd from the PASID table, since the page tables are about to be freed. Invalidate the IOTLBs.
Here the device may still perform DMA on the address space. Incoming transactions are aborted but faults aren't printed out. ATS Translation Requests return Successful Translation Completions with R=W=0. PRI Page Requests return with Invalid Request.
(3) The device driver stops DMA, possibly following release of a fd, and calls unbind(). PASID table is cleared, IOTLB invalidated if necessary. The page fault queues are drained, and the PASID is freed.
If DMA for that PASID is still running here, something went seriously wrong and errors should be reported.
For now remove iommu_sva_ops entirely. We might need to re-introduce them at some point, for example to notify device drivers of unhandled IOPF.
[1] https://lore.kernel.org/linux-iommu/[email protected]/
[2] https://lore.kernel.org/linux-iommu/[email protected]/
---v1->v2: tried to clarify the lifetime of the PASID
--- include/linux/iommu.h | 30 ------------------------------ drivers/iommu/iommu.c | 11 ----------- 2 files changed, 41 deletions(-)
include/linux/iommu.h +0 -30
@@ -53,8 +53,6 @@ struct iommu_fault_event;typedef int (*iommu_fault_handler_t )(struct iommu_domain *,struct device *,unsigned long ,int ,void *); -typedef int (*iommu_mm_exit_handler_t )(struct device *dev,struct iommu_sva *, -void *);typedef int (*iommu_dev_fault_handler_t )(struct iommu_fault *,void *);struct iommu_domain_geometry {
@@ -171,25 +169,6 @@ enum iommu_dev_features {#define IOMMU_PASID_INVALID (-1U) -/** -* struct iommu_sva_ops - device driver callbacks for an SVA context -* -* @mm_exit: called when the mm 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 @mm_exit handler is allowed to sleep. Be careful about the -* locks taken in @mm_exit, because they might lead to deadlocks if -* they are also held when dropping references to the mm. Consider the -* following call chain: -* mutex_lock(A); mmput(mm) -> exit_mm() -> @mm_exit() -> mutex_lock(A) -* Using mmput_async() prevents this scenario. -* -*/ -struct iommu_sva_ops { -iommu_mm_exit_handler_t mm_exit; -}; -#ifdef CONFIG_IOMMU_API /**
@@ -605,7 +584,6 @@ struct iommu_fwspec {*/ struct iommu_sva {struct device *dev; -const struct iommu_sva_ops *ops; }; int iommu_fwspec_init(struct device *dev, struct fwnode_handle *iommu_fwnode,
@@ -653,8 +631,6 @@ struct iommu_sva *iommu_sva_bind_device(struct device *dev,struct mm_struct *mm, void *drvdata);void iommu_sva_unbind_device (struct iommu_sva *handle); -int iommu_sva_set_ops (struct iommu_sva *handle, -const struct iommu_sva_ops *ops);int iommu_sva_get_pasid (struct iommu_sva *handle);#else /* CONFIG_IOMMU_API */
@@ -1058,12 +1034,6 @@ static inline void iommu_sva_unbind_device(struct iommu_sva *handle) { } -static inline int iommu_sva_set_ops (struct iommu_sva *handle, -const struct iommu_sva_ops *ops) -{ -return -EINVAL ; -} -static inline int iommu_sva_get_pasid (struct iommu_sva *handle) {return IOMMU_PASID_INVALID ;
drivers/iommu/iommu.c +0 -11
@@ -2637,17 +2637,6 @@ void iommu_sva_unbind_device(struct iommu_sva *handle) }EXPORT_SYMBOL_GPL (iommu_sva_unbind_device); -int iommu_sva_set_ops (struct iommu_sva *handle, -const struct iommu_sva_ops *sva_ops) -{ -if (handle->ops && handle->ops != sva_ops) -return -EEXIST ; - - handle->ops = sva_ops; -return 0 ; -} -EXPORT_SYMBOL_GPL (iommu_sva_set_ops); -int iommu_sva_get_pasid (struct iommu_sva *handle) {const struct iommu_ops *ops = handle->dev->bus->iommu_ops;
Signature · 6 lines
2.26.0 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
Hi Joerg,
I was wondering if you could take these two patches for v5.8. The API change is a precursor for the SVA support in SMMUv3, and the VT-d implementation of the SVA API (queued for 5.8) doesn't implement iommu_sva_ops.
Thanks,
Jean
Quoted 11 lines · Jean-Philippe Brucker
The IOMMU SVA API currently requires device drivers to implement an
mm_exit()callback, which stops device jobs that do DMA. This function is called in therelease()MMU notifier, when an address space that is shared with a device exits.It has been noted several time during discussions about SVA that cancelling DMA jobs can be slow and complex, and doing it in the
release()notifier might cause synchronization issues. Device drivers must in any case callunbind()to remove their bond, after stopping DMA from a more favorable context (release of a file descriptor).
Quoted 3 lines
Patch 1 removes the
mm_exit()callback from the uacce module, and patch 2 removes it from the IOMMU API. Since v1 [1] I fixed the uacce unbind reported by Zhangfei and added details in the commit message of patch 2.
[1] https://lore.kernel.org/linux-iommu/[email protected]/
Quoted 4 lines
Jean-Philippe Brucker (2):
uacce: Removemm_exit()op
iommu: Removeiommu_sva_ops::mm_exit()
Quoted 9 lines
include/linux/iommu.h | 30 ------- include/linux/uacce.h | 34 ++------ drivers/iommu/iommu.c | 11 --- drivers/misc/uacce/uacce.c | 172 +++++++++---------------------------- 4 files changed, 51 insertions(+), 196 deletions(-)Signature · 1 line
2.26.0
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Joerg Roedel
maintainerHi Jean-Philippe,
Quoted 4 lines · Jean-Philippe Brucker
I was wondering if you could take these two patches for v5.8. The API change is a precursor for the SVA support in SMMUv3, and the VT-d implementation of the SVA API (queued for 5.8) doesn't implement
iommu_sva_ops.
I'd like some Acks on patch 2 (at least from the Intel people) before going ahead with this.
Regards,
Joerg
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Lu Baolu
Acked-byHi Jorge,
Quoted 11 lines · Joerg Roedel
Hi Jean-Philippe,
Quoted 4 lines · Jean-Philippe Brucker
I was wondering if you could take these two patches for v5.8. The API change is a precursor for the SVA support in SMMUv3, and the VT-d implementation of the SVA API (queued for 5.8) doesn't implement
iommu_sva_ops.I'd like some Acks on patch 2 (at least from the Intel people) before going ahead with this.
Patch 2 in this series looks good to me.
+Jacob, he participated in the discussions.
Best regards,
baolu
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Sorry for the typo.
Quoted 1 line · Lu Baolu
Hi Jorge,
^^^^^
JoergQuoted 14 lines · Joerg Roedel
Quoted 11 lines
Hi Jean-Philippe,
Quoted 4 lines · Jean-Philippe Brucker
I was wondering if you could take these two patches for v5.8. The API change is a precursor for the SVA support in SMMUv3, and the VT-d implementation of the SVA API (queued for 5.8) doesn't implement
iommu_sva_ops.I'd like some Acks on patch 2 (at least from the Intel people) before going ahead with this.
Quoted 8 lines
Patch 2 in this series looks good to me.
Acked-by Lu Baolu <[email protected]>+Jacob, he participated in the discussions.
Best regards,
baolu
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Jacob Pan
Acked-byQuoted 16 lines · On Thu, 28 May 2020 11:32:50 +0800 Lu Baolu <[email protected]> wrote:
Hi Jorge,
Quoted 4 lines · Joerg Roedel
Hi Jean-Philippe,
On Wed, May 27, 2020 at 12:10:38PM +0200, Jean-Philippe Brucker wrote:
Quoted 8 lines
Quoted 4 lines
I was wondering if you could take these two patches for v5.8. The API change is a precursor for the SVA support in SMMUv3, and the VT-d implementation of the SVA API (queued for 5.8) doesn't implement
iommu_sva_ops.I'd like some Acks on patch 2 (at least from the Intel people) before going ahead with this.
Quoted 6 lines
Patch 2 in this series looks good to me.
Acked-by Lu Baolu <[email protected]>+Jacob, he participated in the discussions.
Patch 2 looks good to me, VT-d has a similar flow and challenge to stop DMA in mm_exit. We disable fault reporting during this window between mm_exit and FD close trigged unbind.
Quoted 2 lines
Best regards,
baolu
[Jacob Pan]
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Joerg Roedel
maintainerQuoted 11 lines · Jean-Philippe Brucker
The IOMMU SVA API currently requires device drivers to implement an
mm_exit()callback, which stops device jobs that do DMA. This function is called in therelease()MMU notifier, when an address space that is shared with a device exits.It has been noted several time during discussions about SVA that cancelling DMA jobs can be slow and complex, and doing it in the
release()notifier might cause synchronization issues. Device drivers must in any case callunbind()to remove their bond, after stopping DMA from a more favorable context (release of a file descriptor).
Quoted 7 lines
Patch 1 removes the
mm_exit()callback from the uacce module, and patch 2 removes it from the IOMMU API. Since v1 [1] I fixed the uacce unbind reported by Zhangfei and added details in the commit message of patch 2.Jean-Philippe Brucker (2):
uacce: Removemm_exit()op
iommu: Removeiommu_sva_ops::mm_exit()
Applied, thanks.
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu