linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Matthias Kaehlcke <mka@chromium.org>
To: hpa@zytor.com
Cc: Ingo Molnar <mingo@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	md@google.com, tglx@linutronix.de, torvalds@linux-foundation.org,
	grundler@chromium.org, linux-kernel@vger.kernel.org,
	ghackmann@google.com, keescook@chromium.org,
	linux-tip-commits@vger.kernel.org
Subject: Re: [tip:x86/urgent] x86/mm/kaslr: Use the _ASM_MUL macro for multiplication to work around Clang incompatibility
Date: Fri, 5 May 2017 14:24:07 -0700	[thread overview]
Message-ID: <20170505212407.GD128305@google.com> (raw)
In-Reply-To: <B4757808-8E1E-4003-99B6-CC1F9F199D9A@zytor.com>

Hi Peter,

El Fri, May 05, 2017 at 12:37:23PM -0700 hpa@zytor.com ha dit:

> On May 5, 2017 11:44:05 AM PDT, Matthias Kaehlcke <mka@chromium.org> wrote:
> >El Fri, May 05, 2017 at 07:50:39PM +0200 Ingo Molnar ha dit:
> >
> >> 
> >> * Peter Zijlstra <peterz@infradead.org> wrote:
> >> 
> >> > On Fri, May 05, 2017 at 01:11:47AM -0700, tip-bot for Matthias
> >Kaehlcke wrote:
> >> > > Commit-ID:  121843eb02a6e2fa30aefab64bfe183c97230c75
> >> > > Gitweb:    
> >http://git.kernel.org/tip/121843eb02a6e2fa30aefab64bfe183c97230c75
> >> > > Author:     Matthias Kaehlcke <mka@chromium.org>
> >> > > AuthorDate: Mon, 1 May 2017 15:47:41 -0700
> >> > > Committer:  Ingo Molnar <mingo@kernel.org>
> >> > > CommitDate: Fri, 5 May 2017 08:31:05 +0200
> >> > > 
> >> > > x86/mm/kaslr: Use the _ASM_MUL macro for multiplication to work
> >around Clang incompatibility
> >> > > 
> >> > > The constraint "rm" allows the compiler to put mix_const into
> >memory.
> >> > > When the input operand is a memory location then MUL needs an
> >operand
> >> > > size suffix, since Clang can't infer the multiplication width
> >from the
> >> > > operand.
> >> > 
> >> > *sigh*, this is another shining example of how LLVM is a better,
> >faster
> >> > moving compiler?
> >> 
> >> Well, I don't like it - but we already have similar patterns to cover
> >some asm 
> >> complications so I didn't mind. Apparently Clang is very close to
> >being able to 
> >> build a working Linux kernel, right?
> >
> >Indeed, I expect 4.12 (with this patch ...) to build with Clang for a
> >x86 defconfig (with tons of warnings). ARM64 is very close.
> >
> >> In that sense it would be unfair to expect it to not have various
> >legacies, 
> >> missing features and quirks - just like the kernel has dozens of GCC
> >related 
> >> workarounds.
> >
> >Also my understanding is that this isn't really a clang issue. In the
> >context of this code gcc apparently chooses to use a register for
> >'mix_const', for memory locations it also needs a suffix.
> >
> >Actually I just tried to build this code from a single C file:
> >
> >void test() {
> >  unsigned long raw, random;
> >  const unsigned long mix_const = 0x3f39e593UL;
> >
> >  asm("MUL %3"
> >    : "=a" (random), "=d" (raw)
> >    : "a" (random), "rm" (mix_const));
> >}
> >
> >gcc -c /tmp/test.c
> >/tmp/test.c: Assembler messages:
> >/tmp/test.c:6: Error: no instruction mnemonic suffix given and no
> >  register operands; can't size instruction
> >
> >gcc version 4.9.x 20150123
> >
> >Cheers
> >
> >Matthias
> 
> Yes, this its a bug regardless of clang or not. It just happens to be hittin by the particular optimization choice is the current versions of gcc makes.
> 
> I asked that that be clear in the commit message, but by the time it was merged it has gotten muddled again.
> 
> However, the clang team also need to accept that they can't do
> arbitrary hacks in the kernel when their compiler is inadequate.

AFAIK there isn't really such a thing as "the clang team" (anymore?),
or at least they don't invite me to their parties :)

Overall I totally agree that we should avoid hacks to support clang.
Short-comings in clang that require ugly or wide-spread hacks should
be fixed in the compiler and out-of-tree patches can be used as
workaround.

However there may be cases where minor innocuous changes are needed
to enable clang (this one could be an example if it was really a
clang issue) and I hope we can be pragmatic in these situations,
especially since these are/seem the last missing bits to support the
other big open source compiler out there.

Cheers

Matthias

      reply	other threads:[~2017-05-05 21:24 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-01 22:47 [PATCH v2] x86/mm/kaslr: Use _ASM_MUL macro for multiplication Matthias Kaehlcke
2017-05-02  2:08 ` Kees Cook
2017-05-05  8:11 ` [tip:x86/urgent] x86/mm/kaslr: Use the _ASM_MUL macro for multiplication to work around Clang incompatibility tip-bot for Matthias Kaehlcke
2017-05-05 10:25   ` Peter Zijlstra
2017-05-05 17:50     ` Ingo Molnar
2017-05-05 18:22       ` Peter Zijlstra
2017-05-05 18:44       ` Matthias Kaehlcke
2017-05-05 19:30         ` Linus Torvalds
2017-05-05 20:36           ` Michael Davidson
2017-05-06  8:16             ` Peter Zijlstra
2017-05-07 15:42               ` hpa
2017-05-05 20:52           ` Matthias Kaehlcke
2017-05-06  9:57             ` Ingo Molnar
2017-05-05 19:37         ` hpa
2017-05-05 21:24           ` Matthias Kaehlcke [this message]

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=20170505212407.GD128305@google.com \
    --to=mka@chromium.org \
    --cc=ghackmann@google.com \
    --cc=grundler@chromium.org \
    --cc=hpa@zytor.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=md@google.com \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.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).