Skip to contentSkip to conversation

Intel IOMMU updates for Linux v6.1

GIT PULL New Lu Baolu 2 participants 8 messages Sep 26, 2022

Subsystems (2)
lore
Share & tools
lore

Lu Baolu

author maintainer
#0 lore raw

Hi Joerg,

This is a resent pull request. It's based on v6.0-rc7. The original pull request was posted here:

https://lore.kernel.org/linux-iommu/[email protected]/

Please pull.

Best regards,
Baolu

Lu Baolu (5):
iommu/vt-d: Remove unnecessary SVA data accesses in page fault path iommu/vt-d: Decouple PASID & PRI enabling from SVA iommu/vt-d: Remove pasid_set_eafe()
iommu/vt-d: Avoid unnecessary global IRTE cache invalidation iommu/vt-d: Avoid unnecessary global DMA cache invalidation

Yi Liu (1):
iommu/vt-d: Rename cap_5lp_support to cap_fl5lp_support

 drivers/iommu/intel/iommu.h         |  7 ++-
 drivers/iommu/intel/cap_audit.c     |  4 +-
 drivers/iommu/intel/iommu.c         | 87 ++++++++---------------------
 drivers/iommu/intel/irq_remapping.c |  6 +-
 drivers/iommu/intel/pasid.c         | 12 +---
 drivers/iommu/intel/svm.c           | 62 +++-----------------
 drivers/iommu/intel/Kconfig         |  5 +-
 7 files changed, 45 insertions(+), 138 deletions(-)
Signature · 1 line
2.34.1
author maintainer
#1 lore raw

PATCH 1/6 iommu/vt-d: Remove unnecessary SVA data accesses in page fault path

The existing I/O page fault handling code accesses the per-PASID SVA data structures. This is unnecessary and makes the fault handling code only suitable for SVA scenarios. This removes the SVA data accesses from the I/O page fault reporting and responding code, so that the fault handling code could be generic.

---
 drivers/iommu/intel/iommu.h |  2 +-
 drivers/iommu/intel/svm.c   | 60 +++++--------------------------------
 2 files changed, 8 insertions(+), 54 deletions(-)
drivers/iommu/intel/iommu.h +1 -1
index 74b0e19e23ee..b5fb7706e97c 100644
@@ -586,6 +586,7 @@ struct intel_iommu {
 #ifdef CONFIG_INTEL_IOMMU_SVM
 	struct page_req_dsc *prq;
 	unsigned char prq_name[16];    /* Name for PRQ interrupt */
+	unsigned long prq_seq_number;
 	struct completion prq_complete;
 	struct ioasid_allocator_ops pasid_allocator; /* Custom allocator for PASIDs */
 #endif
@@ -761,7 +762,6 @@ struct intel_svm_dev {
 	struct device *dev;
 	struct intel_iommu *iommu;
 	struct iommu_sva sva;
-	unsigned long prq_seq_number;
 	u32 pasid;
 	int users;
 	u16 did;
drivers/iommu/intel/svm.c +7 -53

117 lines not on this page · raw message

Signature · 1 line
2.34.1
author maintainer
#2 lore raw

PATCH 2/6 iommu/vt-d: Decouple PASID & PRI enabling from SVA

In reply to Lu Baolu

Previously the PCI PASID and PRI capabilities are enabled in the path of iommu device probe only if INTEL_IOMMU_SVM is configured and the device supports ATS. As we've already decoupled the I/O page fault handler from SVA, we could also decouple PASID and PRI enabling from it to make room for growth of new features like kernel DMA with PASID, SIOV and nested translation.

At the same time, the iommu_enable_dev_iotlb() helper is also called in iommu_dev_enable_feature(dev, IOMMU_DEV_FEAT_SVA) path. It's unnecessary and duplicate. This cleanups this helper to make the code neat.

---
 drivers/iommu/intel/iommu.h |  1 -
 drivers/iommu/intel/iommu.c | 78 ++++++++-----------------------------
 drivers/iommu/intel/Kconfig |  5 +--
 3 files changed, 18 insertions(+), 66 deletions(-)
drivers/iommu/intel/iommu.h +0 -1
index b5fb7706e97c..8f29a183467d 100644
@@ -742,7 +742,6 @@ extern int dmar_ir_support(void);
 void *alloc_pgtable_page(int node);
 void free_pgtable_page(void *vaddr);
 void iommu_flush_write_buffer(struct intel_iommu *iommu);
-int intel_iommu_enable_pasid(struct intel_iommu *iommu, struct device *dev);
 struct intel_iommu *device_to_iommu(struct device *dev, u8 *bus, u8 *devfn);
 
 #ifdef CONFIG_INTEL_IOMMU_SVM
drivers/iommu/intel/iommu.c +16 -62

161 lines not on this page · raw message

drivers/iommu/intel/Kconfig +2 -3
index 39a06d245f12..cd0ec7ed48b6 100644
@@ -21,6 +21,8 @@ config INTEL_IOMMU
 	select IOASID
 	select IOMMU_DMA
 	select PCI_ATS
+	select PCI_PRI
+	select PCI_PASID
 	help
 	  DMA remapping (DMAR) devices support enables independent address
 	  translations for Direct Memory Access (DMA) from devices.
@@ -48,10 +50,7 @@ config INTEL_IOMMU_DEBUGFS
 config INTEL_IOMMU_SVM
 	bool "Support for Shared Virtual Memory with Intel IOMMU"
 	depends on X86_64
-	select PCI_PASID
-	select PCI_PRI
 	select MMU_NOTIFIER
-	select IOASID
 	select IOMMU_SVA
 	help
 	  Shared Virtual Memory (SVM) provides a facility for devices
Signature · 1 line
2.34.1
author maintainer
#3 lore raw

PATCH 3/6 iommu/vt-d: Remove pasid_set_eafe()

In reply to Lu Baolu

It is not used anywhere in the tree. Remove it to avoid dead code. No functional change intended.

---
 drivers/iommu/intel/pasid.c | 10 ----------
 1 file changed, 10 deletions(-)
drivers/iommu/intel/pasid.c +0 -10
index c5e7e8b020a5..ccaf32949254 100644
@@ -392,16 +392,6 @@ pasid_set_flpm(struct pasid_entry *pe, u64 value)
 	pasid_set_bits(&pe->val[2], GENMASK_ULL(3, 2), value << 2);
 }
 
-/*
- * Setup the Extended Access Flag Enable (EAFE) field (Bit 135)
- * of a scalable mode PASID entry.
- */
-static inline void
-pasid_set_eafe(struct pasid_entry *pe)
-{
-	pasid_set_bits(&pe->val[2], 1 << 7, 1 << 7);
-}
-
 static void
 pasid_cache_invalidation_with_pasid(struct intel_iommu *iommu,
 				    u16 did, u32 pasid)
Signature · 1 line
2.34.1
author maintainer
#4 lore raw

PATCH 4/6 iommu/vt-d: Rename cap_5lp_support to cap_fl5lp_support

In reply to Lu Baolu

From: Yi Liu <[email protected]>

This renaming better describes it is for first level page table (a.k.a first stage page table since VT-d spec 3.4).

---
 drivers/iommu/intel/iommu.h     | 2 +-
 drivers/iommu/intel/cap_audit.c | 4 ++--
 drivers/iommu/intel/iommu.c     | 2 +-
 drivers/iommu/intel/pasid.c     | 2 +-
 drivers/iommu/intel/svm.c       | 2 +-
 5 files changed, 6 insertions(+), 6 deletions(-)
drivers/iommu/intel/iommu.h +1 -1
index 8f29a183467d..99cc75ecac63 100644
@@ -146,7 +146,7 @@
 /*
  * Decoding Capability Register
  */
-#define cap_5lp_support(c)	(((c) >> 60) & 1)
+#define cap_fl5lp_support(c)	(((c) >> 60) & 1)
 #define cap_pi_support(c)	(((c) >> 59) & 1)
 #define cap_fl1gp_support(c)	(((c) >> 56) & 1)
 #define cap_read_drain(c)	(((c) >> 55) & 1)
drivers/iommu/intel/cap_audit.c +2 -2
index 3ee68393122f..806986696841 100644
@@ -37,7 +37,7 @@ static inline void check_dmar_capabilities(struct intel_iommu *a,
 	MINIMAL_FEATURE_IOMMU(b, ecap, ECAP_MHMV_MASK);
 	MINIMAL_FEATURE_IOMMU(b, ecap, ECAP_IRO_MASK);
 
-	CHECK_FEATURE_MISMATCH(a, b, cap, 5lp_support, CAP_FL5LP_MASK);
+	CHECK_FEATURE_MISMATCH(a, b, cap, fl5lp_support, CAP_FL5LP_MASK);
 	CHECK_FEATURE_MISMATCH(a, b, cap, fl1gp_support, CAP_FL1GP_MASK);
 	CHECK_FEATURE_MISMATCH(a, b, cap, read_drain, CAP_RD_MASK);
 	CHECK_FEATURE_MISMATCH(a, b, cap, write_drain, CAP_WD_MASK);
@@ -84,7 +84,7 @@ static int cap_audit_hotplug(struct intel_iommu *iommu, enum cap_audit_type type
 		goto out;
 	}
 
-	CHECK_FEATURE_MISMATCH_HOTPLUG(iommu, cap, 5lp_support, CAP_FL5LP_MASK);
+	CHECK_FEATURE_MISMATCH_HOTPLUG(iommu, cap, fl5lp_support, CAP_FL5LP_MASK);
 	CHECK_FEATURE_MISMATCH_HOTPLUG(iommu, cap, fl1gp_support, CAP_FL1GP_MASK);
 	CHECK_FEATURE_MISMATCH_HOTPLUG(iommu, cap, read_drain, CAP_RD_MASK);
 	CHECK_FEATURE_MISMATCH_HOTPLUG(iommu, cap, write_drain, CAP_WD_MASK);
drivers/iommu/intel/iommu.c +1 -1
index af17177b6d76..7410d6232cbb 100644
@@ -404,7 +404,7 @@ static unsigned long __iommu_calculate_sagaw(struct intel_iommu *iommu)
 {
 	unsigned long fl_sagaw, sl_sagaw;
 
-	fl_sagaw = BIT(2) | (cap_5lp_support(iommu->cap) ? BIT(3) : 0);
+	fl_sagaw = BIT(2) | (cap_fl5lp_support(iommu->cap) ? BIT(3) : 0);
 	sl_sagaw = cap_sagaw(iommu->cap);
 
 	/* Second level only. */
drivers/iommu/intel/pasid.c +1 -1
index ccaf32949254..c30ddac40ee5 100644
@@ -519,7 +519,7 @@ int intel_pasid_setup_first_level(struct intel_iommu *iommu,
 		}
 	}
 
-	if ((flags & PASID_FLAG_FL5LP) && !cap_5lp_support(iommu->cap)) {
+	if ((flags & PASID_FLAG_FL5LP) && !cap_fl5lp_support(iommu->cap)) {
 		pr_err("No 5-level paging support for first-level on %s\n",
 		       iommu->name);
 		return -EINVAL;
drivers/iommu/intel/svm.c +1 -1
index d1cab931dcb0..7d08eb034f2d 100644
@@ -164,7 +164,7 @@ void intel_svm_check(struct intel_iommu *iommu)
 	}
 
 	if (cpu_feature_enabled(X86_FEATURE_LA57) &&
-	    !cap_5lp_support(iommu->cap)) {
+	    !cap_fl5lp_support(iommu->cap)) {
 		pr_err("%s SVM disabled, incompatible paging mode\n",
 		       iommu->name);
 		return;
Signature · 1 line
2.34.1
author maintainer
#5 lore raw

PATCH 5/6 iommu/vt-d: Avoid unnecessary global IRTE cache invalidation

In reply to Lu Baolu

Some VT-d hardware implementations invalidate all interrupt remapping hardware translation caches as part of SIRTP flow. The VT-d spec adds a ESIRTPS (Enhanced Set Interrupt Remap Table Pointer Support, section 11.4.2 in VT-d spec) capability bit to indicate this.

The spec also states in 11.4.4 that hardware also performs global invalidation on all interrupt remapping caches as part of Interrupt Remapping Disable operation if ESIRTPS capability bit is set.

This checks the ESIRTPS capability bit and skip software global cache invalidation if it's set.

---
 drivers/iommu/intel/iommu.h         | 1 +
 drivers/iommu/intel/irq_remapping.c | 6 ++++--
 2 files changed, 5 insertions(+), 2 deletions(-)
drivers/iommu/intel/iommu.h +1 -0
index 99cc75ecac63..bddf6c69587d 100644
@@ -146,6 +146,7 @@
 /*
  * Decoding Capability Register
  */
+#define cap_esirtps(c)		(((c) >> 62) & 1)
 #define cap_fl5lp_support(c)	(((c) >> 60) & 1)
 #define cap_pi_support(c)	(((c) >> 59) & 1)
 #define cap_fl1gp_support(c)	(((c) >> 56) & 1)
drivers/iommu/intel/irq_remapping.c +4 -2
index 2e9683e970f8..5962bb5027d0 100644
@@ -494,7 +494,8 @@ static void iommu_set_irq_remapping(struct intel_iommu *iommu, int mode)
 	 * Global invalidation of interrupt entry cache to make sure the
 	 * hardware uses the new irq remapping table.
 	 */
-	qi_global_iec(iommu);
+	if (!cap_esirtps(iommu->cap))
+		qi_global_iec(iommu);
 }
 
 static void iommu_enable_irq_remapping(struct intel_iommu *iommu)
@@ -680,7 +681,8 @@ static void iommu_disable_irq_remapping(struct intel_iommu *iommu)
 	 * global invalidation of interrupt entry cache before disabling
 	 * interrupt-remapping.
 	 */
-	qi_global_iec(iommu);
+	if (!cap_esirtps(iommu->cap))
+		qi_global_iec(iommu);
 
 	raw_spin_lock_irqsave(&iommu->register_lock, flags);
 
Signature · 1 line
2.34.1
author maintainer
#6 lore raw

PATCH 6/6 iommu/vt-d: Avoid unnecessary global DMA cache invalidation

In reply to Lu Baolu

Some VT-d hardware implementations invalidate all DMA remapping hardware translation caches as part of SRTP flow. The VT-d spec adds a ESRTPS (Enhanced Set Root Table Pointer Support, section 11.4.2 in VT-d spec) capability bit to indicate this. With this bit set, software has no need to issue the global invalidation request.

---
 drivers/iommu/intel/iommu.h | 1 +
 drivers/iommu/intel/iommu.c | 7 +++++++
 2 files changed, 8 insertions(+)
drivers/iommu/intel/iommu.h +1 -0
index bddf6c69587d..92023dff9513 100644
@@ -146,6 +146,7 @@
 /*
  * Decoding Capability Register
  */
+#define cap_esrtps(c)		(((c) >> 63) & 1)
 #define cap_esirtps(c)		(((c) >> 62) & 1)
 #define cap_fl5lp_support(c)	(((c) >> 60) & 1)
 #define cap_pi_support(c)	(((c) >> 59) & 1)
drivers/iommu/intel/iommu.c +7 -0
index 7410d6232cbb..2d142ee7bbfa 100644
@@ -1239,6 +1239,13 @@ static void iommu_set_root_entry(struct intel_iommu *iommu)
 
 	raw_spin_unlock_irqrestore(&iommu->register_lock, flag);
 
+	/*
+	 * Hardware invalidates all DMA remapping hardware translation
+	 * caches as part of SRTP flow.
+	 */
+	if (cap_esrtps(iommu->cap))
+		return;
+
 	iommu->flush.flush_context(iommu, 0, 0, 0, DMA_CCMD_GLOBAL_INVL);
 	if (sm_supported(iommu))
 		qi_flush_pasid_cache(iommu, 0, QI_PC_GLOBAL, 0);
Signature · 1 line
2.34.1
maintainer Applied
#7 lore raw
In reply to Lu Baolu
Quoted 9 lines · Lu Baolu

Lu Baolu (5):
iommu/vt-d: Remove unnecessary SVA data accesses in page fault path iommu/vt-d: Decouple PASID & PRI enabling from SVA iommu/vt-d: Remove pasid_set_eafe()
iommu/vt-d: Avoid unnecessary global IRTE cache invalidation iommu/vt-d: Avoid unnecessary global DMA cache invalidation

Yi Liu (1):
iommu/vt-d: Rename cap_5lp_support to cap_fl5lp_support

Applied, thanks Baolu.