Skip to contentSkip to conversation

rcu: off by one in gp_state_getname()

PATCH In review Dan Carpenter 2 participants 4 messages Nov 19, 2015 – Nov 20, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rcu: off by one in gp_state_getname()

It should be >= ARRAY_SIZE() instead of > ARRAY_SIZE().

Fixes 6231da675578 ('rcu: Print symbolic name for ->gp_state')
kernel/rcu/tree.c +1 -1
index 6a5e1c4..6559b3c 100644
@@ -1203,7 +1203,7 @@ static void record_gp_stall_check_time(struct rcu_state *rsp)
  */
 static char *gp_state_getname(short gs)
 {
-	if (gs < 0 || gs > ARRAY_SIZE(gp_state_names))
+	if (gs < 0 || gs >= ARRAY_SIZE(gp_state_names))
 		return "???";
 	return gp_state_names[gs];
 }
#1 lore raw
Quoted 4 lines · Dan Carpenter

It should be >= ARRAY_SIZE() instead of > ARRAY_SIZE().

Fixes 6231da675578 ('rcu: Print symbolic name for ->gp_state')

Good catch! I folded this into the original commit with attribution, please see below.

Thanx, Paul

kernel/rcu/tree.c static void record_gp_stall_check_time(struct rcu_state *rsp) · line 1209

Quoted 13 lines
kernel/rcu/tree.c +1 -1
index 6a5e1c4..6559b3c 100644
@@ -1203,7 +1203,7 @@ static void record_gp_stall_check_time(struct rcu_state *rsp)
  */
 static char *gp_state_getname(short gs)
 {
-	if (gs < 0 || gs > ARRAY_SIZE(gp_state_names))
+	if (gs < 0 || gs >= ARRAY_SIZE(gp_state_names))
 		return "???";
 	return gp_state_names[gs];
 }

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

commit 31bf937d2dcbe71a329e5bc6c7726f3a5949089a

Author: Paul E. McKenney <[email protected]>
Date:   Tue Nov 17 14:39:26 2015 -0800

rcu: Print symbolic name for ->gp_state

Currently, ->gp_state is printed as an integer, which slows debugging. This commit therefore prints a symbolic name in addition to the integer.

[ Updated to fix relational operator called out by Daniel Carpenter. ]
kernel/rcu/tree.c +13 -2
index e768fc64583f..6559b3cb5ea6 100644
@@ -1199,6 +1199,16 @@ static void record_gp_stall_check_time(struct rcu_state *rsp)
 }
 
 /*
+ * Convert a ->gp_state value to a character string.
+ */
+static char *gp_state_getname(short gs)
+{
+	if (gs < 0 || gs >= ARRAY_SIZE(gp_state_names))
+		return "???";
+	return gp_state_names[gs];
+}
+
+/*
  * Complain about starvation of grace-period kthread.
  */
 static void rcu_check_gp_kthread_starvation(struct rcu_state *rsp)
@@ -1209,10 +1219,11 @@ static void rcu_check_gp_kthread_starvation(struct rcu_state *rsp)
 	j = jiffies;
 	gpa = READ_ONCE(rsp->gp_activity);
 	if (j - gpa > 2 * HZ) {
-		pr_err("%s kthread starved for %ld jiffies! g%lu c%lu f%#x s%d ->state=%#lx\n",
+		pr_err("%s kthread starved for %ld jiffies! g%lu c%lu f%#x %s(%d) ->state=%#lx\n",
 		       rsp->name, j - gpa,
 		       rsp->gpnum, rsp->completed,
-		       rsp->gp_flags, rsp->gp_state,
+		       rsp->gp_flags,
+		       gp_state_getname(rsp->gp_state), rsp->gp_state,
 		       rsp->gp_kthread ? rsp->gp_kthread->state : ~0);
 		if (rsp->gp_kthread)
 			sched_show_task(rsp->gp_kthread);
kernel/rcu/tree.h +9 -0
index 6cbec31f99d6..5c70b09a85d4 100644
@@ -546,6 +546,15 @@ struct rcu_state {
 #define RCU_GP_DOING_FQS 4	/* Wait done for force-quiescent-state time. */
 #define RCU_GP_CLEANUP   5	/* Grace-period cleanup started. */
 #define RCU_GP_CLEANED   6	/* Grace-period cleanup complete. */
+static char * const gp_state_names[] = {
+	"RCU_GP_IDLE",
+	"RCU_GP_WAIT_GPS",
+	"RCU_GP_DONE_GPS",
+	"RCU_GP_WAIT_FQS",
+	"RCU_GP_DOING_FQS",
+	"RCU_GP_CLEANUP",
+	"RCU_GP_CLEANED",
+};
 
 extern struct list_head rcu_struct_flavors;
 
#2 lore raw

Heh. It's just "Dan" though, it's not short for anything.

regards,
dan carpenter

#3 lore raw
Quoted 1 line · Dan Carpenter

Heh. It's just "Dan" though, it's not short for anything.

Apologies, fixed!

Thanx, Paul