thread_info.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2009 Chen Liqin <[email protected]>
  4. * Copyright (C) 2012 Regents of the University of California
  5. * Copyright (C) 2017 SiFive
  6. */
  7. #ifndef _ASM_RISCV_THREAD_INFO_H
  8. #define _ASM_RISCV_THREAD_INFO_H
  9. #include <asm/page.h>
  10. #include <linux/const.h>
  11. #ifdef CONFIG_KASAN
  12. #define KASAN_STACK_ORDER 1
  13. #else
  14. #define KASAN_STACK_ORDER 0
  15. #endif
  16. /* thread information allocation */
  17. #ifdef CONFIG_64BIT
  18. #define THREAD_SIZE_ORDER (2 + KASAN_STACK_ORDER)
  19. #else
  20. #define THREAD_SIZE_ORDER (1 + KASAN_STACK_ORDER)
  21. #endif
  22. #define THREAD_SIZE (PAGE_SIZE << THREAD_SIZE_ORDER)
  23. /*
  24. * By aligning VMAP'd stacks to 2 * THREAD_SIZE, we can detect overflow by
  25. * checking sp & (1 << THREAD_SHIFT), which we can do cheaply in the entry
  26. * assembly.
  27. */
  28. #ifdef CONFIG_VMAP_STACK
  29. #define THREAD_ALIGN (2 * THREAD_SIZE)
  30. #else
  31. #define THREAD_ALIGN THREAD_SIZE
  32. #endif
  33. #define THREAD_SHIFT (PAGE_SHIFT + THREAD_SIZE_ORDER)
  34. #define OVERFLOW_STACK_SIZE SZ_4K
  35. #define SHADOW_OVERFLOW_STACK_SIZE (1024)
  36. #ifndef __ASSEMBLY__
  37. extern long shadow_stack[SHADOW_OVERFLOW_STACK_SIZE / sizeof(long)];
  38. extern unsigned long spin_shadow_stack;
  39. #include <asm/processor.h>
  40. #include <asm/csr.h>
  41. /*
  42. * low level task data that entry.S needs immediate access to
  43. * - this struct should fit entirely inside of one cache line
  44. * - if the members of this struct changes, the assembly constants
  45. * in asm-offsets.c must be updated accordingly
  46. * - thread_info is included in task_struct at an offset of 0. This means that
  47. * tp points to both thread_info and task_struct.
  48. */
  49. struct thread_info {
  50. unsigned long flags; /* low level flags */
  51. int preempt_count; /* 0=>preemptible, <0=>BUG */
  52. /*
  53. * These stack pointers are overwritten on every system call or
  54. * exception. SP is also saved to the stack it can be recovered when
  55. * overwritten.
  56. */
  57. long kernel_sp; /* Kernel stack pointer */
  58. long user_sp; /* User stack pointer */
  59. int cpu;
  60. };
  61. /*
  62. * macros/functions for gaining access to the thread information structure
  63. *
  64. * preempt_count needs to be 1 initially, until the scheduler is functional.
  65. */
  66. #define INIT_THREAD_INFO(tsk) \
  67. { \
  68. .flags = 0, \
  69. .preempt_count = INIT_PREEMPT_COUNT, \
  70. }
  71. #endif /* !__ASSEMBLY__ */
  72. /*
  73. * thread information flags
  74. * - these are process state flags that various assembly files may need to
  75. * access
  76. * - pending work-to-be-done flags are in lowest half-word
  77. * - other flags in upper half-word(s)
  78. */
  79. #define TIF_SYSCALL_TRACE 0 /* syscall trace active */
  80. #define TIF_NOTIFY_RESUME 1 /* callback before returning to user */
  81. #define TIF_SIGPENDING 2 /* signal pending */
  82. #define TIF_NEED_RESCHED 3 /* rescheduling necessary */
  83. #define TIF_RESTORE_SIGMASK 4 /* restore signal mask in do_signal() */
  84. #define TIF_MEMDIE 5 /* is terminating due to OOM killer */
  85. #define TIF_SYSCALL_TRACEPOINT 6 /* syscall tracepoint instrumentation */
  86. #define TIF_SYSCALL_AUDIT 7 /* syscall auditing */
  87. #define TIF_SECCOMP 8 /* syscall secure computing */
  88. #define TIF_NOTIFY_SIGNAL 9 /* signal notifications exist */
  89. #define TIF_UPROBE 10 /* uprobe breakpoint or singlestep */
  90. #define TIF_32BIT 11 /* compat-mode 32bit process */
  91. #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
  92. #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
  93. #define _TIF_SIGPENDING (1 << TIF_SIGPENDING)
  94. #define _TIF_NEED_RESCHED (1 << TIF_NEED_RESCHED)
  95. #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
  96. #define _TIF_SYSCALL_AUDIT (1 << TIF_SYSCALL_AUDIT)
  97. #define _TIF_SECCOMP (1 << TIF_SECCOMP)
  98. #define _TIF_NOTIFY_SIGNAL (1 << TIF_NOTIFY_SIGNAL)
  99. #define _TIF_UPROBE (1 << TIF_UPROBE)
  100. #define _TIF_WORK_MASK \
  101. (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING | _TIF_NEED_RESCHED | \
  102. _TIF_NOTIFY_SIGNAL | _TIF_UPROBE)
  103. #define _TIF_SYSCALL_WORK \
  104. (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_TRACEPOINT | _TIF_SYSCALL_AUDIT | \
  105. _TIF_SECCOMP)
  106. #endif /* _ASM_RISCV_THREAD_INFO_H */