From: David Laight <David.Laight@ACULAB.COM>
To: 'Josh Poimboeuf' <jpoimboe@redhat.com>,
Linus Torvalds <torvalds@linux-foundation.org>
Cc: Arnd Bergmann <arnd@arndb.de>,
Nick Desaulniers <ndesaulniers@google.com>,
Ilie Halip <ilie.halip@gmail.com>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
clang-built-linux <clang-built-linux@googlegroups.com>,
Peter Zijlstra <peterz@infradead.org>,
"Paul E. McKenney" <paulmck@linux.ibm.com>
Subject: RE: objtool warning "uses BP as a scratch register" with clang-9
Date: Mon, 2 Sep 2019 09:02:08 +0000 [thread overview]
Message-ID: <e3111f698ba342ca8893f65610990624@AcuMS.aculab.com> (raw)
In-Reply-To: <20190830164927.a2czlphx4ho3rhhf@treble>
From: Josh Poimboeuf
> Sent: 30 August 2019 17:49
> On Fri, Aug 30, 2019 at 08:48:49AM -0700, Linus Torvalds wrote:
> > On Fri, Aug 30, 2019 at 8:02 AM Josh Poimboeuf <jpoimboe@redhat.com> wrote:
> > >
> > > For KASAN, the Clang threshold for inserting memset() is *2* consecutive
> > > writes instead of 17. Isn't that likely to cause tearing-related
> > > surprises?
> >
> > Tearing isn't likely to be a problem.
> >
> > It's not like memcpy() does byte-by-byte copies. If you pass it a
> > word-aligned pointer, it will do word-aligned accesses simply for
> > performance reasons.
> >
> > Even on x86, where we use "rep movsb", we (a) tend to disable it for
> > small copies and (b) it turns out that microcode that does the
> > optimized movsb (which is the only case we use it) probably ends up
> > doing atomic things anyway. Note the "probably". I don't have
> > microcode source code, but there are other indications like "we know
> > it doesn't take interrupts on a byte-per-byte level, only on the
> > cacheline level".
>
> The microcode argument is not all that comforting :-)
>
> Also what about unaligned accesses, e.g. if a struct member isn't on a
> word boundary? Arnd's godbolt link showed those can get combined too.
I'd guess that it has to 'complete' a partial copy.
After all there are no mid-instruction interrupt states so the interrupt
returns to a new 'rep movsb' instruction (the isr can change si/di/cx).
Either the source, or destination is almost certainly cache line aligned.
> I don't see x86 memcpy() doing any destination alignment checks.
I don't think anyone has tried to instrument whether it is better to
do misaligned reads or writes (and it probably depends on the cpu).
The code will probably be more critical on the reads.
The real gain will be when the source and destination have the same
mis-alignment.
...
> > So it's probably not an issue from a tearing standpoint - but it
> > worries me because of "this has to be a leaf function" kind of issues
> > where we may be using individual stores on purpose. We do have things
> > like that.
>
> It sounds like everybody's in agreement that replacing accesses with
> memset/memcpy is bad in a kernel context. Should we push for a new
> fine-grained compiler option to disable it?
I'm not sure it is a good idea in ANY context.
It seems like something the compiler people has discovered they can do
without actually deciding whether it is useful.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
next prev parent reply other threads:[~2019-09-02 9:02 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-27 12:30 Arnd Bergmann
2019-08-27 14:51 ` Josh Poimboeuf
2019-08-27 14:59 ` Ilie Halip
2019-08-27 19:00 ` Arnd Bergmann
2019-08-27 19:22 ` Josh Poimboeuf
2019-08-27 19:47 ` Arnd Bergmann
2019-08-27 21:21 ` Nick Desaulniers
2019-08-28 9:00 ` Arnd Bergmann
2019-08-28 14:06 ` Arnd Bergmann
2019-08-28 14:51 ` Josh Poimboeuf
2019-08-28 15:29 ` Arnd Bergmann
2019-08-28 17:57 ` Josh Poimboeuf
2019-08-28 19:41 ` Arnd Bergmann
2019-08-28 15:13 ` Arnd Bergmann
2019-08-28 15:22 ` Josh Poimboeuf
2019-08-28 15:28 ` Arnd Bergmann
2019-08-28 15:40 ` Arnd Bergmann
2019-08-29 23:24 ` Josh Poimboeuf
2019-08-30 10:44 ` Arnd Bergmann
2019-08-30 15:14 ` Josh Poimboeuf
2019-08-30 15:58 ` Arnd Bergmann
2019-08-30 16:12 ` David Laight
2019-08-30 16:03 ` Linus Torvalds
2019-08-29 17:34 ` Josh Poimboeuf
2019-08-29 18:30 ` Linus Torvalds
2019-08-29 20:21 ` Arnd Bergmann
2019-08-29 22:26 ` Linus Torvalds
2019-08-30 15:02 ` Josh Poimboeuf
2019-08-30 15:39 ` David Laight
2019-08-30 15:48 ` Linus Torvalds
2019-08-30 15:55 ` David Laight
2019-08-30 16:01 ` Linus Torvalds
2019-08-30 16:42 ` David Laight
2019-08-30 16:49 ` Josh Poimboeuf
2019-09-02 9:02 ` David Laight [this message]
2019-09-04 11:53 ` Geert Uytterhoeven
2019-08-28 22:13 ` Nick Desaulniers
2019-08-29 0:28 ` Josh Poimboeuf
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=e3111f698ba342ca8893f65610990624@AcuMS.aculab.com \
--to=david.laight@aculab.com \
--cc=arnd@arndb.de \
--cc=clang-built-linux@googlegroups.com \
--cc=ilie.halip@gmail.com \
--cc=jpoimboe@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=ndesaulniers@google.com \
--cc=paulmck@linux.ibm.com \
--cc=peterz@infradead.org \
--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
all inboxes | Powered by JetHome®