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
,
35 .cputime_atomic
= INIT_CPUTIME_ATOMIC
,
38 INIT_CPU_TIMERS(init_signals
)
40 [PIDTYPE_PID
] = &init_struct_pid
,
41 [PIDTYPE_TGID
] = &init_struct_pid
,
42 [PIDTYPE_PGID
] = &init_struct_pid
,
43 [PIDTYPE_SID
] = &init_struct_pid
,
45 INIT_PREV_CPUTIME(init_signals
)
48 static struct sighand_struct init_sighand
= {
49 .count
= REFCOUNT_INIT(1),
50 .action
= { { { .sa_handler
= SIG_DFL
, } }, },
51 .siglock
= __SPIN_LOCK_UNLOCKED(init_sighand
.siglock
),
52 .signalfd_wqh
= __WAIT_QUEUE_HEAD_INITIALIZER(init_sighand
.signalfd_wqh
),
55 #ifdef CONFIG_SHADOW_CALL_STACK
56 unsigned long init_shadow_call_stack
[SCS_SIZE
/ sizeof(long)] = {
57 [(SCS_SIZE
/ sizeof(long)) - 1] = SCS_END_MAGIC
62 * Set up the first task table, touch at your own risk!. Base=0,
63 * limit=0x1fffff (=2MB)
65 struct task_struct init_task
__aligned(L1_CACHE_BYTES
) = {
66 #ifdef CONFIG_THREAD_INFO_IN_TASK
67 .thread_info
= INIT_THREAD_INFO(init_task
),
68 .stack_refcount
= REFCOUNT_INIT(1),
72 .usage
= REFCOUNT_INIT(2),
74 .prio
= MAX_PRIO
- 20,
75 .static_prio
= MAX_PRIO
- 20,
76 .normal_prio
= MAX_PRIO
- 20,
77 .policy
= SCHED_NORMAL
,
78 .cpus_ptr
= &init_task
.cpus_mask
,
79 .user_cpus_ptr
= NULL
,
80 .cpus_mask
= CPU_MASK_ALL
,
81 .max_allowed_capacity
= SCHED_CAPACITY_SCALE
,
82 .nr_cpus_allowed
= NR_CPUS
,
84 .active_mm
= &init_mm
,
85 .faults_disabled_mapping
= NULL
,
87 .fn
= do_no_restart_syscall
,
90 .group_node
= LIST_HEAD_INIT(init_task
.se
.group_node
),
93 .run_list
= LIST_HEAD_INIT(init_task
.rt
.run_list
),
94 .time_slice
= RR_TIMESLICE
,
96 .tasks
= LIST_HEAD_INIT(init_task
.tasks
),
98 .pushable_tasks
= PLIST_NODE_INIT(init_task
.pushable_tasks
, MAX_PRIO
),
100 #ifdef CONFIG_CGROUP_SCHED
101 .sched_task_group
= &root_task_group
,
103 #ifdef CONFIG_SCHED_CLASS_EXT
105 .dsq_list
.node
= LIST_HEAD_INIT(init_task
.scx
.dsq_list
.node
),
108 .runnable_node
= LIST_HEAD_INIT(init_task
.scx
.runnable_node
),
109 .runnable_at
= INITIAL_JIFFIES
,
110 .ddsp_dsq_id
= SCX_DSQ_INVALID
,
111 .slice
= SCX_SLICE_DFL
,
114 .ptraced
= LIST_HEAD_INIT(init_task
.ptraced
),
115 .ptrace_entry
= LIST_HEAD_INIT(init_task
.ptrace_entry
),
116 .real_parent
= &init_task
,
117 .parent
= &init_task
,
118 .children
= LIST_HEAD_INIT(init_task
.children
),
119 .sibling
= LIST_HEAD_INIT(init_task
.sibling
),
120 .group_leader
= &init_task
,
121 RCU_POINTER_INITIALIZER(real_cred
, &init_cred
),
122 RCU_POINTER_INITIALIZER(cred
, &init_cred
),
123 .comm
= INIT_TASK_COMM
,
124 .thread
= INIT_THREAD
,
126 .files
= &init_files
,
127 #ifdef CONFIG_IO_URING
130 .signal
= &init_signals
,
131 .sighand
= &init_sighand
,
132 .nsproxy
= &init_nsproxy
,
134 .list
= LIST_HEAD_INIT(init_task
.pending
.list
),
138 .alloc_lock
= __SPIN_LOCK_UNLOCKED(init_task
.alloc_lock
),
139 .journal_info
= NULL
,
140 INIT_CPU_TIMERS(init_task
)
141 .pi_lock
= __RAW_SPIN_LOCK_UNLOCKED(init_task
.pi_lock
),
142 .timer_slack_ns
= 50000, /* 50 usec default slack */
143 .thread_pid
= &init_struct_pid
,
144 .thread_node
= LIST_HEAD_INIT(init_signals
.thread_head
),
146 .loginuid
= INVALID_UID
,
147 .sessionid
= AUDIT_SID_UNSET
,
149 #ifdef CONFIG_PERF_EVENTS
150 .perf_event_mutex
= __MUTEX_INITIALIZER(init_task
.perf_event_mutex
),
151 .perf_event_list
= LIST_HEAD_INIT(init_task
.perf_event_list
),
153 #ifdef CONFIG_PREEMPT_RCU
154 .rcu_read_lock_nesting
= 0,
155 .rcu_read_unlock_special
.s
= 0,
156 .rcu_node_entry
= LIST_HEAD_INIT(init_task
.rcu_node_entry
),
157 .rcu_blocked_node
= NULL
,
159 #ifdef CONFIG_TASKS_RCU
160 .rcu_tasks_holdout
= false,
161 .rcu_tasks_holdout_list
= LIST_HEAD_INIT(init_task
.rcu_tasks_holdout_list
),
162 .rcu_tasks_idle_cpu
= -1,
163 .rcu_tasks_exit_list
= LIST_HEAD_INIT(init_task
.rcu_tasks_exit_list
),
165 #ifdef CONFIG_TASKS_TRACE_RCU
166 .trc_reader_nesting
= 0,
167 .trc_reader_special
.s
= 0,
168 .trc_holdout_list
= LIST_HEAD_INIT(init_task
.trc_holdout_list
),
169 .trc_blkd_node
= LIST_HEAD_INIT(init_task
.trc_blkd_node
),
171 #ifdef CONFIG_CPUSETS
172 .mems_allowed_seq
= SEQCNT_SPINLOCK_ZERO(init_task
.mems_allowed_seq
,
173 &init_task
.alloc_lock
),
175 #ifdef CONFIG_RT_MUTEXES
176 .pi_waiters
= RB_ROOT_CACHED
,
179 INIT_PREV_CPUTIME(init_task
)
180 #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
181 .vtime
.seqcount
= SEQCNT_ZERO(init_task
.vtime_seqcount
),
182 .vtime
.starttime
= 0,
183 .vtime
.state
= VTIME_SYS
,
185 #ifdef CONFIG_NUMA_BALANCING
186 .numa_preferred_nid
= NUMA_NO_NODE
,
190 #if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)
195 .scoped_accesses
= {LIST_POISON1
, NULL
},
198 #ifdef CONFIG_TRACE_IRQFLAGS
199 .softirqs_enabled
= 1,
201 #ifdef CONFIG_LOCKDEP
202 .lockdep_depth
= 0, /* no locks held yet */
203 .curr_chain_key
= INITIAL_CHAIN_KEY
,
204 .lockdep_recursion
= 0,
206 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
208 .tracing_graph_pause
= ATOMIC_INIT(0),
210 #if defined(CONFIG_TRACING) && defined(CONFIG_PREEMPTION)
211 .trace_recursion
= 0,
213 #ifdef CONFIG_LIVEPATCH
214 .patch_state
= KLP_TRANSITION_IDLE
,
216 #ifdef CONFIG_SECURITY
219 #ifdef CONFIG_SECCOMP_FILTER
220 .seccomp
= { .filter_count
= ATOMIC_INIT(0) },
223 EXPORT_SYMBOL(init_task
);
226 * Initial thread structure. Alignment of this is handled by a special
229 #ifndef CONFIG_THREAD_INFO_IN_TASK
230 struct thread_info init_thread_info __init_thread_info
= INIT_THREAD_INFO(init_task
);