Skip to content

Commit ccb02b2

Browse files
LuBaolujoergroedel
authored andcommitted
iommu/vt-d: Move PCI PASID enablement to probe path
Currently, PCI PASID is enabled alongside PCI ATS when an iommu domain is attached to the device and disabled when the device transitions to block translation mode. This approach is inappropriate as PCI PASID is a device feature independent of the type of the attached domain. Enable PCI PASID during the IOMMU device probe and disables it during the release path. Suggested-by: Yi Liu <[email protected]> Signed-off-by: Lu Baolu <[email protected]> Reviewed-by: Yi Liu <[email protected]> Tested-by: Yi Liu <[email protected]> Reviewed-by: Jason Gunthorpe <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent 3cf7423 commit ccb02b2

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

drivers/iommu/intel/iommu.c

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,15 +1281,6 @@ static void iommu_enable_pci_caps(struct device_domain_info *info)
12811281
return;
12821282

12831283
pdev = to_pci_dev(info->dev);
1284-
1285-
/* The PCIe spec, in its wisdom, declares that the behaviour of
1286-
the device if you enable PASID support after ATS support is
1287-
undefined. So always enable PASID support on devices which
1288-
have it, even if we can't yet know if we're ever going to
1289-
use it. */
1290-
if (info->pasid_supported && !pci_enable_pasid(pdev, info->pasid_supported & ~1))
1291-
info->pasid_enabled = 1;
1292-
12931284
if (info->ats_supported && pci_ats_page_aligned(pdev) &&
12941285
!pci_enable_ats(pdev, VTD_PAGE_SHIFT))
12951286
info->ats_enabled = 1;
@@ -1308,11 +1299,6 @@ static void iommu_disable_pci_caps(struct device_domain_info *info)
13081299
pci_disable_ats(pdev);
13091300
info->ats_enabled = 0;
13101301
}
1311-
1312-
if (info->pasid_enabled) {
1313-
pci_disable_pasid(pdev);
1314-
info->pasid_enabled = 0;
1315-
}
13161302
}
13171303

13181304
static void intel_flush_iotlb_all(struct iommu_domain *domain)
@@ -3940,6 +3926,16 @@ static struct iommu_device *intel_iommu_probe_device(struct device *dev)
39403926

39413927
intel_iommu_debugfs_create_dev(info);
39423928

3929+
/*
3930+
* The PCIe spec, in its wisdom, declares that the behaviour of the
3931+
* device is undefined if you enable PASID support after ATS support.
3932+
* So always enable PASID support on devices which have it, even if
3933+
* we can't yet know if we're ever going to use it.
3934+
*/
3935+
if (info->pasid_supported &&
3936+
!pci_enable_pasid(pdev, info->pasid_supported & ~1))
3937+
info->pasid_enabled = 1;
3938+
39433939
return &iommu->iommu;
39443940
free_table:
39453941
intel_pasid_free_table(dev);
@@ -3956,6 +3952,11 @@ static void intel_iommu_release_device(struct device *dev)
39563952
struct device_domain_info *info = dev_iommu_priv_get(dev);
39573953
struct intel_iommu *iommu = info->iommu;
39583954

3955+
if (info->pasid_enabled) {
3956+
pci_disable_pasid(to_pci_dev(dev));
3957+
info->pasid_enabled = 0;
3958+
}
3959+
39593960
mutex_lock(&iommu->iopf_lock);
39603961
if (dev_is_pci(dev) && pci_ats_supported(to_pci_dev(dev)))
39613962
device_rbtree_remove(info);

0 commit comments

Comments
 (0)