Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1392233

Re: [PATCH 2/2] target: use RCU_INIT_POINTER() when NULLing.

From "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Newsgroups linux.kernel
Subject Re: [PATCH 2/2] target: use RCU_INIT_POINTER() when NULLing.
Date 2016-05-02 16:20 +0200
Message-ID <rumRA-4OA-17@gated-at.bofh.it> (permalink)
References <rtZ8C-1fy-7@gated-at.bofh.it> <ru32x-4A8-3@gated-at.bofh.it> <ru5H3-6Ma-5@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Sun, May 01, 2016 at 12:53:13PM -0700, Paul E. McKenney wrote:
> On Sun, May 01, 2016 at 10:01:20AM -0700, Christoph Hellwig wrote:
> > On Sun, May 01, 2016 at 06:22:01PM +0530, Muhammad Falak R Wani wrote:
> > > It is safe to use RCU_INIT_POINTER() to NULL, instead of
> > > rcu_assign_pointer().
> > > This results in slightly smaller/faster code.
> > 
> > If this is indeed the case, rcu_assign_pointer should simply check
> > for NULL using __builtin_constant_p and do the right thing transparently
> > instead of burdening it on every user.
> 
> Last time around, there was a compiler bug that prevented this from
> working correctly.  But it could well be time to look at it again.
> How does the following (untested) patch look?

Pretty bad, actually...

People use rcu_assign_pointer() for pointers to functions, which gets
interesting compiler warnings for some configurations.  Please see below
for attempt #2.

							Thanx, Paul

------------------------------------------------------------------------

commit f55c2ffb4e105fa0450fe495788765dffc4b752e
Author: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Date:   Sun May 1 18:46:54 2016 -0700

    rcu: No ordering for rcu_assign_pointer() of NULL
    
    This commit does a compile-time check for rcu_assign_pointer() of NULL,
    and uses WRITE_ONCE() rather than smp_store_release() in that case.
    
    Reported-by: Christoph Hellwig <hch@infradead.org>
    Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>

diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
index c61b6b9506e7..9b8828c5a9c2 100644
--- a/include/linux/rcupdate.h
+++ b/include/linux/rcupdate.h
@@ -650,7 +650,16 @@ static inline void rcu_preempt_sleep_check(void)
  * please be careful when making changes to rcu_assign_pointer() and the
  * other macros that it invokes.
  */
-#define rcu_assign_pointer(p, v) smp_store_release(&p, RCU_INITIALIZER(v))
+#define rcu_assign_pointer(p, v) \
+({ \
+	uintptr_t _r_a_p__v = (uintptr_t)(v); \
+	\
+	if (__builtin_constant_p(v) && (_r_a_p__v) == (uintptr_t)NULL) \
+		WRITE_ONCE((p), (typeof(v))(_r_a_p__v)); \
+	else \
+		smp_store_release(&p, RCU_INITIALIZER((typeof(v))_r_a_p__v)); \
+	_r_a_p__v; \
+})
 
 /**
  * rcu_access_pointer() - fetch RCU pointer with no dereferencing

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 2/2] target: use RCU_INIT_POINTER() when NULLing. Muhammad Falak R Wani <falakreyaz@gmail.com> - 2016-05-01 15:00 +0200
  Re: [PATCH 2/2] target: use RCU_INIT_POINTER() when NULLing. Christoph Hellwig <hch@infradead.org> - 2016-05-01 19:10 +0200
    Re: [PATCH 2/2] target: use RCU_INIT_POINTER() when NULLing. "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2016-05-01 22:00 +0200
      Re: [PATCH 2/2] target: use RCU_INIT_POINTER() when NULLing. "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2016-05-02 16:20 +0200
        Re: [PATCH 2/2] target: use RCU_INIT_POINTER() when NULLing. "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2016-05-02 20:00 +0200
          Re: [PATCH 2/2] target: use RCU_INIT_POINTER() when NULLing. Christoph Hellwig <hch@infradead.org> - 2016-05-02 20:10 +0200
            Re: [PATCH 2/2] target: use RCU_INIT_POINTER() when NULLing. "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2016-05-02 20:10 +0200
              Re: [PATCH 2/2] target: use RCU_INIT_POINTER() when NULLing. Christoph Hellwig <hch@infradead.org> - 2016-05-03 10:50 +0200
                Re: [PATCH 2/2] target: use RCU_INIT_POINTER() when NULLing. "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2016-05-03 15:10 +0200

csiph-web