[PATCH v3 0/6] Support IOMMU page sizes larger than the CPU page size

Sven Peter via iommu
2021-10-19T16:38:55Z

Hi,

RFC: https://lore.kernel.org/linux-iommu/20210806155523.50429-1-sven@svenpeter.dev/
v2: https://lore.kernel.org/linux-iommu/20210828153642.19396-1-sven@svenpeter.dev/

Time to revive this series:

v2 -> v3:
- Dropped support for untrusted devices since swiotlb currently does not
allow aligning buffers to granularities bigger than PAGE_SIZE.
Getting this to work is possibly but a bit tricky together with min_align_mask.
Right now there are no untrusted device on the M1 anyway and this series already
feels big enough. I've therefore decided to address this in a follow up.
- Replaced phys_to_page with pfn_to_page(PHYS_PFN(..)) since not all architectures
define phys_to_page
- Replaced the PAGE_SIZE > granule check in iommu_check_page_size with
domain->pgsize_bitmap & (PAGE_SIZE | (PAGE_SIZE - 1)) as suggested by Robin
- Rebased on the latest rc which required to introduce sg_alloc_append_table_from_pages
since __sg_alloc_table_from_pages no longer exists

RFC -> v2:
- essentially a comlpetely rewrite of the first approach which just padded every
allocation

Some background: On the Apple M1 the IOMMUs are hardwired to only support 16 KB pages.
We'd still like to boot Linux with 4KB pages though because that's what most distros
ship these days. I've been told this also helps with Android userspace compatibility
and x86 emulation.
This patch series adds support for that setup to the IOMMU DMA API.

This is essentially done by always mapping the encapsulating IOMMU page and adjusting
the returned iova offset. There are also changes to only allow DMA domains to make use
of this and prevent UNMANAGED domains from encountering unexpected situations.

Best,

Sven

Sven Peter (6):
iommu/dma: Disable get_sgtable for granule > PAGE_SIZE
iommu/dma: Support granule > PAGE_SIZE in dma_map_sg
iommu/dma: Support granule > PAGE_SIZE allocations
iommu: Move IOMMU pagesize check to attach_device
iommu: Introduce __IOMMU_DOMAIN_LP
iommu/dart: Remove force_bypass logic

drivers/iommu/apple-dart.c | 14 +---
drivers/iommu/dma-iommu.c | 134 +++++++++++++++++++++++++++++++------
drivers/iommu/iommu.c | 40 ++++++++++-
drivers/iommu/iova.c | 7 +-
include/linux/iommu.h | 18 ++++-
5 files changed, 174 insertions(+), 39 deletions(-)

--
2.25.1