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