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>
13 #include <linux/audit.h>
14 #include <linux/numa.h>
15 #include <linux/scs.h>
16 #include <linux/plist.h>
18 #include <linux/uaccess.h>
20 static struct signal_struct init_signals
= {
22 .thread_head
= LIST_HEAD_INIT(init_task
.thread_node
),
23 .wait_chldexit
= __WAIT_QUEUE_HEAD_INITIALIZER(init_signals
.wait_chldexit
),
25 .list
= LIST_HEAD_INIT(init_signals
.shared_pending
.list
),
28 .multiprocess
= HLIST_HEAD_INIT
,
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
,
36 .cputime_atomic
= INIT_CPUTIME_ATOMIC
,
39 INIT_CPU_TIMERS(init_signals
)
41 [PIDTYPE_PID
] = &init_struct_pid
,
42 [PIDTYPE_TGID
] = &init_struct_pid
,
43 [PIDTYPE_PGID
] = &init_struct_pid
,
44 [PIDTYPE_SID
] = &init_struct_pid
,
46 INIT_PREV_CPUTIME(init_signals
)
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
),
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
63 * Set up the first task table, touch at your own risk!. Base=0,
64 * limit=0x1fffff (=2MB)
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),
73 .usage
= REFCOUNT_INIT(2),
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
,
85 .active_mm
= &init_mm
,
86 .faults_disabled_mapping
= NULL
,
88 .fn
= do_no_restart_syscall
,
91 .group_node
= LIST_HEAD_INIT(init_task
.se
.group_node
),
94 .run_list
= LIST_HEAD_INIT(init_task
.rt
.run_list
),
95 .time_slice
= RR_TIMESLICE
,
97 .tasks
= LIST_HEAD_INIT(init_task
.tasks
),
99 .pushable_tasks
= PLIST_NODE_INIT(init_task
.pushable_tasks
, MAX_PRIO
),
101 #ifdef CONFIG_CGROUP_SCHED
102 .sched_task_group
= &root_task_group
,
104 #ifdef CONFIG_SCHED_CLASS_EXT
106 .dsq_list
.node
= LIST_HEAD_INIT(init_task
.scx
.dsq_list
.node
),
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
,
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
,
127 .files
= &init_files
,
128 #ifdef CONFIG_IO_URING
131 .signal
= &init_signals
,
132 .sighand
= &init_sighand
,
133 .nsproxy
= &init_nsproxy
,
135 .list
= LIST_HEAD_INIT(init_task
.pending
.list
),
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
),
147 .loginuid
= INVALID_UID
,
148 .sessionid
= AUDIT_SID_UNSET
,
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
),
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
,
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
),
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
),
172 #ifdef CONFIG_CPUSETS
173 .mems_allowed_seq
= SEQCNT_SPINLOCK_ZERO(init_task
.mems_allowed_seq
,
174 &init_task
.alloc_lock
),
176 #ifdef CONFIG_RT_MUTEXES
177 .pi_waiters
= RB_ROOT_CACHED
,
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
,
186 #ifdef CONFIG_NUMA_BALANCING
187 .numa_preferred_nid
= NUMA_NO_NODE
,
191 #if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)
196 .scoped_accesses
= {LIST_POISON1
, NULL
},
199 #ifdef CONFIG_TRACE_IRQFLAGS
200 .softirqs_enabled
= 1,
202 #ifdef CONFIG_LOCKDEP
203 .lockdep_depth
= 0, /* no locks held yet */
204 .curr_chain_key
= INITIAL_CHAIN_KEY
,
205 .lockdep_recursion
= 0,
207 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
209 .tracing_graph_pause
= ATOMIC_INIT(0),
211 #if defined(CONFIG_TRACING) && defined(CONFIG_PREEMPTION)
212 .trace_recursion
= 0,
214 #ifdef CONFIG_LIVEPATCH
215 .patch_state
= KLP_TRANSITION_IDLE
,
217 #ifdef CONFIG_SECURITY
220 #ifdef CONFIG_SECCOMP_FILTER
221 .seccomp
= { .filter_count
= ATOMIC_INIT(0) },
224 EXPORT_SYMBOL(init_task
);
227 * Initial thread structure. Alignment of this is handled by a special
230 #ifndef CONFIG_THREAD_INFO_IN_TASK
231 struct thread_info init_thread_info __init_thread_info
= INIT_THREAD_INFO(init_task
);