Skip to content

Commit 400b9b9

Browse files
kirylhansendc
authored andcommitted
iommu/sva: Replace pasid_valid() helper with mm_valid_pasid()
Kernel has few users of pasid_valid() and all but one checks if the process has PASID allocated. The helper takes ioasid_t as the input. Replace the helper with mm_valid_pasid() that takes mm_struct as the argument. The only call that checks PASID that is not tied to mm_struct is open-codded now. This is preparatory patch. It helps avoid ifdeffery: no need to dereference mm->pasid in generic code to check if the process has PASID. Signed-off-by: Kirill A. Shutemov <[email protected]> Signed-off-by: Dave Hansen <[email protected]> Acked-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lore.kernel.org/all/20230312112612.31869-11-kirill.shutemov%40linux.intel.com
1 parent f7d3043 commit 400b9b9

File tree

4 files changed

+12
-15
lines changed

4 files changed

+12
-15
lines changed

arch/x86/kernel/traps.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -671,15 +671,15 @@ static bool try_fixup_enqcmd_gp(void)
671671
if (!cpu_feature_enabled(X86_FEATURE_ENQCMD))
672672
return false;
673673

674-
pasid = current->mm->pasid;
675-
676674
/*
677675
* If the mm has not been allocated a
678676
* PASID, the #GP can not be fixed up.
679677
*/
680-
if (!pasid_valid(pasid))
678+
if (!mm_valid_pasid(current->mm))
681679
return false;
682680

681+
pasid = current->mm->pasid;
682+
683683
/*
684684
* Did this thread already have its PASID activated?
685685
* If so, the #GP must be from something else.

drivers/iommu/iommu-sva.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ int iommu_sva_alloc_pasid(struct mm_struct *mm, ioasid_t min, ioasid_t max)
3434

3535
mutex_lock(&iommu_sva_lock);
3636
/* Is a PASID already associated with this mm? */
37-
if (pasid_valid(mm->pasid)) {
37+
if (mm_valid_pasid(mm)) {
3838
if (mm->pasid < min || mm->pasid >= max)
3939
ret = -EOVERFLOW;
4040
goto out;
4141
}
4242

4343
pasid = ioasid_alloc(&iommu_sva_pasid, min, max, mm);
44-
if (!pasid_valid(pasid))
44+
if (pasid == INVALID_IOASID)
4545
ret = -ENOMEM;
4646
else
4747
mm_pasid_set(mm, pasid);

include/linux/ioasid.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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/sched/mm.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,11 @@ static inline void mm_pasid_init(struct mm_struct *mm)
457457
mm->pasid = INVALID_IOASID;
458458
}
459459

460+
static inline bool mm_valid_pasid(struct mm_struct *mm)
461+
{
462+
return mm->pasid != INVALID_IOASID;
463+
}
464+
460465
/* Associate a PASID with an mm_struct: */
461466
static inline void mm_pasid_set(struct mm_struct *mm, u32 pasid)
462467
{
@@ -465,13 +470,14 @@ static inline void mm_pasid_set(struct mm_struct *mm, u32 pasid)
465470

466471
static inline void mm_pasid_drop(struct mm_struct *mm)
467472
{
468-
if (pasid_valid(mm->pasid)) {
473+
if (mm_valid_pasid(mm)) {
469474
ioasid_free(mm->pasid);
470475
mm->pasid = INVALID_IOASID;
471476
}
472477
}
473478
#else
474479
static inline void mm_pasid_init(struct mm_struct *mm) {}
480+
static inline bool mm_valid_pasid(struct mm_struct *mm) { return false; }
475481
static inline void mm_pasid_set(struct mm_struct *mm, u32 pasid) {}
476482
static inline void mm_pasid_drop(struct mm_struct *mm) {}
477483
#endif

0 commit comments

Comments
 (0)