All of lore.kernel.org
 help / color / mirror / Atom feed
From: Glauber Costa <glommer@redhat.com>
To: Alexander van Heukelum <heukelum@fastmail.fm>
Cc: Ingo Molnar <mingo@elte.hu>, LKML <linux-kernel@vger.kernel.org>,
	Andi Kleen <andi@firstfloor.org>,
	Alexander van Heukelum <heukelum@lusi.uni-sb.de>,
	Glauber Costa <gcosta@redhat.com>
Subject: Re: [RFC] x86: save_args out of line
Date: Mon, 17 Nov 2008 10:14:44 -0200	[thread overview]
Message-ID: <20081117121444.GA13427@poweredge.glommer> (raw)
In-Reply-To: <1226845741-12470-2-git-send-email-heukelum@fastmail.fm>

On Sun, Nov 16, 2008 at 03:29:01PM +0100, Alexander van Heukelum wrote:
> From: Alexander van Heukelum <heukelum@sleipnir.lusi.uni-sb.de>
> 
> The macro "interrupt" in entry_64.S generates a lot of code. This
> patch moves most of its contents into an external function. It
> saves anywhere between 500 and 2500 bytes of text depending on the
> configuration.
> 
> The function returns with an altered stackpointer.
> 
> Dwarf2-annotations are most probably wrong or missing.
> 
> There is a comment in the original code about saving rbp twice, but
> I don't understand what the code tries to do. First of all, the
> second copy of rbp is written below the stack.
This is not for the stack, but to keep the registers as the pt_regs struct
expects them. We'll be casting this structure later, and not doing that
can lead to bogus code, whenever we cast regs->bp.

> Second, if the current
> stack is already the irqstack, this second copy is overwritten. Third,
> as far as I can tell, ebp should not be saved in pt_regs at all at
> this stage as it is 'preserved' due to the C calling conventions. So
> I left this second copy out and everything seems to work fine. If it
> wouldn't, all exceptions and NMIs would be dangerous anyhow, as far
> as I can see.
Try testing with a kernel with CONFIG_FRAME_POINTER turned on.

> 
> Signed-off-by: Alexander van Heukelum <heukelum@fastmail.fm>
> Cc: Glauber Costa <gcosta@redhat.com>
> 
> ---
>  arch/x86/kernel/entry_64.S |  123 ++++++++++++++++++++++++++------------------
>  1 files changed, 73 insertions(+), 50 deletions(-)
> 
> diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
> index a3a7fb2..eb57c23 100644
> --- a/arch/x86/kernel/entry_64.S
> +++ b/arch/x86/kernel/entry_64.S
> @@ -247,6 +247,78 @@ ENTRY(native_usergs_sysret64)
>  	CFI_REL_OFFSET	rsp,RSP
>  	/*CFI_REL_OFFSET	ss,SS*/
>  	.endm
> +
> +/*
> + * initial frame state for interrupts and exceptions
> + */
> +	.macro _frame ref
> +	CFI_STARTPROC simple
> +	CFI_SIGNAL_FRAME
> +	CFI_DEF_CFA rsp,SS+8-\ref
> +	/*CFI_REL_OFFSET ss,SS-\ref*/
> +	CFI_REL_OFFSET rsp,RSP-\ref
> +	/*CFI_REL_OFFSET rflags,EFLAGS-\ref*/
> +	/*CFI_REL_OFFSET cs,CS-\ref*/
> +	CFI_REL_OFFSET rip,RIP-\ref
> +	.endm
> +
> +/* initial frame state for interrupts (and exceptions without error code) */
> +#define INTR_FRAME _frame RIP
> +/* initial frame state for exceptions with error code (and interrupts with
> +   vector already pushed) */
> +#define XCPT_FRAME _frame ORIG_RAX
> +
> +/* save_args changes the stack */
> +ENTRY(save_args)
> +	XCPT_FRAME
> +	cld
> +	subq $9*8, %rsp
> +	CFI_ADJUST_CFA_OFFSET 9*8
> +	push 9*8(%rsp)		/* copy return address */
> +	CFI_ADJUST_CFA_OFFSET 8
> +	movq  %rdi, 8*8+16(%rsp)
> +	CFI_REL_OFFSET rdi, 8*8+16
> +	movq  %rsi, 7*8+16(%rsp)
> +	CFI_REL_OFFSET rsi, 7*8+16
> +	movq  %rdx, 6*8+16(%rsp)
> +	CFI_REL_OFFSET rdx, 6*8+16
> +	movq  %rcx, 5*8+16(%rsp)
> +	CFI_REL_OFFSET rcx, 5*8+16
> +	movq  %rax, 4*8+16(%rsp)
> +	CFI_REL_OFFSET rax, 4*8+16
> +	movq  %r8, 3*8+16(%rsp)
> +	CFI_REL_OFFSET r8, 3*8+16
> +	movq  %r9, 2*8+16(%rsp)
> +	CFI_REL_OFFSET r9, 2*8+16
> +	movq  %r10, 1*8+16(%rsp)
> +	CFI_REL_OFFSET r10, 1*8+16
> +	movq  %r11, 0*8+16(%rsp)
> +	CFI_REL_OFFSET r11, 0*8+16
> +	leaq -ARGOFFSET+16(%rsp),%rdi	/* arg1 for handler */
> +	movq %rbp, 8(%rsp)		/* push %rbp */
> +	leaq 8(%rsp), %rbp		/* mov %rsp, %ebp */
> +	testl $3, CS(%rdi)
> +	je 1f
> +	SWAPGS
> +	/*
> +	 * irqcount is used to check if a CPU is already on an interrupt stack
> +	 * or not. While this is essentially redundant with preempt_count it is
> +	 * a little cheaper to use a separate counter in the PDA (short of
> +	 * moving irq_enter into assembly, which would be too much work)
> +	 */
> +1:	incl %gs:pda_irqcount
> +	jne 2f
> +	pop %rax			/* move return address... */
> +	mov %gs:pda_irqstackptr,%rsp
> +	push %rax			/* ... to the new stack */
> +	/*
> +	 * We entered an interrupt context - irqs are off:
> +	 */
> +2:	TRACE_IRQS_OFF
> +	ret
> +	CFI_ENDPROC
> +END(save_args)
> +
>  /*
>   * A newly forked process directly context switches into this.
>   */
> @@ -615,26 +687,6 @@ ENTRY(stub_rt_sigreturn)
>  END(stub_rt_sigreturn)
>  
>  /*
> - * initial frame state for interrupts and exceptions
> - */
> -	.macro _frame ref
> -	CFI_STARTPROC simple
> -	CFI_SIGNAL_FRAME
> -	CFI_DEF_CFA rsp,SS+8-\ref
> -	/*CFI_REL_OFFSET ss,SS-\ref*/
> -	CFI_REL_OFFSET rsp,RSP-\ref
> -	/*CFI_REL_OFFSET rflags,EFLAGS-\ref*/
> -	/*CFI_REL_OFFSET cs,CS-\ref*/
> -	CFI_REL_OFFSET rip,RIP-\ref
> -	.endm
> -
> -/* initial frame state for interrupts (and exceptions without error code) */
> -#define INTR_FRAME _frame RIP
> -/* initial frame state for exceptions with error code (and interrupts with
> -   vector already pushed) */
> -#define XCPT_FRAME _frame ORIG_RAX
> -
> -/*
>   * Interrupt entry/exit.
>   *
>   * Interrupt entry points save only callee clobbered registers in fast path.
> @@ -644,36 +696,7 @@ END(stub_rt_sigreturn)
>  
>  /* 0(%rsp): interrupt number */
>  	.macro interrupt func
> -	cld
> -	SAVE_ARGS
> -	leaq -ARGOFFSET(%rsp),%rdi	# arg1 for handler
> -	pushq %rbp
> -	/*
> -	 * Save rbp twice: One is for marking the stack frame, as usual, and the
> -	 * other, to fill pt_regs properly. This is because bx comes right
> -	 * before the last saved register in that structure, and not bp. If the
> -	 * base pointer were in the place bx is today, this would not be needed.
> -	 */
> -	movq %rbp, -8(%rsp)
> -	CFI_ADJUST_CFA_OFFSET	8
> -	CFI_REL_OFFSET		rbp, 0
> -	movq %rsp,%rbp
> -	CFI_DEF_CFA_REGISTER	rbp
> -	testl $3,CS(%rdi)
> -	je 1f
> -	SWAPGS
> -	/* irqcount is used to check if a CPU is already on an interrupt
> -	   stack or not. While this is essentially redundant with preempt_count
> -	   it is a little cheaper to use a separate counter in the PDA
> -	   (short of moving irq_enter into assembly, which would be too
> -	    much work) */
> -1:	incl	%gs:pda_irqcount
> -	cmoveq %gs:pda_irqstackptr,%rsp
> -	push    %rbp			# backlink for old unwinder
> -	/*
> -	 * We entered an interrupt context - irqs are off:
> -	 */
> -	TRACE_IRQS_OFF
> +	call save_args
>  	call \func
>  	.endm
>  
> -- 
> 1.5.4.3
> 

  reply	other threads:[~2008-11-17 12:13 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 [this message]
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                 ` [PATCH] x86: entry_64.S: Factor out save_paranoid and paranoid_exit Alexander van Heukelum
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=20081117121444.GA13427@poweredge.glommer \
    --to=glommer@redhat.com \
    --cc=andi@firstfloor.org \
    --cc=gcosta@redhat.com \
    --cc=heukelum@fastmail.fm \
    --cc=heukelum@lusi.uni-sb.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.