public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Lu Baolu <baolu.lu@linux.intel.com>
To: Joerg Roedel <joro@8bytes.org>, Will Deacon <will@kernel.org>,
	Robin Murphy <robin.murphy@arm.com>,
	Kevin Tian <kevin.tian@intel.com>,
	Jacek Lawrynowicz <jacek.lawrynowicz@linux.intel.com>
Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org,
	Lu Baolu <baolu.lu@linux.intel.com>
Subject: [PATCH 1/1] iommu/vt-d: Fix missed device TLB cache tag
Date: Wed, 19 Jun 2024 09:53:45 +0800	[thread overview]
Message-ID: <20240619015345.182773-1-baolu.lu@linux.intel.com> (raw)

When a domain is attached to a device, the required cache tags are
assigned to the domain so that the related caches could be flushed
whenever it is needed. The device TLB cache tag is created selectively 
by checking the ats_enabled field of the device's iommu data. This
creates an ordered dependency between attach and ATS enabling paths.

The device TLB cache tag will not be created if device's ATS is enabled
after the domain attachment. This causes some devices, for example
intel_vpu, to malfunction.

Create device TLB cache tags for a domain as long as the ats_supported
field of the attached device is true. In the cache invalidation paths,
the ats_enable field is checked and the device TLB invalidation requests
are issued only when the ATS is really enabled on the device.

Fixes: 3b1d9e2b2d68 ("iommu/vt-d: Add cache tag assignment interface")
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
---
 drivers/iommu/intel/cache.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/drivers/iommu/intel/cache.c b/drivers/iommu/intel/cache.c
index e8418cdd8331..ec6770f556b9 100644
--- a/drivers/iommu/intel/cache.c
+++ b/drivers/iommu/intel/cache.c
@@ -112,7 +112,7 @@ static int __cache_tag_assign_domain(struct dmar_domain *domain, u16 did,
 	int ret;
 
 	ret = cache_tag_assign(domain, did, dev, pasid, CACHE_TAG_IOTLB);
-	if (ret || !info->ats_enabled)
+	if (ret || !info->ats_supported)
 		return ret;
 
 	ret = cache_tag_assign(domain, did, dev, pasid, CACHE_TAG_DEVTLB);
@@ -129,7 +129,7 @@ static void __cache_tag_unassign_domain(struct dmar_domain *domain, u16 did,
 
 	cache_tag_unassign(domain, did, dev, pasid, CACHE_TAG_IOTLB);
 
-	if (info->ats_enabled)
+	if (info->ats_supported)
 		cache_tag_unassign(domain, did, dev, pasid, CACHE_TAG_DEVTLB);
 }
 
@@ -140,7 +140,7 @@ static int __cache_tag_assign_parent_domain(struct dmar_domain *domain, u16 did,
 	int ret;
 
 	ret = cache_tag_assign(domain, did, dev, pasid, CACHE_TAG_NESTING_IOTLB);
-	if (ret || !info->ats_enabled)
+	if (ret || !info->ats_supported)
 		return ret;
 
 	ret = cache_tag_assign(domain, did, dev, pasid, CACHE_TAG_NESTING_DEVTLB);
@@ -157,7 +157,7 @@ static void __cache_tag_unassign_parent_domain(struct dmar_domain *domain, u16 d
 
 	cache_tag_unassign(domain, did, dev, pasid, CACHE_TAG_NESTING_IOTLB);
 
-	if (info->ats_enabled)
+	if (info->ats_supported)
 		cache_tag_unassign(domain, did, dev, pasid, CACHE_TAG_NESTING_DEVTLB);
 }
 
@@ -309,6 +309,9 @@ void cache_tag_flush_range(struct dmar_domain *domain, unsigned long start,
 			info = dev_iommu_priv_get(tag->dev);
 			sid = PCI_DEVID(info->bus, info->devfn);
 
+			if (!info->ats_enabled)
+				break;
+
 			if (tag->pasid == IOMMU_NO_PASID)
 				qi_flush_dev_iotlb(iommu, sid, info->pfsid,
 						   info->ats_qdep, addr, mask);
@@ -356,6 +359,9 @@ void cache_tag_flush_all(struct dmar_domain *domain)
 			info = dev_iommu_priv_get(tag->dev);
 			sid = PCI_DEVID(info->bus, info->devfn);
 
+			if (!info->ats_enabled)
+				break;
+
 			qi_flush_dev_iotlb(iommu, sid, info->pfsid, info->ats_qdep,
 					   0, MAX_AGAW_PFN_WIDTH);
 			quirk_extra_dev_tlb_flush(info, 0, MAX_AGAW_PFN_WIDTH,
-- 
2.34.1


             reply	other threads:[~2024-06-19  1:56 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-19  1:53 Lu Baolu [this message]
2024-06-19 16:46 ` [PATCH 1/1] iommu/vt-d: Fix missed device TLB cache tag Jason Gunthorpe
2024-06-20  0:50   ` Baolu Lu
2024-06-20  3:04     ` Tian, Kevin
2024-06-20  3:13       ` Baolu Lu
2024-06-20  3:57         ` Tian, Kevin
2024-06-20  6:04           ` Baolu Lu
2024-06-20  5:54         ` Vasant Hegde
2024-06-20  6:27           ` Baolu Lu
2024-06-20 10:49             ` Vasant Hegde
2024-06-20 14:08               ` Jason Gunthorpe
2024-06-21  1:44                 ` Baolu Lu
2024-06-21 12:58                   ` Jason Gunthorpe
2024-06-24 14:26                 ` Vasant Hegde
2024-06-24 16:12                   ` Jason Gunthorpe

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=20240619015345.182773-1-baolu.lu@linux.intel.com \
    --to=baolu.lu@linux.intel.com \
    --cc=iommu@lists.linux.dev \
    --cc=jacek.lawrynowicz@linux.intel.com \
    --cc=joro@8bytes.org \
    --cc=kevin.tian@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robin.murphy@arm.com \
    --cc=will@kernel.org \
    /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