[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <cover.1755131672.git.nicolinc@nvidia.com>
Date: Wed, 13 Aug 2025 18:25:31 -0700
From: Nicolin Chen <nicolinc@...dia.com>
To: <jgg@...dia.com>, <will@...nel.org>, <robin.murphy@....com>
CC: <joro@...tes.org>, <jean-philippe@...aro.org>, <miko.lenczewski@....com>,
<balbirs@...dia.com>, <peterz@...radead.org>, <smostafa@...gle.com>,
<kevin.tian@...el.com>, <praan@...gle.com>, <zhangzekun11@...wei.com>,
<linux-arm-kernel@...ts.infradead.org>, <iommu@...ts.linux.dev>,
<linux-kernel@...r.kernel.org>, <patches@...ts.linux.dev>
Subject: [PATCH rfcv1 0/8] iommu/arm-smmu-v3: Introduce an RCU-protected invalidation array
This is a work based on Jason's design and algorithm. This implementation
follows his initial draft as well.
The new arm_smmu_invs array is an RCU-protected array, mutated when device
attach to the domain, iterated when an invalidation is required for IOPTE
changes in this domain. This keeps the current invalidation efficiency of
a smb_mb() followed by a conditional rwlock replacing the atomic/spinlock
combination.
A new data structure is defined for the array and its entry, representing
invalidation operations, such as S1_ASID, S2_VMID, and ATS. The algorithm
adds and deletes array entries efficiently and also keeps the array sorted
so as to group similar invalidations into batches.
During an invalidation, a new invalidation function iterates domain->invs,
and converts each entry to the corresponding invalidation command(s). This
new function is fully compatible with all the existing use cases, allowing
a simple rework/replacement.
Some races to keep in mind:
1) A domain can be shared across SMMU instances. When an SMMU instance is
removed, the updated invs array has to be sync-ed via synchronize_rcu()
to prevent an concurrent invalidation routine that is accessing the old
array from issuing commands to the removed SMMU instance.
2) When there are concurrent IOPTE changes (followed by invalidations) and
a domain attachment, the new attachment must not become out of sync at
the HW level, meaning that an STE store and invalidation array load must
be sequenced by the CPU's memory model.
3) When an ATS-enabled device attaches to a blocking domain, the core code
requires a hard fence to ensure all ATS invalidations to the device are
completed. Relying on RCU alone requires calling synchronize_rcu() that
can be too slow. Instead, when ATS is in use, hold a conditional rwlock
till all concurrent invalidations are finished.
Related future work and dependent projects:
* NVIDIA is building systems with > 10 SMMU instances where > 8 are being
used concurrently in a single VM. So having 8 copies of an identical S2
page table is not efficient. Instead, all vSMMU instances should check
compatibility on a shared S2 iopt, to eliminate 7 copies.
Previous attempt based on the list/spinlock design:
iommu/arm-smmu-v3: Allocate vmid per vsmmu instead of s2_parent
https://lore.kernel.org/all/cover.1744692494.git.nicolinc@nvidia.com/
now can adopt this invs array, avoiding adding complex lists/locks.
* The guest support for BTM requires temporarily invalidating two ASIDs
for a single instance. When it renumbers ASIDs this can now be done via
the invs array.
* SVA with multiple devices being used by a single process (NVIDIA today
has 4-8) sequentially iterates the invalidations through all instances.
This ignores the HW concurrency available in each instance. It would be
nice to not spin on each sync but go forward and issue batches to other
instances also. Reducing to a single SVA domain shared across instances
is required to look at this.
This is on Github:
https://github.com/nicolinc/iommufd/commits/arm_smmu_invs-rfcv1
Thanks
Nicolin
Jason Gunthorpe (1):
iommu/arm-smmu-v3: Introduce a per-domain arm_smmu_invs array
Nicolin Chen (7):
iommu/arm-smmu-v3: Clear cmds->num after arm_smmu_cmdq_batch_submit
iommu/arm-smmu-v3: Explicitly set smmu_domain->stage for SVA
iommu/arm-smmu-v3: Add an inline arm_smmu_domain_free()
iommu/arm-smmu-v3: Pre-allocate a per-master invalidation array
iommu/arm-smmu-v3: Populate smmu_domain->invs when attaching masters
iommu/arm-smmu-v3: Add arm_smmu_invs based arm_smmu_domain_inv_range()
iommu/arm-smmu-v3: Perform per-domain invalidations using
arm_smmu_invs
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 106 ++-
.../iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 32 +-
.../iommu/arm/arm-smmu-v3/arm-smmu-v3-test.c | 85 ++
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 829 +++++++++++++++---
4 files changed, 876 insertions(+), 176 deletions(-)
--
2.43.0
Powered by blists - more mailing lists