The TS_COMPAT bit is very hot and is accessed from code paths that mostly
also touch thread_info::flags.  Move it into struct thread_info to improve
cache locality.
The only reason it was in thread_struct is that there was a brief period
during which arch-specific fields were not allowed in struct thread_info.
Linus suggested further changing:
  ti->status &= ~(TS_COMPAT|TS_I386_REGS_POKED);
to:
  if (unlikely(ti->status & (TS_COMPAT|TS_I386_REGS_POKED)))
          ti->status &= ~(TS_COMPAT|TS_I386_REGS_POKED);
on the theory that frequently dirtying the cacheline even in pure 64-bit
code that never needs to modify status hurts performance.  That could be a
reasonable followup patch, but I suspect it matters less on top of this
patch.
Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Andy Lutomirski <luto@kernel.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Ingo Molnar <mingo@kernel.org>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Kernel Hardening <kernel-hardening@lists.openwall.com>
Link: https://lkml.kernel.org/r/03148bcc1b217100e6e8ecf6a5468c45cf4304b6.1517164461.git.luto@kernel.org
         * special case only applies after poking regs and before the
         * very next return to user mode.
         */
-       current->thread.status &= ~(TS_COMPAT|TS_I386_REGS_POKED);
+       ti->status &= ~(TS_COMPAT|TS_I386_REGS_POKED);
 #endif
 
        user_enter_irqoff();
        unsigned int nr = (unsigned int)regs->orig_ax;
 
 #ifdef CONFIG_IA32_EMULATION
-       current->thread.status |= TS_COMPAT;
+       ti->status |= TS_COMPAT;
 #endif
 
        if (READ_ONCE(ti->flags) & _TIF_WORK_SYSCALL_ENTRY) {
 
        unsigned short          gsindex;
 #endif
 
-       u32                     status;         /* thread synchronous flags */
-
 #ifdef CONFIG_X86_64
        unsigned long           fsbase;
        unsigned long           gsbase;
 
         * TS_COMPAT is set for 32-bit syscall entries and then
         * remains set until we return to user mode.
         */
-       if (task->thread.status & (TS_COMPAT|TS_I386_REGS_POKED))
+       if (task->thread_info.status & (TS_COMPAT|TS_I386_REGS_POKED))
                /*
                 * Sign-extend the value so (int)-EFOO becomes (long)-EFOO
                 * and will match correctly in comparisons.
                                         unsigned long *args)
 {
 # ifdef CONFIG_IA32_EMULATION
-       if (task->thread.status & TS_COMPAT)
+       if (task->thread_info.status & TS_COMPAT)
                switch (i) {
                case 0:
                        if (!n--) break;
                                         const unsigned long *args)
 {
 # ifdef CONFIG_IA32_EMULATION
-       if (task->thread.status & TS_COMPAT)
+       if (task->thread_info.status & TS_COMPAT)
                switch (i) {
                case 0:
                        if (!n--) break;
 
 
 struct thread_info {
        unsigned long           flags;          /* low level flags */
+       u32                     status;         /* thread synchronous flags */
 };
 
 #define INIT_THREAD_INFO(tsk)                  \
 #define in_ia32_syscall() true
 #else
 #define in_ia32_syscall() (IS_ENABLED(CONFIG_IA32_EMULATION) && \
-                          current->thread.status & TS_COMPAT)
+                          current_thread_info()->status & TS_COMPAT)
 #endif
 
 /*
 
         * Pretend to come from a x32 execve.
         */
        task_pt_regs(current)->orig_ax = __NR_x32_execve | __X32_SYSCALL_BIT;
-       current->thread.status &= ~TS_COMPAT;
+       current_thread_info()->status &= ~TS_COMPAT;
 #endif
 }
 
        current->personality |= force_personality32;
        /* Prepare the first "return" to user space */
        task_pt_regs(current)->orig_ax = __NR_ia32_execve;
-       current->thread.status |= TS_COMPAT;
+       current_thread_info()->status |= TS_COMPAT;
 #endif
 }
 
 
                 */
                regs->orig_ax = value;
                if (syscall_get_nr(child, regs) >= 0)
-                       child->thread.status |= TS_I386_REGS_POKED;
+                       child->thread_info.status |= TS_I386_REGS_POKED;
                break;
 
        case offsetof(struct user32, regs.eflags):
 
         * than the tracee.
         */
 #ifdef CONFIG_IA32_EMULATION
-       if (current->thread.status & (TS_COMPAT|TS_I386_REGS_POKED))
+       if (current_thread_info()->status & (TS_COMPAT|TS_I386_REGS_POKED))
                return __NR_ia32_restart_syscall;
 #endif
 #ifdef CONFIG_X86_X32_ABI