From: Mathieu Desnoyers Date: Sun, 13 Sep 2015 15:11:39 +0000 (-0400) Subject: Detect RCU read-side underflows X-Git-Tag: v0.9.0~41 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=343c8b13592134185263cd6e30a615c8c4e35b6d;p=urcu.git Detect RCU read-side underflows Use the urcu_assert() macro (enabled on DEBUG_RCU) to check for unmatched rcu_read_unlock() that leads to nesting counter underflow in urcu.h and urcu-bp.h. Signed-off-by: Mathieu Desnoyers --- diff --git a/urcu/static/urcu-bp.h b/urcu/static/urcu-bp.h index 0fcaa3a..ffd4b89 100644 --- a/urcu/static/urcu-bp.h +++ b/urcu/static/urcu-bp.h @@ -164,11 +164,13 @@ static inline void _rcu_read_lock(void) */ static inline void _rcu_read_unlock(void) { - /* - * Finish using rcu before decrementing the pointer. - */ + unsigned long tmp; + + tmp = URCU_TLS(rcu_reader)->ctr; + urcu_assert(tmp & RCU_GP_CTR_NEST_MASK); + /* Finish using rcu before decrementing the pointer. */ cmm_smp_mb(); - _CMM_STORE_SHARED(URCU_TLS(rcu_reader)->ctr, URCU_TLS(rcu_reader)->ctr - RCU_GP_COUNT); + _CMM_STORE_SHARED(URCU_TLS(rcu_reader)->ctr, tmp - RCU_GP_COUNT); cmm_barrier(); /* Ensure the compiler does not reorder us with mutex */ } diff --git a/urcu/static/urcu.h b/urcu/static/urcu.h index fbba46c..c44c137 100644 --- a/urcu/static/urcu.h +++ b/urcu/static/urcu.h @@ -239,11 +239,11 @@ static inline void _rcu_read_unlock_update_and_wakeup(unsigned long tmp) { if (caa_likely((tmp & RCU_GP_CTR_NEST_MASK) == RCU_GP_COUNT)) { smp_mb_slave(RCU_MB_GROUP); - _CMM_STORE_SHARED(URCU_TLS(rcu_reader).ctr, URCU_TLS(rcu_reader).ctr - RCU_GP_COUNT); + _CMM_STORE_SHARED(URCU_TLS(rcu_reader).ctr, tmp - RCU_GP_COUNT); smp_mb_slave(RCU_MB_GROUP); wake_up_gp(); } else - _CMM_STORE_SHARED(URCU_TLS(rcu_reader).ctr, URCU_TLS(rcu_reader).ctr - RCU_GP_COUNT); + _CMM_STORE_SHARED(URCU_TLS(rcu_reader).ctr, tmp - RCU_GP_COUNT); } /* @@ -257,6 +257,7 @@ static inline void _rcu_read_unlock(void) urcu_assert(URCU_TLS(rcu_reader).registered); tmp = URCU_TLS(rcu_reader).ctr; + urcu_assert(tmp & RCU_GP_CTR_NEST_MASK); _rcu_read_unlock_update_and_wakeup(tmp); cmm_barrier(); /* Ensure the compiler does not reorder us with mutex */ }