[PATCH v6 0/3] iommu/io-pgtable-arm: Add ARM LPAE contiguous hint support

Vijayanand Jitta vijayanand.jitta at oss.qualcomm.com
Tue Dec 1 01:37:10 PST 2026


To: Will Deacon <will at kernel.org>
To: Robin Murphy <robin.murphy at arm.com>
To: "Joerg Roedel (AMD)" <joro at 8bytes.org>
Cc: linux-arm-msm at vger.kernel.org
Cc: linux-arm-kernel at lists.infradead.org
Cc: iommu at lists.linux.dev
Cc: linux-kernel at vger.kernel.org

This series adds opt-in use of the ARM LPAE contiguous descriptor hint for
Arm SMMU page tables. The hint lets the translation hardware combine an
architecture-defined aligned group of adjacent leaf or block descriptors,
increasing TLB reach while retaining the native descriptor representation.

The first patch adds the generic ARM LPAE io-pgtable support. It exposes a
positive, default-off quirk and derives effective CONT mapping sizes from the
selected native granule. Exact effective-size map and unmap requests expand
to the constituent descriptors, all carrying the CONT bit. TLB invalidation
continues at native descriptor granularity. The implementation rejects
partial CONT-group unmaps, while allowing an aggregate native-size unmap
when it fully contains a group. Hardware dirty tracking disables the opt-in,
since it can update attributes of individual descriptors.

The second and third patches enable the audited opt-in for Arm SMMU v2 and
v3 LPAE page tables respectively. SMMUv2 limits this to version 2 LPAE
formats, leaving v1 and ARMv7s unchanged. SMMUv3 enables it for its S1 and
S2 LPAE tables; ARM_HD retains precedence for dirty-tracking S1 domains.
Panfrost, Panthor, and Mali LPAE do not opt in and remain unchanged.

---
Changes in v6:
- Replace the internal CONT-range promotion scheme with an explicit opt-in
  IO_PGTABLE_QUIRK_ARM_CONT_HINT and advertise effective CONT sizes through
  pgsize_bitmap for generic IOMMU page-size selection.
- Expand effective CONT map and unmap requests into native descriptors;
  retain native-granule TLB invalidation and allow native-size aggregate
  unmaps only when they fully contain a CONT group.
- Disable CONT when ARM hardware dirty tracking is selected, since it can
  update individual descriptor attributes within a CONT group.
- Add separate LPAE CONT opt-ins for Arm SMMU v2 and v3. Keep Panfrost,
  Panthor, and Mali LPAE unchanged.
- Link to v5: https://patch.msgid.link/20260921-iommu_contig_hint-v5-1-e7fbd1c3774d@oss.qualcomm.com

Changes in v5:
- Keep CONT sizes that exactly span the configured IAS or OAS, allowing a
  valid mapping at address zero.
- Derive CONT sizes from the architecture-valid base page-size bitmap and
  constrain the final result by IAS and OAS, replacing the bespoke
  arm_lpae_get_cont_sizes() helpers.
- Guard CONT-size expansion against 32-bit overflow.
- Let callers select exact CONT sizes through pgsize_bitmap, and remove the
  internal prefix/group/suffix promotion path.
- Reject a partial CONT-group unmap before any PTE is cleared, making the
  rejection a complete no-op.
- Link to v4: https://lore.kernel.org/all/20260804-iommu_contig_hint-v4-1-d7a47ed5db98@oss.qualcomm.com/

Changes in v4:
- Merge each run of consecutive aligned (or consecutive non-aligned)
  num_cont windows within arm_lpae_install_leaf() into a single
  arm_lpae_init_pte() call instead of one call per window. idx and
  paddr both advance by block_size per entry, so once a window
  qualifies (or fails to qualify) for the CONT hint, every later whole
  window in the same call does too - collapsing the common fully-
  aligned or fully-unaligned case back down to one call, matching v2's
  call count without reintroducing v2's alignment gaps.
- Fix min_t(int, pgcount, max_entries) truncating pgcount (size_t) to a
  signed int in both __arm_lpae_map() and __arm_lpae_unmap(), which
  could go negative and spin the caller's while (pgcount) loop forever
  for a large enough single request - especially reachable now that
  pgcount is scaled by num_cont (up to 128) for whole-CONT-group
  requests. Compare in size_t via min_t(size_t, ...) instead; the
  result remains bounded by max_entries before being stored back into
  the int num_entries. Reported by the Sashiko AI review bot on v3.
- Stop short of the offending entry instead of returning 0 outright
  when __arm_lpae_unmap() detects a misaligned CONT group mid-loop.
  Earlier entries in the same call may already have had non-leaf
  sub-tables torn down and freed, so returning 0 both under-reports
  the actual unmap progress to the caller and skips the bulk
  clear/gather for those already-freed entries. Breaking out of the
  loop at the current index lets the existing post-loop clear/gather
  path handle entries [0, i) correctly and report i * size unmapped.
  Reported by the Sashiko AI review bot on v3.
- Link to v3: https://lore.kernel.org/all/20260722-iommu_contig_hint-v3-1-10923a683441@oss.qualcomm.com/

Changes in v3:
- Collapse arm_lpae_cont_ptes()/arm_lpae_cont_blks()/
  arm_lpae_cont_pte_size()/arm_lpae_cont_blk_size()/
  arm_lpae_find_num_cont() into a single arm_lpae_num_cont(size_t size)
  helper, since leaf/block/L1-block sizes never overlap across granules.
- Fix arm_lpae_pte_is_contiguous_range() never checking that iova/paddr
  are aligned to the contiguous group size, by removing it entirely -
  __arm_lpae_map()'s new arm_lpae_install_leaf() helper scans for
  aligned sub-chunks and independently verifies paddr alignment for
  each one before applying the CONT hint.
- Fold the CONT case into __arm_lpae_map()'s existing size == block_size
  leaf path instead of duplicating arm_lpae_init_pte() in a separate
  branch. A request whose size exactly matches a whole CONT group is
  normalized down to block_size/scaled pgcount so it reaches that path;
  arm_lpae_install_leaf() then walks the resulting range in chunks,
  tagging only the sub-chunks that are both index-aligned and
  paddr-aligned to the group size, since a single map_pages() call at
  the plain block_size can still contain such an aligned group midway
  through a larger, otherwise ungrouped range.
- Replace the unmap-side WARN_ON_ONCE(!IS_ALIGNED(iova, size)) with a
  check on the actual ARM_LPAE_PTE_CONT bit of the PTEs being cleared.
  The previous check incorrectly warned on any unmap whose size
  happened to numerically match a CONT group size, even when the
  underlying PTEs were never CONT-tagged (e.g. because the original
  iommu_map() wasn't group-aligned), and even though iommu_unmap() can
  legitimately assemble such a size from multiple independent prior
  iommu_map() calls.
- Close a leak where ARM_MALI_LPAE would gain CONT-sized entries in its
  pgsize_bitmap despite the format having no CONT bit, by having
  arm_mali_lpae_alloc_pgtable() set IO_PGTABLE_QUIRK_ARM_NO_CONT_HINT
  internally rather than special-casing the format in the shared
  arm_lpae_restrict_pgsizes()/arm_lpae_get_cont_sizes() path.
- Gate each contiguous-hint size in arm_lpae_get_cont_sizes() on whether
  a single group actually fits within the configured IAS/OAS, so e.g. a
  16G level-1 CONT group is never advertised for an IAS too small to
  address it.
- Link to v2: https://patch.msgid.link/20260721-iommu_contig_hint-v2-1-90c731a41163@oss.qualcomm.com

Changes in v2:
- Extend contiguous hint support to level-1 (1G) blocks for the 4K granule,
  adding a CONT L1 (16G) grouping alongside the existing CONT PTE/CONT Block
  sizes.
- Replace the compile-time CONFIG_IOMMU_IO_PGTABLE_CONTIG_HINT Kconfig option
  with a runtime quirk, IO_PGTABLE_QUIRK_ARM_NO_CONT_HINT, so SMMU drivers
  can opt out per page table instance instead of at build time.
- Simplify __arm_lpae_map() to program the CONT-sized block directly via
  arm_lpae_init_pte() instead of recursing into the next level with an
  adjusted pgcount.
- Reject unmaps that are not aligned to the contiguous group size with
  WARN_ON_ONCE(), instead of clearing the CONT bit on a partial group before
  invalidation.
- Link to v1: https://patch.msgid.link/20260618-iommu_contig_hint-v1-1-4502a59e6388@oss.qualcomm.com

Changes in v1:
- Initial version.

To: Will Deacon <will at kernel.org>
To: Robin Murphy <robin.murphy at arm.com>
To: "Joerg Roedel (AMD)" <joro at 8bytes.org>
Cc: linux-arm-msm at vger.kernel.org
Cc: linux-arm-kernel at lists.infradead.org
Cc: iommu at lists.linux.dev
Cc: linux-kernel at vger.kernel.org

---
Prakash Gupta (1):
      iommu/io-pgtable-arm: Add support for contiguous hint bit

Vijayanand Jitta (2):
      iommu/arm-smmu: Enable contiguous hints for LPAE page tables
      iommu/arm-smmu-v3: Enable contiguous hints for LPAE page tables

 drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c |   2 +
 drivers/iommu/arm/arm-smmu/arm-smmu.c       |   3 +
 drivers/iommu/io-pgtable-arm.c              | 120 ++++++++++++++++++++++++++--
 include/linux/io-pgtable.h                  |   6 ++
 4 files changed, 124 insertions(+), 7 deletions(-)
---
base-commit: 3f2425f5b5bbbdd991ca9cdfd5502e68d8895998
change-id: 20260618-iommu_contig_hint-71ae491fbb52

Best regards,
--  
Vijayanand Jitta <vijayanand.jitta at oss.qualcomm.com>




More information about the linux-arm-kernel mailing list