Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1557985

Re: x86-64: Maintain 16-byte stack alignment

From Andy Lutomirski <luto@amacapital.net>
Newsgroups linux.kernel
Subject Re: x86-64: Maintain 16-byte stack alignment
Date 2017-01-13 04:30 +0100
Message-ID <sZ0IV-49E-9@gated-at.bofh.it> (permalink)
References (6 earlier) <sYTHr-80V-1@gated-at.bofh.it> <sYTR7-8jl-5@gated-at.bofh.it> <sYU0O-8mC-11@gated-at.bofh.it> <sYZa9-2Zi-3@gated-at.bofh.it> <sZ0zg-46z-9@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Thu, Jan 12, 2017 at 7:11 PM, Josh Poimboeuf <jpoimboe@redhat.com> wrote:
> On Thu, Jan 12, 2017 at 05:46:55PM -0800, Andy Lutomirski wrote:
>> On Thu, Jan 12, 2017 at 12:15 PM, Josh Poimboeuf <jpoimboe@redhat.com> wrote:
>> > On Thu, Jan 12, 2017 at 12:08:07PM -0800, Andy Lutomirski wrote:
>> >> On Thu, Jan 12, 2017 at 11:51 AM, Linus Torvalds
>> >> <torvalds@linux-foundation.org> wrote:
>> >> > On Thu, Jan 12, 2017 at 6:02 AM, Josh Poimboeuf <jpoimboe@redhat.com> wrote:
>> >> >>
>> >> >> Just to clarify, I think you're asking if, for versions of gcc which
>> >> >> don't support -mpreferred-stack-boundary=3, objtool can analyze all C
>> >> >> functions to ensure their stacks are 16-byte aligned.
>> >> >>
>> >> >> It's certainly possible, but I don't see how that solves the problem.
>> >> >> The stack will still be misaligned by entry code.  Or am I missing
>> >> >> something?
>> >> >
>> >> > I think the argument is that we *could* try to align things, if we
>> >> > just had some tool that actually then verified that we aren't missing
>> >> > anything.
>> >> >
>> >> > I'm not entirely happy with checking the generated code, though,
>> >> > because as Ingo says, you have a 50:50 chance of just getting it right
>> >> > by mistake. So I'd much rather have some static tool that checks
>> >> > things at a code level (ie coccinelle or sparse).
>> >>
>> >> What I meant was checking the entry code to see if it aligns stack
>> >> frames, and good luck getting sparse to do that.  Hmm, getting 16-byte
>> >> alignment for real may actually be entirely a lost cause.  After all,
>> >> 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.
>> >
>> > Actually we already found all such cases and fixed them by forcing a new
>> > stack frame, thanks to objtool.  For example, see 55a76b59b5fe.
>>
>> What I mean is: what guarantees that the stack is properly aligned for
>> the subroutine call?  gcc promises to set up a stack frame, but does
>> it promise that rsp will be properly aligned to call a C function?
>
> Yes, I did an experiment and you're right.  I had naively assumed that
> all stack frames would be aligned.

Just to check: did you do your experiment with -mpreferred-stack-boundary=4?

--Andy

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: x86-64: Maintain 16-byte stack alignment Herbert Xu <herbert@gondor.apana.org.au> - 2017-01-10 15:40 +0100
  Re: x86-64: Maintain 16-byte stack alignment Linus Torvalds <torvalds@linux-foundation.org> - 2017-01-10 18:10 +0100
    Re: x86-64: Maintain 16-byte stack alignment Andy Lutomirski <luto@amacapital.net> - 2017-01-10 18:20 +0100
    Re: x86-64: Maintain 16-byte stack alignment Herbert Xu <herbert@gondor.apana.org.au> - 2017-01-11 04:20 +0100
      Re: x86-64: Maintain 16-byte stack alignment Linus Torvalds <torvalds@linux-foundation.org> - 2017-01-11 04:40 +0100
        Re: x86-64: Maintain 16-byte stack alignment Linus Torvalds <torvalds@linux-foundation.org> - 2017-01-11 05:20 +0100
          Re: x86-64: Maintain 16-byte stack alignment Herbert Xu <herbert@gondor.apana.org.au> - 2017-01-11 05:40 +0100
            Re: x86-64: Maintain 16-byte stack alignment Andy Lutomirski <luto@amacapital.net> - 2017-01-11 07:10 +0100
              Re: x86-64: Maintain 16-byte stack alignment Andy Lutomirski <luto@amacapital.net> - 2017-01-12 07:30 +0100
                Re: x86-64: Maintain 16-byte stack alignment Ingo Molnar <mingo@kernel.org> - 2017-01-12 08:50 +0100
                Re: x86-64: Maintain 16-byte stack alignment Josh Poimboeuf <jpoimboe@redhat.com> - 2017-01-12 15:10 +0100
                Re: x86-64: Maintain 16-byte stack alignment Linus Torvalds <torvalds@linux-foundation.org> - 2017-01-12 21:00 +0100
                Re: x86-64: Maintain 16-byte stack alignment Andy Lutomirski <luto@amacapital.net> - 2017-01-12 21:10 +0100
                Re: x86-64: Maintain 16-byte stack alignment Josh Poimboeuf <jpoimboe@redhat.com> - 2017-01-12 21:20 +0100
                Re: x86-64: Maintain 16-byte stack alignment Josh Poimboeuf <jpoimboe@redhat.com> - 2017-01-12 22:00 +0100
                Re: x86-64: Maintain 16-byte stack alignment Linus Torvalds <torvalds@linux-foundation.org> - 2017-01-12 22:50 +0100
                Re: x86-64: Maintain 16-byte stack alignment Herbert Xu <herbert@gondor.apana.org.au> - 2017-01-13 09:40 +0100
                Re: x86-64: Maintain 16-byte stack alignment Andy Lutomirski <luto@amacapital.net> - 2017-01-13 02:50 +0100
                Re: x86-64: Maintain 16-byte stack alignment Josh Poimboeuf <jpoimboe@redhat.com> - 2017-01-13 04:20 +0100
                Re: x86-64: Maintain 16-byte stack alignment Andy Lutomirski <luto@amacapital.net> - 2017-01-13 04:30 +0100
                Re: x86-64: Maintain 16-byte stack alignment Josh Poimboeuf <jpoimboe@redhat.com> - 2017-01-13 05:30 +0100
                Re: x86-64: Maintain 16-byte stack alignment Josh Poimboeuf <jpoimboe@redhat.com> - 2017-01-13 06:10 +0100
                Re: x86-64: Maintain 16-byte stack alignment Herbert Xu <herbert@gondor.apana.org.au> - 2017-01-13 09:50 +0100
                Re: x86-64: Maintain 16-byte stack alignment Herbert Xu <herbert@gondor.apana.org.au> - 2017-01-13 09:50 +0100
                Re: x86-64: Maintain 16-byte stack alignment Herbert Xu <herbert@gondor.apana.org.au> - 2017-01-13 09:50 +0100
                Re: x86-64: Maintain 16-byte stack alignment Herbert Xu <herbert@gondor.apana.org.au> - 2017-01-13 09:40 +0100
                Re: x86-64: Maintain 16-byte stack alignment Josh Poimboeuf <jpoimboe@redhat.com> - 2017-01-13 14:10 +0100
            Re: x86-64: Maintain 16-byte stack alignment Ard Biesheuvel <ard.biesheuvel@linaro.org> - 2017-01-11 09:10 +0100
              Re: x86-64: Maintain 16-byte stack alignment Herbert Xu <herbert@gondor.apana.org.au> - 2017-01-11 09:20 +0100
                Re: x86-64: Maintain 16-byte stack alignment Andy Lutomirski <luto@amacapital.net> - 2017-01-11 19:30 +0100
    Re: x86-64: Maintain 16-byte stack alignment Herbert Xu <herbert@gondor.apana.org.au> - 2017-01-12 08:10 +0100
      Re: x86-64: Maintain 16-byte stack alignment Ingo Molnar <mingo@kernel.org> - 2017-01-12 08:50 +0100
        Re: x86-64: Maintain 16-byte stack alignment Josh Poimboeuf <jpoimboe@redhat.com> - 2017-01-12 15:50 +0100
      Re: x86-64: Maintain 16-byte stack alignment Andy Lutomirski <luto@amacapital.net> - 2017-01-12 09:00 +0100
        Re: x86-64: Maintain 16-byte stack alignment Herbert Xu <herbert@gondor.apana.org.au> - 2017-01-12 09:10 +0100
          Re: x86-64: Maintain 16-byte stack alignment Ingo Molnar <mingo@kernel.org> - 2017-01-12 09:20 +0100
        Re: x86-64: Maintain 16-byte stack alignment Josh Poimboeuf <jpoimboe@redhat.com> - 2017-01-12 16:10 +0100
          Re: x86-64: Maintain 16-byte stack alignment Herbert Xu <herbert@gondor.apana.org.au> - 2017-01-12 16:10 +0100
            Re: x86-64: Maintain 16-byte stack alignment Josh Poimboeuf <jpoimboe@redhat.com> - 2017-01-12 16:20 +0100
          Re: x86-64: Maintain 16-byte stack alignment Josh Poimboeuf <jpoimboe@redhat.com> - 2017-01-12 16:20 +0100

csiph-web