Skip to content

Commit a6cbd44

Browse files
Fenghua Yusuryasaimadhu
authored andcommitted
kernel/fork: Initialize mm's PASID
A new mm doesn't have a PASID yet when it's created. Initialize the mm's PASID on fork() or for init_mm to INVALID_IOASID (-1). INIT_PASID (0) is reserved for kernel legacy DMA PASID. It cannot be allocated to a user process. Initializing the process's PASID to 0 may cause confusion that's why the process uses the reserved kernel legacy DMA PASID. Initializing the PASID to INVALID_IOASID (-1) explicitly tells the process doesn't have a valid PASID yet. Even though the only user of mm_pasid_init() is in fork.c, define it in <linux/sched/mm.h> as the first of three mm/pasid life cycle functions (init/set/drop) to keep these all together. Suggested-by: Dave Hansen <dave.hansen@linux.intel.com> Signed-off-by: Fenghua Yu <fenghua.yu@intel.com> Signed-off-by: Borislav Petkov <bp@suse.de> Reviewed-by: Tony Luck <tony.luck@intel.com> Reviewed-by: Thomas Gleixner <tglx@linutronix.de> Link: https://lore.kernel.org/r/20220207230254.3342514-5-fenghua.yu@intel.com
1 parent 7a5fbc9 commit a6cbd44

3 files changed

Lines changed: 16 additions & 8 deletions

File tree

include/linux/sched/mm.h

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

1213
/*
1314
* Routines for handling mm_structs
@@ -433,4 +434,13 @@ static inline void membarrier_update_current_mm(struct mm_struct *next_mm)
433434
}
434435
#endif
435436

437+
#ifdef CONFIG_IOMMU_SVA
438+
static inline void mm_pasid_init(struct mm_struct *mm)
439+
{
440+
mm->pasid = INVALID_IOASID;
441+
}
442+
#else
443+
static inline void mm_pasid_init(struct mm_struct *mm) {}
444+
#endif
445+
436446
#endif /* _LINUX_SCHED_MM_H */

kernel/fork.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
#include <linux/scs.h>
9898
#include <linux/io_uring.h>
9999
#include <linux/bpf.h>
100+
#include <linux/sched/mm.h>
100101

101102
#include <asm/pgalloc.h>
102103
#include <linux/uaccess.h>
@@ -1019,13 +1020,6 @@ static void mm_init_owner(struct mm_struct *mm, struct task_struct *p)
10191020
#endif
10201021
}
10211022

1022-
static void mm_init_pasid(struct mm_struct *mm)
1023-
{
1024-
#ifdef CONFIG_IOMMU_SVA
1025-
mm->pasid = INIT_PASID;
1026-
#endif
1027-
}
1028-
10291023
static void mm_init_uprobes_state(struct mm_struct *mm)
10301024
{
10311025
#ifdef CONFIG_UPROBES
@@ -1054,7 +1048,7 @@ static struct mm_struct *mm_init(struct mm_struct *mm, struct task_struct *p,
10541048
mm_init_cpumask(mm);
10551049
mm_init_aio(mm);
10561050
mm_init_owner(mm, p);
1057-
mm_init_pasid(mm);
1051+
mm_pasid_init(mm);
10581052
RCU_INIT_POINTER(mm->exe_file, NULL);
10591053
mmu_notifier_subscriptions_init(mm);
10601054
init_tlb_flush_pending(mm);

mm/init-mm.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include <linux/atomic.h>
1212
#include <linux/user_namespace.h>
13+
#include <linux/ioasid.h>
1314
#include <asm/mmu.h>
1415

1516
#ifndef INIT_MM_CONTEXT
@@ -38,6 +39,9 @@ struct mm_struct init_mm = {
3839
.mmlist = LIST_HEAD_INIT(init_mm.mmlist),
3940
.user_ns = &init_user_ns,
4041
.cpu_bitmap = CPU_BITS_NONE,
42+
#ifdef CONFIG_IOMMU_SVA
43+
.pasid = INVALID_IOASID,
44+
#endif
4145
INIT_MM_CONTEXT(init_mm)
4246
};
4347

0 commit comments

Comments
 (0)