xref: /linux/init/init_task.c (revision f0b752168d7091f38e7d61a80de2542e8b71d266)
1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
2a4a2eb49SThomas Gleixner #include <linux/init_task.h>
3a4a2eb49SThomas Gleixner #include <linux/export.h>
4a4a2eb49SThomas Gleixner #include <linux/mqueue.h>
5a4a2eb49SThomas Gleixner #include <linux/sched.h>
6cf4aebc2SClark Williams #include <linux/sched/sysctl.h>
78bd75c77SClark Williams #include <linux/sched/rt.h>
89164bb4aSIngo Molnar #include <linux/sched/task.h>
9a4a2eb49SThomas Gleixner #include <linux/init.h>
10a4a2eb49SThomas Gleixner #include <linux/fs.h>
11a4a2eb49SThomas Gleixner #include <linux/mm.h>
12*f0b75216SRichard Guy Briggs #include <linux/audit.h>
13a4a2eb49SThomas Gleixner 
14a4a2eb49SThomas Gleixner #include <asm/pgtable.h>
157c0f6ba6SLinus Torvalds #include <linux/uaccess.h>
16a4a2eb49SThomas Gleixner 
173678e2fcSDavid Howells static struct signal_struct init_signals = {
183678e2fcSDavid Howells 	.nr_threads	= 1,
193678e2fcSDavid Howells 	.thread_head	= LIST_HEAD_INIT(init_task.thread_node),
203678e2fcSDavid Howells 	.wait_chldexit	= __WAIT_QUEUE_HEAD_INITIALIZER(init_signals.wait_chldexit),
213678e2fcSDavid Howells 	.shared_pending	= {
223678e2fcSDavid Howells 		.list = LIST_HEAD_INIT(init_signals.shared_pending.list),
233678e2fcSDavid Howells 		.signal =  {{0}}
243678e2fcSDavid Howells 	},
253678e2fcSDavid Howells 	.rlim		= INIT_RLIMITS,
263678e2fcSDavid Howells 	.cred_guard_mutex = __MUTEX_INITIALIZER(init_signals.cred_guard_mutex),
273678e2fcSDavid Howells #ifdef CONFIG_POSIX_TIMERS
283678e2fcSDavid Howells 	.posix_timers = LIST_HEAD_INIT(init_signals.posix_timers),
293678e2fcSDavid Howells 	.cputimer	= {
303678e2fcSDavid Howells 		.cputime_atomic	= INIT_CPUTIME_ATOMIC,
313678e2fcSDavid Howells 		.running	= false,
323678e2fcSDavid Howells 		.checking_timer = false,
333678e2fcSDavid Howells 	},
343678e2fcSDavid Howells #endif
353678e2fcSDavid Howells 	INIT_CPU_TIMERS(init_signals)
363678e2fcSDavid Howells 	INIT_PREV_CPUTIME(init_signals)
373678e2fcSDavid Howells };
383678e2fcSDavid Howells 
393678e2fcSDavid Howells static struct sighand_struct init_sighand = {
403678e2fcSDavid Howells 	.count		= ATOMIC_INIT(1),
413678e2fcSDavid Howells 	.action		= { { { .sa_handler = SIG_DFL, } }, },
423678e2fcSDavid Howells 	.siglock	= __SPIN_LOCK_UNLOCKED(init_sighand.siglock),
433678e2fcSDavid Howells 	.signalfd_wqh	= __WAIT_QUEUE_HEAD_INITIALIZER(init_sighand.signalfd_wqh),
443678e2fcSDavid Howells };
45a4a2eb49SThomas Gleixner 
46d11ed3abSDavid Howells /*
47d11ed3abSDavid Howells  * Set up the first task table, touch at your own risk!. Base=0,
48d11ed3abSDavid Howells  * limit=0x1fffff (=2MB)
49d11ed3abSDavid Howells  */
500500871fSDavid Howells struct task_struct init_task
510500871fSDavid Howells #ifdef CONFIG_ARCH_TASK_STRUCT_ON_STACK
520500871fSDavid Howells 	__init_task_data
530500871fSDavid Howells #endif
54d11ed3abSDavid Howells = {
554e7e3adbSDavid Howells #ifdef CONFIG_THREAD_INFO_IN_TASK
564e7e3adbSDavid Howells 	.thread_info	= INIT_THREAD_INFO(init_task),
574e7e3adbSDavid Howells 	.stack_refcount	= ATOMIC_INIT(1),
584e7e3adbSDavid Howells #endif
59d11ed3abSDavid Howells 	.state		= 0,
60d11ed3abSDavid Howells 	.stack		= init_stack,
61d11ed3abSDavid Howells 	.usage		= ATOMIC_INIT(2),
62d11ed3abSDavid Howells 	.flags		= PF_KTHREAD,
63d11ed3abSDavid Howells 	.prio		= MAX_PRIO - 20,
64d11ed3abSDavid Howells 	.static_prio	= MAX_PRIO - 20,
65d11ed3abSDavid Howells 	.normal_prio	= MAX_PRIO - 20,
66d11ed3abSDavid Howells 	.policy		= SCHED_NORMAL,
67d11ed3abSDavid Howells 	.cpus_allowed	= CPU_MASK_ALL,
68d11ed3abSDavid Howells 	.nr_cpus_allowed= NR_CPUS,
69d11ed3abSDavid Howells 	.mm		= NULL,
70d11ed3abSDavid Howells 	.active_mm	= &init_mm,
71d11ed3abSDavid Howells 	.restart_block	= {
72d11ed3abSDavid Howells 		.fn = do_no_restart_syscall,
73d11ed3abSDavid Howells 	},
74d11ed3abSDavid Howells 	.se		= {
75d11ed3abSDavid Howells 		.group_node 	= LIST_HEAD_INIT(init_task.se.group_node),
76d11ed3abSDavid Howells 	},
77d11ed3abSDavid Howells 	.rt		= {
78d11ed3abSDavid Howells 		.run_list	= LIST_HEAD_INIT(init_task.rt.run_list),
79d11ed3abSDavid Howells 		.time_slice	= RR_TIMESLICE,
80d11ed3abSDavid Howells 	},
81d11ed3abSDavid Howells 	.tasks		= LIST_HEAD_INIT(init_task.tasks),
824e7e3adbSDavid Howells #ifdef CONFIG_SMP
834e7e3adbSDavid Howells 	.pushable_tasks	= PLIST_NODE_INIT(init_task.pushable_tasks, MAX_PRIO),
844e7e3adbSDavid Howells #endif
854e7e3adbSDavid Howells #ifdef CONFIG_CGROUP_SCHED
864e7e3adbSDavid Howells 	.sched_task_group = &root_task_group,
874e7e3adbSDavid Howells #endif
88d11ed3abSDavid Howells 	.ptraced	= LIST_HEAD_INIT(init_task.ptraced),
89d11ed3abSDavid Howells 	.ptrace_entry	= LIST_HEAD_INIT(init_task.ptrace_entry),
90d11ed3abSDavid Howells 	.real_parent	= &init_task,
91d11ed3abSDavid Howells 	.parent		= &init_task,
92d11ed3abSDavid Howells 	.children	= LIST_HEAD_INIT(init_task.children),
93d11ed3abSDavid Howells 	.sibling	= LIST_HEAD_INIT(init_task.sibling),
94d11ed3abSDavid Howells 	.group_leader	= &init_task,
95d11ed3abSDavid Howells 	RCU_POINTER_INITIALIZER(real_cred, &init_cred),
96d11ed3abSDavid Howells 	RCU_POINTER_INITIALIZER(cred, &init_cred),
97d11ed3abSDavid Howells 	.comm		= INIT_TASK_COMM,
98d11ed3abSDavid Howells 	.thread		= INIT_THREAD,
99d11ed3abSDavid Howells 	.fs		= &init_fs,
100d11ed3abSDavid Howells 	.files		= &init_files,
101d11ed3abSDavid Howells 	.signal		= &init_signals,
102d11ed3abSDavid Howells 	.sighand	= &init_sighand,
103d11ed3abSDavid Howells 	.nsproxy	= &init_nsproxy,
104d11ed3abSDavid Howells 	.pending	= {
105d11ed3abSDavid Howells 		.list = LIST_HEAD_INIT(init_task.pending.list),
106d11ed3abSDavid Howells 		.signal = {{0}}
107d11ed3abSDavid Howells 	},
108d11ed3abSDavid Howells 	.blocked	= {{0}},
109d11ed3abSDavid Howells 	.alloc_lock	= __SPIN_LOCK_UNLOCKED(init_task.alloc_lock),
110d11ed3abSDavid Howells 	.journal_info	= NULL,
111d11ed3abSDavid Howells 	INIT_CPU_TIMERS(init_task)
112d11ed3abSDavid Howells 	.pi_lock	= __RAW_SPIN_LOCK_UNLOCKED(init_task.pi_lock),
113d11ed3abSDavid Howells 	.timer_slack_ns = 50000, /* 50 usec default slack */
114d11ed3abSDavid Howells 	.pids = {
115d11ed3abSDavid Howells 		[PIDTYPE_PID]  = INIT_PID_LINK(PIDTYPE_PID),
116d11ed3abSDavid Howells 		[PIDTYPE_PGID] = INIT_PID_LINK(PIDTYPE_PGID),
117d11ed3abSDavid Howells 		[PIDTYPE_SID]  = INIT_PID_LINK(PIDTYPE_SID),
118d11ed3abSDavid Howells 	},
119d11ed3abSDavid Howells 	.thread_group	= LIST_HEAD_INIT(init_task.thread_group),
120d11ed3abSDavid Howells 	.thread_node	= LIST_HEAD_INIT(init_signals.thread_head),
1214e7e3adbSDavid Howells #ifdef CONFIG_AUDITSYSCALL
1224e7e3adbSDavid Howells 	.loginuid	= INVALID_UID,
123*f0b75216SRichard Guy Briggs 	.sessionid	= AUDIT_SID_UNSET,
1244e7e3adbSDavid Howells #endif
1254e7e3adbSDavid Howells #ifdef CONFIG_PERF_EVENTS
1264e7e3adbSDavid Howells 	.perf_event_mutex = __MUTEX_INITIALIZER(init_task.perf_event_mutex),
1274e7e3adbSDavid Howells 	.perf_event_list = LIST_HEAD_INIT(init_task.perf_event_list),
1284e7e3adbSDavid Howells #endif
1294e7e3adbSDavid Howells #ifdef CONFIG_PREEMPT_RCU
1304e7e3adbSDavid Howells 	.rcu_read_lock_nesting = 0,
1314e7e3adbSDavid Howells 	.rcu_read_unlock_special.s = 0,
1324e7e3adbSDavid Howells 	.rcu_node_entry = LIST_HEAD_INIT(init_task.rcu_node_entry),
1334e7e3adbSDavid Howells 	.rcu_blocked_node = NULL,
1344e7e3adbSDavid Howells #endif
1354e7e3adbSDavid Howells #ifdef CONFIG_TASKS_RCU
1364e7e3adbSDavid Howells 	.rcu_tasks_holdout = false,
1374e7e3adbSDavid Howells 	.rcu_tasks_holdout_list = LIST_HEAD_INIT(init_task.rcu_tasks_holdout_list),
1384e7e3adbSDavid Howells 	.rcu_tasks_idle_cpu = -1,
1394e7e3adbSDavid Howells #endif
1404e7e3adbSDavid Howells #ifdef CONFIG_CPUSETS
1414e7e3adbSDavid Howells 	.mems_allowed_seq = SEQCNT_ZERO(init_task.mems_allowed_seq),
1424e7e3adbSDavid Howells #endif
1434e7e3adbSDavid Howells #ifdef CONFIG_RT_MUTEXES
1444e7e3adbSDavid Howells 	.pi_waiters	= RB_ROOT_CACHED,
1454e7e3adbSDavid Howells 	.pi_top_task	= NULL,
1464e7e3adbSDavid Howells #endif
147d11ed3abSDavid Howells 	INIT_PREV_CPUTIME(init_task)
1484e7e3adbSDavid Howells #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
1494e7e3adbSDavid Howells 	.vtime.seqcount	= SEQCNT_ZERO(init_task.vtime_seqcount),
1504e7e3adbSDavid Howells 	.vtime.starttime = 0,
1514e7e3adbSDavid Howells 	.vtime.state	= VTIME_SYS,
1524e7e3adbSDavid Howells #endif
1534e7e3adbSDavid Howells #ifdef CONFIG_NUMA_BALANCING
1544e7e3adbSDavid Howells 	.numa_preferred_nid = -1,
1554e7e3adbSDavid Howells 	.numa_group	= NULL,
1564e7e3adbSDavid Howells 	.numa_faults	= NULL,
1574e7e3adbSDavid Howells #endif
1584e7e3adbSDavid Howells #ifdef CONFIG_KASAN
1594e7e3adbSDavid Howells 	.kasan_depth	= 1,
1604e7e3adbSDavid Howells #endif
1614e7e3adbSDavid Howells #ifdef CONFIG_TRACE_IRQFLAGS
1624e7e3adbSDavid Howells 	.softirqs_enabled = 1,
1634e7e3adbSDavid Howells #endif
1644e7e3adbSDavid Howells #ifdef CONFIG_LOCKDEP
1654e7e3adbSDavid Howells 	.lockdep_recursion = 0,
1664e7e3adbSDavid Howells #endif
1674e7e3adbSDavid Howells #ifdef CONFIG_FUNCTION_GRAPH_TRACER
1684e7e3adbSDavid Howells 	.ret_stack	= NULL,
1694e7e3adbSDavid Howells #endif
1704e7e3adbSDavid Howells #if defined(CONFIG_TRACING) && defined(CONFIG_PREEMPT)
1714e7e3adbSDavid Howells 	.trace_recursion = 0,
1724e7e3adbSDavid Howells #endif
1734e7e3adbSDavid Howells #ifdef CONFIG_LIVEPATCH
1744e7e3adbSDavid Howells 	.patch_state	= KLP_UNDEFINED,
1754e7e3adbSDavid Howells #endif
1764e7e3adbSDavid Howells #ifdef CONFIG_SECURITY
1774e7e3adbSDavid Howells 	.security	= NULL,
1784e7e3adbSDavid Howells #endif
179d11ed3abSDavid Howells };
180a4a2eb49SThomas Gleixner EXPORT_SYMBOL(init_task);
181a4a2eb49SThomas Gleixner 
182a4a2eb49SThomas Gleixner /*
183a4a2eb49SThomas Gleixner  * Initial thread structure. Alignment of this is handled by a special
184a4a2eb49SThomas Gleixner  * linker map entry.
185a4a2eb49SThomas Gleixner  */
186c65eacbeSAndy Lutomirski #ifndef CONFIG_THREAD_INFO_IN_TASK
1870500871fSDavid Howells struct thread_info init_thread_info __init_thread_info = INIT_THREAD_INFO(init_task);
188c65eacbeSAndy Lutomirski #endif
189