x86/asm/entry/64: Simplify optimistic SYSRET
authorDenys Vlasenko <[email protected]>
Thu, 26 Feb 2015 22:40:38 +0000 (14:40 -0800)
committerIngo Molnar <[email protected]>
Wed, 4 Mar 2015 21:50:52 +0000 (22:50 +0100)
Avoid redundant load of %r11 (it is already loaded a few
instructions before).

Also simplify %rsp restoration, instead of two steps:

         add $0x80, %rsp
         mov 0x18(%rsp), %rsp

we can do a simplified single step to restore user-space RSP:

         mov 0x98(%rsp), %rsp

and get the same result.

Signed-off-by: Denys Vlasenko <[email protected]>
Signed-off-by: Andy Lutomirski <[email protected]>
[ Clarified the changelog. ]
Cc: Alexei Starovoitov <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Cc: H. Peter Anvin <[email protected]>
Cc: Kees Cook <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: Oleg Nesterov <[email protected]>
Cc: Steven Rostedt <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Will Drewry <[email protected]>
Link: http://lkml.kernel.org/r/1aef69b346a6db0d99cdfb0f5ba83e8c985e27d7.1424989793.git.luto@amacapital.net
Signed-off-by: Ingo Molnar <[email protected]>
arch/x86/include/asm/calling.h
arch/x86/kernel/entry_64.S

index 337423590b08bc9ebab72db831f89eb7c85a6eb2..f1a962ff7ddfc5a5f30365edbfb02b0bdfb13ef8 100644 (file)
@@ -176,6 +176,9 @@ For 32-bit we have the following conventions - kernel is built with
        .macro RESTORE_C_REGS_EXCEPT_RCX
        RESTORE_C_REGS_HELPER 1,0,1,1,1
        .endm
+       .macro RESTORE_C_REGS_EXCEPT_R11
+       RESTORE_C_REGS_HELPER 1,1,0,1,1
+       .endm
        .macro RESTORE_RSI_RDI
        RESTORE_C_REGS_HELPER 0,0,0,0,0
        .endm
index 858e94e86f5e293cb91030fb7f0bef39a4360c31..bc1527889c406a95a1f22845ee31856c74636cec 100644 (file)
@@ -757,9 +757,9 @@ retint_swapgs:              /* return to user-space */
         */
 irq_return_via_sysret:
        CFI_REMEMBER_STATE
-       RESTORE_C_REGS
-       REMOVE_PT_GPREGS_FROM_STACK 8
-       movq (RSP-RIP)(%rsp),%rsp
+       /* r11 is already restored (see code above) */
+       RESTORE_C_REGS_EXCEPT_R11
+       movq RSP(%rsp),%rsp
        USERGS_SYSRET64
        CFI_RESTORE_STATE