From: "Peng Fan (OSS)" <peng.fan@oss.nxp.com>
To: Will Deacon <will@kernel.org>,
Robin Murphy <robin.murphy@arm.com>,
"Joerg Roedel (AMD)" <joro@8bytes.org>,
Nicolin Chen <nicolinc@nvidia.com>,
Jason Gunthorpe <jgg@ziepe.ca>,
Jean-Philippe Brucker <jpb@kernel.org>
Cc: linux-arm-kernel@lists.infradead.org, iommu@lists.linux.dev,
linux-kernel@vger.kernel.org, Peng Fan <peng.fan@nxp.com>
Subject: [PATCH RFC v4 2/4] iommu/arm-smmu-v3: Support shared SIDs in insert/remove_master
Date: Thu, 01 Oct 2026 20:49:59 +0800 [thread overview]
Message-ID: <20261001-smmu-shared-sid-ver3-v4-2-06b34fb2e691@nxp.com> (raw)
In-Reply-To: <20261001-smmu-shared-sid-ver3-v4-0-06b34fb2e691@nxp.com>
From: Peng Fan <peng.fan@nxp.com>
Some SoCs have a limited number of IOMMU Stream IDs and hardware
that inherently shares them. For example, the NXP i.MX95 has only
64 SIDs (6-bit internal bus) serving 64+ DMA initiators across
separate IP blocks - MMC, SD, NET, PCI, DMA, NPU, DSP, DISPLAY
and more. Genuinely distinct platform devices share a SID by
hardware design because the SID space is exhausted.
When arm_smmu_insert_master() encounters a SID already owned by a
different single-SID master, instead of failing with -ENODEV, link
the new master into the existing stream's shared_masters list.
The stream structure is shared directly: the RB tree entry remains
the same, and all sharing masters are tracked via list_head.
On removal, if the departing master owns the canonical stream,
transfer ownership to the next sharer.
Sharing is restricted to single-SID masters (num_streams == 1)
since multi-SID sharing would require more complex tracking.
Suggested-by: Nicolin Chen <nicolinc@nvidia.com>
Link: https://lore.kernel.org/linux-iommu/arG6hmng3NddGEHm@nvidia.com/
Assisted-by: LLM
Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 94 +++++++++++++++++++++++------
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 3 +
2 files changed, 78 insertions(+), 19 deletions(-)
diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
index a79f2250a4886..9d98d1b2758f7 100644
--- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
+++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
@@ -2037,15 +2037,14 @@ static int arm_smmu_streams_cmp_key(const void *lhs, const struct rb_node *rhs)
return 0;
}
-static int arm_smmu_streams_cmp_node(struct rb_node *lhs,
- const struct rb_node *rhs)
+static int arm_smmu_streams_cmp_node(struct rb_node *lhs, const struct rb_node *rhs)
{
return arm_smmu_streams_cmp_key(
&rb_entry(lhs, struct arm_smmu_stream, node)->id, rhs);
}
-static struct arm_smmu_master *
-arm_smmu_find_master(struct arm_smmu_device *smmu, u32 sid)
+static struct arm_smmu_stream *
+arm_smmu_find_stream(struct arm_smmu_device *smmu, u32 sid)
{
struct rb_node *node;
@@ -2054,7 +2053,20 @@ arm_smmu_find_master(struct arm_smmu_device *smmu, u32 sid)
node = rb_find(&sid, &smmu->streams, arm_smmu_streams_cmp_key);
if (!node)
return NULL;
- return rb_entry(node, struct arm_smmu_stream, node)->master;
+ return rb_entry(node, struct arm_smmu_stream, node);
+}
+
+static struct arm_smmu_master *
+arm_smmu_find_master(struct arm_smmu_device *smmu, u32 sid)
+{
+ struct arm_smmu_stream *stream;
+
+ stream = arm_smmu_find_stream(smmu, sid);
+ if (!stream)
+ return NULL;
+ if (!list_empty(&stream->shared_masters))
+ return NULL;
+ return stream->master;
}
/* IRQ and event handlers */
@@ -4116,6 +4128,7 @@ static int arm_smmu_insert_master(struct arm_smmu_device *smmu,
new_stream->id = fwspec->ids[i];
new_stream->master = master;
}
+ INIT_LIST_HEAD(&master->shared_masters_elm);
/* Put the ids into order for sorted to_merge/to_unref arrays */
sort(master->streams, master->num_streams,
@@ -4128,6 +4141,8 @@ static int arm_smmu_insert_master(struct arm_smmu_device *smmu,
struct rb_node *existing;
u32 sid = new_stream->id;
+ INIT_LIST_HEAD(&new_stream->shared_masters);
+
ret = arm_smmu_init_sid_strtab(smmu, sid);
if (ret)
break;
@@ -4136,23 +4151,33 @@ static int arm_smmu_insert_master(struct arm_smmu_device *smmu,
existing = rb_find_add(&new_stream->node, &smmu->streams,
arm_smmu_streams_cmp_node);
if (existing) {
- struct arm_smmu_master *existing_master =
- rb_entry(existing, struct arm_smmu_stream, node)
- ->master;
+ struct arm_smmu_stream *existing_stream =
+ rb_entry(existing, struct arm_smmu_stream, node);
/* Bridged PCI devices may end up with duplicated IDs */
- if (existing_master == master)
+ if (existing_stream->master == master)
continue;
- dev_warn(master->dev,
- "Aliasing StreamID 0x%x (from %s) unsupported, expect DMA to be broken\n",
- sid, dev_name(existing_master->dev));
- ret = -ENODEV;
- break;
+ if (master->num_streams != 1 ||
+ existing_stream->master->num_streams != 1) {
+ dev_warn(master->dev,
+ "Shared StreamID 0x%x not supported for multi-SID masters\n",
+ sid);
+ ret = -ENODEV;
+ break;
+ }
+
+ if (list_empty(&existing_stream->shared_masters))
+ list_add_tail(&existing_stream->master->shared_masters_elm,
+ &existing_stream->shared_masters);
+ list_add_tail(&master->shared_masters_elm,
+ &existing_stream->shared_masters);
+ continue;
}
}
if (ret) {
+ list_del_init(&master->shared_masters_elm);
for (i--; i >= 0; i--) {
if (i > 0 && master->streams[i - 1].id == master->streams[i].id)
continue;
@@ -4170,16 +4195,47 @@ static void arm_smmu_remove_master(struct arm_smmu_master *master)
{
int i;
struct arm_smmu_device *smmu = master->smmu;
- struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(master->dev);
if (!smmu || !master->streams)
return;
mutex_lock(&smmu->streams_mutex);
- for (i = 0; i < fwspec->num_ids; i++) {
- if (i > 0 && master->streams[i - 1].id == master->streams[i].id)
- continue;
- rb_erase(&master->streams[i].node, &smmu->streams);
+ if (!list_empty(&master->shared_masters_elm)) {
+ struct arm_smmu_stream *stream;
+
+ list_del_init(&master->shared_masters_elm);
+ stream = arm_smmu_find_stream(smmu, master->streams[0].id);
+ if (stream && stream->master == master) {
+ struct arm_smmu_master *next;
+ struct arm_smmu_stream *next_stream;
+
+ next = list_first_entry(&stream->shared_masters,
+ struct arm_smmu_master,
+ shared_masters_elm);
+ next_stream = &next->streams[0];
+ next_stream->ste_installed = stream->ste_installed;
+ INIT_LIST_HEAD(&next_stream->shared_masters);
+ list_splice_init(&stream->shared_masters,
+ &next_stream->shared_masters);
+ rb_replace_node(&stream->node, &next_stream->node,
+ &smmu->streams);
+ stream = next_stream;
+ }
+
+ if (stream && list_is_singular(&stream->shared_masters)) {
+ struct arm_smmu_master *last;
+
+ last = list_first_entry(&stream->shared_masters,
+ struct arm_smmu_master,
+ shared_masters_elm);
+ list_del_init(&last->shared_masters_elm);
+ }
+ } else {
+ for (i = 0; i < master->num_streams; i++) {
+ if (i > 0 && master->streams[i - 1].id == master->streams[i].id)
+ continue;
+ rb_erase(&master->streams[i].node, &smmu->streams);
+ }
}
mutex_unlock(&smmu->streams_mutex);
diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h
index dd2fee2f560e6..89177f3e7dabe 100644
--- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h
+++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h
@@ -969,6 +969,8 @@ struct arm_smmu_stream {
u32 id;
struct arm_smmu_master *master;
struct rb_node node;
+ bool ste_installed;
+ struct list_head shared_masters;
};
struct arm_smmu_vmaster {
@@ -1017,6 +1019,7 @@ struct arm_smmu_master {
bool ste_ats_enabled : 1;
bool stall_enabled;
bool ats_always_on;
+ struct list_head shared_masters_elm;
unsigned int ssid_bits;
unsigned int iopf_refcount;
};
--
2.34.1
next prev parent reply other threads:[~2026-10-01 12:45 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-01 12:49 [PATCH RFC v4 0/4] iommu/arm-smmu-v3: Support shared Stream IDs Peng Fan (OSS)
2026-10-01 12:49 ` [PATCH RFC v4 1/4] iommu/arm-smmu-v3: Skip duplicate SIDs when erasing streams from RB tree Peng Fan (OSS)
2026-10-01 16:07 ` Nicolin Chen
2026-10-01 12:49 ` Peng Fan (OSS) [this message]
2026-10-01 17:17 ` [PATCH RFC v4 2/4] iommu/arm-smmu-v3: Support shared SIDs in insert/remove_master Nicolin Chen
2026-10-01 12:50 ` [PATCH RFC v4 3/4] iommu/arm-smmu-v3: Group aliasing devices into the same IOMMU group Peng Fan (OSS)
2026-10-01 12:50 ` [PATCH RFC v4 4/4] 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=20261001-smmu-shared-sid-ver3-v4-2-06b34fb2e691@nxp.com \
--to=peng.fan@oss.nxp.com \
--cc=iommu@lists.linux.dev \
--cc=jgg@ziepe.ca \
--cc=joro@8bytes.org \
--cc=jpb@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nicolinc@nvidia.com \
--cc=peng.fan@nxp.com \
--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®