init_task.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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 <asm/pgtable.h>
  13. #include <linux/uaccess.h>
  14. static struct signal_struct init_signals = {
  15. .nr_threads = 1,
  16. .thread_head = LIST_HEAD_INIT(init_task.thread_node),
  17. .wait_chldexit = __WAIT_QUEUE_HEAD_INITIALIZER(init_signals.wait_chldexit),
  18. .shared_pending = {
  19. .list = LIST_HEAD_INIT(init_signals.shared_pending.list),
  20. .signal = {{0}}
  21. },
  22. .rlim = INIT_RLIMITS,
  23. .cred_guard_mutex = __MUTEX_INITIALIZER(init_signals.cred_guard_mutex),
  24. #ifdef CONFIG_POSIX_TIMERS
  25. .posix_timers = LIST_HEAD_INIT(init_signals.posix_timers),
  26. .cputimer = {
  27. .cputime_atomic = INIT_CPUTIME_ATOMIC,
  28. .running = false,
  29. .checking_timer = false,
  30. },
  31. #endif
  32. INIT_CPU_TIMERS(init_signals)
  33. INIT_PREV_CPUTIME(init_signals)
  34. };
  35. static struct sighand_struct init_sighand = {
  36. .count = ATOMIC_INIT(1),
  37. .action = { { { .sa_handler = SIG_DFL, } }, },
  38. .siglock = __SPIN_LOCK_UNLOCKED(init_sighand.siglock),
  39. .signalfd_wqh = __WAIT_QUEUE_HEAD_INITIALIZER(init_sighand.signalfd_wqh),
  40. };
  41. /*
  42. * Set up the first task table, touch at your own risk!. Base=0,
  43. * limit=0x1fffff (=2MB)
  44. */
  45. struct task_struct init_task
  46. #ifdef CONFIG_ARCH_TASK_STRUCT_ON_STACK
  47. __init_task_data
  48. #endif
  49. = {
  50. #ifdef CONFIG_THREAD_INFO_IN_TASK
  51. .thread_info = INIT_THREAD_INFO(init_task),
  52. .stack_refcount = ATOMIC_INIT(1),
  53. #endif
  54. .state = 0,
  55. .stack = init_stack,
  56. .usage = ATOMIC_INIT(2),
  57. .flags = PF_KTHREAD,
  58. .prio = MAX_PRIO - 20,
  59. .static_prio = MAX_PRIO - 20,
  60. .normal_prio = MAX_PRIO - 20,
  61. .policy = SCHED_NORMAL,
  62. .cpus_allowed = CPU_MASK_ALL,
  63. .nr_cpus_allowed= NR_CPUS,
  64. .mm = NULL,
  65. .active_mm = &init_mm,
  66. .restart_block = {
  67. .fn = do_no_restart_syscall,
  68. },
  69. .se = {
  70. .group_node = LIST_HEAD_INIT(init_task.se.group_node),
  71. },
  72. .rt = {
  73. .run_list = LIST_HEAD_INIT(init_task.rt.run_list),
  74. .time_slice = RR_TIMESLICE,
  75. },
  76. .tasks = LIST_HEAD_INIT(init_task.tasks),
  77. #ifdef CONFIG_SMP
  78. .pushable_tasks = PLIST_NODE_INIT(init_task.pushable_tasks, MAX_PRIO),
  79. #endif
  80. #ifdef CONFIG_CGROUP_SCHED
  81. .sched_task_group = &root_task_group,
  82. #endif
  83. .ptraced = LIST_HEAD_INIT(init_task.ptraced),
  84. .ptrace_entry = LIST_HEAD_INIT(init_task.ptrace_entry),
  85. .real_parent = &init_task,
  86. .parent = &init_task,
  87. .children = LIST_HEAD_INIT(init_task.children),
  88. .sibling = LIST_HEAD_INIT(init_task.sibling),
  89. .group_leader = &init_task,
  90. RCU_POINTER_INITIALIZER(real_cred, &init_cred),
  91. RCU_POINTER_INITIALIZER(cred, &init_cred),
  92. .comm = INIT_TASK_COMM,
  93. .thread = INIT_THREAD,
  94. .fs = &init_fs,
  95. .files = &init_files,
  96. .signal = &init_signals,
  97. .sighand = &init_sighand,
  98. .nsproxy = &init_nsproxy,
  99. .pending = {
  100. .list = LIST_HEAD_INIT(init_task.pending.list),
  101. .signal = {{0}}
  102. },
  103. .blocked = {{0}},
  104. .alloc_lock = __SPIN_LOCK_UNLOCKED(init_task.alloc_lock),
  105. .journal_info = NULL,
  106. INIT_CPU_TIMERS(init_task)
  107. .pi_lock = __RAW_SPIN_LOCK_UNLOCKED(init_task.pi_lock),
  108. .timer_slack_ns = 50000, /* 50 usec default slack */
  109. .pids = {
  110. [PIDTYPE_PID] = INIT_PID_LINK(PIDTYPE_PID),
  111. [PIDTYPE_PGID] = INIT_PID_LINK(PIDTYPE_PGID),
  112. [PIDTYPE_SID] = INIT_PID_LINK(PIDTYPE_SID),
  113. },
  114. .thread_group = LIST_HEAD_INIT(init_task.thread_group),
  115. .thread_node = LIST_HEAD_INIT(init_signals.thread_head),
  116. #ifdef CONFIG_AUDITSYSCALL
  117. .loginuid = INVALID_UID,
  118. .sessionid = (unsigned int)-1,
  119. #endif
  120. #ifdef CONFIG_PERF_EVENTS
  121. .perf_event_mutex = __MUTEX_INITIALIZER(init_task.perf_event_mutex),
  122. .perf_event_list = LIST_HEAD_INIT(init_task.perf_event_list),
  123. #endif
  124. #ifdef CONFIG_PREEMPT_RCU
  125. .rcu_read_lock_nesting = 0,
  126. .rcu_read_unlock_special.s = 0,
  127. .rcu_node_entry = LIST_HEAD_INIT(init_task.rcu_node_entry),
  128. .rcu_blocked_node = NULL,
  129. #endif
  130. #ifdef CONFIG_TASKS_RCU
  131. .rcu_tasks_holdout = false,
  132. .rcu_tasks_holdout_list = LIST_HEAD_INIT(init_task.rcu_tasks_holdout_list),
  133. .rcu_tasks_idle_cpu = -1,
  134. #endif
  135. #ifdef CONFIG_CPUSETS
  136. .mems_allowed_seq = SEQCNT_ZERO(init_task.mems_allowed_seq),
  137. #endif
  138. #ifdef CONFIG_RT_MUTEXES
  139. .pi_waiters = RB_ROOT_CACHED,
  140. .pi_top_task = NULL,
  141. #endif
  142. INIT_PREV_CPUTIME(init_task)
  143. #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
  144. .vtime.seqcount = SEQCNT_ZERO(init_task.vtime_seqcount),
  145. .vtime.starttime = 0,
  146. .vtime.state = VTIME_SYS,
  147. #endif
  148. #ifdef CONFIG_NUMA_BALANCING
  149. .numa_preferred_nid = -1,
  150. .numa_group = NULL,
  151. .numa_faults = NULL,
  152. #endif
  153. #ifdef CONFIG_KASAN
  154. .kasan_depth = 1,
  155. #endif
  156. #ifdef CONFIG_TRACE_IRQFLAGS
  157. .softirqs_enabled = 1,
  158. #endif
  159. #ifdef CONFIG_LOCKDEP
  160. .lockdep_recursion = 0,
  161. #endif
  162. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  163. .ret_stack = NULL,
  164. #endif
  165. #if defined(CONFIG_TRACING) && defined(CONFIG_PREEMPT)
  166. .trace_recursion = 0,
  167. #endif
  168. #ifdef CONFIG_LIVEPATCH
  169. .patch_state = KLP_UNDEFINED,
  170. #endif
  171. #ifdef CONFIG_SECURITY
  172. .security = NULL,
  173. #endif
  174. };
  175. EXPORT_SYMBOL(init_task);
  176. /*
  177. * Initial thread structure. Alignment of this is handled by a special
  178. * linker map entry.
  179. */
  180. #ifndef CONFIG_THREAD_INFO_IN_TASK
  181. struct thread_info init_thread_info __init_thread_info = INIT_THREAD_INFO(init_task);
  182. #endif