2015-04-07 20:43:57

by Denys Vlasenko

[permalink] [raw]
Subject: [PATCH 1/8] x86/asm/entry/64: Use common code for rt_sigreturn epilogue

Similarly to stub_execve, we can reuse the epilogue in stub_rt_sigreturn
and stub_x32_rt_sigreturn.

Add a comment explaining why we can't eliminage SAVE_EXTRA_REGS here.

Signed-off-by: Denys Vlasenko <[email protected]>
CC: Linus Torvalds <[email protected]>
CC: Steven Rostedt <[email protected]>
CC: Ingo Molnar <[email protected]>
CC: Borislav Petkov <[email protected]>
CC: "H. Peter Anvin" <[email protected]>
CC: Andy Lutomirski <[email protected]>
CC: Oleg Nesterov <[email protected]>
CC: Frederic Weisbecker <[email protected]>
CC: Alexei Starovoitov <[email protected]>
CC: Will Drewry <[email protected]>
CC: Kees Cook <[email protected]>
CC: [email protected]
CC: [email protected]
---
arch/x86/kernel/entry_64.S | 26 ++++++++++++++++----------
1 file changed, 16 insertions(+), 10 deletions(-)

diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
index 15261ba..994f3cb 100644
--- a/arch/x86/kernel/entry_64.S
+++ b/arch/x86/kernel/entry_64.S
@@ -450,12 +450,21 @@ END(stub_execveat)
*/
ENTRY(stub_rt_sigreturn)
CFI_STARTPROC
- addq $8, %rsp
- DEFAULT_FRAME 0
- SAVE_EXTRA_REGS
+ DEFAULT_FRAME 0, 8
+ /*
+ * SAVE_EXTRA_REGS result is not normally needed:
+ * sigreturn overwrites all pt_regs->GPREGS.
+ * But sigreturn can fail (!), and there is no easy way to detect that.
+ * To make sure RESTORE_EXTRA_REGS doesn't restore garbage on error,
+ * we SAVE_EXTRA_REGS here.
+ */
+ SAVE_EXTRA_REGS 8
call sys_rt_sigreturn
- movq %rax,RAX(%rsp) # fixme, this could be done at the higher layer
+return_from_stub:
+ addq $8, %rsp
+ CFI_ADJUST_CFA_OFFSET -8
RESTORE_EXTRA_REGS
+ movq %rax,RAX(%rsp)
jmp int_ret_from_sys_call
CFI_ENDPROC
END(stub_rt_sigreturn)
@@ -463,13 +472,10 @@ END(stub_rt_sigreturn)
#ifdef CONFIG_X86_X32_ABI
ENTRY(stub_x32_rt_sigreturn)
CFI_STARTPROC
- addq $8, %rsp
- DEFAULT_FRAME 0
- SAVE_EXTRA_REGS
+ DEFAULT_FRAME 0, 8
+ SAVE_EXTRA_REGS 8
call sys32_x32_rt_sigreturn
- movq %rax,RAX(%rsp) # fixme, this could be done at the higher layer
- RESTORE_EXTRA_REGS
- jmp int_ret_from_sys_call
+ jmp return_from_stub
CFI_ENDPROC
END(stub_x32_rt_sigreturn)

--
1.8.1.4


2015-04-07 20:44:11

by Denys Vlasenko

[permalink] [raw]
Subject: [PATCH 2/8] x86/asm/entry/64: Move stub_x32_execve[at] closer to stub_execveat

This is a preparatory patch for moving stub32_execve[at] to this file.
It makes sense to have all execve stubs in one place, so that they can reuse code.

Signed-off-by: Denys Vlasenko <[email protected]>
CC: Linus Torvalds <[email protected]>
CC: Steven Rostedt <[email protected]>
CC: Ingo Molnar <[email protected]>
CC: Borislav Petkov <[email protected]>
CC: "H. Peter Anvin" <[email protected]>
CC: Andy Lutomirski <[email protected]>
CC: Oleg Nesterov <[email protected]>
CC: Frederic Weisbecker <[email protected]>
CC: Alexei Starovoitov <[email protected]>
CC: Will Drewry <[email protected]>
CC: Kees Cook <[email protected]>
CC: [email protected]
CC: [email protected]
---
arch/x86/kernel/entry_64.S | 34 +++++++++++++++++-----------------
1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
index 994f3cb..1b0793c 100644
--- a/arch/x86/kernel/entry_64.S
+++ b/arch/x86/kernel/entry_64.S
@@ -444,6 +444,23 @@ ENTRY(stub_execveat)
CFI_ENDPROC
END(stub_execveat)

+#ifdef CONFIG_X86_X32_ABI
+ENTRY(stub_x32_execve)
+ CFI_STARTPROC
+ DEFAULT_FRAME 0, 8
+ call compat_sys_execve
+ jmp return_from_execve
+ CFI_ENDPROC
+END(stub_x32_execve)
+ENTRY(stub_x32_execveat)
+ CFI_STARTPROC
+ DEFAULT_FRAME 0, 8
+ call compat_sys_execveat
+ jmp return_from_execve
+ CFI_ENDPROC
+END(stub_x32_execveat)
+#endif
+
/*
* sigreturn is special because it needs to restore all registers on return.
* This cannot be done with SYSRET, so use the IRET return path instead.
@@ -478,23 +495,6 @@ ENTRY(stub_x32_rt_sigreturn)
jmp return_from_stub
CFI_ENDPROC
END(stub_x32_rt_sigreturn)
-
-ENTRY(stub_x32_execve)
- CFI_STARTPROC
- DEFAULT_FRAME 0, 8
- call compat_sys_execve
- jmp return_from_execve
- CFI_ENDPROC
-END(stub_x32_execve)
-
-ENTRY(stub_x32_execveat)
- CFI_STARTPROC
- DEFAULT_FRAME 0, 8
- call compat_sys_execveat
- jmp return_from_execve
- CFI_ENDPROC
-END(stub_x32_execveat)
-
#endif

/*
--
1.8.1.4

2015-04-07 20:44:42

by Denys Vlasenko

[permalink] [raw]
Subject: [PATCH 3/8] x86/asm/entry: Zero EXTRA_REGS for stub32_execve[at] too

The change which affected how execve clears EXTRA_REGS missed
32-bit execve syscalls.

Fix this by using 64-bit execve stub epilogue for them too.

Run-tested.

Signed-off-by: Denys Vlasenko <[email protected]>
CC: Linus Torvalds <[email protected]>
CC: Steven Rostedt <[email protected]>
CC: Ingo Molnar <[email protected]>
CC: Borislav Petkov <[email protected]>
CC: "H. Peter Anvin" <[email protected]>
CC: Andy Lutomirski <[email protected]>
CC: Oleg Nesterov <[email protected]>
CC: Frederic Weisbecker <[email protected]>
CC: Alexei Starovoitov <[email protected]>
CC: Will Drewry <[email protected]>
CC: Kees Cook <[email protected]>
CC: [email protected]
CC: [email protected]
---
arch/x86/ia32/ia32entry.S | 2 --
arch/x86/kernel/entry_64.S | 15 +++++++++++++++
2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
index 5d8f987..a821b1c 100644
--- a/arch/x86/ia32/ia32entry.S
+++ b/arch/x86/ia32/ia32entry.S
@@ -571,8 +571,6 @@ GLOBAL(\label)

PTREGSCALL stub32_rt_sigreturn, sys32_rt_sigreturn
PTREGSCALL stub32_sigreturn, sys32_sigreturn
- PTREGSCALL stub32_execve, compat_sys_execve
- PTREGSCALL stub32_execveat, compat_sys_execveat
PTREGSCALL stub32_fork, sys_fork
PTREGSCALL stub32_vfork, sys_vfork

diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
index 1b0793c..8e3ba38 100644
--- a/arch/x86/kernel/entry_64.S
+++ b/arch/x86/kernel/entry_64.S
@@ -461,6 +461,21 @@ ENTRY(stub_x32_execveat)
END(stub_x32_execveat)
#endif

+#ifdef CONFIG_IA32_EMULATION
+ENTRY(stub32_execve)
+ CFI_STARTPROC
+ call compat_sys_execve
+ jmp return_from_execve
+ CFI_ENDPROC
+END(stub32_execve)
+ENTRY(stub32_execveat)
+ CFI_STARTPROC
+ call compat_sys_execveat
+ jmp return_from_execve
+ CFI_ENDPROC
+END(stub32_execveat)
+#endif
+
/*
* sigreturn is special because it needs to restore all registers on return.
* This cannot be done with SYSRET, so use the IRET return path instead.
--
1.8.1.4

2015-04-07 20:44:31

by Denys Vlasenko

[permalink] [raw]
Subject: [PATCH 4/8] x86/asm/entry/64: optimize [v]fork/clone stubs

Replace "call func; ret" with "jmp func".

Run-tested.

Signed-off-by: Denys Vlasenko <[email protected]>
CC: Linus Torvalds <[email protected]>
CC: Steven Rostedt <[email protected]>
CC: Ingo Molnar <[email protected]>
CC: Borislav Petkov <[email protected]>
CC: "H. Peter Anvin" <[email protected]>
CC: Andy Lutomirski <[email protected]>
CC: Oleg Nesterov <[email protected]>
CC: Frederic Weisbecker <[email protected]>
CC: Alexei Starovoitov <[email protected]>
CC: Will Drewry <[email protected]>
CC: Kees Cook <[email protected]>
CC: [email protected]
CC: [email protected]
---
arch/x86/kernel/entry_64.S | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
index 8e3ba38..6ad30a7 100644
--- a/arch/x86/kernel/entry_64.S
+++ b/arch/x86/kernel/entry_64.S
@@ -407,8 +407,7 @@ ENTRY(stub_\func)
CFI_STARTPROC
DEFAULT_FRAME 0, 8 /* offset 8: return address */
SAVE_EXTRA_REGS 8
- call sys_\func
- ret
+ jmp sys_\func
CFI_ENDPROC
END(stub_\func)
.endm
--
1.8.1.4

2015-04-07 20:45:08

by Denys Vlasenko

[permalink] [raw]
Subject: [PATCH 5/8] x86/asm/entry/64: remove a redundant jump

Jumping to the very next instruction is not very useful:

jmp label
label:

Removing the jump.

Signed-off-by: Denys Vlasenko <[email protected]>
CC: Linus Torvalds <[email protected]>
CC: Steven Rostedt <[email protected]>
CC: Ingo Molnar <[email protected]>
CC: Borislav Petkov <[email protected]>
CC: "H. Peter Anvin" <[email protected]>
CC: Andy Lutomirski <[email protected]>
CC: Oleg Nesterov <[email protected]>
CC: Frederic Weisbecker <[email protected]>
CC: Alexei Starovoitov <[email protected]>
CC: Will Drewry <[email protected]>
CC: Kees Cook <[email protected]>
CC: [email protected]
CC: [email protected]
---
arch/x86/kernel/entry_64.S | 1 -
1 file changed, 1 deletion(-)

diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
index 6ad30a7..7d4c7c6 100644
--- a/arch/x86/kernel/entry_64.S
+++ b/arch/x86/kernel/entry_64.S
@@ -1455,7 +1455,6 @@ ENTRY(nmi)
/* If it is below the NMI stack, it is a normal NMI */
jb first_nmi
/* Ah, it is within the NMI stack, treat it as nested */
- jmp nested_nmi

CFI_REMEMBER_STATE

--
1.8.1.4

2015-04-07 20:45:11

by Denys Vlasenko

[permalink] [raw]
Subject: [PATCH 6/8] x86/asm/entry/64: simplify jumps in ret_from_fork

Replace
test
jz 1f
jmp label
1:

with
test
jnz label

Run-tested.

Signed-off-by: Denys Vlasenko <[email protected]>
CC: Linus Torvalds <[email protected]>
CC: Steven Rostedt <[email protected]>
CC: Ingo Molnar <[email protected]>
CC: Borislav Petkov <[email protected]>
CC: "H. Peter Anvin" <[email protected]>
CC: Andy Lutomirski <[email protected]>
CC: Oleg Nesterov <[email protected]>
CC: Frederic Weisbecker <[email protected]>
CC: Alexei Starovoitov <[email protected]>
CC: Will Drewry <[email protected]>
CC: Kees Cook <[email protected]>
CC: [email protected]
CC: [email protected]
---
arch/x86/kernel/entry_64.S | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
index 7d4c7c6..9915897 100644
--- a/arch/x86/kernel/entry_64.S
+++ b/arch/x86/kernel/entry_64.S
@@ -531,18 +531,18 @@ ENTRY(ret_from_fork)
RESTORE_EXTRA_REGS

testl $3,CS(%rsp) # from kernel_thread?
- jz 1f

/*
* By the time we get here, we have no idea whether our pt_regs,
* ti flags, and ti status came from the 64-bit SYSCALL fast path,
* the slow path, or one of the ia32entry paths.
- * Use int_ret_from_sys_call to return, since it can safely handle
+ * Use IRET code path to return, since it can safely handle
* all of the above.
*/
- jmp int_ret_from_sys_call
+ jnz int_ret_from_sys_call

-1:
+ /* We came from kernel_thread */
+ /* nb: we depend on RESTORE_EXTRA_REGS above */
movq %rbp, %rdi
call *%rbx
movl $0, RAX(%rsp)
--
1.8.1.4

2015-04-07 20:44:54

by Denys Vlasenko

[permalink] [raw]
Subject: [PATCH 7/8] x86/asm/entry/64: Remove GET_THREAD_INFO in ret_from_fork

It used to be used to check for _TIF_IA32, but the check has been removed.

Remove GET_THREAD_INFO too.

Run-tested.

Signed-off-by: Denys Vlasenko <[email protected]>
CC: Linus Torvalds <[email protected]>
CC: Steven Rostedt <[email protected]>
CC: Ingo Molnar <[email protected]>
CC: Borislav Petkov <[email protected]>
CC: "H. Peter Anvin" <[email protected]>
CC: Andy Lutomirski <[email protected]>
CC: Oleg Nesterov <[email protected]>
CC: Frederic Weisbecker <[email protected]>
CC: Alexei Starovoitov <[email protected]>
CC: Will Drewry <[email protected]>
CC: Kees Cook <[email protected]>
CC: [email protected]
CC: [email protected]
---
arch/x86/kernel/entry_64.S | 2 --
1 file changed, 2 deletions(-)

diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
index 9915897..05224d4 100644
--- a/arch/x86/kernel/entry_64.S
+++ b/arch/x86/kernel/entry_64.S
@@ -526,8 +526,6 @@ ENTRY(ret_from_fork)

call schedule_tail # rdi: 'prev' task parameter

- GET_THREAD_INFO(%rcx)
-
RESTORE_EXTRA_REGS

testl $3,CS(%rsp) # from kernel_thread?
--
1.8.1.4

2015-04-07 20:45:03

by Denys Vlasenko

[permalink] [raw]
Subject: [PATCH 8/8] x86/asm/entry/64: Reduce padding in execve stubs

execve stubs are 7 bytes only. Padding them to 16 bytes is a waste.

text data bss dec hex filename
12594 0 0 12594 3132 entry_64.o.before
12530 0 0 12530 30f2 entry_64.o

Run-tested.

Signed-off-by: Denys Vlasenko <[email protected]>
CC: Linus Torvalds <[email protected]>
CC: Steven Rostedt <[email protected]>
CC: Ingo Molnar <[email protected]>
CC: Borislav Petkov <[email protected]>
CC: "H. Peter Anvin" <[email protected]>
CC: Andy Lutomirski <[email protected]>
CC: Oleg Nesterov <[email protected]>
CC: Frederic Weisbecker <[email protected]>
CC: Alexei Starovoitov <[email protected]>
CC: Will Drewry <[email protected]>
CC: Kees Cook <[email protected]>
CC: [email protected]
CC: [email protected]
---
arch/x86/kernel/entry_64.S | 20 ++++++++++++++------
1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
index 05224d4..2aa3eca 100644
--- a/arch/x86/kernel/entry_64.S
+++ b/arch/x86/kernel/entry_64.S
@@ -434,8 +434,12 @@ return_from_execve:
jmp int_ret_from_sys_call
CFI_ENDPROC
END(stub_execve)
-
-ENTRY(stub_execveat)
+/*
+ * Remaining execve stubs are only 7 bytes long.
+ * ENTRY() often aligns to 16 bytes, which in this case has no benefits.
+ */
+ .align 8
+GLOBAL(stub_execveat)
CFI_STARTPROC
DEFAULT_FRAME 0, 8
call sys_execveat
@@ -444,14 +448,16 @@ ENTRY(stub_execveat)
END(stub_execveat)

#ifdef CONFIG_X86_X32_ABI
-ENTRY(stub_x32_execve)
+ .align 8
+GLOBAL(stub_x32_execve)
CFI_STARTPROC
DEFAULT_FRAME 0, 8
call compat_sys_execve
jmp return_from_execve
CFI_ENDPROC
END(stub_x32_execve)
-ENTRY(stub_x32_execveat)
+ .align 8
+GLOBAL(stub_x32_execveat)
CFI_STARTPROC
DEFAULT_FRAME 0, 8
call compat_sys_execveat
@@ -461,13 +467,15 @@ END(stub_x32_execveat)
#endif

#ifdef CONFIG_IA32_EMULATION
-ENTRY(stub32_execve)
+ .align 8
+GLOBAL(stub32_execve)
CFI_STARTPROC
call compat_sys_execve
jmp return_from_execve
CFI_ENDPROC
END(stub32_execve)
-ENTRY(stub32_execveat)
+ .align 8
+GLOBAL(stub32_execveat)
CFI_STARTPROC
call compat_sys_execveat
jmp return_from_execve
--
1.8.1.4

2015-04-08 02:40:02

by Brian Gerst

[permalink] [raw]
Subject: Re: [PATCH 3/8] x86/asm/entry: Zero EXTRA_REGS for stub32_execve[at] too

On Tue, Apr 7, 2015 at 4:43 PM, Denys Vlasenko <[email protected]> wrote:
> The change which affected how execve clears EXTRA_REGS missed
> 32-bit execve syscalls.
>
> Fix this by using 64-bit execve stub epilogue for them too.
>
> Run-tested.
>
> Signed-off-by: Denys Vlasenko <[email protected]>
> CC: Linus Torvalds <[email protected]>
> CC: Steven Rostedt <[email protected]>
> CC: Ingo Molnar <[email protected]>
> CC: Borislav Petkov <[email protected]>
> CC: "H. Peter Anvin" <[email protected]>
> CC: Andy Lutomirski <[email protected]>
> CC: Oleg Nesterov <[email protected]>
> CC: Frederic Weisbecker <[email protected]>
> CC: Alexei Starovoitov <[email protected]>
> CC: Will Drewry <[email protected]>
> CC: Kees Cook <[email protected]>
> CC: [email protected]
> CC: [email protected]
> ---
> arch/x86/ia32/ia32entry.S | 2 --
> arch/x86/kernel/entry_64.S | 15 +++++++++++++++
> 2 files changed, 15 insertions(+), 2 deletions(-)
>
> diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
> index 5d8f987..a821b1c 100644
> --- a/arch/x86/ia32/ia32entry.S
> +++ b/arch/x86/ia32/ia32entry.S
> @@ -571,8 +571,6 @@ GLOBAL(\label)
>
> PTREGSCALL stub32_rt_sigreturn, sys32_rt_sigreturn
> PTREGSCALL stub32_sigreturn, sys32_sigreturn
> - PTREGSCALL stub32_execve, compat_sys_execve
> - PTREGSCALL stub32_execveat, compat_sys_execveat
> PTREGSCALL stub32_fork, sys_fork
> PTREGSCALL stub32_vfork, sys_vfork
>
> diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
> index 1b0793c..8e3ba38 100644
> --- a/arch/x86/kernel/entry_64.S
> +++ b/arch/x86/kernel/entry_64.S
> @@ -461,6 +461,21 @@ ENTRY(stub_x32_execveat)
> END(stub_x32_execveat)
> #endif
>
> +#ifdef CONFIG_IA32_EMULATION
> +ENTRY(stub32_execve)
> + CFI_STARTPROC
> + call compat_sys_execve
> + jmp return_from_execve
> + CFI_ENDPROC
> +END(stub32_execve)
> +ENTRY(stub32_execveat)
> + CFI_STARTPROC
> + call compat_sys_execveat
> + jmp return_from_execve
> + CFI_ENDPROC
> +END(stub32_execveat)
> +#endif
> +
> /*
> * sigreturn is special because it needs to restore all registers on return.
> * This cannot be done with SYSRET, so use the IRET return path instead.

The X32 and IA32 stubs are now identical and should be merged.

--
Brian Gerst

Subject: [tip:x86/asm] x86/asm/entry/64: Use common code for rt_sigreturn( ) epilogue

Commit-ID: 31f0119b817f6474a7b4c48fed7588af1b62c543
Gitweb: http://git.kernel.org/tip/31f0119b817f6474a7b4c48fed7588af1b62c543
Author: Denys Vlasenko <[email protected]>
AuthorDate: Tue, 7 Apr 2015 22:43:37 +0200
Committer: Ingo Molnar <[email protected]>
CommitDate: Thu, 9 Apr 2015 10:31:24 +0200

x86/asm/entry/64: Use common code for rt_sigreturn() epilogue

Similarly to stub_execve, we can reuse the epilogue in
stub_rt_sigreturn() and stub_x32_rt_sigreturn().

Add a comment explaining why we can't eliminage SAVE_EXTRA_REGS
here.

Signed-off-by: Denys Vlasenko <[email protected]>
Cc: Alexei Starovoitov <[email protected]>
Cc: Andy Lutomirski <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Brian Gerst <[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/[email protected]
Signed-off-by: Ingo Molnar <[email protected]>
---
arch/x86/kernel/entry_64.S | 26 ++++++++++++++++----------
1 file changed, 16 insertions(+), 10 deletions(-)

diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
index 3197f41..5252e60 100644
--- a/arch/x86/kernel/entry_64.S
+++ b/arch/x86/kernel/entry_64.S
@@ -527,12 +527,21 @@ END(stub_execveat)
*/
ENTRY(stub_rt_sigreturn)
CFI_STARTPROC
- addq $8, %rsp
- DEFAULT_FRAME 0
- SAVE_EXTRA_REGS
+ DEFAULT_FRAME 0, 8
+ /*
+ * SAVE_EXTRA_REGS result is not normally needed:
+ * sigreturn overwrites all pt_regs->GPREGS.
+ * But sigreturn can fail (!), and there is no easy way to detect that.
+ * To make sure RESTORE_EXTRA_REGS doesn't restore garbage on error,
+ * we SAVE_EXTRA_REGS here.
+ */
+ SAVE_EXTRA_REGS 8
call sys_rt_sigreturn
- movq %rax,RAX(%rsp) # fixme, this could be done at the higher layer
+return_from_stub:
+ addq $8, %rsp
+ CFI_ADJUST_CFA_OFFSET -8
RESTORE_EXTRA_REGS
+ movq %rax,RAX(%rsp)
jmp int_ret_from_sys_call
CFI_ENDPROC
END(stub_rt_sigreturn)
@@ -540,13 +549,10 @@ END(stub_rt_sigreturn)
#ifdef CONFIG_X86_X32_ABI
ENTRY(stub_x32_rt_sigreturn)
CFI_STARTPROC
- addq $8, %rsp
- DEFAULT_FRAME 0
- SAVE_EXTRA_REGS
+ DEFAULT_FRAME 0, 8
+ SAVE_EXTRA_REGS 8
call sys32_x32_rt_sigreturn
- movq %rax,RAX(%rsp) # fixme, this could be done at the higher layer
- RESTORE_EXTRA_REGS
- jmp int_ret_from_sys_call
+ jmp return_from_stub
CFI_ENDPROC
END(stub_x32_rt_sigreturn)

Subject: [tip:x86/asm] x86/asm/entry/64: Move stub_x32_execvecloser() to stub_execveat()

Commit-ID: 05f1752d195c145d02ae40881d0985c2cfbee473
Gitweb: http://git.kernel.org/tip/05f1752d195c145d02ae40881d0985c2cfbee473
Author: Denys Vlasenko <[email protected]>
AuthorDate: Tue, 7 Apr 2015 22:43:38 +0200
Committer: Ingo Molnar <[email protected]>
CommitDate: Thu, 9 Apr 2015 10:31:24 +0200

x86/asm/entry/64: Move stub_x32_execvecloser() to stub_execveat()

This is a preparatory patch for moving stub32_execve[at]() to this
file. It makes sense to have all execve stubs in one place, so
that they can reuse code.

Signed-off-by: Denys Vlasenko <[email protected]>
Cc: Alexei Starovoitov <[email protected]>
Cc: Andy Lutomirski <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Brian Gerst <[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/[email protected]
Signed-off-by: Ingo Molnar <[email protected]>
---
arch/x86/kernel/entry_64.S | 34 +++++++++++++++++-----------------
1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
index 5252e60..f7d9ba6 100644
--- a/arch/x86/kernel/entry_64.S
+++ b/arch/x86/kernel/entry_64.S
@@ -521,6 +521,23 @@ ENTRY(stub_execveat)
CFI_ENDPROC
END(stub_execveat)

+#ifdef CONFIG_X86_X32_ABI
+ENTRY(stub_x32_execve)
+ CFI_STARTPROC
+ DEFAULT_FRAME 0, 8
+ call compat_sys_execve
+ jmp return_from_execve
+ CFI_ENDPROC
+END(stub_x32_execve)
+ENTRY(stub_x32_execveat)
+ CFI_STARTPROC
+ DEFAULT_FRAME 0, 8
+ call compat_sys_execveat
+ jmp return_from_execve
+ CFI_ENDPROC
+END(stub_x32_execveat)
+#endif
+
/*
* sigreturn is special because it needs to restore all registers on return.
* This cannot be done with SYSRET, so use the IRET return path instead.
@@ -555,23 +572,6 @@ ENTRY(stub_x32_rt_sigreturn)
jmp return_from_stub
CFI_ENDPROC
END(stub_x32_rt_sigreturn)
-
-ENTRY(stub_x32_execve)
- CFI_STARTPROC
- DEFAULT_FRAME 0, 8
- call compat_sys_execve
- jmp return_from_execve
- CFI_ENDPROC
-END(stub_x32_execve)
-
-ENTRY(stub_x32_execveat)
- CFI_STARTPROC
- DEFAULT_FRAME 0, 8
- call compat_sys_execveat
- jmp return_from_execve
- CFI_ENDPROC
-END(stub_x32_execveat)
-
#endif

/*

Subject: [tip:x86/asm] x86/asm/entry: Zero EXTRA_REGS for stub32_execve() too

Commit-ID: 0f90fb979d7b53d80a6d5cb6e127b4b4b249907e
Gitweb: http://git.kernel.org/tip/0f90fb979d7b53d80a6d5cb6e127b4b4b249907e
Author: Denys Vlasenko <[email protected]>
AuthorDate: Tue, 7 Apr 2015 22:43:39 +0200
Committer: Ingo Molnar <[email protected]>
CommitDate: Thu, 9 Apr 2015 10:31:24 +0200

x86/asm/entry: Zero EXTRA_REGS for stub32_execve() too

The change which affected how execve clears EXTRA_REGS missed
32-bit execve syscalls.

Fix this by using 64-bit execve stub epilogue for them too.

Run-tested.

Signed-off-by: Denys Vlasenko <[email protected]>
Cc: Alexei Starovoitov <[email protected]>
Cc: Andy Lutomirski <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Brian Gerst <[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/[email protected]
Signed-off-by: Ingo Molnar <[email protected]>
---
arch/x86/ia32/ia32entry.S | 2 --
arch/x86/kernel/entry_64.S | 15 +++++++++++++++
2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
index 5d8f987..a821b1c 100644
--- a/arch/x86/ia32/ia32entry.S
+++ b/arch/x86/ia32/ia32entry.S
@@ -571,8 +571,6 @@ GLOBAL(\label)

PTREGSCALL stub32_rt_sigreturn, sys32_rt_sigreturn
PTREGSCALL stub32_sigreturn, sys32_sigreturn
- PTREGSCALL stub32_execve, compat_sys_execve
- PTREGSCALL stub32_execveat, compat_sys_execveat
PTREGSCALL stub32_fork, sys_fork
PTREGSCALL stub32_vfork, sys_vfork

diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
index f7d9ba6..5380b3a 100644
--- a/arch/x86/kernel/entry_64.S
+++ b/arch/x86/kernel/entry_64.S
@@ -538,6 +538,21 @@ ENTRY(stub_x32_execveat)
END(stub_x32_execveat)
#endif

+#ifdef CONFIG_IA32_EMULATION
+ENTRY(stub32_execve)
+ CFI_STARTPROC
+ call compat_sys_execve
+ jmp return_from_execve
+ CFI_ENDPROC
+END(stub32_execve)
+ENTRY(stub32_execveat)
+ CFI_STARTPROC
+ call compat_sys_execveat
+ jmp return_from_execve
+ CFI_ENDPROC
+END(stub32_execveat)
+#endif
+
/*
* sigreturn is special because it needs to restore all registers on return.
* This cannot be done with SYSRET, so use the IRET return path instead.

Subject: [tip:x86/asm] x86/asm/entry/64: Optimize [v]fork/clone stubs

Commit-ID: 772951c4e4b06cdffeff499259dba07b544f3166
Gitweb: http://git.kernel.org/tip/772951c4e4b06cdffeff499259dba07b544f3166
Author: Denys Vlasenko <[email protected]>
AuthorDate: Tue, 7 Apr 2015 22:43:40 +0200
Committer: Ingo Molnar <[email protected]>
CommitDate: Thu, 9 Apr 2015 10:31:25 +0200

x86/asm/entry/64: Optimize [v]fork/clone stubs

Replace "call func; ret" with "jmp func".

Run-tested.

Signed-off-by: Denys Vlasenko <[email protected]>
Cc: Alexei Starovoitov <[email protected]>
Cc: Andy Lutomirski <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Brian Gerst <[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/[email protected]
Signed-off-by: Ingo Molnar <[email protected]>
---
arch/x86/kernel/entry_64.S | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
index 5380b3a..ce85256 100644
--- a/arch/x86/kernel/entry_64.S
+++ b/arch/x86/kernel/entry_64.S
@@ -484,8 +484,7 @@ ENTRY(stub_\func)
CFI_STARTPROC
DEFAULT_FRAME 0, 8 /* offset 8: return address */
SAVE_EXTRA_REGS 8
- call sys_\func
- ret
+ jmp sys_\func
CFI_ENDPROC
END(stub_\func)
.endm

Subject: [tip:x86/asm] x86/asm/entry/64: Remove a redundant jump

Commit-ID: a30b0085f54efae11f6256df4e4a16af7eefc1c4
Gitweb: http://git.kernel.org/tip/a30b0085f54efae11f6256df4e4a16af7eefc1c4
Author: Denys Vlasenko <[email protected]>
AuthorDate: Tue, 7 Apr 2015 22:43:41 +0200
Committer: Ingo Molnar <[email protected]>
CommitDate: Thu, 9 Apr 2015 10:31:25 +0200

x86/asm/entry/64: Remove a redundant jump

Jumping to the very next instruction is not very useful:

jmp label
label:

Removing the jump.

Signed-off-by: Denys Vlasenko <[email protected]>
Cc: Alexei Starovoitov <[email protected]>
Cc: Andy Lutomirski <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Brian Gerst <[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/[email protected]
Signed-off-by: Ingo Molnar <[email protected]>
---
arch/x86/kernel/entry_64.S | 1 -
1 file changed, 1 deletion(-)

diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
index ce85256..e8ddd51 100644
--- a/arch/x86/kernel/entry_64.S
+++ b/arch/x86/kernel/entry_64.S
@@ -1448,7 +1448,6 @@ ENTRY(nmi)
/* If it is below the NMI stack, it is a normal NMI */
jb first_nmi
/* Ah, it is within the NMI stack, treat it as nested */
- jmp nested_nmi

CFI_REMEMBER_STATE

Subject: [tip:x86/asm] x86/asm/entry/64: Simplify jumps in ret_from_fork

Commit-ID: 66ad4efa51805964521db03d8aa827a8dd9058b9
Gitweb: http://git.kernel.org/tip/66ad4efa51805964521db03d8aa827a8dd9058b9
Author: Denys Vlasenko <[email protected]>
AuthorDate: Tue, 7 Apr 2015 22:43:42 +0200
Committer: Ingo Molnar <[email protected]>
CommitDate: Thu, 9 Apr 2015 10:31:25 +0200

x86/asm/entry/64: Simplify jumps in ret_from_fork

Replace
test
jz 1f
jmp label
1:

with
test
jnz label

Run-tested.

Signed-off-by: Denys Vlasenko <[email protected]>
Cc: Alexei Starovoitov <[email protected]>
Cc: Andy Lutomirski <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Brian Gerst <[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/[email protected]
Signed-off-by: Ingo Molnar <[email protected]>
---
arch/x86/kernel/entry_64.S | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
index e8ddd51..a35e5e4 100644
--- a/arch/x86/kernel/entry_64.S
+++ b/arch/x86/kernel/entry_64.S
@@ -608,18 +608,18 @@ ENTRY(ret_from_fork)
RESTORE_EXTRA_REGS

testl $3,CS(%rsp) # from kernel_thread?
- jz 1f

/*
* By the time we get here, we have no idea whether our pt_regs,
* ti flags, and ti status came from the 64-bit SYSCALL fast path,
* the slow path, or one of the ia32entry paths.
- * Use int_ret_from_sys_call to return, since it can safely handle
+ * Use IRET code path to return, since it can safely handle
* all of the above.
*/
- jmp int_ret_from_sys_call
+ jnz int_ret_from_sys_call

-1:
+ /* We came from kernel_thread */
+ /* nb: we depend on RESTORE_EXTRA_REGS above */
movq %rbp, %rdi
call *%rbx
movl $0, RAX(%rsp)

Subject: [tip:x86/asm] x86/asm/entry/64: Remove GET_THREAD_INFO() in ret_from_fork

Commit-ID: 54a81e914b2432a86dd49cf611b0f71ef44ca7ad
Gitweb: http://git.kernel.org/tip/54a81e914b2432a86dd49cf611b0f71ef44ca7ad
Author: Denys Vlasenko <[email protected]>
AuthorDate: Tue, 7 Apr 2015 22:43:43 +0200
Committer: Ingo Molnar <[email protected]>
CommitDate: Thu, 9 Apr 2015 10:31:26 +0200

x86/asm/entry/64: Remove GET_THREAD_INFO() in ret_from_fork

It used to be used to check for _TIF_IA32, but the check has
been removed.

Remove GET_THREAD_INFO() too.

Run-tested.

Signed-off-by: Denys Vlasenko <[email protected]>
Cc: Alexei Starovoitov <[email protected]>
Cc: Andy Lutomirski <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Brian Gerst <[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/[email protected]
Signed-off-by: Ingo Molnar <[email protected]>
---
arch/x86/kernel/entry_64.S | 2 --
1 file changed, 2 deletions(-)

diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
index a35e5e4..b67f2fc 100644
--- a/arch/x86/kernel/entry_64.S
+++ b/arch/x86/kernel/entry_64.S
@@ -603,8 +603,6 @@ ENTRY(ret_from_fork)

call schedule_tail # rdi: 'prev' task parameter

- GET_THREAD_INFO(%rcx)
-
RESTORE_EXTRA_REGS

testl $3,CS(%rsp) # from kernel_thread?

Subject: [tip:x86/asm] x86/asm/entry/64: Reduce padding in execve stubs

Commit-ID: a37f34a325d90856314ccd4994e1070dcc6bdcc4
Gitweb: http://git.kernel.org/tip/a37f34a325d90856314ccd4994e1070dcc6bdcc4
Author: Denys Vlasenko <[email protected]>
AuthorDate: Tue, 7 Apr 2015 22:43:44 +0200
Committer: Ingo Molnar <[email protected]>
CommitDate: Thu, 9 Apr 2015 10:31:26 +0200

x86/asm/entry/64: Reduce padding in execve stubs

execve stubs are 7 bytes only. Padding them to 16 bytes is a
waste.

text data bss dec hex filename
12594 0 0 12594 3132 entry_64.o.before
12530 0 0 12530 30f2 entry_64.o

Run-tested.

Signed-off-by: Denys Vlasenko <[email protected]>
Cc: Alexei Starovoitov <[email protected]>
Cc: Andy Lutomirski <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Brian Gerst <[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/[email protected]
Signed-off-by: Ingo Molnar <[email protected]>
---
arch/x86/kernel/entry_64.S | 20 ++++++++++++++------
1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
index b67f2fc..c7b2384 100644
--- a/arch/x86/kernel/entry_64.S
+++ b/arch/x86/kernel/entry_64.S
@@ -511,8 +511,12 @@ return_from_execve:
jmp int_ret_from_sys_call
CFI_ENDPROC
END(stub_execve)
-
-ENTRY(stub_execveat)
+/*
+ * Remaining execve stubs are only 7 bytes long.
+ * ENTRY() often aligns to 16 bytes, which in this case has no benefits.
+ */
+ .align 8
+GLOBAL(stub_execveat)
CFI_STARTPROC
DEFAULT_FRAME 0, 8
call sys_execveat
@@ -521,14 +525,16 @@ ENTRY(stub_execveat)
END(stub_execveat)

#ifdef CONFIG_X86_X32_ABI
-ENTRY(stub_x32_execve)
+ .align 8
+GLOBAL(stub_x32_execve)
CFI_STARTPROC
DEFAULT_FRAME 0, 8
call compat_sys_execve
jmp return_from_execve
CFI_ENDPROC
END(stub_x32_execve)
-ENTRY(stub_x32_execveat)
+ .align 8
+GLOBAL(stub_x32_execveat)
CFI_STARTPROC
DEFAULT_FRAME 0, 8
call compat_sys_execveat
@@ -538,13 +544,15 @@ END(stub_x32_execveat)
#endif

#ifdef CONFIG_IA32_EMULATION
-ENTRY(stub32_execve)
+ .align 8
+GLOBAL(stub32_execve)
CFI_STARTPROC
call compat_sys_execve
jmp return_from_execve
CFI_ENDPROC
END(stub32_execve)
-ENTRY(stub32_execveat)
+ .align 8
+GLOBAL(stub32_execveat)
CFI_STARTPROC
call compat_sys_execveat
jmp return_from_execve