patches.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH v5 0/5] Disable ATS via iommu during PCI resets
@ 2025-11-11  5:12 Nicolin Chen
  2025-11-11  5:12 ` [PATCH v5 1/5] iommu: Lock group->mutex in iommu_deferred_attach() Nicolin Chen
                   ` (4 more replies)
  0 siblings, 5 replies; 36+ messages in thread
From: Nicolin Chen @ 2025-11-11  5:12 UTC (permalink / raw)
  To: joro, afael, bhelgaas, alex, jgg, kevin.tian
  Cc: will, robin.murphy, lenb, baolu.lu, linux-arm-kernel, iommu,
	linux-kernel, linux-acpi, linux-pci, kvm, patches, pjaroszynski,
	vsethi, helgaas, etzhao1900

Hi all,

PCIe permits a device to ignore ATS invalidation TLPs, while processing a
reset. This creates a problem visible to the OS where an ATS invalidation
command will time out: e.g. an SVA domain will have no coordination with a
reset event and can racily issue ATS invalidations to a resetting device.

The OS should do something to mitigate this as we do not want production
systems to be reporting critical ATS failures, especially in a hypervisor
environment. Broadly, OS could arrange to ignore the timeouts, block page
table mutations to prevent invalidations, or disable and block ATS.

The PCIe spec in sec 10.3.1 IMPLEMENTATION NOTE recommends to disable and
block ATS before initiating a Function Level Reset. It also mentions that
other reset methods could have the same vulnerability as well.

Provide a callback from the PCI subsystem that will enclose the reset and
have the iommu core temporarily change domains to group->blocking_domain,
so IOMMU drivers would fence any incoming ATS queries, synchronously stop
issuing new ATS invalidations, and wait for existing ATS invalidations to
complete. Doing this can avoid any ATS invaliation timeouts.

When a device is resetting, any new domain attachment has to be rejected,
until the reset is finished, to prevent ATS activity from being activated
between the two callback functions. Introduce a new resetting_domain, and
reject a concurrent __iommu_attach_device/set_group_pasid().

Finally, apply these iommu_dev_reset_prepare/done() functions in the PCI
reset functions.

Note this series does not support a shared iommu_group cases. And PF will
be blocked, even though VFs (that are already broken) would not be aware
of the reset.

This is on Github:
https://github.com/nicolinc/iommufd/commits/iommu_dev_reset-v5

Changelog
v5
 * Rebase on Joerg's next tree
 * [iommu] Skip in shared iommu_group cases
 * [iommu] Pass in default_domain to iommu_setup_dma_ops
 * [iommu] Add kdocs to iommu_get_domain_for_dev_locked()
 * [iommu] s/get_domain_for_dev_locked/driver_get_domain_for_dev
 * [iommu] Replace per-gdev pending_reset with per-group resetting_domain
v4
 https://lore.kernel.org/all/cover.1756682135.git.nicolinc@nvidia.com/
 * Add Reviewed-by from Baolu
 * [iommu] Use guard(mutex)
 * [iommu] Update kdocs for typos and revisings
 * [iommu] Skip two corner cases (alias and SRIOV)
 * [iommu] Rework attach_dev to pass in old domain pointer
 * [iommu] Reject concurrent attach_dev/set_dev_pasid for compatibility
           concern
 * [smmuv3] Drop the old_domain depedency in its release_dev callback
 * [pci] Add pci_reset_iommu_prepare/_done() wrappers checking ATS cap
v3
 https://lore.kernel.org/all/cover.1754952762.git.nicolinc@nvidia.com/
 * Add Reviewed-by from Jason
 * [iommu] Add a fast return in iommu_deferred_attach()
 * [iommu] Update kdocs, inline comments, and commit logs
 * [iommu] Use group->blocking_domain v.s. ops->blocked_domain
 * [iommu] Drop require_direct, iommu_group_get(), and xa_lock()
 * [iommu] Set the pending_reset flag after RID/PASID domain setups
 * [iommu] Do not bypass PASID domains when RID domain is already the
           blocking_domain
 * [iommu] Add iommu_get_domain_for_dev_locked to correctly return the
           blocking_domain
v2
 https://lore.kernel.org/all/cover.1751096303.git.nicolinc@nvidia.com/
 * [iommu] Update kdocs, inline comments, and commit logs
 * [iommu] Replace long-holding group->mutex with a pending_reset flag
 * [pci] Abort reset routines if iommu_dev_reset_prepare() fails
 * [pci] Apply the same vulnerability fix to other reset functions
v1
 https://lore.kernel.org/all/cover.1749494161.git.nicolinc@nvidia.com/

Thanks
Nicolin

Nicolin Chen (5):
  iommu: Lock group->mutex in iommu_deferred_attach()
  iommu: Tiny domain for iommu_setup_dma_ops()
  iommu: Add iommu_driver_get_domain_for_dev() helper
  iommu: Introduce iommu_dev_reset_prepare() and iommu_dev_reset_done()
  pci: Suspend iommu function prior to resetting a device

 drivers/iommu/dma-iommu.h                   |   5 +-
 drivers/pci/pci.h                           |   2 +
 include/linux/iommu.h                       |  13 ++
 include/uapi/linux/vfio.h                   |   3 +
 drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c |   5 +-
 drivers/iommu/dma-iommu.c                   |   4 +-
 drivers/iommu/iommu.c                       | 230 +++++++++++++++++++-
 drivers/pci/pci-acpi.c                      |  12 +-
 drivers/pci/pci.c                           |  68 +++++-
 drivers/pci/quirks.c                        |  18 +-
 10 files changed, 339 insertions(+), 21 deletions(-)

-- 
2.43.0


^ permalink raw reply	[flat|nested] 36+ messages in thread

end of thread, other threads:[~2025-11-19  2:57 UTC | newest]

Thread overview: 36+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-11  5:12 [PATCH v5 0/5] Disable ATS via iommu during PCI resets Nicolin Chen
2025-11-11  5:12 ` [PATCH v5 1/5] iommu: Lock group->mutex in iommu_deferred_attach() Nicolin Chen
2025-11-12  2:47   ` Baolu Lu
2025-11-11  5:12 ` [PATCH v5 2/5] iommu: Tiny domain for iommu_setup_dma_ops() Nicolin Chen
2025-11-12  5:22   ` Baolu Lu
2025-11-14  9:17   ` Tian, Kevin
2025-11-14  9:18   ` Tian, Kevin
2025-11-11  5:12 ` [PATCH v5 3/5] iommu: Add iommu_driver_get_domain_for_dev() helper Nicolin Chen
2025-11-12  5:58   ` Baolu Lu
2025-11-12 17:41     ` Nicolin Chen
2025-11-18  7:02       ` Nicolin Chen
2025-11-19  2:47         ` Baolu Lu
2025-11-19  2:57           ` Nicolin Chen
2025-11-12  8:52   ` kernel test robot
2025-11-14  9:18   ` Tian, Kevin
2025-11-11  5:12 ` [PATCH v5 4/5] iommu: Introduce iommu_dev_reset_prepare() and iommu_dev_reset_done() Nicolin Chen
2025-11-12  6:18   ` Baolu Lu
2025-11-12 17:43     ` Nicolin Chen
2025-11-14  9:37   ` Tian, Kevin
2025-11-14 18:26     ` Nicolin Chen
2025-11-17  4:59   ` Tian, Kevin
2025-11-17 19:27     ` Nicolin Chen
2025-11-17 23:04   ` Bjorn Helgaas
2025-11-11  5:12 ` [PATCH v5 5/5] pci: Suspend iommu function prior to resetting a device Nicolin Chen
2025-11-14  9:45   ` Tian, Kevin
2025-11-14 18:00     ` Nicolin Chen
2025-11-17  4:52       ` Tian, Kevin
2025-11-17 19:26         ` Nicolin Chen
2025-11-18  0:29           ` Tian, Kevin
2025-11-18  1:42             ` Nicolin Chen
2025-11-18  5:38               ` Baolu Lu
2025-11-18  6:53                 ` Nicolin Chen
2025-11-18  7:53               ` Tian, Kevin
2025-11-18  8:17                 ` Nicolin Chen
2025-11-17 22:58   ` Bjorn Helgaas
2025-11-18  8:16     ` Nicolin Chen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).