Detect RCU read-side underflows
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sun, 13 Sep 2015 15:11:39 +0000 (11:11 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sun, 13 Sep 2015 15:14:45 +0000 (11:14 -0400)
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 <mathieu.desnoyers@efficios.com>
urcu/static/urcu-bp.h
urcu/static/urcu.h

index 0fcaa3aa272806aa9c8786c96b7675de4fcfddd3..ffd4b8959b61e49c092fa7d72a3053d5223ab500 100644 (file)
@@ -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 */
 }
 
index fbba46cde9afdc6bff0c4b337a22afc78d40fea7..c44c137278301a9b02e5b0c13693968c95e75d03 100644 (file)
@@ -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 */
 }
This page took 0.034159 seconds and 4 git commands to generate.