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 ...
Showing the changes to include/linux (6 of 26 files). Show all
Unified · Split
| @@ -42,6 +42,7 @@ struct iommu_ops; · 41 unmodified lines | ||
| 42 | 42 | struct iommu_group; |
| 43 | 43 | struct iommu_fwspec; |
| 44 | 44 | struct dev_pin_info; |
| 45 | +struct iommu_param; | |
| 45 | 46 | |
| 46 | 47 | struct bus_attribute { |
| 47 | 48 | struct attribute attr; |
| @@ -961,6 +962,7 @@ struct dev_links_info { · 913 unmodified lines | ||
| 961 | 962 | * device (i.e. the bus driver that discovered the device). |
| 962 | 963 | * @iommu_group: IOMMU group the device belongs to. |
| 963 | 964 | * @iommu_fwspec: IOMMU-specific properties supplied by firmware. |
| 965 | + * @iommu_param: Per device generic IOMMU runtime data | |
| 964 | 966 | * |
| 965 | 967 | * @offline_disabled: If set, the device is permanently online. |
| 966 | 968 | * @offline: Set after successful invocation of bus type's .offline(). |
| @@ -1054,6 +1056,7 @@ struct device { · 87 unmodified lines | ||
| 1054 | 1056 | void (*release)(struct device *dev); |
| 1055 | 1057 | struct iommu_group *iommu_group; |
| 1056 | 1058 | struct iommu_fwspec *iommu_fwspec; |
| 1059 | + struct iommu_param *iommu_param; | |
| 1057 | 1060 | |
| 1058 | 1061 | bool offline_disabled:1; |
| 1059 | 1062 | bool offline:1; |
| @@ -5,59 +5,21 @@ · 4 unmodified lines | ||
| 5 | 5 | #ifndef __DMA_IOMMU_H |
| 6 | 6 | #define __DMA_IOMMU_H |
| 7 | 7 | |
| 8 | −#ifdef __KERNEL__ | |
| 8 | +#include <linux/errno.h> | |
| 9 | 9 | #include <linux/types.h> |
| 10 | −#include <asm/errno.h> | |
| 11 | 10 | |
| 12 | 11 | #ifdef CONFIG_IOMMU_DMA |
| 13 | 12 | #include <linux/dma-mapping.h> |
| 14 | 13 | #include <linux/iommu.h> |
| 15 | 14 | #include <linux/msi.h> |
| 16 | 15 | |
| 17 | −int iommu_dma_init(void); | |
| 18 | − | |
| 19 | 16 | /* Domain management interface for IOMMU drivers */ |
| 20 | 17 | int iommu_get_dma_cookie(struct iommu_domain *domain); |
| 21 | 18 | int iommu_get_msi_cookie(struct iommu_domain *domain, dma_addr_t base); |
| 22 | 19 | void iommu_put_dma_cookie(struct iommu_domain *domain); |
| 23 | 20 | |
| 24 | 21 | /* 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); | |
| 61 | 23 | |
| 62 | 24 | /* The DMA API isn't _quite_ the whole story, though... */ |
| 63 | 25 | /* |
| @@ -75,16 +37,16 @@ void iommu_dma_compose_msi_msg(struct msi_desc *desc, · 11 unmodified lines | ||
| 75 | 37 | |
| 76 | 38 | void iommu_dma_get_resv_regions(struct device *dev, struct list_head *list); |
| 77 | 39 | |
| 78 | −#else | |
| 40 | +#else /* CONFIG_IOMMU_DMA */ | |
| 79 | 41 | |
| 80 | 42 | struct iommu_domain; |
| 81 | 43 | struct msi_desc; |
| 82 | 44 | struct msi_msg; |
| 83 | 45 | struct device; |
| 84 | 46 | |
| 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) | |
| 86 | 49 | { |
| 87 | − return 0; | |
| 88 | 50 | } |
| 89 | 51 | |
| 90 | 52 | 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 | ||
| 117 | 79 | } |
| 118 | 80 | |
| 119 | 81 | #endif /* CONFIG_IOMMU_DMA */ |
| 120 | −#endif /* __KERNEL__ */ | |
| 121 | 82 | #endif /* __DMA_IOMMU_H */ |
| @@ -435,6 +435,12 @@ enum { · 434 unmodified lines | ||
| 435 | 435 | #define VTD_FLAG_TRANS_PRE_ENABLED (1 << 0) |
| 436 | 436 | #define VTD_FLAG_IRQ_REMAP_PRE_ENABLED (1 << 1) |
| 437 | 437 | |
| 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 | + | |
| 438 | 444 | struct pasid_entry; |
| 439 | 445 | struct pasid_state_entry; |
| 440 | 446 | struct page_req_dsc; |
| @@ -642,7 +648,6 @@ extern int qi_submit_sync(struct qi_desc *desc, struct intel_iommu *iommu); · 201 unmodified lines | ||
| 642 | 648 | |
| 643 | 649 | extern int dmar_ir_support(void); |
| 644 | 650 | |
| 645 | −struct dmar_domain *get_valid_domain_for_dev(struct device *dev); | |
| 646 | 651 | void *alloc_pgtable_page(int node); |
| 647 | 652 | void free_pgtable_page(void *vaddr); |
| 648 | 653 | struct intel_iommu *domain_get_iommu(struct dmar_domain *domain); |
| @@ -49,7 +49,7 @@ struct svm_dev_ops { · 48 unmodified lines | ||
| 49 | 49 | |
| 50 | 50 | /** |
| 51 | 51 | * 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 | |
| 53 | 53 | * @pasid: Address for allocated PASID |
| 54 | 54 | * @flags: Flags. Later for requesting supervisor mode, etc. |
| 55 | 55 | * @ops: Callbacks to device driver |
| @@ -44,6 +44,8 @@ struct iommu_gather_ops { · 43 unmodified lines | ||
| 44 | 44 | * tables. |
| 45 | 45 | * @ias: Input address (iova) size, in bits. |
| 46 | 46 | * @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. | |
| 47 | 49 | * @tlb: TLB management callbacks for this set of tables. |
| 48 | 50 | * @iommu_dev: The device representing the DMA configuration for the |
| 49 | 51 | * page table walker. |
| @@ -68,11 +70,6 @@ struct io_pgtable_cfg { · 18 unmodified lines | ||
| 68 | 70 | * when the SoC is in "4GB mode" and they can only access the high |
| 69 | 71 | * remap of DRAM (0x1_00000000 to 0x1_ffffffff). |
| 70 | 72 | * |
| 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 | − * | |
| 76 | 73 | * IO_PGTABLE_QUIRK_NON_STRICT: Skip issuing synchronous leaf TLBIs |
| 77 | 74 | * on unmap, for DMA domains using the flush queue mechanism for |
| 78 | 75 | * delayed invalidation. |
| @@ -81,12 +78,12 @@ struct io_pgtable_cfg { · 2 unmodified lines | ||
| 81 | 78 | #define IO_PGTABLE_QUIRK_NO_PERMS BIT(1) |
| 82 | 79 | #define IO_PGTABLE_QUIRK_TLBI_ON_MAP BIT(2) |
| 83 | 80 | #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) | |
| 86 | 82 | unsigned long quirks; |
| 87 | 83 | unsigned long pgsize_bitmap; |
| 88 | 84 | unsigned int ias; |
| 89 | 85 | unsigned int oas; |
| 86 | + bool coherent_walk; | |
| 90 | 87 | const struct iommu_gather_ops *tlb; |
| 91 | 88 | struct device *iommu_dev; |
| 92 | 89 | |
| @@ -13,6 +13,7 @@ · 12 unmodified lines | ||
| 13 | 13 | #include <linux/errno.h> |
| 14 | 14 | #include <linux/err.h> |
| 15 | 15 | #include <linux/of.h> |
| 16 | +#include <uapi/linux/iommu.h> | |
| 16 | 17 | |
| 17 | 18 | #define IOMMU_READ (1 << 0) |
| 18 | 19 | #define IOMMU_WRITE (1 << 1) |
| @@ -29,6 +30,12 @@ · 10 unmodified lines | ||
| 29 | 30 | * if the IOMMU page table format is equivalent. |
| 30 | 31 | */ |
| 31 | 32 | #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) | |
| 32 | 39 | |
| 33 | 40 | struct iommu_ops; |
| 34 | 41 | struct iommu_group; |
| @@ -37,6 +44,7 @@ struct device; · 2 unmodified lines | ||
| 37 | 44 | struct iommu_domain; |
| 38 | 45 | struct notifier_block; |
| 39 | 46 | struct iommu_sva; |
| 47 | +struct iommu_fault_event; | |
| 40 | 48 | |
| 41 | 49 | /* iommu fault flags */ |
| 42 | 50 | #define IOMMU_FAULT_READ 0x0 |
| @@ -46,6 +54,7 @@ typedef int (*iommu_fault_handler_t)(struct iommu_domain *, · 3 unmodified lines | ||
| 46 | 54 | struct device *, unsigned long, int, void *); |
| 47 | 55 | typedef int (*iommu_mm_exit_handler_t)(struct device *dev, struct iommu_sva *, |
| 48 | 56 | void *); |
| 57 | +typedef int (*iommu_dev_fault_handler_t)(struct iommu_fault *, void *); | |
| 49 | 58 | |
| 50 | 59 | struct iommu_domain_geometry { |
| 51 | 60 | dma_addr_t aperture_start; /* First address that can be mapped */ |
| @@ -123,6 +132,12 @@ enum iommu_attr { · 71 unmodified lines | ||
| 123 | 132 | enum iommu_resv_type { |
| 124 | 133 | /* Memory regions which must be mapped 1:1 at all times */ |
| 125 | 134 | 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, | |
| 126 | 141 | /* Arbitrary "never map this or give it to a device" address ranges */ |
| 127 | 142 | IOMMU_RESV_RESERVED, |
| 128 | 143 | /* Hardware MSI region (untranslated) */ |
| @@ -212,6 +227,7 @@ struct iommu_sva_ops { · 83 unmodified lines | ||
| 212 | 227 | * @sva_bind: Bind process address space to device |
| 213 | 228 | * @sva_unbind: Unbind process address space from device |
| 214 | 229 | * @sva_get_pasid: Get PASID associated to a SVA handle |
| 230 | + * @page_response: handle page request response | |
| 215 | 231 | * @pgsize_bitmap: bitmap of all possible supported page sizes |
| 216 | 232 | */ |
| 217 | 233 | struct iommu_ops { |
| @@ -272,6 +288,10 @@ struct iommu_ops { · 54 unmodified lines | ||
| 272 | 288 | void (*sva_unbind)(struct iommu_sva *handle); |
| 273 | 289 | int (*sva_get_pasid)(struct iommu_sva *handle); |
| 274 | 290 | |
| 291 | + int (*page_response)(struct device *dev, | |
| 292 | + struct iommu_fault_event *evt, | |
| 293 | + struct iommu_page_response *msg); | |
| 294 | + | |
| 275 | 295 | unsigned long pgsize_bitmap; |
| 276 | 296 | }; |
| 277 | 297 | |
| @@ -289,6 +309,48 @@ struct iommu_device { · 11 unmodified lines | ||
| 289 | 309 | struct device *dev; |
| 290 | 310 | }; |
| 291 | 311 | |
| 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 | + | |
| 292 | 354 | int iommu_device_register(struct iommu_device *iommu); |
| 293 | 355 | void iommu_device_unregister(struct iommu_device *iommu); |
| 294 | 356 | 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 | ||
| 350 | 412 | extern void iommu_get_resv_regions(struct device *dev, struct list_head *list); |
| 351 | 413 | extern void iommu_put_resv_regions(struct device *dev, struct list_head *list); |
| 352 | 414 | extern int iommu_request_dm_for_dev(struct device *dev); |
| 415 | +extern int iommu_request_dma_domain_for_dev(struct device *dev); | |
| 353 | 416 | extern struct iommu_resv_region * |
| 354 | 417 | iommu_alloc_resv_region(phys_addr_t start, size_t length, int prot, |
| 355 | 418 | enum iommu_resv_type type); |
| @@ -378,6 +441,17 @@ extern int iommu_group_register_notifier(struct iommu_group *group, · 22 unmodified lines | ||
| 378 | 441 | struct notifier_block *nb); |
| 379 | 442 | extern int iommu_group_unregister_notifier(struct iommu_group *group, |
| 380 | 443 | 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 | + | |
| 381 | 455 | extern int iommu_group_id(struct iommu_group *group); |
| 382 | 456 | extern struct iommu_group *iommu_group_get_for_dev(struct device *dev); |
| 383 | 457 | extern struct iommu_domain *iommu_group_default_domain(struct iommu_group *); |
| @@ -492,6 +566,7 @@ struct iommu_ops {}; · 108 unmodified lines | ||
| 492 | 566 | struct iommu_group {}; |
| 493 | 567 | struct iommu_fwspec {}; |
| 494 | 568 | struct iommu_device {}; |
| 569 | +struct iommu_fault_param {}; | |
| 495 | 570 | |
| 496 | 571 | static inline bool iommu_present(struct bus_type *bus) |
| 497 | 572 | { |
| @@ -614,6 +689,11 @@ static inline int iommu_request_dm_for_dev(struct device *dev) · 116 unmodified lines | ||
| 614 | 689 | return -ENODEV; |
| 615 | 690 | } |
| 616 | 691 | |
| 692 | +static inline int iommu_request_dma_domain_for_dev(struct device *dev) | |
| 693 | +{ | |
| 694 | + return -ENODEV; | |
| 695 | +} | |
| 696 | + | |
| 617 | 697 | static inline int iommu_attach_group(struct iommu_domain *domain, |
| 618 | 698 | struct iommu_group *group) |
| 619 | 699 | { |
| @@ -685,6 +765,31 @@ static inline int iommu_group_unregister_notifier(struct iommu_group *group, · 65 unmodified lines | ||
| 685 | 765 | return 0; |
| 686 | 766 | } |
| 687 | 767 | |
| 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 | + | |
| 688 | 793 | static inline int iommu_group_id(struct iommu_group *group) |
| 689 | 794 | { |
| 690 | 795 | return -ENODEV; |