RFC iommu: Reduce iommu_probe_device_lock contention
Get series with b4
b4 am [email protected]Versions newest first
- v1 RFC Latest3 patches 2 repliesIn review
Patches in v1 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/3 | iommu: split sysfs link publication out of iommu_group_alloc_device()drivers/ | +67 | 0 replies | |
| 2/3 | iommu: create device sysfs links outside iommu_probe_device_lockdrivers/ | +65 | 0 replies | |
| 3/3 | iommu: set up the default domain outside iommu_probe_device_lockdrivers/ | +34 | 0 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.
Cover letter [RFC PATCH 0/3] iommu: Reduce iommu_probe_device_lock contention
iommu_probe_device_lock is a file-scope mutex held across __iommu_probe_device(): every device's IOMMU probe serializes against every other. With "PCI/IOV: Initialize virtual functions in parallel" [1] fanning an SR-IOV enable across CPUs, it collects 94.7% of all lock wait. Patch 1 gathers per-member sysfs publication into one all-or-nothing helper (no functional change); patches 2-3 move that publication and first-device default-domain setup into per-group finalisation after the global unlock, under group->mutex, mirroring the removal path and bus_iommu_probe().
Lock statistics and SR-IOV init time for 4x PF (NVMe, 255 VFs each), on the reproducer from the parallel VF initialization cover letter [1]:
lock_stat:
Lock wait: Before After contentions: Before After
iommu_probe_device_lock 25507 ms 10471 ms 1143 841
&root->kernfs_rwsem 942 ms 1834 ms 93208 116316 &vfio.group_lock 425 ms 3614 ms 497 736
avg wait per acquisition 6.3 ms -> 2.6 ms (4080 acq., both arms)
Stage SR-IOV init time:
S0 (baseline) 3027 ms
S1 999 ms
S2 (this series) 995 ms
Reproducer disclaimer:
I lean primarily on lock_stat numbers to defend the improvements. In the reproducer, this lock's residual hold dominates the window and masks the later series' wall-time gains, more in [1].
This is relief, not removal: the lock still has the highest wait time in the profile after this series. Wait per acquisition drops from 6.3 ms to 2.6 ms, which is what makes the smaller serialization points behind it measurable for the later series.
RFC on the direction: The comment in __iommu_probe_device() expects the lock to narrow to device_lock() once the ACPI/OF replay calls are cleaned up. I could not make that work for the whole section:
group formation in ops->device_group() is a cross-device decision a per-device lock cannot order. This series instead moves the work that needs no global ordering out of the section. Is that an acceptable step, or is there a scoping or removal plan this should wait for?
A second question: I have measured where 90% of the residual hold goes:get_pci_alias_group() walks every PCI device in the system to find same-bus DMA aliases. It runs once per device probed, so once per VF, under this lock, and the VFs keep growing the list it walks. A prototype that skips the walk when no device has a dma_alias_mask and this device has no pci_real_dma_dev() override cuts this lock's hold time by about 90%, for the same acquisitions and the same groups. I am not proposing it here, as I do not have the time to get it right this cycle. How can we optimize this preferably in O(1) time?
The lock_stat and timing figures come from the public reproducer. The full series has also been tested on current datacenter server hardware with thousands of VFs.
[1] https://lore.kernel.org/r/[email protected]
Pavol Sakac (3):
iommu: split sysfs link publication out of iommu_group_alloc_device()
iommu: create device sysfs links outside iommu_probe_device_lock
iommu: set up the default domain outside iommu_probe_device_lock
drivers/iommu/iommu.c | 197 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 160 insertions(+), 37 deletions(-)
base-commit: cee9395acd8043be0644b25c34bfa86623f2b935
Signature · 1 line
2.47.3