Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /* thread_info.h: PowerPC low-level thread information
0003  * adapted from the i386 version by Paul Mackerras
0004  *
0005  * Copyright (C) 2002  David Howells (dhowells@redhat.com)
0006  * - Incorporating suggestions made by Linus Torvalds and Dave Miller
0007  */
0008 
0009 #ifndef _ASM_POWERPC_THREAD_INFO_H
0010 #define _ASM_POWERPC_THREAD_INFO_H
0011 
0012 #include <asm/asm-const.h>
0013 #include <asm/page.h>
0014 
0015 #ifdef __KERNEL__
0016 
0017 #ifdef CONFIG_KASAN
0018 #define MIN_THREAD_SHIFT    (CONFIG_THREAD_SHIFT + 1)
0019 #else
0020 #define MIN_THREAD_SHIFT    CONFIG_THREAD_SHIFT
0021 #endif
0022 
0023 #if defined(CONFIG_VMAP_STACK) && MIN_THREAD_SHIFT < PAGE_SHIFT
0024 #define THREAD_SHIFT        PAGE_SHIFT
0025 #else
0026 #define THREAD_SHIFT        MIN_THREAD_SHIFT
0027 #endif
0028 
0029 #define THREAD_SIZE     (1 << THREAD_SHIFT)
0030 
0031 /*
0032  * By aligning VMAP'd stacks to 2 * THREAD_SIZE, we can detect overflow by
0033  * checking sp & (1 << THREAD_SHIFT), which we can do cheaply in the entry
0034  * assembly.
0035  */
0036 #ifdef CONFIG_VMAP_STACK
0037 #define THREAD_ALIGN_SHIFT  (THREAD_SHIFT + 1)
0038 #else
0039 #define THREAD_ALIGN_SHIFT  THREAD_SHIFT
0040 #endif
0041 
0042 #define THREAD_ALIGN        (1 << THREAD_ALIGN_SHIFT)
0043 
0044 #ifndef __ASSEMBLY__
0045 #include <linux/cache.h>
0046 #include <asm/processor.h>
0047 #include <asm/accounting.h>
0048 
0049 #define SLB_PRELOAD_NR  16U
0050 /*
0051  * low level task data.
0052  */
0053 struct thread_info {
0054     int     preempt_count;      /* 0 => preemptable,
0055                            <0 => BUG */
0056 #ifdef CONFIG_SMP
0057     unsigned int    cpu;
0058 #endif
0059     unsigned long   local_flags;        /* private flags for thread */
0060 #ifdef CONFIG_LIVEPATCH_64
0061     unsigned long *livepatch_sp;
0062 #endif
0063 #if defined(CONFIG_VIRT_CPU_ACCOUNTING_NATIVE) && defined(CONFIG_PPC32)
0064     struct cpu_accounting_data accounting;
0065 #endif
0066     unsigned char slb_preload_nr;
0067     unsigned char slb_preload_tail;
0068     u32 slb_preload_esid[SLB_PRELOAD_NR];
0069 
0070     /* low level flags - has atomic operations done on it */
0071     unsigned long   flags ____cacheline_aligned_in_smp;
0072 };
0073 
0074 /*
0075  * macros/functions for gaining access to the thread information structure
0076  */
0077 #define INIT_THREAD_INFO(tsk)           \
0078 {                       \
0079     .preempt_count = INIT_PREEMPT_COUNT,    \
0080     .flags =    0,          \
0081 }
0082 
0083 #define THREAD_SIZE_ORDER   (THREAD_SHIFT - PAGE_SHIFT)
0084 
0085 /* how to get the thread information struct from C */
0086 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
0087 
0088 void arch_setup_new_exec(void);
0089 #define arch_setup_new_exec arch_setup_new_exec
0090 
0091 #endif /* __ASSEMBLY__ */
0092 
0093 /*
0094  * thread information flag bit numbers
0095  */
0096 #define TIF_SYSCALL_TRACE   0   /* syscall trace active */
0097 #define TIF_SIGPENDING      1   /* signal pending */
0098 #define TIF_NEED_RESCHED    2   /* rescheduling necessary */
0099 #define TIF_NOTIFY_SIGNAL   3   /* signal notifications exist */
0100 #define TIF_SYSCALL_EMU     4   /* syscall emulation active */
0101 #define TIF_RESTORE_TM      5   /* need to restore TM FP/VEC/VSX */
0102 #define TIF_PATCH_PENDING   6   /* pending live patching update */
0103 #define TIF_SYSCALL_AUDIT   7   /* syscall auditing active */
0104 #define TIF_SINGLESTEP      8   /* singlestepping active */
0105 #define TIF_SECCOMP     10  /* secure computing */
0106 #define TIF_RESTOREALL      11  /* Restore all regs (implies NOERROR) */
0107 #define TIF_NOERROR     12  /* Force successful syscall return */
0108 #define TIF_NOTIFY_RESUME   13  /* callback before returning to user */
0109 #define TIF_UPROBE      14  /* breakpointed or single-stepping */
0110 #define TIF_SYSCALL_TRACEPOINT  15  /* syscall tracepoint instrumentation */
0111 #define TIF_EMULATE_STACK_STORE 16  /* Is an instruction emulation
0112                         for stack store? */
0113 #define TIF_MEMDIE      17  /* is terminating due to OOM killer */
0114 #if defined(CONFIG_PPC64)
0115 #define TIF_ELF2ABI     18  /* function descriptors must die! */
0116 #endif
0117 #define TIF_POLLING_NRFLAG  19  /* true if poll_idle() is polling TIF_NEED_RESCHED */
0118 #define TIF_32BIT       20  /* 32 bit binary */
0119 
0120 /* as above, but as bit values */
0121 #define _TIF_SYSCALL_TRACE  (1<<TIF_SYSCALL_TRACE)
0122 #define _TIF_SIGPENDING     (1<<TIF_SIGPENDING)
0123 #define _TIF_NEED_RESCHED   (1<<TIF_NEED_RESCHED)
0124 #define _TIF_NOTIFY_SIGNAL  (1<<TIF_NOTIFY_SIGNAL)
0125 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
0126 #define _TIF_32BIT      (1<<TIF_32BIT)
0127 #define _TIF_RESTORE_TM     (1<<TIF_RESTORE_TM)
0128 #define _TIF_PATCH_PENDING  (1<<TIF_PATCH_PENDING)
0129 #define _TIF_SYSCALL_AUDIT  (1<<TIF_SYSCALL_AUDIT)
0130 #define _TIF_SINGLESTEP     (1<<TIF_SINGLESTEP)
0131 #define _TIF_SECCOMP        (1<<TIF_SECCOMP)
0132 #define _TIF_RESTOREALL     (1<<TIF_RESTOREALL)
0133 #define _TIF_NOERROR        (1<<TIF_NOERROR)
0134 #define _TIF_NOTIFY_RESUME  (1<<TIF_NOTIFY_RESUME)
0135 #define _TIF_UPROBE     (1<<TIF_UPROBE)
0136 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
0137 #define _TIF_EMULATE_STACK_STORE    (1<<TIF_EMULATE_STACK_STORE)
0138 #define _TIF_SYSCALL_EMU    (1<<TIF_SYSCALL_EMU)
0139 #define _TIF_SYSCALL_DOTRACE    (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
0140                  _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
0141                  _TIF_SYSCALL_EMU)
0142 
0143 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
0144                  _TIF_NOTIFY_RESUME | _TIF_UPROBE | \
0145                  _TIF_RESTORE_TM | _TIF_PATCH_PENDING | \
0146                  _TIF_NOTIFY_SIGNAL)
0147 #define _TIF_PERSYSCALL_MASK    (_TIF_RESTOREALL|_TIF_NOERROR)
0148 
0149 /* Bits in local_flags */
0150 /* Don't move TLF_NAPPING without adjusting the code in entry_32.S */
0151 #define TLF_NAPPING     0   /* idle thread enabled NAP mode */
0152 #define TLF_SLEEPING        1   /* suspend code enabled SLEEP mode */
0153 #define TLF_LAZY_MMU        3   /* tlb_batch is active */
0154 #define TLF_RUNLATCH        4   /* Is the runlatch enabled? */
0155 
0156 #define _TLF_NAPPING        (1 << TLF_NAPPING)
0157 #define _TLF_SLEEPING       (1 << TLF_SLEEPING)
0158 #define _TLF_LAZY_MMU       (1 << TLF_LAZY_MMU)
0159 #define _TLF_RUNLATCH       (1 << TLF_RUNLATCH)
0160 
0161 #ifndef __ASSEMBLY__
0162 
0163 static inline void clear_thread_local_flags(unsigned int flags)
0164 {
0165     struct thread_info *ti = current_thread_info();
0166     ti->local_flags &= ~flags;
0167 }
0168 
0169 static inline bool test_thread_local_flags(unsigned int flags)
0170 {
0171     struct thread_info *ti = current_thread_info();
0172     return (ti->local_flags & flags) != 0;
0173 }
0174 
0175 #ifdef CONFIG_COMPAT
0176 #define is_32bit_task() (test_thread_flag(TIF_32BIT))
0177 #define is_tsk_32bit_task(tsk)  (test_tsk_thread_flag(tsk, TIF_32BIT))
0178 #else
0179 #define is_32bit_task() (IS_ENABLED(CONFIG_PPC32))
0180 #define is_tsk_32bit_task(tsk)  (IS_ENABLED(CONFIG_PPC32))
0181 #endif
0182 
0183 #if defined(CONFIG_PPC64)
0184 #define is_elf2_task() (test_thread_flag(TIF_ELF2ABI))
0185 #else
0186 #define is_elf2_task() (0)
0187 #endif
0188 
0189 #endif  /* !__ASSEMBLY__ */
0190 
0191 #endif /* __KERNEL__ */
0192 
0193 #endif /* _ASM_POWERPC_THREAD_INFO_H */