Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
David Gibson | 6cb7bfe | 2005-10-21 15:45:50 +1000 | [diff] [blame] | 2 | /* thread_info.h: PowerPC low-level thread information |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * adapted from the i386 version by Paul Mackerras |
| 4 | * |
| 5 | * Copyright (C) 2002 David Howells (dhowells@redhat.com) |
| 6 | * - Incorporating suggestions made by Linus Torvalds and Dave Miller |
| 7 | */ |
| 8 | |
David Gibson | 6cb7bfe | 2005-10-21 15:45:50 +1000 | [diff] [blame] | 9 | #ifndef _ASM_POWERPC_THREAD_INFO_H |
| 10 | #define _ASM_POWERPC_THREAD_INFO_H |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | |
Christophe Leroy | ec0c464 | 2018-07-05 16:24:57 +0000 | [diff] [blame] | 12 | #include <asm/asm-const.h> |
Christophe Leroy | 0284748 | 2019-12-21 08:32:27 +0000 | [diff] [blame] | 13 | #include <asm/page.h> |
Christophe Leroy | ec0c464 | 2018-07-05 16:24:57 +0000 | [diff] [blame] | 14 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #ifdef __KERNEL__ |
| 16 | |
Christophe Leroy | 0284748 | 2019-12-21 08:32:27 +0000 | [diff] [blame] | 17 | #if defined(CONFIG_VMAP_STACK) && CONFIG_THREAD_SHIFT < PAGE_SHIFT |
| 18 | #define THREAD_SHIFT PAGE_SHIFT |
| 19 | #else |
Hamish Martin | 4761340 | 2017-02-24 13:52:09 +1300 | [diff] [blame] | 20 | #define THREAD_SHIFT CONFIG_THREAD_SHIFT |
Christophe Leroy | 0284748 | 2019-12-21 08:32:27 +0000 | [diff] [blame] | 21 | #endif |
David Gibson | 6cb7bfe | 2005-10-21 15:45:50 +1000 | [diff] [blame] | 22 | |
| 23 | #define THREAD_SIZE (1 << THREAD_SHIFT) |
| 24 | |
Christophe Leroy | 63289e7 | 2019-12-21 08:32:28 +0000 | [diff] [blame] | 25 | /* |
| 26 | * By aligning VMAP'd stacks to 2 * THREAD_SIZE, we can detect overflow by |
| 27 | * checking sp & (1 << THREAD_SHIFT), which we can do cheaply in the entry |
| 28 | * assembly. |
| 29 | */ |
| 30 | #ifdef CONFIG_VMAP_STACK |
| 31 | #define THREAD_ALIGN_SHIFT (THREAD_SHIFT + 1) |
| 32 | #else |
| 33 | #define THREAD_ALIGN_SHIFT THREAD_SHIFT |
| 34 | #endif |
| 35 | |
| 36 | #define THREAD_ALIGN (1 << THREAD_ALIGN_SHIFT) |
| 37 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | #ifndef __ASSEMBLY__ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include <linux/cache.h> |
| 40 | #include <asm/processor.h> |
Christophe Leroy | c223c90 | 2016-05-17 08:33:46 +0200 | [diff] [blame] | 41 | #include <asm/accounting.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
Nicholas Piggin | 5434ae7 | 2018-09-15 01:30:56 +1000 | [diff] [blame] | 43 | #define SLB_PRELOAD_NR 16U |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | /* |
| 45 | * low level task data. |
| 46 | */ |
| 47 | struct thread_info { |
David Gibson | 6cb7bfe | 2005-10-21 15:45:50 +1000 | [diff] [blame] | 48 | int preempt_count; /* 0 => preemptable, |
| 49 | <0 => BUG */ |
Ard Biesheuvel | 227d735 | 2021-09-14 14:10:32 +0200 | [diff] [blame] | 50 | #ifdef CONFIG_SMP |
| 51 | unsigned int cpu; |
| 52 | #endif |
Paul Mackerras | f39224a | 2006-04-18 21:49:11 +1000 | [diff] [blame] | 53 | unsigned long local_flags; /* private flags for thread */ |
Michael Ellerman | 5d31a96 | 2016-03-24 22:04:04 +1100 | [diff] [blame] | 54 | #ifdef CONFIG_LIVEPATCH |
| 55 | unsigned long *livepatch_sp; |
| 56 | #endif |
Christophe Leroy | c223c90 | 2016-05-17 08:33:46 +0200 | [diff] [blame] | 57 | #if defined(CONFIG_VIRT_CPU_ACCOUNTING_NATIVE) && defined(CONFIG_PPC32) |
| 58 | struct cpu_accounting_data accounting; |
| 59 | #endif |
Nicholas Piggin | 5434ae7 | 2018-09-15 01:30:56 +1000 | [diff] [blame] | 60 | unsigned char slb_preload_nr; |
| 61 | unsigned char slb_preload_tail; |
| 62 | u32 slb_preload_esid[SLB_PRELOAD_NR]; |
| 63 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | /* low level flags - has atomic operations done on it */ |
| 65 | unsigned long flags ____cacheline_aligned_in_smp; |
| 66 | }; |
| 67 | |
| 68 | /* |
| 69 | * macros/functions for gaining access to the thread information structure |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | */ |
| 71 | #define INIT_THREAD_INFO(tsk) \ |
| 72 | { \ |
Peter Zijlstra | c99e6ef | 2009-07-10 14:57:56 +0200 | [diff] [blame] | 73 | .preempt_count = INIT_PREEMPT_COUNT, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | .flags = 0, \ |
| 75 | } |
| 76 | |
FUJITA Tomonori | b69c49b | 2008-07-25 01:45:40 -0700 | [diff] [blame] | 77 | #define THREAD_SIZE_ORDER (THREAD_SHIFT - PAGE_SHIFT) |
David Gibson | 328985b | 2005-10-24 14:05:38 +1000 | [diff] [blame] | 78 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | /* how to get the thread information struct from C */ |
Mathieu Malaterre | fd70d9f | 2018-02-25 18:22:28 +0100 | [diff] [blame] | 80 | extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src); |
Nicholas Piggin | 425d331 | 2018-09-15 01:30:55 +1000 | [diff] [blame] | 81 | |
Nicholas Piggin | 425d331 | 2018-09-15 01:30:55 +1000 | [diff] [blame] | 82 | void arch_setup_new_exec(void); |
| 83 | #define arch_setup_new_exec arch_setup_new_exec |
Nicholas Piggin | 425d331 | 2018-09-15 01:30:55 +1000 | [diff] [blame] | 84 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | #endif /* __ASSEMBLY__ */ |
| 86 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | /* |
| 88 | * thread information flag bit numbers |
| 89 | */ |
| 90 | #define TIF_SYSCALL_TRACE 0 /* syscall trace active */ |
Stephane Eranian | a583f1b | 2007-07-31 00:38:00 -0700 | [diff] [blame] | 91 | #define TIF_SIGPENDING 1 /* signal pending */ |
| 92 | #define TIF_NEED_RESCHED 2 /* rescheduling necessary */ |
Jens Axboe | 900f071 | 2020-10-22 20:11:56 -0600 | [diff] [blame] | 93 | #define TIF_NOTIFY_SIGNAL 3 /* signal notifications exist */ |
Breno Leitao | 5521eb4 | 2018-09-20 13:45:06 -0300 | [diff] [blame] | 94 | #define TIF_SYSCALL_EMU 4 /* syscall emulation active */ |
Paul Mackerras | d31626f | 2014-01-13 15:56:29 +1100 | [diff] [blame] | 95 | #define TIF_RESTORE_TM 5 /* need to restore TM FP/VEC/VSX */ |
Josh Poimboeuf | a768f78 | 2017-02-13 19:42:32 -0600 | [diff] [blame] | 96 | #define TIF_PATCH_PENDING 6 /* pending live patching update */ |
Stephane Eranian | a583f1b | 2007-07-31 00:38:00 -0700 | [diff] [blame] | 97 | #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */ |
| 98 | #define TIF_SINGLESTEP 8 /* singlestepping active */ |
Stephane Eranian | a583f1b | 2007-07-31 00:38:00 -0700 | [diff] [blame] | 99 | #define TIF_SECCOMP 10 /* secure computing */ |
| 100 | #define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */ |
| 101 | #define TIF_NOERROR 12 /* Force successful syscall return */ |
Roland McGrath | 7d6d637 | 2008-07-27 16:52:52 +1000 | [diff] [blame] | 102 | #define TIF_NOTIFY_RESUME 13 /* callback before returning to user */ |
Ananth N Mavinakayanahalli | 8b7b80b | 2012-08-23 21:31:32 +0000 | [diff] [blame] | 103 | #define TIF_UPROBE 14 /* breakpointed or single-stepping */ |
Ian Munsie | 02424d8 | 2011-02-02 17:27:24 +0000 | [diff] [blame] | 104 | #define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */ |
Tiejun Chen | f0d1128 | 2012-09-16 23:54:29 +0000 | [diff] [blame] | 105 | #define TIF_EMULATE_STACK_STORE 16 /* Is an instruction emulation |
| 106 | for stack store? */ |
Li Zhong | 22ecbe8 | 2013-05-13 16:16:40 +0000 | [diff] [blame] | 107 | #define TIF_MEMDIE 17 /* is terminating due to OOM killer */ |
Rusty Russell | 373c76d | 2013-11-20 22:15:00 +1100 | [diff] [blame] | 108 | #if defined(CONFIG_PPC64) |
| 109 | #define TIF_ELF2ABI 18 /* function descriptors must die! */ |
| 110 | #endif |
Michael Ellerman | 3e37868 | 2018-05-14 23:03:16 +1000 | [diff] [blame] | 111 | #define TIF_POLLING_NRFLAG 19 /* true if poll_idle() is polling TIF_NEED_RESCHED */ |
Breno Leitao | 16d7c69 | 2018-09-20 13:45:05 -0300 | [diff] [blame] | 112 | #define TIF_32BIT 20 /* 32 bit binary */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | |
| 114 | /* as above, but as bit values */ |
| 115 | #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | #define _TIF_SIGPENDING (1<<TIF_SIGPENDING) |
| 117 | #define _TIF_NEED_RESCHED (1<<TIF_NEED_RESCHED) |
Jens Axboe | 900f071 | 2020-10-22 20:11:56 -0600 | [diff] [blame] | 118 | #define _TIF_NOTIFY_SIGNAL (1<<TIF_NOTIFY_SIGNAL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG) |
| 120 | #define _TIF_32BIT (1<<TIF_32BIT) |
Paul Mackerras | d31626f | 2014-01-13 15:56:29 +1100 | [diff] [blame] | 121 | #define _TIF_RESTORE_TM (1<<TIF_RESTORE_TM) |
Josh Poimboeuf | a768f78 | 2017-02-13 19:42:32 -0600 | [diff] [blame] | 122 | #define _TIF_PATCH_PENDING (1<<TIF_PATCH_PENDING) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT) |
| 124 | #define _TIF_SINGLESTEP (1<<TIF_SINGLESTEP) |
| 125 | #define _TIF_SECCOMP (1<<TIF_SECCOMP) |
David Woodhouse | 401d1f0 | 2005-11-15 18:52:18 +0000 | [diff] [blame] | 126 | #define _TIF_RESTOREALL (1<<TIF_RESTOREALL) |
David Woodhouse | 401d1f0 | 2005-11-15 18:52:18 +0000 | [diff] [blame] | 127 | #define _TIF_NOERROR (1<<TIF_NOERROR) |
Roland McGrath | 7d6d637 | 2008-07-27 16:52:52 +1000 | [diff] [blame] | 128 | #define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME) |
Ananth N Mavinakayanahalli | 8b7b80b | 2012-08-23 21:31:32 +0000 | [diff] [blame] | 129 | #define _TIF_UPROBE (1<<TIF_UPROBE) |
Ian Munsie | 02424d8 | 2011-02-02 17:27:24 +0000 | [diff] [blame] | 130 | #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT) |
Tiejun Chen | f0d1128 | 2012-09-16 23:54:29 +0000 | [diff] [blame] | 131 | #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE) |
Breno Leitao | 5521eb4 | 2018-09-20 13:45:06 -0300 | [diff] [blame] | 132 | #define _TIF_SYSCALL_EMU (1<<TIF_SYSCALL_EMU) |
Michael Ellerman | 10ea834 | 2015-01-15 12:01:42 +1100 | [diff] [blame] | 133 | #define _TIF_SYSCALL_DOTRACE (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \ |
Li Zhong | 22ecbe8 | 2013-05-13 16:16:40 +0000 | [diff] [blame] | 134 | _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \ |
Nicholas Piggin | 2a06bf3 | 2021-01-30 23:08:40 +1000 | [diff] [blame] | 135 | _TIF_SYSCALL_EMU) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | |
Roland McGrath | 7d6d637 | 2008-07-27 16:52:52 +1000 | [diff] [blame] | 137 | #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \ |
Paul Mackerras | d31626f | 2014-01-13 15:56:29 +1100 | [diff] [blame] | 138 | _TIF_NOTIFY_RESUME | _TIF_UPROBE | \ |
Jens Axboe | 900f071 | 2020-10-22 20:11:56 -0600 | [diff] [blame] | 139 | _TIF_RESTORE_TM | _TIF_PATCH_PENDING | \ |
| 140 | _TIF_NOTIFY_SIGNAL) |
Paul Mackerras | 1bd7933 | 2006-03-08 13:24:22 +1100 | [diff] [blame] | 141 | #define _TIF_PERSYSCALL_MASK (_TIF_RESTOREALL|_TIF_NOERROR) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | |
Paul Mackerras | f39224a | 2006-04-18 21:49:11 +1000 | [diff] [blame] | 143 | /* Bits in local_flags */ |
| 144 | /* Don't move TLF_NAPPING without adjusting the code in entry_32.S */ |
| 145 | #define TLF_NAPPING 0 /* idle thread enabled NAP mode */ |
Paul Mackerras | a560643 | 2008-05-14 14:30:48 +1000 | [diff] [blame] | 146 | #define TLF_SLEEPING 1 /* suspend code enabled SLEEP mode */ |
Peter Zijlstra | d6bf29b | 2011-05-24 17:11:48 -0700 | [diff] [blame] | 147 | #define TLF_LAZY_MMU 3 /* tlb_batch is active */ |
Benjamin Herrenschmidt | fe1952f | 2012-03-01 12:45:27 +1100 | [diff] [blame] | 148 | #define TLF_RUNLATCH 4 /* Is the runlatch enabled? */ |
Paul Mackerras | f39224a | 2006-04-18 21:49:11 +1000 | [diff] [blame] | 149 | |
| 150 | #define _TLF_NAPPING (1 << TLF_NAPPING) |
Paul Mackerras | a560643 | 2008-05-14 14:30:48 +1000 | [diff] [blame] | 151 | #define _TLF_SLEEPING (1 << TLF_SLEEPING) |
Peter Zijlstra | d6bf29b | 2011-05-24 17:11:48 -0700 | [diff] [blame] | 152 | #define _TLF_LAZY_MMU (1 << TLF_LAZY_MMU) |
Benjamin Herrenschmidt | fe1952f | 2012-03-01 12:45:27 +1100 | [diff] [blame] | 153 | #define _TLF_RUNLATCH (1 << TLF_RUNLATCH) |
Roland McGrath | 7a10174 | 2008-04-28 17:30:37 +1000 | [diff] [blame] | 154 | |
| 155 | #ifndef __ASSEMBLY__ |
Anton Blanchard | a465f9b | 2009-02-22 01:49:58 +0000 | [diff] [blame] | 156 | |
Nicholas Piggin | 98db179 | 2021-04-06 12:55:08 +1000 | [diff] [blame] | 157 | static inline void clear_thread_local_flags(unsigned int flags) |
| 158 | { |
| 159 | struct thread_info *ti = current_thread_info(); |
| 160 | ti->local_flags &= ~flags; |
| 161 | } |
| 162 | |
Benjamin Herrenschmidt | fe1952f | 2012-03-01 12:45:27 +1100 | [diff] [blame] | 163 | static inline bool test_thread_local_flags(unsigned int flags) |
| 164 | { |
| 165 | struct thread_info *ti = current_thread_info(); |
| 166 | return (ti->local_flags & flags) != 0; |
| 167 | } |
| 168 | |
Michal Suchanek | 0a7601b | 2020-03-20 11:20:16 +0100 | [diff] [blame] | 169 | #ifdef CONFIG_COMPAT |
Anton Blanchard | a465f9b | 2009-02-22 01:49:58 +0000 | [diff] [blame] | 170 | #define is_32bit_task() (test_thread_flag(TIF_32BIT)) |
| 171 | #else |
Michal Suchanek | 0a7601b | 2020-03-20 11:20:16 +0100 | [diff] [blame] | 172 | #define is_32bit_task() (IS_ENABLED(CONFIG_PPC32)) |
Anton Blanchard | a465f9b | 2009-02-22 01:49:58 +0000 | [diff] [blame] | 173 | #endif |
| 174 | |
Rusty Russell | 373c76d | 2013-11-20 22:15:00 +1100 | [diff] [blame] | 175 | #if defined(CONFIG_PPC64) |
| 176 | #define is_elf2_task() (test_thread_flag(TIF_ELF2ABI)) |
| 177 | #else |
| 178 | #define is_elf2_task() (0) |
| 179 | #endif |
| 180 | |
Roland McGrath | 7a10174 | 2008-04-28 17:30:37 +1000 | [diff] [blame] | 181 | #endif /* !__ASSEMBLY__ */ |
Paul Mackerras | f39224a | 2006-04-18 21:49:11 +1000 | [diff] [blame] | 182 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | #endif /* __KERNEL__ */ |
| 184 | |
David Gibson | 6cb7bfe | 2005-10-21 15:45:50 +1000 | [diff] [blame] | 185 | #endif /* _ASM_POWERPC_THREAD_INFO_H */ |