lttng-dev.lists.lttng.org archive mirror
 help / color / mirror / Atom feed
From: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
To: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Cc: lttng-dev@lists.lttng.org, linux-kernel@vger.kernel.org,
	rp@svcs.cs.pdx.edu, khlebnikov@openvz.org,
	stern@rowland.harvard.edu, shemminger@vyatta.com
Subject: Re: [lttng-dev] [PATCH] Add ACCESS_ONCE() to avoid compiler splitting assignments
Date: Tue, 15 Jan 2013 18:56:42 -0500	[thread overview]
Message-ID: <20130115235642.GA31367@Krystal> (raw)
In-Reply-To: <20130115181936.GA30319@linux.vnet.ibm.com>

* Paul E. McKenney (paulmck@linux.vnet.ibm.com) wrote:
> As noted by Konstantin Khlebnikov, gcc can split assignment of
> constants to long variables (https://lkml.org/lkml/2013/1/15/141),
> though assignment of NULL (0) is OK.  Assuming that a gcc bug is
> fixed (http://gcc.gnu.org/bugzilla/attachment.cgi?id=29169&action=diff
> has a patch), making the store be volatile keeps gcc from splitting.
> 
> This commit therefore applies ACCESS_ONCE() to CMM_STORE_SHARED(),
> which is the underlying primitive used by rcu_assign_pointer().

Hi Paul,

I recognise that this is an issue in the Linux kernel, since a simple
store is used and expected to be performed atomically when aligned.
However, I think this does not affect liburcu, see below:

> 
> Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
> 
> diff --git a/urcu/system.h b/urcu/system.h
> index 2a45f22..7a1887e 100644
> --- a/urcu/system.h
> +++ b/urcu/system.h
> @@ -49,7 +49,7 @@
>   */
>  #define CMM_STORE_SHARED(x, v)		\
>  	({				\
> -		__typeof__(x) _v = _CMM_STORE_SHARED(x, v);	\
> +		__typeof__(x) CMM_ACCESS_ONCE(_v) = _CMM_STORE_SHARED(x, v);	\

Here, the macro "_CMM_STORE_SHARED(x, v)" is doing the actual store.
It stores v into "x". So adding a CMM_ACCESS_ONCE(_v), as you propose
here, is really only making sure the return value (usually unused),
located on the stack, is accessed with a volatile access, which does not
make much sense.

What really matters is the _CMM_STORE_SHARED() macro:

#define _CMM_STORE_SHARED(x, v) ({ CMM_ACCESS_ONCE(x) = (v); })

which already uses a volatile access for the store. So this seems to be
a case where our preemptive use of volatile for stores in addition to
loads made us bug-free for a gcc behavior unexpected at the time we
implemented this macro. Just a touch of paranoia seems to be a good
thing sometimes. ;-)

Thoughts ?

Thanks,

Mathieu

>  		cmm_smp_wmc();		\
>  		_v;			\
>  	})
> 
> 
> _______________________________________________
> lttng-dev mailing list
> lttng-dev@lists.lttng.org
> http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com

  reply	other threads:[~2013-01-15 23:56 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-15 18:19 [PATCH] Add ACCESS_ONCE() to avoid compiler splitting assignments Paul E. McKenney
2013-01-15 23:56 ` Mathieu Desnoyers [this message]
2013-01-16 12:50   ` [lttng-dev] " Mathieu Desnoyers
2013-01-19 19:17     ` Paul E. McKenney
2013-01-20 20:51       ` Mathieu Desnoyers
2013-01-25 13:53         ` 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=20130115235642.GA31367@Krystal \
    --to=mathieu.desnoyers@efficios.com \
    --cc=khlebnikov@openvz.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lttng-dev@lists.lttng.org \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=rp@svcs.cs.pdx.edu \
    --cc=shemminger@vyatta.com \
    --cc=stern@rowland.harvard.edu \
    /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).