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.
Signed-off-by: Jacob Pan <jacob.jun.pan@linux.intel.com>
---
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(-)
diff --git a/drivers/iommu/iommu-sva.c b/drivers/iommu/iommu-sva.c
index 24bf9b2b58aa..fcfdc80a3939 100644
--- a/drivers/iommu/iommu-sva.c
+++ b/drivers/iommu/iommu-sva.c
@@ -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;
+ }
+}
diff --git a/include/linux/ioasid.h b/include/linux/ioasid.h
index af1c9d62e642..2c502e77ee78 100644
--- a/include/linux/ioasid.h
+++ b/include/linux/ioasid.h
@@ -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);
diff --git a/include/linux/iommu-helper.h b/include/linux/iommu-helper.h
index 74be34f3a20a..be1451a05a15 100644
--- a/include/linux/iommu-helper.h
+++ b/include/linux/iommu-helper.h
@@ -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
diff --git a/include/linux/sched/mm.h b/include/linux/sched/mm.h
index 2a243616f222..f341a7a855e8 100644
--- a/include/linux/sched/mm.h
+++ b/include/linux/sched/mm.h
@@ -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 */
--
2.25.1
On 2023-03-09 22:21, Jacob Pan wrote:
> 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.
>
> Signed-off-by: Jacob Pan <jacob.jun.pan@linux.intel.com>
> ---
> 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 ++++++++++++
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.
> include/linux/sched/mm.h | 27 +--------------------------
> 4 files changed, 23 insertions(+), 28 deletions(-)
>
> diff --git a/drivers/iommu/iommu-sva.c b/drivers/iommu/iommu-sva.c
> index 24bf9b2b58aa..fcfdc80a3939 100644
> --- a/drivers/iommu/iommu-sva.c
> +++ b/drivers/iommu/iommu-sva.c
> @@ -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;
> + }
> +}
> diff --git a/include/linux/ioasid.h b/include/linux/ioasid.h
> index af1c9d62e642..2c502e77ee78 100644
> --- a/include/linux/ioasid.h
> +++ b/include/linux/ioasid.h
> @@ -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);
> diff --git a/include/linux/iommu-helper.h b/include/linux/iommu-helper.h
> index 74be34f3a20a..be1451a05a15 100644
> --- a/include/linux/iommu-helper.h
> +++ b/include/linux/iommu-helper.h
> @@ -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
> diff --git a/include/linux/sched/mm.h b/include/linux/sched/mm.h
> index 2a243616f222..f341a7a855e8 100644
> --- a/include/linux/sched/mm.h
> +++ b/include/linux/sched/mm.h
> @@ -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 */
Hi Robin, On Fri, 10 Mar 2023 20:00:52 +0000, Robin Murphy <robin.murphy@arm.com> wrote: > On 2023-03-09 22:21, Jacob Pan wrote: > > 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. > > > > Signed-off-by: Jacob Pan <jacob.jun.pan@linux.intel.com> > > --- > > 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 ++++++++++++ > > 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
On Thu, Mar 09, 2023 at 02:21:54PM -0800, Jacob Pan wrote: > diff --git a/include/linux/sched/mm.h b/include/linux/sched/mm.h > index 2a243616f222..f341a7a855e8 100644 > --- a/include/linux/sched/mm.h > +++ b/include/linux/sched/mm.h > @@ -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
Hi Jason, On Thu, 9 Mar 2023 21:43:44 -0400, Jason Gunthorpe <jgg@nvidia.com> wrote: > On Thu, Mar 09, 2023 at 02:21:54PM -0800, Jacob Pan wrote: > > diff --git a/include/linux/sched/mm.h b/include/linux/sched/mm.h > > index 2a243616f222..f341a7a855e8 100644 > > --- a/include/linux/sched/mm.h > > +++ b/include/linux/sched/mm.h > > @@ -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
© 2016 - 2026 Red Hat, Inc.