From: "Peng Fan (OSS)" <peng.fan@oss.nxp.com>
To: Will Deacon <will@kernel.org>,
Robin Murphy <robin.murphy@arm.com>,
Jason Gunthorpe <jgg@ziepe.ca>,
Nicolin Chen <nicolinc@nvidia.com>,
"Joerg Roedel (AMD)" <joro@8bytes.org>,
Thierry Reding <thierry.reding@kernel.org>,
Krishna Reddy <vdumpa@nvidia.com>,
Jonathan Hunter <jonathanh@nvidia.com>,
Jean-Philippe Brucker <jpb@kernel.org>
Cc: linux-arm-kernel@lists.infradead.org, iommu@lists.linux.dev,
linux-kernel@vger.kernel.org, linux-tegra@vger.kernel.org,
Peng Fan <peng.fan@nxp.com>
Subject: [PATCH RFC v7 0/7] iommu/arm-smmu-v3: Support shared Stream IDs
Date: Fri, 30 Oct 2026 20:09:32 +0800 [thread overview]
Message-ID: <20261030-smmu-shared-sid-ver7-2026-10-26-v7-0-961726ebd6ab@Example.Com> (raw)
Changes since RFC v6:
- Add "Plumb the CD table into the CD helpers" as a preparation patch, then
introduce a per-domain CD table for non-PASID S1 streams. Normal non-PASID
devices in one domain now share a single CD table; private tables are kept
only for PASID, ATS-always-on, and stalling devices.
- Rework shared-SID STE handling. With the domain-owned CD table, all sharers
build the same S1ContextPtr, so any sharer may program a normal domain STE.
Release/blocked STE writes are skipped while the SID is shared, and the last
master tears the STE down.
- Keep CD.S per-device rather than deriving it from the SMMU stall capability.
Stall-capable masters use their private CD table so CD.S, STE.S1STALLD and
STE.S2S remain consistent.
- Add arm_smmu_master_stall_enabled() and use it uniformly. Reject sharing if
either master wants stalling, and resolve the stall policy before
insert_master() so the incoming master's policy is visible.
- Reject sharing when the existing master has ATS, PASID, or stall enabled.
Disable ATS, PASID, SVA, vSMMU and IOPF for shared SIDs.
- Link to v6: https://lore.kernel.org/linux-iommu/20261011-smmu-shared-sid-v6-0-cb76b89dc612@nxp.com/
Changes since RFC v5:
- Actively deduplicate Stream IDs during insertion instead of
storing duplicate pointers. num_streams now reflects the unique
count, eliminating pointer-equality dedup loops from all cleanup
paths (Robin).
- Extracted arm_smmu_find_stream() into patch 2 instead of patch 3
to clean up the find-before-allocate code (Nicolin).
- Extracted arm_smmu_free_master_streams() helper shared between
error rollback and arm_smmu_remove_master() (Nicolin).
- Fixed remove_master to reassign stream->master when the current
owner departs, preventing dangling pointer (Nicolin).
- Fixed remove_master to use a for loop iterating master->streams[]
with per-stream shared vs non-shared handling (Nicolin).
- Reset ste_installed on ABORT so domain transitions (e.g. DMA ->
VFIO) correctly re-write the STE instead of freezing it.
- Clear stall_enabled on the first master retroactively when
sharing is detected in arm_smmu_insert_master(), not just on
subsequent masters at probe time. Prevents bus lockup when
the first master probes before sharing is known.
- Link to v5: https://lore.kernel.org/linux-iommu/20261006-smmu-shared-sid-v5-0-169a59c671d3@nxp.com/
Changes since RFC v4:
- Include Nicolin's patch ("iommu/arm-smmu-v3: Don't rb_erase() a
never-inserted stream node") to avoid conflicts in future.
so the standalone patch 1 from v4 is dropped.
- Split old patch 2 (shared SID support) into two:
- New patch 2: Convert streams from embedded array to individually
allocated objects (struct arm_smmu_stream ** instead of *).
- New patch 3: Move stream allocation inside the mutex and look up
existing entries first (find-before-allocate), avoiding unnecessary
allocation when the SID already exists. Pure refactor, no
functional change.
- New patch 4: Add shared-SID logic on top of the refactored code.
- Duplicate-SID cleanup (bridged PCI) now uses pointer-equality dedup
instead of RB_EMPTY_NODE checks, since streams are no longer
pre-allocated with cleared nodes.
- Link to v4: https://lore.kernel.org/all/20261001-smmu-shared-sid-ver3-v4-0-06b34fb2e691@nxp.com/
Changes since RFC v3:
- Added a standalone bugfix for duplicate-SID rb_erase (new patch 1).
- Stream structures are now shared directly between masters
instead of duplicating them (Nicolin). No ref_count field;
sharing is detected via list_empty(&stream->shared_masters).
- On owner removal, use rb_replace_node() + list_splice_init()
to transfer the RB tree entry and shared_masters list to the
next sharer, avoiding use-after-free.
- INIT_LIST_HEAD(&stream->shared_masters) moved after sort() to
avoid list pointer corruption from bitwise memory swaps.
- Both sides of the sharing pair are checked for num_streams == 1.
- Link to v3: https://lore.kernel.org/all/20260930-smmu-shared-sid-v3-0-8abe6c1b4c20@nxp.com/
Changes since RFC v2:
- Dropped the RB tree to XArray conversion patch (Nicolin).
The RB tree is retained as-is; a new arm_smmu_find_stream()
helper provides stream-level lookup.
- No per-master shared_sid bool; replaced by
list_empty(&master->shared_masters_elm) (Nicolin).
- Only SID-sharing for single SID device
- Follow Nicolin's suggestion https://lore.kernel.org/linux-iommu/arG6hmng3NddGEHm@nvidia.com/
- Link to v2: https://lore.kernel.org/linux-iommu/20260921-smmu-shared-sid-v2-0-4b656ce68178@nxp.com/
Changes since RFC v1:
- Revised cover letter to drop eDMA channel example (Jason).
Some SoCs have a limited number of IOMMU Stream IDs (SIDs) and
hardware that inherently shares them. For example, the NXP i.MX95
only has 64 SIDs, only 6 bits for SID in the system chip bus.
However there are many device IPs, such as SDHC, PCIE, NETC, GPU,
NPU, Display, VPU, ISP, ISI, JPEG, SATA, DMA and etc. Each Kind IP has
mutilple instances inside the SoC. So I introudce this patchset to
support shared SID.
The current ARM SMMUv3 driver rejects this with:
"Aliasing StreamID unsupported, expect DMA to be broken"
I took comments in [1] and implement this patchset and only want to
support a very simple case that multiple platform devices share one SID.
Patch 1 converts the per-master streams array from an embedded array
of structs to an array of individually allocated pointers. This
prepares for subsequent patches where multiple masters will point
to the same stream object.
Patch 2 moves stream allocation from upfront into the mutex-protected
loop in arm_smmu_insert_master(), using a find-before-allocate pattern:
first look up whether the SID already exists in the RB tree, only
allocate and insert a new stream when no existing entry is found.
This is a pure refactor with no functional change.
Patch 3 adds shared-SID tracking so that when a second single-SID
master registers an already-owned SID, it joins the existing
stream rather than being rejected. The stream structure is shared
directly between masters via a linked list. On removal, a shared
master detaches from the list; the stream and its RB tree entry
are kept alive until the last master is removed.
Patch 4 places devices that share a SID into the same IOMMU
group, ensuring they share a single IOMMU domain (required
because one STE can only point to one cd_table).
Patch 5 wires up STE write ordering (first master writes, last
master tears down) and gates features that require unambiguous
SID-to-device mapping: SVA, IOPF/stall, and vSMMU nesting are
disabled for shared-SID masters.
[1] https://lore.kernel.org/linux-iommu/DU0PR04MB94172CB3F138AD39E9B6DEEF887F9@DU0PR04MB9417.eurprd04.prod.outlook.com/
Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
Peng Fan (7):
iommu/arm-smmu-v3: Allocate streams individually
iommu/arm-smmu-v3: Delay stream allocation to inside the mutex
iommu/arm-smmu-v3: Plumb the CD table into the CD helpers
iommu/arm-smmu-v3: Use a per-domain CD table for non-PASID streams
iommu/arm-smmu-v3: Support shared SIDs in insert/remove_master
iommu/arm-smmu-v3: Group aliasing devices into the same IOMMU group
iommu/arm-smmu-v3: Wire up shared-SID STE ordering and feature gating
.../iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c | 4 +-
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 3 +
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-test.c | 8 +-
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 485 +++++++++++++++------
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 35 +-
drivers/iommu/arm/arm-smmu-v3/tegra241-cmdqv.c | 2 +-
6 files changed, 401 insertions(+), 136 deletions(-)
---
base-commit: d89e1d186ec9271bf78e62771779e9fc03bf0fc3
change-id: 20261026-smmu-shared-sid-ver7-2026-10-26-49ba8474f782
Best regards,
--
OpenCode Assistant <opencode@Example.Com>
next reply other threads:[~2026-10-30 12:04 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-30 12:09 Peng Fan (OSS) [this message]
2026-10-30 12:09 ` [PATCH RFC v7 1/7] iommu/arm-smmu-v3: Allocate streams individually Peng Fan (OSS)
2026-10-30 12:09 ` [PATCH RFC v7 2/7] iommu/arm-smmu-v3: Delay stream allocation to inside the mutex Peng Fan (OSS)
2026-10-30 12:09 ` [PATCH RFC v7 3/7] iommu/arm-smmu-v3: Plumb the CD table into the CD helpers Peng Fan (OSS)
2026-10-30 20:54 ` Nicolin Chen
2026-10-30 12:09 ` [PATCH RFC v7 4/7] iommu/arm-smmu-v3: Use a per-domain CD table for non-PASID streams Peng Fan (OSS)
2026-10-31 1:07 ` Nicolin Chen
2026-10-30 12:09 ` [PATCH RFC v7 5/7] iommu/arm-smmu-v3: Support shared SIDs in insert/remove_master Peng Fan (OSS)
2026-10-30 12:09 ` [PATCH RFC v7 6/7] iommu/arm-smmu-v3: Group aliasing devices into the same IOMMU group Peng Fan (OSS)
2026-10-30 12:09 ` [PATCH RFC v7 7/7] iommu/arm-smmu-v3: Wire up shared-SID STE ordering and feature gating Peng Fan (OSS)
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=20261030-smmu-shared-sid-ver7-2026-10-26-v7-0-961726ebd6ab@Example.Com \
--to=peng.fan@oss.nxp.com \
--cc=iommu@lists.linux.dev \
--cc=jgg@ziepe.ca \
--cc=jonathanh@nvidia.com \
--cc=joro@8bytes.org \
--cc=jpb@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tegra@vger.kernel.org \
--cc=nicolinc@nvidia.com \
--cc=peng.fan@nxp.com \
--cc=robin.murphy@arm.com \
--cc=thierry.reding@kernel.org \
--cc=vdumpa@nvidia.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®