Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
1da177e4 LT |
2 | #ifndef _LINUX__INIT_TASK_H |
3 | #define _LINUX__INIT_TASK_H | |
4 | ||
ab2af1f5 | 5 | #include <linux/rcupdate.h> |
de30a2b3 | 6 | #include <linux/irqflags.h> |
4865ecf1 | 7 | #include <linux/utsname.h> |
fbb9ce95 | 8 | #include <linux/lockdep.h> |
5ac9f622 | 9 | #include <linux/ftrace.h> |
73ea4130 | 10 | #include <linux/ipc.h> |
9a575a92 | 11 | #include <linux/pid_namespace.h> |
acce292c | 12 | #include <linux/user_namespace.h> |
3898b1b4 | 13 | #include <linux/securebits.h> |
6a61671b | 14 | #include <linux/seqlock.h> |
fb00aca4 | 15 | #include <linux/rbtree.h> |
dfc3401a | 16 | #include <linux/sched/autogroup.h> |
772698f6 | 17 | #include <net/net_namespace.h> |
77852fea | 18 | #include <linux/sched/rt.h> |
d83a7cb3 | 19 | #include <linux/livepatch.h> |
589ee628 | 20 | #include <linux/mm_types.h> |
1da177e4 | 21 | |
c65eacbe AL |
22 | #include <asm/thread_info.h> |
23 | ||
806c09a7 DF |
24 | #ifdef CONFIG_SMP |
25 | # define INIT_PUSHABLE_TASKS(tsk) \ | |
26 | .pushable_tasks = PLIST_NODE_INIT(tsk.pushable_tasks, MAX_PRIO), | |
27 | #else | |
28 | # define INIT_PUSHABLE_TASKS(tsk) | |
29 | #endif | |
30 | ||
f52111b1 | 31 | extern struct files_struct init_files; |
18d8fda7 | 32 | extern struct fs_struct init_fs; |
1da177e4 | 33 | |
cc9a6c87 | 34 | #ifdef CONFIG_CPUSETS |
1ca7d67c JS |
35 | #define INIT_CPUSET_SEQ(tsk) \ |
36 | .mems_allowed_seq = SEQCNT_ZERO(tsk.mems_allowed_seq), | |
cc9a6c87 | 37 | #else |
1ca7d67c | 38 | #define INIT_CPUSET_SEQ(tsk) |
cc9a6c87 MG |
39 | #endif |
40 | ||
9d7fb042 PZ |
41 | #ifndef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE |
42 | #define INIT_PREV_CPUTIME(x) .prev_cputime = { \ | |
43 | .lock = __RAW_SPIN_LOCK_UNLOCKED(x.prev_cputime.lock), \ | |
44 | }, | |
45 | #else | |
46 | #define INIT_PREV_CPUTIME(x) | |
47 | #endif | |
48 | ||
b18b6a9c NP |
49 | #ifdef CONFIG_POSIX_TIMERS |
50 | #define INIT_POSIX_TIMERS(s) \ | |
51 | .posix_timers = LIST_HEAD_INIT(s.posix_timers), | |
52 | #define INIT_CPU_TIMERS(s) \ | |
53 | .cpu_timers = { \ | |
54 | LIST_HEAD_INIT(s.cpu_timers[0]), \ | |
55 | LIST_HEAD_INIT(s.cpu_timers[1]), \ | |
56 | LIST_HEAD_INIT(s.cpu_timers[2]), \ | |
57 | }, | |
58 | #define INIT_CPUTIMER(s) \ | |
59 | .cputimer = { \ | |
60 | .cputime_atomic = INIT_CPUTIME_ATOMIC, \ | |
61 | .running = false, \ | |
62 | .checking_timer = false, \ | |
63 | }, | |
64 | #else | |
65 | #define INIT_POSIX_TIMERS(s) | |
66 | #define INIT_CPU_TIMERS(s) | |
67 | #define INIT_CPUTIMER(s) | |
68 | #endif | |
69 | ||
1ec320af | 70 | #define INIT_SIGNALS(sig) { \ |
b3ac022c | 71 | .nr_threads = 1, \ |
0c740d0a | 72 | .thread_head = LIST_HEAD_INIT(init_task.thread_node), \ |
1da177e4 | 73 | .wait_chldexit = __WAIT_QUEUE_HEAD_INITIALIZER(sig.wait_chldexit),\ |
1ec320af | 74 | .shared_pending = { \ |
1da177e4 | 75 | .list = LIST_HEAD_INIT(sig.shared_pending.list), \ |
1ec320af | 76 | .signal = {{0}}}, \ |
b18b6a9c NP |
77 | INIT_POSIX_TIMERS(sig) \ |
78 | INIT_CPU_TIMERS(sig) \ | |
1da177e4 | 79 | .rlim = INIT_RLIMITS, \ |
b18b6a9c | 80 | INIT_CPUTIMER(sig) \ |
9d7fb042 | 81 | INIT_PREV_CPUTIME(sig) \ |
9b1bf12d KM |
82 | .cred_guard_mutex = \ |
83 | __MUTEX_INITIALIZER(sig.cred_guard_mutex), \ | |
1da177e4 LT |
84 | } |
85 | ||
ab516013 | 86 | extern struct nsproxy init_nsproxy; |
ab516013 | 87 | |
1da177e4 LT |
88 | #define INIT_SIGHAND(sighand) { \ |
89 | .count = ATOMIC_INIT(1), \ | |
0a14a130 | 90 | .action = { { { .sa_handler = SIG_DFL, } }, }, \ |
e4d91918 | 91 | .siglock = __SPIN_LOCK_UNLOCKED(sighand.siglock), \ |
b8fceee1 | 92 | .signalfd_wqh = __WAIT_QUEUE_HEAD_INITIALIZER(sighand.signalfd_wqh), \ |
1da177e4 LT |
93 | } |
94 | ||
95 | extern struct group_info init_groups; | |
96 | ||
820e45db SB |
97 | #define INIT_STRUCT_PID { \ |
98 | .count = ATOMIC_INIT(1), \ | |
820e45db | 99 | .tasks = { \ |
f2001145 ON |
100 | { .first = NULL }, \ |
101 | { .first = NULL }, \ | |
102 | { .first = NULL }, \ | |
820e45db | 103 | }, \ |
4c3f2ead SB |
104 | .level = 0, \ |
105 | .numbers = { { \ | |
106 | .nr = 0, \ | |
107 | .ns = &init_pid_ns, \ | |
108 | .pid_chain = { .next = NULL, .pprev = NULL }, \ | |
109 | }, } \ | |
820e45db SB |
110 | } |
111 | ||
112 | #define INIT_PID_LINK(type) \ | |
113 | { \ | |
114 | .node = { \ | |
115 | .next = NULL, \ | |
f2001145 | 116 | .pprev = NULL, \ |
820e45db SB |
117 | }, \ |
118 | .pid = &init_struct_pid, \ | |
119 | } | |
120 | ||
bfef93a5 AV |
121 | #ifdef CONFIG_AUDITSYSCALL |
122 | #define INIT_IDS \ | |
e1760bd5 | 123 | .loginuid = INVALID_UID, \ |
4440e854 | 124 | .sessionid = (unsigned int)-1, |
bfef93a5 AV |
125 | #else |
126 | #define INIT_IDS | |
127 | #endif | |
3b7391de | 128 | |
a57eb940 | 129 | #ifdef CONFIG_PREEMPT_RCU |
f41d911f PM |
130 | #define INIT_TASK_RCU_PREEMPT(tsk) \ |
131 | .rcu_read_lock_nesting = 0, \ | |
1d082fd0 | 132 | .rcu_read_unlock_special.s = 0, \ |
a57eb940 | 133 | .rcu_node_entry = LIST_HEAD_INIT(tsk.rcu_node_entry), \ |
4e327470 | 134 | .rcu_blocked_node = NULL, |
f41d911f PM |
135 | #else |
136 | #define INIT_TASK_RCU_PREEMPT(tsk) | |
137 | #endif | |
8315f422 PM |
138 | #ifdef CONFIG_TASKS_RCU |
139 | #define INIT_TASK_RCU_TASKS(tsk) \ | |
140 | .rcu_tasks_holdout = false, \ | |
141 | .rcu_tasks_holdout_list = \ | |
176f8f7a PM |
142 | LIST_HEAD_INIT(tsk.rcu_tasks_holdout_list), \ |
143 | .rcu_tasks_idle_cpu = -1, | |
8315f422 PM |
144 | #else |
145 | #define INIT_TASK_RCU_TASKS(tsk) | |
146 | #endif | |
f41d911f | 147 | |
b6dff3ec DH |
148 | extern struct cred init_cred; |
149 | ||
8323f26c PZ |
150 | #ifdef CONFIG_CGROUP_SCHED |
151 | # define INIT_CGROUP_SCHED(tsk) \ | |
152 | .sched_task_group = &root_task_group, | |
153 | #else | |
154 | # define INIT_CGROUP_SCHED(tsk) | |
155 | #endif | |
156 | ||
cdd6c482 | 157 | #ifdef CONFIG_PERF_EVENTS |
8323f26c | 158 | # define INIT_PERF_EVENTS(tsk) \ |
cdd6c482 IM |
159 | .perf_event_mutex = \ |
160 | __MUTEX_INITIALIZER(tsk.perf_event_mutex), \ | |
161 | .perf_event_list = LIST_HEAD_INIT(tsk.perf_event_list), | |
082ff5a2 | 162 | #else |
cdd6c482 | 163 | # define INIT_PERF_EVENTS(tsk) |
082ff5a2 PZ |
164 | #endif |
165 | ||
6a61671b FW |
166 | #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN |
167 | # define INIT_VTIME(tsk) \ | |
bac5b6b6 FW |
168 | .vtime.seqcount = SEQCNT_ZERO(tsk.vtime.seqcount), \ |
169 | .vtime.starttime = 0, \ | |
170 | .vtime.state = VTIME_SYS, | |
6a61671b FW |
171 | #else |
172 | # define INIT_VTIME(tsk) | |
173 | #endif | |
174 | ||
f1c6f1a7 CE |
175 | #define INIT_TASK_COMM "swapper" |
176 | ||
fb00aca4 PZ |
177 | #ifdef CONFIG_RT_MUTEXES |
178 | # define INIT_RT_MUTEXES(tsk) \ | |
a23ba907 DB |
179 | .pi_waiters = RB_ROOT_CACHED, \ |
180 | .pi_top_task = NULL, | |
fb00aca4 PZ |
181 | #else |
182 | # define INIT_RT_MUTEXES(tsk) | |
183 | #endif | |
184 | ||
d8b163c4 KT |
185 | #ifdef CONFIG_NUMA_BALANCING |
186 | # define INIT_NUMA_BALANCING(tsk) \ | |
187 | .numa_preferred_nid = -1, \ | |
188 | .numa_group = NULL, \ | |
189 | .numa_faults = NULL, | |
190 | #else | |
191 | # define INIT_NUMA_BALANCING(tsk) | |
192 | #endif | |
193 | ||
c420f167 AR |
194 | #ifdef CONFIG_KASAN |
195 | # define INIT_KASAN(tsk) \ | |
196 | .kasan_depth = 1, | |
197 | #else | |
198 | # define INIT_KASAN(tsk) | |
199 | #endif | |
200 | ||
d83a7cb3 JP |
201 | #ifdef CONFIG_LIVEPATCH |
202 | # define INIT_LIVEPATCH(tsk) \ | |
203 | .patch_state = KLP_UNDEFINED, | |
204 | #else | |
205 | # define INIT_LIVEPATCH(tsk) | |
206 | #endif | |
207 | ||
c65eacbe | 208 | #ifdef CONFIG_THREAD_INFO_IN_TASK |
68f24b08 AL |
209 | # define INIT_TASK_TI(tsk) \ |
210 | .thread_info = INIT_THREAD_INFO(tsk), \ | |
211 | .stack_refcount = ATOMIC_INIT(1), | |
c65eacbe AL |
212 | #else |
213 | # define INIT_TASK_TI(tsk) | |
214 | #endif | |
215 | ||
e4e55b47 TH |
216 | #ifdef CONFIG_SECURITY |
217 | #define INIT_TASK_SECURITY .security = NULL, | |
218 | #else | |
219 | #define INIT_TASK_SECURITY | |
220 | #endif | |
221 | ||
1da177e4 LT |
222 | /* |
223 | * INIT_TASK is used to set up the first task table, touch at | |
224 | * your own risk!. Base=0, limit=0x1fffff (=2MB) | |
225 | */ | |
226 | #define INIT_TASK(tsk) \ | |
227 | { \ | |
c65eacbe | 228 | INIT_TASK_TI(tsk) \ |
1da177e4 | 229 | .state = 0, \ |
7f1a00b6 | 230 | .stack = init_stack, \ |
1da177e4 | 231 | .usage = ATOMIC_INIT(2), \ |
7b34e428 | 232 | .flags = PF_KTHREAD, \ |
1da177e4 LT |
233 | .prio = MAX_PRIO-20, \ |
234 | .static_prio = MAX_PRIO-20, \ | |
b29739f9 | 235 | .normal_prio = MAX_PRIO-20, \ |
1da177e4 LT |
236 | .policy = SCHED_NORMAL, \ |
237 | .cpus_allowed = CPU_MASK_ALL, \ | |
29baa747 | 238 | .nr_cpus_allowed= NR_CPUS, \ |
1da177e4 LT |
239 | .mm = NULL, \ |
240 | .active_mm = &init_mm, \ | |
f56141e3 AL |
241 | .restart_block = { \ |
242 | .fn = do_no_restart_syscall, \ | |
243 | }, \ | |
4a55bd5e PZ |
244 | .se = { \ |
245 | .group_node = LIST_HEAD_INIT(tsk.se.group_node), \ | |
246 | }, \ | |
fa717060 PZ |
247 | .rt = { \ |
248 | .run_list = LIST_HEAD_INIT(tsk.rt.run_list), \ | |
de5bdff7 | 249 | .time_slice = RR_TIMESLICE, \ |
6f505b16 | 250 | }, \ |
1da177e4 | 251 | .tasks = LIST_HEAD_INIT(tsk.tasks), \ |
806c09a7 | 252 | INIT_PUSHABLE_TASKS(tsk) \ |
8323f26c | 253 | INIT_CGROUP_SCHED(tsk) \ |
f470021a RM |
254 | .ptraced = LIST_HEAD_INIT(tsk.ptraced), \ |
255 | .ptrace_entry = LIST_HEAD_INIT(tsk.ptrace_entry), \ | |
1da177e4 LT |
256 | .real_parent = &tsk, \ |
257 | .parent = &tsk, \ | |
258 | .children = LIST_HEAD_INIT(tsk.children), \ | |
259 | .sibling = LIST_HEAD_INIT(tsk.sibling), \ | |
260 | .group_leader = &tsk, \ | |
d36cc701 PM |
261 | RCU_POINTER_INITIALIZER(real_cred, &init_cred), \ |
262 | RCU_POINTER_INITIALIZER(cred, &init_cred), \ | |
f1c6f1a7 | 263 | .comm = INIT_TASK_COMM, \ |
1da177e4 LT |
264 | .thread = INIT_THREAD, \ |
265 | .fs = &init_fs, \ | |
266 | .files = &init_files, \ | |
267 | .signal = &init_signals, \ | |
268 | .sighand = &init_sighand, \ | |
ab516013 | 269 | .nsproxy = &init_nsproxy, \ |
1da177e4 LT |
270 | .pending = { \ |
271 | .list = LIST_HEAD_INIT(tsk.pending.list), \ | |
272 | .signal = {{0}}}, \ | |
273 | .blocked = {{0}}, \ | |
e4d91918 | 274 | .alloc_lock = __SPIN_LOCK_UNLOCKED(tsk.alloc_lock), \ |
b6e3224f | 275 | .journal_info = NULL, \ |
b18b6a9c | 276 | INIT_CPU_TIMERS(tsk) \ |
1d615482 | 277 | .pi_lock = __RAW_SPIN_LOCK_UNLOCKED(tsk.pi_lock), \ |
6976675d | 278 | .timer_slack_ns = 50000, /* 50 usec default slack */ \ |
820e45db SB |
279 | .pids = { \ |
280 | [PIDTYPE_PID] = INIT_PID_LINK(PIDTYPE_PID), \ | |
281 | [PIDTYPE_PGID] = INIT_PID_LINK(PIDTYPE_PGID), \ | |
282 | [PIDTYPE_SID] = INIT_PID_LINK(PIDTYPE_SID), \ | |
283 | }, \ | |
fa2755e2 | 284 | .thread_group = LIST_HEAD_INIT(tsk.thread_group), \ |
0c740d0a | 285 | .thread_node = LIST_HEAD_INIT(init_signals.thread_head), \ |
bfef93a5 | 286 | INIT_IDS \ |
cdd6c482 | 287 | INIT_PERF_EVENTS(tsk) \ |
de30a2b3 | 288 | INIT_TRACE_IRQFLAGS \ |
fbb9ce95 | 289 | INIT_LOCKDEP \ |
5ac9f622 | 290 | INIT_FTRACE_GRAPH \ |
261842b7 | 291 | INIT_TRACE_RECURSION \ |
f41d911f | 292 | INIT_TASK_RCU_PREEMPT(tsk) \ |
8315f422 | 293 | INIT_TASK_RCU_TASKS(tsk) \ |
1ca7d67c | 294 | INIT_CPUSET_SEQ(tsk) \ |
fb00aca4 | 295 | INIT_RT_MUTEXES(tsk) \ |
9d7fb042 | 296 | INIT_PREV_CPUTIME(tsk) \ |
6a61671b | 297 | INIT_VTIME(tsk) \ |
d8b163c4 | 298 | INIT_NUMA_BALANCING(tsk) \ |
c420f167 | 299 | INIT_KASAN(tsk) \ |
d83a7cb3 | 300 | INIT_LIVEPATCH(tsk) \ |
e4e55b47 | 301 | INIT_TASK_SECURITY \ |
1da177e4 LT |
302 | } |
303 | ||
304 | ||
857eceeb | 305 | /* Attach to the init_task data structure for proper alignment */ |
2af7687f | 306 | #define __init_task_data __attribute__((__section__(".data..init_task"))) |
857eceeb | 307 | |
1da177e4 LT |
308 | |
309 | #endif |