[PATCH RFC v7 5/7] iommu/arm-smmu-v3: Support shared SIDs in insert/remove_master
Peng Fan (OSS)
peng.fan at oss.nxp.com
Fri Oct 30 05:09:37 PDT 2026
From: Peng Fan <peng.fan at nxp.com>
On SoCs like NXP i.MX95 where the SMMU has a limited number of Stream
IDs (e.g. 6-bit bus = 64 SIDs), multiple DMA-capable devices are
assigned the same Stream ID by SCU configuration.
When a second master attempts to use a SID that is already claimed,
link the masters together via the stream's shared_masters list instead
of rejecting the probe. The stream object is shared directly between
masters - no duplication.
Sharing is restricted to single-SID masters (num_streams == 1) to keep
the STE lifecycle simple. Multi-SID sharing is explicitly rejected.
Sharing is also rejected if the existing master has stall enabled, since
dynamically clearing stall_enabled without reprogramming the hardware
STE would leave the stall bit active and risk an unrecoverable bus
lockup when CMD_RESUME cannot be issued.
On removal, arm_smmu_free_master_streams() handles both the shared and
non-shared cases: a shared master detaches from the shared_masters list
and ownership transfers to the next sharer if the departing master was
the stream owner; the stream and its RB tree entry are kept alive until
the last master using that SID is removed.
Since fault events on shared SIDs cannot be attributed to a specific
master, arm_smmu_find_master() returns NULL when the stream's
shared_masters list is non-empty.
Suggested-by: Nicolin Chen <nicolinc at nvidia.com>
Link: https://lore.kernel.org/linux-iommu/Z3r-cBm00tVE4eKe@Asurada-Nvidia/
Reviewed-by: Nicolin Chen <nicolinc at nvidia.com>
Signed-off-by: Peng Fan <peng.fan at nxp.com>
---
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 55 ++++++++++++++++++++++++-----
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 2 ++
2 files changed, 49 insertions(+), 8 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 510c9028fa19f..605d4179caaa9 100644
--- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
+++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
@@ -2124,6 +2124,8 @@ arm_smmu_find_master(struct arm_smmu_device *smmu, u32 sid)
stream = arm_smmu_find_stream(smmu, sid);
if (!stream)
return NULL;
+ if (!list_empty(&stream->shared_masters))
+ return NULL;
return stream->master;
}
@@ -4415,10 +4417,26 @@ static void arm_smmu_free_master_streams(struct arm_smmu_master *master)
lockdep_assert_held(&smmu->streams_mutex);
for (i = 0; i < master->num_streams; i++) {
- if (!master->streams[i])
+ struct arm_smmu_stream *stream = master->streams[i];
+
+ if (!stream)
+ continue;
+
+ if (!list_empty(&stream->shared_masters)) {
+ struct arm_smmu_master *next;
+
+ list_del_init(&master->shared_masters_elm);
+ next = list_first_entry(&stream->shared_masters,
+ struct arm_smmu_master,
+ shared_masters_elm);
+ if (stream->master == master)
+ stream->master = next;
+ if (list_is_singular(&stream->shared_masters))
+ list_del_init(&next->shared_masters_elm);
continue;
- rb_erase(&master->streams[i]->node, &smmu->streams);
- kfree(master->streams[i]);
+ }
+ rb_erase(&stream->node, &smmu->streams);
+ kfree(stream);
}
}
@@ -4446,6 +4464,7 @@ static int arm_smmu_insert_master(struct arm_smmu_device *smmu,
kfree(master->streams);
return -ENOMEM;
}
+ INIT_LIST_HEAD(&master->shared_masters_elm);
mutex_lock(&smmu->streams_mutex);
for (i = 0, n = 0; i < fwspec->num_ids; i++) {
@@ -4462,11 +4481,30 @@ static int arm_smmu_insert_master(struct arm_smmu_device *smmu,
if (stream->master == master)
continue;
- dev_warn(master->dev,
- "Aliasing StreamID 0x%x (from %s) unsupported, expect DMA to be broken\n",
- sid, dev_name(stream->master->dev));
- ret = -ENODEV;
- break;
+ if (fwspec->num_ids != 1 ||
+ 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 (stream->master->stall_enabled) {
+ dev_warn(master->dev,
+ "Shared StreamID 0x%x rejected: existing master has stall enabled\n",
+ sid);
+ ret = -EBUSY;
+ break;
+ }
+
+ if (list_empty(&stream->shared_masters))
+ list_add_tail(&stream->master->shared_masters_elm,
+ &stream->shared_masters);
+ list_add_tail(&master->shared_masters_elm,
+ &stream->shared_masters);
+ master->streams[n++] = stream;
+ continue;
}
stream = kzalloc_obj(*stream, GFP_KERNEL);
@@ -4476,6 +4514,7 @@ static int arm_smmu_insert_master(struct arm_smmu_device *smmu,
}
stream->id = sid;
stream->master = master;
+ INIT_LIST_HEAD(&stream->shared_masters);
rb_find_add(&stream->node, &smmu->streams,
arm_smmu_streams_cmp_node);
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 a45a5a1580e0c..c57221b311245 100644
--- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h
+++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h
@@ -1021,6 +1021,7 @@ struct arm_smmu_stream {
u32 id;
struct arm_smmu_master *master;
struct rb_node node;
+ struct list_head shared_masters;
};
struct arm_smmu_vmaster {
@@ -1069,6 +1070,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
More information about the linux-arm-kernel
mailing list