From: Arvind Sankar <nivedita@alum.mit.edu>
To: David Laight <David.Laight@ACULAB.COM>
Cc: 'Arvind Sankar' <nivedita@alum.mit.edu>,
Nathan Chancellor <natechancellor@gmail.com>,
Nick Desaulniers <ndesaulniers@google.com>,
"clang-built-linux@googlegroups.com"
<clang-built-linux@googlegroups.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] compiler.h: Fix barrier_data() on clang
Date: Thu, 15 Oct 2020 11:39:01 -0400 [thread overview]
Message-ID: <20201015153901.GA593731@rani.riverdale.lan> (raw)
In-Reply-To: <4a8c47b5eeb44b789abbb617f0a95993@AcuMS.aculab.com>
On Thu, Oct 15, 2020 at 03:24:09PM +0000, David Laight wrote:
> > I think the comment is unclear now that you bring it up, but the problem
> > it actually addresses is not that the data is held in registers: in the
> > sha256_transform() case mentioned in the commit message, for example,
> > the data is in fact in memory even before this change (it's a 256-byte
> > array), and that together with the memory clobber is enough for gcc to
> > assume that the asm might use it. But with clang, if the address of that
> > data has never escaped -- in this case the data is a local variable
> > whose address was never passed out of the function -- the compiler
> > assumes that the asm cannot possibly depend on that memory, because it
> > has no way of getting its address.
>
> Ok, slightly different from what i thought.
> But the current comment is just wrong.
Should I fix up the comment in the same commit, or do a second one after
moving the macro?
> > i.e. something like:
> > static inline void barrier_data(void *ptr, size_t size)
> > {
> > asm volatile("" : "+m"(*(char (*)[size])ptr));
>
> I think it has to be a struct with an array member?
I don't think so, this is actually an example in gcc's documentation:
An x86 example where the string memory argument is of unknown length.
asm("repne scasb"
: "=c" (count), "+D" (p)
: "m" (*(const char (*)[]) p), "0" (-1), "a" (0));
If you know the above will only be reading a ten byte array then you
could instead use a memory input like: "m" (*(const char (*)[10]) p).
>
> > }
> > plus some magic to disable the VLA warning, otherwise it causes a build
> > error.
>
> It shouldn't if the size is a compile time constant.
> And given this is an instruction to the compiler it better be.
Ah right. I saw the warning when playing with something else where size
could be constant or variable depending on the call.
> >
> > With a memory clobber, the compiler has to keep x and y at different
> > addresses, since the first barrier_data() might have saved the address
> > of x.
>
> Maybe "+m"(*ptr) : "r"(ptr) would work.
Nothing that can only modify what ptr points to could avoid this, since
that storage is dead after the barrier.
> OTOH a "memory" clobber at the bottom of a function isn't going to
> cause bloat.
>
> The explicit ranged memory access (without "memory") probably has its
> uses - but only if the full "memory" clobber causes grief.
>
> David
>
> -
> Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
> Registration No: 1397386 (Wales)
next prev parent reply other threads:[~2020-10-15 15:39 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-14 21:26 Arvind Sankar
2020-10-14 22:51 ` Nick Desaulniers
2020-10-15 8:50 ` David Laight
2020-10-15 14:45 ` Arvind Sankar
2020-10-15 15:24 ` David Laight
2020-10-15 15:39 ` Arvind Sankar [this message]
2020-10-15 17:39 ` Nick Desaulniers
2020-10-15 18:13 ` [PATCH] compiler.h: Clarify comment about the need for barrier_data() Arvind Sankar
2020-10-15 18:25 ` Nick Desaulniers
2020-10-15 21:09 ` David Laight
2020-10-15 22:01 ` Arvind Sankar
2020-10-16 8:13 ` David Laight
2020-10-16 13:09 ` Arvind Sankar
2020-10-21 19:46 ` [PATCH] compiler.h: Fix barrier_data() on clang Kees Cook
2020-11-16 17:47 ` Andreas Schwab
2020-11-16 17:53 ` Randy Dunlap
2020-11-16 18:30 ` Andreas Schwab
2020-11-16 19:28 ` Randy Dunlap
2020-11-16 22:19 ` Randy Dunlap
2020-11-16 19:31 ` Nick Desaulniers
2020-11-16 21:07 ` Andreas Schwab
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=20201015153901.GA593731@rani.riverdale.lan \
--to=nivedita@alum.mit.edu \
--cc=David.Laight@ACULAB.COM \
--cc=clang-built-linux@googlegroups.com \
--cc=linux-kernel@vger.kernel.org \
--cc=natechancellor@gmail.com \
--cc=ndesaulniers@google.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
all inboxes | Powered by JetHome®