iommu_completion_wait() checks iommu->need_sync without iommu->lock and
returns at once when it is clear. A completion wait queued by another
CPU clears the flag before the IOMMU has executed the commands in front
of it, so the caller can return while its own invalidations are still
pending. After an unmap that lets an IOVA or a page table page be
reused while the IOMMU may still hold the old translation. It also
leaves a hole in "iommu/amd/pgtbl: fix DMA faults on IOVAs mapped while
the table grows": the DTE flush done before the new page table level is
published can return before the IOMMU has dropped the old DTE.

Patch 3 is the mainline fix 1e75a8255f11c. It waits for the last
allocated completion sequence number, which relies on the model
introduced by patches 1 and 2, also from mainline: the wait moves out of
iommu->lock and the sequence number is allocated under it. vz10 still
had the old model, an atomic increment outside the lock and the wait
under it. 6.12.y carries the same three commits. Patch 2 needed a
context fix only: vz10 has no cmd_sem_paddr in struct amd_iommu.

Tested on epyc06 (EPYC 7352, four Optane in one IOMMU group) with the
VSTOR-154276 reproducer: an out-of-tree module exhausts the group's
32-bit IOVA space while fio reads the drives, and a kprobe holds the DTE
update open for 5 ms. The stock 8.0 kernel gives IO_PAGE_FAULTs and fio
verify mismatches with no I/O error. 22.19 with the VSTOR-154276 fix and
this series gives no faults, no mismatches and no completion wait
timeouts.

https://virtuozzo.atlassian.net/browse/VSTOR-154424

Ankit Soni (2):
  ms/iommu/amd: move wait_on_sem() out of spinlock
  ms/iommu/amd: serialize sequence allocation under concurrent TLB
    invalidations

Guanghui Feng (1):
  ms/iommu/amd: Wait for completion instead of returning early in
    iommu_completion_wait()

 drivers/iommu/amd/amd_iommu_types.h |  2 +-
 drivers/iommu/amd/init.c            |  2 +-
 drivers/iommu/amd/iommu.c           | 61 ++++++++++++++++++++---------
 3 files changed, 45 insertions(+), 20 deletions(-)

-- 
2.53.0

_______________________________________________
Devel mailing list
[email protected]
https://lists.openvz.org/mailman/listinfo/devel

Reply via email to