Skip to contentSkip to conversation

x86/boot/64: a couple of start_cpu() cleanups

PATCH In review Josh Poimboeuf 3 participants 7 messages Dec 14, 2016 x86

lore
Share & tools
lore
#0 lore raw

cover x86/boot/64: a couple of start_cpu() cleanups

Josh Poimboeuf (2):
x86/boot/64: use 'push' instead of 'call' in start_cpu() x86/boot/64: push correct start_cpu() return address

 arch/x86/kernel/head_64.S | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/2 x86/boot/64: use 'push' instead of 'call' in start_cpu()

start_cpu() pushes a text address on the stack so that stack traces from idle tasks will show start_cpu() at the end. But it uses a call instruction to do that, which is rather obtuse. Use a straightforward push instead.

---
 arch/x86/kernel/head_64.S | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/head_64.S +1 -1
index 90de288..1facaf4 100644
@@ -298,7 +298,7 @@ ENTRY(start_cpu)
 	 *	REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
 	 *		address given in m16:64.
 	 */
-	call	1f		# put return address on stack for unwinder
+	pushq	$1f		# put return address on stack for unwinder
 1:	xorq	%rbp, %rbp	# clear frame pointer
 	movq	initial_code(%rip), %rax
 	pushq	$__KERNEL_CS	# set correct cs
Signature · 1 line
2.7.4
#2 lore raw

[tip:x86/urgent] x86/boot/64: Use 'push' instead of 'call' in start_cpu()

x86/boot/64: Use 'push' instead of 'call' in start_cpu()
Commit-ID:  ec2d86a9b646d93f1948569f368e2c6f5449e6c7
Gitweb:     http://git.kernel.org/tip/ec2d86a9b646d93f1948569f368e2c6f5449e6c7
Author:     Josh Poimboeuf <[email protected]>
AuthorDate: Tue, 13 Dec 2016 21:25:35 -0600
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 14 Dec 2016 08:48:05 +0100

x86/boot/64: Use 'push' instead of 'call' in start_cpu()

start_cpu() pushes a text address on the stack so that stack traces from idle tasks will show start_cpu() at the end. But it uses a call instruction to do that, which is rather obtuse. Use a straightforward push instead.

---
 arch/x86/kernel/head_64.S | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/head_64.S +1 -1
index 90de288..1facaf4 100644
@@ -298,7 +298,7 @@ ENTRY(start_cpu)
 	 *	REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
 	 *		address given in m16:64.
 	 */
-	call	1f		# put return address on stack for unwinder
+	pushq	$1f		# put return address on stack for unwinder
 1:	xorq	%rbp, %rbp	# clear frame pointer
 	movq	initial_code(%rip), %rax
 	pushq	$__KERNEL_CS	# set correct cs
#3 lore raw

Re: [tip:x86/urgent] x86/boot/64: Use 'push' instead of 'call' in start_cpu()

Quoted 42 lines · tip-bot for Josh Poimboeuf

Commit-ID: ec2d86a9b646d93f1948569f368e2c6f5449e6c7 Gitweb:
http://git.kernel.org/tip/ec2d86a9b646d93f1948569f368e2c6f5449e6c7

Author:     Josh Poimboeuf <[email protected]>
AuthorDate: Tue, 13 Dec 2016 21:25:35 -0600
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 14 Dec 2016 08:48:05 +0100

x86/boot/64: Use 'push' instead of 'call' in start_cpu()

start_cpu() pushes a text address on the stack so that stack traces from
idle tasks will show start_cpu() at the end. But it uses a call instruction to do that, which is rather obtuse. Use a straightforward push instead.

Cc Andy Lutomirski <[email protected]>
Cc Brian Gerst <[email protected]>
Cc Denys Vlasenko <[email protected]>
Cc H. Peter Anvin <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>

Link:
http://lkml.kernel.org/r/4d8a1952759721d42d1e62ba9e4a7e3ac5df8574.1481685203.git.jpoimboe@redhat.com

---
arch/x86/kernel/head_64.S | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/head_64.S +1 -1
index 90de288..1facaf4 100644
@@ -298,7 +298,7 @@ ENTRY(start_cpu)
 	 *	REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
 	 *		address given in m16:64.
 	 */
-	call	1f		# put return address on stack for unwinder
+	pushq	$1f		# put return address on stack for unwinder
Quoted 3 lines

1: xorq %rbp, %rbp # clear frame pointer
movq initial_code(%rip), %rax
pushq $__KERNEL_CS # set correct cs

This adds another relocation to the kernel. I hope this is safe at this point in the code?

Signature · 1 line
Sent from my Android device with K-9 Mail. Please excuse my brevity.
#4 lore raw

Re: [tip:x86/urgent] x86/boot/64: Use 'push' instead of 'call' in start_cpu()

Quoted 16 lines · On Wed, Dec 14, 2016 at 11:24:19AM -0800, [email protected] wrote:
Quoted 10 lines · tip-bot for Josh Poimboeuf
arch/x86/kernel/head_64.S +1 -1
index 90de288..1facaf4 100644
@@ -298,7 +298,7 @@ ENTRY(start_cpu)
 	 *	REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
 	 *		address given in m16:64.
 	 */
-	call	1f		# put return address on stack for unwinder
+	pushq	$1f		# put return address on stack for unwinder
Quoted 3 lines

1: xorq %rbp, %rbp # clear frame pointer
movq initial_code(%rip), %rax
pushq $__KERNEL_CS # set correct cs

This adds another relocation to the kernel. I hope this is safe at this point in the code?

AFAIK, it should be fine. All relocations were either applied at build time, or for KASLR, in the compressed boot code which extracts and copies this code.

Also there are already a bunch of relocations in the rest of the code in this file, all of which runs before this code does.

(And even if that weren't the case, this address is only used for displaying stack traces, so pushing a zero or some garbage here wouldn't really break anything.)

Signature · 1 line
Josh
#5 lore raw

PATCH 2/2 x86/boot/64: push correct start_cpu() return address

In reply to Josh Poimboeuf

start_cpu() pushes a text address on the stack so that stack traces from idle tasks will show start_cpu() at the end. But it currently shows the wrong function offset. It's more correct to show the address immediately after the 'lretq' instruction.

---
 arch/x86/kernel/head_64.S | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/x86/kernel/head_64.S +3 -2
index 1facaf4..b467b14 100644
@@ -298,12 +298,13 @@ ENTRY(start_cpu)
 	 *	REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
 	 *		address given in m16:64.
 	 */
-	pushq	$1f		# put return address on stack for unwinder
-1:	xorq	%rbp, %rbp	# clear frame pointer
+	pushq	$.Lafter_lret	# put return address on stack for unwinder
+	xorq	%rbp, %rbp	# clear frame pointer
 	movq	initial_code(%rip), %rax
 	pushq	$__KERNEL_CS	# set correct cs
 	pushq	%rax		# target address in negative space
 	lretq
+.Lafter_lret:
 ENDPROC(start_cpu)
 
 #include "verify_cpu.S"
Signature · 1 line
2.7.4
#6 lore raw

[tip:x86/urgent] x86/boot/64: Push correct start_cpu() return address

x86/boot/64: Push correct start_cpu() return address
Commit-ID:  31dcfec11f827e9a5d8720fe4728f1305894884f
Gitweb:     http://git.kernel.org/tip/31dcfec11f827e9a5d8720fe4728f1305894884f
Author:     Josh Poimboeuf <[email protected]>
AuthorDate: Tue, 13 Dec 2016 21:25:36 -0600
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 14 Dec 2016 08:48:05 +0100

x86/boot/64: Push correct start_cpu() return address

start_cpu() pushes a text address on the stack so that stack traces from idle tasks will show start_cpu() at the end. But it currently shows the wrong function offset. It's more correct to show the address immediately after the 'lretq' instruction.

---
 arch/x86/kernel/head_64.S | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/x86/kernel/head_64.S +3 -2
index 1facaf4..b467b14 100644
@@ -298,12 +298,13 @@ ENTRY(start_cpu)
 	 *	REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
 	 *		address given in m16:64.
 	 */
-	pushq	$1f		# put return address on stack for unwinder
-1:	xorq	%rbp, %rbp	# clear frame pointer
+	pushq	$.Lafter_lret	# put return address on stack for unwinder
+	xorq	%rbp, %rbp	# clear frame pointer
 	movq	initial_code(%rip), %rax
 	pushq	$__KERNEL_CS	# set correct cs
 	pushq	%rax		# target address in negative space
 	lretq
+.Lafter_lret:
 ENDPROC(start_cpu)
 
 #include "verify_cpu.S"