From: Liu Yi L <yi.l.liu@intel.com>
To: baolu.lu@linux.intel.com, jacob.jun.pan@intel.com,
xin.zeng@intel.com, Kaijie.Guo@intel.com, will@kernel.org,
joro@8bytes.org
Cc: kevin.tian@intel.com, jun.j.tian@intel.com,
iommu@lists.linux-foundation.org, ashok.raj@intel.com
Subject: [PATCH 3/3] iommu/vt-d: A fix to iommu_flush_dev_iotlb() for aux-domain
Date: Sun, 20 Dec 2020 08:03:52 +0800 [thread overview]
Message-ID: <20201220000352.183523-4-yi.l.liu@intel.com> (raw)
In-Reply-To: <20201220000352.183523-1-yi.l.liu@intel.com>
iommu_flush_dev_iotlb() is called to invalidate caches on device. It only
loops the devices which are full-attached to the domain. For sub-devices,
this is ineffective. This results in invalid caching entries left on the
device. Fix it by adding loop for subdevices as well. Also, update the
domain->has_iotlb_device for both device/subdevice attach/detach and
ATS enabling/disabling.
Signed-off-by: Liu Yi L <yi.l.liu@intel.com>
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
---
drivers/iommu/intel/iommu.c | 90 +++++++++++++++++++++++++++++--------
1 file changed, 72 insertions(+), 18 deletions(-)
diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index 4274b4acc325..d9b6037b72b1 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -1437,6 +1437,10 @@ static void __iommu_flush_iotlb(struct intel_iommu *iommu, u16 did,
(unsigned long long)DMA_TLB_IAIG(val));
}
+/**
+ * For a given bus/devfn, fetch its device_domain_info if it supports
+ * device tlb. Only needs to loop devices attached in normal manner.
+ */
static struct device_domain_info *
iommu_support_dev_iotlb (struct dmar_domain *domain, struct intel_iommu *iommu,
u8 bus, u8 devfn)
@@ -1459,6 +1463,18 @@ iommu_support_dev_iotlb (struct dmar_domain *domain, struct intel_iommu *iommu,
return NULL;
}
+static bool dev_iotlb_enabled(struct device *dev)
+{
+ struct pci_dev *pdev;
+
+ if (!dev || !dev_is_pci(dev))
+ return false;
+
+ pdev = to_pci_dev(dev);
+
+ return !!pdev->ats_enabled;
+}
+
static void domain_update_iotlb(struct dmar_domain *domain)
{
struct device_domain_info *info;
@@ -1467,21 +1483,37 @@ static void domain_update_iotlb(struct dmar_domain *domain)
assert_spin_locked(&device_domain_lock);
list_for_each_entry(info, &domain->devices, link) {
- struct pci_dev *pdev;
-
- if (!info->dev || !dev_is_pci(info->dev))
- continue;
-
- pdev = to_pci_dev(info->dev);
- if (pdev->ats_enabled) {
+ if (dev_iotlb_enabled(info->dev)) {
has_iotlb_device = true;
break;
}
}
+ if (!has_iotlb_device) {
+ struct subdevice_domain_info *subinfo;
+
+ list_for_each_entry(subinfo, &domain->sub_devices, link_phys) {
+ if (dev_iotlb_enabled(subinfo->dev)) {
+ has_iotlb_device = true;
+ break;
+ }
+ }
+ }
domain->has_iotlb_device = has_iotlb_device;
}
+static void dev_update_domain_iotlb(struct device_domain_info *info)
+{
+ struct subdevice_domain_info *subinfo;
+
+ assert_spin_locked(&device_domain_lock);
+
+ domain_update_iotlb(info->domain);
+
+ list_for_each_entry(subinfo, &info->auxiliary_domains, link_domain)
+ domain_update_iotlb(subinfo->domain);
+}
+
static void iommu_enable_dev_iotlb(struct device_domain_info *info)
{
struct pci_dev *pdev;
@@ -1524,7 +1556,7 @@ static void iommu_enable_dev_iotlb(struct device_domain_info *info)
if (info->ats_supported && pci_ats_page_aligned(pdev) &&
!pci_enable_ats(pdev, VTD_PAGE_SHIFT)) {
info->ats_enabled = 1;
- domain_update_iotlb(info->domain);
+ dev_update_domain_iotlb(info);
info->ats_qdep = pci_ats_queue_depth(pdev);
}
}
@@ -1543,7 +1575,7 @@ static void iommu_disable_dev_iotlb(struct device_domain_info *info)
if (info->ats_enabled) {
pci_disable_ats(pdev);
info->ats_enabled = 0;
- domain_update_iotlb(info->domain);
+ dev_update_domain_iotlb(info);
}
#ifdef CONFIG_INTEL_IOMMU_SVM
if (info->pri_enabled) {
@@ -1557,26 +1589,43 @@ static void iommu_disable_dev_iotlb(struct device_domain_info *info)
#endif
}
+static void __iommu_flush_dev_iotlb(struct device_domain_info *info,
+ u64 addr, unsigned mask)
+{
+ u16 sid, qdep;
+
+ if (!info || !info->ats_enabled)
+ return;
+
+ sid = info->bus << 8 | info->devfn;
+ qdep = info->ats_qdep;
+ qi_flush_dev_iotlb(info->iommu, sid, info->pfsid,
+ qdep, addr, mask);
+}
+
static void iommu_flush_dev_iotlb(struct dmar_domain *domain,
u64 addr, unsigned mask)
{
- u16 sid, qdep;
unsigned long flags;
struct device_domain_info *info;
+ struct subdevice_domain_info *subinfo;
if (!domain->has_iotlb_device)
return;
spin_lock_irqsave(&device_domain_lock, flags);
- list_for_each_entry(info, &domain->devices, link) {
- if (!info->ats_enabled)
- continue;
+ list_for_each_entry(info, &domain->devices, link)
+ __iommu_flush_dev_iotlb(info, addr, mask);
+
+ /*
+ * Besides looping all devices attached normally, also
+ * needs to loop all devices attached via auxiliary
+ * manner.
+ */
+ list_for_each_entry(subinfo, &domain->sub_devices, link_phys)
+ __iommu_flush_dev_iotlb(get_domain_info(subinfo->dev),
+ addr, mask);
- sid = info->bus << 8 | info->devfn;
- qdep = info->ats_qdep;
- qi_flush_dev_iotlb(info->iommu, sid, info->pfsid,
- qdep, addr, mask);
- }
spin_unlock_irqrestore(&device_domain_lock, flags);
}
@@ -5208,6 +5257,9 @@ static void auxiliary_link_device(struct dmar_domain *domain,
subinfo->dev = dev;
list_add(&subinfo->link_domain, &info->auxiliary_domains);
list_add(&subinfo->link_phys, &domain->sub_devices);
+ if (dev_iotlb_enabled(dev))
+ domain_update_iotlb(domain);
+
_auxiliary_link_device(domain, subinfo, dev);
domain->auxd_refcnt++;
}
@@ -5242,6 +5294,8 @@ static int auxiliary_unlink_device(struct dmar_domain *domain,
list_del(&subinfo->link_domain);
list_del(&subinfo->link_phys);
kfree(subinfo);
+ if (domain->has_iotlb_device)
+ domain_update_iotlb(domain);
}
domain->auxd_refcnt--;
--
2.25.1
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
next prev parent reply other threads:[~2020-12-19 0:04 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-20 0:03 [PATCH 0/4] iommu/vtd-: Misc fixes on scalable mode Liu Yi L
2020-12-20 0:03 ` [PATCH 1/3] iommu/vt-d: Move intel_iommu info from struct intel_svm to struct intel_svm_dev Liu Yi L
2020-12-19 6:50 ` Lu Baolu
2020-12-21 1:43 ` Guo, Kaijie
2020-12-20 0:03 ` [PATCH 2/3] iommu/vt-d: Track device aux-attach with subdevice_domain_info Liu Yi L
2020-12-19 6:52 ` Lu Baolu
2020-12-22 20:21 ` Jacob Pan
2020-12-23 3:59 ` Liu, Yi L
2020-12-20 0:03 ` Liu Yi L [this message]
2020-12-19 6:52 ` [PATCH 3/3] iommu/vt-d: A fix to iommu_flush_dev_iotlb() for aux-domain Lu Baolu
2020-12-22 18:17 ` [PATCH 0/4] iommu/vtd-: Misc fixes on scalable mode Jacob Pan
2020-12-23 3:57 ` Liu, Yi L
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201220000352.183523-4-yi.l.liu@intel.com \
--to=yi.l.liu@intel.com \
--cc=Kaijie.Guo@intel.com \
--cc=ashok.raj@intel.com \
--cc=baolu.lu@linux.intel.com \
--cc=iommu@lists.linux-foundation.org \
--cc=jacob.jun.pan@intel.com \
--cc=joro@8bytes.org \
--cc=jun.j.tian@intel.com \
--cc=kevin.tian@intel.com \
--cc=will@kernel.org \
--cc=xin.zeng@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox