History

Merge tag 'iommu-updates-v5.3' of git://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu

Pull iommu updates from Joerg Roedel: - Make the dma-iommu code more generic so that it can be used outside of the ARM context with other IOMMU drivers. Goal is to make use of it on x86 too. - Generic IOMMU domain support for the Intel VT-d driver. This driver now makes more use of common IOMMU code to allocate default domains for the devices it handles. - An IOMMU fault reporting API to userspace. With that the IOMMU fault handling can be done in user-space, for example to forward the faults to a VM. - Better handling for reserved regions requested by the firmware. These can be 'relaxed' now, meaning that those don't prevent a device being attached to a VM. - Suspend/Resume support for the Renesas IOMMU driver. - Added support for dumping SVA related fields of the DMAR table in the Intel VT-d driver via debugfs. - A pile of smaller fixes and cleanups. * tag 'iommu-updates-v5.3' of git://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu: (90 commits) iommu/omap: No need to check return value of debugfs_create functions iommu/arm-smmu-v3: Invalidate ATC when detaching a device iommu/arm-smmu-v3: Fix compilation when CONFIG_CMA=n iommu/vt-d: Cleanup unused variable iommu/amd: Flush not present cache in iommu_map_page iommu/amd: Only free resources once on init error iommu/amd: Move gart fallback to amd_iommu_init iommu/amd: Make iommu_disable safer iommu/io-pgtable: Support non-coherent page tables iommu/io-pgtable: Replace IO_PGTABLE_QUIRK_NO_DMA with specific flag iommu/io-pgtable-arm: Add support to use system cache iommu/arm-smmu-v3: Increase maximum size of queues iommu/vt-d: Silence a variable set but not used iommu/vt-d: Remove an unused variable "length" iommu: Fix integer truncation iommu: Add padding to struct iommu_fault iommu/vt-d: Consolidate domain_init() to avoid duplication iommu/vt-d: Cleanup after delegating DMA domain to generic iommu iommu/vt-d: Fix suspicious RCU usage in probe_acpi_namespace_devices() iommu/vt-d: Allow DMA domain attaching to rmrr locked device ...

Linus Torvalds committed 7 years ago

Commit 6b040142 parents c6b6ceb d95c38826 files · +1772 −1301Browse files

Showing the changes to include/linux (6 of 26 files). Show all

Unified · Split

6 files
  1. include/linux/device.h +3 −0
  2. include/linux/dma-iommu.h +5 −44
  3. include/linux/intel-iommu.h +6 −1
  4. include/linux/intel-svm.h +1 −1
  5. include/linux/io-pgtable.h +4 −7
  6. include/linux/iommu.h +105 −0
include/linux/device.h+3−0
@@ -42,6 +42,7 @@ struct iommu_ops; · 41 unmodified lines
4242 struct iommu_group;
4343 struct iommu_fwspec;
4444 struct dev_pin_info;
45+struct iommu_param;
4546
4647 struct bus_attribute {
4748 struct attribute attr;
@@ -961,6 +962,7 @@ struct dev_links_info { · 913 unmodified lines
961962 * device (i.e. the bus driver that discovered the device).
962963 * @iommu_group: IOMMU group the device belongs to.
963964 * @iommu_fwspec: IOMMU-specific properties supplied by firmware.
965+ * @iommu_param: Per device generic IOMMU runtime data
964966 *
965967 * @offline_disabled: If set, the device is permanently online.
966968 * @offline: Set after successful invocation of bus type's .offline().
@@ -1054,6 +1056,7 @@ struct device { · 87 unmodified lines
10541056 void (*release)(struct device *dev);
10551057 struct iommu_group *iommu_group;
10561058 struct iommu_fwspec *iommu_fwspec;
1059+ struct iommu_param *iommu_param;
10571060
10581061 bool offline_disabled:1;
10591062 bool offline:1;
include/linux/dma-iommu.h+5−44
@@ -5,59 +5,21 @@ · 4 unmodified lines
55 #ifndef __DMA_IOMMU_H
66 #define __DMA_IOMMU_H
77
8−#ifdef __KERNEL__
8+#include <linux/errno.h>
99 #include <linux/types.h>
10−#include <asm/errno.h>
1110
1211 #ifdef CONFIG_IOMMU_DMA
1312 #include <linux/dma-mapping.h>
1413 #include <linux/iommu.h>
1514 #include <linux/msi.h>
1615
17−int iommu_dma_init(void);
18−
1916 /* Domain management interface for IOMMU drivers */
2017 int iommu_get_dma_cookie(struct iommu_domain *domain);
2118 int iommu_get_msi_cookie(struct iommu_domain *domain, dma_addr_t base);
2219 void iommu_put_dma_cookie(struct iommu_domain *domain);
2320
2421 /* Setup call for arch DMA mapping code */
25−int iommu_dma_init_domain(struct iommu_domain *domain, dma_addr_t base,
26− u64 size, struct device *dev);
27−
28−/* General helpers for DMA-API <-> IOMMU-API interaction */
29−int dma_info_to_prot(enum dma_data_direction dir, bool coherent,
30− unsigned long attrs);
31−
32−/*
33− * These implement the bulk of the relevant DMA mapping callbacks, but require
34− * the arch code to take care of attributes and cache maintenance
35− */
36−struct page **iommu_dma_alloc(struct device *dev, size_t size, gfp_t gfp,
37− unsigned long attrs, int prot, dma_addr_t *handle,
38− void (*flush_page)(struct device *, const void *, phys_addr_t));
39−void iommu_dma_free(struct device *dev, struct page **pages, size_t size,
40− dma_addr_t *handle);
41−
42−int iommu_dma_mmap(struct page **pages, size_t size, struct vm_area_struct *vma);
43−
44−dma_addr_t iommu_dma_map_page(struct device *dev, struct page *page,
45− unsigned long offset, size_t size, int prot);
46−int iommu_dma_map_sg(struct device *dev, struct scatterlist *sg,
47− int nents, int prot);
48−
49−/*
50− * Arch code with no special attribute handling may use these
51− * directly as DMA mapping callbacks for simplicity
52− */
53−void iommu_dma_unmap_page(struct device *dev, dma_addr_t handle, size_t size,
54− enum dma_data_direction dir, unsigned long attrs);
55−void iommu_dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nents,
56− enum dma_data_direction dir, unsigned long attrs);
57−dma_addr_t iommu_dma_map_resource(struct device *dev, phys_addr_t phys,
58− size_t size, enum dma_data_direction dir, unsigned long attrs);
59−void iommu_dma_unmap_resource(struct device *dev, dma_addr_t handle,
60− size_t size, enum dma_data_direction dir, unsigned long attrs);
22+void iommu_setup_dma_ops(struct device *dev, u64 dma_base, u64 size);
6123
6224 /* The DMA API isn't _quite_ the whole story, though... */
6325 /*
@@ -75,16 +37,16 @@ void iommu_dma_compose_msi_msg(struct msi_desc *desc, · 11 unmodified lines
7537
7638 void iommu_dma_get_resv_regions(struct device *dev, struct list_head *list);
7739
78−#else
40+#else /* CONFIG_IOMMU_DMA */
7941
8042 struct iommu_domain;
8143 struct msi_desc;
8244 struct msi_msg;
8345 struct device;
8446
85−static inline int iommu_dma_init(void)
47+static inline void iommu_setup_dma_ops(struct device *dev, u64 dma_base,
48+ u64 size)
8649 {
87− return 0;
8850 }
8951
9052 static inline int iommu_get_dma_cookie(struct iommu_domain *domain)
@@ -117,5 +79,4 @@ static inline void iommu_dma_get_resv_regions(struct device *dev, struct list_he · 26 unmodified lines
11779 }
11880
11981 #endif /* CONFIG_IOMMU_DMA */
120−#endif /* __KERNEL__ */
12182 #endif /* __DMA_IOMMU_H */
include/linux/intel-iommu.h+6−1
@@ -435,6 +435,12 @@ enum { · 434 unmodified lines
435435 #define VTD_FLAG_TRANS_PRE_ENABLED (1 << 0)
436436 #define VTD_FLAG_IRQ_REMAP_PRE_ENABLED (1 << 1)
437437
438+extern int intel_iommu_sm;
439+
440+#define sm_supported(iommu) (intel_iommu_sm && ecap_smts((iommu)->ecap))
441+#define pasid_supported(iommu) (sm_supported(iommu) && \
442+ ecap_pasid((iommu)->ecap))
443+
438444 struct pasid_entry;
439445 struct pasid_state_entry;
440446 struct page_req_dsc;
@@ -642,7 +648,6 @@ extern int qi_submit_sync(struct qi_desc *desc, struct intel_iommu *iommu); · 201 unmodified lines
642648
643649 extern int dmar_ir_support(void);
644650
645−struct dmar_domain *get_valid_domain_for_dev(struct device *dev);
646651 void *alloc_pgtable_page(int node);
647652 void free_pgtable_page(void *vaddr);
648653 struct intel_iommu *domain_get_iommu(struct dmar_domain *domain);
include/linux/intel-svm.h+1−1
@@ -49,7 +49,7 @@ struct svm_dev_ops { · 48 unmodified lines
4949
5050 /**
5151 * intel_svm_bind_mm() - Bind the current process to a PASID
52− * @dev: Device to be granted acccess
52+ * @dev: Device to be granted access
5353 * @pasid: Address for allocated PASID
5454 * @flags: Flags. Later for requesting supervisor mode, etc.
5555 * @ops: Callbacks to device driver
include/linux/io-pgtable.h+4−7
@@ -44,6 +44,8 @@ struct iommu_gather_ops { · 43 unmodified lines
4444 * tables.
4545 * @ias: Input address (iova) size, in bits.
4646 * @oas: Output address (paddr) size, in bits.
47+ * @coherent_walk A flag to indicate whether or not page table walks made
48+ * by the IOMMU are coherent with the CPU caches.
4749 * @tlb: TLB management callbacks for this set of tables.
4850 * @iommu_dev: The device representing the DMA configuration for the
4951 * page table walker.
@@ -68,11 +70,6 @@ struct io_pgtable_cfg { · 18 unmodified lines
6870 * when the SoC is in "4GB mode" and they can only access the high
6971 * remap of DRAM (0x1_00000000 to 0x1_ffffffff).
7072 *
71− * IO_PGTABLE_QUIRK_NO_DMA: Guarantees that the tables will only ever
72− * be accessed by a fully cache-coherent IOMMU or CPU (e.g. for a
73− * software-emulated IOMMU), such that pagetable updates need not
74− * be treated as explicit DMA data.
75− *
7673 * IO_PGTABLE_QUIRK_NON_STRICT: Skip issuing synchronous leaf TLBIs
7774 * on unmap, for DMA domains using the flush queue mechanism for
7875 * delayed invalidation.
@@ -81,12 +78,12 @@ struct io_pgtable_cfg { · 2 unmodified lines
8178 #define IO_PGTABLE_QUIRK_NO_PERMS BIT(1)
8279 #define IO_PGTABLE_QUIRK_TLBI_ON_MAP BIT(2)
8380 #define IO_PGTABLE_QUIRK_ARM_MTK_4GB BIT(3)
84− #define IO_PGTABLE_QUIRK_NO_DMA BIT(4)
85− #define IO_PGTABLE_QUIRK_NON_STRICT BIT(5)
81+ #define IO_PGTABLE_QUIRK_NON_STRICT BIT(4)
8682 unsigned long quirks;
8783 unsigned long pgsize_bitmap;
8884 unsigned int ias;
8985 unsigned int oas;
86+ bool coherent_walk;
9087 const struct iommu_gather_ops *tlb;
9188 struct device *iommu_dev;
9289
include/linux/iommu.h+105−0
@@ -13,6 +13,7 @@ · 12 unmodified lines
1313 #include <linux/errno.h>
1414 #include <linux/err.h>
1515 #include <linux/of.h>
16+#include <uapi/linux/iommu.h>
1617
1718 #define IOMMU_READ (1 << 0)
1819 #define IOMMU_WRITE (1 << 1)
@@ -29,6 +30,12 @@ · 10 unmodified lines
2930 * if the IOMMU page table format is equivalent.
3031 */
3132 #define IOMMU_PRIV (1 << 5)
33+/*
34+ * Non-coherent masters on few Qualcomm SoCs can use this page protection flag
35+ * to set correct cacheability attributes to use an outer level of cache -
36+ * last level cache, aka system cache.
37+ */
38+#define IOMMU_QCOM_SYS_CACHE (1 << 6)
3239
3340 struct iommu_ops;
3441 struct iommu_group;
@@ -37,6 +44,7 @@ struct device; · 2 unmodified lines
3744 struct iommu_domain;
3845 struct notifier_block;
3946 struct iommu_sva;
47+struct iommu_fault_event;
4048
4149 /* iommu fault flags */
4250 #define IOMMU_FAULT_READ 0x0
@@ -46,6 +54,7 @@ typedef int (*iommu_fault_handler_t)(struct iommu_domain *, · 3 unmodified lines
4654 struct device *, unsigned long, int, void *);
4755 typedef int (*iommu_mm_exit_handler_t)(struct device *dev, struct iommu_sva *,
4856 void *);
57+typedef int (*iommu_dev_fault_handler_t)(struct iommu_fault *, void *);
4958
5059 struct iommu_domain_geometry {
5160 dma_addr_t aperture_start; /* First address that can be mapped */
@@ -123,6 +132,12 @@ enum iommu_attr { · 71 unmodified lines
123132 enum iommu_resv_type {
124133 /* Memory regions which must be mapped 1:1 at all times */
125134 IOMMU_RESV_DIRECT,
135+ /*
136+ * Memory regions which are advertised to be 1:1 but are
137+ * commonly considered relaxable in some conditions,
138+ * for instance in device assignment use case (USB, Graphics)
139+ */
140+ IOMMU_RESV_DIRECT_RELAXABLE,
126141 /* Arbitrary "never map this or give it to a device" address ranges */
127142 IOMMU_RESV_RESERVED,
128143 /* Hardware MSI region (untranslated) */
@@ -212,6 +227,7 @@ struct iommu_sva_ops { · 83 unmodified lines
212227 * @sva_bind: Bind process address space to device
213228 * @sva_unbind: Unbind process address space from device
214229 * @sva_get_pasid: Get PASID associated to a SVA handle
230+ * @page_response: handle page request response
215231 * @pgsize_bitmap: bitmap of all possible supported page sizes
216232 */
217233 struct iommu_ops {
@@ -272,6 +288,10 @@ struct iommu_ops { · 54 unmodified lines
272288 void (*sva_unbind)(struct iommu_sva *handle);
273289 int (*sva_get_pasid)(struct iommu_sva *handle);
274290
291+ int (*page_response)(struct device *dev,
292+ struct iommu_fault_event *evt,
293+ struct iommu_page_response *msg);
294+
275295 unsigned long pgsize_bitmap;
276296 };
277297
@@ -289,6 +309,48 @@ struct iommu_device { · 11 unmodified lines
289309 struct device *dev;
290310 };
291311
312+/**
313+ * struct iommu_fault_event - Generic fault event
314+ *
315+ * Can represent recoverable faults such as a page requests or
316+ * unrecoverable faults such as DMA or IRQ remapping faults.
317+ *
318+ * @fault: fault descriptor
319+ * @list: pending fault event list, used for tracking responses
320+ */
321+struct iommu_fault_event {
322+ struct iommu_fault fault;
323+ struct list_head list;
324+};
325+
326+/**
327+ * struct iommu_fault_param - per-device IOMMU fault data
328+ * @handler: Callback function to handle IOMMU faults at device level
329+ * @data: handler private data
330+ * @faults: holds the pending faults which needs response
331+ * @lock: protect pending faults list
332+ */
333+struct iommu_fault_param {
334+ iommu_dev_fault_handler_t handler;
335+ void *data;
336+ struct list_head faults;
337+ struct mutex lock;
338+};
339+
340+/**
341+ * struct iommu_param - collection of per-device IOMMU data
342+ *
343+ * @fault_param: IOMMU detected device fault reporting data
344+ *
345+ * TODO: migrate other per device data pointers under iommu_dev_data, e.g.
346+ * struct iommu_group *iommu_group;
347+ * struct iommu_fwspec *iommu_fwspec;
348+ */
349+struct iommu_param {
350+ struct mutex lock;
351+ struct iommu_fault_param *fault_param;
352+};
353+
292354 int iommu_device_register(struct iommu_device *iommu);
293355 void iommu_device_unregister(struct iommu_device *iommu);
294356 int iommu_device_sysfs_add(struct iommu_device *iommu,
@@ -350,6 +412,7 @@ extern void iommu_set_fault_handler(struct iommu_domain *domain, · 55 unmodified lines
350412 extern void iommu_get_resv_regions(struct device *dev, struct list_head *list);
351413 extern void iommu_put_resv_regions(struct device *dev, struct list_head *list);
352414 extern int iommu_request_dm_for_dev(struct device *dev);
415+extern int iommu_request_dma_domain_for_dev(struct device *dev);
353416 extern struct iommu_resv_region *
354417 iommu_alloc_resv_region(phys_addr_t start, size_t length, int prot,
355418 enum iommu_resv_type type);
@@ -378,6 +441,17 @@ extern int iommu_group_register_notifier(struct iommu_group *group, · 22 unmodified lines
378441 struct notifier_block *nb);
379442 extern int iommu_group_unregister_notifier(struct iommu_group *group,
380443 struct notifier_block *nb);
444+extern int iommu_register_device_fault_handler(struct device *dev,
445+ iommu_dev_fault_handler_t handler,
446+ void *data);
447+
448+extern int iommu_unregister_device_fault_handler(struct device *dev);
449+
450+extern int iommu_report_device_fault(struct device *dev,
451+ struct iommu_fault_event *evt);
452+extern int iommu_page_response(struct device *dev,
453+ struct iommu_page_response *msg);
454+
381455 extern int iommu_group_id(struct iommu_group *group);
382456 extern struct iommu_group *iommu_group_get_for_dev(struct device *dev);
383457 extern struct iommu_domain *iommu_group_default_domain(struct iommu_group *);
@@ -492,6 +566,7 @@ struct iommu_ops {}; · 108 unmodified lines
492566 struct iommu_group {};
493567 struct iommu_fwspec {};
494568 struct iommu_device {};
569+struct iommu_fault_param {};
495570
496571 static inline bool iommu_present(struct bus_type *bus)
497572 {
@@ -614,6 +689,11 @@ static inline int iommu_request_dm_for_dev(struct device *dev) · 116 unmodified lines
614689 return -ENODEV;
615690 }
616691
692+static inline int iommu_request_dma_domain_for_dev(struct device *dev)
693+{
694+ return -ENODEV;
695+}
696+
617697 static inline int iommu_attach_group(struct iommu_domain *domain,
618698 struct iommu_group *group)
619699 {
@@ -685,6 +765,31 @@ static inline int iommu_group_unregister_notifier(struct iommu_group *group, · 65 unmodified lines
685765 return 0;
686766 }
687767
768+static inline
769+int iommu_register_device_fault_handler(struct device *dev,
770+ iommu_dev_fault_handler_t handler,
771+ void *data)
772+{
773+ return -ENODEV;
774+}
775+
776+static inline int iommu_unregister_device_fault_handler(struct device *dev)
777+{
778+ return 0;
779+}
780+
781+static inline
782+int iommu_report_device_fault(struct device *dev, struct iommu_fault_event *evt)
783+{
784+ return -ENODEV;
785+}
786+
787+static inline int iommu_page_response(struct device *dev,
788+ struct iommu_page_response *msg)
789+{
790+ return -ENODEV;
791+}
792+
688793 static inline int iommu_group_id(struct iommu_group *group)
689794 {
690795 return -ENODEV;

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