Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /* thread_info.h: low-level thread information
0003  *
0004  * Copyright (C) 2002  David Howells (dhowells@redhat.com)
0005  * - Incorporating suggestions made by Linus Torvalds and Dave Miller
0006  */
0007 
0008 #ifndef _ASM_X86_THREAD_INFO_H
0009 #define _ASM_X86_THREAD_INFO_H
0010 
0011 #include <linux/compiler.h>
0012 #include <asm/page.h>
0013 #include <asm/percpu.h>
0014 #include <asm/types.h>
0015 
0016 /*
0017  * TOP_OF_KERNEL_STACK_PADDING is a number of unused bytes that we
0018  * reserve at the top of the kernel stack.  We do it because of a nasty
0019  * 32-bit corner case.  On x86_32, the hardware stack frame is
0020  * variable-length.  Except for vm86 mode, struct pt_regs assumes a
0021  * maximum-length frame.  If we enter from CPL 0, the top 8 bytes of
0022  * pt_regs don't actually exist.  Ordinarily this doesn't matter, but it
0023  * does in at least one case:
0024  *
0025  * If we take an NMI early enough in SYSENTER, then we can end up with
0026  * pt_regs that extends above sp0.  On the way out, in the espfix code,
0027  * we can read the saved SS value, but that value will be above sp0.
0028  * Without this offset, that can result in a page fault.  (We are
0029  * careful that, in this case, the value we read doesn't matter.)
0030  *
0031  * In vm86 mode, the hardware frame is much longer still, so add 16
0032  * bytes to make room for the real-mode segments.
0033  *
0034  * x86_64 has a fixed-length stack frame.
0035  */
0036 #ifdef CONFIG_X86_32
0037 # ifdef CONFIG_VM86
0038 #  define TOP_OF_KERNEL_STACK_PADDING 16
0039 # else
0040 #  define TOP_OF_KERNEL_STACK_PADDING 8
0041 # endif
0042 #else
0043 # define TOP_OF_KERNEL_STACK_PADDING 0
0044 #endif
0045 
0046 /*
0047  * low level task data that entry.S needs immediate access to
0048  * - this struct should fit entirely inside of one cache line
0049  * - this struct shares the supervisor stack pages
0050  */
0051 #ifndef __ASSEMBLY__
0052 struct task_struct;
0053 #include <asm/cpufeature.h>
0054 #include <linux/atomic.h>
0055 
0056 struct thread_info {
0057     unsigned long       flags;      /* low level flags */
0058     unsigned long       syscall_work;   /* SYSCALL_WORK_ flags */
0059     u32         status;     /* thread synchronous flags */
0060 #ifdef CONFIG_SMP
0061     u32         cpu;        /* current CPU */
0062 #endif
0063 };
0064 
0065 #define INIT_THREAD_INFO(tsk)           \
0066 {                       \
0067     .flags      = 0,            \
0068 }
0069 
0070 #else /* !__ASSEMBLY__ */
0071 
0072 #include <asm/asm-offsets.h>
0073 
0074 #endif
0075 
0076 /*
0077  * thread information flags
0078  * - these are process state flags that various assembly files
0079  *   may need to access
0080  */
0081 #define TIF_NOTIFY_RESUME   1   /* callback before returning to user */
0082 #define TIF_SIGPENDING      2   /* signal pending */
0083 #define TIF_NEED_RESCHED    3   /* rescheduling necessary */
0084 #define TIF_SINGLESTEP      4   /* reenable singlestep on user return*/
0085 #define TIF_SSBD        5   /* Speculative store bypass disable */
0086 #define TIF_SPEC_IB     9   /* Indirect branch speculation mitigation */
0087 #define TIF_SPEC_L1D_FLUSH  10  /* Flush L1D on mm switches (processes) */
0088 #define TIF_USER_RETURN_NOTIFY  11  /* notify kernel of userspace return */
0089 #define TIF_UPROBE      12  /* breakpointed or singlestepping */
0090 #define TIF_PATCH_PENDING   13  /* pending live patching update */
0091 #define TIF_NEED_FPU_LOAD   14  /* load FPU on return to userspace */
0092 #define TIF_NOCPUID     15  /* CPUID is not accessible in userland */
0093 #define TIF_NOTSC       16  /* TSC is not accessible in userland */
0094 #define TIF_NOTIFY_SIGNAL   17  /* signal notifications exist */
0095 #define TIF_MEMDIE      20  /* is terminating due to OOM killer */
0096 #define TIF_POLLING_NRFLAG  21  /* idle is polling for TIF_NEED_RESCHED */
0097 #define TIF_IO_BITMAP       22  /* uses I/O bitmap */
0098 #define TIF_SPEC_FORCE_UPDATE   23  /* Force speculation MSR update in context switch */
0099 #define TIF_FORCED_TF       24  /* true if TF in eflags artificially */
0100 #define TIF_BLOCKSTEP       25  /* set when we want DEBUGCTLMSR_BTF */
0101 #define TIF_LAZY_MMU_UPDATES    27  /* task is updating the mmu lazily */
0102 #define TIF_ADDR32      29  /* 32-bit address space on 64 bits */
0103 
0104 #define _TIF_NOTIFY_RESUME  (1 << TIF_NOTIFY_RESUME)
0105 #define _TIF_SIGPENDING     (1 << TIF_SIGPENDING)
0106 #define _TIF_NEED_RESCHED   (1 << TIF_NEED_RESCHED)
0107 #define _TIF_SINGLESTEP     (1 << TIF_SINGLESTEP)
0108 #define _TIF_SSBD       (1 << TIF_SSBD)
0109 #define _TIF_SPEC_IB        (1 << TIF_SPEC_IB)
0110 #define _TIF_SPEC_L1D_FLUSH (1 << TIF_SPEC_L1D_FLUSH)
0111 #define _TIF_USER_RETURN_NOTIFY (1 << TIF_USER_RETURN_NOTIFY)
0112 #define _TIF_UPROBE     (1 << TIF_UPROBE)
0113 #define _TIF_PATCH_PENDING  (1 << TIF_PATCH_PENDING)
0114 #define _TIF_NEED_FPU_LOAD  (1 << TIF_NEED_FPU_LOAD)
0115 #define _TIF_NOCPUID        (1 << TIF_NOCPUID)
0116 #define _TIF_NOTSC      (1 << TIF_NOTSC)
0117 #define _TIF_NOTIFY_SIGNAL  (1 << TIF_NOTIFY_SIGNAL)
0118 #define _TIF_POLLING_NRFLAG (1 << TIF_POLLING_NRFLAG)
0119 #define _TIF_IO_BITMAP      (1 << TIF_IO_BITMAP)
0120 #define _TIF_SPEC_FORCE_UPDATE  (1 << TIF_SPEC_FORCE_UPDATE)
0121 #define _TIF_FORCED_TF      (1 << TIF_FORCED_TF)
0122 #define _TIF_BLOCKSTEP      (1 << TIF_BLOCKSTEP)
0123 #define _TIF_LAZY_MMU_UPDATES   (1 << TIF_LAZY_MMU_UPDATES)
0124 #define _TIF_ADDR32     (1 << TIF_ADDR32)
0125 
0126 /* flags to check in __switch_to() */
0127 #define _TIF_WORK_CTXSW_BASE                    \
0128     (_TIF_NOCPUID | _TIF_NOTSC | _TIF_BLOCKSTEP |       \
0129      _TIF_SSBD | _TIF_SPEC_FORCE_UPDATE)
0130 
0131 /*
0132  * Avoid calls to __switch_to_xtra() on UP as STIBP is not evaluated.
0133  */
0134 #ifdef CONFIG_SMP
0135 # define _TIF_WORK_CTXSW    (_TIF_WORK_CTXSW_BASE | _TIF_SPEC_IB)
0136 #else
0137 # define _TIF_WORK_CTXSW    (_TIF_WORK_CTXSW_BASE)
0138 #endif
0139 
0140 #ifdef CONFIG_X86_IOPL_IOPERM
0141 # define _TIF_WORK_CTXSW_PREV   (_TIF_WORK_CTXSW| _TIF_USER_RETURN_NOTIFY | \
0142                  _TIF_IO_BITMAP)
0143 #else
0144 # define _TIF_WORK_CTXSW_PREV   (_TIF_WORK_CTXSW| _TIF_USER_RETURN_NOTIFY)
0145 #endif
0146 
0147 #define _TIF_WORK_CTXSW_NEXT    (_TIF_WORK_CTXSW)
0148 
0149 #define STACK_WARN      (THREAD_SIZE/8)
0150 
0151 /*
0152  * macros/functions for gaining access to the thread information structure
0153  *
0154  * preempt_count needs to be 1 initially, until the scheduler is functional.
0155  */
0156 #ifndef __ASSEMBLY__
0157 
0158 /*
0159  * Walks up the stack frames to make sure that the specified object is
0160  * entirely contained by a single stack frame.
0161  *
0162  * Returns:
0163  *  GOOD_FRAME  if within a frame
0164  *  BAD_STACK   if placed across a frame boundary (or outside stack)
0165  *  NOT_STACK   unable to determine (no frame pointers, etc)
0166  */
0167 static inline int arch_within_stack_frames(const void * const stack,
0168                        const void * const stackend,
0169                        const void *obj, unsigned long len)
0170 {
0171 #if defined(CONFIG_FRAME_POINTER)
0172     const void *frame = NULL;
0173     const void *oldframe;
0174 
0175     oldframe = __builtin_frame_address(1);
0176     if (oldframe)
0177         frame = __builtin_frame_address(2);
0178     /*
0179      * low ----------------------------------------------> high
0180      * [saved bp][saved ip][args][local vars][saved bp][saved ip]
0181      *                     ^----------------^
0182      *               allow copies only within here
0183      */
0184     while (stack <= frame && frame < stackend) {
0185         /*
0186          * If obj + len extends past the last frame, this
0187          * check won't pass and the next frame will be 0,
0188          * causing us to bail out and correctly report
0189          * the copy as invalid.
0190          */
0191         if (obj + len <= frame)
0192             return obj >= oldframe + 2 * sizeof(void *) ?
0193                 GOOD_FRAME : BAD_STACK;
0194         oldframe = frame;
0195         frame = *(const void * const *)frame;
0196     }
0197     return BAD_STACK;
0198 #else
0199     return NOT_STACK;
0200 #endif
0201 }
0202 
0203 #endif  /* !__ASSEMBLY__ */
0204 
0205 /*
0206  * Thread-synchronous status.
0207  *
0208  * This is different from the flags in that nobody else
0209  * ever touches our thread-synchronous status, so we don't
0210  * have to worry about atomic accesses.
0211  */
0212 #define TS_COMPAT       0x0002  /* 32bit syscall active (64BIT)*/
0213 
0214 #ifndef __ASSEMBLY__
0215 #ifdef CONFIG_COMPAT
0216 #define TS_I386_REGS_POKED  0x0004  /* regs poked by 32-bit ptracer */
0217 
0218 #define arch_set_restart_data(restart)  \
0219     do { restart->arch_data = current_thread_info()->status; } while (0)
0220 
0221 #endif
0222 
0223 #ifdef CONFIG_X86_32
0224 #define in_ia32_syscall() true
0225 #else
0226 #define in_ia32_syscall() (IS_ENABLED(CONFIG_IA32_EMULATION) && \
0227                current_thread_info()->status & TS_COMPAT)
0228 #endif
0229 
0230 extern void arch_task_cache_init(void);
0231 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
0232 extern void arch_release_task_struct(struct task_struct *tsk);
0233 extern void arch_setup_new_exec(void);
0234 #define arch_setup_new_exec arch_setup_new_exec
0235 #endif  /* !__ASSEMBLY__ */
0236 
0237 #endif /* _ASM_X86_THREAD_INFO_H */