^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) #include <linux/mm_types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #include <linux/rbtree.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) #include <linux/rwsem.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/cpumask.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/mman.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/pgtable.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/atomic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/user_namespace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <asm/mmu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #ifndef INIT_MM_CONTEXT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #define INIT_MM_CONTEXT(name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * For dynamically allocated mm_structs, there is a dynamically sized cpumask
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * at the end of the structure, the size of which depends on the maximum CPU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * number the system can see. That way we allocate only as much memory for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * mm_cpumask() as needed for the hundreds, or thousands of processes that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * a system typically runs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * Since there is only one init_mm in the entire system, keep it simple
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * and size this cpu_bitmask to NR_CPUS.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) struct mm_struct init_mm = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) .mm_rb = RB_ROOT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #ifdef CONFIG_SPECULATIVE_PAGE_FAULT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) .mm_rb_lock = __RW_LOCK_UNLOCKED(init_mm.mm_rb_lock),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) .pgd = swapper_pg_dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) .mm_users = ATOMIC_INIT(2),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) .mm_count = ATOMIC_INIT(1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) .write_protect_seq = SEQCNT_ZERO(init_mm.write_protect_seq),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) MMAP_LOCK_INITIALIZER(init_mm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) .page_table_lock = __SPIN_LOCK_UNLOCKED(init_mm.page_table_lock),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) .arg_lock = __SPIN_LOCK_UNLOCKED(init_mm.arg_lock),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) .mmlist = LIST_HEAD_INIT(init_mm.mmlist),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) .user_ns = &init_user_ns,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) .cpu_bitmap = CPU_BITS_NONE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) INIT_MM_CONTEXT(init_mm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) };