init_task.h 8.0 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3
#ifndef _LINUX__INIT_TASK_H
#define _LINUX__INIT_TASK_H

4
#include <linux/rcupdate.h>
5
#include <linux/irqflags.h>
6
#include <linux/utsname.h>
I
Ingo Molnar 已提交
7
#include <linux/lockdep.h>
8
#include <linux/ftrace.h>
K
Kirill Korotaev 已提交
9
#include <linux/ipc.h>
C
Cedric Le Goater 已提交
10
#include <linux/pid_namespace.h>
11
#include <linux/user_namespace.h>
12
#include <linux/securebits.h>
13
#include <linux/seqlock.h>
14
#include <linux/rbtree.h>
15
#include <linux/sched/autogroup.h>
16
#include <net/net_namespace.h>
17
#include <linux/sched/rt.h>
18
#include <linux/livepatch.h>
19
#include <linux/mm_types.h>
L
Linus Torvalds 已提交
20

21 22
#include <asm/thread_info.h>

23 24 25 26 27 28 29
#ifdef CONFIG_SMP
# define INIT_PUSHABLE_TASKS(tsk)					\
	.pushable_tasks = PLIST_NODE_INIT(tsk.pushable_tasks, MAX_PRIO),
#else
# define INIT_PUSHABLE_TASKS(tsk)
#endif

A
Al Viro 已提交
30
extern struct files_struct init_files;
A
Al Viro 已提交
31
extern struct fs_struct init_fs;
L
Linus Torvalds 已提交
32

33
#ifdef CONFIG_CPUSETS
34 35
#define INIT_CPUSET_SEQ(tsk)							\
	.mems_allowed_seq = SEQCNT_ZERO(tsk.mems_allowed_seq),
36
#else
37
#define INIT_CPUSET_SEQ(tsk)
38 39
#endif

40 41 42 43 44 45 46 47
#ifndef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
#define INIT_PREV_CPUTIME(x)	.prev_cputime = {			\
	.lock = __RAW_SPIN_LOCK_UNLOCKED(x.prev_cputime.lock),		\
},
#else
#define INIT_PREV_CPUTIME(x)
#endif

48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
#ifdef CONFIG_POSIX_TIMERS
#define INIT_POSIX_TIMERS(s)						\
	.posix_timers = LIST_HEAD_INIT(s.posix_timers),
#define INIT_CPU_TIMERS(s)						\
	.cpu_timers = {							\
		LIST_HEAD_INIT(s.cpu_timers[0]),			\
		LIST_HEAD_INIT(s.cpu_timers[1]),			\
		LIST_HEAD_INIT(s.cpu_timers[2]),								\
	},
#define INIT_CPUTIMER(s)						\
	.cputimer	= { 						\
		.cputime_atomic	= INIT_CPUTIME_ATOMIC,			\
		.running	= false,				\
		.checking_timer = false,				\
	},
#else
#define INIT_POSIX_TIMERS(s)
#define INIT_CPU_TIMERS(s)
#define INIT_CPUTIMER(s)
#endif

69
#define INIT_SIGNALS(sig) {						\
70
	.nr_threads	= 1,						\
71
	.thread_head	= LIST_HEAD_INIT(init_task.thread_node),	\
L
Linus Torvalds 已提交
72
	.wait_chldexit	= __WAIT_QUEUE_HEAD_INITIALIZER(sig.wait_chldexit),\
73
	.shared_pending	= { 						\
L
Linus Torvalds 已提交
74
		.list = LIST_HEAD_INIT(sig.shared_pending.list),	\
75
		.signal =  {{0}}},					\
76 77
	INIT_POSIX_TIMERS(sig)						\
	INIT_CPU_TIMERS(sig)						\
L
Linus Torvalds 已提交
78
	.rlim		= INIT_RLIMITS,					\
79
	INIT_CPUTIMER(sig)						\
80
	INIT_PREV_CPUTIME(sig)						\
81 82
	.cred_guard_mutex =						\
		 __MUTEX_INITIALIZER(sig.cred_guard_mutex),		\
L
Linus Torvalds 已提交
83 84
}

S
Serge E. Hallyn 已提交
85 86
extern struct nsproxy init_nsproxy;

L
Linus Torvalds 已提交
87 88
#define INIT_SIGHAND(sighand) {						\
	.count		= ATOMIC_INIT(1), 				\
89
	.action		= { { { .sa_handler = SIG_DFL, } }, },		\
90
	.siglock	= __SPIN_LOCK_UNLOCKED(sighand.siglock),	\
D
Davide Libenzi 已提交
91
	.signalfd_wqh	= __WAIT_QUEUE_HEAD_INITIALIZER(sighand.signalfd_wqh),	\
L
Linus Torvalds 已提交
92 93 94 95
}

extern struct group_info init_groups;

96 97 98
#define INIT_STRUCT_PID {						\
	.count 		= ATOMIC_INIT(1),				\
	.tasks		= {						\
99 100 101
		{ .first = NULL },					\
		{ .first = NULL },					\
		{ .first = NULL },					\
102
	},								\
103 104 105 106 107 108
	.level		= 0,						\
	.numbers	= { {						\
		.nr		= 0,					\
		.ns		= &init_pid_ns,				\
		.pid_chain	= { .next = NULL, .pprev = NULL },	\
	}, }								\
109 110 111 112 113 114
}

#define INIT_PID_LINK(type) 					\
{								\
	.node = {						\
		.next = NULL,					\
115
		.pprev = NULL,					\
116 117 118 119
	},							\
	.pid = &init_struct_pid,				\
}

A
Al Viro 已提交
120 121
#ifdef CONFIG_AUDITSYSCALL
#define INIT_IDS \
122
	.loginuid = INVALID_UID, \
123
	.sessionid = (unsigned int)-1,
A
Al Viro 已提交
124 125 126
#else
#define INIT_IDS
#endif
127

128
#ifdef CONFIG_PREEMPT_RCU
P
Paul E. McKenney 已提交
129 130 131 132 133 134
#define INIT_TASK_RCU_TREE_PREEMPT()					\
	.rcu_blocked_node = NULL,
#else
#define INIT_TASK_RCU_TREE_PREEMPT(tsk)
#endif
#ifdef CONFIG_PREEMPT_RCU
135 136
#define INIT_TASK_RCU_PREEMPT(tsk)					\
	.rcu_read_lock_nesting = 0,					\
137
	.rcu_read_unlock_special.s = 0,					\
P
Paul E. McKenney 已提交
138
	.rcu_node_entry = LIST_HEAD_INIT(tsk.rcu_node_entry),		\
139
	INIT_TASK_RCU_TREE_PREEMPT()
140 141 142
#else
#define INIT_TASK_RCU_PREEMPT(tsk)
#endif
P
Paul E. McKenney 已提交
143 144 145 146
#ifdef CONFIG_TASKS_RCU
#define INIT_TASK_RCU_TASKS(tsk)					\
	.rcu_tasks_holdout = false,					\
	.rcu_tasks_holdout_list =					\
147 148
		LIST_HEAD_INIT(tsk.rcu_tasks_holdout_list),		\
	.rcu_tasks_idle_cpu = -1,
P
Paul E. McKenney 已提交
149 150 151
#else
#define INIT_TASK_RCU_TASKS(tsk)
#endif
152

153 154
extern struct cred init_cred;

P
Peter Zijlstra 已提交
155 156 157 158 159 160 161
#ifdef CONFIG_CGROUP_SCHED
# define INIT_CGROUP_SCHED(tsk)						\
	.sched_task_group = &root_task_group,
#else
# define INIT_CGROUP_SCHED(tsk)
#endif

162
#ifdef CONFIG_PERF_EVENTS
P
Peter Zijlstra 已提交
163
# define INIT_PERF_EVENTS(tsk)						\
164 165 166
	.perf_event_mutex = 						\
		 __MUTEX_INITIALIZER(tsk.perf_event_mutex),		\
	.perf_event_list = LIST_HEAD_INIT(tsk.perf_event_list),
167
#else
168
# define INIT_PERF_EVENTS(tsk)
169 170
#endif

171 172
#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
# define INIT_VTIME(tsk)						\
173 174 175
	.vtime.seqcount = SEQCNT_ZERO(tsk.vtime.seqcount),		\
	.vtime.starttime = 0,						\
	.vtime.state = VTIME_SYS,
176 177 178 179
#else
# define INIT_VTIME(tsk)
#endif

180 181
#define INIT_TASK_COMM "swapper"

182 183 184
#ifdef CONFIG_RT_MUTEXES
# define INIT_RT_MUTEXES(tsk)						\
	.pi_waiters = RB_ROOT,						\
185
	.pi_top_task = NULL,						\
186 187 188 189 190
	.pi_waiters_leftmost = NULL,
#else
# define INIT_RT_MUTEXES(tsk)
#endif

191 192 193 194 195 196 197 198 199
#ifdef CONFIG_NUMA_BALANCING
# define INIT_NUMA_BALANCING(tsk)					\
	.numa_preferred_nid = -1,					\
	.numa_group = NULL,						\
	.numa_faults = NULL,
#else
# define INIT_NUMA_BALANCING(tsk)
#endif

200 201 202 203 204 205 206
#ifdef CONFIG_KASAN
# define INIT_KASAN(tsk)						\
	.kasan_depth = 1,
#else
# define INIT_KASAN(tsk)
#endif

207 208 209 210 211 212 213
#ifdef CONFIG_LIVEPATCH
# define INIT_LIVEPATCH(tsk)						\
	.patch_state = KLP_UNDEFINED,
#else
# define INIT_LIVEPATCH(tsk)
#endif

214
#ifdef CONFIG_THREAD_INFO_IN_TASK
215 216 217
# define INIT_TASK_TI(tsk)			\
	.thread_info = INIT_THREAD_INFO(tsk),	\
	.stack_refcount = ATOMIC_INIT(1),
218 219 220 221
#else
# define INIT_TASK_TI(tsk)
#endif

222 223 224 225 226 227
#ifdef CONFIG_SECURITY
#define INIT_TASK_SECURITY .security = NULL,
#else
#define INIT_TASK_SECURITY
#endif

L
Linus Torvalds 已提交
228 229 230 231 232 233
/*
 *  INIT_TASK is used to set up the first task table, touch at
 * your own risk!. Base=0, limit=0x1fffff (=2MB)
 */
#define INIT_TASK(tsk)	\
{									\
234
	INIT_TASK_TI(tsk)						\
L
Linus Torvalds 已提交
235
	.state		= 0,						\
236
	.stack		= init_stack,					\
L
Linus Torvalds 已提交
237
	.usage		= ATOMIC_INIT(2),				\
O
Oleg Nesterov 已提交
238
	.flags		= PF_KTHREAD,					\
L
Linus Torvalds 已提交
239 240
	.prio		= MAX_PRIO-20,					\
	.static_prio	= MAX_PRIO-20,					\
241
	.normal_prio	= MAX_PRIO-20,					\
L
Linus Torvalds 已提交
242 243
	.policy		= SCHED_NORMAL,					\
	.cpus_allowed	= CPU_MASK_ALL,					\
244
	.nr_cpus_allowed= NR_CPUS,					\
L
Linus Torvalds 已提交
245 246
	.mm		= NULL,						\
	.active_mm	= &init_mm,					\
247 248 249
	.restart_block = {						\
		.fn = do_no_restart_syscall,				\
	},								\
250 251 252
	.se		= {						\
		.group_node 	= LIST_HEAD_INIT(tsk.se.group_node),	\
	},								\
P
Peter Zijlstra 已提交
253 254
	.rt		= {						\
		.run_list	= LIST_HEAD_INIT(tsk.rt.run_list),	\
255
		.time_slice	= RR_TIMESLICE,				\
P
Peter Zijlstra 已提交
256
	},								\
L
Linus Torvalds 已提交
257
	.tasks		= LIST_HEAD_INIT(tsk.tasks),			\
258
	INIT_PUSHABLE_TASKS(tsk)					\
P
Peter Zijlstra 已提交
259
	INIT_CGROUP_SCHED(tsk)						\
R
Roland McGrath 已提交
260 261
	.ptraced	= LIST_HEAD_INIT(tsk.ptraced),			\
	.ptrace_entry	= LIST_HEAD_INIT(tsk.ptrace_entry),		\
L
Linus Torvalds 已提交
262 263 264 265 266
	.real_parent	= &tsk,						\
	.parent		= &tsk,						\
	.children	= LIST_HEAD_INIT(tsk.children),			\
	.sibling	= LIST_HEAD_INIT(tsk.sibling),			\
	.group_leader	= &tsk,						\
267 268
	RCU_POINTER_INITIALIZER(real_cred, &init_cred),			\
	RCU_POINTER_INITIALIZER(cred, &init_cred),			\
269
	.comm		= INIT_TASK_COMM,				\
L
Linus Torvalds 已提交
270 271 272 273 274
	.thread		= INIT_THREAD,					\
	.fs		= &init_fs,					\
	.files		= &init_files,					\
	.signal		= &init_signals,				\
	.sighand	= &init_sighand,				\
S
Serge E. Hallyn 已提交
275
	.nsproxy	= &init_nsproxy,				\
L
Linus Torvalds 已提交
276 277 278 279
	.pending	= {						\
		.list = LIST_HEAD_INIT(tsk.pending.list),		\
		.signal = {{0}}},					\
	.blocked	= {{0}},					\
280
	.alloc_lock	= __SPIN_LOCK_UNLOCKED(tsk.alloc_lock),		\
281
	.journal_info	= NULL,						\
282
	INIT_CPU_TIMERS(tsk)						\
283
	.pi_lock	= __RAW_SPIN_LOCK_UNLOCKED(tsk.pi_lock),	\
284
	.timer_slack_ns = 50000, /* 50 usec default slack */		\
285 286 287 288 289
	.pids = {							\
		[PIDTYPE_PID]  = INIT_PID_LINK(PIDTYPE_PID),		\
		[PIDTYPE_PGID] = INIT_PID_LINK(PIDTYPE_PGID),		\
		[PIDTYPE_SID]  = INIT_PID_LINK(PIDTYPE_SID),		\
	},								\
290
	.thread_group	= LIST_HEAD_INIT(tsk.thread_group),		\
291
	.thread_node	= LIST_HEAD_INIT(init_signals.thread_head),	\
A
Al Viro 已提交
292
	INIT_IDS							\
293
	INIT_PERF_EVENTS(tsk)						\
294
	INIT_TRACE_IRQFLAGS						\
I
Ingo Molnar 已提交
295
	INIT_LOCKDEP							\
296
	INIT_FTRACE_GRAPH						\
297
	INIT_TRACE_RECURSION						\
298
	INIT_TASK_RCU_PREEMPT(tsk)					\
P
Paul E. McKenney 已提交
299
	INIT_TASK_RCU_TASKS(tsk)					\
300
	INIT_CPUSET_SEQ(tsk)						\
301
	INIT_RT_MUTEXES(tsk)						\
302
	INIT_PREV_CPUTIME(tsk)						\
303
	INIT_VTIME(tsk)							\
304
	INIT_NUMA_BALANCING(tsk)					\
305
	INIT_KASAN(tsk)							\
306
	INIT_LIVEPATCH(tsk)						\
307
	INIT_TASK_SECURITY						\
L
Linus Torvalds 已提交
308 309 310
}


311
/* Attach to the init_task data structure for proper alignment */
312
#define __init_task_data __attribute__((__section__(".data..init_task")))
313

L
Linus Torvalds 已提交
314 315

#endif