Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 54ad726c authored by Ingo Molnar's avatar Ingo Molnar
Browse files

x86/asm/entry/32: Improve code readability



Make the 64-bit compat 32-bit syscall entry code a bit more readable:

 - eliminate whitespace noise

 - use consistent vertical spacing

 - use consistent assembly coding style similar to entry_64.S

 - fix various comments

No code changed:

arch/x86/entry/ia32entry.o:

   text	   data	    bss	    dec	    hex	filename
   1391	      0	      0	   1391	    56f	ia32entry.o.before
   1391	      0	      0	   1391	    56f	ia32entry.o.after

md5:
   f28501dcc366e68b557313942c6496d6  ia32entry.o.before.asm
   f28501dcc366e68b557313942c6496d6  ia32entry.o.after.asm

Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent 53e9accf
Loading
Loading
Loading
Loading
+146 −141
Original line number Diff line number Diff line
@@ -3,7 +3,6 @@
 *
 * Copyright 2000-2002 Andi Kleen, SuSE Labs.
 */

#include "calling.h"
#include <asm/asm-offsets.h>
#include <asm/current.h>
@@ -37,7 +36,7 @@ ENDPROC(native_usergs_sysret32)
#endif

/*
 * 32bit SYSENTER instruction entry.
 * 32-bit SYSENTER instruction entry.
 *
 * SYSENTER loads ss, rsp, cs, and rip from previously programmed MSRs.
 * IF and VM in rflags are cleared (IOW: interrupts are off).
@@ -91,7 +90,7 @@ ENTRY(ia32_sysenter_target)

	/*
	 * no need to do an access_ok check here because rbp has been
	 * 32bit zero extended
	 * 32-bit zero extended
	 */
	ASM_STAC
1:	movl	(%rbp), %ebp
@@ -112,7 +111,7 @@ sysenter_flags_fixed:
	jnz	sysenter_tracesys

sysenter_do_call:
	/* 32bit syscall -> 64bit C ABI argument conversion */
	/* 32-bit syscall -> 64-bit C ABI argument conversion */
	movl	%edi, %r8d		/* arg5 */
	movl	%ebp, %r9d		/* arg6 */
	xchg	%ecx, %esi		/* rsi:arg2, rcx:arg4 */
@@ -142,7 +141,7 @@ sysexit_from_sys_call:
	andl    $~TS_COMPAT, ASM_THREAD_INFO(TI_status, %rsp, SIZEOF_PTREGS)
	movl	RIP(%rsp), %ecx		/* User %eip */
	RESTORE_RSI_RDI
	xorl	%edx,%edx		/* avoid info leaks */
	xorl	%edx, %edx		/* Do not leak kernel information */
	xorq	%r8, %r8
	xorq	%r9, %r9
	xorq	%r10, %r10
@@ -212,7 +211,7 @@ sysexit_from_sys_call:
	TRACE_IRQS_OFF
	testl	%edi, ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS)
	jz	\exit
	xorl	%eax, %eax	/* do not leak kernel information */
	xorl	%eax, %eax		/* Do not leak kernel information */
	movq	%rax, R11(%rsp)
	movq	%rax, R10(%rsp)
	movq	%rax, R9(%rsp)
@@ -240,7 +239,7 @@ sysenter_tracesys:
	jz	sysenter_auditsys
#endif
	SAVE_EXTRA_REGS
	xorl	%eax, %eax	/* do not leak kernel information */
	xorl	%eax, %eax		/* Do not leak kernel information */
	movq	%rax, R11(%rsp)
	movq	%rax, R10(%rsp)
	movq	%rax, R9(%rsp)
@@ -260,16 +259,16 @@ sysenter_tracesys:
ENDPROC(ia32_sysenter_target)

/*
 * 32bit SYSCALL instruction entry.
 * 32-bit SYSCALL instruction entry.
 *
 * 32bit SYSCALL saves rip to rcx, clears rflags.RF, then saves rflags to r11,
 * 32-bit SYSCALL saves rip to rcx, clears rflags.RF, then saves rflags to r11,
 * then loads new ss, cs, and rip from previously programmed MSRs.
 * rflags gets masked by a value from another MSR (so CLD and CLAC
 * are not needed). SYSCALL does not save anything on the stack
 * and does not change rsp.
 *
 * Note: rflags saving+masking-with-MSR happens only in Long mode
 * (in legacy 32bit mode, IF, RF and VM bits are cleared and that's it).
 * (in legacy 32-bit mode, IF, RF and VM bits are cleared and that's it).
 * Don't get confused: rflags saving+masking depends on Long Mode Active bit
 * (EFER.LMA=1), NOT on bitness of userspace where SYSCALL executes
 * or target CS descriptor's L bit (SYSCALL does not read segment descriptors).
@@ -319,8 +318,8 @@ ENTRY(ia32_cstar_target)
	sub	$(10*8), %rsp		/* pt_regs->r8-11, bp, bx, r12-15 not saved */

	/*
	 * no need to do an access_ok check here because r8 has been
	 * 32bit zero extended
	 * No need to do an access_ok check here because r8 has been
	 * 32-bit zero extended:
	 */
	ASM_STAC
1:	movl	(%r8), %ebp
@@ -331,15 +330,17 @@ ENTRY(ia32_cstar_target)
	jnz   cstar_tracesys

cstar_do_call:
	/* 32bit syscall -> 64bit C ABI argument conversion */
	/* 32-bit syscall -> 64-bit C ABI argument conversion */
	movl	%edi, %r8d		/* arg5 */
	movl	%ebp, %r9d		/* arg6 */
	xchg	%ecx, %esi		/* rsi:arg2, rcx:arg4 */
	movl	%ebx, %edi		/* arg1 */
	movl	%edx, %edx		/* arg3 (zero extension) */

cstar_dispatch:
	cmpq	$(IA32_NR_syscalls-1), %rax
	ja	1f

	call	*ia32_sys_call_table(, %rax, 8)
	movq	%rax, RAX(%rsp)
1:
@@ -347,6 +348,7 @@ cstar_dispatch:
	TRACE_IRQS_OFF
	testl	$_TIF_ALLWORK_MASK, ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS)
	jnz	sysretl_audit

sysretl_from_sys_call:
	andl	$~TS_COMPAT, ASM_THREAD_INFO(TI_status, %rsp, SIZEOF_PTREGS)
	movl	RCX(%rsp), %ebp
@@ -359,10 +361,10 @@ sysretl_from_sys_call:
	TRACE_IRQS_ON
	movl	RSP(%rsp), %esp
	/*
	 * 64bit->32bit SYSRET restores eip from ecx,
	 * 64-bit->32-bit SYSRET restores eip from ecx,
	 * eflags from r11 (but RF and VM bits are forced to 0),
	 * cs and ss are loaded from MSRs.
	 * (Note: 32bit->32bit SYSRET is different: since r11
	 * (Note: 32-bit->32-bit SYSRET is different: since r11
	 * does not exist, it merely sets eflags.IF=1).
	 *
	 * NB: On AMD CPUs with the X86_BUG_SYSRET_SS_ATTRS bug, the ss
@@ -390,7 +392,7 @@ cstar_tracesys:
	jz	cstar_auditsys
#endif
	SAVE_EXTRA_REGS
	xorl	%eax, %eax	/* do not leak kernel information */
	xorl	%eax, %eax		/* Do not leak kernel information */
	movq	%rax, R11(%rsp)
	movq	%rax, R10(%rsp)
	movq	%rax, R9(%rsp)
@@ -415,7 +417,7 @@ ia32_badarg:
	jmp	ia32_sysret

ia32_ret_from_sys_call:
	xorl	%eax, %eax	/* do not leak kernel information */
	xorl	%eax, %eax		/* Do not leak kernel information */
	movq	%rax, R11(%rsp)
	movq	%rax, R10(%rsp)
	movq	%rax, R9(%rsp)
@@ -473,8 +475,9 @@ ENTRY(ia32_syscall)
	orl	$TS_COMPAT, ASM_THREAD_INFO(TI_status, %rsp, SIZEOF_PTREGS)
	testl	$_TIF_WORK_SYSCALL_ENTRY, ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS)
	jnz	ia32_tracesys

ia32_do_call:
	/* 32bit syscall -> 64bit C ABI argument conversion */
	/* 32-bit syscall -> 64-bit C ABI argument conversion */
	movl	%edi, %r8d		/* arg5 */
	movl	%ebp, %r9d		/* arg6 */
	xchg	%ecx, %esi		/* rsi:arg2, rcx:arg4 */
@@ -482,7 +485,9 @@ ia32_do_call:
	movl	%edx, %edx		/* arg3 (zero extension) */
	cmpq	$(IA32_NR_syscalls-1), %rax
	ja	1f
	call *ia32_sys_call_table(,%rax,8) # xxx: rip relative

	call	*ia32_sys_call_table(, %rax, 8) /* RIP relative */

ia32_sysret:
	movq	%rax, RAX(%rsp)
1: