init_task.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. #ifndef _LINUX__INIT_TASK_H
  2. #define _LINUX__INIT_TASK_H
  3. #include <linux/rcupdate.h>
  4. #include <linux/irqflags.h>
  5. #include <linux/utsname.h>
  6. #include <linux/lockdep.h>
  7. #include <linux/ftrace.h>
  8. #include <linux/ipc.h>
  9. #include <linux/pid_namespace.h>
  10. #include <linux/user_namespace.h>
  11. #include <linux/securebits.h>
  12. #include <linux/seqlock.h>
  13. #include <linux/rbtree.h>
  14. #include <net/net_namespace.h>
  15. #include <linux/sched/rt.h>
  16. #ifdef CONFIG_SMP
  17. # define INIT_PUSHABLE_TASKS(tsk) \
  18. .pushable_tasks = PLIST_NODE_INIT(tsk.pushable_tasks, MAX_PRIO),
  19. #else
  20. # define INIT_PUSHABLE_TASKS(tsk)
  21. #endif
  22. extern struct files_struct init_files;
  23. extern struct fs_struct init_fs;
  24. #ifdef CONFIG_CPUSETS
  25. #define INIT_CPUSET_SEQ(tsk) \
  26. .mems_allowed_seq = SEQCNT_ZERO(tsk.mems_allowed_seq),
  27. #else
  28. #define INIT_CPUSET_SEQ(tsk)
  29. #endif
  30. #ifndef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
  31. #define INIT_PREV_CPUTIME(x) .prev_cputime = { \
  32. .lock = __RAW_SPIN_LOCK_UNLOCKED(x.prev_cputime.lock), \
  33. },
  34. #else
  35. #define INIT_PREV_CPUTIME(x)
  36. #endif
  37. #define INIT_SIGNALS(sig) { \
  38. .nr_threads = 1, \
  39. .thread_head = LIST_HEAD_INIT(init_task.thread_node), \
  40. .wait_chldexit = __WAIT_QUEUE_HEAD_INITIALIZER(sig.wait_chldexit),\
  41. .shared_pending = { \
  42. .list = LIST_HEAD_INIT(sig.shared_pending.list), \
  43. .signal = {{0}}}, \
  44. .posix_timers = LIST_HEAD_INIT(sig.posix_timers), \
  45. .cpu_timers = INIT_CPU_TIMERS(sig.cpu_timers), \
  46. .rlim = INIT_RLIMITS, \
  47. .cputimer = { \
  48. .cputime_atomic = INIT_CPUTIME_ATOMIC, \
  49. .running = false, \
  50. .checking_timer = false, \
  51. }, \
  52. INIT_PREV_CPUTIME(sig) \
  53. .cred_guard_mutex = \
  54. __MUTEX_INITIALIZER(sig.cred_guard_mutex), \
  55. }
  56. extern struct nsproxy init_nsproxy;
  57. #define INIT_SIGHAND(sighand) { \
  58. .count = ATOMIC_INIT(1), \
  59. .action = { { { .sa_handler = SIG_DFL, } }, }, \
  60. .siglock = __SPIN_LOCK_UNLOCKED(sighand.siglock), \
  61. .signalfd_wqh = __WAIT_QUEUE_HEAD_INITIALIZER(sighand.signalfd_wqh), \
  62. }
  63. extern struct group_info init_groups;
  64. #define INIT_STRUCT_PID { \
  65. .count = ATOMIC_INIT(1), \
  66. .tasks = { \
  67. { .first = NULL }, \
  68. { .first = NULL }, \
  69. { .first = NULL }, \
  70. }, \
  71. .level = 0, \
  72. .numbers = { { \
  73. .nr = 0, \
  74. .ns = &init_pid_ns, \
  75. .pid_chain = { .next = NULL, .pprev = NULL }, \
  76. }, } \
  77. }
  78. #define INIT_PID_LINK(type) \
  79. { \
  80. .node = { \
  81. .next = NULL, \
  82. .pprev = NULL, \
  83. }, \
  84. .pid = &init_struct_pid, \
  85. }
  86. #ifdef CONFIG_AUDITSYSCALL
  87. #define INIT_IDS \
  88. .loginuid = INVALID_UID, \
  89. .sessionid = (unsigned int)-1,
  90. #else
  91. #define INIT_IDS
  92. #endif
  93. #ifdef CONFIG_PREEMPT_RCU
  94. #define INIT_TASK_RCU_TREE_PREEMPT() \
  95. .rcu_blocked_node = NULL,
  96. #else
  97. #define INIT_TASK_RCU_TREE_PREEMPT(tsk)
  98. #endif
  99. #ifdef CONFIG_PREEMPT_RCU
  100. #define INIT_TASK_RCU_PREEMPT(tsk) \
  101. .rcu_read_lock_nesting = 0, \
  102. .rcu_read_unlock_special.s = 0, \
  103. .rcu_node_entry = LIST_HEAD_INIT(tsk.rcu_node_entry), \
  104. INIT_TASK_RCU_TREE_PREEMPT()
  105. #else
  106. #define INIT_TASK_RCU_PREEMPT(tsk)
  107. #endif
  108. #ifdef CONFIG_TASKS_RCU
  109. #define INIT_TASK_RCU_TASKS(tsk) \
  110. .rcu_tasks_holdout = false, \
  111. .rcu_tasks_holdout_list = \
  112. LIST_HEAD_INIT(tsk.rcu_tasks_holdout_list), \
  113. .rcu_tasks_idle_cpu = -1,
  114. #else
  115. #define INIT_TASK_RCU_TASKS(tsk)
  116. #endif
  117. extern struct cred init_cred;
  118. extern struct task_group root_task_group;
  119. #ifdef CONFIG_CGROUP_SCHED
  120. # define INIT_CGROUP_SCHED(tsk) \
  121. .sched_task_group = &root_task_group,
  122. #else
  123. # define INIT_CGROUP_SCHED(tsk)
  124. #endif
  125. #ifdef CONFIG_PERF_EVENTS
  126. # define INIT_PERF_EVENTS(tsk) \
  127. .perf_event_mutex = \
  128. __MUTEX_INITIALIZER(tsk.perf_event_mutex), \
  129. .perf_event_list = LIST_HEAD_INIT(tsk.perf_event_list),
  130. #else
  131. # define INIT_PERF_EVENTS(tsk)
  132. #endif
  133. #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
  134. # define INIT_VTIME(tsk) \
  135. .vtime_seqlock = __SEQLOCK_UNLOCKED(tsk.vtime_seqlock), \
  136. .vtime_snap = 0, \
  137. .vtime_snap_whence = VTIME_SYS,
  138. #else
  139. # define INIT_VTIME(tsk)
  140. #endif
  141. #define INIT_TASK_COMM "swapper"
  142. #ifdef CONFIG_RT_MUTEXES
  143. # define INIT_RT_MUTEXES(tsk) \
  144. .pi_waiters = RB_ROOT, \
  145. .pi_waiters_leftmost = NULL,
  146. #else
  147. # define INIT_RT_MUTEXES(tsk)
  148. #endif
  149. #ifdef CONFIG_NUMA_BALANCING
  150. # define INIT_NUMA_BALANCING(tsk) \
  151. .numa_preferred_nid = -1, \
  152. .numa_group = NULL, \
  153. .numa_faults = NULL,
  154. #else
  155. # define INIT_NUMA_BALANCING(tsk)
  156. #endif
  157. #ifdef CONFIG_KASAN
  158. # define INIT_KASAN(tsk) \
  159. .kasan_depth = 1,
  160. #else
  161. # define INIT_KASAN(tsk)
  162. #endif
  163. /*
  164. * INIT_TASK is used to set up the first task table, touch at
  165. * your own risk!. Base=0, limit=0x1fffff (=2MB)
  166. */
  167. #define INIT_TASK(tsk) \
  168. { \
  169. .state = 0, \
  170. .stack = &init_thread_info, \
  171. .usage = ATOMIC_INIT(2), \
  172. .flags = PF_KTHREAD, \
  173. .prio = MAX_PRIO-20, \
  174. .static_prio = MAX_PRIO-20, \
  175. .normal_prio = MAX_PRIO-20, \
  176. .policy = SCHED_NORMAL, \
  177. .cpus_allowed = CPU_MASK_ALL, \
  178. .nr_cpus_allowed= NR_CPUS, \
  179. .mm = NULL, \
  180. .active_mm = &init_mm, \
  181. .restart_block = { \
  182. .fn = do_no_restart_syscall, \
  183. }, \
  184. .se = { \
  185. .group_node = LIST_HEAD_INIT(tsk.se.group_node), \
  186. }, \
  187. .rt = { \
  188. .run_list = LIST_HEAD_INIT(tsk.rt.run_list), \
  189. .time_slice = RR_TIMESLICE, \
  190. }, \
  191. .tasks = LIST_HEAD_INIT(tsk.tasks), \
  192. INIT_PUSHABLE_TASKS(tsk) \
  193. INIT_CGROUP_SCHED(tsk) \
  194. .ptraced = LIST_HEAD_INIT(tsk.ptraced), \
  195. .ptrace_entry = LIST_HEAD_INIT(tsk.ptrace_entry), \
  196. .real_parent = &tsk, \
  197. .parent = &tsk, \
  198. .children = LIST_HEAD_INIT(tsk.children), \
  199. .sibling = LIST_HEAD_INIT(tsk.sibling), \
  200. .group_leader = &tsk, \
  201. RCU_POINTER_INITIALIZER(real_cred, &init_cred), \
  202. RCU_POINTER_INITIALIZER(cred, &init_cred), \
  203. .comm = INIT_TASK_COMM, \
  204. .thread = INIT_THREAD, \
  205. .fs = &init_fs, \
  206. .files = &init_files, \
  207. .signal = &init_signals, \
  208. .sighand = &init_sighand, \
  209. .nsproxy = &init_nsproxy, \
  210. .pending = { \
  211. .list = LIST_HEAD_INIT(tsk.pending.list), \
  212. .signal = {{0}}}, \
  213. .blocked = {{0}}, \
  214. .alloc_lock = __SPIN_LOCK_UNLOCKED(tsk.alloc_lock), \
  215. .journal_info = NULL, \
  216. .cpu_timers = INIT_CPU_TIMERS(tsk.cpu_timers), \
  217. .pi_lock = __RAW_SPIN_LOCK_UNLOCKED(tsk.pi_lock), \
  218. .timer_slack_ns = 50000, /* 50 usec default slack */ \
  219. .pids = { \
  220. [PIDTYPE_PID] = INIT_PID_LINK(PIDTYPE_PID), \
  221. [PIDTYPE_PGID] = INIT_PID_LINK(PIDTYPE_PGID), \
  222. [PIDTYPE_SID] = INIT_PID_LINK(PIDTYPE_SID), \
  223. }, \
  224. .thread_group = LIST_HEAD_INIT(tsk.thread_group), \
  225. .thread_node = LIST_HEAD_INIT(init_signals.thread_head), \
  226. INIT_IDS \
  227. INIT_PERF_EVENTS(tsk) \
  228. INIT_TRACE_IRQFLAGS \
  229. INIT_LOCKDEP \
  230. INIT_FTRACE_GRAPH \
  231. INIT_TRACE_RECURSION \
  232. INIT_TASK_RCU_PREEMPT(tsk) \
  233. INIT_TASK_RCU_TASKS(tsk) \
  234. INIT_CPUSET_SEQ(tsk) \
  235. INIT_RT_MUTEXES(tsk) \
  236. INIT_PREV_CPUTIME(tsk) \
  237. INIT_VTIME(tsk) \
  238. INIT_NUMA_BALANCING(tsk) \
  239. INIT_KASAN(tsk) \
  240. }
  241. #define INIT_CPU_TIMERS(cpu_timers) \
  242. { \
  243. LIST_HEAD_INIT(cpu_timers[0]), \
  244. LIST_HEAD_INIT(cpu_timers[1]), \
  245. LIST_HEAD_INIT(cpu_timers[2]), \
  246. }
  247. /* Attach to the init_task data structure for proper alignment */
  248. #define __init_task_data __attribute__((__section__(".data..init_task")))
  249. #endif