Skip to content

Commit cd38911

Browse files
Jacob Panjoergroedel
authored andcommitted
iommu/sva: Move PASID helpers to sva code
Preparing to remove IOASID infrastructure, PASID management will be under SVA code. Decouple mm code from IOASID. Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Signed-off-by: Jacob Pan <jacob.jun.pan@linux.intel.com> Reviewed-by: Kevin Tian <kevin.tian@intel.com> Link: https://lore.kernel.org/r/20230322200803.869130-3-jacob.jun.pan@linux.intel.com Signed-off-by: Joerg Roedel <jroedel@suse.de>
1 parent 760f41d commit cd38911

5 files changed

Lines changed: 24 additions & 38 deletions

File tree

drivers/iommu/iommu-sva.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ int iommu_sva_alloc_pasid(struct mm_struct *mm, ioasid_t min, ioasid_t max)
4444
if (!pasid_valid(pasid))
4545
ret = -ENOMEM;
4646
else
47-
mm_pasid_set(mm, pasid);
47+
mm->pasid = pasid;
4848
out:
4949
mutex_unlock(&iommu_sva_lock);
5050
return ret;
@@ -238,3 +238,11 @@ iommu_sva_handle_iopf(struct iommu_fault *fault, void *data)
238238

239239
return status;
240240
}
241+
242+
void mm_pasid_drop(struct mm_struct *mm)
243+
{
244+
if (pasid_valid(mm->pasid)) {
245+
ioasid_free(mm->pasid);
246+
mm->pasid = INVALID_IOASID;
247+
}
248+
}

include/linux/ioasid.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
#include <linux/types.h>
66
#include <linux/errno.h>
7+
#include <linux/iommu.h>
78

8-
#define INVALID_IOASID ((ioasid_t)-1)
99
typedef unsigned int ioasid_t;
1010
typedef ioasid_t (*ioasid_alloc_fn_t)(ioasid_t min, ioasid_t max, void *data);
1111
typedef void (*ioasid_free_fn_t)(ioasid_t ioasid, void *data);
@@ -40,10 +40,6 @@ void *ioasid_find(struct ioasid_set *set, ioasid_t ioasid,
4040
int ioasid_register_allocator(struct ioasid_allocator_ops *allocator);
4141
void ioasid_unregister_allocator(struct ioasid_allocator_ops *allocator);
4242
int ioasid_set_data(ioasid_t ioasid, void *data);
43-
static inline bool pasid_valid(ioasid_t ioasid)
44-
{
45-
return ioasid != INVALID_IOASID;
46-
}
4743

4844
#else /* !CONFIG_IOASID */
4945
static inline ioasid_t ioasid_alloc(struct ioasid_set *set, ioasid_t min,
@@ -74,10 +70,5 @@ static inline int ioasid_set_data(ioasid_t ioasid, void *data)
7470
return -ENOTSUPP;
7571
}
7672

77-
static inline bool pasid_valid(ioasid_t ioasid)
78-
{
79-
return false;
80-
}
81-
8273
#endif /* CONFIG_IOASID */
8374
#endif /* __LINUX_IOASID_H */

include/linux/iommu.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include <linux/errno.h>
1414
#include <linux/err.h>
1515
#include <linux/of.h>
16-
#include <linux/ioasid.h>
1716
#include <uapi/linux/iommu.h>
1817

1918
#define IOMMU_READ (1 << 0)
@@ -192,6 +191,8 @@ enum iommu_dev_features {
192191
};
193192

194193
#define IOMMU_PASID_INVALID (-1U)
194+
typedef unsigned int ioasid_t;
195+
#define INVALID_IOASID ((ioasid_t)-1)
195196

196197
#ifdef CONFIG_IOMMU_API
197198

@@ -1172,7 +1173,16 @@ static inline bool tegra_dev_iommu_get_stream_id(struct device *dev, u32 *stream
11721173
return false;
11731174
}
11741175

1176+
static inline bool pasid_valid(ioasid_t ioasid)
1177+
{
1178+
return ioasid != INVALID_IOASID;
1179+
}
11751180
#ifdef CONFIG_IOMMU_SVA
1181+
static inline void mm_pasid_init(struct mm_struct *mm)
1182+
{
1183+
mm->pasid = INVALID_IOASID;
1184+
}
1185+
void mm_pasid_drop(struct mm_struct *mm);
11761186
struct iommu_sva *iommu_sva_bind_device(struct device *dev,
11771187
struct mm_struct *mm);
11781188
void iommu_sva_unbind_device(struct iommu_sva *handle);
@@ -1192,6 +1202,8 @@ static inline u32 iommu_sva_get_pasid(struct iommu_sva *handle)
11921202
{
11931203
return IOMMU_PASID_INVALID;
11941204
}
1205+
static inline void mm_pasid_init(struct mm_struct *mm) {}
1206+
static inline void mm_pasid_drop(struct mm_struct *mm) {}
11951207
#endif /* CONFIG_IOMMU_SVA */
11961208

11971209
#endif /* __LINUX_IOMMU_H */

include/linux/sched/mm.h

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include <linux/mm_types.h>
99
#include <linux/gfp.h>
1010
#include <linux/sync_core.h>
11-
#include <linux/ioasid.h>
1211

1312
/*
1413
* Routines for handling mm_structs
@@ -451,29 +450,4 @@ static inline void membarrier_update_current_mm(struct mm_struct *next_mm)
451450
}
452451
#endif
453452

454-
#ifdef CONFIG_IOMMU_SVA
455-
static inline void mm_pasid_init(struct mm_struct *mm)
456-
{
457-
mm->pasid = INVALID_IOASID;
458-
}
459-
460-
/* Associate a PASID with an mm_struct: */
461-
static inline void mm_pasid_set(struct mm_struct *mm, u32 pasid)
462-
{
463-
mm->pasid = pasid;
464-
}
465-
466-
static inline void mm_pasid_drop(struct mm_struct *mm)
467-
{
468-
if (pasid_valid(mm->pasid)) {
469-
ioasid_free(mm->pasid);
470-
mm->pasid = INVALID_IOASID;
471-
}
472-
}
473-
#else
474-
static inline void mm_pasid_init(struct mm_struct *mm) {}
475-
static inline void mm_pasid_set(struct mm_struct *mm, u32 pasid) {}
476-
static inline void mm_pasid_drop(struct mm_struct *mm) {}
477-
#endif
478-
479453
#endif /* _LINUX_SCHED_MM_H */

kernel/fork.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
#include <linux/io_uring.h>
9898
#include <linux/bpf.h>
9999
#include <linux/stackprotector.h>
100+
#include <linux/iommu.h>
100101

101102
#include <asm/pgalloc.h>
102103
#include <linux/uaccess.h>

0 commit comments

Comments
 (0)