[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <cover.1766088962.git.nicolinc@nvidia.com>
Date: Thu, 18 Dec 2025 12:26:46 -0800
From: Nicolin Chen <nicolinc@...dia.com>
To: <will@...nel.org>, <robin.murphy@....com>, <jgg@...dia.com>
CC: <joro@...tes.org>, <jpb@...nel.org>, <praan@...gle.com>,
<miko.lenczewski@....com>, <linux-arm-kernel@...ts.infradead.org>,
<iommu@...ts.linux.dev>, <linux-kernel@...r.kernel.org>,
<patches@...ts.linux.dev>
Subject: [PATCH v1 0/9] iommu/arm-smmu-v3: Share domain across SMMU/vSMMU instances
In a system with multiple physical SMMU instances, multiple devices can be
passed through to a VM. Currently, a VM would allocate one domain per SMMU
instance that might be shared across devices that sit behind the same SMMU
instance. However, the gPA->PA mappings (either an S1 unmanaged domain or
an S2 nesting parent domain) can be shared across all the devices that sit
behind different SMMU instances as well, provided that the shared I/O page
table is compatible with all the SMMU instances.
The major difficulty in sharing the domain has been invalidation, since a
change to the shared I/O page table results in an invalidation on all SMMU
instances. A traditional approach involves building a linked list of SMMUs
within the domain, which is very inefficient for the invalidation path as
the linked list has to be locked.
To address this, the SMMUv3 driver now uses an RCU-protected invalidation
array. Any new device (and its SMMU) is preloaded into the array during a
device attachment. This array maintains all necessary information, such as
ASID/VMID and which SMMU instance (CMDQ) to issue the command to.
The second issue concerns the lifecycle of the iotlb tag. Currently, ASID
or VMID is allocated per domain and kept in the domain structure (cd->asid
or s2_cfg->vmid). This does not work ideally when the domain (e.g. S2) is
shared, as the VMID will have to be global across all SMMU instances, even
if a VM is not using all of them. This results in wasted VMID resources in
the bitmaps of unused SMMU instances.
Instead, an iotlb tag should be allocated per SMMU instance. Consequently,
these tags must be allocated and maintained separately. Since ASID or VMID
is only used when a CD or STE is installed to the HW (which happens during
device attachment), and the invalidation array is built right before that,
arm_smmu_invs_merge() is the ideal place to allocate a new iotlb tag:
- when a device attaches, the driver first searches for an existing iotlb
tag for the SMMU the device sits behind
- If a match is found, the "users" counter is incremented
- otherwise, a new tag is allocated.
As ASID/VMID are programmed to CD/STE that belong to a device, it's natural
to store the ASID/VMID in the master structure.
Given the above, this series reworks the driver further:
- Add ASID/VMID allocation/free ops to the arm_smmu_invs data structure
- Store the allocated ASID/VMID in the arm_smmu_master structure
- Replace cd->asid and s2_cfg->vmid with the tags stored in the master
structure, when installing them to the CD and STE
- Deprecate cd->asid and s2_cfg->vmid.
Finally, allow sharing a domain across the SMMU instances, so long as they
passes a compatibility test.
This is on Github:
https://github.com/nicolinc/iommufd/commits/smmuv3_share_domain-v1
This is based on the series "Introduce an RCU-protected invalidation array"
https://lore.kernel.org/all/cover.1766013662.git.nicolinc@nvidia.com/
So the whole implementation follows the path Jason envisioned initially.
A earlier effort to share S2 domain can be found:
https://lore.kernel.org/all/cover.1744692494.git.nicolinc@nvidia.com/
Thanks
Nicolin
Nicolin Chen (9):
iommu/arm-smmu-v3: Pass in ssid to arm_smmu_make_s1_cd()
iommu/arm-smmu-v3: Add alloc_id/free_id functions to arm_smmu_invs
iommu/arm-smmu-v3: Store ASIDs and VMID in arm_smmu_master
iommu/arm-smmu-v3: Use alloc_id/free_id ops in
arm_smmu_invs_merge/unref
iommu/arm-smmu-v3: Install to CD/STE the ASID/VMID stored in the
master
iommu/arm-smmu-v3: Use dummy ASID/VMID in arm_smmu_master_build_invs()
iommu/arm-smmu-v3: Remove free_fn argument from arm_smmu_invs_unref()
iommu/arm-smmu-v3: Remove ASID/VMID from arm_smmu_domain
iommu/arm-smmu-v3: Allow sharing domain across SMMUs
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 47 ++-
.../arm/arm-smmu-v3/arm-smmu-v3-iommufd.c | 17 +-
.../iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 27 +-
.../iommu/arm/arm-smmu-v3/arm-smmu-v3-test.c | 24 +-
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 307 +++++++++++-------
5 files changed, 265 insertions(+), 157 deletions(-)
--
2.43.0
Powered by blists - more mailing lists