From: Josh Poimboeuf <jpoimboe@redhat.com>
To: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Andy Lutomirski <luto@amacapital.net>,
Linus Torvalds <torvalds@linux-foundation.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Linux Crypto Mailing List <linux-crypto@vger.kernel.org>,
Ingo Molnar <mingo@kernel.org>,
Thomas Gleixner <tglx@linutronix.de>,
Andy Lutomirski <luto@kernel.org>,
Ard Biesheuvel <ard.biesheuvel@linaro.org>
Subject: Re: x86-64: Maintain 16-byte stack alignment
Date: Fri, 13 Jan 2017 07:07:58 -0600 [thread overview]
Message-ID: <20170113130758.t6flrek6v7r2qkp6@treble> (raw)
In-Reply-To: <20170113083648.GA22022@gondor.apana.org.au>
On Fri, Jan 13, 2017 at 04:36:48PM +0800, Herbert Xu wrote:
> On Thu, Jan 12, 2017 at 12:08:07PM -0800, Andy Lutomirski wrote:
> >
> > I think we have some inline functions that do asm volatile ("call
> > ..."), and I don't see any credible way of forcing alignment short of
> > generating an entirely new stack frame and aligning that. Ick. This
>
> A straight asm call from C should always work because gcc keeps
> the stack aligned in the prologue.
>
> The only problem with inline assembly is when you start pushing
> things onto the stack directly.
I tried another approach. I rebuilt the kernel with
-mpreferred-stack-boundary=4 and used awk (poor man's objtool) to find
all leaf functions with misaligned stacks.
objdump -d ~/k/vmlinux | awk '/>:/ { f=$2; call=0; push=0 } /fentry/ { next } /callq/ { call=1 } /push/ { push=!push } /sub.*8,%rsp/ { push=!push } /^$/ && call == 0 && push == 0 { print f }'
It found a lot of functions. Here's one of them:
ffffffff814ab450 <mpihelp_add_n>:
ffffffff814ab450: 55 push %rbp
ffffffff814ab451: f7 d9 neg %ecx
ffffffff814ab453: 31 c0 xor %eax,%eax
ffffffff814ab455: 4c 63 c1 movslq %ecx,%r8
ffffffff814ab458: 48 89 e5 mov %rsp,%rbp
ffffffff814ab45b: 53 push %rbx
ffffffff814ab45c: 4a 8d 1c c5 00 00 00 lea 0x0(,%r8,8),%rbx
ffffffff814ab463: 00
ffffffff814ab464: eb 03 jmp ffffffff814ab469 <mpihelp_add_n+0x19>
ffffffff814ab466: 4c 63 c1 movslq %ecx,%r8
ffffffff814ab469: 49 c1 e0 03 shl $0x3,%r8
ffffffff814ab46d: 45 31 c9 xor %r9d,%r9d
ffffffff814ab470: 49 29 d8 sub %rbx,%r8
ffffffff814ab473: 4a 03 04 02 add (%rdx,%r8,1),%rax
ffffffff814ab477: 41 0f 92 c1 setb %r9b
ffffffff814ab47b: 4a 03 04 06 add (%rsi,%r8,1),%rax
ffffffff814ab47f: 41 0f 92 c2 setb %r10b
ffffffff814ab483: 49 89 c3 mov %rax,%r11
ffffffff814ab486: 83 c1 01 add $0x1,%ecx
ffffffff814ab489: 45 0f b6 d2 movzbl %r10b,%r10d
ffffffff814ab48d: 4e 89 1c 07 mov %r11,(%rdi,%r8,1)
ffffffff814ab491: 4b 8d 04 0a lea (%r10,%r9,1),%rax
ffffffff814ab495: 75 cf jne ffffffff814ab466 <mpihelp_add_n+0x16>
ffffffff814ab497: 5b pop %rbx
ffffffff814ab498: 5d pop %rbp
ffffffff814ab499: c3 retq
ffffffff814ab49a: 66 0f 1f 44 00 00 nopw 0x0(%rax,%rax,1)
That's a leaf function which, as far as I can tell, doesn't use any
inline asm, but its prologue produces a misaligned stack.
I added inline asm with a call instruction and no operands or clobbers,
and got the same result.
So Andy's theory seems to be correct. As long as we allow calls from
inline asm, we can't rely on aligned stacks.
--
Josh
next prev parent reply other threads:[~2017-01-13 13:08 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
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 [this message]
[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=20170113130758.t6flrek6v7r2qkp6@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).