Skip to contentSkip to conversation

Remove VT-d virtual command interface and IOASID

PATCH Superseded Jacob Pan 4 participants 16 messages Mar 9, 2023 – Mar 10, 2023

Subsystems (8)

v5 of 8 Superseded Latest is v8 →

lore
Share & tools
lore

Jacob Pan

author
#0 lore raw

v5 cover Remove VT-d virtual command interface and IOASID

Hi all,

This patch set removes unused VT-d virtual command interface followed by removal of the IOASID infrastructure.

This has only been tested on x86 platforms, need help with testing on ARM SMMU and other architectures.

Thanks,

Jacob

ChangeLog:
v5:
- rebased on v6.3-rc1
- put removing iommu_sva_find() in a separate patch (Kevin)
- move definition of helpers to iommu code to be consistent with declarations. (Kevin)
- misc fixes

v4:
- keep mm_pasid helpers inline as much as we can for fork performance
- separate GFP_ATOMIC to GFP_KERNEL change for bisectability

v3:
- moved helper functions for PASID under SVA code, avoided circular inclusion between mm.h and iommu.h
- deleted makefiles
- put rename under a different patch

Jacob Pan (5):
iommu/vt-d: Remove virtual command interface
iommu/sva: Move PASID helpers to sva code
iommu/sva: Remove PASID to mm lookup function
iommu/sva: Use GFP_KERNEL for pasid allocation
iommu/ioasid: Rename INVALID_IOASID

Jason Gunthorpe (2):
iommu/sva: Stop using ioasid_set for SVA
iommu: Remove ioasid infrastructure

 Documentation/x86/sva.rst       |   2 +-
 arch/x86/kernel/traps.c         |   5 +-
 drivers/dma/idxd/device.c       |   8 +-
 drivers/dma/idxd/idxd.h         |   2 +-
 drivers/dma/idxd/init.c         |   2 +-
 drivers/dma/idxd/irq.c          |   2 +-
 drivers/iommu/Kconfig           |   5 -
 drivers/iommu/Makefile          |   1 -
 drivers/iommu/intel/cap_audit.c |   2 -
 drivers/iommu/intel/dmar.c      |   6 +-
 drivers/iommu/intel/iommu.c     |  87 +------
 drivers/iommu/intel/iommu.h     |   3 -
 drivers/iommu/intel/svm.c       |   3 +-
 drivers/iommu/ioasid.c          | 422 --------------------------------
 drivers/iommu/iommu-sva.c       |  62 ++---
 drivers/iommu/iommu-sva.h       |   4 -
 include/linux/ioasid.h          |  83 -------
 include/linux/iommu-helper.h    |  12 +
 include/linux/iommu.h           |   8 +-
 include/linux/sched/mm.h        |  27 +-
 mm/init-mm.c                    |   4 +-
 21 files changed, 54 insertions(+), 696 deletions(-)
 delete mode 100644 drivers/iommu/ioasid.c
 delete mode 100644 include/linux/ioasid.h
Signature · 1 line
2.25.1
author
#1 lore raw

v5 cover Remove VT-d virtual command interface and IOASID

Hi all,

This patch set removes unused VT-d virtual command interface followed by removal of the IOASID infrastructure.

This has only been tested on x86 platforms, need help with testing on ARM SMMU and other architectures.

Thanks,

Jacob

ChangeLog:
v5:
- put removing iommu_sva_find() in a separate patch (Kevin)
- move definition of helpers to iommu code to be consistent with declarations. (Kevin)
- misc fixes

v4:
- keep mm_pasid helpers inline as much as we can for fork performance
- separate GFP_ATOMIC to GFP_KERNEL change for bisectability

v3:
- moved helper functions for PASID under SVA code, avoided circular inclusion between mm.h and iommu.h
- deleted makefiles
- put rename under a different patch

Jacob Pan (5):
iommu/vt-d: Remove virtual command interface
iommu/sva: Move PASID helpers to sva code
iommu/sva: Remove PASID to mm lookup function
iommu/sva: Use GFP_KERNEL for pasid allocation
iommu/ioasid: Rename INVALID_IOASID

Jason Gunthorpe (2):
iommu/sva: Stop using ioasid_set for SVA
iommu: Remove ioasid infrastructure

 Documentation/x86/sva.rst       |   2 +-
 arch/x86/kernel/traps.c         |   5 +-
 drivers/dma/idxd/device.c       |   8 +-
 drivers/dma/idxd/idxd.h         |   2 +-
 drivers/dma/idxd/init.c         |   2 +-
 drivers/dma/idxd/irq.c          |   2 +-
 drivers/iommu/Kconfig           |   5 -
 drivers/iommu/Makefile          |   1 -
 drivers/iommu/intel/cap_audit.c |   2 -
 drivers/iommu/intel/dmar.c      |   6 +-
 drivers/iommu/intel/iommu.c     |  87 +------
 drivers/iommu/intel/iommu.h     |   3 -
 drivers/iommu/intel/svm.c       |   3 +-
 drivers/iommu/ioasid.c          | 422 --------------------------------
 drivers/iommu/iommu-sva.c       |  62 ++---
 drivers/iommu/iommu-sva.h       |   4 -
 include/linux/ioasid.h          |  83 -------
 include/linux/iommu-helper.h    |  12 +
 include/linux/iommu.h           |   8 +-
 include/linux/sched/mm.h        |  27 +-
 mm/init-mm.c                    |   4 +-
 21 files changed, 54 insertions(+), 696 deletions(-)
 delete mode 100644 drivers/iommu/ioasid.c
 delete mode 100644 include/linux/ioasid.h
Signature · 1 line
2.25.1
author
#2 lore raw

PATCH v5 1/7 iommu/vt-d: Remove virtual command interface

In reply to Jacob Pan

Virtual command interface was introduced to allow using host PASIDs inside VMs. It is unused and abandoned due to architectural change.

With this patch, we can safely remove this feature and the related helpers.

---
 drivers/iommu/intel/cap_audit.c |  2 -
 drivers/iommu/intel/dmar.c      |  2 -
 drivers/iommu/intel/iommu.c     | 85 ---------------------------------
 drivers/iommu/intel/iommu.h     |  2 -
 4 files changed, 91 deletions(-)
drivers/iommu/intel/cap_audit.c +0 -2
index 806986696841..9862dc20b35e 100644
@@ -54,7 +54,6 @@ static inline void check_dmar_capabilities(struct intel_iommu *a,
 	CHECK_FEATURE_MISMATCH(a, b, ecap, slts, ECAP_SLTS_MASK);
 	CHECK_FEATURE_MISMATCH(a, b, ecap, nwfs, ECAP_NWFS_MASK);
 	CHECK_FEATURE_MISMATCH(a, b, ecap, slads, ECAP_SLADS_MASK);
-	CHECK_FEATURE_MISMATCH(a, b, ecap, vcs, ECAP_VCS_MASK);
 	CHECK_FEATURE_MISMATCH(a, b, ecap, smts, ECAP_SMTS_MASK);
 	CHECK_FEATURE_MISMATCH(a, b, ecap, pds, ECAP_PDS_MASK);
 	CHECK_FEATURE_MISMATCH(a, b, ecap, dit, ECAP_DIT_MASK);
@@ -101,7 +100,6 @@ static int cap_audit_hotplug(struct intel_iommu *iommu, enum cap_audit_type type
 	CHECK_FEATURE_MISMATCH_HOTPLUG(iommu, ecap, slts, ECAP_SLTS_MASK);
 	CHECK_FEATURE_MISMATCH_HOTPLUG(iommu, ecap, nwfs, ECAP_NWFS_MASK);
 	CHECK_FEATURE_MISMATCH_HOTPLUG(iommu, ecap, slads, ECAP_SLADS_MASK);
-	CHECK_FEATURE_MISMATCH_HOTPLUG(iommu, ecap, vcs, ECAP_VCS_MASK);
 	CHECK_FEATURE_MISMATCH_HOTPLUG(iommu, ecap, smts, ECAP_SMTS_MASK);
 	CHECK_FEATURE_MISMATCH_HOTPLUG(iommu, ecap, pds, ECAP_PDS_MASK);
 	CHECK_FEATURE_MISMATCH_HOTPLUG(iommu, ecap, dit, ECAP_DIT_MASK);
drivers/iommu/intel/dmar.c +0 -2
index 6acfe879589c..0f348439ef0e 100644
@@ -993,8 +993,6 @@ static int map_iommu(struct intel_iommu *iommu, struct dmar_drhd_unit *drhd)
 		warn_invalid_dmar(phys_addr, " returns all ones");
 		goto unmap;
 	}
-	if (ecap_vcs(iommu->ecap))
-		iommu->vccap = dmar_readq(iommu->reg + DMAR_VCCAP_REG);
 
 	/* the registers might be more than one page */
 	map_size = max_t(int, ecap_max_iotlb_offset(iommu->ecap),
drivers/iommu/intel/iommu.c +0 -85

103 lines not on this page · raw message

drivers/iommu/intel/iommu.h +0 -2
index d6df3b865812..a2010fb120e2 100644
@@ -198,7 +198,6 @@
 #define ecap_flts(e)		(((e) >> 47) & 0x1)
 #define ecap_slts(e)		(((e) >> 46) & 0x1)
 #define ecap_slads(e)		(((e) >> 45) & 0x1)
-#define ecap_vcs(e)		(((e) >> 44) & 0x1)
 #define ecap_smts(e)		(((e) >> 43) & 0x1)
 #define ecap_dit(e)		(((e) >> 41) & 0x1)
 #define ecap_pds(e)		(((e) >> 42) & 0x1)
@@ -676,7 +675,6 @@ struct intel_iommu {
 	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
 	struct iopf_queue *iopf_queue;
 	unsigned char iopfq_name[16];
Signature · 1 line
2.25.1
author
#3 lore raw

PATCH v5 2/7 iommu/sva: Move PASID helpers to sva code

In reply to Jacob Pan

Preparing to remove IOASID infrastructure, PASID management will be under SVA code. Decouple mm code from IOASID. Use iommu-help.h instead of iommu.h to prevent circular inclusion.

---
v5:
- move definition of helpers to iommu code to be consistent with declarations. (Kevin)
- fix patch partitioning bug (Baolu)
v4:
- delete and open code mm_set_pasid
- keep mm_init_pasid() as inline for fork performance

---
 drivers/iommu/iommu-sva.c    | 10 +++++++++-
 include/linux/ioasid.h       |  2 +-
 include/linux/iommu-helper.h | 12 ++++++++++++
 include/linux/sched/mm.h     | 27 +--------------------------
 4 files changed, 23 insertions(+), 28 deletions(-)
drivers/iommu/iommu-sva.c +9 -1
index 24bf9b2b58aa..fcfdc80a3939 100644
@@ -44,7 +44,7 @@ int iommu_sva_alloc_pasid(struct mm_struct *mm, ioasid_t min, ioasid_t max)
 	if (!pasid_valid(pasid))
 		ret = -ENOMEM;
 	else
-		mm_pasid_set(mm, pasid);
+		mm->pasid = pasid;
 out:
 	mutex_unlock(&iommu_sva_lock);
 	return ret;
@@ -238,3 +238,11 @@ iommu_sva_handle_iopf(struct iommu_fault *fault, void *data)
 
 	return status;
 }
+
+void mm_pasid_drop(struct mm_struct *mm)
+{
+	if (pasid_valid(mm->pasid)) {
+		ioasid_free(mm->pasid);
+		mm->pasid = INVALID_IOASID;
+	}
+}
include/linux/ioasid.h +1 -1
index af1c9d62e642..2c502e77ee78 100644
@@ -4,8 +4,8 @@
 
 #include <linux/types.h>
 #include <linux/errno.h>
+#include <linux/iommu-helper.h>
 
-#define INVALID_IOASID ((ioasid_t)-1)
 typedef unsigned int ioasid_t;
 typedef ioasid_t (*ioasid_alloc_fn_t)(ioasid_t min, ioasid_t max, void *data);
 typedef void (*ioasid_free_fn_t)(ioasid_t ioasid, void *data);
include/linux/iommu-helper.h +12 -0
index 74be34f3a20a..be1451a05a15 100644
@@ -6,6 +6,7 @@
 #include <linux/log2.h>
 #include <linux/math.h>
 #include <linux/types.h>
+#include <linux/mm_types.h>
 
 static inline unsigned long iommu_device_max_index(unsigned long size,
 						   unsigned long offset,
@@ -41,4 +42,15 @@ static inline unsigned long iommu_num_pages(unsigned long addr,
 	return DIV_ROUND_UP(size, io_page_size);
 }
 
+#define INVALID_IOASID	(-1U)
+#ifdef CONFIG_IOMMU_SVA
+static inline void mm_pasid_init(struct mm_struct *mm)
+{
+	mm->pasid = INVALID_IOASID;
+}
+void mm_pasid_drop(struct mm_struct *mm);
+#else
+static inline void mm_pasid_init(struct mm_struct *mm) {}
+static inline void mm_pasid_drop(struct mm_struct *mm) {}
+#endif
 #endif
include/linux/sched/mm.h +1 -26
index 2a243616f222..f341a7a855e8 100644
@@ -8,7 +8,7 @@
 #include <linux/mm_types.h>
 #include <linux/gfp.h>
 #include <linux/sync_core.h>
-#include <linux/ioasid.h>
+#include <linux/iommu-helper.h>
 
 /*
  * Routines for handling mm_structs
@@ -451,29 +451,4 @@ static inline void membarrier_update_current_mm(struct mm_struct *next_mm)
 }
 #endif
 
-#ifdef CONFIG_IOMMU_SVA
-static inline void mm_pasid_init(struct mm_struct *mm)
-{
-	mm->pasid = INVALID_IOASID;
-}
-
-/* Associate a PASID with an mm_struct: */
-static inline void mm_pasid_set(struct mm_struct *mm, u32 pasid)
-{
-	mm->pasid = pasid;
-}
-
-static inline void mm_pasid_drop(struct mm_struct *mm)
-{
-	if (pasid_valid(mm->pasid)) {
-		ioasid_free(mm->pasid);
-		mm->pasid = INVALID_IOASID;
-	}
-}
-#else
-static inline void mm_pasid_init(struct mm_struct *mm) {}
-static inline void mm_pasid_set(struct mm_struct *mm, u32 pasid) {}
-static inline void mm_pasid_drop(struct mm_struct *mm) {}
-#endif
-
 #endif /* _LINUX_SCHED_MM_H */
Signature · 1 line
2.25.1
#4 lore raw

Re: [PATCH v5 2/7] iommu/sva: Move PASID helpers to sva code

include/linux/sched/mm.h line 11

Quoted 10 lines · Jacob Pan
include/linux/sched/mm.h +1 -1
index 2a243616f222..f341a7a855e8 100644
@@ -8,7 +8,7 @@
 #include <linux/mm_types.h>
 #include <linux/gfp.h>
 #include <linux/sync_core.h>
-#include <linux/ioasid.h>
+#include <linux/iommu-helper.h>

Don't include this here, fork.cc is the only caller put the include there

Otherwise it looks pretty logical

Jason

author
#5 lore raw

Re: [PATCH v5 2/7] iommu/sva: Move PASID helpers to sva code

Hi Jason,

Quoted 14 lines · Jason Gunthorpe

include/linux/sched/mm.h line 11

Quoted 10 lines · Jacob Pan
include/linux/sched/mm.h +1 -1
index 2a243616f222..f341a7a855e8 100644
@@ -8,7 +8,7 @@
 #include <linux/mm_types.h>
 #include <linux/gfp.h>
 #include <linux/sync_core.h>
-#include <linux/ioasid.h>
+#include <linux/iommu-helper.h>  

Don't include this here, fork.cc is the only caller put the include there

make sense, will do.

Thanks,

Jacob

reviewer
#6 lore raw

Re: [PATCH v5 2/7] iommu/sva: Move PASID helpers to sva code

In reply to Jacob Pan
Quoted 13 lines · Jacob Pan

Preparing to remove IOASID infrastructure, PASID management will be under SVA code. Decouple mm code from IOASID. Use iommu-help.h instead of iommu.h to prevent circular inclusion.

---
v5:
- move definition of helpers to iommu code to be consistent with declarations. (Kevin)
- fix patch partitioning bug (Baolu)
v4:
- delete and open code mm_set_pasid
- keep mm_init_pasid() as inline for fork performance

Quoted 4 lines
---
  drivers/iommu/iommu-sva.c    | 10 +++++++++-
  include/linux/ioasid.h       |  2 +-
  include/linux/iommu-helper.h | 12 ++++++++++++

Eww, can we not? iommu-helper is very much just parts of a specific type of bitmap-based IOVA allocator used by some crusty old arch-specific IOMMU code and SWIOTLB. It is unrelated to the iommu.h IOMMU API, and dragging that stuff into modern SVA-related matters seems bizarrely inappropriate. Could we just move the mm_pasid stuff into ioasid.h here, then maybe rename it to iommu-sva.h at the end if eradicating the old name really matters?

Thanks,
Robin.

Quoted 113 lines
  include/linux/sched/mm.h     | 27 +--------------------------
  4 files changed, 23 insertions(+), 28 deletions(-)
drivers/iommu/iommu-sva.c +9 -1
index 24bf9b2b58aa..fcfdc80a3939 100644
@@ -44,7 +44,7 @@ int iommu_sva_alloc_pasid(struct mm_struct *mm, ioasid_t min, ioasid_t max)
  	if (!pasid_valid(pasid))
  		ret = -ENOMEM;
  	else
-		mm_pasid_set(mm, pasid);
+		mm->pasid = pasid;
  out:
  	mutex_unlock(&iommu_sva_lock);
  	return ret;
@@ -238,3 +238,11 @@ iommu_sva_handle_iopf(struct iommu_fault *fault, void *data)
 
  	return status;
  }
+
+void mm_pasid_drop(struct mm_struct *mm)
+{
+	if (pasid_valid(mm->pasid)) {
+		ioasid_free(mm->pasid);
+		mm->pasid = INVALID_IOASID;
+	}
+}
include/linux/ioasid.h +1 -1
index af1c9d62e642..2c502e77ee78 100644
@@ -4,8 +4,8 @@
 
  #include <linux/types.h>
  #include <linux/errno.h>
+#include <linux/iommu-helper.h>
 
-#define INVALID_IOASID ((ioasid_t)-1)
  typedef unsigned int ioasid_t;
  typedef ioasid_t (*ioasid_alloc_fn_t)(ioasid_t min, ioasid_t max, void *data);
  typedef void (*ioasid_free_fn_t)(ioasid_t ioasid, void *data);
include/linux/iommu-helper.h +12 -0
index 74be34f3a20a..be1451a05a15 100644
@@ -6,6 +6,7 @@
  #include <linux/log2.h>
  #include <linux/math.h>
  #include <linux/types.h>
+#include <linux/mm_types.h>
 
  static inline unsigned long iommu_device_max_index(unsigned long size,
  						   unsigned long offset,
@@ -41,4 +42,15 @@ static inline unsigned long iommu_num_pages(unsigned long addr,
  	return DIV_ROUND_UP(size, io_page_size);
  }
 
+#define INVALID_IOASID	(-1U)
+#ifdef CONFIG_IOMMU_SVA
+static inline void mm_pasid_init(struct mm_struct *mm)
+{
+	mm->pasid = INVALID_IOASID;
+}
+void mm_pasid_drop(struct mm_struct *mm);
+#else
+static inline void mm_pasid_init(struct mm_struct *mm) {}
+static inline void mm_pasid_drop(struct mm_struct *mm) {}
+#endif
  #endif
include/linux/sched/mm.h +1 -26
index 2a243616f222..f341a7a855e8 100644
@@ -8,7 +8,7 @@
  #include <linux/mm_types.h>
  #include <linux/gfp.h>
  #include <linux/sync_core.h>
-#include <linux/ioasid.h>
+#include <linux/iommu-helper.h>
 
  /*
   * Routines for handling mm_structs
@@ -451,29 +451,4 @@ static inline void membarrier_update_current_mm(struct mm_struct *next_mm)
  }
  #endif
 
-#ifdef CONFIG_IOMMU_SVA
-static inline void mm_pasid_init(struct mm_struct *mm)
-{
-	mm->pasid = INVALID_IOASID;
-}
-
-/* Associate a PASID with an mm_struct: */
-static inline void mm_pasid_set(struct mm_struct *mm, u32 pasid)
-{
-	mm->pasid = pasid;
-}
-
-static inline void mm_pasid_drop(struct mm_struct *mm)
-{
-	if (pasid_valid(mm->pasid)) {
-		ioasid_free(mm->pasid);
-		mm->pasid = INVALID_IOASID;
-	}
-}
-#else
-static inline void mm_pasid_init(struct mm_struct *mm) {}
-static inline void mm_pasid_set(struct mm_struct *mm, u32 pasid) {}
-static inline void mm_pasid_drop(struct mm_struct *mm) {}
-#endif
-
  #endif /* _LINUX_SCHED_MM_H */
author
#7 lore raw

Re: [PATCH v5 2/7] iommu/sva: Move PASID helpers to sva code

Hi Robin,

Quoted 19 lines · Robin Murphy
Quoted 13 lines · Jacob Pan

Preparing to remove IOASID infrastructure, PASID management will be under SVA code. Decouple mm code from IOASID. Use iommu-help.h instead of iommu.h to prevent circular inclusion.

---
v5:
- move definition of helpers to iommu code to be consistent with declarations. (Kevin)
- fix patch partitioning bug (Baolu)
v4:
- delete and open code mm_set_pasid
- keep mm_init_pasid() as inline for fork performance

Quoted 4 lines
---
  drivers/iommu/iommu-sva.c    | 10 +++++++++-
  include/linux/ioasid.h       |  2 +-
  include/linux/iommu-helper.h | 12 ++++++++++++  
Quoted 7 lines

Eww, can we not? iommu-helper is very much just parts of a specific type of bitmap-based IOVA allocator used by some crusty old arch-specific IOMMU code and SWIOTLB. It is unrelated to the iommu.h IOMMU API, and dragging that stuff into modern SVA-related matters seems bizarrely inappropriate. Could we just move the mm_pasid stuff into ioasid.h here, then maybe rename it to iommu-sva.h at the end if eradicating the old name really matters?

thanks for explaining the history behind iommu-helper.h, having a new include/linux/iommu-sva.h would probably be cleaner.

my original intent for using iommu-helper.h was to avoid problems by mm.h #include iommu.h. So I just needed a separate small header. let me do without iommu-helper.h.

Thanks,

Jacob

author
#8 lore raw

PATCH v5 3/7 iommu/sva: Remove PASID to mm lookup function

In reply to Jacob Pan

There is no user of iommu_sva_find() function, remove it so that PASID allocator can be a simple IDA. Device drivers are expected to store and keep track of their own PASID metadata.

---
 drivers/iommu/iommu-sva.c | 20 --------------------
 drivers/iommu/iommu-sva.h |  1 -
 2 files changed, 21 deletions(-)
drivers/iommu/iommu-sva.c +0 -20
index fcfdc80a3939..4f357ef14f04 100644
@@ -51,26 +51,6 @@ int iommu_sva_alloc_pasid(struct mm_struct *mm, ioasid_t min, ioasid_t max)
 }
 EXPORT_SYMBOL_GPL(iommu_sva_alloc_pasid);
 
-/* ioasid_find getter() requires a void * argument */
-static bool __mmget_not_zero(void *mm)
-{
-	return mmget_not_zero(mm);
-}
-
-/**
- * iommu_sva_find() - Find mm associated to the given PASID
- * @pasid: Process Address Space ID assigned to the mm
- *
- * On success a reference to the mm is taken, and must be released with mmput().
- *
- * Returns the mm corresponding to this PASID, or an error if not found.
- */
-struct mm_struct *iommu_sva_find(ioasid_t pasid)
-{
-	return ioasid_find(&iommu_sva_pasid, pasid, __mmget_not_zero);
-}
-EXPORT_SYMBOL_GPL(iommu_sva_find);
-
 /**
  * iommu_sva_bind_device() - Bind a process address space to a device
  * @dev: the device
drivers/iommu/iommu-sva.h +0 -1
index 7215a761b962..102eae1817a2 100644
@@ -9,7 +9,6 @@
 #include <linux/mm_types.h>
 
 int iommu_sva_alloc_pasid(struct mm_struct *mm, ioasid_t min, ioasid_t max);
-struct mm_struct *iommu_sva_find(ioasid_t pasid);
 
 /* I/O Page fault */
 struct device;
Signature · 1 line
2.25.1
maintainer Reviewed-by on v5 3/7
#9 lore raw

Re: [PATCH v5 3/7] iommu/sva: Remove PASID to mm lookup function

Quoted 6 lines · Jacob Pan

There is no user of iommu_sva_find() function, remove it so that PASID allocator can be a simple IDA. Device drivers are expected to store and keep track of their own PASID metadata.

Best regards,
baolu

author
#10 lore raw

PATCH v5 4/7 iommu/sva: Stop using ioasid_set for SVA

In reply to Jacob Pan

From: Jason Gunthorpe <[email protected]>

Instead SVA drivers can use a simple global IDA to allocate PASIDs for each mm_struct.

Future work would be to allow drivers using the SVA APIs to reserve global PASIDs from this IDA for their internal use, eg with the DMA API PASID support.

---
v5:
- Put removing iommu_sva_find() to a separate patch (Kevin)
- Make pasid allocation range to be inclusive (Tina)
- Simplified return code handling (Baolu)
v4:
- Keep GFP_ATOMIC flag for PASID allocation, will changed to GFP_KERNEL in a separate patch.

---
 drivers/iommu/iommu-sva.c | 42 +++++++++++++--------------------------
 drivers/iommu/iommu-sva.h |  2 --
 2 files changed, 14 insertions(+), 30 deletions(-)
drivers/iommu/iommu-sva.c +14 -28
index 4f357ef14f04..b75711bdbe97 100644
@@ -9,47 +9,33 @@
 #include "iommu-sva.h"
 
 static DEFINE_MUTEX(iommu_sva_lock);
-static DECLARE_IOASID_SET(iommu_sva_pasid);
+static DEFINE_IDA(iommu_global_pasid_ida);
 
-/**
- * iommu_sva_alloc_pasid - Allocate a PASID for the mm
- * @mm: the mm
- * @min: minimum PASID value (inclusive)
- * @max: maximum PASID value (inclusive)
- *
- * Try to allocate a PASID for this mm, or take a reference to the existing one
- * provided it fits within the [@min, @max] range. On success the PASID is
- * available in mm->pasid and will be available for the lifetime of the mm.
- *
- * Returns 0 on success and < 0 on error.
- */
-int iommu_sva_alloc_pasid(struct mm_struct *mm, ioasid_t min, ioasid_t max)
+static int iommu_sva_alloc_pasid(struct mm_struct *mm, ioasid_t min, ioasid_t max)
 {
 	int ret = 0;
-	ioasid_t pasid;
 
-	if (min == INVALID_IOASID || max == INVALID_IOASID ||
-	    min == 0 || max < min)
+	if (!pasid_valid(min) || !pasid_valid(max) ||
+	     min == 0 || max < min)
 		return -EINVAL;
 
 	mutex_lock(&iommu_sva_lock);
 	/* Is a PASID already associated with this mm? */
 	if (pasid_valid(mm->pasid)) {
-		if (mm->pasid < min || mm->pasid >= max)
+		if (mm->pasid < min || mm->pasid > max)
 			ret = -EOVERFLOW;
 		goto out;
 	}
 
-	pasid = ioasid_alloc(&iommu_sva_pasid, min, max, mm);
-	if (!pasid_valid(pasid))
-		ret = -ENOMEM;
-	else
-		mm->pasid = pasid;
+	ret = ida_alloc_range(&iommu_global_pasid_ida, min, max, GFP_ATOMIC);
+	if (ret < 0)
+		goto out;
+	mm->pasid = ret;
+	ret = 0;
 out:
 	mutex_unlock(&iommu_sva_lock);
 	return ret;
 }
-EXPORT_SYMBOL_GPL(iommu_sva_alloc_pasid);
 
 /**
  * iommu_sva_bind_device() - Bind a process address space to a device
@@ -221,8 +207,8 @@ iommu_sva_handle_iopf(struct iommu_fault *fault, void *data)
 
 void mm_pasid_drop(struct mm_struct *mm)
 {
-	if (pasid_valid(mm->pasid)) {
-		ioasid_free(mm->pasid);
-		mm->pasid = INVALID_IOASID;
-	}
+	if (likely(!pasid_valid(mm->pasid)))
+		return;
+
+	ida_free(&iommu_global_pasid_ida, mm->pasid);
 }
drivers/iommu/iommu-sva.h +0 -2
index 102eae1817a2..c22d0174ad61 100644
@@ -8,8 +8,6 @@
 #include <linux/ioasid.h>
 #include <linux/mm_types.h>
 
-int iommu_sva_alloc_pasid(struct mm_struct *mm, ioasid_t min, ioasid_t max);
-
 /* I/O Page fault */
 struct device;
 struct iommu_fault;
Signature · 1 line
2.25.1
maintainer
#11 lore raw

Re: [PATCH v5 4/7] iommu/sva: Stop using ioasid_set for SVA

Quoted 47 lines · Jacob Pan

From: Jason Gunthorpe <[email protected]>

Instead SVA drivers can use a simple global IDA to allocate PASIDs for each mm_struct.

Future work would be to allow drivers using the SVA APIs to reserve global PASIDs from this IDA for their internal use, eg with the DMA API PASID support.

---
v5:
- Put removing iommu_sva_find() to a separate patch (Kevin)
- Make pasid allocation range to be inclusive (Tina)
- Simplified return code handling (Baolu)
v4:
- Keep GFP_ATOMIC flag for PASID allocation, will changed to GFP_KERNEL in a separate patch.

---
  drivers/iommu/iommu-sva.c | 42 +++++++++++++--------------------------
  drivers/iommu/iommu-sva.h |  2 --
  2 files changed, 14 insertions(+), 30 deletions(-)
drivers/iommu/iommu-sva.c +1 -13
index 4f357ef14f04..b75711bdbe97 100644
@@ -9,47 +9,33 @@
  #include "iommu-sva.h"
 
  static DEFINE_MUTEX(iommu_sva_lock);
-static DECLARE_IOASID_SET(iommu_sva_pasid);
+static DEFINE_IDA(iommu_global_pasid_ida);
 
-/**
- * iommu_sva_alloc_pasid - Allocate a PASID for the mm
- * @mm: the mm
- * @min: minimum PASID value (inclusive)
- * @max: maximum PASID value (inclusive)
- *
- * Try to allocate a PASID for this mm, or take a reference to the existing one
- * provided it fits within the [@min, @max] range. On success the PASID is
- * available in mm->pasid and will be available for the lifetime of the mm.
- *
- * Returns 0 on success and < 0 on error.
- */

drivers/iommu/iommu-sva.c line 19

Quoted 10 lines
drivers/iommu/iommu-sva.c +3 -4
-int iommu_sva_alloc_pasid(struct mm_struct *mm, ioasid_t min, ioasid_t max)
+static int iommu_sva_alloc_pasid(struct mm_struct *mm, ioasid_t min, ioasid_t max)
  {
  	int ret = 0;
-	ioasid_t pasid;
 
-	if (min == INVALID_IOASID || max == INVALID_IOASID ||
-	    min == 0 || max < min)
+	if (!pasid_valid(min) || !pasid_valid(max) ||
+	     min == 0 || max < min)

No need to change above line.

drivers/iommu/iommu-sva.c line 25

Quoted 7 lines
drivers/iommu/iommu-sva.c +1 -1
  		return -EINVAL;
 
  	mutex_lock(&iommu_sva_lock);
  	/* Is a PASID already associated with this mm? */
  	if (pasid_valid(mm->pasid)) {
-		if (mm->pasid < min || mm->pasid >= max)
+		if (mm->pasid < min || mm->pasid > max)

I forgot why do we need to change above line. But it's better to put some comments there so that people don't need to dive into ioasid_alloc() to know the inclusion or exclusion of @min or @max.

Quoted 24 lines
drivers/iommu/iommu-sva.c +5 -6
  			ret = -EOVERFLOW;
  		goto out;
  	}
 
-	pasid = ioasid_alloc(&iommu_sva_pasid, min, max, mm);
-	if (!pasid_valid(pasid))
-		ret = -ENOMEM;
-	else
-		mm->pasid = pasid;
+	ret = ida_alloc_range(&iommu_global_pasid_ida, min, max, GFP_ATOMIC);
+	if (ret < 0)
+		goto out;
+	mm->pasid = ret;
+	ret = 0;
  out:
  	mutex_unlock(&iommu_sva_lock);
  	return ret;
  }
-EXPORT_SYMBOL_GPL(iommu_sva_alloc_pasid);
 
  /**
   * iommu_sva_bind_device() - Bind a process address space to a device
@@ -221,8 +207,8 @@ iommu_sva_handle_iopf(struct iommu_fault *fault, void *data)
 

drivers/iommu/iommu-sva.c iommu_sva_handle_iopf(struct iommu_fault *fault, void *data) · line 213

Quoted 10 lines
drivers/iommu/iommu-sva.c +4 -4
  void mm_pasid_drop(struct mm_struct *mm)
  {
-	if (pasid_valid(mm->pasid)) {
-		ioasid_free(mm->pasid);
-		mm->pasid = INVALID_IOASID;
-	}
+	if (likely(!pasid_valid(mm->pasid)))
+		return;
+
+	ida_free(&iommu_global_pasid_ida, mm->pasid);

Any reason why do you drop "mm->pasid = INVALID_IOASID;" here?

Quoted 6 lines
drivers/iommu/iommu-sva.c +0 -0
  }
drivers/iommu/iommu-sva.h +0 -0
index 102eae1817a2..c22d0174ad61 100644

drivers/iommu/iommu-sva.h line 13

Quoted 8 lines
drivers/iommu/iommu-sva.h +0 -2
@@ -8,8 +8,6 @@
  #include <linux/ioasid.h>
  #include <linux/mm_types.h>
 
-int iommu_sva_alloc_pasid(struct mm_struct *mm, ioasid_t min, ioasid_t max);
-
  /* I/O Page fault */
  struct device;
  struct iommu_fault;

Best regards,
baolu

author
#12 lore raw

Re: [PATCH v5 4/7] iommu/sva: Stop using ioasid_set for SVA

Hi Baolu,

Quoted 66 lines · Baolu Lu
Quoted 54 lines · Jacob Pan

From: Jason Gunthorpe <[email protected]>

Instead SVA drivers can use a simple global IDA to allocate PASIDs for each mm_struct.

Future work would be to allow drivers using the SVA APIs to reserve global PASIDs from this IDA for their internal use, eg with the DMA API PASID support.

---
v5:
- Put removing iommu_sva_find() to a separate patch (Kevin)
- Make pasid allocation range to be inclusive (Tina)
- Simplified return code handling (Baolu)
v4:
- Keep GFP_ATOMIC flag for PASID allocation, will changed to GFP_KERNEL in a separate patch.

---
  drivers/iommu/iommu-sva.c | 42 +++++++++++++--------------------------
  drivers/iommu/iommu-sva.h |  2 --
  2 files changed, 14 insertions(+), 30 deletions(-)
drivers/iommu/iommu-sva.c +1 -8
index 4f357ef14f04..b75711bdbe97 100644
@@ -9,47 +9,33 @@
  #include "iommu-sva.h"
 
  static DEFINE_MUTEX(iommu_sva_lock);
-static DECLARE_IOASID_SET(iommu_sva_pasid);
+static DEFINE_IDA(iommu_global_pasid_ida);
 
-/**
- * iommu_sva_alloc_pasid - Allocate a PASID for the mm
- * @mm: the mm
- * @min: minimum PASID value (inclusive)
- * @max: maximum PASID value (inclusive)
- *
- * Try to allocate a PASID for this mm, or take a reference to the

existing one
- * provided it fits within the [@min, @max] range. On success the PASID is
- * available in mm->pasid and will be available for the lifetime of the mm.
- *
- * Returns 0 on success and < 0 on error.
- */
-int iommu_sva_alloc_pasid(struct mm_struct *mm, ioasid_t min, ioasid_t max) +static int iommu_sva_alloc_pasid(struct mm_struct *mm, ioasid_t min, ioasid_t max) {
int ret = 0;

drivers/iommu/iommu-sva.c line 19

Quoted 6 lines
drivers/iommu/iommu-sva.c +2 -3
-	ioasid_t pasid;
 
-	if (min == INVALID_IOASID || max == INVALID_IOASID ||
-	    min == 0 || max < min)
+	if (!pasid_valid(min) || !pasid_valid(max) ||
+	     min == 0 || max < min)  

No need to change above line.

Quoted 2 lines

return -EINVAL;

Quoted 10 lines

drivers/iommu/iommu-sva.c line 25

Quoted 5 lines
  	mutex_lock(&iommu_sva_lock);
  	/* Is a PASID already associated with this mm? */
  	if (pasid_valid(mm->pasid)) {
drivers/iommu/iommu-sva.c +1 -1
-		if (mm->pasid < min || mm->pasid >= max)
+		if (mm->pasid < min || mm->pasid > max)  

I forgot why do we need to change above line. But it's better to put some comments there so that people don't need to dive into ioasid_alloc() to know the inclusion or exclusion of @min or @max.

just to be consistent for both limits. sure, we can add the comment.

Quoted 21 lines
Quoted 21 lines
  			ret = -EOVERFLOW;
  		goto out;
  	}
drivers/iommu/iommu-sva.c +1 -5
-	pasid = ioasid_alloc(&iommu_sva_pasid, min, max, mm);
-	if (!pasid_valid(pasid))
-		ret = -ENOMEM;
-	else
-		mm->pasid = pasid;
+	ret = ida_alloc_range(&iommu_global_pasid_ida, min, max,

GFP_ATOMIC);

drivers/iommu/iommu-sva.c +4 -1
+	if (ret < 0)
+		goto out;
+	mm->pasid = ret;
+	ret = 0;
  out:
  	mutex_unlock(&iommu_sva_lock);
  	return ret;
  }
-EXPORT_SYMBOL_GPL(iommu_sva_alloc_pasid);
Quoted 17 lines
Quoted 4 lines

/**
* iommu_sva_bind_device() - Bind a process address space to a device

drivers/iommu/iommu-sva.c +0 -0
@@ -221,8 +207,8 @@ iommu_sva_handle_iopf(struct iommu_fault *fault,
 void *data) 

drivers/iommu/iommu-sva.c iommu_sva_handle_iopf(struct iommu_fault *fault, · line 213

Quoted 10 lines
drivers/iommu/iommu-sva.c +4 -4
  void mm_pasid_drop(struct mm_struct *mm)
  {
-	if (pasid_valid(mm->pasid)) {
-		ioasid_free(mm->pasid);
-		mm->pasid = INVALID_IOASID;
-	}
+	if (likely(!pasid_valid(mm->pasid)))
+		return;
+
+	ida_free(&iommu_global_pasid_ida, mm->pasid);  

Any reason why do you drop "mm->pasid = INVALID_IOASID;" here?

mm_drop is called when mm gets released because "mm_count" becomes zero. so there is no more mm_users. No one will see mm->pasid after this.

On the other hand, iommu_sva_bind_device() needs to hold mm_users refcount so it won;t happen after mm_drop.

Quoted 9 lines
Quoted 9 lines
drivers/iommu/iommu-sva.c +0 -0
  }
drivers/iommu/iommu-sva.h +0 -0
index 102eae1817a2..c22d0174ad61 100644
@@ -8,8 +8,6 @@
  #include <linux/ioasid.h>
  #include <linux/mm_types.h>
 
Quoted 8 lines
Quoted 5 lines
drivers/iommu/iommu-sva.h +0 -1
-int iommu_sva_alloc_pasid(struct mm_struct *mm, ioasid_t min, ioasid_t

max); -
/* I/O Page fault */
struct device;
struct iommu_fault;

Best regards,
baolu

Thanks,

Jacob

author
#13 lore raw

PATCH v5 5/7 iommu/sva: Use GFP_KERNEL for pasid allocation

In reply to Jacob Pan

We’re not using spinlock-protected IOASID allocation anymore, there’s no need for GFP_ATOMIC.

---
 drivers/iommu/iommu-sva.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iommu/iommu-sva.c +2 -2
index b75711bdbe97..bd6fb2a6df23 100644
@@ -27,8 +27,8 @@ static int iommu_sva_alloc_pasid(struct mm_struct *mm, ioasid_t min, ioasid_t ma
 		goto out;
 	}
 
-	ret = ida_alloc_range(&iommu_global_pasid_ida, min, max, GFP_ATOMIC);
-	if (ret < 0)
+	ret = ida_alloc_range(&iommu_global_pasid_ida, min, max, GFP_KERNEL);
+	if (ret < min)
 		goto out;
 	mm->pasid = ret;
 	ret = 0;
Signature · 1 line
2.25.1
author
#14 lore raw

PATCH v5 6/7 iommu/ioasid: Rename INVALID_IOASID

In reply to Jacob Pan

INVALID_IOASID and IOMMU_PASID_INVALID are duplicated. Rename INVALID_IOASID and consolidate since we are moving away from IOASID infrastructure.

---
v5:
- Use pasid_valid() helper

---
 Documentation/x86/sva.rst    | 2 +-
 arch/x86/kernel/traps.c      | 5 ++++-
 drivers/dma/idxd/device.c    | 8 ++++----
 drivers/dma/idxd/idxd.h      | 1 +
 drivers/dma/idxd/init.c      | 2 +-
 drivers/dma/idxd/irq.c       | 2 +-
 drivers/iommu/intel/dmar.c   | 4 ++--
 drivers/iommu/intel/iommu.c  | 2 +-
 drivers/iommu/intel/svm.c    | 2 +-
 include/linux/ioasid.h       | 5 +----
 include/linux/iommu-helper.h | 4 ++--
 include/linux/iommu.h        | 7 +++++--
 mm/init-mm.c                 | 4 ++--
 13 files changed, 26 insertions(+), 22 deletions(-)
Documentation/x86/sva.rst +1 -1
index 2e9b8b0f9a0f..33cb05005982 100644
@@ -107,7 +107,7 @@ process share the same page tables, thus the same MSR value.
 PASID Life Cycle Management
 ===========================
 
-PASID is initialized as INVALID_IOASID (-1) when a process is created.
+PASID is initialized as IOMMU_PASID_INVALID (-1) when a process is created.
 
 Only processes that access SVA-capable devices need to have a PASID
 allocated. This allocation happens when a process opens/binds an SVA-capable
arch/x86/kernel/traps.c +4 -1
index d317dc3d06a3..d6fb03ebf548 100644
@@ -40,7 +40,10 @@
 #include <linux/io.h>
 #include <linux/hardirq.h>
 #include <linux/atomic.h>
-#include <linux/ioasid.h>
+
+#ifdef CONFIG_IOMMU_SVA
+#include <linux/iommu.h>
+#endif
 
 #include <asm/stacktrace.h>
 #include <asm/processor.h>
drivers/dma/idxd/device.c +4 -4
index 5f321f3b4242..6fca8fa8d3a8 100644
@@ -1194,7 +1194,7 @@ static void idxd_device_set_perm_entry(struct idxd_device *idxd,
 {
 	union msix_perm mperm;
 
-	if (ie->pasid == INVALID_IOASID)
+	if (ie->pasid == IOMMU_PASID_INVALID)
 		return;
 
 	mperm.bits = 0;
@@ -1224,7 +1224,7 @@ void idxd_wq_free_irq(struct idxd_wq *wq)
 	idxd_device_clear_perm_entry(idxd, ie);
 	ie->vector = -1;
 	ie->int_handle = INVALID_INT_HANDLE;
-	ie->pasid = INVALID_IOASID;
+	ie->pasid = IOMMU_PASID_INVALID;
 }
 
 int idxd_wq_request_irq(struct idxd_wq *wq)
@@ -1240,7 +1240,7 @@ int idxd_wq_request_irq(struct idxd_wq *wq)
 
 	ie = &wq->ie;
 	ie->vector = pci_irq_vector(pdev, ie->id);
-	ie->pasid = device_pasid_enabled(idxd) ? idxd->pasid : INVALID_IOASID;
+	ie->pasid = device_pasid_enabled(idxd) ? idxd->pasid : IOMMU_PASID_INVALID;
 	idxd_device_set_perm_entry(idxd, ie);
 
 	rc = request_threaded_irq(ie->vector, NULL, idxd_wq_thread, 0, "idxd-portal", ie);
@@ -1265,7 +1265,7 @@ int idxd_wq_request_irq(struct idxd_wq *wq)
 	free_irq(ie->vector, ie);
 err_irq:
 	idxd_device_clear_perm_entry(idxd, ie);
-	ie->pasid = INVALID_IOASID;
+	ie->pasid = IOMMU_PASID_INVALID;
 	return rc;
 }
 
drivers/dma/idxd/idxd.h +1 -0
index 7ced8d283d98..417e602a46b6 100644
@@ -13,6 +13,7 @@
 #include <linux/ioasid.h>
 #include <linux/bitmap.h>
 #include <linux/perf_event.h>
+#include <linux/iommu.h>
 #include <uapi/linux/idxd.h>
 #include "registers.h"
 
drivers/dma/idxd/init.c +1 -1
index 640d3048368e..e6ee267da0ff 100644
@@ -105,7 +105,7 @@ static int idxd_setup_interrupts(struct idxd_device *idxd)
 		ie = idxd_get_ie(idxd, msix_idx);
 		ie->id = msix_idx;
 		ie->int_handle = INVALID_INT_HANDLE;
-		ie->pasid = INVALID_IOASID;
+		ie->pasid = IOMMU_PASID_INVALID;
 
 		spin_lock_init(&ie->list_lock);
 		init_llist_head(&ie->pending_llist);
drivers/dma/idxd/irq.c +1 -1
index aa314ebec587..242f1f0b9f09 100644
@@ -80,7 +80,7 @@ static void idxd_int_handle_revoke_drain(struct idxd_irq_entry *ie)
 	desc.opcode = DSA_OPCODE_DRAIN;
 	desc.priv = 1;
 
-	if (ie->pasid != INVALID_IOASID)
+	if (ie->pasid != IOMMU_PASID_INVALID)
 		desc.pasid = ie->pasid;
 	desc.int_handle = ie->int_handle;
 	portal = idxd_wq_portal_addr(wq);
drivers/iommu/intel/dmar.c +2 -2
index 0f348439ef0e..10bb20ff50fd 100644
@@ -1958,7 +1958,7 @@ static int dmar_fault_do_one(struct intel_iommu *iommu, int type,
 		return 0;
 	}
 
-	if (pasid == INVALID_IOASID)
+	if (pasid == IOMMU_PASID_INVALID)
 		pr_err("[%s NO_PASID] Request device [%02x:%02x.%d] fault addr 0x%llx [fault reason 0x%02x] %s\n",
 		       type ? "DMA Read" : "DMA Write",
 		       source_id >> 8, PCI_SLOT(source_id & 0xFF),
@@ -2039,7 +2039,7 @@ irqreturn_t dmar_fault(int irq, void *dev_id)
 		if (!ratelimited)
 			/* Using pasid -1 if pasid is not present */
 			dmar_fault_do_one(iommu, type, fault_reason,
-					  pasid_present ? pasid : INVALID_IOASID,
+					  pasid_present ? pasid : IOMMU_PASID_INVALID,
 					  source_id, guest_addr);
 
 		fault_index++;
drivers/iommu/intel/iommu.c +1 -1
index 21c14e00c852..0768dcae90fd 100644
@@ -876,7 +876,7 @@ void dmar_fault_dump_ptes(struct intel_iommu *iommu, u16 source_id,
 		return;
 	}
 	/* For request-without-pasid, get the pasid from context entry */
-	if (intel_iommu_sm && pasid == INVALID_IOASID)
+	if (intel_iommu_sm && pasid == IOMMU_PASID_INVALID)
 		pasid = PASID_RID2PASID;
 
 	dir_index = pasid >> PASID_PDE_SHIFT;
drivers/iommu/intel/svm.c +1 -1
index 7367f56c3bad..3848a1b0800c 100644
@@ -273,7 +273,7 @@ static int pasid_to_svm_sdev(struct device *dev, unsigned int pasid,
 	if (WARN_ON(!mutex_is_locked(&pasid_mutex)))
 		return -EINVAL;
 
-	if (pasid == INVALID_IOASID || pasid >= PASID_MAX)
+	if (pasid == IOMMU_PASID_INVALID || pasid >= PASID_MAX)
 		return -EINVAL;
 
 	svm = pasid_private_find(pasid);
include/linux/ioasid.h +1 -4
index 2c502e77ee78..665a3773a409 100644
@@ -7,6 +7,7 @@
 #include <linux/iommu-helper.h>
 
 typedef unsigned int ioasid_t;
+#define INVALID_IOASID ((ioasid_t)-1)
 typedef ioasid_t (*ioasid_alloc_fn_t)(ioasid_t min, ioasid_t max, void *data);
 typedef void (*ioasid_free_fn_t)(ioasid_t ioasid, void *data);
 
@@ -40,10 +41,6 @@ void *ioasid_find(struct ioasid_set *set, ioasid_t ioasid,
 int ioasid_register_allocator(struct ioasid_allocator_ops *allocator);
 void ioasid_unregister_allocator(struct ioasid_allocator_ops *allocator);
 int ioasid_set_data(ioasid_t ioasid, void *data);
-static inline bool pasid_valid(ioasid_t ioasid)
-{
-	return ioasid != INVALID_IOASID;
-}
 
 #else /* !CONFIG_IOASID */
 static inline ioasid_t ioasid_alloc(struct ioasid_set *set, ioasid_t min,
include/linux/iommu-helper.h +2 -2
index be1451a05a15..7753b42ad8e1 100644
@@ -42,11 +42,11 @@ static inline unsigned long iommu_num_pages(unsigned long addr,
 	return DIV_ROUND_UP(size, io_page_size);
 }
 
-#define INVALID_IOASID	(-1U)
+#define IOMMU_PASID_INVALID	(-1U)
 #ifdef CONFIG_IOMMU_SVA
 static inline void mm_pasid_init(struct mm_struct *mm)
 {
-	mm->pasid = INVALID_IOASID;
+	mm->pasid = IOMMU_PASID_INVALID;
 }
 void mm_pasid_drop(struct mm_struct *mm);
 #else
include/linux/iommu.h +5 -2
index 6595454d4f48..945a2f09b442 100644
@@ -191,8 +191,11 @@ enum iommu_dev_features {
 	IOMMU_DEV_FEAT_IOPF,
 };
 
-#define IOMMU_PASID_INVALID	(-1U)
-
+typedef unsigned int ioasid_t;
+static inline bool pasid_valid(ioasid_t ioasid)
+{
+	return ioasid != IOMMU_PASID_INVALID;
+}
 #ifdef CONFIG_IOMMU_API
 
 /**
mm/init-mm.c +2 -2
index c9327abb771c..a084039f55d8 100644
@@ -10,7 +10,7 @@
 
 #include <linux/atomic.h>
 #include <linux/user_namespace.h>
-#include <linux/ioasid.h>
+#include <linux/iommu.h>
 #include <asm/mmu.h>
 
 #ifndef INIT_MM_CONTEXT
@@ -40,7 +40,7 @@ struct mm_struct init_mm = {
 	.user_ns	= &init_user_ns,
 	.cpu_bitmap	= CPU_BITS_NONE,
 #ifdef CONFIG_IOMMU_SVA
-	.pasid		= INVALID_IOASID,
+	.pasid		= IOMMU_PASID_INVALID,
 #endif
 	INIT_MM_CONTEXT(init_mm)
 };
Signature · 1 line
2.25.1
author
#15 lore raw

PATCH v5 7/7 iommu: Remove ioasid infrastructure

In reply to Jacob Pan

From: Jason Gunthorpe <[email protected]>

This has no use anymore, delete it all.

---
v3: - put rename under a different patch
- delete makefile and Kconfig
v2:
- fix compile issue w/o CONFIG_IOMMU_SVA
- consolidate INVALID_IOASID w/ IOMMU_PASID_INVALID

---
 drivers/dma/idxd/idxd.h     |   1 -
 drivers/iommu/Kconfig       |   5 -
 drivers/iommu/Makefile      |   1 -
 drivers/iommu/intel/iommu.h |   1 -
 drivers/iommu/intel/svm.c   |   1 -
 drivers/iommu/ioasid.c      | 422 ------------------------------------
 drivers/iommu/iommu-sva.h   |   1 -
 include/linux/ioasid.h      |  80 -------
 include/linux/iommu.h       |   1 -
 9 files changed, 513 deletions(-)
 delete mode 100644 drivers/iommu/ioasid.c
 delete mode 100644 include/linux/ioasid.h
drivers/dma/idxd/idxd.h +0 -1
index 417e602a46b6..dd2a6ed8949b 100644
@@ -10,7 +10,6 @@
 #include <linux/cdev.h>
 #include <linux/idr.h>
 #include <linux/pci.h>
-#include <linux/ioasid.h>
 #include <linux/bitmap.h>
 #include <linux/perf_event.h>
 #include <linux/iommu.h>
drivers/iommu/Kconfig +0 -5
index 889c7efd050b..a799221f8844 100644
@@ -3,10 +3,6 @@
 config IOMMU_IOVA
 	tristate
 
-# The IOASID library may also be used by non-IOMMU_API users
-config IOASID
-	tristate
-
 # IOMMU_API always gets selected by whoever wants it.
 config IOMMU_API
 	bool
@@ -160,7 +156,6 @@ config IOMMU_DMA
 # Shared Virtual Addressing
 config IOMMU_SVA
 	bool
-	select IOASID
 
 config FSL_PAMU
 	bool "Freescale IOMMU support"
drivers/iommu/Makefile +0 -1
index f461d0651385..769e43d780ce 100644
@@ -9,7 +9,6 @@ obj-$(CONFIG_IOMMU_IO_PGTABLE) += io-pgtable.o
 obj-$(CONFIG_IOMMU_IO_PGTABLE_ARMV7S) += io-pgtable-arm-v7s.o
 obj-$(CONFIG_IOMMU_IO_PGTABLE_LPAE) += io-pgtable-arm.o
 obj-$(CONFIG_IOMMU_IO_PGTABLE_DART) += io-pgtable-dart.o
-obj-$(CONFIG_IOASID) += ioasid.o
 obj-$(CONFIG_IOMMU_IOVA) += iova.o
 obj-$(CONFIG_OF_IOMMU)	+= of_iommu.o
 obj-$(CONFIG_MSM_IOMMU) += msm_iommu.o
drivers/iommu/intel/iommu.h +0 -1
index a2010fb120e2..65b15be72878 100644
@@ -19,7 +19,6 @@
 #include <linux/iommu.h>
 #include <linux/io-64-nonatomic-lo-hi.h>
 #include <linux/dmar.h>
-#include <linux/ioasid.h>
 #include <linux/bitfield.h>
 #include <linux/xarray.h>
 #include <linux/perf_event.h>
drivers/iommu/intel/svm.c +0 -1
index 3848a1b0800c..e95b339e9cdc 100644
@@ -16,7 +16,6 @@
 #include <linux/interrupt.h>
 #include <linux/mm_types.h>
 #include <linux/xarray.h>
-#include <linux/ioasid.h>
 #include <asm/page.h>
 #include <asm/fpu/api.h>
 
drivers/iommu/ioasid.c deleted +0 -422

422 lines not on this page · raw message

drivers/iommu/iommu-sva.h +0 -1
index c22d0174ad61..54946b5a7caf 100644
@@ -5,7 +5,6 @@
 #ifndef _IOMMU_SVA_H
 #define _IOMMU_SVA_H
 
-#include <linux/ioasid.h>
 #include <linux/mm_types.h>
 
 /* I/O Page fault */
include/linux/ioasid.h deleted +0 -80

80 lines not on this page · raw message

include/linux/iommu.h +0 -1
index 945a2f09b442..94f4e53c50e7 100644
@@ -13,7 +13,6 @@
 #include <linux/errno.h>
 #include <linux/err.h>
 #include <linux/of.h>
-#include <linux/ioasid.h>
 #include <uapi/linux/iommu.h>
 
 #define IOMMU_READ	(1 << 0)
Signature · 1 line
2.25.1