blob: 5725029aaa2957eef73c9c3a92429fff441cb5d7 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
David Gibson6cb7bfe2005-10-21 15:45:50 +10002/* thread_info.h: PowerPC low-level thread information
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * 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 Gibson6cb7bfe2005-10-21 15:45:50 +10009#ifndef _ASM_POWERPC_THREAD_INFO_H
10#define _ASM_POWERPC_THREAD_INFO_H
Linus Torvalds1da177e2005-04-16 15:20:36 -070011
Christophe Leroyec0c4642018-07-05 16:24:57 +000012#include <asm/asm-const.h>
Christophe Leroy02847482019-12-21 08:32:27 +000013#include <asm/page.h>
Christophe Leroyec0c4642018-07-05 16:24:57 +000014
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#ifdef __KERNEL__
16
Christophe Leroy02847482019-12-21 08:32:27 +000017#if defined(CONFIG_VMAP_STACK) && CONFIG_THREAD_SHIFT < PAGE_SHIFT
18#define THREAD_SHIFT PAGE_SHIFT
19#else
Hamish Martin47613402017-02-24 13:52:09 +130020#define THREAD_SHIFT CONFIG_THREAD_SHIFT
Christophe Leroy02847482019-12-21 08:32:27 +000021#endif
David Gibson6cb7bfe2005-10-21 15:45:50 +100022
23#define THREAD_SIZE (1 << THREAD_SHIFT)
24
Christophe Leroy63289e72019-12-21 08:32:28 +000025/*
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 Torvalds1da177e2005-04-16 15:20:36 -070038#ifndef __ASSEMBLY__
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#include <linux/cache.h>
40#include <asm/processor.h>
Christophe Leroyc223c902016-05-17 08:33:46 +020041#include <asm/accounting.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
Nicholas Piggin5434ae72018-09-15 01:30:56 +100043#define SLB_PRELOAD_NR 16U
Linus Torvalds1da177e2005-04-16 15:20:36 -070044/*
45 * low level task data.
46 */
47struct thread_info {
David Gibson6cb7bfe2005-10-21 15:45:50 +100048 int preempt_count; /* 0 => preemptable,
49 <0 => BUG */
Ard Biesheuvel227d7352021-09-14 14:10:32 +020050#ifdef CONFIG_SMP
51 unsigned int cpu;
52#endif
Paul Mackerrasf39224a2006-04-18 21:49:11 +100053 unsigned long local_flags; /* private flags for thread */
Michael Ellerman5d31a962016-03-24 22:04:04 +110054#ifdef CONFIG_LIVEPATCH
55 unsigned long *livepatch_sp;
56#endif
Christophe Leroyc223c902016-05-17 08:33:46 +020057#if defined(CONFIG_VIRT_CPU_ACCOUNTING_NATIVE) && defined(CONFIG_PPC32)
58 struct cpu_accounting_data accounting;
59#endif
Nicholas Piggin5434ae72018-09-15 01:30:56 +100060 unsigned char slb_preload_nr;
61 unsigned char slb_preload_tail;
62 u32 slb_preload_esid[SLB_PRELOAD_NR];
63
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 /* 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 Torvalds1da177e2005-04-16 15:20:36 -070070 */
71#define INIT_THREAD_INFO(tsk) \
72{ \
Peter Zijlstrac99e6ef2009-07-10 14:57:56 +020073 .preempt_count = INIT_PREEMPT_COUNT, \
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 .flags = 0, \
75}
76
FUJITA Tomonorib69c49b2008-07-25 01:45:40 -070077#define THREAD_SIZE_ORDER (THREAD_SHIFT - PAGE_SHIFT)
David Gibson328985b2005-10-24 14:05:38 +100078
Linus Torvalds1da177e2005-04-16 15:20:36 -070079/* how to get the thread information struct from C */
Mathieu Malaterrefd70d9f2018-02-25 18:22:28 +010080extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
Nicholas Piggin425d3312018-09-15 01:30:55 +100081
Nicholas Piggin425d3312018-09-15 01:30:55 +100082void arch_setup_new_exec(void);
83#define arch_setup_new_exec arch_setup_new_exec
Nicholas Piggin425d3312018-09-15 01:30:55 +100084
Linus Torvalds1da177e2005-04-16 15:20:36 -070085#endif /* __ASSEMBLY__ */
86
Linus Torvalds1da177e2005-04-16 15:20:36 -070087/*
88 * thread information flag bit numbers
89 */
90#define TIF_SYSCALL_TRACE 0 /* syscall trace active */
Stephane Eraniana583f1b2007-07-31 00:38:00 -070091#define TIF_SIGPENDING 1 /* signal pending */
92#define TIF_NEED_RESCHED 2 /* rescheduling necessary */
Jens Axboe900f0712020-10-22 20:11:56 -060093#define TIF_NOTIFY_SIGNAL 3 /* signal notifications exist */
Breno Leitao5521eb42018-09-20 13:45:06 -030094#define TIF_SYSCALL_EMU 4 /* syscall emulation active */
Paul Mackerrasd31626f2014-01-13 15:56:29 +110095#define TIF_RESTORE_TM 5 /* need to restore TM FP/VEC/VSX */
Josh Poimboeufa768f782017-02-13 19:42:32 -060096#define TIF_PATCH_PENDING 6 /* pending live patching update */
Stephane Eraniana583f1b2007-07-31 00:38:00 -070097#define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
98#define TIF_SINGLESTEP 8 /* singlestepping active */
Stephane Eraniana583f1b2007-07-31 00:38:00 -070099#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 McGrath7d6d6372008-07-27 16:52:52 +1000102#define TIF_NOTIFY_RESUME 13 /* callback before returning to user */
Ananth N Mavinakayanahalli8b7b80b2012-08-23 21:31:32 +0000103#define TIF_UPROBE 14 /* breakpointed or single-stepping */
Ian Munsie02424d82011-02-02 17:27:24 +0000104#define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
Tiejun Chenf0d11282012-09-16 23:54:29 +0000105#define TIF_EMULATE_STACK_STORE 16 /* Is an instruction emulation
106 for stack store? */
Li Zhong22ecbe82013-05-13 16:16:40 +0000107#define TIF_MEMDIE 17 /* is terminating due to OOM killer */
Rusty Russell373c76d2013-11-20 22:15:00 +1100108#if defined(CONFIG_PPC64)
109#define TIF_ELF2ABI 18 /* function descriptors must die! */
110#endif
Michael Ellerman3e378682018-05-14 23:03:16 +1000111#define TIF_POLLING_NRFLAG 19 /* true if poll_idle() is polling TIF_NEED_RESCHED */
Breno Leitao16d7c692018-09-20 13:45:05 -0300112#define TIF_32BIT 20 /* 32 bit binary */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
114/* as above, but as bit values */
115#define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116#define _TIF_SIGPENDING (1<<TIF_SIGPENDING)
117#define _TIF_NEED_RESCHED (1<<TIF_NEED_RESCHED)
Jens Axboe900f0712020-10-22 20:11:56 -0600118#define _TIF_NOTIFY_SIGNAL (1<<TIF_NOTIFY_SIGNAL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119#define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
120#define _TIF_32BIT (1<<TIF_32BIT)
Paul Mackerrasd31626f2014-01-13 15:56:29 +1100121#define _TIF_RESTORE_TM (1<<TIF_RESTORE_TM)
Josh Poimboeufa768f782017-02-13 19:42:32 -0600122#define _TIF_PATCH_PENDING (1<<TIF_PATCH_PENDING)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123#define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
124#define _TIF_SINGLESTEP (1<<TIF_SINGLESTEP)
125#define _TIF_SECCOMP (1<<TIF_SECCOMP)
David Woodhouse401d1f02005-11-15 18:52:18 +0000126#define _TIF_RESTOREALL (1<<TIF_RESTOREALL)
David Woodhouse401d1f02005-11-15 18:52:18 +0000127#define _TIF_NOERROR (1<<TIF_NOERROR)
Roland McGrath7d6d6372008-07-27 16:52:52 +1000128#define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME)
Ananth N Mavinakayanahalli8b7b80b2012-08-23 21:31:32 +0000129#define _TIF_UPROBE (1<<TIF_UPROBE)
Ian Munsie02424d82011-02-02 17:27:24 +0000130#define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
Tiejun Chenf0d11282012-09-16 23:54:29 +0000131#define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
Breno Leitao5521eb42018-09-20 13:45:06 -0300132#define _TIF_SYSCALL_EMU (1<<TIF_SYSCALL_EMU)
Michael Ellerman10ea8342015-01-15 12:01:42 +1100133#define _TIF_SYSCALL_DOTRACE (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
Li Zhong22ecbe82013-05-13 16:16:40 +0000134 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
Nicholas Piggin2a06bf32021-01-30 23:08:40 +1000135 _TIF_SYSCALL_EMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
Roland McGrath7d6d6372008-07-27 16:52:52 +1000137#define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
Paul Mackerrasd31626f2014-01-13 15:56:29 +1100138 _TIF_NOTIFY_RESUME | _TIF_UPROBE | \
Jens Axboe900f0712020-10-22 20:11:56 -0600139 _TIF_RESTORE_TM | _TIF_PATCH_PENDING | \
140 _TIF_NOTIFY_SIGNAL)
Paul Mackerras1bd79332006-03-08 13:24:22 +1100141#define _TIF_PERSYSCALL_MASK (_TIF_RESTOREALL|_TIF_NOERROR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
Paul Mackerrasf39224a2006-04-18 21:49:11 +1000143/* 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 Mackerrasa5606432008-05-14 14:30:48 +1000146#define TLF_SLEEPING 1 /* suspend code enabled SLEEP mode */
Peter Zijlstrad6bf29b2011-05-24 17:11:48 -0700147#define TLF_LAZY_MMU 3 /* tlb_batch is active */
Benjamin Herrenschmidtfe1952f2012-03-01 12:45:27 +1100148#define TLF_RUNLATCH 4 /* Is the runlatch enabled? */
Paul Mackerrasf39224a2006-04-18 21:49:11 +1000149
150#define _TLF_NAPPING (1 << TLF_NAPPING)
Paul Mackerrasa5606432008-05-14 14:30:48 +1000151#define _TLF_SLEEPING (1 << TLF_SLEEPING)
Peter Zijlstrad6bf29b2011-05-24 17:11:48 -0700152#define _TLF_LAZY_MMU (1 << TLF_LAZY_MMU)
Benjamin Herrenschmidtfe1952f2012-03-01 12:45:27 +1100153#define _TLF_RUNLATCH (1 << TLF_RUNLATCH)
Roland McGrath7a101742008-04-28 17:30:37 +1000154
155#ifndef __ASSEMBLY__
Anton Blancharda465f9b2009-02-22 01:49:58 +0000156
Nicholas Piggin98db1792021-04-06 12:55:08 +1000157static 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 Herrenschmidtfe1952f2012-03-01 12:45:27 +1100163static 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 Suchanek0a7601b2020-03-20 11:20:16 +0100169#ifdef CONFIG_COMPAT
Anton Blancharda465f9b2009-02-22 01:49:58 +0000170#define is_32bit_task() (test_thread_flag(TIF_32BIT))
171#else
Michal Suchanek0a7601b2020-03-20 11:20:16 +0100172#define is_32bit_task() (IS_ENABLED(CONFIG_PPC32))
Anton Blancharda465f9b2009-02-22 01:49:58 +0000173#endif
174
Rusty Russell373c76d2013-11-20 22:15:00 +1100175#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 McGrath7a101742008-04-28 17:30:37 +1000181#endif /* !__ASSEMBLY__ */
Paul Mackerrasf39224a2006-04-18 21:49:11 +1000182
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183#endif /* __KERNEL__ */
184
David Gibson6cb7bfe2005-10-21 15:45:50 +1000185#endif /* _ASM_POWERPC_THREAD_INFO_H */