~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/x86/include/asm/entry-common.h

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* SPDX-License-Identifier: GPL-2.0-only */
  2 #ifndef _ASM_X86_ENTRY_COMMON_H
  3 #define _ASM_X86_ENTRY_COMMON_H
  4 
  5 #include <linux/randomize_kstack.h>
  6 #include <linux/user-return-notifier.h>
  7 
  8 #include <asm/nospec-branch.h>
  9 #include <asm/io_bitmap.h>
 10 #include <asm/fpu/api.h>
 11 
 12 /* Check that the stack and regs on entry from user mode are sane. */
 13 static __always_inline void arch_enter_from_user_mode(struct pt_regs *regs)
 14 {
 15         if (IS_ENABLED(CONFIG_DEBUG_ENTRY)) {
 16                 /*
 17                  * Make sure that the entry code gave us a sensible EFLAGS
 18                  * register.  Native because we want to check the actual CPU
 19                  * state, not the interrupt state as imagined by Xen.
 20                  */
 21                 unsigned long flags = native_save_fl();
 22                 unsigned long mask = X86_EFLAGS_DF | X86_EFLAGS_NT;
 23 
 24                 /*
 25                  * For !SMAP hardware we patch out CLAC on entry.
 26                  */
 27                 if (cpu_feature_enabled(X86_FEATURE_SMAP) ||
 28                     cpu_feature_enabled(X86_FEATURE_XENPV))
 29                         mask |= X86_EFLAGS_AC;
 30 
 31                 WARN_ON_ONCE(flags & mask);
 32 
 33                 /* We think we came from user mode. Make sure pt_regs agrees. */
 34                 WARN_ON_ONCE(!user_mode(regs));
 35 
 36                 /*
 37                  * All entries from user mode (except #DF) should be on the
 38                  * normal thread stack and should have user pt_regs in the
 39                  * correct location.
 40                  */
 41                 WARN_ON_ONCE(!on_thread_stack());
 42                 WARN_ON_ONCE(regs != task_pt_regs(current));
 43         }
 44 }
 45 #define arch_enter_from_user_mode arch_enter_from_user_mode
 46 
 47 static inline void arch_exit_to_user_mode_prepare(struct pt_regs *regs,
 48                                                   unsigned long ti_work)
 49 {
 50         if (ti_work & _TIF_USER_RETURN_NOTIFY)
 51                 fire_user_return_notifiers();
 52 
 53         if (unlikely(ti_work & _TIF_IO_BITMAP))
 54                 tss_update_io_bitmap();
 55 
 56         fpregs_assert_state_consistent();
 57         if (unlikely(ti_work & _TIF_NEED_FPU_LOAD))
 58                 switch_fpu_return();
 59 
 60 #ifdef CONFIG_COMPAT
 61         /*
 62          * Compat syscalls set TS_COMPAT.  Make sure we clear it before
 63          * returning to user mode.  We need to clear it *after* signal
 64          * handling, because syscall restart has a fixup for compat
 65          * syscalls.  The fixup is exercised by the ptrace_syscall_32
 66          * selftest.
 67          *
 68          * We also need to clear TS_REGS_POKED_I386: the 32-bit tracer
 69          * special case only applies after poking regs and before the
 70          * very next return to user mode.
 71          */
 72         current_thread_info()->status &= ~(TS_COMPAT | TS_I386_REGS_POKED);
 73 #endif
 74 
 75         /*
 76          * This value will get limited by KSTACK_OFFSET_MAX(), which is 10
 77          * bits. The actual entropy will be further reduced by the compiler
 78          * when applying stack alignment constraints (see cc_stack_align4/8 in
 79          * arch/x86/Makefile), which will remove the 3 (x86_64) or 2 (ia32)
 80          * low bits from any entropy chosen here.
 81          *
 82          * Therefore, final stack offset entropy will be 7 (x86_64) or
 83          * 8 (ia32) bits.
 84          */
 85         choose_random_kstack_offset(rdtsc());
 86 }
 87 #define arch_exit_to_user_mode_prepare arch_exit_to_user_mode_prepare
 88 
 89 static __always_inline void arch_exit_to_user_mode(void)
 90 {
 91         amd_clear_divider();
 92 }
 93 #define arch_exit_to_user_mode arch_exit_to_user_mode
 94 
 95 #endif
 96 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php