xref: /linux-6.15/init/init_task.c (revision 69f032c9)
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>
9f0e1a064STejun Heo #include <linux/sched/ext.h>
10a4a2eb49SThomas Gleixner #include <linux/init.h>
11a4a2eb49SThomas Gleixner #include <linux/fs.h>
12a4a2eb49SThomas Gleixner #include <linux/mm.h>
13f0b75216SRichard Guy Briggs #include <linux/audit.h>
1498fa15f3SAnshuman Khandual #include <linux/numa.h>
15d08b9f0cSSami Tolvanen #include <linux/scs.h>
168b7787a5SKent Overstreet #include <linux/plist.h>
17a4a2eb49SThomas Gleixner 
187c0f6ba6SLinus Torvalds #include <linux/uaccess.h>
19a4a2eb49SThomas Gleixner 
203678e2fcSDavid Howells static struct signal_struct init_signals = {
213678e2fcSDavid Howells 	.nr_threads	= 1,
223678e2fcSDavid Howells 	.thread_head	= LIST_HEAD_INIT(init_task.thread_node),
233678e2fcSDavid Howells 	.wait_chldexit	= __WAIT_QUEUE_HEAD_INITIALIZER(init_signals.wait_chldexit),
243678e2fcSDavid Howells 	.shared_pending	= {
253678e2fcSDavid Howells 		.list = LIST_HEAD_INIT(init_signals.shared_pending.list),
263678e2fcSDavid Howells 		.signal =  {{0}}
273678e2fcSDavid Howells 	},
28c3ad2c3bSEric W. Biederman 	.multiprocess	= HLIST_HEAD_INIT,
293678e2fcSDavid Howells 	.rlim		= INIT_RLIMITS,
303678e2fcSDavid Howells 	.cred_guard_mutex = __MUTEX_INITIALIZER(init_signals.cred_guard_mutex),
31f7cfd871SEric W. Biederman 	.exec_update_lock = __RWSEM_INITIALIZER(init_signals.exec_update_lock),
323678e2fcSDavid Howells #ifdef CONFIG_POSIX_TIMERS
3352dea0a1SThomas Gleixner 	.posix_timers		= HLIST_HEAD_INIT,
34*69f032c9SThomas Gleixner 	.ignored_posix_timers	= HLIST_HEAD_INIT,
353678e2fcSDavid Howells 	.cputimer		= {
363678e2fcSDavid Howells 		.cputime_atomic	= INIT_CPUTIME_ATOMIC,
373678e2fcSDavid Howells 	},
383678e2fcSDavid Howells #endif
393678e2fcSDavid Howells 	INIT_CPU_TIMERS(init_signals)
402c470475SEric W. Biederman 	.pids = {
412c470475SEric W. Biederman 		[PIDTYPE_PID]	= &init_struct_pid,
426883f81aSEric W. Biederman 		[PIDTYPE_TGID]	= &init_struct_pid,
432c470475SEric W. Biederman 		[PIDTYPE_PGID]	= &init_struct_pid,
442c470475SEric W. Biederman 		[PIDTYPE_SID]	= &init_struct_pid,
452c470475SEric W. Biederman 	},
463678e2fcSDavid Howells 	INIT_PREV_CPUTIME(init_signals)
473678e2fcSDavid Howells };
483678e2fcSDavid Howells 
493678e2fcSDavid Howells static struct sighand_struct init_sighand = {
5060d4de3fSElena Reshetova 	.count		= REFCOUNT_INIT(1),
513678e2fcSDavid Howells 	.action		= { { { .sa_handler = SIG_DFL, } }, },
523678e2fcSDavid Howells 	.siglock	= __SPIN_LOCK_UNLOCKED(init_sighand.siglock),
533678e2fcSDavid Howells 	.signalfd_wqh	= __WAIT_QUEUE_HEAD_INITIALIZER(init_sighand.signalfd_wqh),
543678e2fcSDavid Howells };
55a4a2eb49SThomas Gleixner 
56d08b9f0cSSami Tolvanen #ifdef CONFIG_SHADOW_CALL_STACK
570eb5085cSHeiko Carstens unsigned long init_shadow_call_stack[SCS_SIZE / sizeof(long)] = {
58d08b9f0cSSami Tolvanen 	[(SCS_SIZE / sizeof(long)) - 1] = SCS_END_MAGIC
59d08b9f0cSSami Tolvanen };
60d08b9f0cSSami Tolvanen #endif
61d08b9f0cSSami Tolvanen 
62d11ed3abSDavid Howells /*
63d11ed3abSDavid Howells  * Set up the first task table, touch at your own risk!. Base=0,
64d11ed3abSDavid Howells  * limit=0x1fffff (=2MB)
65d11ed3abSDavid Howells  */
660eb5085cSHeiko Carstens struct task_struct init_task __aligned(L1_CACHE_BYTES) = {
674e7e3adbSDavid Howells #ifdef CONFIG_THREAD_INFO_IN_TASK
684e7e3adbSDavid Howells 	.thread_info	= INIT_THREAD_INFO(init_task),
69f0b89d39SElena Reshetova 	.stack_refcount	= REFCOUNT_INIT(1),
704e7e3adbSDavid Howells #endif
712f064a59SPeter Zijlstra 	.__state	= 0,
72d11ed3abSDavid Howells 	.stack		= init_stack,
73ec1d2819SElena Reshetova 	.usage		= REFCOUNT_INIT(2),
74d11ed3abSDavid Howells 	.flags		= PF_KTHREAD,
75d11ed3abSDavid Howells 	.prio		= MAX_PRIO - 20,
76d11ed3abSDavid Howells 	.static_prio	= MAX_PRIO - 20,
77d11ed3abSDavid Howells 	.normal_prio	= MAX_PRIO - 20,
78d11ed3abSDavid Howells 	.policy		= SCHED_NORMAL,
793bd37062SSebastian Andrzej Siewior 	.cpus_ptr	= &init_task.cpus_mask,
80b90ca8baSWill Deacon 	.user_cpus_ptr	= NULL,
813bd37062SSebastian Andrzej Siewior 	.cpus_mask	= CPU_MASK_ALL,
8222d56074SQais Yousef 	.max_allowed_capacity	= SCHED_CAPACITY_SCALE,
83d11ed3abSDavid Howells 	.nr_cpus_allowed= NR_CPUS,
84d11ed3abSDavid Howells 	.mm		= NULL,
85d11ed3abSDavid Howells 	.active_mm	= &init_mm,
862b69987bSKent Overstreet 	.faults_disabled_mapping = NULL,
87d11ed3abSDavid Howells 	.restart_block	= {
88d11ed3abSDavid Howells 		.fn = do_no_restart_syscall,
89d11ed3abSDavid Howells 	},
90d11ed3abSDavid Howells 	.se		= {
91d11ed3abSDavid Howells 		.group_node 	= LIST_HEAD_INIT(init_task.se.group_node),
92d11ed3abSDavid Howells 	},
93d11ed3abSDavid Howells 	.rt		= {
94d11ed3abSDavid Howells 		.run_list	= LIST_HEAD_INIT(init_task.rt.run_list),
95d11ed3abSDavid Howells 		.time_slice	= RR_TIMESLICE,
96d11ed3abSDavid Howells 	},
97d11ed3abSDavid Howells 	.tasks		= LIST_HEAD_INIT(init_task.tasks),
984e7e3adbSDavid Howells #ifdef CONFIG_SMP
994e7e3adbSDavid Howells 	.pushable_tasks	= PLIST_NODE_INIT(init_task.pushable_tasks, MAX_PRIO),
1004e7e3adbSDavid Howells #endif
1014e7e3adbSDavid Howells #ifdef CONFIG_CGROUP_SCHED
1024e7e3adbSDavid Howells 	.sched_task_group = &root_task_group,
1034e7e3adbSDavid Howells #endif
104f0e1a064STejun Heo #ifdef CONFIG_SCHED_CLASS_EXT
105f0e1a064STejun Heo 	.scx		= {
106d4af01c3STejun Heo 		.dsq_list.node	= LIST_HEAD_INIT(init_task.scx.dsq_list.node),
107f0e1a064STejun Heo 		.sticky_cpu	= -1,
108f0e1a064STejun Heo 		.holding_cpu	= -1,
109f0e1a064STejun Heo 		.runnable_node	= LIST_HEAD_INIT(init_task.scx.runnable_node),
1108a010b81SDavid Vernet 		.runnable_at	= INITIAL_JIFFIES,
111f0e1a064STejun Heo 		.ddsp_dsq_id	= SCX_DSQ_INVALID,
112f0e1a064STejun Heo 		.slice		= SCX_SLICE_DFL,
113f0e1a064STejun Heo 	},
114f0e1a064STejun Heo #endif
115d11ed3abSDavid Howells 	.ptraced	= LIST_HEAD_INIT(init_task.ptraced),
116d11ed3abSDavid Howells 	.ptrace_entry	= LIST_HEAD_INIT(init_task.ptrace_entry),
117d11ed3abSDavid Howells 	.real_parent	= &init_task,
118d11ed3abSDavid Howells 	.parent		= &init_task,
119d11ed3abSDavid Howells 	.children	= LIST_HEAD_INIT(init_task.children),
120d11ed3abSDavid Howells 	.sibling	= LIST_HEAD_INIT(init_task.sibling),
121d11ed3abSDavid Howells 	.group_leader	= &init_task,
122d11ed3abSDavid Howells 	RCU_POINTER_INITIALIZER(real_cred, &init_cred),
123d11ed3abSDavid Howells 	RCU_POINTER_INITIALIZER(cred, &init_cred),
124d11ed3abSDavid Howells 	.comm		= INIT_TASK_COMM,
125d11ed3abSDavid Howells 	.thread		= INIT_THREAD,
126d11ed3abSDavid Howells 	.fs		= &init_fs,
127d11ed3abSDavid Howells 	.files		= &init_files,
1280f212204SJens Axboe #ifdef CONFIG_IO_URING
1290f212204SJens Axboe 	.io_uring	= NULL,
1300f212204SJens Axboe #endif
131d11ed3abSDavid Howells 	.signal		= &init_signals,
132d11ed3abSDavid Howells 	.sighand	= &init_sighand,
133d11ed3abSDavid Howells 	.nsproxy	= &init_nsproxy,
134d11ed3abSDavid Howells 	.pending	= {
135d11ed3abSDavid Howells 		.list = LIST_HEAD_INIT(init_task.pending.list),
136d11ed3abSDavid Howells 		.signal = {{0}}
137d11ed3abSDavid Howells 	},
138d11ed3abSDavid Howells 	.blocked	= {{0}},
139d11ed3abSDavid Howells 	.alloc_lock	= __SPIN_LOCK_UNLOCKED(init_task.alloc_lock),
140d11ed3abSDavid Howells 	.journal_info	= NULL,
141d11ed3abSDavid Howells 	INIT_CPU_TIMERS(init_task)
142d11ed3abSDavid Howells 	.pi_lock	= __RAW_SPIN_LOCK_UNLOCKED(init_task.pi_lock),
143d11ed3abSDavid Howells 	.timer_slack_ns = 50000, /* 50 usec default slack */
1442c470475SEric W. Biederman 	.thread_pid	= &init_struct_pid,
145d11ed3abSDavid Howells 	.thread_node	= LIST_HEAD_INIT(init_signals.thread_head),
1464b7d248bSRichard Guy Briggs #ifdef CONFIG_AUDIT
1474e7e3adbSDavid Howells 	.loginuid	= INVALID_UID,
148f0b75216SRichard Guy Briggs 	.sessionid	= AUDIT_SID_UNSET,
1494e7e3adbSDavid Howells #endif
1504e7e3adbSDavid Howells #ifdef CONFIG_PERF_EVENTS
1514e7e3adbSDavid Howells 	.perf_event_mutex = __MUTEX_INITIALIZER(init_task.perf_event_mutex),
1524e7e3adbSDavid Howells 	.perf_event_list = LIST_HEAD_INIT(init_task.perf_event_list),
1534e7e3adbSDavid Howells #endif
1544e7e3adbSDavid Howells #ifdef CONFIG_PREEMPT_RCU
1554e7e3adbSDavid Howells 	.rcu_read_lock_nesting = 0,
1564e7e3adbSDavid Howells 	.rcu_read_unlock_special.s = 0,
1574e7e3adbSDavid Howells 	.rcu_node_entry = LIST_HEAD_INIT(init_task.rcu_node_entry),
1584e7e3adbSDavid Howells 	.rcu_blocked_node = NULL,
1594e7e3adbSDavid Howells #endif
1604e7e3adbSDavid Howells #ifdef CONFIG_TASKS_RCU
1614e7e3adbSDavid Howells 	.rcu_tasks_holdout = false,
1624e7e3adbSDavid Howells 	.rcu_tasks_holdout_list = LIST_HEAD_INIT(init_task.rcu_tasks_holdout_list),
1634e7e3adbSDavid Howells 	.rcu_tasks_idle_cpu = -1,
16446faf9d8SPaul E. McKenney 	.rcu_tasks_exit_list = LIST_HEAD_INIT(init_task.rcu_tasks_exit_list),
1654e7e3adbSDavid Howells #endif
166d5f177d3SPaul E. McKenney #ifdef CONFIG_TASKS_TRACE_RCU
167d5f177d3SPaul E. McKenney 	.trc_reader_nesting = 0,
168276c4104SPaul E. McKenney 	.trc_reader_special.s = 0,
169d5f177d3SPaul E. McKenney 	.trc_holdout_list = LIST_HEAD_INIT(init_task.trc_holdout_list),
170434c9eefSPaul E. McKenney 	.trc_blkd_node = LIST_HEAD_INIT(init_task.trc_blkd_node),
171d5f177d3SPaul E. McKenney #endif
1724e7e3adbSDavid Howells #ifdef CONFIG_CPUSETS
173b7505861SAhmed S. Darwish 	.mems_allowed_seq = SEQCNT_SPINLOCK_ZERO(init_task.mems_allowed_seq,
174b7505861SAhmed S. Darwish 						 &init_task.alloc_lock),
1754e7e3adbSDavid Howells #endif
1764e7e3adbSDavid Howells #ifdef CONFIG_RT_MUTEXES
1774e7e3adbSDavid Howells 	.pi_waiters	= RB_ROOT_CACHED,
1784e7e3adbSDavid Howells 	.pi_top_task	= NULL,
1794e7e3adbSDavid Howells #endif
180d11ed3abSDavid Howells 	INIT_PREV_CPUTIME(init_task)
1814e7e3adbSDavid Howells #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
1824e7e3adbSDavid Howells 	.vtime.seqcount	= SEQCNT_ZERO(init_task.vtime_seqcount),
1834e7e3adbSDavid Howells 	.vtime.starttime = 0,
1844e7e3adbSDavid Howells 	.vtime.state	= VTIME_SYS,
1854e7e3adbSDavid Howells #endif
1864e7e3adbSDavid Howells #ifdef CONFIG_NUMA_BALANCING
18798fa15f3SAnshuman Khandual 	.numa_preferred_nid = NUMA_NO_NODE,
1884e7e3adbSDavid Howells 	.numa_group	= NULL,
1894e7e3adbSDavid Howells 	.numa_faults	= NULL,
1904e7e3adbSDavid Howells #endif
191d73b4936SAndrey Konovalov #if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)
1924e7e3adbSDavid Howells 	.kasan_depth	= 1,
1934e7e3adbSDavid Howells #endif
194dfd402a4SMarco Elver #ifdef CONFIG_KCSAN
195dfd402a4SMarco Elver 	.kcsan_ctx = {
196757a4cefSMarco Elver 		.scoped_accesses	= {LIST_POISON1, NULL},
197dfd402a4SMarco Elver 	},
198dfd402a4SMarco Elver #endif
1994e7e3adbSDavid Howells #ifdef CONFIG_TRACE_IRQFLAGS
2004e7e3adbSDavid Howells 	.softirqs_enabled = 1,
2014e7e3adbSDavid Howells #endif
2024e7e3adbSDavid Howells #ifdef CONFIG_LOCKDEP
203e196e479SYuyang Du 	.lockdep_depth = 0, /* no locks held yet */
204f6ec8829SYuyang Du 	.curr_chain_key = INITIAL_CHAIN_KEY,
2054e7e3adbSDavid Howells 	.lockdep_recursion = 0,
2064e7e3adbSDavid Howells #endif
2074e7e3adbSDavid Howells #ifdef CONFIG_FUNCTION_GRAPH_TRACER
2084e7e3adbSDavid Howells 	.ret_stack		= NULL,
2097e0a9220SSteven Rostedt (VMware) 	.tracing_graph_pause	= ATOMIC_INIT(0),
2104e7e3adbSDavid Howells #endif
211c1a280b6SThomas Gleixner #if defined(CONFIG_TRACING) && defined(CONFIG_PREEMPTION)
2124e7e3adbSDavid Howells 	.trace_recursion = 0,
2134e7e3adbSDavid Howells #endif
2144e7e3adbSDavid Howells #ifdef CONFIG_LIVEPATCH
215d927752fSWardenjohn 	.patch_state	= KLP_TRANSITION_IDLE,
2164e7e3adbSDavid Howells #endif
2174e7e3adbSDavid Howells #ifdef CONFIG_SECURITY
2184e7e3adbSDavid Howells 	.security	= NULL,
2194e7e3adbSDavid Howells #endif
22064bdc024S[email protected] #ifdef CONFIG_SECCOMP_FILTER
221c818c03bSKees Cook 	.seccomp	= { .filter_count = ATOMIC_INIT(0) },
222c818c03bSKees Cook #endif
223d11ed3abSDavid Howells };
224a4a2eb49SThomas Gleixner EXPORT_SYMBOL(init_task);
225a4a2eb49SThomas Gleixner 
226a4a2eb49SThomas Gleixner /*
227a4a2eb49SThomas Gleixner  * Initial thread structure. Alignment of this is handled by a special
228a4a2eb49SThomas Gleixner  * linker map entry.
229a4a2eb49SThomas Gleixner  */
230c65eacbeSAndy Lutomirski #ifndef CONFIG_THREAD_INFO_IN_TASK
2310500871fSDavid Howells struct thread_info init_thread_info __init_thread_info = INIT_THREAD_INFO(init_task);
232c65eacbeSAndy Lutomirski #endif
233