From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
To: Christian Borntraeger <borntraeger@de.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
Davidlohr Bueso <dave@stgolabs.net>,
linux-kernel@vger.kernel.org, mingo@kernel.org,
laijs@cn.fujitsu.com, dipankar@in.ibm.com,
akpm@linux-foundation.org, mathieu.desnoyers@efficios.com,
josh@joshtriplett.org, tglx@linutronix.de, rostedt@goodmis.org,
dhowells@redhat.com, edumazet@google.com, dvhart@linux.intel.com,
fweisbec@gmail.com, oleg@redhat.com,
Pranith Kumar <bobby.prani@gmail.com>,
Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: [PATCH tip/core/rcu 01/14] rcu: Protect rcu_boost() lockless accesses with ACCESS_ONCE()
Date: Tue, 13 Jan 2015 09:47:55 -0800 [thread overview]
Message-ID: <20150113174755.GJ9719@linux.vnet.ibm.com> (raw)
In-Reply-To: <54B4D4E7.2030703@de.ibm.com>
On Tue, Jan 13, 2015 at 09:18:47AM +0100, Christian Borntraeger wrote:
> Am 12.01.2015 um 23:12 schrieb Paul E. McKenney:
> > On Mon, Jan 12, 2015 at 09:59:57AM +0100, Peter Zijlstra wrote:
> >> On Fri, Jan 09, 2015 at 10:58:50PM +0100, Christian Borntraeger wrote:
> >>> Am 09.01.2015 um 14:56 schrieb Peter Zijlstra:
> >>>> On Fri, Jan 09, 2015 at 05:49:54AM -0800, Paul E. McKenney wrote:
> >>>>>> That reminds me, I think the new conversion for stores will most likely
> >>>>>> introduce silly arg bugs:
> >>>>>>
> >>>>>> - ACCESS_ONCE(a) = b;
> >>>>>> + ASSIGN_ONCE(b, a);
> >>>>>
> >>>>> I was planning to do mine by hand for this sort of reason.
> >>>>>
> >>>>> Or are you thinking of something more subtle than the case where
> >>>>> "b" is an unparenthesized comma-separated expression?
> >>>>
> >>>> I think he's revering to the wrong way around-ness of the thing.
> >>>>
> >>>> Its a bit of a mixed bag on assignments, but for instance
> >>>> rcu_assign_pointer() takes them the right way around, as does
> >>>> atomic_set().
> >>>>
> >>>> So yes, I think the ASSIGN_ONCE() thing got the arguments the wrong way
> >>>> around.
> >>>>
> >>>> We could maybe still change it, before its in too long ?
> >>>
> >>> Linus initial proposal was inspired by put_user model which is (val,
> >>> ptr) and I took that.
> >>
> >> Yeah, like I said, its a bit of a mixed bag. We've got plenty examples
> >> of the wrong way around.
> >>
> >>> As my focus was on avoiding the volatile bug,
> >>> all my current conversions are READ_ONCE as no potential ASSIGN_ONCE
> >>> user was done on a non-scalar type, so I have no first hand
> >>> experience.
> >>
> >> So the implication there is that we'd preserve ACCESS_ONCE() for use on
> >> scalar types. I don't think we should do that, I think we should just
> >> en-mass convert to {READ,WRITE}/{LOAD,STORE}_ONCE() and kill off
> >> ACCESS_ONCE().
> >
> > Yep. For one thing, the proposed replacements work much better with
> > C11 than does ACCESS_ONCE().
>
> As we agreed there is no perfect interface regarding val,x vs. x,val.
> But it seems that there is some consensus that I should push something like the following (still whitespace damaged) to Linus for 3.19?
> Peter, Davidlohr, Paul (maybe Linus) can you ACK/NACK?
>
>
> Subject: Change ASSIGN_ONCE(val, x) to WRITE_ONCE(x, val)
>
> Feedback has shown that WRITE_ONCE(x, val) is easier to use than ASSIGN_ONCE(val,x).
> There are no in-tree users yet, so lets change it.
>
> Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
> diff --git a/include/linux/compiler.h b/include/linux/compiler.h
> index 84734a7..38865c7 100644
> --- a/include/linux/compiler.h
> +++ b/include/linux/compiler.h
> @@ -215,7 +215,7 @@ static __always_inline void __read_once_size(volatile void *p, void *res, int si
> }
> }
>
> -static __always_inline void __assign_once_size(volatile void *p, void *res, int size)
> +static __always_inline void __write_once_size(volatile void *p, void *res, int size)
> {
> switch (size) {
> case 1: *(volatile __u8 *)p = *(__u8 *)res; break;
> @@ -235,15 +235,15 @@ static __always_inline void __assign_once_size(volatile void *p, void *res, int
> /*
> * Prevent the compiler from merging or refetching reads or writes. The
> * compiler is also forbidden from reordering successive instances of
> - * READ_ONCE, ASSIGN_ONCE and ACCESS_ONCE (see below), but only when the
> + * READ_ONCE, WRITE_ONCE and ACCESS_ONCE (see below), but only when the
> * compiler is aware of some particular ordering. One way to make the
> * compiler aware of ordering is to put the two invocations of READ_ONCE,
> - * ASSIGN_ONCE or ACCESS_ONCE() in different C statements.
> + * WRITE_ONCE or ACCESS_ONCE() in different C statements.
> *
> * In contrast to ACCESS_ONCE these two macros will also work on aggregate
> * data types like structs or unions. If the size of the accessed data
> * type exceeds the word size of the machine (e.g., 32 bits or 64 bits)
> - * READ_ONCE() and ASSIGN_ONCE() will fall back to memcpy and print a
> + * READ_ONCE() and WRITE_ONCE() will fall back to memcpy and print a
> * compile-time warning.
> *
> * Their two major use cases are: (1) Mediating communication between
> @@ -257,8 +257,8 @@ static __always_inline void __assign_once_size(volatile void *p, void *res, int
> #define READ_ONCE(x) \
> ({ typeof(x) __val; __read_once_size(&x, &__val, sizeof(__val)); __val; })
>
> -#define ASSIGN_ONCE(val, x) \
> - ({ typeof(x) __val; __val = val; __assign_once_size(&x, &__val, sizeof(__val)); __val; })
> +#define WRITE_ONCE(x, val) \
> + ({ typeof(x) __val; __val = val; __write_once_size(&x, &__val, sizeof(__val)); __val; })
>
> #endif /* __KERNEL__ */
>
> @@ -458,7 +458,7 @@ static __always_inline void __assign_once_size(volatile void *p, void *res, int
> * with an explicit memory barrier or atomic instruction that provides the
> * required ordering.
> *
> - * If possible use READ_ONCE/ASSIGN_ONCE instead.
> + * If possible use READ_ONCE/WRITE_ONCE instead.
> */
> #define __ACCESS_ONCE(x) ({ \
> __maybe_unused typeof(x) __var = (typeof(x)) 0;
>
>
>
next prev parent reply other threads:[~2015-01-13 17:48 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-07 17:32 [PATCH tip/core/rcu 0/14] Preemptible-RCU updates for 3.20 Paul E. McKenney
2015-01-07 17:32 ` [PATCH tip/core/rcu 01/14] rcu: Protect rcu_boost() lockless accesses with ACCESS_ONCE() Paul E. McKenney
2015-01-07 17:32 ` [PATCH tip/core/rcu 02/14] rcu: Rename "empty" to "empty_norm" in preparation for boost rework Paul E. McKenney
2015-01-07 17:32 ` [PATCH tip/core/rcu 03/14] rcu: Abstract rcu_cleanup_dead_rnp() from rcu_cleanup_dead_cpu() Paul E. McKenney
2015-01-07 17:32 ` [PATCH tip/core/rcu 04/14] rcu: Make rcu_read_unlock_special() propagate ->qsmaskinit bit clearing Paul E. McKenney
2015-01-07 17:32 ` [PATCH tip/core/rcu 05/14] rcu: Don't migrate blocked tasks even if all corresponding CPUs offline Paul E. McKenney
2015-01-07 17:32 ` [PATCH tip/core/rcu 06/14] rcu: Shorten irq-disable region in rcu_cleanup_dead_cpu() Paul E. McKenney
2015-01-07 17:32 ` [PATCH tip/core/rcu 07/14] rcu: Make use of rcu_preempt_has_tasks() Paul E. McKenney
2015-01-07 17:32 ` [PATCH tip/core/rcu 08/14] rcu: Don't spawn rcub kthreads on root rcu_node structure Paul E. McKenney
2015-01-07 17:32 ` [PATCH tip/core/rcu 09/14] rcu: Don't initiate RCU priority boosting on root rcu_node Paul E. McKenney
2015-01-07 17:32 ` [PATCH tip/core/rcu 10/14] rcu: Don't bother affinitying rcub kthreads away from offline CPUs Paul E. McKenney
2015-01-07 17:32 ` [PATCH tip/core/rcu 11/14] rcu: Note quiescent state when CPU goes offline Paul E. McKenney
2015-01-07 17:32 ` [PATCH tip/core/rcu 12/14] rcu: Revert "Allow post-unlock reference for rt_mutex" to avoid priority-inversion Paul E. McKenney
2015-01-07 17:32 ` [PATCH tip/core/rcu 13/14] rcu: Don't scan root rcu_node structure for stalled tasks Paul E. McKenney
2015-01-07 17:32 ` [PATCH tip/core/rcu 14/14] rcu: Remove redundant callback-list initialization Paul E. McKenney
2015-01-08 9:41 ` [PATCH tip/core/rcu 01/14] rcu: Protect rcu_boost() lockless accesses with ACCESS_ONCE() Peter Zijlstra
2015-01-08 15:22 ` Paul E. McKenney
2015-01-09 6:41 ` Davidlohr Bueso
2015-01-09 13:49 ` Paul E. McKenney
2015-01-09 13:56 ` Peter Zijlstra
2015-01-09 14:07 ` Paul E. McKenney
2015-01-09 16:53 ` Mathieu Desnoyers
2015-01-09 21:58 ` Christian Borntraeger
2015-01-10 0:27 ` Davidlohr Bueso
2015-01-12 8:59 ` Peter Zijlstra
2015-01-12 22:12 ` Paul E. McKenney
2015-01-13 8:18 ` Christian Borntraeger
2015-01-13 9:29 ` Peter Zijlstra
2015-01-13 17:47 ` Paul E. McKenney [this message]
2015-01-13 19:12 ` Davidlohr Bueso
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=20150113174755.GJ9719@linux.vnet.ibm.com \
--to=paulmck@linux.vnet.ibm.com \
--cc=akpm@linux-foundation.org \
--cc=bobby.prani@gmail.com \
--cc=borntraeger@de.ibm.com \
--cc=dave@stgolabs.net \
--cc=dhowells@redhat.com \
--cc=dipankar@in.ibm.com \
--cc=dvhart@linux.intel.com \
--cc=edumazet@google.com \
--cc=fweisbec@gmail.com \
--cc=josh@joshtriplett.org \
--cc=laijs@cn.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=mingo@kernel.org \
--cc=oleg@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.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).