[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <cover.1769044718.git.nicolinc@nvidia.com>
Date: Wed, 21 Jan 2026 17:24:18 -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 v2 00/10] 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,
it is ideal to allocate a new iotlb tag before arm_smmu_invs_merge():
- 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.
A nested domain case is slightly unique as certain HW requires the VMID at
the vSMMU init stage v.s. a device attachment (to the nested domain). Thus
- allocate/free a vmid in vsmmu_init/vsmmu_destroy and store in vSMMU
- introduce an INV_TYPE_S2_VMID_VSMMU to separate it from a naked S2 case
- retrieve the vmid from the vSMMU during attachment instead of allocation
With this, deprecate the cd->asid and s2_cfg->vmid from struct smmu_domain,
and replace them with the iotlb tag stored in the smmu_domain->invs array.
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-v2
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/
Changelog
v2
* Add arm_smmu_domain_get_iotlb_tag()
* Drop asid array and vmid from master structure, and get the iotlb
tag in the smmu_domain->invs array
* Introduce INV_TYPE_S2_VMID_VSMMU for vSMMU type, and separate the
nested attach case from a naked S2 attach case
v1
https://lore.kernel.org/all/cover.1766088962.git.nicolinc@nvidia.com/
Thanks
Nicolin
Nicolin Chen (10):
iommu/arm-smmu-v3: Store IOTLB cache tags in struct
arm_smmu_attach_state
iommu/arm-smmu-v3: Pass in IOTLB cache tag to CD and STE
iommu/arm-smmu-v3: Look for existing iotlb tag in smmu_domain->invs
iommu/arm-smmu-v3: Allocate IOTLB cache tag if no id to reuse
iommu/arm-smmu-v3: Flush iotlb in arm_smmu_iotlb_tag_free()
iommu/arm-smmu-v3: Allocate vmid in arm_vsmmu_init
iommu/arm-smmu-v3: Pass in vsmmu to arm_smmu_domain_get_iotlb_tag()
iommu/arm-smmu-v3: Introduce INV_TYPE_S2_VMID_VSMMU
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 | 53 +++-
.../arm/arm-smmu-v3/arm-smmu-v3-iommufd.c | 50 ++-
.../iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 42 ++-
.../iommu/arm/arm-smmu-v3/arm-smmu-v3-test.c | 21 +-
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 286 ++++++++++--------
.../iommu/arm/arm-smmu-v3/tegra241-cmdqv.c | 1 +
6 files changed, 266 insertions(+), 187 deletions(-)
--
2.43.0
Powered by blists - more mailing lists