From: Jan Beulich Date: Fri, 15 Oct 2021 10:47:18 +0000 (+0200) Subject: AMD/IOMMU: pull ATS disabling earlier X-Git-Tag: archive/raspbian/4.16.0+51-g0941d6cb-1+rpi1~2^2~42^2~80 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=388b5f1be68861b8abaf67e6a311b09b5a0816c5;p=xen.git AMD/IOMMU: pull ATS disabling earlier Disabling should be done in the opposite order of enabling: ATS wants to be turned off before adjusting the DTE, just like it gets enabled only after the DTE was suitably prepared. Note that we want ATS to be disabled as soon as any of the DTEs involved in the handling of a device (including phantom devices) gets adjusted respectively. For this reason the "devfn == pdev->devfn" of the original conditional gets dropped. Signed-off-by: Jan Beulich Reviewed-by: Paul Durrant --- diff --git a/xen/drivers/passthrough/amd/pci_amd_iommu.c b/xen/drivers/passthrough/amd/pci_amd_iommu.c index 45d16b731f..63fa426273 100644 --- a/xen/drivers/passthrough/amd/pci_amd_iommu.c +++ b/xen/drivers/passthrough/amd/pci_amd_iommu.c @@ -313,6 +313,12 @@ static void amd_iommu_disable_domain_device(const struct domain *domain, if ( QUARANTINE_SKIP(domain) ) return; + ASSERT(pcidevs_locked()); + + if ( pci_ats_device(iommu->seg, bus, pdev->devfn) && + pci_ats_enabled(iommu->seg, bus, pdev->devfn) ) + disable_ats_device(pdev); + BUG_ON ( iommu->dev_table.buffer == NULL ); req_id = get_dma_requestor_id(iommu->seg, PCI_BDF2(bus, devfn)); table = iommu->dev_table.buffer; @@ -348,13 +354,6 @@ static void amd_iommu_disable_domain_device(const struct domain *domain, } else spin_unlock_irqrestore(&iommu->lock, flags); - - ASSERT(pcidevs_locked()); - - if ( devfn == pdev->devfn && - pci_ats_device(iommu->seg, bus, devfn) && - pci_ats_enabled(iommu->seg, bus, devfn) ) - disable_ats_device(pdev); } static int reassign_device(struct domain *source, struct domain *target,