1 // SPDX-License-Identifier: GPL-2.0 2 #include <linux/init_task.h> 3 #include <linux/export.h> 4 #include <linux/mqueue.h> 5 #include <linux/sched.h> 6 #include <linux/sched/sysctl.h> 7 #include <linux/sched/rt.h> 8 #include <linux/sched/task.h> 9 #include <linux/sched/ext.h> 10 #include <linux/sched/exec_state.h> 11 #include <linux/user_namespace.h> 12 #include <linux/init.h> 13 #include <linux/fs.h> 14 #include <linux/mm.h> 15 #include <linux/audit.h> 16 #include <linux/numa.h> 17 #include <linux/scs.h> 18 #include <linux/plist.h> 19 20 #include <linux/uaccess.h> 21 22 static struct signal_struct init_signals = { 23 .nr_threads = 1, 24 .thread_head = LIST_HEAD_INIT(init_task.thread_node), 25 .wait_chldexit = __WAIT_QUEUE_HEAD_INITIALIZER(init_signals.wait_chldexit), 26 .shared_pending = { 27 .list = LIST_HEAD_INIT(init_signals.shared_pending.list), 28 .signal = {{0}} 29 }, 30 .multiprocess = HLIST_HEAD_INIT, 31 .rlim = INIT_RLIMITS, 32 #ifdef CONFIG_CGROUPS 33 .cgroup_threadgroup_rwsem = __RWSEM_INITIALIZER(init_signals.cgroup_threadgroup_rwsem), 34 #endif 35 .cred_guard_mutex = __MUTEX_INITIALIZER(init_signals.cred_guard_mutex), 36 .exec_update_lock = __RWSEM_INITIALIZER(init_signals.exec_update_lock), 37 #ifdef CONFIG_POSIX_TIMERS 38 .posix_timers = HLIST_HEAD_INIT, 39 .ignored_posix_timers = HLIST_HEAD_INIT, 40 .cputimer = { 41 .cputime_atomic = INIT_CPUTIME_ATOMIC, 42 }, 43 #endif 44 INIT_CPU_TIMERS(init_signals) 45 .pids = { 46 [PIDTYPE_PID] = &init_struct_pid, 47 [PIDTYPE_TGID] = &init_struct_pid, 48 [PIDTYPE_PGID] = &init_struct_pid, 49 [PIDTYPE_SID] = &init_struct_pid, 50 }, 51 INIT_PREV_CPUTIME(init_signals) 52 }; 53 54 static struct sighand_struct init_sighand = { 55 .count = REFCOUNT_INIT(1), 56 .action = { { { .sa_handler = SIG_DFL, } }, }, 57 .siglock = __SPIN_LOCK_UNLOCKED(init_sighand.siglock), 58 .signalfd_wqh = __WAIT_QUEUE_HEAD_INITIALIZER(init_sighand.signalfd_wqh), 59 }; 60 61 /* init to 2 - one for init_task, one to ensure it is never freed */ 62 struct task_exec_state init_task_exec_state = { 63 .count = REFCOUNT_INIT(2), 64 .dumpable = TASK_DUMPABLE_OWNER, 65 .user_ns = &init_user_ns, 66 }; 67 68 #ifdef CONFIG_SHADOW_CALL_STACK 69 unsigned long init_shadow_call_stack[SCS_SIZE / sizeof(long)] = { 70 [(SCS_SIZE / sizeof(long)) - 1] = SCS_END_MAGIC 71 }; 72 #endif 73 74 /* init to 2 - one for init_task, one to ensure it is never freed */ 75 static struct group_info init_groups = { .usage = REFCOUNT_INIT(2) }; 76 77 /* 78 * The initial credentials for the initial task 79 */ 80 static struct cred init_cred = { 81 .usage = ATOMIC_INIT(4), 82 .uid = GLOBAL_ROOT_UID, 83 .gid = GLOBAL_ROOT_GID, 84 .suid = GLOBAL_ROOT_UID, 85 .sgid = GLOBAL_ROOT_GID, 86 .euid = GLOBAL_ROOT_UID, 87 .egid = GLOBAL_ROOT_GID, 88 .fsuid = GLOBAL_ROOT_UID, 89 .fsgid = GLOBAL_ROOT_GID, 90 .securebits = SECUREBITS_DEFAULT, 91 .cap_inheritable = CAP_EMPTY_SET, 92 .cap_permitted = CAP_FULL_SET, 93 .cap_effective = CAP_FULL_SET, 94 .cap_bset = CAP_FULL_SET, 95 .user = INIT_USER, 96 .user_ns = &init_user_ns, 97 .group_info = &init_groups, 98 .ucounts = &init_ucounts, 99 }; 100 101 /* 102 * Set up the first task table, touch at your own risk!. Base=0, 103 * limit=0x1fffff (=2MB) 104 */ 105 struct task_struct init_task __aligned(L1_CACHE_BYTES) = { 106 #ifdef CONFIG_THREAD_INFO_IN_TASK 107 .thread_info = INIT_THREAD_INFO(init_task), 108 .stack_refcount = REFCOUNT_INIT(1), 109 #endif 110 .__state = 0, 111 .stack = init_stack, 112 .usage = REFCOUNT_INIT(2), 113 .flags = PF_KTHREAD, 114 .prio = MAX_PRIO - 20, 115 .static_prio = MAX_PRIO - 20, 116 .normal_prio = MAX_PRIO - 20, 117 .policy = SCHED_NORMAL, 118 .cpus_ptr = &init_task.cpus_mask, 119 .user_cpus_ptr = NULL, 120 .cpus_mask = CPU_MASK_ALL, 121 .max_allowed_capacity = SCHED_CAPACITY_SCALE, 122 .nr_cpus_allowed= NR_CPUS, 123 .mm = NULL, 124 .active_mm = &init_mm, 125 .exec_state = &init_task_exec_state, 126 .restart_block = { 127 .fn = do_no_restart_syscall, 128 }, 129 .se = { 130 .group_node = LIST_HEAD_INIT(init_task.se.group_node), 131 }, 132 .rt = { 133 .run_list = LIST_HEAD_INIT(init_task.rt.run_list), 134 .time_slice = RR_TIMESLICE, 135 }, 136 .tasks = LIST_HEAD_INIT(init_task.tasks), 137 #ifdef CONFIG_SMP 138 .pushable_tasks = PLIST_NODE_INIT(init_task.pushable_tasks, MAX_PRIO), 139 #endif 140 #ifdef CONFIG_CGROUP_SCHED 141 .sched_task_group = &root_task_group, 142 #endif 143 #ifdef CONFIG_SCHED_CLASS_EXT 144 .scx = { 145 .dsq_list.node = LIST_HEAD_INIT(init_task.scx.dsq_list.node), 146 .sticky_cpu = -1, 147 .holding_cpu = -1, 148 .runnable_node = LIST_HEAD_INIT(init_task.scx.runnable_node), 149 .runnable_at = INITIAL_JIFFIES, 150 .ddsp_dsq_id = SCX_DSQ_INVALID, 151 .slice = SCX_SLICE_DFL, 152 }, 153 #endif 154 .ptraced = LIST_HEAD_INIT(init_task.ptraced), 155 .ptrace_entry = LIST_HEAD_INIT(init_task.ptrace_entry), 156 .real_parent = &init_task, 157 .parent = &init_task, 158 .children = LIST_HEAD_INIT(init_task.children), 159 .sibling = LIST_HEAD_INIT(init_task.sibling), 160 .group_leader = &init_task, 161 RCU_POINTER_INITIALIZER(real_cred, &init_cred), 162 RCU_POINTER_INITIALIZER(cred, &init_cred), 163 .comm = INIT_TASK_COMM, 164 .thread = INIT_THREAD, 165 .real_fs = &init_fs, 166 .fs = &init_fs, 167 .files = &init_files, 168 #ifdef CONFIG_IO_URING 169 .io_uring = NULL, 170 #endif 171 .signal = &init_signals, 172 .sighand = &init_sighand, 173 .nsproxy = &init_nsproxy, 174 .pending = { 175 .list = LIST_HEAD_INIT(init_task.pending.list), 176 .signal = {{0}} 177 }, 178 .blocked = {{0}}, 179 .alloc_lock = __SPIN_LOCK_UNLOCKED(init_task.alloc_lock), 180 .journal_info = NULL, 181 INIT_CPU_TIMERS(init_task) 182 .pi_lock = __RAW_SPIN_LOCK_UNLOCKED(init_task.pi_lock), 183 .blocked_lock = __RAW_SPIN_LOCK_UNLOCKED(init_task.blocked_lock), 184 .timer_slack_ns = 50000, /* 50 usec default slack */ 185 .thread_pid = &init_struct_pid, 186 .thread_node = LIST_HEAD_INIT(init_signals.thread_head), 187 #ifdef CONFIG_AUDIT 188 .loginuid = INVALID_UID, 189 .sessionid = AUDIT_SID_UNSET, 190 #endif 191 #ifdef CONFIG_PERF_EVENTS 192 .perf_event_mutex = __MUTEX_INITIALIZER(init_task.perf_event_mutex), 193 .perf_event_list = LIST_HEAD_INIT(init_task.perf_event_list), 194 #endif 195 #ifdef CONFIG_PREEMPT_RCU 196 .rcu_read_lock_nesting = 0, 197 .rcu_read_unlock_special.s = 0, 198 .rcu_node_entry = LIST_HEAD_INIT(init_task.rcu_node_entry), 199 .rcu_blocked_node = NULL, 200 #endif 201 #ifdef CONFIG_TASKS_RCU 202 .rcu_tasks_holdout = false, 203 .rcu_tasks_holdout_list = LIST_HEAD_INIT(init_task.rcu_tasks_holdout_list), 204 .rcu_tasks_idle_cpu = -1, 205 .rcu_tasks_exit_list = LIST_HEAD_INIT(init_task.rcu_tasks_exit_list), 206 #endif 207 #ifdef CONFIG_TASKS_TRACE_RCU 208 .trc_reader_nesting = 0, 209 #endif 210 #ifdef CONFIG_CPUSETS 211 .mems_allowed_seq = SEQCNT_SPINLOCK_ZERO(init_task.mems_allowed_seq, 212 &init_task.alloc_lock), 213 #endif 214 .blocked_donor = NULL, 215 #ifdef CONFIG_RT_MUTEXES 216 .pi_waiters = RB_ROOT_CACHED, 217 .pi_top_task = NULL, 218 #endif 219 INIT_PREV_CPUTIME(init_task) 220 #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN 221 .vtime.seqcount = SEQCNT_ZERO(init_task.vtime_seqcount), 222 .vtime.starttime = 0, 223 .vtime.state = VTIME_SYS, 224 #endif 225 #ifdef CONFIG_NUMA_BALANCING 226 .numa_preferred_nid = NUMA_NO_NODE, 227 .numa_group = NULL, 228 .numa_faults = NULL, 229 #endif 230 #ifdef CONFIG_SCHED_CACHE 231 .preferred_llc = -1, 232 .pref_llc_queued = 0, 233 #endif 234 #if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) 235 .kasan_depth = 1, 236 #endif 237 #ifdef CONFIG_KCSAN 238 .kcsan_ctx = { 239 .scoped_accesses = {LIST_POISON1, NULL}, 240 }, 241 #endif 242 #ifdef CONFIG_TRACE_IRQFLAGS 243 .softirqs_enabled = 1, 244 #endif 245 #ifdef CONFIG_LOCKDEP 246 .lockdep_depth = 0, /* no locks held yet */ 247 .curr_chain_key = INITIAL_CHAIN_KEY, 248 .lockdep_recursion = 0, 249 #endif 250 #ifdef CONFIG_FUNCTION_GRAPH_TRACER 251 .ret_stack = NULL, 252 .tracing_graph_pause = ATOMIC_INIT(0), 253 #endif 254 #if defined(CONFIG_TRACING) && defined(CONFIG_PREEMPTION) 255 .trace_recursion = 0, 256 #endif 257 #ifdef CONFIG_LIVEPATCH 258 .patch_state = KLP_TRANSITION_IDLE, 259 #endif 260 #ifdef CONFIG_SECURITY 261 .security = NULL, 262 #endif 263 #ifdef CONFIG_SECCOMP_FILTER 264 .seccomp = { .filter_count = ATOMIC_INIT(0) }, 265 #endif 266 #ifdef CONFIG_SCHED_MM_CID 267 .mm_cid = { .cid = MM_CID_UNSET, }, 268 #endif 269 }; 270 EXPORT_SYMBOL(init_task); 271 272 /* 273 * Initial thread structure. Alignment of this is handled by a special 274 * linker map entry. 275 */ 276 #ifndef CONFIG_THREAD_INFO_IN_TASK 277 struct thread_info init_thread_info __init_thread_info = INIT_THREAD_INFO(init_task); 278 #endif 279