init_task.c 4.3 KB

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