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