init_task.h 7.9 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
	.vtime_seqcount = SEQCNT_ZERO(tsk.vtime_seqcount),	\
174 175 176 177 178 179
	.vtime_snap = 0,				\
	.vtime_snap_whence = VTIME_SYS,
#else
# define INIT_VTIME(tsk)
#endif

180 181
#define INIT_TASK_COMM "swapper"

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

190 191 192 193 194 195 196 197 198
#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

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

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

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

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


303
/* Attach to the init_task data structure for proper alignment */
304
#define __init_task_data __attribute__((__section__(".data..init_task")))
305

L
Linus Torvalds 已提交
306 307

#endif