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