All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arvind Sankar <nivedita@alum.mit.edu>
To: David Laight <David.Laight@ACULAB.COM>
Cc: 'Arvind Sankar' <nivedita@alum.mit.edu>,
	Nick Desaulniers <ndesaulniers@google.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Kees Cook <keescook@chromium.org>,
	Nathan Chancellor <natechancellor@gmail.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: Clarify comment about the need for barrier_data()
Date: Fri, 16 Oct 2020 09:09:39 -0400	[thread overview]
Message-ID: <20201016130939.GB1040839@rani.riverdale.lan> (raw)
In-Reply-To: <407e91d1d36d48faa8bbdfe4f51033ad@AcuMS.aculab.com>

On Fri, Oct 16, 2020 at 08:13:44AM +0000, David Laight wrote:
> From: Arvind Sankar
> > Sent: 15 October 2020 23:01
> ,,,
> > I think it's helpful to have the more detailed explanation about
> > register variables -- at first glance, it's a bit mystifying as to why
> > the compiler would think that the asm can't access the stack. Spilling
> > registers to the stack is actually an undesirable side-effect of the
> > workaround.
> 
> That is the very bit that just confuses things.
> The data the memzero_explictit() is trying to clear is (probably)
> on-stack already - it won't be in registers.
> 

Are you saying the explanation is confusing things?

What I think is confusing is the fact that the compiler believes that an
asm with a memory clobber cannot access a variable that happens to be in
memory, and the comment is explaining how the compiler came to that
conclusion. The comment is already saying that this applies to LLVM
(unlike GCC) even if the variable isn't actually in registers.

> If it were in registers you wouldn't need the memset().

There's obviously no guarantee of where the compiler decided to keep the
variables. This isn't so clear-cut: for SHA, there is a 256-byte array
that you can be pretty sure will be in memory, but there are also 10 u32
variables which may or may not be in registers depending on how many
registers the arch has and how clever the compiler was in allocating
them.

> 
> Actually I suspect that the memset() is inlined so that is
> just assigns zeros to all the variables.
> This will be done using 'virtual registers' that cache the
> on-stack value.
> You then need to do something to force the instructions to flush
> the 'virtual registers' back to stack to be generated.

This is definitely getting too much into the weeds. What the compiler
knows is that memset does nothing other than writing to the variable,
and if the variable is never used after that, then the memset can be
eliminated.  Whether the memset ends up getting inlined or not is not
relevant here: clang doesn't inline it, for eg.

  reply	other threads:[~2020-10-16 13:10 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-14 21:26 [PATCH] compiler.h: Fix barrier_data() on clang 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
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 [this message]
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:47   ` Andreas Schwab
2020-11-16 17:53   ` Randy Dunlap
2020-11-16 17:53     ` Randy Dunlap
2020-11-16 18:30     ` Andreas Schwab
2020-11-16 18:30       ` Andreas Schwab
2020-11-16 19:28       ` Randy Dunlap
2020-11-16 19:28         ` Randy Dunlap
2020-11-16 22:19         ` Randy Dunlap
2020-11-16 22:19           ` Randy Dunlap
2020-11-16 19:31   ` Nick Desaulniers
2020-11-16 19:31     ` Nick Desaulniers
2020-11-16 21:07     ` Andreas Schwab
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=20201016130939.GB1040839@rani.riverdale.lan \
    --to=nivedita@alum.mit.edu \
    --cc=David.Laight@ACULAB.COM \
    --cc=akpm@linux-foundation.org \
    --cc=clang-built-linux@googlegroups.com \
    --cc=keescook@chromium.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.