blob: 30a89b99a5af8b9348b4168015b18d48759aaa54 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002#ifndef _LINUX__INIT_TASK_H
3#define _LINUX__INIT_TASK_H
4
Dipankar Sarmaab2af1f2005-09-09 13:04:13 -07005#include <linux/rcupdate.h>
Ingo Molnarde30a2b2006-07-03 00:24:42 -07006#include <linux/irqflags.h>
Serge E. Hallyn4865ecf2006-10-02 02:18:14 -07007#include <linux/utsname.h>
Ingo Molnarfbb9ce952006-07-03 00:24:50 -07008#include <linux/lockdep.h>
Steven Rostedt5ac9f622009-03-25 20:55:00 -04009#include <linux/ftrace.h>
Kirill Korotaev73ea4132006-10-02 02:18:20 -070010#include <linux/ipc.h>
Cedric Le Goater9a575a92006-12-08 02:37:59 -080011#include <linux/pid_namespace.h>
Cedric Le Goateracce2922007-07-15 23:40:59 -070012#include <linux/user_namespace.h>
Andrew G. Morgan3898b1b2008-04-28 02:13:40 -070013#include <linux/securebits.h>
Frederic Weisbecker6a616712012-12-16 20:00:34 +010014#include <linux/seqlock.h>
Peter Zijlstrafb00aca2013-11-07 14:43:43 +010015#include <linux/rbtree.h>
Ingo Molnardfc34012017-02-03 23:15:21 +010016#include <linux/sched/autogroup.h>
Eric W. Biederman772698f2007-09-12 11:55:17 +020017#include <net/net_namespace.h>
Ingo Molnar77852fe2013-02-16 09:46:48 +010018#include <linux/sched/rt.h>
Josh Poimboeufd83a7cb2017-02-13 19:42:40 -060019#include <linux/livepatch.h>
Ingo Molnar589ee622017-02-04 00:16:44 +010020#include <linux/mm_types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
Andy Lutomirskic65eacb2016-09-13 14:29:24 -070022#include <asm/thread_info.h>
23
Dario Faggioli806c09a2010-11-30 19:51:33 +010024#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
Al Virof52111b2008-05-08 18:19:16 -040031extern struct files_struct init_files;
Al Viro18d8fda2008-12-26 00:35:37 -050032extern struct fs_struct init_fs;
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
Mel Gormancc9a6c82012-03-21 16:34:11 -070034#ifdef CONFIG_CPUSETS
John Stultz1ca7d672013-10-07 15:51:59 -070035#define INIT_CPUSET_SEQ(tsk) \
36 .mems_allowed_seq = SEQCNT_ZERO(tsk.mems_allowed_seq),
Mel Gormancc9a6c82012-03-21 16:34:11 -070037#else
John Stultz1ca7d672013-10-07 15:51:59 -070038#define INIT_CPUSET_SEQ(tsk)
Mel Gormancc9a6c82012-03-21 16:34:11 -070039#endif
40
Peter Zijlstra9d7fb042015-06-30 11:30:54 +020041#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
Nicolas Pitreb18b6a92017-01-21 00:09:08 -050049#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
Cedric Le Goater1ec320a2006-12-08 02:37:55 -080070#define INIT_SIGNALS(sig) { \
Oleg Nesterovb3ac0222010-05-26 14:43:24 -070071 .nr_threads = 1, \
Oleg Nesterov0c740d02014-01-21 15:49:56 -080072 .thread_head = LIST_HEAD_INIT(init_task.thread_node), \
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 .wait_chldexit = __WAIT_QUEUE_HEAD_INITIALIZER(sig.wait_chldexit),\
Cedric Le Goater1ec320a2006-12-08 02:37:55 -080074 .shared_pending = { \
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 .list = LIST_HEAD_INIT(sig.shared_pending.list), \
Cedric Le Goater1ec320a2006-12-08 02:37:55 -080076 .signal = {{0}}}, \
Nicolas Pitreb18b6a92017-01-21 00:09:08 -050077 INIT_POSIX_TIMERS(sig) \
78 INIT_CPU_TIMERS(sig) \
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 .rlim = INIT_RLIMITS, \
Nicolas Pitreb18b6a92017-01-21 00:09:08 -050080 INIT_CPUTIMER(sig) \
Peter Zijlstra9d7fb042015-06-30 11:30:54 +020081 INIT_PREV_CPUTIME(sig) \
KOSAKI Motohiro9b1bf122010-10-27 15:34:08 -070082 .cred_guard_mutex = \
83 __MUTEX_INITIALIZER(sig.cred_guard_mutex), \
Linus Torvalds1da177e2005-04-16 15:20:36 -070084}
85
Serge E. Hallynab516012006-10-02 02:18:06 -070086extern struct nsproxy init_nsproxy;
Serge E. Hallynab516012006-10-02 02:18:06 -070087
Linus Torvalds1da177e2005-04-16 15:20:36 -070088#define INIT_SIGHAND(sighand) { \
89 .count = ATOMIC_INIT(1), \
Oleg Nesterov0a14a132010-05-26 14:44:12 -070090 .action = { { { .sa_handler = SIG_DFL, } }, }, \
Ingo Molnare4d91912006-07-03 00:24:34 -070091 .siglock = __SPIN_LOCK_UNLOCKED(sighand.siglock), \
Davide Libenzib8fceee2007-09-20 12:40:16 -070092 .signalfd_wqh = __WAIT_QUEUE_HEAD_INITIALIZER(sighand.signalfd_wqh), \
Linus Torvalds1da177e2005-04-16 15:20:36 -070093}
94
95extern struct group_info init_groups;
96
Sukadev Bhattiprolu820e45d2007-05-10 22:23:00 -070097#define INIT_STRUCT_PID { \
98 .count = ATOMIC_INIT(1), \
Sukadev Bhattiprolu820e45d2007-05-10 22:23:00 -070099 .tasks = { \
Oleg Nesterovf2001142010-05-26 14:44:10 -0700100 { .first = NULL }, \
101 { .first = NULL }, \
102 { .first = NULL }, \
Sukadev Bhattiprolu820e45d2007-05-10 22:23:00 -0700103 }, \
Sukadev Bhattiprolu4c3f2ea2007-10-18 23:40:03 -0700104 .level = 0, \
105 .numbers = { { \
106 .nr = 0, \
107 .ns = &init_pid_ns, \
Sukadev Bhattiprolu4c3f2ea2007-10-18 23:40:03 -0700108 }, } \
Sukadev Bhattiprolu820e45d2007-05-10 22:23:00 -0700109}
110
111#define INIT_PID_LINK(type) \
112{ \
113 .node = { \
114 .next = NULL, \
Oleg Nesterovf2001142010-05-26 14:44:10 -0700115 .pprev = NULL, \
Sukadev Bhattiprolu820e45d2007-05-10 22:23:00 -0700116 }, \
117 .pid = &init_struct_pid, \
118}
119
Al Virobfef93a2008-01-10 04:53:18 -0500120#ifdef CONFIG_AUDITSYSCALL
121#define INIT_IDS \
Eric W. Biedermane1760bd2012-09-10 22:39:43 -0700122 .loginuid = INVALID_UID, \
Eric Paris4440e852013-11-27 17:35:17 -0500123 .sessionid = (unsigned int)-1,
Al Virobfef93a2008-01-10 04:53:18 -0500124#else
125#define INIT_IDS
126#endif
Serge E. Hallyn3b7391d2008-02-04 22:29:45 -0800127
Pranith Kumar28f65692014-09-22 14:00:48 -0400128#ifdef CONFIG_PREEMPT_RCU
Paul E. McKenneyf41d9112009-08-22 13:56:52 -0700129#define INIT_TASK_RCU_PREEMPT(tsk) \
130 .rcu_read_lock_nesting = 0, \
Paul E. McKenney1d082fd2014-08-14 16:01:53 -0700131 .rcu_read_unlock_special.s = 0, \
Paul E. McKenneya57eb942010-06-29 16:49:16 -0700132 .rcu_node_entry = LIST_HEAD_INIT(tsk.rcu_node_entry), \
Paul E. McKenney4e327472017-06-07 16:02:24 -0700133 .rcu_blocked_node = NULL,
Paul E. McKenneyf41d9112009-08-22 13:56:52 -0700134#else
135#define INIT_TASK_RCU_PREEMPT(tsk)
136#endif
Paul E. McKenney8315f422014-06-27 13:42:20 -0700137#ifdef CONFIG_TASKS_RCU
138#define INIT_TASK_RCU_TASKS(tsk) \
139 .rcu_tasks_holdout = false, \
140 .rcu_tasks_holdout_list = \
Paul E. McKenney176f8f72014-08-04 17:43:50 -0700141 LIST_HEAD_INIT(tsk.rcu_tasks_holdout_list), \
142 .rcu_tasks_idle_cpu = -1,
Paul E. McKenney8315f422014-06-27 13:42:20 -0700143#else
144#define INIT_TASK_RCU_TASKS(tsk)
145#endif
Paul E. McKenneyf41d9112009-08-22 13:56:52 -0700146
David Howellsb6dff3e2008-11-14 10:39:16 +1100147extern struct cred init_cred;
148
Peter Zijlstra8323f262012-06-22 13:36:05 +0200149#ifdef CONFIG_CGROUP_SCHED
150# define INIT_CGROUP_SCHED(tsk) \
151 .sched_task_group = &root_task_group,
152#else
153# define INIT_CGROUP_SCHED(tsk)
154#endif
155
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200156#ifdef CONFIG_PERF_EVENTS
Peter Zijlstra8323f262012-06-22 13:36:05 +0200157# define INIT_PERF_EVENTS(tsk) \
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200158 .perf_event_mutex = \
159 __MUTEX_INITIALIZER(tsk.perf_event_mutex), \
160 .perf_event_list = LIST_HEAD_INIT(tsk.perf_event_list),
Peter Zijlstra082ff5a2009-05-23 18:29:00 +0200161#else
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200162# define INIT_PERF_EVENTS(tsk)
Peter Zijlstra082ff5a2009-05-23 18:29:00 +0200163#endif
164
Frederic Weisbecker6a616712012-12-16 20:00:34 +0100165#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
166# define INIT_VTIME(tsk) \
Frederic Weisbeckerbac5b6b2017-06-29 19:15:10 +0200167 .vtime.seqcount = SEQCNT_ZERO(tsk.vtime.seqcount), \
168 .vtime.starttime = 0, \
169 .vtime.state = VTIME_SYS,
Frederic Weisbecker6a616712012-12-16 20:00:34 +0100170#else
171# define INIT_VTIME(tsk)
172#endif
173
Carsten Emdef1c6f1a2011-10-26 23:14:16 +0200174#define INIT_TASK_COMM "swapper"
175
Peter Zijlstrafb00aca2013-11-07 14:43:43 +0100176#ifdef CONFIG_RT_MUTEXES
177# define INIT_RT_MUTEXES(tsk) \
Davidlohr Buesoa23ba902017-09-08 16:15:01 -0700178 .pi_waiters = RB_ROOT_CACHED, \
179 .pi_top_task = NULL,
Peter Zijlstrafb00aca2013-11-07 14:43:43 +0100180#else
181# define INIT_RT_MUTEXES(tsk)
182#endif
183
Kirill Tkhaid8b163c2014-11-11 12:46:29 +0300184#ifdef CONFIG_NUMA_BALANCING
185# define INIT_NUMA_BALANCING(tsk) \
186 .numa_preferred_nid = -1, \
187 .numa_group = NULL, \
188 .numa_faults = NULL,
189#else
190# define INIT_NUMA_BALANCING(tsk)
191#endif
192
Andrey Ryabininc420f162015-02-13 14:39:59 -0800193#ifdef CONFIG_KASAN
194# define INIT_KASAN(tsk) \
195 .kasan_depth = 1,
196#else
197# define INIT_KASAN(tsk)
198#endif
199
Josh Poimboeufd83a7cb2017-02-13 19:42:40 -0600200#ifdef CONFIG_LIVEPATCH
201# define INIT_LIVEPATCH(tsk) \
202 .patch_state = KLP_UNDEFINED,
203#else
204# define INIT_LIVEPATCH(tsk)
205#endif
206
Andy Lutomirskic65eacb2016-09-13 14:29:24 -0700207#ifdef CONFIG_THREAD_INFO_IN_TASK
Andy Lutomirski68f24b082016-09-15 22:45:48 -0700208# define INIT_TASK_TI(tsk) \
209 .thread_info = INIT_THREAD_INFO(tsk), \
210 .stack_refcount = ATOMIC_INIT(1),
Andy Lutomirskic65eacb2016-09-13 14:29:24 -0700211#else
212# define INIT_TASK_TI(tsk)
213#endif
214
Tetsuo Handae4e55b42017-03-24 20:46:33 +0900215#ifdef CONFIG_SECURITY
216#define INIT_TASK_SECURITY .security = NULL,
217#else
218#define INIT_TASK_SECURITY
219#endif
220
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221/*
222 * INIT_TASK is used to set up the first task table, touch at
223 * your own risk!. Base=0, limit=0x1fffff (=2MB)
224 */
225#define INIT_TASK(tsk) \
226{ \
Andy Lutomirskic65eacb2016-09-13 14:29:24 -0700227 INIT_TASK_TI(tsk) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 .state = 0, \
Linus Torvalds7f1a00b2016-06-24 17:07:33 -0700229 .stack = init_stack, \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 .usage = ATOMIC_INIT(2), \
Oleg Nesterov7b34e422008-07-25 01:47:37 -0700231 .flags = PF_KTHREAD, \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 .prio = MAX_PRIO-20, \
233 .static_prio = MAX_PRIO-20, \
Ingo Molnarb29739f2006-06-27 02:54:51 -0700234 .normal_prio = MAX_PRIO-20, \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 .policy = SCHED_NORMAL, \
236 .cpus_allowed = CPU_MASK_ALL, \
Peter Zijlstra29baa742012-04-23 12:11:21 +0200237 .nr_cpus_allowed= NR_CPUS, \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 .mm = NULL, \
239 .active_mm = &init_mm, \
Andy Lutomirskif56141e2015-02-12 15:01:14 -0800240 .restart_block = { \
241 .fn = do_no_restart_syscall, \
242 }, \
Peter Zijlstra4a55bd52008-04-19 19:45:00 +0200243 .se = { \
244 .group_node = LIST_HEAD_INIT(tsk.se.group_node), \
245 }, \
Peter Zijlstrafa717062008-01-25 21:08:27 +0100246 .rt = { \
247 .run_list = LIST_HEAD_INIT(tsk.rt.run_list), \
Hiroshi Shimamotode5bdff2012-02-16 14:52:21 +0900248 .time_slice = RR_TIMESLICE, \
Peter Zijlstra6f505b12008-01-25 21:08:30 +0100249 }, \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 .tasks = LIST_HEAD_INIT(tsk.tasks), \
Dario Faggioli806c09a2010-11-30 19:51:33 +0100251 INIT_PUSHABLE_TASKS(tsk) \
Peter Zijlstra8323f262012-06-22 13:36:05 +0200252 INIT_CGROUP_SCHED(tsk) \
Roland McGrathf4700212008-03-24 18:36:23 -0700253 .ptraced = LIST_HEAD_INIT(tsk.ptraced), \
254 .ptrace_entry = LIST_HEAD_INIT(tsk.ptrace_entry), \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 .real_parent = &tsk, \
256 .parent = &tsk, \
257 .children = LIST_HEAD_INIT(tsk.children), \
258 .sibling = LIST_HEAD_INIT(tsk.sibling), \
259 .group_leader = &tsk, \
Paul E. McKenneyd36cc702012-05-16 15:33:15 -0700260 RCU_POINTER_INITIALIZER(real_cred, &init_cred), \
261 RCU_POINTER_INITIALIZER(cred, &init_cred), \
Carsten Emdef1c6f1a2011-10-26 23:14:16 +0200262 .comm = INIT_TASK_COMM, \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 .thread = INIT_THREAD, \
264 .fs = &init_fs, \
265 .files = &init_files, \
266 .signal = &init_signals, \
267 .sighand = &init_sighand, \
Serge E. Hallynab516012006-10-02 02:18:06 -0700268 .nsproxy = &init_nsproxy, \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 .pending = { \
270 .list = LIST_HEAD_INIT(tsk.pending.list), \
271 .signal = {{0}}}, \
272 .blocked = {{0}}, \
Ingo Molnare4d91912006-07-03 00:24:34 -0700273 .alloc_lock = __SPIN_LOCK_UNLOCKED(tsk.alloc_lock), \
Linus Torvaldsb6e32242009-12-17 13:23:24 -0800274 .journal_info = NULL, \
Nicolas Pitreb18b6a92017-01-21 00:09:08 -0500275 INIT_CPU_TIMERS(tsk) \
Thomas Gleixner1d615482009-11-17 14:54:03 +0100276 .pi_lock = __RAW_SPIN_LOCK_UNLOCKED(tsk.pi_lock), \
Arjan van de Ven69766752008-09-01 15:52:40 -0700277 .timer_slack_ns = 50000, /* 50 usec default slack */ \
Sukadev Bhattiprolu820e45d2007-05-10 22:23:00 -0700278 .pids = { \
279 [PIDTYPE_PID] = INIT_PID_LINK(PIDTYPE_PID), \
280 [PIDTYPE_PGID] = INIT_PID_LINK(PIDTYPE_PGID), \
281 [PIDTYPE_SID] = INIT_PID_LINK(PIDTYPE_SID), \
282 }, \
Oleg Nesterovfa2755e2010-05-26 14:44:08 -0700283 .thread_group = LIST_HEAD_INIT(tsk.thread_group), \
Oleg Nesterov0c740d02014-01-21 15:49:56 -0800284 .thread_node = LIST_HEAD_INIT(init_signals.thread_head), \
Al Virobfef93a2008-01-10 04:53:18 -0500285 INIT_IDS \
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200286 INIT_PERF_EVENTS(tsk) \
Ingo Molnarde30a2b2006-07-03 00:24:42 -0700287 INIT_TRACE_IRQFLAGS \
Ingo Molnarfbb9ce952006-07-03 00:24:50 -0700288 INIT_LOCKDEP \
Steven Rostedt5ac9f622009-03-25 20:55:00 -0400289 INIT_FTRACE_GRAPH \
Steven Rostedt261842b2009-04-16 21:41:52 -0400290 INIT_TRACE_RECURSION \
Paul E. McKenneyf41d9112009-08-22 13:56:52 -0700291 INIT_TASK_RCU_PREEMPT(tsk) \
Paul E. McKenney8315f422014-06-27 13:42:20 -0700292 INIT_TASK_RCU_TASKS(tsk) \
John Stultz1ca7d672013-10-07 15:51:59 -0700293 INIT_CPUSET_SEQ(tsk) \
Peter Zijlstrafb00aca2013-11-07 14:43:43 +0100294 INIT_RT_MUTEXES(tsk) \
Peter Zijlstra9d7fb042015-06-30 11:30:54 +0200295 INIT_PREV_CPUTIME(tsk) \
Frederic Weisbecker6a616712012-12-16 20:00:34 +0100296 INIT_VTIME(tsk) \
Kirill Tkhaid8b163c2014-11-11 12:46:29 +0300297 INIT_NUMA_BALANCING(tsk) \
Andrey Ryabininc420f162015-02-13 14:39:59 -0800298 INIT_KASAN(tsk) \
Josh Poimboeufd83a7cb2017-02-13 19:42:40 -0600299 INIT_LIVEPATCH(tsk) \
Tetsuo Handae4e55b42017-03-24 20:46:33 +0900300 INIT_TASK_SECURITY \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301}
302
303
Tim Abbott857ecee2009-06-23 19:59:36 -0400304/* Attach to the init_task data structure for proper alignment */
Tim Abbott2af76872010-02-20 01:03:35 +0100305#define __init_task_data __attribute__((__section__(".data..init_task")))
Tim Abbott857ecee2009-06-23 19:59:36 -0400306
David Howells05008712018-01-02 15:12:01 +0000307/* Attach to the thread_info data structure for proper alignment */
308#define __init_thread_info __attribute__((__section__(".data..init_thread_info")))
309
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310
311#endif