projects/linux·blob v7.3-rc2 · refs

279 lines · 7.8 KiB

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
22static 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
54static 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 */
62struct 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
69unsigned 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 */
75static struct group_info init_groups = { .usage = REFCOUNT_INIT(2) };
76
77/*
78 * The initial credentials for the initial task
79 */
80static 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 */
105struct 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_cpu = -1,
149 .runnable_node = LIST_HEAD_INIT(init_task.scx.runnable_node),
150 .runnable_at = INITIAL_JIFFIES,
151 .ddsp_dsq_id = SCX_DSQ_INVALID,
152 .slice = SCX_SLICE_DFL,
153 },
154#endif
155 .ptraced = LIST_HEAD_INIT(init_task.ptraced),
156 .ptrace_entry = LIST_HEAD_INIT(init_task.ptrace_entry),
157 .real_parent = &init_task,
158 .parent = &init_task,
159 .children = LIST_HEAD_INIT(init_task.children),
160 .sibling = LIST_HEAD_INIT(init_task.sibling),
161 .group_leader = &init_task,
162 RCU_POINTER_INITIALIZER(real_cred, &init_cred),
163 RCU_POINTER_INITIALIZER(cred, &init_cred),
164 .comm = INIT_TASK_COMM,
165 .thread = INIT_THREAD,
166 .real_fs = &init_fs,
167 .fs = &init_fs,
168 .files = &init_files,
169#ifdef CONFIG_IO_URING
170 .io_uring = NULL,
171#endif
172 .signal = &init_signals,
173 .sighand = &init_sighand,
174 .nsproxy = &init_nsproxy,
175 .pending = {
176 .list = LIST_HEAD_INIT(init_task.pending.list),
177 .signal = {{0}}
178 },
179 .blocked = {{0}},
180 .alloc_lock = __SPIN_LOCK_UNLOCKED(init_task.alloc_lock),
181 .journal_info = NULL,
182 INIT_CPU_TIMERS(init_task)
183 .pi_lock = __RAW_SPIN_LOCK_UNLOCKED(init_task.pi_lock),
184 .blocked_lock = __RAW_SPIN_LOCK_UNLOCKED(init_task.blocked_lock),
185 .timer_slack_ns = 50000, /* 50 usec default slack */
186 .thread_pid = &init_struct_pid,
187 .thread_node = LIST_HEAD_INIT(init_signals.thread_head),
188#ifdef CONFIG_AUDIT
189 .loginuid = INVALID_UID,
190 .sessionid = AUDIT_SID_UNSET,
191#endif
192#ifdef CONFIG_PERF_EVENTS
193 .perf_event_mutex = __MUTEX_INITIALIZER(init_task.perf_event_mutex),
194 .perf_event_list = LIST_HEAD_INIT(init_task.perf_event_list),
195#endif
196#ifdef CONFIG_PREEMPT_RCU
197 .rcu_read_lock_nesting = 0,
198 .rcu_read_unlock_special.s = 0,
199 .rcu_node_entry = LIST_HEAD_INIT(init_task.rcu_node_entry),
200 .rcu_blocked_node = NULL,
201#endif
202#ifdef CONFIG_TASKS_RCU
203 .rcu_tasks_holdout = false,
204 .rcu_tasks_holdout_list = LIST_HEAD_INIT(init_task.rcu_tasks_holdout_list),
205 .rcu_tasks_idle_cpu = -1,
206 .rcu_tasks_exit_list = LIST_HEAD_INIT(init_task.rcu_tasks_exit_list),
207#endif
208#ifdef CONFIG_TASKS_TRACE_RCU
209 .trc_reader_nesting = 0,
210#endif
211#ifdef CONFIG_CPUSETS
212 .mems_allowed_seq = SEQCNT_SPINLOCK_ZERO(init_task.mems_allowed_seq,
213 &init_task.alloc_lock),
214#endif
215 .blocked_donor = NULL,
216#ifdef CONFIG_RT_MUTEXES
217 .pi_waiters = RB_ROOT_CACHED,
218 .pi_top_task = NULL,
219#endif
220 INIT_PREV_CPUTIME(init_task)
221#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
222 .vtime.seqcount = SEQCNT_ZERO(init_task.vtime_seqcount),
223 .vtime.starttime = 0,
224 .vtime.state = VTIME_SYS,
225#endif
226#ifdef CONFIG_NUMA_BALANCING
227 .numa_preferred_nid = NUMA_NO_NODE,
228 .numa_group = NULL,
229 .numa_faults = NULL,
230#endif
231#ifdef CONFIG_SCHED_CACHE
232 .preferred_llc = -1,
233 .pref_llc_queued = 0,
234#endif
235#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)
236 .kasan_depth = 1,
237#endif
238#ifdef CONFIG_KCSAN
239 .kcsan_ctx = {
240 .scoped_accesses = {LIST_POISON1, NULL},
241 },
242#endif
243#ifdef CONFIG_TRACE_IRQFLAGS
244 .softirqs_enabled = 1,
245#endif
246#ifdef CONFIG_LOCKDEP
247 .lockdep_depth = 0, /* no locks held yet */
248 .curr_chain_key = INITIAL_CHAIN_KEY,
249 .lockdep_recursion = 0,
250#endif
251#ifdef CONFIG_FUNCTION_GRAPH_TRACER
252 .ret_stack = NULL,
253 .tracing_graph_pause = ATOMIC_INIT(0),
254#endif
255#if defined(CONFIG_TRACING) && defined(CONFIG_PREEMPTION)
256 .trace_recursion = 0,
257#endif
258#ifdef CONFIG_LIVEPATCH
259 .patch_state = KLP_TRANSITION_IDLE,
260#endif
261#ifdef CONFIG_SECURITY
262 .security = NULL,
263#endif
264#ifdef CONFIG_SECCOMP_FILTER
265 .seccomp = { .filter_count = ATOMIC_INIT(0) },
266#endif
267#ifdef CONFIG_SCHED_MM_CID
268 .mm_cid = { .cid = MM_CID_UNSET, },
269#endif
270};
271EXPORT_SYMBOL(init_task);
272
273/*
274 * Initial thread structure. Alignment of this is handled by a special
275 * linker map entry.
276 */
277#ifndef CONFIG_THREAD_INFO_IN_TASK
278struct thread_info init_thread_info __init_thread_info = INIT_THREAD_INFO(init_task);
279#endif