linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Will Deacon <will@kernel.org>
To: Masahiro Yamada <yamada.masahiro@socionext.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	Nick Desaulniers <ndesaulniers@google.com>,
	Nicolas Saenz Julienne <nsaenzjulienne@suse.de>,
	Andrew Morton <akpm@linux-foundation.org>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>,
	linux-arch <linux-arch@vger.kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Russell King <rmk+kernel@arm.linux.org.uk>,
	Stefan Wahren <wahrenst@gmx.net>, Kees Cook <keescook@google.com>
Subject: Re: [PATCH] compiler: enable CONFIG_OPTIMIZE_INLINING forcibly
Date: Mon, 30 Sep 2019 13:18:04 +0100	[thread overview]
Message-ID: <20190930121803.n34i63scet2ec7ll@willie-the-truck> (raw)
In-Reply-To: <CAK7LNASQZ82KSOrQW7+Wq1vFDCg2__maBEAPMLqUDqZMLuj1rA@mail.gmail.com>

On Mon, Sep 30, 2019 at 09:05:11PM +0900, Masahiro Yamada wrote:
> On Mon, Sep 30, 2019 at 8:26 PM Will Deacon <will@kernel.org> wrote:
> > On Fri, Sep 27, 2019 at 03:38:44PM -0700, Linus Torvalds wrote:
> > > Soem of that code is pretty subtle. They have fixed register usage
> > > (but the asm macros actually check them). And the inline asms clobber
> > > the link register, but they do seem to clearly _state_ that they
> > > clobber it, so who knows.
> > >
> > > Just based on the EFAULT, I'd _guess_ that it's some interaction with
> > > the domain access control register (so that get/set_domain() thing).
> > > But I'm not even sure that code is enabled for the Rpi2, so who
> > > knows..
> >
> > FWIW, we've run into issues with CONFIG_OPTIMIZE_INLINING and local
> > variables marked as 'register' where GCC would do crazy things and end
> > up corrupting data, so I suspect the use of fixed registers in the arm
> > uaccess functions is hitting something similar:
> >
> > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91111
> 
> No. Not similar at all.

They're similar in that enabling CONFIG_OPTIMIZE_INLINING causes register
variables to go wrong. I agree that the ARM code looks dodgy with
that call to uaccess_save_and_enable(), but there are __asmeq macros
in there to try to catch that, so it's still very fishy.

> I fixed it already. See
> https://lore.kernel.org/patchwork/patch/1132459/

You fixed the specific case above for 32-bit ARM, but the arm64 case
is due to a compiler bug. As it happens, we've reworked our atomics
in 5.4 so that particular issue no longer triggers, but the fact remains
that GCC has been shown to screw up explicit register allocation for
perfectly legitimate code when giving the flexibility to move code out
of line.

> The problems are fixable by writing correct code.

Right, in the compiler ;)

> I think we discussed this already.

We did?

> - There is nothing arch-specific in CONFIG_OPTIMIZE_INLINING

Apart from the bugs... and even then, that's just based on reports.

> - 'inline' is just a hint. It does not guarantee function inlining.
>   This is standard.
> 
> - The kernel macrofies 'inline' to add __attribute__((__always_inline__))
>   This terrible hack must end.

I'm all for getting rid of hacks, but not at the cost of correctness.

> -  __attribute__((__always_inline__)) takes aways compiler's freedom,
>    and prevents it from optimizing the code for -O2, -Os, or whatever.

s/whatever/miscompiling the code/

If it helps, here is more information about the arm64 failure which
triggered the GCC bugzilla:

https://www.spinics.net/lists/arm-kernel/msg730329.html

Will

  reply	other threads:[~2019-09-30 12:18 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-30  3:43 [PATCH] compiler: enable CONFIG_OPTIMIZE_INLINING forcibly Masahiro Yamada
2019-08-30 20:54 ` Nick Desaulniers
2019-09-26  8:54 ` Geert Uytterhoeven
2019-09-26  9:02   ` Masahiro Yamada
2019-09-26  9:26     ` Geert Uytterhoeven
2019-09-26  9:46       ` Masahiro Yamada
2019-09-27 10:43 ` Nicolas Saenz Julienne
2019-09-27 10:59   ` Charles Keepax
2019-09-27 22:08   ` Nick Desaulniers
2019-09-27 22:38     ` Linus Torvalds
2019-09-30 11:26       ` Will Deacon
2019-09-30 12:05         ` Masahiro Yamada
2019-09-30 12:18           ` Will Deacon [this message]
2019-09-30 21:50             ` Nick Desaulniers
2019-09-30 22:08               ` Miguel Ojeda
2019-09-30 22:34                 ` Nick Desaulniers
2019-10-01  9:28               ` Will Deacon
2019-10-01 16:32                 ` Nick Desaulniers
2019-10-01 17:01                   ` Will Deacon
2019-10-01 17:44                     ` Nick Desaulniers
2019-10-01 17:55                       ` Russell King - ARM Linux admin
2019-10-01 18:00                         ` Nick Desaulniers
2019-10-01 18:14                           ` Russell King - ARM Linux admin
2019-10-01 20:21                             ` Nick Desaulniers
2019-10-01 20:53                               ` Arnd Bergmann
2019-10-01 21:06                                 ` Miguel Ojeda
2019-10-01 21:14                                   ` Nick Desaulniers
2019-10-01 20:59                               ` Russell King - ARM Linux admin
2019-10-01 21:26                                 ` Russell King - ARM Linux admin
2019-10-01 21:32                                   ` Nick Desaulniers
2019-10-01 21:58                                     ` Russell King - ARM Linux admin
2019-10-02 12:55                               ` Geert Uytterhoeven
2019-10-02 18:51                                 ` Will Deacon
2019-10-02 20:39                                 ` Linus Torvalds
2019-10-03  2:10                                   ` Masahiro Yamada
2019-10-03 17:01                                     ` Linus Torvalds
2019-10-03 17:08                                       ` Linus Torvalds
2019-10-03 17:23                                       ` Masahiro Yamada
2019-10-03 17:29                                         ` Linus Torvalds
2019-10-03 20:21                                           ` Miguel Ojeda
2019-10-04  7:37                                             ` Geert Uytterhoeven
2019-10-03 16:36                                   ` Will Deacon
2019-10-12 10:15                                     ` Stefan Wahren
2019-10-12 11:12                                       ` Masahiro Yamada
2019-10-12 14:45                                       ` Russell King - ARM Linux admin
2019-10-01  9:39             ` Masahiro Yamada
2019-10-01 10:40               ` Will Deacon
2019-09-27 10:58 ` Nicolas Saenz Julienne
2019-09-30  6:04   ` Masahiro Yamada

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=20190930121803.n34i63scet2ec7ll@willie-the-truck \
    --to=will@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=bp@alien8.de \
    --cc=catalin.marinas@arm.com \
    --cc=keescook@google.com \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=miguel.ojeda.sandonis@gmail.com \
    --cc=mingo@redhat.com \
    --cc=ndesaulniers@google.com \
    --cc=nsaenzjulienne@suse.de \
    --cc=rmk+kernel@arm.linux.org.uk \
    --cc=torvalds@linux-foundation.org \
    --cc=wahrenst@gmx.net \
    --cc=yamada.masahiro@socionext.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).