linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexander van Heukelum <heukelum@mailshack.com>
To: Ingo Molnar <mingo@elte.hu>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Andi Kleen <andi@firstfloor.org>,
	"H. Peter Anvin" <hpa@zytor.com>,
	Jan Beulich <jbeulich@novell.com>,
	Glauber Costa <gcosta@redhat.com>, Matt Mackall <mpm@selenic.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Nick Piggin <nickpiggin@yahoo.com.au>,
	Cyrill Gorcunov <gorcunov@gmail.com>
Subject: [PATCH] x86: entry_64.S: Factor out save_paranoid and paranoid_exit.
Date: Fri, 21 Nov 2008 16:43:18 +0100	[thread overview]
Message-ID: <20081121154318.GA13014@mailshack.com> (raw)
In-Reply-To: <20081121154155.GA12999@mailshack.com>

Also expand the paranoid_exit0 macro into nmi_exit inside the
nmi stub in the case of enabled irq-tracing.

This gives a few hundred bytes code size reduction.

Signed-off-by: Alexander van Heukelum <heukelum@fastmail.fm>
---
 arch/x86/kernel/entry_64.S |  151 +++++++++++++++++++++++++++++--------------
 1 files changed, 102 insertions(+), 49 deletions(-)

diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
index ef95c45..fad777b 100644
--- a/arch/x86/kernel/entry_64.S
+++ b/arch/x86/kernel/entry_64.S
@@ -353,6 +353,36 @@ ENTRY(save_rest)
 	CFI_ENDPROC
 END(save_rest)
 
+/* save complete stack frame */
+ENTRY(save_paranoid)
+	XCPT_FRAME 1 RDI+8
+	cld
+	movq_cfi rdi, RDI+8
+	movq_cfi rsi, RSI+8
+	movq_cfi rdx, RDX+8
+	movq_cfi rcx, RCX+8
+	movq_cfi rax, RAX+8
+	movq_cfi r8, R8+8
+	movq_cfi r9, R9+8
+	movq_cfi r10, R10+8
+	movq_cfi r11, R11+8
+	movq_cfi rbx, RBX+8
+	movq_cfi rbp, RBP+8
+	movq_cfi r12, R12+8
+	movq_cfi r13, R13+8
+	movq_cfi r14, R14+8
+	movq_cfi r15, R15+8
+	movl $1,%ebx
+	movl $MSR_GS_BASE,%ecx
+	rdmsr
+	testl %edx,%edx
+	js 1f	/* negative -> in kernel */
+	SWAPGS
+	xorl %ebx,%ebx
+1:	ret
+	CFI_ENDPROC
+END(save_paranoid)
+
 /*
  * A newly forked process directly context switches into this.
  */
@@ -1012,24 +1042,15 @@ END(spurious_interrupt)
 	.endm
 
 	/* error code is on the stack already */
-	/* handle NMI like exceptions that can happen everywhere */
-	.macro paranoidentry sym, ist=0, irqtrace=1
-	SAVE_ALL
-	cld
-	movl $1,%ebx
-	movl  $MSR_GS_BASE,%ecx
-	rdmsr
-	testl %edx,%edx
-	js    1f
-	SWAPGS
-	xorl  %ebx,%ebx
-1:
+	.macro paranoidentry sym ist=0
+	subq $15*8, %rsp
+	CFI_ADJUST_CFA_OFFSET 15*8
+	call save_paranoid
+	DEFAULT_FRAME 0
 	.if \ist
 	movq	%gs:pda_data_offset, %rbp
 	.endif
-	.if \irqtrace
 	TRACE_IRQS_OFF
-	.endif
 	movq %rsp,%rdi
 	movq ORIG_RAX(%rsp),%rsi
 	movq $-1,ORIG_RAX(%rsp)
@@ -1041,9 +1062,7 @@ END(spurious_interrupt)
 	addq	$EXCEPTION_STKSZ, per_cpu__init_tss + TSS_ist + (\ist - 1) * 8(%rbp)
 	.endif
 	DISABLE_INTERRUPTS(CLBR_NONE)
-	.if \irqtrace
 	TRACE_IRQS_OFF
-	.endif
 	.endm
 
 	/*
@@ -1058,57 +1077,48 @@ END(spurious_interrupt)
 	 * is fundamentally NMI-unsafe. (we cannot change the soft and
 	 * hard flags at once, atomically)
 	 */
-	.macro paranoidexit trace=1
+
 	/* ebx:	no swapgs flag */
-paranoid_exit\trace:
+KPROBE_ENTRY(paranoid_exit)
+	INTR_FRAME
 	testl %ebx,%ebx				/* swapgs needed? */
-	jnz paranoid_restore\trace
+	jnz paranoid_restore
 	testl $3,CS(%rsp)
-	jnz   paranoid_userspace\trace
-paranoid_swapgs\trace:
-	.if \trace
+	jnz   paranoid_userspace
+paranoid_swapgs:
 	TRACE_IRQS_IRETQ 0
-	.endif
 	SWAPGS_UNSAFE_STACK
-paranoid_restore\trace:
+paranoid_restore:
 	RESTORE_ALL 8
 	jmp irq_return
-paranoid_userspace\trace:
+paranoid_userspace:
 	GET_THREAD_INFO(%rcx)
 	movl TI_flags(%rcx),%ebx
 	andl $_TIF_WORK_MASK,%ebx
-	jz paranoid_swapgs\trace
+	jz paranoid_swapgs
 	movq %rsp,%rdi			/* &pt_regs */
 	call sync_regs
 	movq %rax,%rsp			/* switch stack for scheduling */
 	testl $_TIF_NEED_RESCHED,%ebx
-	jnz paranoid_schedule\trace
+	jnz paranoid_schedule
 	movl %ebx,%edx			/* arg3: thread flags */
-	.if \trace
 	TRACE_IRQS_ON
-	.endif
 	ENABLE_INTERRUPTS(CLBR_NONE)
 	xorl %esi,%esi 			/* arg2: oldset */
 	movq %rsp,%rdi 			/* arg1: &pt_regs */
 	call do_notify_resume
 	DISABLE_INTERRUPTS(CLBR_NONE)
-	.if \trace
 	TRACE_IRQS_OFF
-	.endif
-	jmp paranoid_userspace\trace
-paranoid_schedule\trace:
-	.if \trace
+	jmp paranoid_userspace
+paranoid_schedule:
 	TRACE_IRQS_ON
-	.endif
 	ENABLE_INTERRUPTS(CLBR_ANY)
 	call schedule
 	DISABLE_INTERRUPTS(CLBR_ANY)
-	.if \trace
 	TRACE_IRQS_OFF
-	.endif
-	jmp paranoid_userspace\trace
+	jmp paranoid_userspace
 	CFI_ENDPROC
-	.endm
+END(paranoid_exit)
 
 /*
  * Exception entry point. This expects an error code/orig_rax on the stack.
@@ -1326,20 +1336,63 @@ KPROBE_ENTRY(debug)
 	pushq $0
 	CFI_ADJUST_CFA_OFFSET 8
 	paranoidentry do_debug, DEBUG_STACK
-	paranoidexit
+	jmp paranoid_exit
+ 	CFI_ENDPROC
 KPROBE_END(debug)
 
 	/* runs on exception stack */
 KPROBE_ENTRY(nmi)
 	INTR_FRAME
 	PARAVIRT_ADJUST_EXCEPTION_FRAME
-	pushq $-1
-	CFI_ADJUST_CFA_OFFSET 8
-	paranoidentry do_nmi, 0, 0
+	pushq_cfi $-1
+	subq $15*8, %rsp
+	CFI_ADJUST_CFA_OFFSET 15*8
+	call save_paranoid
+	DEFAULT_FRAME 0
+	/* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
+	movq %rsp,%rdi
+	movq ORIG_RAX(%rsp),%rsi
+	movq $-1,ORIG_RAX(%rsp)
+	call do_nmi
+	DISABLE_INTERRUPTS(CLBR_NONE)
 #ifdef CONFIG_TRACE_IRQFLAGS
-	paranoidexit 0
+	/* paranoidexit; without TRACE_IRQS_OFF */
+	/* ebx:	no swapgs flag */
+nmi_exit:
+	testl %ebx,%ebx				/* swapgs needed? */
+	jnz nmi_restore
+	testl $3,CS(%rsp)
+	jnz nmi_userspace
+nmi_swapgs:
+	SWAPGS_UNSAFE_STACK
+nmi_restore:
+	RESTORE_ALL 8
+	jmp irq_return
+nmi_userspace:
+	GET_THREAD_INFO(%rcx)
+	movl TI_flags(%rcx),%ebx
+	andl $_TIF_WORK_MASK,%ebx
+	jz nmi_swapgs
+	movq %rsp,%rdi			/* &pt_regs */
+	call sync_regs
+	movq %rax,%rsp			/* switch stack for scheduling */
+	testl $_TIF_NEED_RESCHED,%ebx
+	jnz nmi_schedule
+	movl %ebx,%edx			/* arg3: thread flags */
+	ENABLE_INTERRUPTS(CLBR_NONE)
+	xorl %esi,%esi 			/* arg2: oldset */
+	movq %rsp,%rdi 			/* arg1: &pt_regs */
+	call do_notify_resume
+	DISABLE_INTERRUPTS(CLBR_NONE)
+	jmp nmi_userspace
+nmi_schedule:
+	ENABLE_INTERRUPTS(CLBR_ANY)
+	call schedule
+	DISABLE_INTERRUPTS(CLBR_ANY)
+	jmp nmi_userspace
+	CFI_ENDPROC
 #else
-	jmp paranoid_exit1
+	jmp paranoid_exit
  	CFI_ENDPROC
 #endif
 KPROBE_END(nmi)
@@ -1350,7 +1403,7 @@ KPROBE_ENTRY(int3)
  	pushq $0
  	CFI_ADJUST_CFA_OFFSET 8
  	paranoidentry do_int3, DEBUG_STACK
- 	jmp paranoid_exit1
+ 	jmp paranoid_exit
  	CFI_ENDPROC
 KPROBE_END(int3)
 
@@ -1375,7 +1428,7 @@ ENTRY(double_fault)
 	XCPT_FRAME
 	PARAVIRT_ADJUST_EXCEPTION_FRAME
 	paranoidentry do_double_fault
-	jmp paranoid_exit1
+	jmp paranoid_exit
 	CFI_ENDPROC
 END(double_fault)
 
@@ -1392,7 +1445,7 @@ ENTRY(stack_segment)
 	XCPT_FRAME
 	PARAVIRT_ADJUST_EXCEPTION_FRAME
 	paranoidentry do_stack_segment
-	jmp paranoid_exit1
+	jmp paranoid_exit
 	CFI_ENDPROC
 END(stack_segment)
 
@@ -1420,7 +1473,7 @@ ENTRY(machine_check)
 	pushq $0
 	CFI_ADJUST_CFA_OFFSET 8
 	paranoidentry do_machine_check
-	jmp paranoid_exit1
+	jmp paranoid_exit
 	CFI_ENDPROC
 END(machine_check)
 #endif
-- 
1.5.4.3


  reply	other threads:[~2008-11-21 15:48 UTC|newest]

Thread overview: 75+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-16 14:29 [PATCH] trivial, entry_64: remove whitespace at end of lines Alexander van Heukelum
2008-11-16 14:29 ` [RFC] x86: save_args out of line Alexander van Heukelum
2008-11-17 12:14   ` Glauber Costa
2008-11-17 15:13     ` Alexander van Heukelum
2008-11-17 12:53   ` Andi Kleen
2008-11-17 15:37     ` Alexander van Heukelum
2008-11-17 18:23       ` Andi Kleen
2008-11-17 19:22         ` Cyrill Gorcunov
2008-11-17 19:29           ` Cyrill Gorcunov
2008-11-17 19:49             ` Alexander van Heukelum
2008-11-17 19:54               ` Cyrill Gorcunov
2008-11-17 19:43           ` Alexander van Heukelum
2008-11-17 19:49             ` Cyrill Gorcunov
2008-11-17 17:52   ` [RFC,v2] x86_64: " Alexander van Heukelum
2008-11-18  8:09     ` Jan Beulich
2008-11-18 11:16       ` Alexander van Heukelum
2008-11-18 12:51         ` Jan Beulich
2008-11-18 14:03           ` Ingo Molnar
2008-11-18 14:52             ` Jan Beulich
2008-11-18 15:00               ` Ingo Molnar
2008-11-18 22:53                 ` Roland McGrath
2008-11-18 23:35                   ` Andi Kleen
2008-11-18 23:36                     ` Jeremy Fitzhardinge
2008-11-18 23:44                       ` H. Peter Anvin
2008-11-19  0:08                         ` Jeremy Fitzhardinge
2008-11-18 23:45                     ` Roland McGrath
2008-11-19  0:06                       ` Andi Kleen
2008-11-19  0:01                         ` H. Peter Anvin
2008-11-19 10:34                   ` Ingo Molnar
2008-11-19 20:09                     ` Ingo Molnar
2008-11-19  0:18     ` [PATCH/RFC] Move entry_64.S register saving out of the macros Alexander van Heukelum
2008-11-19 17:54       ` H. Peter Anvin
2008-11-19 20:16         ` Ingo Molnar
2008-11-20 13:40       ` [PATCH] x86: clean up after: move " Alexander van Heukelum
2008-11-20 14:01         ` Andi Kleen
2008-11-20 15:04         ` Ingo Molnar
2008-11-20 15:26           ` Alexander van Heukelum
2008-11-20 15:39             ` Ingo Molnar
2008-11-20 15:50               ` [PATCH] x86: clean up after: move entry_64.S register savingout " Jan Beulich
2008-11-20 15:57               ` [PATCH] x86: clean up after: move entry_64.S register saving out " Alexander van Heukelum
2008-11-20 16:07                 ` Cyrill Gorcunov
2008-11-20 16:29                 ` Alexander van Heukelum
2008-11-20 17:24                 ` Ingo Molnar
2008-11-21 15:41               ` [PATCH] x86: Introduce save_rest and restructure the PTREGSCALL macro in entry_64.S Alexander van Heukelum
2008-11-21 15:43                 ` Alexander van Heukelum [this message]
2008-11-21 15:44                   ` [PATCH] Split out some macro's and move common code to paranoid_exit Alexander van Heukelum
2008-11-21 16:06                     ` Ingo Molnar
2008-11-23  9:08                       ` [PATCH] x86: include ENTRY/END in entry handlers in entry_64.S Alexander van Heukelum
2008-11-23  9:15                         ` [PATCH] x86: KPROBE_ENTRY should be paired wth KPROBE_END Alexander van Heukelum
2008-11-23 13:27                           ` Ingo Molnar
2008-11-23 13:51                             ` Cyrill Gorcunov
2008-11-23 14:12                               ` Cyrill Gorcunov
2008-11-23 14:55                                 ` Ingo Molnar
2008-11-23 15:04                                   ` Cyrill Gorcunov
2008-11-23 15:04                                 ` Alexander van Heukelum
2008-11-23 15:12                                   ` Cyrill Gorcunov
2008-11-23 15:31                                     ` Ingo Molnar
2008-11-23 15:41                                       ` Cyrill Gorcunov
2008-11-23 15:37                                   ` Cyrill Gorcunov
2008-11-23 16:29                                     ` Ingo Molnar
2008-11-24  9:17                           ` Jan Beulich
2008-11-24 10:26                             ` Alexander van Heukelum
2008-11-24 10:35                               ` Jan Beulich
2008-11-24 12:24                                 ` [PATCH] x86_64: get rid of the use of KPROBE_ENTRY / KPROBE_END Alexander van Heukelum
2008-11-24 13:33                                   ` Jan Beulich
2008-11-24 14:38                                     ` [PATCH] i386: " Alexander van Heukelum
2008-11-23  9:21                         ` [PATCH] x86: include ENTRY/END in entry handlers in entry_64.S Cyrill Gorcunov
2008-11-23 11:23                           ` Alexander van Heukelum
2008-11-23 11:35                             ` Cyrill Gorcunov
2008-11-23 20:13                             ` H. Peter Anvin
2008-11-24 10:06                               ` Alexander van Heukelum
2008-11-24 18:07                                 ` H. Peter Anvin
2008-11-23 13:23                         ` Ingo Molnar
2008-11-17  9:47 ` [PATCH] trivial, entry_64: remove whitespace at end of lines Ingo Molnar
2008-11-17 15:14   ` Alexander van Heukelum

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20081121154318.GA13014@mailshack.com \
    --to=heukelum@mailshack.com \
    --cc=andi@firstfloor.org \
    --cc=gcosta@redhat.com \
    --cc=gorcunov@gmail.com \
    --cc=hpa@zytor.com \
    --cc=jbeulich@novell.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=mpm@selenic.com \
    --cc=nickpiggin@yahoo.com.au \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).