x86/entry/64: Split the IRET-to-user and IRET-to-kernel paths
authorAndy Lutomirski <luto@kernel.org>
Thu, 2 Nov 2017 07:58:59 +0000 (00:58 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 25 Dec 2017 13:26:16 +0000 (14:26 +0100)
commit 26c4ef9c49d8a0341f6d97ce2cfdd55d1236ed29 upstream.

These code paths will diverge soon.

Signed-off-by: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bpetkov@suse.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dave Hansen <dave.hansen@intel.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/dccf8c7b3750199b4b30383c812d4e2931811509.1509609304.git.luto@kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
arch/x86/entry/entry_64.S
arch/x86/entry/entry_64_compat.S
arch/x86/kernel/head_64.S

index 33eb2127eac8bf8cf9da0d13926c1088c5b33303..9e262c8ccc2d97ffc8d9d68489fc6b07dc956d24 100644 (file)
@@ -322,7 +322,7 @@ syscall_return_via_sysret:
 
 opportunistic_sysret_failed:
        SWAPGS
-       jmp     restore_regs_and_iret
+       jmp     restore_regs_and_return_to_usermode
 END(entry_SYSCALL_64)
 
 ENTRY(stub_ptregs_64)
@@ -424,7 +424,7 @@ ENTRY(ret_from_fork)
        call    syscall_return_slowpath /* returns with IRQs disabled */
        TRACE_IRQS_ON                   /* user mode is traced as IRQS on */
        SWAPGS
-       jmp     restore_regs_and_iret
+       jmp     restore_regs_and_return_to_usermode
 
 1:
        /* kernel thread */
@@ -613,7 +613,20 @@ GLOBAL(retint_user)
        call    prepare_exit_to_usermode
        TRACE_IRQS_IRETQ
        SWAPGS
-       jmp     restore_regs_and_iret
+
+GLOBAL(restore_regs_and_return_to_usermode)
+#ifdef CONFIG_DEBUG_ENTRY
+       /* Assert that pt_regs indicates user mode. */
+       testl   $3, CS(%rsp)
+       jnz     1f
+       ud2
+1:
+#endif
+       RESTORE_EXTRA_REGS
+       RESTORE_C_REGS
+       REMOVE_PT_GPREGS_FROM_STACK 8
+       INTERRUPT_RETURN
+
 
 /* Returning to kernel space */
 retint_kernel:
@@ -633,11 +646,14 @@ retint_kernel:
         */
        TRACE_IRQS_IRETQ
 
-/*
- * At this label, code paths which return to kernel and to user,
- * which come from interrupts/exception and from syscalls, merge.
- */
-GLOBAL(restore_regs_and_iret)
+GLOBAL(restore_regs_and_return_to_kernel)
+#ifdef CONFIG_DEBUG_ENTRY
+       /* Assert that pt_regs indicates kernel mode. */
+       testl   $3, CS(%rsp)
+       jz      1f
+       ud2
+1:
+#endif
        RESTORE_EXTRA_REGS
        RESTORE_C_REGS
        REMOVE_PT_GPREGS_FROM_STACK 8
@@ -1328,7 +1344,7 @@ ENTRY(nmi)
         * work, because we don't want to enable interrupts.
         */
        SWAPGS
-       jmp     restore_regs_and_iret
+       jmp     restore_regs_and_return_to_usermode
 
 .Lnmi_from_kernel:
        /*
index b5c7a56ed256d4cb12d55a18bdaa045229b8093d..2fd682212d1d6ca96691be7ee95d308db81c99c6 100644 (file)
@@ -338,7 +338,7 @@ ENTRY(entry_INT80_compat)
        /* Go back to user mode. */
        TRACE_IRQS_ON
        SWAPGS
-       jmp     restore_regs_and_iret
+       jmp     restore_regs_and_return_to_usermode
 END(entry_INT80_compat)
 
 ENTRY(stub32_clone)
index 1f747734318dab757f53345bce08e9c3c5874fff..7dca675fe78db60c5d79bc450bbd14bfee35cfc2 100644 (file)
@@ -328,7 +328,7 @@ early_idt_handler_common:
 
 20:
        decl early_recursion_flag(%rip)
-       jmp restore_regs_and_iret
+       jmp restore_regs_and_return_to_kernel
 END(early_idt_handler_common)
 
        __INITDATA