[PATCH RFC v6 2/5] iommu/arm-smmu-v3: Delay stream allocation to inside the mutex
Nicolin Chen
nicolinc at nvidia.com
Mon Oct 12 13:36:51 PDT 2026
On Sun, Oct 11, 2026 at 07:31:26PM +0800, Peng Fan (OSS) wrote:
> From: Peng Fan <peng.fan at nxp.com>
>
> Move arm_smmu_stream allocation from upfront (before the mutex) into
> the mutex-protected loop in arm_smmu_insert_master(). Instead of
> pre-allocating all stream objects and then inserting them into the RB
> tree, first look up whether the SID already exists in the tree via the
> new arm_smmu_find_stream() helper. Only allocate and insert a new
> stream when no existing entry is found.
>
> Duplicated Stream IDs from bridged PCI devices are now actively
> skipped rather than stored as duplicate pointers. A separate write
> index (n) tracks only unique entries, and master->num_streams is set
> to the deduplicated count. This eliminates the need for duplicate-
> pointer tracking in all cleanup paths.
>
> Extract arm_smmu_find_stream() from arm_smmu_find_master() to provide
> stream-level lookup, which will also be used by subsequent shared-SID
> patches.
>
> Extract arm_smmu_free_master_streams() to share the stream cleanup
> logic between the error rollback in arm_smmu_insert_master() and
> arm_smmu_remove_master().
>
> The sort is moved after the mutex section, since streams are now
> populated inside the loop rather than beforehand.
>
> Suggested-by: Nicolin Chen <nicolinc at nvidia.com>
> Suggested-by: Robin Murphy <robin.murphy at arm.com>
> Assisted-by: LLM
> Signed-off-by: Peng Fan <peng.fan at nxp.com>
Reviewed-by: Nicolin Chen <nicolinc at nvidia.com>
More information about the linux-arm-kernel
mailing list