LKML Archive on
help / color / mirror / Atom feed
From: Andrea Parri <>
Cc: Andrea Parri <>,
	"Paul E. McKenney" <>,
	Josh Triplett <>,
	Steven Rostedt <>,
	Mathieu Desnoyers <>,
	Lai Jiangshan <>,
	Joel Fernandes <>,, Peter Zijlstra <>,
	Will Deacon <>,
	Mark Rutland <>
Subject: [RFC PATCH] rcu: Make 'rcu_assign_pointer(p, v)' of type 'typeof(p)'
Date: Thu, 23 May 2019 15:32:20 +0200	[thread overview]
Message-ID: <> (raw)

The expression

  rcu_assign_pointer(p, typeof(p) v)

is reported to be of type 'typeof(p)' in the documentation (c.f., e.g.,
Documentation/RCU/whatisRCU.txt) but this is not the case: for example,
the following snippet

  int **y;
  int *x;
  int *r0;


  r0 = rcu_assign_pointer(*y, x);

can currently result in the compiler warning

  warning: assignment to ‘int *’ from ‘uintptr_t’ {aka ‘long unsigned int’} makes pointer from integer without a cast [-Wint-conversion]

Cast the uintptr_t value to a typeof(p) value.

Signed-off-by: Andrea Parri <>
Cc: "Paul E. McKenney" <>
Cc: Josh Triplett <>
Cc: Steven Rostedt <>
Cc: Mathieu Desnoyers <>
Cc: Lai Jiangshan <>
Cc: Joel Fernandes <>
Cc: Peter Zijlstra <>
Cc: Will Deacon <>
Cc: Mark Rutland <>

TBH, I'm not sure this is 'the right patch' (hence the RFC...): in
fact, I'm currently missing the motivations for allowing assignments
such as the "r0 = ..." assignment above in generic code.  (BTW, it's
not currently possible to use such assignments in litmus tests...)

The usual concern is, of course, that if something is allowed (read
'compile!' ;/) then people will soon or later use it and they'll do
it in all sorts of 'creative' ways, such as 'to extend dependencies
across rcu_assign_pointer() calls' as in

  x = READ_ONCE(*z);
  r0 = rcu_assign_pointer(*y, x);
  WRITE_ONCE(*w, r0);

Notice that using a 'do { ... } while (0)', say, would prevent such
tricks/rvalues. (The same approach is used by smp_store_release().)

For a related discussion, please see:


 include/linux/rcupdate.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
index 915460ec08722..b94ba5de78fba 100644
--- a/include/linux/rcupdate.h
+++ b/include/linux/rcupdate.h
@@ -375,7 +375,7 @@ static inline void rcu_preempt_sleep_check(void) { }
 		WRITE_ONCE((p), (typeof(p))(_r_a_p__v));		      \
 	else								      \
 		smp_store_release(&p, RCU_INITIALIZER((typeof(p))_r_a_p__v)); \
-	_r_a_p__v;							      \
+	((typeof(p))_r_a_p__v);						      \

             reply	other threads:[~2019-05-23 13:32 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-23 13:32 Andrea Parri [this message]
2019-05-23 13:50 ` Paul E. McKenney
2019-05-23 14:19   ` Mark Rutland
2019-05-23 14:54     ` Andrea Parri
2019-05-23 15:23     ` Paul E. McKenney
2019-05-23 14:53   ` Andrea Parri

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:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \ \ \ \ \ \ \ \ \ \
    --subject='Re: [RFC PATCH] rcu: Make '\''rcu_assign_pointer(p, v)'\'' of type '\''typeof(p)'\''' \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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).