History

iommu: Bind process address spaces to devices

Add bind() and unbind() operations to the IOMMU API. iommu_sva_bind_device() binds a device to an mm, and returns a handle to the bond, which is released by calling iommu_sva_unbind_device(). Each mm bound to devices gets a PASID (by convention, a 20-bit system-wide ID representing the address space), which can be retrieved with iommu_sva_get_pasid(). When programming DMA addresses, device drivers include this PASID in a device-specific manner, to let the device access the given address space. Since the process memory may be paged out, device and IOMMU must support I/O page faults (e.g. PCI PRI). Using iommu_sva_set_ops(), device drivers provide an mm_exit() callback that is called by the IOMMU driver if the process exits before the device driver called unbind(). In mm_exit(), device driver should disable DMA from the given context, so that the core IOMMU can reallocate the PASID. Whether the process exited or nor, the device driver should always release the handle with unbind(). To use these functions, device driver must first enable the IOMMU_DEV_FEAT_SVA device feature with iommu_dev_enable_feature().

Jean-Philippe Brucker committed 7 years ago

Commit 26b25a21 parent a3a19592 files · +174 −0Browse files

Showing the changes to include/linux (1 of 2 files). Show all

Unified · Split

include/linux/iommu.h+70−0
@@ -48,6 +48,7 @@ struct bus_type; · 47 unmodified lines
48struct device;48struct device;
49struct iommu_domain;49struct iommu_domain;
50struct notifier_block;50struct notifier_block;
51struct iommu_sva;
51 52
52/* iommu fault flags */53/* iommu fault flags */
53#define IOMMU_FAULT_READ 0x054#define IOMMU_FAULT_READ 0x0
@@ -55,6 +56,8 @@ struct notifier_block; · 1 unmodified line
55 56
56typedef int (*iommu_fault_handler_t)(struct iommu_domain *,57typedef int (*iommu_fault_handler_t)(struct iommu_domain *,
57 struct device *, unsigned long, int, void *);58 struct device *, unsigned long, int, void *);
59typedef int (*iommu_mm_exit_handler_t)(struct device *dev, struct iommu_sva *,
60 void *);
58 61
59struct iommu_domain_geometry {62struct iommu_domain_geometry {
60 dma_addr_t aperture_start; /* First address that can be mapped */63 dma_addr_t aperture_start; /* First address that can be mapped */
@@ -159,6 +162,28 @@ struct iommu_resv_region { · 98 unmodified lines
159/* Per device IOMMU features */162/* Per device IOMMU features */
160enum iommu_dev_features {163enum iommu_dev_features {
161 IOMMU_DEV_FEAT_AUX, /* Aux-domain feature */164 IOMMU_DEV_FEAT_AUX, /* Aux-domain feature */
165 IOMMU_DEV_FEAT_SVA, /* Shared Virtual Addresses */
166};
167
168#define IOMMU_PASID_INVALID (-1U)
169
170/**
171 * struct iommu_sva_ops - device driver callbacks for an SVA context
172 *
173 * @mm_exit: called when the mm is about to be torn down by exit_mmap. After
174 * @mm_exit returns, the device must not issue any more transaction
175 * with the PASID given as argument.
176 *
177 * The @mm_exit handler is allowed to sleep. Be careful about the
178 * locks taken in @mm_exit, because they might lead to deadlocks if
179 * they are also held when dropping references to the mm. Consider the
180 * following call chain:
181 * mutex_lock(A); mmput(mm) -> exit_mm() -> @mm_exit() -> mutex_lock(A)
182 * Using mmput_async() prevents this scenario.
183 *
184 */
185struct iommu_sva_ops {
186 iommu_mm_exit_handler_t mm_exit;
162};187};
163 188
164#ifdef CONFIG_IOMMU_API189#ifdef CONFIG_IOMMU_API
@@ -196,6 +221,9 @@ enum iommu_dev_features { · 31 unmodified lines
196 * @dev_feat_enabled: check enabled feature221 * @dev_feat_enabled: check enabled feature
197 * @aux_attach/detach_dev: aux-domain specific attach/detach entries.222 * @aux_attach/detach_dev: aux-domain specific attach/detach entries.
198 * @aux_get_pasid: get the pasid given an aux-domain223 * @aux_get_pasid: get the pasid given an aux-domain
224 * @sva_bind: Bind process address space to device
225 * @sva_unbind: Unbind process address space from device
226 * @sva_get_pasid: Get PASID associated to a SVA handle
199 * @pgsize_bitmap: bitmap of all possible supported page sizes227 * @pgsize_bitmap: bitmap of all possible supported page sizes
200 */228 */
201struct iommu_ops {229struct iommu_ops {
@@ -251,6 +279,11 @@ struct iommu_ops { · 49 unmodified lines
251 void (*aux_detach_dev)(struct iommu_domain *domain, struct device *dev);279 void (*aux_detach_dev)(struct iommu_domain *domain, struct device *dev);
252 int (*aux_get_pasid)(struct iommu_domain *domain, struct device *dev);280 int (*aux_get_pasid)(struct iommu_domain *domain, struct device *dev);
253 281
282 struct iommu_sva *(*sva_bind)(struct device *dev, struct mm_struct *mm,
283 void *drvdata);
284 void (*sva_unbind)(struct iommu_sva *handle);
285 int (*sva_get_pasid)(struct iommu_sva *handle);
286
254 unsigned long pgsize_bitmap;287 unsigned long pgsize_bitmap;
255};288};
256 289
@@ -417,6 +450,14 @@ struct iommu_fwspec { · 160 unmodified lines
417 u32 ids[1];450 u32 ids[1];
418};451};
419 452
453/**
454 * struct iommu_sva - handle to a device-mm bond
455 */
456struct iommu_sva {
457 struct device *dev;
458 const struct iommu_sva_ops *ops;
459};
460
420int iommu_fwspec_init(struct device *dev, struct fwnode_handle *iommu_fwnode,461int iommu_fwspec_init(struct device *dev, struct fwnode_handle *iommu_fwnode,
421 const struct iommu_ops *ops);462 const struct iommu_ops *ops);
422void iommu_fwspec_free(struct device *dev);463void iommu_fwspec_free(struct device *dev);
@@ -445,6 +486,14 @@ int iommu_aux_attach_device(struct iommu_domain *domain, struct device *dev); · 22 unmodified lines
445void iommu_aux_detach_device(struct iommu_domain *domain, struct device *dev);486void iommu_aux_detach_device(struct iommu_domain *domain, struct device *dev);
446int iommu_aux_get_pasid(struct iommu_domain *domain, struct device *dev);487int iommu_aux_get_pasid(struct iommu_domain *domain, struct device *dev);
447 488
489struct iommu_sva *iommu_sva_bind_device(struct device *dev,
490 struct mm_struct *mm,
491 void *drvdata);
492void iommu_sva_unbind_device(struct iommu_sva *handle);
493int iommu_sva_set_ops(struct iommu_sva *handle,
494 const struct iommu_sva_ops *ops);
495int iommu_sva_get_pasid(struct iommu_sva *handle);
496
448#else /* CONFIG_IOMMU_API */497#else /* CONFIG_IOMMU_API */
449 498
450struct iommu_ops {};499struct iommu_ops {};
@@ -770,6 +819,27 @@ iommu_aux_get_pasid(struct iommu_domain *domain, struct device *dev) · 319 unmodified lines
770 return -ENODEV;819 return -ENODEV;
771}820}
772 821
822static inline struct iommu_sva *
823iommu_sva_bind_device(struct device *dev, struct mm_struct *mm, void *drvdata)
824{
825 return NULL;
826}
827
828static inline void iommu_sva_unbind_device(struct iommu_sva *handle)
829{
830}
831
832static inline int iommu_sva_set_ops(struct iommu_sva *handle,
833 const struct iommu_sva_ops *ops)
834{
835 return -EINVAL;
836}
837
838static inline int iommu_sva_get_pasid(struct iommu_sva *handle)
839{
840 return IOMMU_PASID_INVALID;
841}
842
773#endif /* CONFIG_IOMMU_API */843#endif /* CONFIG_IOMMU_API */
774 844
775#ifdef CONFIG_IOMMU_DEBUGFS845#ifdef CONFIG_IOMMU_DEBUGFS

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t