Skip to contentSkip to conversation

Remove VT-d virtual command interface and IOASID

PATCH Superseded Jacob Pan 5 participants 19 messages Feb 14, 2023 – Feb 24, 2023

Subsystems (8)

v2 of 8 Superseded Latest is v8 →

lore
Share & tools
lore

Jacob Pan

author
#0 lore raw

v2 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

Jacob Pan (2):
iommu/vt-d: Remove virtual command interface
iommu: Remove ioasid infrastructure

Jason Gunthorpe (1):
iommu/sva: Stop using ioasid_set for SVA

 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/intel/cap_audit.c |   2 -
 drivers/iommu/intel/dmar.c      |   6 +-
 drivers/iommu/intel/iommu.c     |  87 +------
 drivers/iommu/intel/iommu.h     |   9 -
 drivers/iommu/intel/svm.c       |   3 +-
 drivers/iommu/ioasid.c          | 422 --------------------------------
 drivers/iommu/iommu-sva.c       |  55 ++---
 drivers/iommu/iommu-sva.h       |   4 -
 include/linux/ioasid.h          |  83 -------
 include/linux/iommu.h           |  11 +-
 include/linux/sched/mm.h        |  12 +-
 include/uapi/linux/iommu.h      |   1 +
 mm/init-mm.c                    |   4 +-
 19 files changed, 46 insertions(+), 674 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

PATCH v2 1/3 iommu/vt-d: Remove virtual command interface

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     |  8 ----
 4 files changed, 97 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 b00a0ceb2d13..bf0bfe5ba7a7 100644
@@ -989,8 +989,6 @@ static int map_iommu(struct intel_iommu *iommu, u64 phys_addr)
 		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 -8
index 06e61e474856..6bdfbead82c4 100644
@@ -184,7 +184,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)
@@ -210,9 +209,6 @@
 #define ecap_max_handle_mask(e) (((e) >> 20) & 0xf)
 #define ecap_sc_support(e)	(((e) >> 7) & 0x1) /* Snooping Control */
 
-/* Virtual command interface capability */
-#define vccap_pasid(v)		(((v) & DMA_VCS_PAS)) /* PASID allocation */
-
 /* IOTLB_REG */
 #define DMA_TLB_FLUSH_GRANU_OFFSET  60
 #define DMA_TLB_GLOBAL_FLUSH (((u64)1) << 60)
@@ -307,8 +303,6 @@
 #define DMA_PRS_PPR	((u32)1)
 #define DMA_PRS_PRO	((u32)2)
 
-#define DMA_VCS_PAS	((u64)1)
-
 #define IOMMU_WAIT_OP(iommu, offset, op, cond, sts)			\
 do {									\
 	cycles_t start_time = get_cycles();				\
@@ -560,7 +554,6 @@ struct intel_iommu {
 	u64		reg_size; /* size of hw register set */
 	u64		cap;
 	u64		ecap;
-	u64		vccap;
 	u32		gcmd; /* Holds TE, EAFL. Don't need SRTP, SFL, WBF */
 	raw_spinlock_t	register_lock; /* protect register handling */
 	int		seq_id;	/* sequence id of the iommu */
@@ -583,7 +576,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
maintainer Reviewed-by on v2 1/3
#2 lore raw

Re: [PATCH v2 1/3] iommu/vt-d: Remove virtual command interface

Quoted 9 lines · 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.

Best regards,
baolu

author
#3 lore raw

PATCH v2 2/3 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.

---
v2: minor fixes
- let idxd driver use iommu.h for ioasid_t
- return 0 after mm_pasid_set()

---
 drivers/dma/idxd/idxd.h   |  1 +
 drivers/iommu/iommu-sva.c | 53 +++++++++++----------------------------
 drivers/iommu/iommu-sva.h |  3 ---
 include/linux/sched/mm.h  |  8 +-----
 4 files changed, 17 insertions(+), 48 deletions(-)
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/iommu/iommu-sva.c +15 -38

78 lines not on this page · raw message

drivers/iommu/iommu-sva.h +0 -3
index 7215a761b962..c22d0174ad61 100644
@@ -8,9 +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);
-struct mm_struct *iommu_sva_find(ioasid_t pasid);
-
 /* I/O Page fault */
 struct device;
 struct iommu_fault;
include/linux/sched/mm.h +1 -7
index 2a243616f222..cdc138086230 100644
@@ -463,13 +463,7 @@ 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;
-	}
-}
+void mm_pasid_drop(struct mm_struct *mm);
 #else
 static inline void mm_pasid_init(struct mm_struct *mm) {}
 static inline void mm_pasid_set(struct mm_struct *mm, u32 pasid) {}
Signature · 1 line
2.25.1
#4 lore raw

Re: [PATCH v2 2/3] iommu/sva: Stop using ioasid_set for SVA

Quoted 27 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.

---
v2: minor fixes
- let idxd driver use iommu.h for ioasid_t
- return 0 after mm_pasid_set()

---
 drivers/dma/idxd/idxd.h   |  1 +
 drivers/iommu/iommu-sva.c | 53 +++++++++++----------------------------
 drivers/iommu/iommu-sva.h |  3 ---
 include/linux/sched/mm.h  |  8 +-----
 4 files changed, 17 insertions(+), 48 deletions(-)
drivers/dma/idxd/idxd.h +0 -0
index 7ced8d283d98..417e602a46b6 100644

drivers/dma/idxd/idxd.h line 16

Quoted 4 lines
drivers/dma/idxd/idxd.h +1 -0
@@ -13,6 +13,7 @@
 #include <linux/ioasid.h>
 #include <linux/bitmap.h>
 #include <linux/perf_event.h>
+#include <linux/iommu.h>

Unrelated

Quoted 41 lines
drivers/dma/idxd/idxd.h +0 -0
 #include <uapi/linux/idxd.h>
 #include "registers.h"
 
drivers/iommu/iommu-sva.c +5 -16
index 24bf9b2b58aa..8fb6f1867af3 100644
@@ -9,24 +9,11 @@
 #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;
+	int ret;
 
 	if (min == INVALID_IOASID || max == INVALID_IOASID ||
 	    min == 0 || max < min)
@@ -37,39 +24,29 @@ int iommu_sva_alloc_pasid(struct mm_struct *mm, ioasid_t min, ioasid_t max)
 	if (pasid_valid(mm->pasid)) {
 		if (mm->pasid < min || mm->pasid >= max)
 			ret = -EOVERFLOW;
+		else
+			ret = 0;

drivers/iommu/iommu-sva.c int iommu_sva_alloc_pasid(struct mm_struct *mm, ioasid_t min, ioasid_t max) · line 33

Quoted 10 lines
drivers/iommu/iommu-sva.c +2 -5
 		goto out;
 	}
 
-	pasid = ioasid_alloc(&iommu_sva_pasid, min, max, mm);
-	if (!pasid_valid(pasid))
-		ret = -ENOMEM;
-	else
-		mm_pasid_set(mm, pasid);
+	ret = ida_alloc_range(&iommu_global_pasid_ida, min, max, GFP_KERNEL);
+	if (ret < min)

Just check ret < 0

Quoted 6 lines
drivers/iommu/iommu-sva.c +3 -0
+		goto out;
+	mm_pasid_set(mm, ret);
+	ret = 0;
 out:
 	mutex_unlock(&iommu_sva_lock);
 	return ret;

drivers/iommu/iommu-sva.c int iommu_sva_alloc_pasid(struct mm_struct *mm, ioasid_t min, ioasid_t max) · line 44

Quoted 10 lines
drivers/iommu/iommu-sva.c +2 -5
 }
-EXPORT_SYMBOL_GPL(iommu_sva_alloc_pasid);
 
-/* ioasid_find getter() requires a void * argument */
-static bool __mmget_not_zero(void *mm)
+void mm_pasid_drop(struct mm_struct *mm)
 {
-	return mmget_not_zero(mm);
-}
+	pr_alert("%s %d", __func__, mm->pasid);

Debug print

Thanks,
Jean

Quoted 56 lines
drivers/iommu/iommu-sva.c +3 -12
+	if (likely(!pasid_valid(mm->pasid)))
+		return;
 
-/**
- * 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);
+	ida_free(&iommu_global_pasid_ida, mm->pasid);
 }
-EXPORT_SYMBOL_GPL(iommu_sva_find);
 
 /**
  * iommu_sva_bind_device() - Bind a process address space to a device
drivers/iommu/iommu-sva.h +0 -3
index 7215a761b962..c22d0174ad61 100644
@@ -8,9 +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);
-struct mm_struct *iommu_sva_find(ioasid_t pasid);
-
 /* I/O Page fault */
 struct device;
 struct iommu_fault;
include/linux/sched/mm.h +1 -7
index 2a243616f222..cdc138086230 100644
@@ -463,13 +463,7 @@ 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;
-	}
-}
+void mm_pasid_drop(struct mm_struct *mm);
 #else
 static inline void mm_pasid_init(struct mm_struct *mm) {}
 static inline void mm_pasid_set(struct mm_struct *mm, u32 pasid) {}
Signature · 1 line
2.25.1
author
#5 lore raw

Re: [PATCH v2 2/3] iommu/sva: Stop using ioasid_set for SVA

Hi Jean-Philippe,

Quoted 23 lines · Jean-Philippe Brucker
Quoted 22 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.

---
v2: minor fixes
- let idxd driver use iommu.h for ioasid_t
- return 0 after mm_pasid_set()

---
 drivers/dma/idxd/idxd.h   |  1 +
 drivers/iommu/iommu-sva.c | 53 +++++++++++----------------------------
 drivers/iommu/iommu-sva.h |  3 ---
 include/linux/sched/mm.h  |  8 +-----
 4 files changed, 17 insertions(+), 48 deletions(-)
Quoted 11 lines

drivers/dma/idxd/idxd.h line 16

Quoted 9 lines
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>  

Unrelated

this is for ioasid_t, won't compile without it

Quoted 47 lines
Quoted 47 lines
drivers/dma/idxd/idxd.h +0 -0
 #include <uapi/linux/idxd.h>
 #include "registers.h"
 
drivers/iommu/iommu-sva.c +1 -8
index 24bf9b2b58aa..8fb6f1867af3 100644
@@ -9,24 +9,11 @@
 #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) {

drivers/iommu/iommu-sva.c +3 -2
-	int ret = 0;
-	ioasid_t pasid;
+	int ret;
 
 	if (min == INVALID_IOASID || max == INVALID_IOASID ||
 	    min == 0 || max < min)
@@ -37,39 +24,29 @@ int iommu_sva_alloc_pasid(struct mm_struct *mm,
 ioasid_t min, ioasid_t max) if (pasid_valid(mm->pasid)) {
 		if (mm->pasid < min || mm->pasid >= max)
 			ret = -EOVERFLOW;
+		else
+			ret = 0;
 		goto out;
 	}
 
Quoted 10 lines

drivers/iommu/iommu-sva.c int iommu_sva_alloc_pasid(struct mm_struct *mm, ioasid_t min, ioasid_t max) · line 33

Quoted 8 lines
drivers/iommu/iommu-sva.c +2 -5
-	pasid = ioasid_alloc(&iommu_sva_pasid, min, max, mm);
-	if (!pasid_valid(pasid))
-		ret = -ENOMEM;
-	else
-		mm_pasid_set(mm, pasid);
+	ret = ida_alloc_range(&iommu_global_pasid_ida, min, max,
 GFP_KERNEL);
+	if (ret < min)  

Just check ret < 0

yes, but i thought < min is safe too.

Quoted 9 lines
Quoted 9 lines
drivers/iommu/iommu-sva.c +3 -1
+		goto out;
+	mm_pasid_set(mm, ret);
+	ret = 0;
 out:
 	mutex_unlock(&iommu_sva_lock);
 	return ret;
 }
-EXPORT_SYMBOL_GPL(iommu_sva_alloc_pasid);
 
Quoted 9 lines

drivers/iommu/iommu-sva.c int iommu_sva_alloc_pasid(struct mm_struct *mm, ioasid_t min, ioasid_t max) · line 44

Quoted 7 lines
drivers/iommu/iommu-sva.c +2 -4
-/* ioasid_find getter() requires a void * argument */
-static bool __mmget_not_zero(void *mm)
+void mm_pasid_drop(struct mm_struct *mm)
 {
-	return mmget_not_zero(mm);
-}
+	pr_alert("%s %d", __func__, mm->pasid);  

Debug print

will remove,
Thanks a lot!

Jacob

#6 lore raw

Re: [PATCH v2 2/3] iommu/sva: Stop using ioasid_set for SVA

Quoted 11 lines · Jacob Pan
Quoted 10 lines

drivers/iommu/iommu-sva.c int iommu_sva_alloc_pasid(struct mm_struct *mm, ioasid_t min, ioasid_t max) · line 33

Quoted 8 lines
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_set(mm, pasid);
+	ret = ida_alloc_range(&iommu_global_pasid_ida, min, max,

GFP_KERNEL);

drivers/iommu/iommu-sva.c +1 -0
+	if (ret < min)  

Just check ret < 0

yes, but i thought < min is safe too.

It is, but 'ret < 0' is the standard used everywhere else. So someone reading this code will stop and spend time trying to figure out why this isn't 'ret < 0', wonder what's special here, inspect the ida_alloc_range() doc, etc. No big deal, but I think it's unnecessary.

Thanks,
Jean

#7 lore raw

RE: [PATCH v2 2/3] iommu/sva: Stop using ioasid_set for SVA

In reply to Jacob Pan
Quoted 11 lines

From: Jacob Pan <[email protected]>
Sent: Tuesday, February 14, 2023 2:44 PM

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.

I think DMA API PASID will need new API around this IDA. SVA APIs should be just for SVA.

Quoted 17 lines
drivers/iommu/iommu-sva.c +4 -7
+void mm_pasid_drop(struct mm_struct *mm)
 {
-	return mmget_not_zero(mm);
-}
+	pr_alert("%s %d", __func__, mm->pasid);
+	if (likely(!pasid_valid(mm->pasid)))
+		return;
 
-/**
- * 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.
- */

drivers/iommu/iommu-sva.c int iommu_sva_alloc_pasid(struct mm_struct *mm, ioasid_t min, ioasid_t max) · line 49

Quoted 5 lines
drivers/iommu/iommu-sva.c +1 -3
-struct mm_struct *iommu_sva_find(ioasid_t pasid)
-{
-	return ioasid_find(&iommu_sva_pasid, pasid, __mmget_not_zero);
+	ida_free(&iommu_global_pasid_ida, mm->pasid);
 }

when moving this function following line is missed:

	mm->pasid = INVALID_IOASID;

btw the current placement looks asymmetric. We now have mm_pasid_init() and mm_pasid_set() in mm.h while mm_pasid_drop() in iommu-sva.c.

Is it cleaner to introduce a iommu_sva_free_pasid() helper and then call it from mm_pasid_drop() in mm.h?

author
#8 lore raw

Re: [PATCH v2 2/3] iommu/sva: Stop using ioasid_set for SVA

Hi Kevin,

Quoted 41 lines · Kevin
Quoted 11 lines

From: Jacob Pan <[email protected]>
Sent: Tuesday, February 14, 2023 2:44 PM

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.

I think DMA API PASID will need new API around this IDA. SVA APIs should be just for SVA.

Quoted 18 lines
drivers/iommu/iommu-sva.c +4 -7
+void mm_pasid_drop(struct mm_struct *mm)
 {
-	return mmget_not_zero(mm);
-}
+	pr_alert("%s %d", __func__, mm->pasid);
+	if (likely(!pasid_valid(mm->pasid)))
+		return;
 
-/**
- * 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.
- */

drivers/iommu/iommu-sva.c int iommu_sva_alloc_pasid(struct mm_struct *mm, ioasid_t min, ioasid_t max) · line 49

Quoted 5 lines
drivers/iommu/iommu-sva.c +1 -3
-struct mm_struct *iommu_sva_find(ioasid_t pasid)
-{
-	return ioasid_find(&iommu_sva_pasid, pasid, __mmget_not_zero);
+	ida_free(&iommu_global_pasid_ida, mm->pasid);
 }  

when moving this function following line is missed:

Quoted 2 lines
	mm->pasid = INVALID_IOASID;

not needed, mm is gone by now.

Quoted 5 lines

btw the current placement looks asymmetric. We now have mm_pasid_init() and mm_pasid_set() in mm.h while mm_pasid_drop() in iommu-sva.c.
Is it cleaner to introduce a iommu_sva_free_pasid() helper and then call it from mm_pasid_drop() in mm.h?

That is what we had before, it seems logical to me. Jason?

Thanks,

Jacob

#9 lore raw

Re: [PATCH v2 2/3] iommu/sva: Stop using ioasid_set for SVA

Quoted 48 lines · Jacob Pan

Hi Kevin,

Quoted 41 lines · Kevin
Quoted 11 lines

From: Jacob Pan <[email protected]>
Sent: Tuesday, February 14, 2023 2:44 PM

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.

I think DMA API PASID will need new API around this IDA. SVA APIs should be just for SVA.

Quoted 18 lines
drivers/iommu/iommu-sva.c +4 -7
+void mm_pasid_drop(struct mm_struct *mm)
 {
-	return mmget_not_zero(mm);
-}
+	pr_alert("%s %d", __func__, mm->pasid);
+	if (likely(!pasid_valid(mm->pasid)))
+		return;
 
-/**
- * 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.
- */

drivers/iommu/iommu-sva.c int iommu_sva_alloc_pasid(struct mm_struct *mm, ioasid_t min, ioasid_t max) · line 49

Quoted 5 lines
drivers/iommu/iommu-sva.c +1 -3
-struct mm_struct *iommu_sva_find(ioasid_t pasid)
-{
-	return ioasid_find(&iommu_sva_pasid, pasid, __mmget_not_zero);
+	ida_free(&iommu_global_pasid_ida, mm->pasid);
 }  

when moving this function following line is missed:

Quoted 2 lines
	mm->pasid = INVALID_IOASID;
Quoted 8 lines

not needed, mm is gone by now.

Quoted 5 lines

btw the current placement looks asymmetric. We now have mm_pasid_init() and mm_pasid_set() in mm.h while mm_pasid_drop() in iommu-sva.c.
Is it cleaner to introduce a iommu_sva_free_pasid() helper and then call it from mm_pasid_drop() in mm.h?

That is what we had before, it seems logical to me. Jason?

I don't much like a maze of functions calling each other.

Renaming the helper might help, especially if it comes from iommu.h

Jason

author
#10 lore raw

PATCH v2 3/3 iommu: Remove ioasid infrastructure

In reply to Jacob Pan

This has no use anymore, delete it all.

---
v2:
- fix compile issue w/o CONFIG_IOMMU_SVA
- consolidate INVALID_IOASID w/ IOMMU_PASID_INVALID

---
 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/iommu.h |   1 -
 drivers/iommu/intel/svm.c   |   3 +-
 drivers/iommu/ioasid.c      | 422 ------------------------------------
 drivers/iommu/iommu-sva.c   |   2 +-
 drivers/iommu/iommu-sva.h   |   1 -
 include/linux/ioasid.h      |  83 -------
 include/linux/iommu.h       |  11 +-
 include/linux/sched/mm.h    |   4 +-
 include/uapi/linux/iommu.h  |   1 +
 mm/init-mm.c                |   4 +-
 18 files changed, 29 insertions(+), 529 deletions(-)
 delete mode 100644 drivers/iommu/ioasid.c
 delete mode 100644 include/linux/ioasid.h
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 29dbb0f52e18..125652a8bb29 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 +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/dma/idxd/init.c +1 -1
index 529ea09c9094..f30eef701970 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 bf0bfe5ba7a7..c567f94b66c7 100644
@@ -1933,7 +1933,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),
@@ -2014,7 +2014,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 a295e80fdfe8..10f657828d3a 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/iommu.h +0 -1
index 6bdfbead82c4..80582e497782 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>
 
drivers/iommu/intel/svm.c +1 -2
index c76b66263467..b4efc541f6b3 100644
@@ -17,7 +17,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>
 
@@ -274,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);
drivers/iommu/ioasid.c deleted +0 -422

422 lines not on this page · raw message

drivers/iommu/iommu-sva.c +1 -1
index 8fb6f1867af3..5daf3353e149 100644
@@ -15,7 +15,7 @@ static int iommu_sva_alloc_pasid(struct mm_struct *mm, ioasid_t min, ioasid_t ma
 {
 	int ret;
 
-	if (min == INVALID_IOASID || max == INVALID_IOASID ||
+	if (min == IOMMU_PASID_INVALID || max == IOMMU_PASID_INVALID ||
 	    min == 0 || max < min)
 		return -EINVAL;
 
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 -83

83 lines not on this page · raw message

include/linux/iommu.h +8 -3
index 46e1347bfa22..7cbcf37df8cd 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)
@@ -192,8 +191,14 @@ enum iommu_dev_features {
 	IOMMU_DEV_FEAT_IOPF,
 };
 
-#define IOMMU_PASID_INVALID	(-1U)
-
+//#define IOMMU_PASID_INVALID	(-1U)
+typedef unsigned int ioasid_t;
+#ifdef CONFIG_IOMMU_SVA
+static inline bool pasid_valid(ioasid_t ioasid)
+{
+	return ioasid != IOMMU_PASID_INVALID;
+}
+#endif
 #ifdef CONFIG_IOMMU_API
 
 /**
include/linux/sched/mm.h +2 -2
index cdc138086230..4c52835d3359 100644
@@ -8,7 +8,7 @@
 #include <linux/mm_types.h>
 #include <linux/gfp.h>
 #include <linux/sync_core.h>
-#include <linux/ioasid.h>
+#include <uapi/linux/iommu.h>
 
 /*
  * Routines for handling mm_structs
@@ -454,7 +454,7 @@ static inline void membarrier_update_current_mm(struct mm_struct *next_mm)
 #ifdef CONFIG_IOMMU_SVA
 static inline void mm_pasid_init(struct mm_struct *mm)
 {
-	mm->pasid = INVALID_IOASID;
+	mm->pasid = IOMMU_PASID_INVALID;
 }
 
 /* Associate a PASID with an mm_struct: */
include/uapi/linux/iommu.h +1 -0
index 65d8b0234f69..a95f07f0c98c 100644
@@ -157,5 +157,6 @@ struct iommu_page_response {
 	__u32	grpid;
 	__u32	code;
 };
+#define IOMMU_PASID_INVALID	(-1U)
 
 #endif /* _UAPI_IOMMU_H */
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
#11 lore raw

Re: [PATCH v2 3/3] iommu: Remove ioasid infrastructure

Quoted 4 lines · Jacob Pan

This has no use anymore, delete it all.

Yes, a number of intended users haven't materialized yet. They can re-introduce the allocator when they need it.

Quoted 4 lines

---
v2:
- fix compile issue w/o CONFIG_IOMMU_SVA
- consolidate INVALID_IOASID w/ IOMMU_PASID_INVALID

Why not rename ioasid_t as well? Probably better to move all the renaming to a separate patch

Quoted 11 lines
---
 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/iommu.h |   1 -
 drivers/iommu/intel/svm.c   |   3 +-
Quoted 8 lines
 drivers/iommu/ioasid.c      | 422 ------------------------------------
 drivers/iommu/iommu-sva.c   |   2 +-
 drivers/iommu/iommu-sva.h   |   1 -
 include/linux/ioasid.h      |  83 -------
 include/linux/iommu.h       |  11 +-
 include/linux/sched/mm.h    |   4 +-
 include/uapi/linux/iommu.h  |   1 +
 mm/init-mm.c                |   4 +-

drivers/iommu/{Makefile,Kconfig} also need updates

Quoted 17 lines
 18 files changed, 29 insertions(+), 529 deletions(-)
 delete mode 100644 drivers/iommu/ioasid.c
 delete mode 100644 include/linux/ioasid.h
include/linux/iommu.h +0 -1
index 46e1347bfa22..7cbcf37df8cd 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)

include/linux/iommu.h enum iommu_dev_features { · line 194

Quoted 6 lines
include/linux/iommu.h +1 -2
@@ -192,8 +191,14 @@ enum iommu_dev_features {
 	IOMMU_DEV_FEAT_IOPF,
 };
 
-#define IOMMU_PASID_INVALID	(-1U)
-
+//#define IOMMU_PASID_INVALID	(-1U)

Remove this

include/linux/iommu.h enum iommu_dev_features { · line 201

Quoted 7 lines
include/linux/iommu.h +7 -0
+typedef unsigned int ioasid_t;
+#ifdef CONFIG_IOMMU_SVA
+static inline bool pasid_valid(ioasid_t ioasid)
+{
+	return ioasid != IOMMU_PASID_INVALID;
+}
+#endif

This isn't specific to SVA, doesn't need an ifdef

Quoted 30 lines
include/linux/iommu.h +0 -0
 #ifdef CONFIG_IOMMU_API
 
 /**
include/linux/sched/mm.h +2 -2
index cdc138086230..4c52835d3359 100644
@@ -8,7 +8,7 @@
 #include <linux/mm_types.h>
 #include <linux/gfp.h>
 #include <linux/sync_core.h>
-#include <linux/ioasid.h>
+#include <uapi/linux/iommu.h>
 
 /*
  * Routines for handling mm_structs
@@ -454,7 +454,7 @@ static inline void membarrier_update_current_mm(struct mm_struct *next_mm)
 #ifdef CONFIG_IOMMU_SVA
 static inline void mm_pasid_init(struct mm_struct *mm)
 {
-	mm->pasid = INVALID_IOASID;
+	mm->pasid = IOMMU_PASID_INVALID;
 }
 
 /* Associate a PASID with an mm_struct: */
include/uapi/linux/iommu.h +0 -0
index 65d8b0234f69..a95f07f0c98c 100644

include/uapi/linux/iommu.h struct iommu_page_response { · line 160

Quoted 4 lines
include/uapi/linux/iommu.h +1 -0
@@ -157,5 +157,6 @@ struct iommu_page_response {
 	__u32	grpid;
 	__u32	code;
 };
+#define IOMMU_PASID_INVALID	(-1U)

Why change UAPI?

Thanks,
Jean

Quoted 27 lines
include/uapi/linux/iommu.h +0 -0
 #endif /* _UAPI_IOMMU_H */
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
#12 lore raw

Re: [PATCH v2 3/3] iommu: Remove ioasid infrastructure

Quoted 11 lines · Jean-Philippe Brucker

include/uapi/linux/iommu.h struct iommu_page_response { · line 160

Quoted 9 lines
include/uapi/linux/iommu.h +1 -0
index 65d8b0234f69..a95f07f0c98c 100644
@@ -157,5 +157,6 @@ struct iommu_page_response {
 	__u32	grpid;
 	__u32	code;
 };
+#define IOMMU_PASID_INVALID	(-1U)

Why change UAPI?

There is no uapi, this whole file needs to be deleted too

JAson

author
#13 lore raw

Re: [PATCH v2 3/3] iommu: Remove ioasid infrastructure

Hi Jason,

Quoted 13 lines · Jason Gunthorpe
Quoted 11 lines · Jean-Philippe Brucker

include/uapi/linux/iommu.h struct iommu_page_response { · line 160

Quoted 9 lines
include/uapi/linux/iommu.h +1 -0
index 65d8b0234f69..a95f07f0c98c 100644
@@ -157,5 +157,6 @@ struct iommu_page_response {
 	__u32	grpid;
 	__u32	code;
 };
+#define IOMMU_PASID_INVALID	(-1U)  

Why change UAPI?

Quoted 2 lines

There is no uapi, this whole file needs to be deleted too

ok. another clean up.

As I also replied to Jean, I ran into a circular #include problem if mm.h #include iommu.h, I guess I could also create another header, e.g. iommu_defs.h to avoid it. any other suggestions?

Thanks,

Jacob

#14 lore raw

Re: [PATCH v2 3/3] iommu: Remove ioasid infrastructure

Quoted 17 lines · Jacob Pan

Hi Jason,

Quoted 13 lines · Jason Gunthorpe
Quoted 11 lines · Jean-Philippe Brucker

include/uapi/linux/iommu.h struct iommu_page_response { · line 160

Quoted 9 lines
include/uapi/linux/iommu.h +1 -0
index 65d8b0234f69..a95f07f0c98c 100644
@@ -157,5 +157,6 @@ struct iommu_page_response {
 	__u32	grpid;
 	__u32	code;
 };
+#define IOMMU_PASID_INVALID	(-1U)  

Why change UAPI?

Quoted 7 lines
Quoted 2 lines

There is no uapi, this whole file needs to be deleted too

ok. another clean up.

As I also replied to Jean, I ran into a circular #include problem if mm.h #include iommu.h, I guess I could also create another header, e.g. iommu_defs.h to avoid it. any other suggestions?

Given this header is not used, just delete things from it to resolve the problem?

Jason

author
#15 lore raw

Re: [PATCH v2 3/3] iommu: Remove ioasid infrastructure

Hi Jason,

Quoted 21 lines · Jason Gunthorpe
Quoted 20 lines · Jacob Pan

Hi Jason,

Quoted 16 lines · Jason Gunthorpe
Quoted 11 lines · Jean-Philippe Brucker

include/uapi/linux/iommu.h struct iommu_page_response { · line 160

Quoted 9 lines
(quoted diff) +0 -0

b/include/uapi/linux/iommu.h index 65d8b0234f69..a95f07f0c98c 100644 --- a/include/uapi/linux/iommu.h
+++ b/include/uapi/linux/iommu.h

include/uapi/linux/iommu.h +1 -0
@@ -157,5 +157,6 @@ struct iommu_page_response {
 	__u32	grpid;
 	__u32	code;
 };
+#define IOMMU_PASID_INVALID	(-1U)    

Why change UAPI?

There is no uapi, this whole file needs to be deleted too

Quoted 8 lines
Quoted 5 lines

ok. another clean up.

As I also replied to Jean, I ran into a circular #include problem if mm.h #include iommu.h, I guess I could also create another header, e.g. iommu_defs.h to avoid it. any other suggestions?

Given this header is not used, just delete things from it to resolve the problem?

no, sorry i didn't make it clear. I meant if we do #include <linux/iommu.h> in sched/mm.h, then I got circular include problem.

The problem is not with include/uapi/linux/iommu.h

I could fix it by adding another header include/linux/iommu_defs.h for
#define IOMMU_PASID_INVALID (-1U)
But it feels like an overkill.

Thanks,

Jacob

#16 lore raw

Re: [PATCH v2 3/3] iommu: Remove ioasid infrastructure

Quoted 27 lines · Jacob Pan

Hi Jason,

Quoted 23 lines · Jason Gunthorpe
Quoted 22 lines · Jacob Pan

Hi Jason,

Quoted 14 lines · Jason Gunthorpe
Quoted 11 lines · Jean-Philippe Brucker

include/uapi/linux/iommu.h struct iommu_page_response { · line 160

Quoted 9 lines
(quoted diff) +0 -0

b/include/uapi/linux/iommu.h index 65d8b0234f69..a95f07f0c98c 100644 --- a/include/uapi/linux/iommu.h
+++ b/include/uapi/linux/iommu.h

include/uapi/linux/iommu.h +1 -0
@@ -157,5 +157,6 @@ struct iommu_page_response {
 	__u32	grpid;
 	__u32	code;
 };
+#define IOMMU_PASID_INVALID	(-1U)    

Why change UAPI?

Quoted 2 lines

There is no uapi, this whole file needs to be deleted too

ok. another clean up.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

As I also replied to Jean, I ran into a circular #include problem if mm.h #include iommu.h, I guess I could also create another header, e.g. iommu_defs.h to avoid it. any other suggestions?

Given this header is not used, just delete things from it to resolve the problem?

no, sorry i didn't make it clear. I meant if we do #include <linux/iommu.h> in sched/mm.h, then I got circular include problem.

You shouldn't do that at all, mm.h is included everywhere.

Try to make it smaller not larger.

You are better to include iommu.h in the few .c files that need these shims than put them in mm.h

Jason

author
#17 lore raw

Re: [PATCH v2 3/3] iommu: Remove ioasid infrastructure

In reply to Jean-Philippe Brucker

Hi Jean-Philippe,

Quoted 9 lines · Jean-Philippe Brucker
Quoted 4 lines · Jacob Pan

This has no use anymore, delete it all.

Yes, a number of intended users haven't materialized yet. They can re-introduce the allocator when they need it.

Quoted 8 lines
Quoted 4 lines

---
v2:
- fix compile issue w/o CONFIG_IOMMU_SVA
- consolidate INVALID_IOASID w/ IOMMU_PASID_INVALID

Why not rename ioasid_t as well? Probably better to move all the renaming to a separate patch

sounds good.

Quoted 20 lines
Quoted 11 lines
---
 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/iommu.h |   1 -
 drivers/iommu/intel/svm.c   |   3 +-
Quoted 8 lines
 drivers/iommu/ioasid.c      | 422 ------------------------------------
 drivers/iommu/iommu-sva.c   |   2 +-
 drivers/iommu/iommu-sva.h   |   1 -
 include/linux/ioasid.h      |  83 -------
 include/linux/iommu.h       |  11 +-
 include/linux/sched/mm.h    |   4 +-
 include/uapi/linux/iommu.h  |   1 +
 mm/init-mm.c                |   4 +-  
Quoted 2 lines

drivers/iommu/{Makefile,Kconfig} also need updates

good catch!

Quoted 20 lines
Quoted 20 lines
 18 files changed, 29 insertions(+), 529 deletions(-)
 delete mode 100644 drivers/iommu/ioasid.c
 delete mode 100644 include/linux/ioasid.h  
include/linux/iommu.h +0 -1
index 46e1347bfa22..7cbcf37df8cd 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)
@@ -192,8 +191,14 @@ enum iommu_dev_features {
 	IOMMU_DEV_FEAT_IOPF,
 };
 
Quoted 6 lines

include/linux/iommu.h enum iommu_dev_features { · line 194

Quoted 3 lines
include/linux/iommu.h +1 -2
-#define IOMMU_PASID_INVALID	(-1U)
-
+//#define IOMMU_PASID_INVALID	(-1U)  

Remove this

will do

Quoted 10 lines

include/linux/iommu.h enum iommu_dev_features { · line 201

Quoted 7 lines
include/linux/iommu.h +7 -0
+typedef unsigned int ioasid_t;
+#ifdef CONFIG_IOMMU_SVA
+static inline bool pasid_valid(ioasid_t ioasid)
+{
+	return ioasid != IOMMU_PASID_INVALID;
+}
+#endif  

This isn't specific to SVA, doesn't need an ifdef

until DMA API PASID support is in, this is SVA only? at least on x86?

Quoted 24 lines
Quoted 24 lines
include/linux/iommu.h +0 -0
 #ifdef CONFIG_IOMMU_API
 
 /**
include/linux/sched/mm.h +1 -1
index cdc138086230..4c52835d3359 100644
@@ -8,7 +8,7 @@
 #include <linux/mm_types.h>
 #include <linux/gfp.h>
 #include <linux/sync_core.h>
-#include <linux/ioasid.h>
+#include <uapi/linux/iommu.h>
 
 /*
  * Routines for handling mm_structs
@@ -454,7 +454,7 @@ static inline void

membarrier_update_current_mm(struct mm_struct *next_mm) #ifdef CONFIG_IOMMU_SVA static inline void mm_pasid_init(struct mm_struct *mm)
{

include/linux/sched/mm.h +1 -1
-	mm->pasid = INVALID_IOASID;
+	mm->pasid = IOMMU_PASID_INVALID;
 }
Quoted 12 lines

include/uapi/linux/iommu.h struct iommu_page_response { · line 160

Quoted 10 lines

/* Associate a PASID with an mm_struct: */

include/uapi/linux/iommu.h +1 -0
index 65d8b0234f69..a95f07f0c98c 100644
@@ -157,5 +157,6 @@ struct iommu_page_response {
 	__u32	grpid;
 	__u32	code;
 };
+#define IOMMU_PASID_INVALID	(-1U)  

Why change UAPI?

I ran into circular #include problem if mm.h #include iommu.h, I guess I could also create another header, e.g. iommu_defs.h to avoid it. any other suggestions?
Don't we need this in uapi anyway?

Quoted 14 lines
Quoted 14 lines
include/uapi/linux/iommu.h +0 -0
 #endif /* _UAPI_IOMMU_H */
mm/init-mm.c +1 -1
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>
 
Quoted 13 lines
Quoted 13 lines
mm/init-mm.c +1 -1
 #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

Thanks,

Jacob

#18 lore raw

RE: [PATCH v2 3/3] iommu: Remove ioasid infrastructure

Quoted 19 lines

From: Jacob Pan <[email protected]>
Sent: Wednesday, February 15, 2023 1:05 AM

Hi Jean-Philippe,

Quoted 11 lines · Jean-Philippe Brucker

include/linux/iommu.h enum iommu_dev_features { · line 201

Quoted 7 lines · Jacob Pan
include/linux/iommu.h +7 -0
+typedef unsigned int ioasid_t;
+#ifdef CONFIG_IOMMU_SVA
+static inline bool pasid_valid(ioasid_t ioasid)
+{
+	return ioasid != IOMMU_PASID_INVALID;
+}
+#endif

This isn't specific to SVA, doesn't need an ifdef

Quoted 2 lines

until DMA API PASID support is in, this is SVA only? at least on x86?

the name is pretty generic and it doesn't need SVA specific logic.