rcu: Limit rcu_state::levelcnt[] to RCU_NUM_LVLS items
authorAlexander Gordeev <agordeev@redhat.com>
Wed, 3 Jun 2015 06:18:27 +0000 (08:18 +0200)
committerPaul E. McKenney <paulmck@linux.vnet.ibm.com>
Wed, 15 Jul 2015 21:45:16 +0000 (14:45 -0700)
Variable rcu_num_lvls is limited by RCU_NUM_LVLS macro.
In turn, rcu_state::levelcnt[] array is never accessed
beyond rcu_num_lvls. Thus, rcu_state::levelcnt[] is safe
to limit to RCU_NUM_LVLS items.

Since rcu_num_lvls could be changed during boot (as result
of rcutree.rcu_fanout_leaf kernel parameter update) one might
assume a new value could overflow the value of RCU_NUM_LVLS.
However, that is not the case, since leaf-level fanout is only
permitted to increase, resulting in rcu_num_lvls possibly to
decrease.

Cc: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Alexander Gordeev <agordeev@redhat.com>
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
kernel/rcu/tree.h

index f1f4784..a6faae5 100644 (file)
@@ -443,7 +443,7 @@ do {                                                                        \
 struct rcu_state {
        struct rcu_node node[NUM_RCU_NODES];    /* Hierarchy. */
        struct rcu_node *level[RCU_NUM_LVLS];   /* Hierarchy levels. */
-       u32 levelcnt[MAX_RCU_LVLS + 1];         /* # nodes in each level. */
+       u32 levelcnt[RCU_NUM_LVLS];             /* # nodes in each level. */
        u8 levelspread[RCU_NUM_LVLS];           /* kids/node in each level. */
        u8 flavor_mask;                         /* bit in flavor mask. */
        struct rcu_data __percpu *rda;          /* pointer of percu rcu_data. */