18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/* thread_info.h: PowerPC low-level thread information
38c2ecf20Sopenharmony_ci * adapted from the i386 version by Paul Mackerras
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 2002  David Howells (dhowells@redhat.com)
68c2ecf20Sopenharmony_ci * - Incorporating suggestions made by Linus Torvalds and Dave Miller
78c2ecf20Sopenharmony_ci */
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#ifndef _ASM_POWERPC_THREAD_INFO_H
108c2ecf20Sopenharmony_ci#define _ASM_POWERPC_THREAD_INFO_H
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#include <asm/asm-const.h>
138c2ecf20Sopenharmony_ci#include <asm/page.h>
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci#ifdef __KERNEL__
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#ifdef CONFIG_KASAN
188c2ecf20Sopenharmony_ci#define MIN_THREAD_SHIFT	(CONFIG_THREAD_SHIFT + 1)
198c2ecf20Sopenharmony_ci#else
208c2ecf20Sopenharmony_ci#define MIN_THREAD_SHIFT	CONFIG_THREAD_SHIFT
218c2ecf20Sopenharmony_ci#endif
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci#if defined(CONFIG_VMAP_STACK) && MIN_THREAD_SHIFT < PAGE_SHIFT
248c2ecf20Sopenharmony_ci#define THREAD_SHIFT		PAGE_SHIFT
258c2ecf20Sopenharmony_ci#else
268c2ecf20Sopenharmony_ci#define THREAD_SHIFT		MIN_THREAD_SHIFT
278c2ecf20Sopenharmony_ci#endif
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci#define THREAD_SIZE		(1 << THREAD_SHIFT)
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci/*
328c2ecf20Sopenharmony_ci * By aligning VMAP'd stacks to 2 * THREAD_SIZE, we can detect overflow by
338c2ecf20Sopenharmony_ci * checking sp & (1 << THREAD_SHIFT), which we can do cheaply in the entry
348c2ecf20Sopenharmony_ci * assembly.
358c2ecf20Sopenharmony_ci */
368c2ecf20Sopenharmony_ci#ifdef CONFIG_VMAP_STACK
378c2ecf20Sopenharmony_ci#define THREAD_ALIGN_SHIFT	(THREAD_SHIFT + 1)
388c2ecf20Sopenharmony_ci#else
398c2ecf20Sopenharmony_ci#define THREAD_ALIGN_SHIFT	THREAD_SHIFT
408c2ecf20Sopenharmony_ci#endif
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci#define THREAD_ALIGN		(1 << THREAD_ALIGN_SHIFT)
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci#ifndef __ASSEMBLY__
458c2ecf20Sopenharmony_ci#include <linux/cache.h>
468c2ecf20Sopenharmony_ci#include <asm/processor.h>
478c2ecf20Sopenharmony_ci#include <asm/page.h>
488c2ecf20Sopenharmony_ci#include <asm/accounting.h>
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci#define SLB_PRELOAD_NR	16U
518c2ecf20Sopenharmony_ci/*
528c2ecf20Sopenharmony_ci * low level task data.
538c2ecf20Sopenharmony_ci */
548c2ecf20Sopenharmony_cistruct thread_info {
558c2ecf20Sopenharmony_ci	int		preempt_count;		/* 0 => preemptable,
568c2ecf20Sopenharmony_ci						   <0 => BUG */
578c2ecf20Sopenharmony_ci	unsigned long	local_flags;		/* private flags for thread */
588c2ecf20Sopenharmony_ci#ifdef CONFIG_LIVEPATCH
598c2ecf20Sopenharmony_ci	unsigned long *livepatch_sp;
608c2ecf20Sopenharmony_ci#endif
618c2ecf20Sopenharmony_ci#if defined(CONFIG_VIRT_CPU_ACCOUNTING_NATIVE) && defined(CONFIG_PPC32)
628c2ecf20Sopenharmony_ci	struct cpu_accounting_data accounting;
638c2ecf20Sopenharmony_ci#endif
648c2ecf20Sopenharmony_ci	unsigned char slb_preload_nr;
658c2ecf20Sopenharmony_ci	unsigned char slb_preload_tail;
668c2ecf20Sopenharmony_ci	u32 slb_preload_esid[SLB_PRELOAD_NR];
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci	/* low level flags - has atomic operations done on it */
698c2ecf20Sopenharmony_ci	unsigned long	flags ____cacheline_aligned_in_smp;
708c2ecf20Sopenharmony_ci};
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_ci/*
738c2ecf20Sopenharmony_ci * macros/functions for gaining access to the thread information structure
748c2ecf20Sopenharmony_ci */
758c2ecf20Sopenharmony_ci#define INIT_THREAD_INFO(tsk)			\
768c2ecf20Sopenharmony_ci{						\
778c2ecf20Sopenharmony_ci	.preempt_count = INIT_PREEMPT_COUNT,	\
788c2ecf20Sopenharmony_ci	.flags =	0,			\
798c2ecf20Sopenharmony_ci}
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci#define THREAD_SIZE_ORDER	(THREAD_SHIFT - PAGE_SHIFT)
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci/* how to get the thread information struct from C */
848c2ecf20Sopenharmony_ciextern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci#ifdef CONFIG_PPC_BOOK3S_64
878c2ecf20Sopenharmony_civoid arch_setup_new_exec(void);
888c2ecf20Sopenharmony_ci#define arch_setup_new_exec arch_setup_new_exec
898c2ecf20Sopenharmony_ci#endif
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci#endif /* __ASSEMBLY__ */
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci/*
948c2ecf20Sopenharmony_ci * thread information flag bit numbers
958c2ecf20Sopenharmony_ci */
968c2ecf20Sopenharmony_ci#define TIF_SYSCALL_TRACE	0	/* syscall trace active */
978c2ecf20Sopenharmony_ci#define TIF_SIGPENDING		1	/* signal pending */
988c2ecf20Sopenharmony_ci#define TIF_NEED_RESCHED	2	/* rescheduling necessary */
998c2ecf20Sopenharmony_ci#define TIF_NOTIFY_SIGNAL	3	/* signal notifications exist */
1008c2ecf20Sopenharmony_ci#define TIF_SYSCALL_EMU		4	/* syscall emulation active */
1018c2ecf20Sopenharmony_ci#define TIF_RESTORE_TM		5	/* need to restore TM FP/VEC/VSX */
1028c2ecf20Sopenharmony_ci#define TIF_PATCH_PENDING	6	/* pending live patching update */
1038c2ecf20Sopenharmony_ci#define TIF_SYSCALL_AUDIT	7	/* syscall auditing active */
1048c2ecf20Sopenharmony_ci#define TIF_SINGLESTEP		8	/* singlestepping active */
1058c2ecf20Sopenharmony_ci#define TIF_NOHZ		9	/* in adaptive nohz mode */
1068c2ecf20Sopenharmony_ci#define TIF_SECCOMP		10	/* secure computing */
1078c2ecf20Sopenharmony_ci#define TIF_RESTOREALL		11	/* Restore all regs (implies NOERROR) */
1088c2ecf20Sopenharmony_ci#define TIF_NOERROR		12	/* Force successful syscall return */
1098c2ecf20Sopenharmony_ci#define TIF_NOTIFY_RESUME	13	/* callback before returning to user */
1108c2ecf20Sopenharmony_ci#define TIF_UPROBE		14	/* breakpointed or single-stepping */
1118c2ecf20Sopenharmony_ci#define TIF_SYSCALL_TRACEPOINT	15	/* syscall tracepoint instrumentation */
1128c2ecf20Sopenharmony_ci#define TIF_EMULATE_STACK_STORE	16	/* Is an instruction emulation
1138c2ecf20Sopenharmony_ci						for stack store? */
1148c2ecf20Sopenharmony_ci#define TIF_MEMDIE		17	/* is terminating due to OOM killer */
1158c2ecf20Sopenharmony_ci#if defined(CONFIG_PPC64)
1168c2ecf20Sopenharmony_ci#define TIF_ELF2ABI		18	/* function descriptors must die! */
1178c2ecf20Sopenharmony_ci#endif
1188c2ecf20Sopenharmony_ci#define TIF_POLLING_NRFLAG	19	/* true if poll_idle() is polling TIF_NEED_RESCHED */
1198c2ecf20Sopenharmony_ci#define TIF_32BIT		20	/* 32 bit binary */
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_ci/* as above, but as bit values */
1228c2ecf20Sopenharmony_ci#define _TIF_SYSCALL_TRACE	(1<<TIF_SYSCALL_TRACE)
1238c2ecf20Sopenharmony_ci#define _TIF_SIGPENDING		(1<<TIF_SIGPENDING)
1248c2ecf20Sopenharmony_ci#define _TIF_NEED_RESCHED	(1<<TIF_NEED_RESCHED)
1258c2ecf20Sopenharmony_ci#define _TIF_NOTIFY_SIGNAL	(1<<TIF_NOTIFY_SIGNAL)
1268c2ecf20Sopenharmony_ci#define _TIF_POLLING_NRFLAG	(1<<TIF_POLLING_NRFLAG)
1278c2ecf20Sopenharmony_ci#define _TIF_32BIT		(1<<TIF_32BIT)
1288c2ecf20Sopenharmony_ci#define _TIF_RESTORE_TM		(1<<TIF_RESTORE_TM)
1298c2ecf20Sopenharmony_ci#define _TIF_PATCH_PENDING	(1<<TIF_PATCH_PENDING)
1308c2ecf20Sopenharmony_ci#define _TIF_SYSCALL_AUDIT	(1<<TIF_SYSCALL_AUDIT)
1318c2ecf20Sopenharmony_ci#define _TIF_SINGLESTEP		(1<<TIF_SINGLESTEP)
1328c2ecf20Sopenharmony_ci#define _TIF_SECCOMP		(1<<TIF_SECCOMP)
1338c2ecf20Sopenharmony_ci#define _TIF_RESTOREALL		(1<<TIF_RESTOREALL)
1348c2ecf20Sopenharmony_ci#define _TIF_NOERROR		(1<<TIF_NOERROR)
1358c2ecf20Sopenharmony_ci#define _TIF_NOTIFY_RESUME	(1<<TIF_NOTIFY_RESUME)
1368c2ecf20Sopenharmony_ci#define _TIF_UPROBE		(1<<TIF_UPROBE)
1378c2ecf20Sopenharmony_ci#define _TIF_SYSCALL_TRACEPOINT	(1<<TIF_SYSCALL_TRACEPOINT)
1388c2ecf20Sopenharmony_ci#define _TIF_EMULATE_STACK_STORE	(1<<TIF_EMULATE_STACK_STORE)
1398c2ecf20Sopenharmony_ci#define _TIF_NOHZ		(1<<TIF_NOHZ)
1408c2ecf20Sopenharmony_ci#define _TIF_SYSCALL_EMU	(1<<TIF_SYSCALL_EMU)
1418c2ecf20Sopenharmony_ci#define _TIF_SYSCALL_DOTRACE	(_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
1428c2ecf20Sopenharmony_ci				 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
1438c2ecf20Sopenharmony_ci				 _TIF_NOHZ | _TIF_SYSCALL_EMU)
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_ci#define _TIF_USER_WORK_MASK	(_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
1468c2ecf20Sopenharmony_ci				 _TIF_NOTIFY_RESUME | _TIF_UPROBE | \
1478c2ecf20Sopenharmony_ci				 _TIF_RESTORE_TM | _TIF_PATCH_PENDING | \
1488c2ecf20Sopenharmony_ci				 _TIF_NOTIFY_SIGNAL)
1498c2ecf20Sopenharmony_ci#define _TIF_PERSYSCALL_MASK	(_TIF_RESTOREALL|_TIF_NOERROR)
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_ci/* Bits in local_flags */
1528c2ecf20Sopenharmony_ci/* Don't move TLF_NAPPING without adjusting the code in entry_32.S */
1538c2ecf20Sopenharmony_ci#define TLF_NAPPING		0	/* idle thread enabled NAP mode */
1548c2ecf20Sopenharmony_ci#define TLF_SLEEPING		1	/* suspend code enabled SLEEP mode */
1558c2ecf20Sopenharmony_ci#define TLF_LAZY_MMU		3	/* tlb_batch is active */
1568c2ecf20Sopenharmony_ci#define TLF_RUNLATCH		4	/* Is the runlatch enabled? */
1578c2ecf20Sopenharmony_ci
1588c2ecf20Sopenharmony_ci#define _TLF_NAPPING		(1 << TLF_NAPPING)
1598c2ecf20Sopenharmony_ci#define _TLF_SLEEPING		(1 << TLF_SLEEPING)
1608c2ecf20Sopenharmony_ci#define _TLF_LAZY_MMU		(1 << TLF_LAZY_MMU)
1618c2ecf20Sopenharmony_ci#define _TLF_RUNLATCH		(1 << TLF_RUNLATCH)
1628c2ecf20Sopenharmony_ci
1638c2ecf20Sopenharmony_ci#ifndef __ASSEMBLY__
1648c2ecf20Sopenharmony_ci
1658c2ecf20Sopenharmony_cistatic inline bool test_thread_local_flags(unsigned int flags)
1668c2ecf20Sopenharmony_ci{
1678c2ecf20Sopenharmony_ci	struct thread_info *ti = current_thread_info();
1688c2ecf20Sopenharmony_ci	return (ti->local_flags & flags) != 0;
1698c2ecf20Sopenharmony_ci}
1708c2ecf20Sopenharmony_ci
1718c2ecf20Sopenharmony_ci#ifdef CONFIG_COMPAT
1728c2ecf20Sopenharmony_ci#define is_32bit_task()	(test_thread_flag(TIF_32BIT))
1738c2ecf20Sopenharmony_ci#else
1748c2ecf20Sopenharmony_ci#define is_32bit_task()	(IS_ENABLED(CONFIG_PPC32))
1758c2ecf20Sopenharmony_ci#endif
1768c2ecf20Sopenharmony_ci
1778c2ecf20Sopenharmony_ci#if defined(CONFIG_PPC64)
1788c2ecf20Sopenharmony_ci#define is_elf2_task() (test_thread_flag(TIF_ELF2ABI))
1798c2ecf20Sopenharmony_ci#else
1808c2ecf20Sopenharmony_ci#define is_elf2_task() (0)
1818c2ecf20Sopenharmony_ci#endif
1828c2ecf20Sopenharmony_ci
1838c2ecf20Sopenharmony_ci#endif	/* !__ASSEMBLY__ */
1848c2ecf20Sopenharmony_ci
1858c2ecf20Sopenharmony_ci#endif /* __KERNEL__ */
1868c2ecf20Sopenharmony_ci
1878c2ecf20Sopenharmony_ci#endif /* _ASM_POWERPC_THREAD_INFO_H */
188