RE: [PATCH v4 6/7] iommu: Introduce iommu_dev_reset_prepare() and iommu_dev_reset_done()

Tian, Kevin
2025-09-12T09:49:19Z

> From: Nicolin Chen <nicolinc@nvidia.com>
> Sent: Monday, September 1, 2025 7:32 AM
>
> 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 all the attached domain to
> BLOCKED.
> After attaching a BLOCKED domain, IOMMU hardware would fence any
> incoming
> ATS queries. And IOMMU drivers should also synchronously stop issuing new
> ATS invalidations and wait for all ATS invalidations to complete. This can
> avoid any ATS invaliation timeouts.
>
> However, if there is a domain attachment/replacement happening during an
> ongoing reset, ATS routines may be re-activated between the two function
> calls. So, introduce a new pending_reset flag in group_device, and reject
> any concurrent attach_dev/set_dev_pasid call during a reset for a concern
> of compatibility failure.
>
> There are two corner cases that won't work:
> 1. Alias devices that share the same RID
> Blocking one device also blocks the other alias devices that might not
> want a reset. Given that it's very rare for an alias device to support
> ATS, simply skip the blocking routine.

it also applies to the devices in the same iommu group. While one device
is being reset, all other devices in the group cannot change the domain.
This needs to be documented in the attach uAPI.

>
> 2. SRIOV devices that its PF is resetting while its VF isn't.
> Both PF and VF should block RID and PASIDs. But, since VF is not aware
> of the reset, it is difficult to block it and reject concurrent attach
> calls, because it's not logically reasonable to reject a VF attachment
> due to a resetting PF unless the VF is resetting too. To address this,
> we won't be able to reject any concurrent attachment as simple as this
> patch does; instead we will need two new compatibility testing ops for
> attach_dev/set_dev_pasid to allowing caching a compatible attach. This
> itself, however, would be a big series. So, for now, skip the blocking
> routine for PF devices, and leave a note.
>

given it impacts uAPI:

- now attach/replace can be done anytime
- with this series attach/replace is rejected when a device is being reset
- later with compat testing ops attach/replace can be done again at
any time

we should be cautious here, especially if this series goes into 6.18 (likely
the next LTS version) the interim behavior change may last long. yes
we discussed that no know usage would want to do attach/replace
while a device is being reset, but I wonder whether we should instead
wait for a full solution to avoid unnecessary uAPI change back-and-forth...

Thanks
Kevin