Skip to contentSkip to conversation

x86/asm/entry/64: Tidy up JZ insns after TESTs

PATCH In review Denys Vlasenko 4 participants 7 messages Apr 27, 2015 – May 8, 2015 x86

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 x86/asm/entry/64: Tidy up JZ insns after TESTs

After TESTs, use logically correct JZ/JNZ mnemonics instead of JE/JNE. This doesn't change code.

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]>
---
 arch/x86/kernel/entry_64.S | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
arch/x86/kernel/entry_64.S +4 -4
index e952f6b..8f8b22a 100644
@@ -666,7 +666,7 @@ END(irq_entries_start)
 	leaq -RBP(%rsp),%rdi	/* arg1 for \func (pointer to pt_regs) */
 
 	testl $3, CS-RBP(%rsp)
-	je 1f
+	jz	1f
 	SWAPGS
 1:
 	/*
@@ -721,7 +721,7 @@ ret_from_intr:
 	CFI_ADJUST_CFA_OFFSET	RBP
 
 	testl $3,CS(%rsp)
-	je retint_kernel
+	jz	retint_kernel
 	/* Interrupt came from user space */
 
 	GET_THREAD_INFO(%rcx)
@@ -1310,7 +1310,7 @@ ENTRY(error_entry)
 	SAVE_EXTRA_REGS 8
 	xorl %ebx,%ebx
 	testl $3,CS+8(%rsp)
-	je error_kernelspace
+	jz	error_kernelspace
 error_swapgs:
 	SWAPGS
 error_sti:
@@ -1361,7 +1361,7 @@ ENTRY(error_exit)
 	TRACE_IRQS_OFF
 	GET_THREAD_INFO(%rcx)
 	testl %eax,%eax
-	jne retint_kernel
+	jnz retint_kernel
 	LOCKDEP_SYS_EXIT_IRQ
 	movl TI_flags(%rcx),%edx
 	movl $_TIF_WORK_MASK,%edi
Signature · 1 line
1.8.1.4
#1 lore raw

PATCH 2/2 x86/asm/entry/64: Clean up usage of TEST insns

By the nature of TEST operation, it is often possible to test a narrower part of the operand:

    "testl $3, mem"  -> "testb $3, mem"

This results in shorter insns, because TEST insn has no sign-entending byte-immediate forms unlike other ALU ops.

text data bss dec hex filename

  11674	      0	      0	  11674	   2d9a	entry_64.o.before
  11658	      0	      0	  11658	   2d8a	entry_64.o

Changes in object code:

-	f7 84 24 88 00 00 00 03 00 00 00 	testl  $0x3,0x88(%rsp)
+	f6 84 24 88 00 00 00 03	         	testb  $0x3,0x88(%rsp)
-	f7 44 24 68 03 00 00 00          	testl  $0x3,0x68(%rsp)
+	f6 44 24 68 03                  	testb  $0x3,0x68(%rsp)
-	f7 84 24 90 00 00 00 03 00 00 00	testl  $0x3,0x90(%rsp)
+	f6 84 24 90 00 00 00 03         	testb  $0x3,0x90(%rsp)
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]>
---
 arch/x86/kernel/entry_64.S | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
arch/x86/kernel/entry_64.S +5 -6
index 8f8b22a..60705b03 100644
@@ -601,7 +601,7 @@ ENTRY(ret_from_fork)
 
 	RESTORE_EXTRA_REGS
 
-	testl $3,CS(%rsp)			# from kernel_thread?
+	testb	$3, CS(%rsp)			# from kernel_thread?
 
 	/*
 	 * By the time we get here, we have no idea whether our pt_regs,
@@ -665,7 +665,7 @@ END(irq_entries_start)
 
 	leaq -RBP(%rsp),%rdi	/* arg1 for \func (pointer to pt_regs) */
 
-	testl $3, CS-RBP(%rsp)
+	testb	$3, CS-RBP(%rsp)
 	jz	1f
 	SWAPGS
 1:
@@ -720,7 +720,7 @@ ret_from_intr:
 	CFI_DEF_CFA_REGISTER	rsp
 	CFI_ADJUST_CFA_OFFSET	RBP
 
-	testl $3,CS(%rsp)
+	testb	$3, CS(%rsp)
 	jz	retint_kernel
 	/* Interrupt came from user space */
 
@@ -968,7 +968,7 @@ ENTRY(\sym)
 	.if \paranoid
 	.if \paranoid == 1
 	CFI_REMEMBER_STATE
-	testl $3, CS(%rsp)		/* If coming from userspace, switch */
+	testb	$3, CS(%rsp)		/* If coming from userspace, switch */
 	jnz 1f				/* stacks. */
 	.endif
 	call paranoid_entry
@@ -1309,7 +1309,7 @@ ENTRY(error_entry)
 	SAVE_C_REGS 8
 	SAVE_EXTRA_REGS 8
 	xorl %ebx,%ebx
-	testl $3,CS+8(%rsp)
+	testb	$3, CS+8(%rsp)
 	jz	error_kernelspace
 error_swapgs:
 	SWAPGS
@@ -1606,7 +1606,6 @@ end_repeat_nmi:
 	je 1f
 	movq %r12, %cr2
 1:
-	
 	testl %ebx,%ebx				/* swapgs needed? */
 	jnz nmi_restore
 nmi_swapgs:
Signature · 1 line
1.8.1.4
#2 lore raw

[tip:x86/asm] x86/asm/entry/64: Clean up usage of TEST insns

x86/asm/entry/64: Clean up usage of TEST insns
Commit-ID:  03335e95e27fc1f2b17b05b27342ad76986b3cf0
Gitweb:     http://git.kernel.org/tip/03335e95e27fc1f2b17b05b27342ad76986b3cf0
Author:     Denys Vlasenko <[email protected]>
AuthorDate: Mon, 27 Apr 2015 15:21:52 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 8 May 2015 11:07:32 +0200

x86/asm/entry/64: Clean up usage of TEST insns

By the nature of TEST operation, it is often possible to test a narrower part of the operand:

    "testl $3, mem"  -> "testb $3, mem"

This results in shorter insns, because TEST insn has no sign-entending byte-immediate forms unlike other ALU ops.

text data bss dec hex filename

  11674	      0	      0	  11674	   2d9a	entry_64.o.before
  11658	      0	      0	  11658	   2d8a	entry_64.o

Changes in object code:

-	f7 84 24 88 00 00 00 03 00 00 00 	testl  $0x3,0x88(%rsp)
+	f6 84 24 88 00 00 00 03	         	testb  $0x3,0x88(%rsp)
-	f7 44 24 68 03 00 00 00          	testl  $0x3,0x68(%rsp)
+	f6 44 24 68 03                  	testb  $0x3,0x68(%rsp)
-	f7 84 24 90 00 00 00 03 00 00 00	testl  $0x3,0x90(%rsp)
+	f6 84 24 90 00 00 00 03         	testb  $0x3,0x90(%rsp)
Cc Alexei Starovoitov <[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]>
---
 arch/x86/kernel/entry_64.S | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
arch/x86/kernel/entry_64.S +5 -6
index 8f8b22a..60705b03 100644
@@ -601,7 +601,7 @@ ENTRY(ret_from_fork)
 
 	RESTORE_EXTRA_REGS
 
-	testl $3,CS(%rsp)			# from kernel_thread?
+	testb	$3, CS(%rsp)			# from kernel_thread?
 
 	/*
 	 * By the time we get here, we have no idea whether our pt_regs,
@@ -665,7 +665,7 @@ END(irq_entries_start)
 
 	leaq -RBP(%rsp),%rdi	/* arg1 for \func (pointer to pt_regs) */
 
-	testl $3, CS-RBP(%rsp)
+	testb	$3, CS-RBP(%rsp)
 	jz	1f
 	SWAPGS
 1:
@@ -720,7 +720,7 @@ ret_from_intr:
 	CFI_DEF_CFA_REGISTER	rsp
 	CFI_ADJUST_CFA_OFFSET	RBP
 
-	testl $3,CS(%rsp)
+	testb	$3, CS(%rsp)
 	jz	retint_kernel
 	/* Interrupt came from user space */
 
@@ -968,7 +968,7 @@ ENTRY(\sym)
 	.if \paranoid
 	.if \paranoid == 1
 	CFI_REMEMBER_STATE
-	testl $3, CS(%rsp)		/* If coming from userspace, switch */
+	testb	$3, CS(%rsp)		/* If coming from userspace, switch */
 	jnz 1f				/* stacks. */
 	.endif
 	call paranoid_entry
@@ -1309,7 +1309,7 @@ ENTRY(error_entry)
 	SAVE_C_REGS 8
 	SAVE_EXTRA_REGS 8
 	xorl %ebx,%ebx
-	testl $3,CS+8(%rsp)
+	testb	$3, CS+8(%rsp)
 	jz	error_kernelspace
 error_swapgs:
 	SWAPGS
@@ -1606,7 +1606,6 @@ end_repeat_nmi:
 	je 1f
 	movq %r12, %cr2
 1:
-	
 	testl %ebx,%ebx				/* swapgs needed? */
 	jnz nmi_restore
 nmi_swapgs:
#4 lore raw
In reply to Denys Vlasenko

arch/x86/kernel/entry_64.S END(irq_entries_start) · line 671

Quoted 13 lines · Denys Vlasenko
arch/x86/kernel/entry_64.S +1 -1
index e952f6b..8f8b22a 100644
@@ -666,7 +666,7 @@ END(irq_entries_start)
 	leaq -RBP(%rsp),%rdi	/* arg1 for \func (pointer to pt_regs) */
 
 	testl $3, CS-RBP(%rsp)
-	je 1f
+	jz	1f
 	SWAPGS
 1:

Please don't insert tabs between opcode and operand unless that is the style of the surrounding code.

Otherwise this patchset looks good.

-hpa

#5 lore raw
Quoted 9 lines · H. Peter Anvin
Quoted 8 lines · Denys Vlasenko
arch/x86/kernel/entry_64.S +0 -0
index e952f6b..8f8b22a 100644
@@ -666,7 +666,7 @@ END(irq_entries_start)
 	leaq -RBP(%rsp),%rdi	/* arg1 for \func (pointer to pt_regs) */
 
Quoted 8 lines

arch/x86/kernel/entry_64.S END(irq_entries_start) · line 671

Quoted 5 lines
arch/x86/kernel/entry_64.S +1 -1
 	testl $3, CS-RBP(%rsp)
-	je 1f
+	jz	1f
 	SWAPGS
 1:

Please don't insert tabs between opcode and operand unless that is the style of the surrounding code.

The next patch inserts tab in the preceding TEST insn too, converting entire mini-block of code to "tab" style.

#6 lore raw
In reply to Denys Vlasenko
x86/asm/entry/64: Tidy up JZ insns after TESTs
Commit-ID:  dde74f2e4a4447ef838c57e407f7139de3df68cb
Gitweb:     http://git.kernel.org/tip/dde74f2e4a4447ef838c57e407f7139de3df68cb
Author:     Denys Vlasenko <[email protected]>
AuthorDate: Mon, 27 Apr 2015 15:21:51 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 8 May 2015 11:07:31 +0200

x86/asm/entry/64: Tidy up JZ insns after TESTs

After TESTs, use logically correct JZ/JNZ mnemonics instead of JE/JNE. This doesn't change code.

Cc Alexei Starovoitov <[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]>
---
 arch/x86/kernel/entry_64.S | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
arch/x86/kernel/entry_64.S +4 -4
index e952f6b..8f8b22a 100644
@@ -666,7 +666,7 @@ END(irq_entries_start)
 	leaq -RBP(%rsp),%rdi	/* arg1 for \func (pointer to pt_regs) */
 
 	testl $3, CS-RBP(%rsp)
-	je 1f
+	jz	1f
 	SWAPGS
 1:
 	/*
@@ -721,7 +721,7 @@ ret_from_intr:
 	CFI_ADJUST_CFA_OFFSET	RBP
 
 	testl $3,CS(%rsp)
-	je retint_kernel
+	jz	retint_kernel
 	/* Interrupt came from user space */
 
 	GET_THREAD_INFO(%rcx)
@@ -1310,7 +1310,7 @@ ENTRY(error_entry)
 	SAVE_EXTRA_REGS 8
 	xorl %ebx,%ebx
 	testl $3,CS+8(%rsp)
-	je error_kernelspace
+	jz	error_kernelspace
 error_swapgs:
 	SWAPGS
 error_sti:
@@ -1361,7 +1361,7 @@ ENTRY(error_exit)
 	TRACE_IRQS_OFF
 	GET_THREAD_INFO(%rcx)
 	testl %eax,%eax
-	jne retint_kernel
+	jnz retint_kernel
 	LOCKDEP_SYS_EXIT_IRQ
 	movl TI_flags(%rcx),%edx
 	movl $_TIF_WORK_MASK,%edi