Skip to content

iommufd: Recommended reservations query and opt-in IOAS reservation

Guanghui Feng kvm linux-iommu lkml 5 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v7 Latest3 patches 1 replyIn review
  2. v63 patches 1 replySuperseded
  3. v53 patches 0 repliesSuperseded
Earlier versions · 2
VersionPostedPatchesRepliesStatus
v42 patches2 repliesSuperseded
v32 patches2 repliesSuperseded

Changes in v7 from the cover letter

- Patch 3: use > ULONG_MAX instead of >= ULONG_MAX for the range bounds check. struct iommu_iova_range is an inclusive [start, last] interval and ULONG_MAX is a valid upper bound (iopt_table_add_domain() reserves up to ULONG_MAX), so >= wrongly rejected ranges ending at ULONG_MAX. Per Jason's review of v6.

Patches in v7 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3iommu: Add iommu_for_each_pci_mmio_window() iteratordrivers/iommu/dma-iommu.c drivers/iommu/iommu-priv.h drivers/iommu/iommu.c+68 -80 replies
2/3iommufd: Add IOMMU_GET_RECOMMENDED_RESERVATIONS ioctldrivers/iommu/iommufd/device.c drivers/iommu/iommufd/iommufd_private.h drivers/iommu/iommufd/main.c +1 more+108 -00 replies
3/3iommufd: Add IOMMU_IOAS_RESERVE_IOVAS ioctldrivers/iommu/iommufd/io_pagetable.c drivers/iommu/iommufd/ioas.c drivers/iommu/iommufd/iommufd_private.h +2 more+95 -20 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v7 yet.

Read the v7 thread

Cover letter [PATCH v7 0/3] iommufd: Recommended reservations query and opt-in IOAS reservation

This series lets userspace learn which IOVA ranges the kernel recommends avoiding for a device, and optionally feed them back so the IOAS allocator enforces them.

The motivating case is a PCI device behind a PCIe switch: DMA using
IOVAs that fall inside the host bridge MMIO windows may be misrouted
as peer-to-peer traffic instead of reaching the root complex for IOMMU
translation. The DMA IOVA layer already avoids these windows
internally, but passthrough userspace had no way to learn about them.
Per commit cd2c9fcf5c66 ("iommu/dma: Move PCI window region reservation back into dma specific path.") this information must not be forced through the IOMMU reserved-region
API, so the series is fully opt-in:

Patch 1 adds iommu_for_each_pci_mmio_window(), a callback-based iterator in the IOMMU core, and refactors dma-iommu.c to share it.

Patch 2 adds IOMMU_GET_RECOMMENDED_RESERVATIONS, a per-device query returning recommended ranges (currently PCI host bridge MMIO windows) as struct iommu_iova_range entries. Advisory only.

Patch 3 adds IOMMU_IOAS_RESERVE_IOVAS, letting userspace send chosen ranges back in to restrict the IOAS allocator: reserved ranges disappear from IOMMU_IOAS_IOVA_RANGES and are rejected by mapping. Overlapping reservations are permitted, so the same ranges recommended for several devices behind one host bridge can each be reserved independently.

Typical flow: bind device -> query recommendations -> reserve chosen ranges -> map. Userspace that ignores the new ioctls sees no behaviour change.

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
[3] https://lore.kernel.org/all/[email protected]/

v6: https://lore.kernel.org/all/[email protected]/
v5: https://lore.kernel.org/all/[email protected]/
v4: https://lore.kernel.org/all/[email protected]/
v3: https://lore.kernel.org/all/[email protected]/
v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/

Changes since v6:
- Patch 3: use > ULONG_MAX instead of >= ULONG_MAX for the range bounds check. struct iommu_iova_range is an inclusive [start, last] interval and ULONG_MAX is a valid upper bound (iopt_table_add_domain() reserves up to ULONG_MAX), so >= wrongly rejected ranges ending at ULONG_MAX. Per Jason's review of v6.

Changes since v5:
- Patch 3: reject ranges with start or last >= ULONG_MAX with -EOVERFLOW, matching the existing checks in IOMMU_IOAS_MAP/UNMAP/ COPY; on 32-bit kernels such ranges would be silently truncated when passed to iopt_reserve_iova(), and a wrapped pair could even insert an inverted node into the reserved interval tree (reported by the Sashiko AI review of v5).
- Patch 3: drop the iommufd_ucmd_respond() call - all fields of struct iommu_ioas_reserve_iovas are inputs and the handler never modifies them, matching iommufd_ioas_allow_iovas() which also returns directly (reported by the Sashiko AI review of v5).

Changes since v4 (all per Jason's review [2][3]):
- Patch 1: drop the single-pointer wrapper struct in dma-iommu.c and pass the iova_domain directly as callback data.
- Patch 1: drop the typedef kdoc and trim the iterator kdoc to the essential description.
- Patch 1: WARN_ON(!bridge) instead of a silent check; inline the start/end temporaries.
- Patch 2: reuse struct iommu_iova_range instead of adding a new per-window struct.
- Patch 2: rename away from PCI-specific naming: the interface is now IOMMU_GET_RECOMMENDED_RESERVATIONS reporting recommended reserved regions, with PCI host bridge MMIO windows as the first source.
- Patch 3 (new): add IOMMU_IOAS_RESERVE_IOVAS so userspace can send the ranges back in to create a restriction for the allocator, as requested in [3]. The NULL-owner cleanup in iopt_destroy_table() is no longer conditional on CONFIG_IOMMUFD_TEST since production userspace can now create such reservations.

Changes since v3:
- Helper redesigned as a callback iterator shared with dma-iommu.c (v4 changes).

Changes since v2:
- Redesign from forced reservation to opt-in query (v3 changes).

The suggested removal of the now-redundant IOMMU_TEST_OP_ADD_RESERVED selftest op (switching the selftests to IOMMU_IOAS_RESERVE_IOVAS for coverage) will follow as a separate patch.

Guanghui Feng (3):
iommu: Add iommu_for_each_pci_mmio_window() iterator
iommufd: Add IOMMU_GET_RECOMMENDED_RESERVATIONS ioctl
iommufd: Add IOMMU_IOAS_RESERVE_IOVAS ioctl

 drivers/iommu/dma-iommu.c               | 22 +++++---
 drivers/iommu/iommu-priv.h              | 17 ++++++
 drivers/iommu/iommu.c                   | 37 +++++++++++++
 drivers/iommu/iommufd/device.c          | 65 ++++++++++++++++++++++
 drivers/iommu/iommufd/io_pagetable.c    |  7 ++-
 drivers/iommu/iommufd/ioas.c            | 51 +++++++++++++++++
 drivers/iommu/iommufd/iommufd_private.h |  2 +
 drivers/iommu/iommufd/main.c            |  7 +++
 include/uapi/linux/iommufd.h            | 73 +++++++++++++++++++++++++
 9 files changed, 271 insertions(+), 10 deletions(-)
Signature · 1 line
2.43.7