blob: efa97b57acfd888a0e5db8b1e34cc4dcc20da70c [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Alexey Dobriyanbb1f17b2009-06-16 15:31:18 -07002#include <linux/mm_types.h>
Liam R. Howlettd4af56c2022-09-06 19:48:45 +00003#include <linux/maple_tree.h>
Alexey Dobriyanbb1f17b2009-06-16 15:31:18 -07004#include <linux/rwsem.h>
5#include <linux/spinlock.h>
6#include <linux/list.h>
7#include <linux/cpumask.h>
Ben Dooks (Codethink)a2ae8c02019-10-18 20:20:24 -07008#include <linux/mman.h>
Mike Rapoport65fddcf2020-06-08 21:32:42 -07009#include <linux/pgtable.h>
Alexey Dobriyanbb1f17b2009-06-16 15:31:18 -070010
Arun Sharma600634972011-07-26 16:09:06 -070011#include <linux/atomic.h>
Eric W. Biedermanbfedb582016-10-13 21:23:16 -050012#include <linux/user_namespace.h>
Jacob Panfffaed12023-03-22 13:08:02 -070013#include <linux/iommu.h>
Heiko Carstensa1b200e2010-08-09 17:18:28 -070014#include <asm/mmu.h>
15
16#ifndef INIT_MM_CONTEXT
17#define INIT_MM_CONTEXT(name)
18#endif
Alexey Dobriyanbb1f17b2009-06-16 15:31:18 -070019
Rik van Rielc1a2f7f2018-07-16 15:03:31 -040020/*
21 * For dynamically allocated mm_structs, there is a dynamically sized cpumask
22 * at the end of the structure, the size of which depends on the maximum CPU
23 * number the system can see. That way we allocate only as much memory for
24 * mm_cpumask() as needed for the hundreds, or thousands of processes that
25 * a system typically runs.
26 *
27 * Since there is only one init_mm in the entire system, keep it simple
28 * and size this cpu_bitmask to NR_CPUS.
29 */
Alexey Dobriyanbb1f17b2009-06-16 15:31:18 -070030struct mm_struct init_mm = {
Liam R. Howlettd4af56c2022-09-06 19:48:45 +000031 .mm_mt = MTREE_INIT_EXT(mm_mt, MM_MT_FLAGS, init_mm.mmap_lock),
Alexey Dobriyanbb1f17b2009-06-16 15:31:18 -070032 .pgd = swapper_pg_dir,
33 .mm_users = ATOMIC_INIT(2),
34 .mm_count = ATOMIC_INIT(1),
Jason Gunthorpe57efa1f2020-12-14 19:05:44 -080035 .write_protect_seq = SEQCNT_ZERO(init_mm.write_protect_seq),
Michel Lespinasse14c36562020-06-08 21:33:40 -070036 MMAP_LOCK_INITIALIZER(init_mm)
Alexey Dobriyanbb1f17b2009-06-16 15:31:18 -070037 .page_table_lock = __SPIN_LOCK_UNLOCKED(init_mm.page_table_lock),
Yang Shi88aa7cc2018-06-07 17:05:28 -070038 .arg_lock = __SPIN_LOCK_UNLOCKED(init_mm.arg_lock),
Alexey Dobriyanbb1f17b2009-06-16 15:31:18 -070039 .mmlist = LIST_HEAD_INIT(init_mm.mmlist),
Suren Baghdasaryan5e312752023-02-27 09:36:11 -080040#ifdef CONFIG_PER_VMA_LOCK
41 .mm_lock_seq = 0,
42#endif
Eric W. Biedermanbfedb582016-10-13 21:23:16 -050043 .user_ns = &init_user_ns,
Mike Rapoport2286bf42019-09-23 15:36:45 -070044 .cpu_bitmap = CPU_BITS_NONE,
Fenghua Yua6cbd442022-02-07 15:02:47 -080045#ifdef CONFIG_IOMMU_SVA
Jacob Panfffaed12023-03-22 13:08:02 -070046 .pasid = IOMMU_PASID_INVALID,
Fenghua Yua6cbd442022-02-07 15:02:47 -080047#endif
Heiko Carstensa1b200e2010-08-09 17:18:28 -070048 INIT_MM_CONTEXT(init_mm)
Alexey Dobriyanbb1f17b2009-06-16 15:31:18 -070049};
Kefeng Wang5748fbc2021-07-07 18:08:22 -070050
51void setup_initial_init_mm(void *start_code, void *end_code,
52 void *end_data, void *brk)
53{
54 init_mm.start_code = (unsigned long)start_code;
55 init_mm.end_code = (unsigned long)end_code;
56 init_mm.end_data = (unsigned long)end_data;
57 init_mm.brk = (unsigned long)brk;
58}