From: "Paul E. McKenney" <paulmck@linux.ibm.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Andi Kleen <ak@linux.intel.com>, Arnd Bergmann <arnd@arndb.de>,
Nicolas Pitre <nico@linaro.org>,
Will Deacon <will.deacon@arm.com>,
linux-kernel@vger.kernel.org,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@kernel.org>,
linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH 0/7] ARM: hacks for link-time optimization
Date: Fri, 21 Dec 2018 06:23:23 -0800 [thread overview]
Message-ID: <20181221142323.GO4170@linux.ibm.com> (raw)
In-Reply-To: <20181218100014.GA16284@hirez.programming.kicks-ass.net>
On Tue, Dec 18, 2018 at 11:00:14AM +0100, Peter Zijlstra wrote:
> On Tue, Dec 18, 2018 at 10:18:24AM +0100, Peter Zijlstra wrote:
> > In particular turning an address-dependency into a control-dependency,
> > which is something allowed by the C language, since it doesn't recognise
> > these concepts as such.
> >
> > The 'optimization' is allowed currently, but LTO will make it much more
> > likely since it will have a much wider view of things. Esp. when combined
> > with PGO.
> >
> > Specifically; if you have something like:
> >
> > int idx;
> > struct object objs[2];
> >
> > the statement:
> >
> > val = objs[idx & 1].ponies;
> >
> > which you 'need' to be translated like:
> >
> > struct object *obj = objs;
> > obj += (idx & 1);
> > val = obj->ponies;
> >
> > Such that the load of obj->ponies depends on the load of idx. However
> > our dear compiler is allowed to make it:
> >
> > if (idx & 1)
> > obj = &objs[1];
> > else
> > obj = &objs[0];
> >
> > val = obj->ponies;
> >
> > Because C doesn't recognise this as being different. However this is
> > utterly broken, because in this translation we can speculate the load
> > of obj->ponies such that it no longer depends on the load of idx, which
> > breaks RCU.
Hence the following in Documentation/RCU/rcu_dereference.txt:
You are only permitted to use rcu_dereference on pointer values.
The compiler simply knows too much about integral values to
trust it to carry dependencies through integer operations.
I got rid of the carrying of dependencies via non-pointers in 2014.
You are telling me that they have crept back? Sigh!!! :-/
Thanx, Paul
> > Note that further 'optimization' is possible and the compiler could even
> > make it:
> >
> > if (idx & 1)
> > val = objs[1].ponies;
> > else
> > val = objs[0].ponies;
>
> A variant that is actually broken on x86 too (due to issuing the loads
> in the 'wrong' order):
>
> val = objs[0].ponies;
> if (idx & 1)
> val = objs[1].ponies;
>
> Which is a translation that makes sense if we either marked
> unlikely(idx & 1) or if PGO found the same.
>
> > Now, granted, this is a fairly artificial example, but it does
> > illustrate the exact problem.
> >
> > The more the compiler can see of the complete program, the more likely
> > it can make inferrences like this, esp. when coupled with PGO.
> >
> > Now, we're (usually) very careful to wrap things in READ_ONCE() and
> > rcu_dereference() and the like, which makes it harder on the compiler
> > (because 'volatile' is special), but nothing really stops it from doing
> > this.
> >
> > Paul has been trying to beat clue into the language people, but given
> > he's been at it for 10 years now, and there's no resolution, I figure we
> > ought to get compiler implementations to give us a knob.
>
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2018-12-21 14:23 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-20 21:59 [PATCH 0/7] ARM: hacks for link-time optimization Arnd Bergmann
2018-02-20 21:59 ` [PATCH 1/7] ARM: disallow combining XIP and LTO Arnd Bergmann
2018-02-21 3:01 ` Nicolas Pitre
2018-02-21 11:50 ` Arnd Bergmann
2018-02-21 15:13 ` Nicolas Pitre
2018-03-12 2:40 ` Nicolas Pitre
2018-03-12 13:52 ` Arnd Bergmann
2018-03-12 16:46 ` Arnd Bergmann
2018-03-12 17:00 ` Nicolas Pitre
2018-03-12 17:05 ` Nicolas Pitre
2018-03-12 17:07 ` Arnd Bergmann
2018-02-20 21:59 ` [PATCH 2/7] ARM: LTO: avoid THUMB2_KERNEL+LTO Arnd Bergmann
2018-02-21 3:12 ` Nicolas Pitre
2018-02-21 11:48 ` Arnd Bergmann
2018-03-07 18:30 ` Matthias Kaehlcke
2018-03-07 18:52 ` Nicolas Pitre
2018-02-20 21:59 ` [PATCH 3/7] [HACK] pass endianess flag to LTO linker Arnd Bergmann
2018-02-21 3:15 ` Nicolas Pitre
2018-02-21 9:44 ` Arnd Bergmann
2018-02-21 8:37 ` Ard Biesheuvel
2018-02-21 9:48 ` Arnd Bergmann
2018-02-21 10:09 ` Ard Biesheuvel
2018-02-21 13:00 ` Arnd Bergmann
2018-02-20 21:59 ` [PATCH 4/7] ARM: io-acorn: fix LTO linking without CONFIG_PRINTK Arnd Bergmann
2018-02-20 21:59 ` [PATCH 5/7] ARM: fix __inflate_kernel_data stack warning for LTO Arnd Bergmann
2018-02-21 3:26 ` Nicolas Pitre
2018-02-20 21:59 ` [PATCH 6/7] ARM: mark assembler-referenced symbols as __visible Arnd Bergmann
2018-02-20 21:59 ` [PATCH 7/7] efi: disable LTO for EFI stub Arnd Bergmann
2018-12-17 22:50 ` [PATCH 0/7] ARM: hacks for link-time optimization Peter Zijlstra
2018-12-18 0:08 ` Andi Kleen
2018-12-18 9:18 ` Peter Zijlstra
2018-12-18 10:00 ` Peter Zijlstra
2018-12-21 14:23 ` Paul E. McKenney [this message]
2018-12-21 17:20 ` Andi Kleen
2018-12-21 18:00 ` Paul E. McKenney
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=20181221142323.GO4170@linux.ibm.com \
--to=paulmck@linux.ibm.com \
--cc=ak@linux.intel.com \
--cc=arnd@arndb.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=nico@linaro.org \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--cc=will.deacon@arm.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).