From: Guanghui Feng <guanghuifeng@linux.alibaba.com>
To: jgg@ziepe.ca
Cc: alex@shazbot.org, iommu@lists.linux.dev, joro@8bytes.org,
kevin.tian@intel.com, kvm@vger.kernel.org,
linux-kernel@vger.kernel.org, robin.murphy@arm.com,
will@kernel.org
Subject: [PATCH v4 0/2] iommu/iommufd: Expose PCI host bridge MMIO windows for opt-in IOVA avoidance
Date: Sun, 25 Oct 2026 21:29:58 +0800 [thread overview]
Message-ID: <20261025133000.205508-1-guanghuifeng@linux.alibaba.com> (raw)
In-Reply-To: <20261022193359.GF3381610@ziepe.ca>
When a device sits behind a PCIe switch and ACS Upstream Forwarding is
not fully enabled, DMA TLPs whose IOVA happens to fall within a host
bridge MMIO window may be routed peer-to-peer to another downstream
device instead of upstream to the root complex for IOMMU translation.
This can lead to faults, data corruption, or silent misrouting.
The DMA IOVA layer already avoids this via iova_reserve_pci_windows().
However, passthrough paths that let userspace pick IOVAs (VFIO type1,
iommufd) had no mechanism to learn about these ranges. Commit
cd2c9fcf5c66 ("iommu/dma: Move PCI window region reservation back into
dma specific path.") intentionally keeps this information out of the
IOMMU reserved-region API to avoid pessimistically restricting
userspace.
Following Jason Gunthorpe's suggestion [1], this series takes an opt-in
approach: the kernel reports the information, userspace decides whether
to avoid it.
Patch 1 adds iommu_for_each_pci_mmio_window(), a callback-based
iterator in the IOMMU core that enumerates host bridge MMIO windows
with zero intermediate allocation. dma-iommu.c is refactored to use
it, sharing the same algorithm.
Patch 2 adds the IOMMU_GET_PCI_MMIO_WINDOWS ioctl to iommufd, a
per-device query that returns these windows to userspace without
reserving or enforcing them.
[1] https://lore.kernel.org/all/20260921115513.GK11599@ziepe.ca/
v3: https://lore.kernel.org/all/20261004162213.3787623-1-guanghuifeng@linux.alibaba.com/
v2: https://lore.kernel.org/all/20260921103922.1113752-1-guanghuifeng@linux.alibaba.com/
v1: https://lore.kernel.org/all/20260921070234.897736-1-guanghuifeng@linux.alibaba.com/
Changes since v3:
- Patch 1: redesign helper as a callback-based iterator
(iommu_for_each_pci_mmio_window) per Jason's review [2]. This
eliminates intermediate iommu_resv_region allocations, avoids size_t
truncation on 32-bit PAE (callback receives phys_addr_t directly),
and allows dma-iommu.c to share the same algorithm with zero overhead.
- Patch 1: dma-iommu.c now uses the shared iterator as Jason requested
("if you are going to add a function to the iommu core then
dma-iommu.c should also use it").
- Patch 2: rename 'windows' field to 'out_windows' per iommufd
convention.
- Patch 2: remove irrelevant 1:1 IOVA discussion from kdoc (iommufd
only supports identity-mapped devices).
- Patch 2: explicitly state that windows are reported in host bridge
resource list order, typically non-overlapping but no sorting
guarantee.
- Patch 2: handler simplified to use callback directly (no linked list
allocation/cleanup needed).
[2] https://lore.kernel.org/all/20261022193527.GG3381610@ziepe.ca/
Changes since v2:
- Complete redesign from forced reservation to opt-in query (per Robin
Murphy's and Jason Gunthorpe's v2 review).
Changes since v1:
- (Superseded by later changes.)
Guanghui Feng (2):
iommu: Add iommu_for_each_pci_mmio_window() iterator
iommufd: Add IOMMU_GET_PCI_MMIO_WINDOWS ioctl
drivers/iommu/dma-iommu.c | 29 +++++++----
drivers/iommu/iommu-priv.h | 25 ++++++++++
drivers/iommu/iommu.c | 51 ++++++++++++++++++++
drivers/iommu/iommufd/device.c | 64 +++++++++++++++++++++++++
drivers/iommu/iommufd/iommufd_private.h | 1 +
drivers/iommu/iommufd/main.c | 3 ++
include/uapi/linux/iommufd.h | 59 +++++++++++++++++++++++
7 files changed, 224 insertions(+), 8 deletions(-)
--
2.43.7
next prev parent reply other threads:[~2026-10-25 13:30 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-21 7:02 [PATCH] iommu: Reserve PCI host bridge MMIO windows in group reserved regions Guanghui Feng
2026-09-21 10:39 ` [PATCH v2 0/2] iommu: Reserve PCI host bridge MMIO windows for IOVA Guanghui Feng
2026-09-21 10:39 ` [PATCH v2 1/2] iommu: Reserve PCI host bridge MMIO windows in group reserved regions Guanghui Feng
2026-09-21 10:39 ` [PATCH v2 2/2] iommufd: Reserve PCI host bridge MMIO windows in IOAS " Guanghui Feng
2026-09-21 11:24 ` [PATCH v2 0/2] iommu: Reserve PCI host bridge MMIO windows for IOVA Robin Murphy
2026-09-21 11:55 ` Jason Gunthorpe
2026-10-04 16:22 ` [PATCH v3 0/2] iommu/iommufd: Expose PCI host bridge MMIO windows for opt-in IOVA avoidance Guanghui Feng
2026-10-04 16:22 ` [PATCH v3 1/2] iommu: Add iommu_get_pci_resv_windows() helper Guanghui Feng
2026-10-22 19:35 ` Jason Gunthorpe
2026-10-04 16:22 ` [PATCH v3 2/2] iommufd: Add IOMMU_GET_PCI_MMIO_WINDOWS ioctl Guanghui Feng
2026-10-22 19:33 ` Jason Gunthorpe
2026-10-25 13:29 ` Guanghui Feng [this message]
2026-10-25 13:29 ` [PATCH v4 1/2] iommu: Add iommu_for_each_pci_mmio_window() iterator Guanghui Feng
2026-10-25 13:30 ` [PATCH v4 2/2] iommufd: Add IOMMU_GET_PCI_MMIO_WINDOWS ioctl Guanghui Feng
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261025133000.205508-1-guanghuifeng@linux.alibaba.com \
--to=guanghuifeng@linux.alibaba.com \
--cc=alex@shazbot.org \
--cc=iommu@lists.linux.dev \
--cc=jgg@ziepe.ca \
--cc=joro@8bytes.org \
--cc=kevin.tian@intel.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=robin.murphy@arm.com \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®