linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: hpa@zytor.com
To: Nick Desaulniers <ndesaulniers@google.com>
Cc: Alistair Strachan <astrachan@google.com>,
	Manoj Gupta <manojgupta@google.com>,
	Matthias Kaehlcke <mka@google.com>,
	Greg Hackmann <ghackmann@google.com>,
	sedat.dilek@gmail.com, tstellar@redhat.com,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [clang] stack protector and f1f029c7bf
Date: Thu, 24 May 2018 11:59:36 -0700	[thread overview]
Message-ID: <BDEF22F0-84A5-4A36-B153-13E6A4260922@zytor.com> (raw)
In-Reply-To: <CAKwvOd=jmi_7LvZbS0PA5-zt62m5ZFPUNG7JtMQVmerCR63ebQ@mail.gmail.com>

On May 23, 2018 3:08:19 PM PDT, Nick Desaulniers <ndesaulniers@google.com> wrote:
>H. Peter,
>
>It was reported [0] that compiling the Linux kernel with Clang +
>CC_STACKPROTECTOR_STRONG was causing a crash in native_save_fl(), due
>to
>how GCC does not emit a stack guard for static inline functions (see
>Alistair's excellent report in [1]) but Clang does.
>
>When working with the LLVM release maintainers, Tom had suggested [2]
>changing the inline assembly constraint in native_save_fl() from '=rm'
>to
>'=r', and Alistair had verified the disassembly:
>
>(good) code generated w/o -fstack-protector-strong:
>
>native_save_fl:
>          pushfq
>          popq    -8(%rsp)
>          movq    -8(%rsp), %rax
>          retq
>
>(good) code generated w/ =r input constraint:
>
>native_save_fl:
>          pushfq
>          popq    %rax
>          retq
>
>(bad) code generated with -fstack-protector-strong:
>
>native_save_fl:
>          subq    $24, %rsp
>          movq    %fs:40, %rax
>          movq    %rax, 16(%rsp)
>          pushfq
>          popq    8(%rsp)
>          movq    8(%rsp), %rax
>          movq    %fs:40, %rcx
>          cmpq    16(%rsp), %rcx
>          jne     .LBB0_2
>          addq    $24, %rsp
>          retq
>.LBB0_2:
>          callq   __stack_chk_fail
>
>It looks like the sugguestion is actually a revert of your commit:
>ab94fcf528d127fcb490175512a8910f37e5b346:
>x86: allow "=rm" in native_save_fl()
>
>It seemed like there was a question internally about why worry about
>pop
>adjusting the stack if the stack could be avoided altogether.
>
>I think Sedat can retest this, but I was curious as well about the
>commit
>message in ab94fcf528d: "[ Impact: performance ]", but Alistair's
>analysis
>of the disassembly seems to indicate there is no performance impact (in
>fact, looks better as there's one less mov).
>
>Is there a reason we should not revert ab94fcf528d12, or maybe a better
>approach?
>
>[0] https://lkml.org/lkml/2018/5/7/534
>[1] https://bugs.llvm.org/show_bug.cgi?id=37512#c15
>[2] https://bugs.llvm.org/show_bug.cgi?id=37512#c22

Ok, this is the *second* thing about LLVM-originated bug reports that drives me batty. When you *do* identify a real problem, you propose a paper over and/or talk about it as an LLVM issue and don't consider the often far bigger picture.

Issue 1: Fundamentally, the compiler is doing The Wrong Thing if it generates worse code with a less constrained =rm than with =r. That is a compiler optimization bug, period. The whole point with the less constrained option is to give the compiler the freedom of action.

You are claiming it doesn't buy us anything, but you are only looking at the paravirt case which is kind of "special" (in the short bus kind of way), and only because the compiler in question makes an incredibly stupid decision.

Issue 2: What you are flagging seems to be a far more fundamental problem, which would affect *any* use of push/pop in inline assembly. If that is true, we need to pull in the gcc people too and create an interface to let the compiler know that online assembly needs a certain number of stack slots. We do a lot of push/pop in assembly. The other option is to turn stack canary explicitly off for all such functions.

Issue 3: Let's face it, reading and writing the flags should be builtins, exactly because it has to do stack operations, which really means the compiler should be involved.

-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.

  parent reply	other threads:[~2018-05-24 18:59 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-23 22:08 [clang] stack protector and f1f029c7bf Nick Desaulniers
2018-05-24 10:33 ` Sedat Dilek
2018-05-24 18:12   ` Nick Desaulniers
2018-05-24 18:19 ` hpa
2018-05-24 18:24   ` Nick Desaulniers
2018-05-24 18:48     ` Alistair Strachan
2018-05-24 19:49   ` Tom Stellard
2018-05-24 21:33     ` hpa
2018-05-24 18:59 ` hpa [this message]
2018-05-24 20:26   ` Nick Desaulniers
2018-05-24 20:52     ` Nick Desaulniers
2018-05-24 21:12       ` Nick Desaulniers
2018-05-24 21:27         ` Nick Desaulniers
2018-05-24 21:56           ` H. Peter Anvin
2018-05-24 21:49         ` H. Peter Anvin
2018-05-24 21:38       ` hpa
2018-05-24 22:05     ` H. Peter Anvin
2018-05-24 22:31       ` Nick Desaulniers
2018-05-24 22:43         ` hpa
2018-05-25 16:27           ` Nick Desaulniers
2018-05-25 16:32             ` hpa
2018-05-25 16:46               ` Nick Desaulniers
2018-05-25 16:53                 ` hpa
2018-05-25 17:31                   ` Nick Desaulniers
2018-05-25 17:35                     ` Tom Stellard
2018-05-25 17:49                       ` Nick Desaulniers
2018-05-25 17:57                         ` hpa
2018-05-25 17:59                         ` Nick Desaulniers
2018-05-25 17:56                     ` hpa
2018-05-25 20:36                       ` Nick Desaulniers
2018-05-25 21:06                         ` H. Peter Anvin
2018-05-25 22:38                           ` Nick Desaulniers
2018-05-31  6:50                             ` Nick Desaulniers
2018-06-01 17:13                               ` Nick Desaulniers
2018-05-25 16:34             ` hpa
2018-05-25  8:24     ` Sedat Dilek

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=BDEF22F0-84A5-4A36-B153-13E6A4260922@zytor.com \
    --to=hpa@zytor.com \
    --cc=astrachan@google.com \
    --cc=ghackmann@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=manojgupta@google.com \
    --cc=mka@google.com \
    --cc=ndesaulniers@google.com \
    --cc=sedat.dilek@gmail.com \
    --cc=tstellar@redhat.com \
    /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).