• Jason Gunthorpe's avatar
    iommu/arm-smmu-v3: Make changing domains be hitless for ATS · 7497f421
    Jason Gunthorpe authored
    The core code allows the domain to be changed on the fly without a forced
    stop in BLOCKED/IDENTITY. In this flow the driver should just continually
    maintain the ATS with no change while the STE is updated.
    
    ATS relies on a linked list smmu_domain->devices to keep track of which
    masters have the domain programmed, but this list is also used by
    arm_smmu_share_asid(), unrelated to ats.
    
    Create two new functions to encapsulate this combined logic:
     arm_smmu_attach_prepare()
     <caller generates and sets the STE>
     arm_smmu_attach_commit()
    
    The two functions can sequence both enabling ATS and disabling across
    the STE store. Have every update of the STE use this sequence.
    
    Installing a S1/S2 domain always enables the ATS if the PCIe device
    supports it.
    
    The enable flow is now ordered differently to allow it to be hitless:
    
     1) Add the master to the new smmu_domain->devices list
     2) Program the STE
     3) Enable ATS at PCIe
     4) Remove the master from the old smmu_domain
    
    This flow ensures that invalidations to either domain will generate an ATC
    invalidation to the device while the STE is being switched. Thus we don't
    need to turn off the ATS anymore for correctness.
    
    The disable flow is the reverse:
     1) Disable ATS at PCIe
     2) Program the STE
     3) Invalidate the ATC
     4) Remove the master from the old smmu_domain
    
    Move the nr_ats_masters adjustments to be close to the list
    manipulations. It is a count of the number of ATS enabled masters
    currently in the list. This is stricly before and after the STE/CD are
    revised, and done under the list's spin_lock.
    
    This is part of the bigger picture to allow changing the RID domain while
    a PASID is in use. If a SVA PASID is relying on ATS to function then
    changing the RID domain cannot just temporarily toggle ATS off without
    also wrecking the SVA PASID. The new infrastructure here is organized so
    that the PASID attach/detach flows will make use of it as well in
    following patches.
    Tested-by: default avatarNicolin Chen <nicolinc@nvidia.com>
    Tested-by: default avatarShameer Kolothum <shameerali.kolothum.thodi@huawei.com>
    Reviewed-by: default avatarNicolin Chen <nicolinc@nvidia.com>
    Reviewed-by: default avatarMichael Shavit <mshavit@google.com>
    Reviewed-by: default avatarJerry Snitselaar <jsnitsel@redhat.com>
    Signed-off-by: default avatarJason Gunthorpe <jgg@nvidia.com>
    Link: https://lore.kernel.org/r/4-v9-5cd718286059+79186-smmuv3_newapi_p2b_jgg@nvidia.comSigned-off-by: default avatarWill Deacon <will@kernel.org>
    7497f421
arm-smmu-v3.h 23.3 KB