1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef _LINUX__INIT_TASK_H 3 #define _LINUX__INIT_TASK_H 4 5 #include <linux/rcupdate.h> 6 #include <linux/irqflags.h> 7 #include <linux/utsname.h> 8 #include <linux/lockdep.h> 9 #include <linux/ftrace.h> 10 #include <linux/ipc.h> 11 #include <linux/pid_namespace.h> 12 #include <linux/user_namespace.h> 13 #include <linux/securebits.h> 14 #include <linux/seqlock.h> 15 #include <linux/rbtree.h> 16 #include <linux/sched/autogroup.h> 17 #include <net/net_namespace.h> 18 #include <linux/sched/rt.h> 19 #include <linux/livepatch.h> 20 #include <linux/mm_types.h> 21 22 #include <asm/thread_info.h> 23 24 #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 31 extern struct files_struct init_files; 32 extern struct fs_struct init_fs; 33 34 #ifdef CONFIG_CPUSETS 35 #define INIT_CPUSET_SEQ(tsk) \ 36 .mems_allowed_seq = SEQCNT_ZERO(tsk.mems_allowed_seq), 37 #else 38 #define INIT_CPUSET_SEQ(tsk) 39 #endif 40 41 #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 49 #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 70 #define INIT_SIGNALS(sig) { \ 71 .nr_threads = 1, \ 72 .thread_head = LIST_HEAD_INIT(init_task.thread_node), \ 73 .wait_chldexit = __WAIT_QUEUE_HEAD_INITIALIZER(sig.wait_chldexit),\ 74 .shared_pending = { \ 75 .list = LIST_HEAD_INIT(sig.shared_pending.list), \ 76 .signal = {{0}}}, \ 77 INIT_POSIX_TIMERS(sig) \ 78 INIT_CPU_TIMERS(sig) \ 79 .rlim = INIT_RLIMITS, \ 80 INIT_CPUTIMER(sig) \ 81 INIT_PREV_CPUTIME(sig) \ 82 .cred_guard_mutex = \ 83 __MUTEX_INITIALIZER(sig.cred_guard_mutex), \ 84 } 85 86 extern struct nsproxy init_nsproxy; 87 88 #define INIT_SIGHAND(sighand) { \ 89 .count = ATOMIC_INIT(1), \ 90 .action = { { { .sa_handler = SIG_DFL, } }, }, \ 91 .siglock = __SPIN_LOCK_UNLOCKED(sighand.siglock), \ 92 .signalfd_wqh = __WAIT_QUEUE_HEAD_INITIALIZER(sighand.signalfd_wqh), \ 93 } 94 95 extern struct group_info init_groups; 96 97 #define INIT_STRUCT_PID { \ 98 .count = ATOMIC_INIT(1), \ 99 .tasks = { \ 100 { .first = NULL }, \ 101 { .first = NULL }, \ 102 { .first = NULL }, \ 103 }, \ 104 .level = 0, \ 105 .numbers = { { \ 106 .nr = 0, \ 107 .ns = &init_pid_ns, \ 108 }, } \ 109 } 110 111 #define INIT_PID_LINK(type) \ 112 { \ 113 .node = { \ 114 .next = NULL, \ 115 .pprev = NULL, \ 116 }, \ 117 .pid = &init_struct_pid, \ 118 } 119 120 #ifdef CONFIG_AUDITSYSCALL 121 #define INIT_IDS \ 122 .loginuid = INVALID_UID, \ 123 .sessionid = (unsigned int)-1, 124 #else 125 #define INIT_IDS 126 #endif 127 128 #ifdef CONFIG_PREEMPT_RCU 129 #define INIT_TASK_RCU_PREEMPT(tsk) \ 130 .rcu_read_lock_nesting = 0, \ 131 .rcu_read_unlock_special.s = 0, \ 132 .rcu_node_entry = LIST_HEAD_INIT(tsk.rcu_node_entry), \ 133 .rcu_blocked_node = NULL, 134 #else 135 #define INIT_TASK_RCU_PREEMPT(tsk) 136 #endif 137 #ifdef CONFIG_TASKS_RCU 138 #define INIT_TASK_RCU_TASKS(tsk) \ 139 .rcu_tasks_holdout = false, \ 140 .rcu_tasks_holdout_list = \ 141 LIST_HEAD_INIT(tsk.rcu_tasks_holdout_list), \ 142 .rcu_tasks_idle_cpu = -1, 143 #else 144 #define INIT_TASK_RCU_TASKS(tsk) 145 #endif 146 147 extern struct cred init_cred; 148 149 #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 156 #ifdef CONFIG_PERF_EVENTS 157 # define INIT_PERF_EVENTS(tsk) \ 158 .perf_event_mutex = \ 159 __MUTEX_INITIALIZER(tsk.perf_event_mutex), \ 160 .perf_event_list = LIST_HEAD_INIT(tsk.perf_event_list), 161 #else 162 # define INIT_PERF_EVENTS(tsk) 163 #endif 164 165 #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN 166 # define INIT_VTIME(tsk) \ 167 .vtime.seqcount = SEQCNT_ZERO(tsk.vtime.seqcount), \ 168 .vtime.starttime = 0, \ 169 .vtime.state = VTIME_SYS, 170 #else 171 # define INIT_VTIME(tsk) 172 #endif 173 174 #define INIT_TASK_COMM "swapper" 175 176 #ifdef CONFIG_RT_MUTEXES 177 # define INIT_RT_MUTEXES(tsk) \ 178 .pi_waiters = RB_ROOT_CACHED, \ 179 .pi_top_task = NULL, 180 #else 181 # define INIT_RT_MUTEXES(tsk) 182 #endif 183 184 #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 193 #ifdef CONFIG_KASAN 194 # define INIT_KASAN(tsk) \ 195 .kasan_depth = 1, 196 #else 197 # define INIT_KASAN(tsk) 198 #endif 199 200 #ifdef CONFIG_LIVEPATCH 201 # define INIT_LIVEPATCH(tsk) \ 202 .patch_state = KLP_UNDEFINED, 203 #else 204 # define INIT_LIVEPATCH(tsk) 205 #endif 206 207 #ifdef CONFIG_THREAD_INFO_IN_TASK 208 # define INIT_TASK_TI(tsk) \ 209 .thread_info = INIT_THREAD_INFO(tsk), \ 210 .stack_refcount = ATOMIC_INIT(1), 211 #else 212 # define INIT_TASK_TI(tsk) 213 #endif 214 215 #ifdef CONFIG_SECURITY 216 #define INIT_TASK_SECURITY .security = NULL, 217 #else 218 #define INIT_TASK_SECURITY 219 #endif 220 221 /* Attach to the init_task data structure for proper alignment */ 222 #ifdef CONFIG_ARCH_TASK_STRUCT_ON_STACK 223 #define __init_task_data __attribute__((__section__(".data..init_task"))) 224 #else 225 #define __init_task_data /**/ 226 #endif 227 228 /* Attach to the thread_info data structure for proper alignment */ 229 #define __init_thread_info __attribute__((__section__(".data..init_thread_info"))) 230 231 232 #endif 233