On Tue, Apr 12, 2022 at 09:13:27PM +0800, Lu Baolu wrote: > > > > btw as discussed in last version it is not necessarily to recalculate > > > > snoop control globally with this new approach. Will follow up to > > > > clean it up after this series is merged. > > > Agreed. But it also requires the enforce_cache_coherency() to be called > > > only after domain being attached to a device just as VFIO is doing. > > that actually makes sense, right? w/o device attached it's pointless to > > call that interface on a domain... > > Agreed. Return -EOPNOTSUPP or -EINVAL to tell the caller that this > operation is invalid before any device attachment. That is backwards. enforce_cache_coherency() succeeds on an empty domain and attach of an incompatible device must fail. Meaning you check the force_snoop flag in the domain when attaching and refuse to attach the device if it cannot support it. This will trigger vfio to create a new iommu_domain for that device and then enforce_cache_coherency() will fail on that domain due to the incompatible attached device. Same scenario if it is the Nth device to be attached to a domain. Jason