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

Commit ebfc453e authored by Denys Vlasenko's avatar Denys Vlasenko Committed by Ingo Molnar
Browse files

x86/asm/entry/64: Clean up and document various entry code details



This patch does a lot of cleanup in comments and formatting,
but it does not change any code:

 - Rename 'save_paranoid' to 'paranoid_entry': this makes naming
   similar to its "non-paranoid" sibling, 'error_entry',
   and to its counterpart, 'paranoid_exit'.

 - Use the same CFI annotation atop 'paranoid_entry' and 'error_entry'.

 - Fix irregular indentation of assembler operands.

 - Add/fix comments on top of 'paranoid_entry' and 'error_entry'.

 - Remove stale comment about "oldrax".

 - Make comments about "no swapgs" flag in ebx more prominent.

 - Deindent wrongly indented top-level comment atop 'paranoid_exit'.

 - Indent wrongly deindented comment inside 'error_entry'.

Signed-off-by: default avatarDenys Vlasenko <dvlasenk@redhat.com>
Signed-off-by: default avatarAndy Lutomirski <luto@amacapital.net>
Cc: Alexei Starovoitov <ast@plumgrid.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Will Drewry <wad@chromium.org>
Link: http://lkml.kernel.org/r/4640f9fcd5ea46eb299b1cd6d3f5da3167d2f78d.1424989793.git.luto@amacapital.net


Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent 1eeb207f
Loading
Loading
Loading
Loading
+36 −32
Original line number Original line Diff line number Diff line
@@ -982,10 +982,11 @@ ENTRY(\sym)
	testl $3, CS(%rsp)		/* If coming from userspace, switch */
	testl $3, CS(%rsp)		/* If coming from userspace, switch */
	jnz 1f				/* stacks. */
	jnz 1f				/* stacks. */
	.endif
	.endif
	call save_paranoid
	call paranoid_entry
	.else
	.else
	call error_entry
	call error_entry
	.endif
	.endif
	/* returned flag: ebx=0: need swapgs on exit, ebx=1: don't need it */


	DEFAULT_FRAME 0
	DEFAULT_FRAME 0


@@ -1016,10 +1017,11 @@ ENTRY(\sym)
	addq $EXCEPTION_STKSZ, INIT_TSS_IST(\shift_ist)
	addq $EXCEPTION_STKSZ, INIT_TSS_IST(\shift_ist)
	.endif
	.endif


	/* these procedures expect "no swapgs" flag in ebx */
	.if \paranoid
	.if \paranoid
	jmp paranoid_exit		/* %ebx: no swapgs flag */
	jmp paranoid_exit
	.else
	.else
	jmp error_exit			/* %ebx: no swapgs flag */
	jmp error_exit
	.endif
	.endif


	.if \paranoid == 1
	.if \paranoid == 1
@@ -1257,8 +1259,13 @@ idtentry async_page_fault do_async_page_fault has_error_code=1
idtentry machine_check has_error_code=0 paranoid=1 do_sym=*machine_check_vector(%rip)
idtentry machine_check has_error_code=0 paranoid=1 do_sym=*machine_check_vector(%rip)
#endif
#endif


ENTRY(save_paranoid)
/*
	XCPT_FRAME 1 RDI+8
 * Save all registers in pt_regs, and switch gs if needed.
 * Use slow, but surefire "are we in kernel?" check.
 * Return: ebx=0: need swapgs on exit, ebx=1: otherwise
 */
ENTRY(paranoid_entry)
	XCPT_FRAME 1 15*8
	cld
	cld
	SAVE_C_REGS 8
	SAVE_C_REGS 8
	SAVE_EXTRA_REGS 8
	SAVE_EXTRA_REGS 8
@@ -1271,7 +1278,7 @@ ENTRY(save_paranoid)
	xorl %ebx,%ebx
	xorl %ebx,%ebx
1:	ret
1:	ret
	CFI_ENDPROC
	CFI_ENDPROC
END(save_paranoid)
END(paranoid_entry)


/*
/*
 * "Paranoid" exit path from exception stack.  This is invoked
 * "Paranoid" exit path from exception stack.  This is invoked
@@ -1283,8 +1290,7 @@ END(save_paranoid)
 * be complicated.  Fortunately, we there's no good reason
 * be complicated.  Fortunately, we there's no good reason
 * to try to handle preemption here.
 * to try to handle preemption here.
 */
 */

/* On entry, ebx is "no swapgs" flag (1: don't need swapgs, 0: need it) */
	/* ebx:	no swapgs flag */
ENTRY(paranoid_exit)
ENTRY(paranoid_exit)
	DEFAULT_FRAME
	DEFAULT_FRAME
	DISABLE_INTERRUPTS(CLBR_NONE)
	DISABLE_INTERRUPTS(CLBR_NONE)
@@ -1305,13 +1311,11 @@ paranoid_exit_restore:
END(paranoid_exit)
END(paranoid_exit)


/*
/*
 * Exception entry point. This expects an error code/orig_rax on the stack.
 * Save all registers in pt_regs, and switch gs if needed.
 * returns in "no swapgs flag" in %ebx.
 * Return: ebx=0: need swapgs on exit, ebx=1: otherwise
 */
 */
ENTRY(error_entry)
ENTRY(error_entry)
	XCPT_FRAME
	XCPT_FRAME 1 15*8
	CFI_ADJUST_CFA_OFFSET 15*8
	/* oldrax contains error code */
	cld
	cld
	SAVE_C_REGS 8
	SAVE_C_REGS 8
	SAVE_EXTRA_REGS 8
	SAVE_EXTRA_REGS 8
@@ -1359,7 +1363,7 @@ error_bad_iret:
END(error_entry)
END(error_entry)




/* ebx:	no swapgs flag (1: don't need swapgs, 0: need it) */
/* On entry, ebx is "no swapgs" flag (1: don't need swapgs, 0: need it) */
ENTRY(error_exit)
ENTRY(error_exit)
	DEFAULT_FRAME
	DEFAULT_FRAME
	movl %ebx,%eax
	movl %ebx,%eax
@@ -1585,13 +1589,13 @@ end_repeat_nmi:
	ALLOC_PT_GPREGS_ON_STACK
	ALLOC_PT_GPREGS_ON_STACK


	/*
	/*
	 * Use save_paranoid to handle SWAPGS, but no need to use paranoid_exit
	 * Use paranoid_entry to handle SWAPGS, but no need to use paranoid_exit
	 * as we should not be calling schedule in NMI context.
	 * as we should not be calling schedule in NMI context.
	 * Even with normal interrupts enabled. An NMI should not be
	 * Even with normal interrupts enabled. An NMI should not be
	 * setting NEED_RESCHED or anything that normal interrupts and
	 * setting NEED_RESCHED or anything that normal interrupts and
	 * exceptions might do.
	 * exceptions might do.
	 */
	 */
	call save_paranoid
	call paranoid_entry
	DEFAULT_FRAME 0
	DEFAULT_FRAME 0


	/*
	/*