All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 0/3] Misc fixes to intel iommu driver
@ 2021-08-17  4:24 Liu Yi L
  2021-08-17  4:24 ` [PATCH v1 1/3] iommu/vt-d: Using pasid_pte_is_present() helper function Liu Yi L
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Liu Yi L @ 2021-08-17  4:24 UTC (permalink / raw)
  To: iommu, baolu.lu; +Cc: yi.y.sun, jun.j.tian

Hi,

This series includes two minor enhancements and one bug fix. Please have
a review.

Thanks,
Yi Liu
---

Liu Yi L (3):
  iommu/vt-d: Using pasid_pte_is_present() helper function
  iommu/vt-d: Add present bit check in pasid entry setup helper
    functions
  iommu/vt-d: Fix Unexpected page request in Privilege Mode

 drivers/iommu/intel/pasid.c | 28 +++++++++++++++++++++++++---
 drivers/iommu/intel/pasid.h |  5 +++++
 2 files changed, 30 insertions(+), 3 deletions(-)

-- 
2.25.1

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v1 1/3] iommu/vt-d: Using pasid_pte_is_present() helper function
  2021-08-17  4:24 [PATCH v1 0/3] Misc fixes to intel iommu driver Liu Yi L
@ 2021-08-17  4:24 ` Liu Yi L
  2021-08-17  4:24 ` [PATCH v1 2/3] iommu/vt-d: Add present bit check in pasid entry setup helper functions Liu Yi L
  2021-08-17  4:24 ` [PATCH v1 3/3] iommu/vt-d: Fix Unexpected page request in Privilege Mode Liu Yi L
  2 siblings, 0 replies; 5+ messages in thread
From: Liu Yi L @ 2021-08-17  4:24 UTC (permalink / raw)
  To: iommu, baolu.lu; +Cc: yi.y.sun, jun.j.tian

Use pasid_pte_is_present() for present bit check in intel_pasid_tear_down_entry().

Cc: Lu Baolu <baolu.lu@linux.intel.com>
Signed-off-by: Liu Yi L <yi.l.liu@intel.com>
---
 drivers/iommu/intel/pasid.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iommu/intel/pasid.c b/drivers/iommu/intel/pasid.c
index c6cf44a6c923..02e10491184b 100644
--- a/drivers/iommu/intel/pasid.c
+++ b/drivers/iommu/intel/pasid.c
@@ -517,7 +517,7 @@ void intel_pasid_tear_down_entry(struct intel_iommu *iommu, struct device *dev,
 	if (WARN_ON(!pte))
 		return;
 
-	if (!(pte->val[0] & PASID_PTE_PRESENT))
+	if (!pasid_pte_is_present(pte))
 		return;
 
 	did = pasid_get_domain_id(pte);
-- 
2.25.1

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v1 2/3] iommu/vt-d: Add present bit check in pasid entry setup helper functions
  2021-08-17  4:24 [PATCH v1 0/3] Misc fixes to intel iommu driver Liu Yi L
  2021-08-17  4:24 ` [PATCH v1 1/3] iommu/vt-d: Using pasid_pte_is_present() helper function Liu Yi L
@ 2021-08-17  4:24 ` Liu Yi L
  2021-08-17  4:24 ` [PATCH v1 3/3] iommu/vt-d: Fix Unexpected page request in Privilege Mode Liu Yi L
  2 siblings, 0 replies; 5+ messages in thread
From: Liu Yi L @ 2021-08-17  4:24 UTC (permalink / raw)
  To: iommu, baolu.lu; +Cc: yi.y.sun, jun.j.tian

The helper functions is not capable to modify the pasid entries which
are still in use. So should have a check against present bit.

Cc: Lu Baolu <baolu.lu@linux.intel.com>
Signed-off-by: Liu Yi L <yi.l.liu@intel.com>
---
 drivers/iommu/intel/pasid.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/drivers/iommu/intel/pasid.c b/drivers/iommu/intel/pasid.c
index 02e10491184b..b1d0c2945c9a 100644
--- a/drivers/iommu/intel/pasid.c
+++ b/drivers/iommu/intel/pasid.c
@@ -534,6 +534,10 @@ void intel_pasid_tear_down_entry(struct intel_iommu *iommu, struct device *dev,
 		devtlb_invalidation_with_pasid(iommu, dev, pasid);
 }
 
+/*
+ * This function flushes cache for a newly setup pasid table entry.
+ * Caller of it should not modify the in-use pasid table entries.
+ */
 static void pasid_flush_caches(struct intel_iommu *iommu,
 				struct pasid_entry *pte,
 			       u32 pasid, u16 did)
@@ -585,6 +589,10 @@ int intel_pasid_setup_first_level(struct intel_iommu *iommu,
 	if (WARN_ON(!pte))
 		return -EINVAL;
 
+	/* Caller must ensure PASID entry is not in use. */
+	if (pasid_pte_is_present(pte))
+		return -EBUSY;
+
 	pasid_clear_entry(pte);
 
 	/* Setup the first level page table pointer: */
@@ -684,6 +692,10 @@ int intel_pasid_setup_second_level(struct intel_iommu *iommu,
 		return -ENODEV;
 	}
 
+	/* Caller must ensure PASID entry is not in use. */
+	if (pasid_pte_is_present(pte))
+		return -EBUSY;
+
 	pasid_clear_entry(pte);
 	pasid_set_domain_id(pte, did);
 	pasid_set_slptr(pte, pgd_val);
@@ -723,6 +735,10 @@ int intel_pasid_setup_pass_through(struct intel_iommu *iommu,
 		return -ENODEV;
 	}
 
+	/* Caller must ensure PASID entry is not in use. */
+	if (pasid_pte_is_present(pte))
+		return -EBUSY;
+
 	pasid_clear_entry(pte);
 	pasid_set_domain_id(pte, did);
 	pasid_set_address_width(pte, iommu->agaw);
-- 
2.25.1

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v1 3/3] iommu/vt-d: Fix Unexpected page request in Privilege Mode
  2021-08-17  4:24 [PATCH v1 0/3] Misc fixes to intel iommu driver Liu Yi L
  2021-08-17  4:24 ` [PATCH v1 1/3] iommu/vt-d: Using pasid_pte_is_present() helper function Liu Yi L
  2021-08-17  4:24 ` [PATCH v1 2/3] iommu/vt-d: Add present bit check in pasid entry setup helper functions Liu Yi L
@ 2021-08-17  4:24 ` Liu Yi L
  2021-08-17 12:49   ` Lu Baolu
  2 siblings, 1 reply; 5+ messages in thread
From: Liu Yi L @ 2021-08-17  4:24 UTC (permalink / raw)
  To: iommu, baolu.lu; +Cc: yi.y.sun, jun.j.tian

This patch fixes the below error. This is due to improper iotlb invalidation
in intel_pasid_tear_down_entry().

[  180.187556] Unexpected page request in Privilege Mode
[  180.187565] Unexpected page request in Privilege Mode
[  180.279933] Unexpected page request in Privilege Mode
[  180.279937] Unexpected page request in Privilege Mode

Per chapter 6.5.3.3 of VT-d spec 3.3, when tear down a pasid entry, software
should use Domain selective IOTLB flush if the PGTT of the pasid entry is
SL only or Nested, while for the pasid entries whose PGTT is FL only or PT
using PASID-based IOTLB flush is enough.

Fixes: 1c4f88b7f1f9 ("iommu/vt-d: Shared virtual address in scalable mode")
Cc: Lu Baolu <baolu.lu@linux.intel.com>
Signed-off-by: Kumar Sanjay K <sanjay.k.kumar@intel.com>
Signed-off-by: Liu Yi L <yi.l.liu@intel.com>
Tested-by: Yi Sun <yi.y.sun@intel.com>
---
 drivers/iommu/intel/pasid.c | 10 ++++++++--
 drivers/iommu/intel/pasid.h |  5 +++++
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/drivers/iommu/intel/pasid.c b/drivers/iommu/intel/pasid.c
index b1d0c2945c9a..07c390aed1fe 100644
--- a/drivers/iommu/intel/pasid.c
+++ b/drivers/iommu/intel/pasid.c
@@ -511,7 +511,7 @@ void intel_pasid_tear_down_entry(struct intel_iommu *iommu, struct device *dev,
 				 u32 pasid, bool fault_ignore)
 {
 	struct pasid_entry *pte;
-	u16 did;
+	u16 did, pgtt;
 
 	pte = intel_pasid_get_entry(dev, pasid);
 	if (WARN_ON(!pte))
@@ -521,13 +521,19 @@ void intel_pasid_tear_down_entry(struct intel_iommu *iommu, struct device *dev,
 		return;
 
 	did = pasid_get_domain_id(pte);
+	pgtt = pasid_pte_get_pgtt(pte);
+
 	intel_pasid_clear_entry(dev, pasid, fault_ignore);
 
 	if (!ecap_coherent(iommu->ecap))
 		clflush_cache_range(pte, sizeof(*pte));
 
 	pasid_cache_invalidation_with_pasid(iommu, did, pasid);
-	qi_flush_piotlb(iommu, did, pasid, 0, -1, 0);
+
+	if (pgtt == PASID_ENTRY_PGTT_PT || pgtt == PASID_ENTRY_PGTT_FL_ONLY)
+		qi_flush_piotlb(iommu, did, pasid, 0, -1, 0);
+	else
+		iommu->flush.flush_iotlb(iommu, did, 0, 0, DMA_TLB_DSI_FLUSH);
 
 	/* Device IOTLB doesn't need to be flushed in caching mode. */
 	if (!cap_caching_mode(iommu->cap))
diff --git a/drivers/iommu/intel/pasid.h b/drivers/iommu/intel/pasid.h
index 5ff61c3d401f..637141d71092 100644
--- a/drivers/iommu/intel/pasid.h
+++ b/drivers/iommu/intel/pasid.h
@@ -99,6 +99,11 @@ static inline bool pasid_pte_is_present(struct pasid_entry *pte)
 	return READ_ONCE(pte->val[0]) & PASID_PTE_PRESENT;
 }
 
+static inline u16 pasid_pte_get_pgtt(struct pasid_entry *pte)
+{
+	return (READ_ONCE(pte->val[0]) >> 6) & 0x7;
+}
+
 extern unsigned int intel_pasid_max_id;
 int intel_pasid_alloc_table(struct device *dev);
 void intel_pasid_free_table(struct device *dev);
-- 
2.25.1

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v1 3/3] iommu/vt-d: Fix Unexpected page request in Privilege Mode
  2021-08-17  4:24 ` [PATCH v1 3/3] iommu/vt-d: Fix Unexpected page request in Privilege Mode Liu Yi L
@ 2021-08-17 12:49   ` Lu Baolu
  0 siblings, 0 replies; 5+ messages in thread
From: Lu Baolu @ 2021-08-17 12:49 UTC (permalink / raw)
  To: Liu Yi L, iommu; +Cc: yi.y.sun, jun.j.tian

On 2021/8/17 12:24, Liu Yi L wrote:
> This patch fixes the below error. This is due to improper iotlb invalidation
> in intel_pasid_tear_down_entry().
> 
> [  180.187556] Unexpected page request in Privilege Mode
> [  180.187565] Unexpected page request in Privilege Mode
> [  180.279933] Unexpected page request in Privilege Mode
> [  180.279937] Unexpected page request in Privilege Mode
> 
> Per chapter 6.5.3.3 of VT-d spec 3.3, when tear down a pasid entry, software
> should use Domain selective IOTLB flush if the PGTT of the pasid entry is
> SL only or Nested, while for the pasid entries whose PGTT is FL only or PT
> using PASID-based IOTLB flush is enough.
> 
> Fixes: 1c4f88b7f1f9 ("iommu/vt-d: Shared virtual address in scalable mode")
> Cc: Lu Baolu<baolu.lu@linux.intel.com>
> Signed-off-by: Kumar Sanjay K<sanjay.k.kumar@intel.com>
> Signed-off-by: Liu Yi L<yi.l.liu@intel.com>
> Tested-by: Yi Sun<yi.y.sun@intel.com>

Good catch! Thanks!

It has been queued for iommu/fix.

Best regards,
baolu
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-08-17 12:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-17  4:24 [PATCH v1 0/3] Misc fixes to intel iommu driver Liu Yi L
2021-08-17  4:24 ` [PATCH v1 1/3] iommu/vt-d: Using pasid_pte_is_present() helper function Liu Yi L
2021-08-17  4:24 ` [PATCH v1 2/3] iommu/vt-d: Add present bit check in pasid entry setup helper functions Liu Yi L
2021-08-17  4:24 ` [PATCH v1 3/3] iommu/vt-d: Fix Unexpected page request in Privilege Mode Liu Yi L
2021-08-17 12:49   ` Lu Baolu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.