Skip to content

Commit 7c29ada

Browse files
yiliu1765willdeacon
authored andcommitted
iommu/vt-d: Fix ineffective devTLB invalidation for subdevices
iommu_flush_dev_iotlb() is called to invalidate caches on a device but only loops over the devices which are fully-attached to the domain. For sub-devices, this is ineffective and can result in invalid caching entries left on the device. Fix the missing invalidation by adding a loop over the subdevices and ensuring that 'domain->has_iotlb_device' is updated when attaching to subdevices. Fixes: 67b8e02 ("iommu/vt-d: Aux-domain specific domain attach/detach") Signed-off-by: Liu Yi L <[email protected]> Acked-by: Lu Baolu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent 18abda7 commit 7c29ada

File tree

1 file changed

+37
-16
lines changed

1 file changed

+37
-16
lines changed

drivers/iommu/intel/iommu.c

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,8 @@ static int domain_update_device_node(struct dmar_domain *domain)
719719
return nid;
720720
}
721721

722+
static void domain_update_iotlb(struct dmar_domain *domain);
723+
722724
/* Some capabilities may be different across iommus */
723725
static void domain_update_iommu_cap(struct dmar_domain *domain)
724726
{
@@ -744,6 +746,8 @@ static void domain_update_iommu_cap(struct dmar_domain *domain)
744746
domain->domain.geometry.aperture_end = __DOMAIN_MAX_ADDR(domain->gaw - 1);
745747
else
746748
domain->domain.geometry.aperture_end = __DOMAIN_MAX_ADDR(domain->gaw);
749+
750+
domain_update_iotlb(domain);
747751
}
748752

749753
struct context_entry *iommu_context_addr(struct intel_iommu *iommu, u8 bus,
@@ -1464,17 +1468,22 @@ static void domain_update_iotlb(struct dmar_domain *domain)
14641468

14651469
assert_spin_locked(&device_domain_lock);
14661470

1467-
list_for_each_entry(info, &domain->devices, link) {
1468-
struct pci_dev *pdev;
1469-
1470-
if (!info->dev || !dev_is_pci(info->dev))
1471-
continue;
1472-
1473-
pdev = to_pci_dev(info->dev);
1474-
if (pdev->ats_enabled) {
1471+
list_for_each_entry(info, &domain->devices, link)
1472+
if (info->ats_enabled) {
14751473
has_iotlb_device = true;
14761474
break;
14771475
}
1476+
1477+
if (!has_iotlb_device) {
1478+
struct subdev_domain_info *sinfo;
1479+
1480+
list_for_each_entry(sinfo, &domain->subdevices, link_domain) {
1481+
info = get_domain_info(sinfo->pdev);
1482+
if (info && info->ats_enabled) {
1483+
has_iotlb_device = true;
1484+
break;
1485+
}
1486+
}
14781487
}
14791488

14801489
domain->has_iotlb_device = has_iotlb_device;
@@ -1555,25 +1564,37 @@ static void iommu_disable_dev_iotlb(struct device_domain_info *info)
15551564
#endif
15561565
}
15571566

1567+
static void __iommu_flush_dev_iotlb(struct device_domain_info *info,
1568+
u64 addr, unsigned int mask)
1569+
{
1570+
u16 sid, qdep;
1571+
1572+
if (!info || !info->ats_enabled)
1573+
return;
1574+
1575+
sid = info->bus << 8 | info->devfn;
1576+
qdep = info->ats_qdep;
1577+
qi_flush_dev_iotlb(info->iommu, sid, info->pfsid,
1578+
qdep, addr, mask);
1579+
}
1580+
15581581
static void iommu_flush_dev_iotlb(struct dmar_domain *domain,
15591582
u64 addr, unsigned mask)
15601583
{
1561-
u16 sid, qdep;
15621584
unsigned long flags;
15631585
struct device_domain_info *info;
1586+
struct subdev_domain_info *sinfo;
15641587

15651588
if (!domain->has_iotlb_device)
15661589
return;
15671590

15681591
spin_lock_irqsave(&device_domain_lock, flags);
1569-
list_for_each_entry(info, &domain->devices, link) {
1570-
if (!info->ats_enabled)
1571-
continue;
1592+
list_for_each_entry(info, &domain->devices, link)
1593+
__iommu_flush_dev_iotlb(info, addr, mask);
15721594

1573-
sid = info->bus << 8 | info->devfn;
1574-
qdep = info->ats_qdep;
1575-
qi_flush_dev_iotlb(info->iommu, sid, info->pfsid,
1576-
qdep, addr, mask);
1595+
list_for_each_entry(sinfo, &domain->subdevices, link_domain) {
1596+
info = get_domain_info(sinfo->pdev);
1597+
__iommu_flush_dev_iotlb(info, addr, mask);
15771598
}
15781599
spin_unlock_irqrestore(&device_domain_lock, flags);
15791600
}

0 commit comments

Comments
 (0)