init_task.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <linux/init_task.h>
  3. #include <linux/export.h>
  4. #include <linux/mqueue.h>
  5. #include <linux/sched.h>
  6. #include <linux/sched/sysctl.h>
  7. #include <linux/sched/rt.h>
  8. #include <linux/sched/task.h>
  9. #include <linux/init.h>
  10. #include <linux/fs.h>
  11. #include <linux/mm.h>
  12. #include <linux/audit.h>
  13. #include <linux/numa.h>
  14. #include <linux/scs.h>
  15. #include <linux/uaccess.h>
  16. static struct signal_struct init_signals = {
  17. .nr_threads = 1,
  18. .thread_head = LIST_HEAD_INIT(init_task.thread_node),
  19. .wait_chldexit = __WAIT_QUEUE_HEAD_INITIALIZER(init_signals.wait_chldexit),
  20. .shared_pending = {
  21. .list = LIST_HEAD_INIT(init_signals.shared_pending.list),
  22. .signal = {{0}}
  23. },
  24. .multiprocess = HLIST_HEAD_INIT,
  25. .rlim = INIT_RLIMITS,
  26. .cred_guard_mutex = __MUTEX_INITIALIZER(init_signals.cred_guard_mutex),
  27. .exec_update_lock = __RWSEM_INITIALIZER(init_signals.exec_update_lock),
  28. #ifdef CONFIG_POSIX_TIMERS
  29. .posix_timers = LIST_HEAD_INIT(init_signals.posix_timers),
  30. .cputimer = {
  31. .cputime_atomic = INIT_CPUTIME_ATOMIC,
  32. },
  33. #endif
  34. INIT_CPU_TIMERS(init_signals)
  35. .pids = {
  36. [PIDTYPE_PID] = &init_struct_pid,
  37. [PIDTYPE_TGID] = &init_struct_pid,
  38. [PIDTYPE_PGID] = &init_struct_pid,
  39. [PIDTYPE_SID] = &init_struct_pid,
  40. },
  41. INIT_PREV_CPUTIME(init_signals)
  42. };
  43. static struct sighand_struct init_sighand = {
  44. .count = REFCOUNT_INIT(1),
  45. .action = { { { .sa_handler = SIG_DFL, } }, },
  46. .siglock = __SPIN_LOCK_UNLOCKED(init_sighand.siglock),
  47. .signalfd_wqh = __WAIT_QUEUE_HEAD_INITIALIZER(init_sighand.signalfd_wqh),
  48. };
  49. #ifdef CONFIG_SHADOW_CALL_STACK
  50. unsigned long init_shadow_call_stack[SCS_SIZE / sizeof(long)]
  51. __init_task_data = {
  52. [(SCS_SIZE / sizeof(long)) - 1] = SCS_END_MAGIC
  53. };
  54. #endif
  55. /*
  56. * Set up the first task table, touch at your own risk!. Base=0,
  57. * limit=0x1fffff (=2MB)
  58. */
  59. struct task_struct init_task
  60. #ifdef CONFIG_ARCH_TASK_STRUCT_ON_STACK
  61. __init_task_data
  62. #endif
  63. __aligned(L1_CACHE_BYTES)
  64. = {
  65. #ifdef CONFIG_THREAD_INFO_IN_TASK
  66. .thread_info = INIT_THREAD_INFO(init_task),
  67. .stack_refcount = REFCOUNT_INIT(1),
  68. #endif
  69. .state = 0,
  70. .stack = init_stack,
  71. .usage = REFCOUNT_INIT(2),
  72. .flags = PF_KTHREAD,
  73. .prio = MAX_PRIO - 20,
  74. .static_prio = MAX_PRIO - 20,
  75. .normal_prio = MAX_PRIO - 20,
  76. .policy = SCHED_NORMAL,
  77. .cpus_ptr = &init_task.cpus_mask,
  78. .cpus_mask = CPU_MASK_ALL,
  79. .nr_cpus_allowed= NR_CPUS,
  80. .mm = NULL,
  81. .active_mm = &init_mm,
  82. .restart_block = {
  83. .fn = do_no_restart_syscall,
  84. },
  85. .se = {
  86. .group_node = LIST_HEAD_INIT(init_task.se.group_node),
  87. },
  88. .rt = {
  89. .run_list = LIST_HEAD_INIT(init_task.rt.run_list),
  90. .time_slice = RR_TIMESLICE,
  91. },
  92. .tasks = LIST_HEAD_INIT(init_task.tasks),
  93. #ifdef CONFIG_SMP
  94. .pushable_tasks = PLIST_NODE_INIT(init_task.pushable_tasks, MAX_PRIO),
  95. #endif
  96. #ifdef CONFIG_CGROUP_SCHED
  97. .sched_task_group = &root_task_group,
  98. #endif
  99. .ptraced = LIST_HEAD_INIT(init_task.ptraced),
  100. .ptrace_entry = LIST_HEAD_INIT(init_task.ptrace_entry),
  101. .real_parent = &init_task,
  102. .parent = &init_task,
  103. .children = LIST_HEAD_INIT(init_task.children),
  104. .sibling = LIST_HEAD_INIT(init_task.sibling),
  105. .group_leader = &init_task,
  106. RCU_POINTER_INITIALIZER(real_cred, &init_cred),
  107. RCU_POINTER_INITIALIZER(cred, &init_cred),
  108. .comm = INIT_TASK_COMM,
  109. .thread = INIT_THREAD,
  110. .fs = &init_fs,
  111. .files = &init_files,
  112. #ifdef CONFIG_IO_URING
  113. .io_uring = NULL,
  114. #endif
  115. .signal = &init_signals,
  116. .sighand = &init_sighand,
  117. .nsproxy = &init_nsproxy,
  118. .pending = {
  119. .list = LIST_HEAD_INIT(init_task.pending.list),
  120. .signal = {{0}}
  121. },
  122. .blocked = {{0}},
  123. .alloc_lock = __SPIN_LOCK_UNLOCKED(init_task.alloc_lock),
  124. .journal_info = NULL,
  125. INIT_CPU_TIMERS(init_task)
  126. .pi_lock = __RAW_SPIN_LOCK_UNLOCKED(init_task.pi_lock),
  127. .timer_slack_ns = 50000, /* 50 usec default slack */
  128. .thread_pid = &init_struct_pid,
  129. .thread_group = LIST_HEAD_INIT(init_task.thread_group),
  130. .thread_node = LIST_HEAD_INIT(init_signals.thread_head),
  131. #ifdef CONFIG_AUDIT
  132. .loginuid = INVALID_UID,
  133. .sessionid = AUDIT_SID_UNSET,
  134. #endif
  135. #ifdef CONFIG_PERF_EVENTS
  136. .perf_event_mutex = __MUTEX_INITIALIZER(init_task.perf_event_mutex),
  137. .perf_event_list = LIST_HEAD_INIT(init_task.perf_event_list),
  138. #endif
  139. #ifdef CONFIG_PREEMPT_RCU
  140. .rcu_read_lock_nesting = 0,
  141. .rcu_read_unlock_special.s = 0,
  142. .rcu_node_entry = LIST_HEAD_INIT(init_task.rcu_node_entry),
  143. .rcu_blocked_node = NULL,
  144. #endif
  145. #ifdef CONFIG_TASKS_RCU
  146. .rcu_tasks_holdout = false,
  147. .rcu_tasks_holdout_list = LIST_HEAD_INIT(init_task.rcu_tasks_holdout_list),
  148. .rcu_tasks_idle_cpu = -1,
  149. #endif
  150. #ifdef CONFIG_TASKS_TRACE_RCU
  151. .trc_reader_nesting = 0,
  152. .trc_reader_special.s = 0,
  153. .trc_holdout_list = LIST_HEAD_INIT(init_task.trc_holdout_list),
  154. #endif
  155. #ifdef CONFIG_CPUSETS
  156. .mems_allowed_seq = SEQCNT_SPINLOCK_ZERO(init_task.mems_allowed_seq,
  157. &init_task.alloc_lock),
  158. #endif
  159. #ifdef CONFIG_RT_MUTEXES
  160. .pi_waiters = RB_ROOT_CACHED,
  161. .pi_top_task = NULL,
  162. #endif
  163. INIT_PREV_CPUTIME(init_task)
  164. #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
  165. .vtime.seqcount = SEQCNT_ZERO(init_task.vtime_seqcount),
  166. .vtime.starttime = 0,
  167. .vtime.state = VTIME_SYS,
  168. #endif
  169. #ifdef CONFIG_NUMA_BALANCING
  170. .numa_preferred_nid = NUMA_NO_NODE,
  171. .numa_group = NULL,
  172. .numa_faults = NULL,
  173. #endif
  174. #if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)
  175. .kasan_depth = 1,
  176. #endif
  177. #ifdef CONFIG_KCSAN
  178. .kcsan_ctx = {
  179. .disable_count = 0,
  180. .atomic_next = 0,
  181. .atomic_nest_count = 0,
  182. .in_flat_atomic = false,
  183. .access_mask = 0,
  184. .scoped_accesses = {LIST_POISON1, NULL},
  185. },
  186. #endif
  187. #ifdef CONFIG_TRACE_IRQFLAGS
  188. .softirqs_enabled = 1,
  189. #endif
  190. #ifdef CONFIG_LOCKDEP
  191. .lockdep_depth = 0, /* no locks held yet */
  192. .curr_chain_key = INITIAL_CHAIN_KEY,
  193. .lockdep_recursion = 0,
  194. #endif
  195. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  196. .ret_stack = NULL,
  197. .tracing_graph_pause = ATOMIC_INIT(0),
  198. #endif
  199. #if defined(CONFIG_TRACING) && defined(CONFIG_PREEMPTION)
  200. .trace_recursion = 0,
  201. #endif
  202. #ifdef CONFIG_LIVEPATCH
  203. .patch_state = KLP_UNDEFINED,
  204. #endif
  205. #ifdef CONFIG_SECURITY
  206. .security = NULL,
  207. #endif
  208. #ifdef CONFIG_SECCOMP_FILTER
  209. .seccomp = { .filter_count = ATOMIC_INIT(0) },
  210. #endif
  211. #ifdef CONFIG_ANDROID_VENDOR_OEM_DATA
  212. .android_vendor_data1 = {0, },
  213. .android_oem_data1 = {0, },
  214. #endif
  215. };
  216. EXPORT_SYMBOL(init_task);
  217. /*
  218. * Initial thread structure. Alignment of this is handled by a special
  219. * linker map entry.
  220. */
  221. #ifndef CONFIG_THREAD_INFO_IN_TASK
  222. struct thread_info init_thread_info __init_thread_info = INIT_THREAD_INFO(init_task);
  223. #endif