linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Josh Poimboeuf <jpoimboe@redhat.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Linux Crypto Mailing List <linux-crypto@vger.kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	Andy Lutomirski <luto@kernel.org>, Ingo Molnar <mingo@kernel.org>,
	Andy Lutomirski <luto@amacapital.net>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Ard Biesheuvel <ard.biesheuvel@linaro.org>
Subject: Re: x86-64: Maintain 16-byte stack alignment
Date: Thu, 12 Jan 2017 23:07:09 -0600	[thread overview]
Message-ID: <20170113050709.yrdtfet5d4sebubi@treble> (raw)
In-Reply-To: <CA+55aFzRrSwGxxfZk-RUEnsz=xhcSmOwE1CenfCPBWtsS9MwDw@mail.gmail.com>

On Thu, Jan 12, 2017 at 08:37:18PM -0800, Linus Torvalds wrote:
> On Jan 12, 2017 8:28 PM, "Josh Poimboeuf" <jpoimboe@redhat.com> wrote:
> 
> 
> The stack frame was always 16-byte aligned regardless of whether the
> buf array size was even or odd.
> 
> 
> Including with -fomit-frame-pointer?
> 
> With frame pointers, stack frames really are naturally 16 bytes, and then
> keeping the frame 16-byte aligned is just a matter of making any extra
> frame allocations or push/pop sequences that you do also be a multiple of
> 16 bytes.
> 
> But *without* frame pointers, the"native" frame size is just 8 bytes, and a
> function that doesn't need any other local storage and then calls another
> function (think various trivial wrapper functions that just add an argument
> and then munge the return value) would thus naturally cause the frame to
> become misaligned.
> 
> So then the compiler actually needs to start adding useless instructions
> just to keep the stack 16-byte aligned.

Disabling frame pointers didn't seem to help, but I finally got it to
misalign with a different test case.  I think it had been aligning the
array, so instead I made it push a register.


void otherfunc(void);

static inline void bar(int f)
{
	register void *__sp asm(_ASM_SP);
	asm volatile("call otherfunc" : "+r" (__sp) : "b"(f));
}

void foo(void)
{
	bar(5);
}


00000000000020f0 <foo>:
    20f0:	55                   	push   %rbp
    20f1:	48 89 e5             	mov    %rsp,%rbp
    20f4:	53                   	push   %rbx
    20f5:	bb 05 00 00 00       	mov    $0x5,%ebx
    20fa:	e8 00 00 00 00       	callq  20ff <foo+0xf>
			20fb: R_X86_64_PC32	otherfunc-0x4
    20ff:	5b                   	pop    %rbx
    2100:	5d                   	pop    %rbp
    2101:	c3                   	retq   
    2102:	0f 1f 40 00          	nopl   0x0(%rax)
    2106:	66 2e 0f 1f 84 00 00 	nopw   %cs:0x0(%rax,%rax,1)
    210d:	00 00 00 

-- 
Josh

  parent reply	other threads:[~2017-01-13  5:07 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-10 14:33 x86-64: Maintain 16-byte stack alignment Herbert Xu
2017-01-10 14:39 ` Herbert Xu
2017-01-10 17:05   ` Linus Torvalds
2017-01-10 17:09     ` Andy Lutomirski
2017-01-11  3:11     ` Herbert Xu
2017-01-11  3:30       ` Linus Torvalds
2017-01-11  4:17         ` Linus Torvalds
2017-01-11  4:35           ` Herbert Xu
2017-01-11  6:01             ` Andy Lutomirski
2017-01-12  6:21               ` Andy Lutomirski
2017-01-12  7:40                 ` Ingo Molnar
2017-01-12 14:02                 ` Josh Poimboeuf
2017-01-12 19:51                   ` Linus Torvalds
2017-01-12 20:08                     ` Andy Lutomirski
2017-01-12 20:15                       ` Josh Poimboeuf
2017-01-12 20:55                         ` Josh Poimboeuf
2017-01-12 21:40                           ` Linus Torvalds
2017-01-13  8:38                             ` Herbert Xu
2017-01-13  1:46                         ` Andy Lutomirski
2017-01-13  3:11                           ` Josh Poimboeuf
2017-01-13  3:23                             ` Andy Lutomirski
2017-01-13  4:27                               ` Josh Poimboeuf
     [not found]                                 ` <CA+55aFzRrSwGxxfZk-RUEnsz=xhcSmOwE1CenfCPBWtsS9MwDw@mail.gmail.com>
2017-01-13  5:07                                   ` Josh Poimboeuf [this message]
2017-01-13  8:43                                     ` Herbert Xu
2017-01-13  8:42                                   ` Herbert Xu
2017-01-13  8:39                           ` Herbert Xu
2017-01-13  8:36                       ` Herbert Xu
2017-01-13 13:07                         ` Josh Poimboeuf
     [not found]             ` <CA+55aFw+Z_ieo6DzTVB6_-TvQ0jj60s=T0mvXfqkBVFdKFPw_Q@mail.gmail.com>
2017-01-11  8:06               ` Ard Biesheuvel
2017-01-11  8:09                 ` Herbert Xu
2017-01-11 18:20                   ` Andy Lutomirski
2017-01-12  7:05     ` Herbert Xu
2017-01-12  7:46       ` Ingo Molnar
2017-01-12 14:49         ` Josh Poimboeuf
2017-01-12  7:51       ` Andy Lutomirski
2017-01-12  8:04         ` Herbert Xu
2017-01-12  8:18           ` Ingo Molnar
2017-01-12 15:03         ` Josh Poimboeuf
2017-01-12 15:06           ` Herbert Xu
2017-01-12 15:18             ` Josh Poimboeuf
2017-01-12 15:10           ` Josh Poimboeuf
2017-01-10 17:30 ` Ard Biesheuvel
2017-01-10 19:00   ` Andy Lutomirski
2017-01-10 19:16     ` Ard Biesheuvel
2017-01-10 19:22       ` Andy Lutomirski
2017-01-10 20:00         ` Ard Biesheuvel
2017-01-10 23:25           ` Andy Lutomirski
2017-01-11  3:26             ` Herbert Xu
2017-01-11  3:26         ` Herbert Xu
2017-01-11  3:16     ` Herbert Xu
2017-01-11  3:15   ` Herbert Xu
2017-01-12  6:12   ` Herbert Xu
2017-01-12  8:01     ` Ard Biesheuvel
2017-01-12  8:06       ` Herbert Xu

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=20170113050709.yrdtfet5d4sebubi@treble \
    --to=jpoimboe@redhat.com \
    --cc=ard.biesheuvel@linaro.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@amacapital.net \
    --cc=luto@kernel.org \
    --cc=mingo@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    /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).