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