Skip to contentSkip to conversation

Early boot self tests for RCU

RFC PATCH In review Pranith Kumar 2 participants 8 messages Sep 18, 2014 – Sep 19, 2014

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

cover Early boot self tests for RCU

Hi Paul,

Please find the following patches which enable RCU early boot tests. For now all we do in these tests are enqueue test callbacks and check if they are being invoked or not.

I was able to reproduce the hang which Amit reported after reverting the fix. So this should catch such errors if they occur in the future.

I enabled the selftests in a few rcutorture configurations.

Thanks!
--
Pranith

Pranith Kumar (3):
rcu: Add early boot self tests
doc: Document RCU self test boot params
rcutorture: Enable RCU self test in configs

 Documentation/kernel-parameters.txt                | 12 +++
 kernel/rcu/rcu.h                                   |  2 +
 kernel/rcu/tiny.c                                  |  4 +-
 kernel/rcu/tree.c                                  |  2 +
 kernel/rcu/update.c                                | 91 ++++++++++++++++++++++
 .../selftests/rcutorture/configs/rcu/TINY02        |  2 +
 .../selftests/rcutorture/configs/rcu/TINY02.boot   |  2 +
 .../selftests/rcutorture/configs/rcu/TREE05.boot   |  1 +
 .../selftests/rcutorture/configs/rcu/TREE06.boot   |  4 +
 .../selftests/rcutorture/configs/rcu/TREE08        |  2 +
 .../selftests/rcutorture/configs/rcu/TREE08.boot   |  2 +
 11 files changed, 123 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/rcutorture/configs/rcu/TINY02.boot
 create mode 100644 tools/testing/selftests/rcutorture/configs/rcu/TREE06.boot
Signature · 1 line
2.1.0
#1 lore raw

cover Early boot self tests for RCU

Hi Paul,

Please find the following patches which enable RCU early boot tests. For now all we do in these tests are enqueue test callbacks and check if they are being invoked or not.

I was able to reproduce the hang which Amit reported after reverting the fix. So this should catch such errors if they occur in the future.

I enabled the selftests in a few rcutorture configurations.

Thanks!
--
Pranith

Pranith Kumar (3):
rcu: Add early boot self tests
doc: Document RCU self test boot params
rcutorture: Enable RCU self test in configs

 Documentation/kernel-parameters.txt                | 12 +++
 kernel/rcu/rcu.h                                   |  2 +
 kernel/rcu/tiny.c                                  |  4 +-
 kernel/rcu/tree.c                                  |  2 +
 kernel/rcu/update.c                                | 91 ++++++++++++++++++++++
 .../selftests/rcutorture/configs/rcu/TINY02        |  2 +
 .../selftests/rcutorture/configs/rcu/TINY02.boot   |  2 +
 .../selftests/rcutorture/configs/rcu/TREE05.boot   |  1 +
 .../selftests/rcutorture/configs/rcu/TREE06.boot   |  4 +
 .../selftests/rcutorture/configs/rcu/TREE08        |  2 +
 .../selftests/rcutorture/configs/rcu/TREE08.boot   |  2 +
 11 files changed, 123 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/rcutorture/configs/rcu/TINY02.boot
 create mode 100644 tools/testing/selftests/rcutorture/configs/rcu/TREE06.boot
Signature · 1 line
2.1.0
#2 lore raw

RFC PATCH 1/3 rcu: Add early boot self tests

In reply to Pranith Kumar

Add early boot self tests for RCU under CONFIG_PROVE_RCU.

Currently the only test is adding a dummy callback which increments a counter which we then later verify after calling rcu_barrier*().

---
 kernel/rcu/rcu.h    |  2 ++
 kernel/rcu/tiny.c   |  4 ++-
 kernel/rcu/tree.c   |  2 ++
 kernel/rcu/update.c | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 98 insertions(+), 1 deletion(-)
kernel/rcu/rcu.h +2 -0
index ff1a6de..07bb02e 100644
@@ -135,4 +135,6 @@ int rcu_jiffies_till_stall_check(void);
  */
 #define TPS(x)  tracepoint_string(x)
 
+void rcu_early_boot_tests(void);
+
 #endif /* __LINUX_RCU_H */
kernel/rcu/tiny.c +3 -1
index c0623fc..d3d44c5 100644
@@ -380,7 +380,9 @@ void call_rcu_bh(struct rcu_head *head, void (*func)(struct rcu_head *rcu))
 }
 EXPORT_SYMBOL_GPL(call_rcu_bh);
 
-void rcu_init(void)
+void __init rcu_init(void)
 {
 	open_softirq(RCU_SOFTIRQ, rcu_process_callbacks);
+
+	rcu_early_boot_tests();
 }
kernel/rcu/tree.c +2 -0
index e4c6d60..f93a62c 100644
@@ -3766,6 +3766,8 @@ void __init rcu_init(void)
 	pm_notifier(rcu_pm_notify, 0);
 	for_each_online_cpu(cpu)
 		rcu_cpu_notify(NULL, CPU_UP_PREPARE, (void *)(long)cpu);
+
+	rcu_early_boot_tests();
 }
 
 #include "tree_plugin.h"
kernel/rcu/update.c +91 -0

94 lines not on this page · raw message

Signature · 1 line
2.1.0
#3 lore raw

Re: [RFC PATCH 1/3] rcu: Add early boot self tests

Quoted 6 lines · Pranith Kumar

Add early boot self tests for RCU under CONFIG_PROVE_RCU.

Currently the only test is adding a dummy callback which increments a counter which we then later verify after calling rcu_barrier*().

Great addition to RCU self-testing!

A couple of comments below.

Quoted 62 lines
---
 kernel/rcu/rcu.h    |  2 ++
 kernel/rcu/tiny.c   |  4 ++-
 kernel/rcu/tree.c   |  2 ++
 kernel/rcu/update.c | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 98 insertions(+), 1 deletion(-)
kernel/rcu/rcu.h +2 -0
index ff1a6de..07bb02e 100644
@@ -135,4 +135,6 @@ int rcu_jiffies_till_stall_check(void);
  */
 #define TPS(x)  tracepoint_string(x)
 
+void rcu_early_boot_tests(void);
+
 #endif /* __LINUX_RCU_H */
kernel/rcu/tiny.c +3 -1
index c0623fc..d3d44c5 100644
@@ -380,7 +380,9 @@ void call_rcu_bh(struct rcu_head *head, void (*func)(struct rcu_head *rcu))
 }
 EXPORT_SYMBOL_GPL(call_rcu_bh);
 
-void rcu_init(void)
+void __init rcu_init(void)
 {
 	open_softirq(RCU_SOFTIRQ, rcu_process_callbacks);
+
+	rcu_early_boot_tests();
 }
kernel/rcu/tree.c +2 -0
index e4c6d60..f93a62c 100644
@@ -3766,6 +3766,8 @@ void __init rcu_init(void)
 	pm_notifier(rcu_pm_notify, 0);
 	for_each_online_cpu(cpu)
 		rcu_cpu_notify(NULL, CPU_UP_PREPARE, (void *)(long)cpu);
+
+	rcu_early_boot_tests();
 }
 
 #include "tree_plugin.h"
kernel/rcu/update.c +8 -0
index 3ef8ba5..5929f0c 100644
@@ -690,3 +690,94 @@ static void rcu_spawn_tasks_kthread(void)
 }
 
 #endif /* #ifdef CONFIG_TASKS_RCU */
+
+#ifdef CONFIG_PROVE_RCU
+
+/*
+ * Early boot self test parameters, one for each flavor
+ */
+static bool rcu_self_test;
+static bool rcu_self_test_bh;

kernel/rcu/update.c static void rcu_spawn_tasks_kthread(void) · line 710

Quoted 10 lines
kernel/rcu/update.c +10 -0
+static bool rcu_self_test_sched;
+static bool rcu_self_test_srcu;
+
+module_param(rcu_self_test, bool, 0444);
+module_param(rcu_self_test_bh, bool, 0444);
+module_param(rcu_self_test_sched, bool, 0444);
+module_param(rcu_self_test_srcu, bool, 0444);
+
+static int rcu_self_test_counter;
+static struct rcu_head head;

This needs to be within the individual functions, because otherwise the lists get messed up when you to multiple tests during the same boot...

kernel/rcu/update.c static void rcu_spawn_tasks_kthread(void) · line 720

Quoted 10 lines
kernel/rcu/update.c +10 -0
+DEFINE_STATIC_SRCU(srcu_struct);
+
+static void test_callback(struct rcu_head *r)
+{
+	rcu_self_test_counter++;
+	pr_info("RCU test callback executed %d\n", rcu_self_test_counter);
+}
+
+static void early_boot_test_call_rcu(void)
+{

... as in:

	static struct rcu_head head;
Quoted 6 lines
kernel/rcu/update.c +6 -0
+	call_rcu(&head, test_callback);
+}
+
+static void early_boot_test_call_rcu_bh(void)
+{
+	call_rcu_bh(&head, test_callback);

kernel/rcu/update.c static void rcu_spawn_tasks_kthread(void) · line 736

Quoted 10 lines
kernel/rcu/update.c +10 -0
+}
+
+static void early_boot_test_call_rcu_sched(void)
+{
+	call_rcu_sched(&head, test_callback);
+}
+
+static void early_boot_test_call_srcu(void)
+{
+	call_srcu(&srcu_struct, &head, test_callback);

This looked like a great idea at first, but unfortunately call_srcu() invokes queue_delayed_work(), which breaks horribly this early in boot. Either this test has to be removed, or call_srcu() has to be updated to handle early-boot invocation. Given that no one is using call_srcu() during early boot, it is probably best to just drop the test.

(In case you were wondering, TEST06 dies during boot.)

Could you please send an updated patch?

Quoted 55 lines
kernel/rcu/update.c +47 -0
+}
+
+void rcu_early_boot_tests(void)
+{
+	pr_info("Running RCU self tests\n");
+
+	if (rcu_self_test)
+		early_boot_test_call_rcu();
+	if (rcu_self_test_bh)
+		early_boot_test_call_rcu_bh();
+	if (rcu_self_test_sched)
+		early_boot_test_call_rcu_sched();
+	if (rcu_self_test_srcu)
+		early_boot_test_call_srcu();
+}
+
+static int rcu_verify_early_boot_tests(void)
+{
+	int ret = 0;
+	int early_boot_test_counter = 0;
+
+	if (rcu_self_test) {
+		early_boot_test_counter++;
+		rcu_barrier();
+	}
+	if (rcu_self_test_bh) {
+		early_boot_test_counter++;
+		rcu_barrier_bh();
+	}
+	if (rcu_self_test_sched) {
+		early_boot_test_counter++;
+		rcu_barrier_sched();
+	}
+	if (rcu_self_test_srcu) {
+		early_boot_test_counter++;
+		srcu_barrier(&srcu_struct);
+	}
+
+	if (rcu_self_test_counter != early_boot_test_counter)
+		ret = -1;
+
+	return ret;
+}
+late_initcall(rcu_verify_early_boot_tests);
+#else
+void rcu_early_boot_tests(void) {}
+#endif /* CONFIG_PROVE_RCU */
Signature · 7 lines
2.1.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
#4 lore raw

Re: [RFC PATCH 1/3] rcu: Add early boot self tests

Quoted 6 lines · Paul E. McKenney

kernel/rcu/update.c static void rcu_spawn_tasks_kthread(void) · line 710

Quoted 2 lines
kernel/rcu/update.c +2 -0
+static int rcu_self_test_counter;
+static struct rcu_head head;

This needs to be within the individual functions, because otherwise the lists get messed up when you to multiple tests during the same boot...

Hmm, I thought this was OK since we are not using this head anywhere. What lists are getting messed up?

In any case, I will update this as you suggested.

Quoted 38 lines

kernel/rcu/update.c static void rcu_spawn_tasks_kthread(void) · line 720

Quoted 10 lines
kernel/rcu/update.c +10 -0
+DEFINE_STATIC_SRCU(srcu_struct);
+
+static void test_callback(struct rcu_head *r)
+{
+     rcu_self_test_counter++;
+     pr_info("RCU test callback executed %d\n", rcu_self_test_counter);
+}
+
+static void early_boot_test_call_rcu(void)
+{

... as in:

        static struct rcu_head head;
Quoted 6 lines
kernel/rcu/update.c +6 -0
+     call_rcu(&head, test_callback);
+}
+
+static void early_boot_test_call_rcu_bh(void)
+{
+     call_rcu_bh(&head, test_callback);

kernel/rcu/update.c static void rcu_spawn_tasks_kthread(void) · line 736

Quoted 10 lines
kernel/rcu/update.c +10 -0
+}
+
+static void early_boot_test_call_rcu_sched(void)
+{
+     call_rcu_sched(&head, test_callback);
+}
+
+static void early_boot_test_call_srcu(void)
+{
+     call_srcu(&srcu_struct, &head, test_callback);

This looked like a great idea at first, but unfortunately call_srcu() invokes queue_delayed_work(), which breaks horribly this early in boot. Either this test has to be removed, or call_srcu() has to be updated to handle early-boot invocation. Given that no one is using call_srcu() during early boot, it is probably best to just drop the test.

Quoted 3 lines

(In case you were wondering, TEST06 dies during boot.)

Could you please send an updated patch?

Yup, will do. Please see one question below:

<...>

Quoted 16 lines
Quoted 16 lines
kernel/rcu/update.c +16 -0
+static int rcu_verify_early_boot_tests(void)
+{
+     int ret = 0;
+     int early_boot_test_counter = 0;
+
+     if (rcu_self_test) {
+             early_boot_test_counter++;
+             rcu_barrier();
+     }
+     if (rcu_self_test_bh) {
+             early_boot_test_counter++;
+             rcu_barrier_bh();
+     }
+     if (rcu_self_test_sched) {
+             early_boot_test_counter++;
+             rcu_barrier_sched();
Quoted 8 lines

kernel/rcu/update.c static void rcu_spawn_tasks_kthread(void) · line 776

Quoted 8 lines
kernel/rcu/update.c +8 -0
+     }
+     if (rcu_self_test_srcu) {
+             early_boot_test_counter++;
+             srcu_barrier(&srcu_struct);
+     }
+
+     if (rcu_self_test_counter != early_boot_test_counter)
+             ret = -1;

So this basically does nothing when it does not match. All we see is the return value when we pass initcall_debug. Should I add a WARN_ON() or some such so that it is more explicit?

Quoted 16 lines
Quoted 15 lines
kernel/rcu/update.c +7 -1
+
+     return ret;
+}
+late_initcall(rcu_verify_early_boot_tests);
+#else
+void rcu_early_boot_tests(void) {}
+#endif /* CONFIG_PROVE_RCU */
--

2.1.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Signature · 1 line
Pranith
#5 lore raw

Re: [RFC PATCH 1/3] rcu: Add early boot self tests

Quoted 11 lines · Pranith Kumar
Quoted 5 lines · Paul E. McKenney

kernel/rcu/update.c static void rcu_spawn_tasks_kthread(void) · line 710

Quoted 2 lines
kernel/rcu/update.c +2 -0
+static int rcu_self_test_counter;
+static struct rcu_head head;

This needs to be within the individual functions, because otherwise the lists get messed up when you to multiple tests during the same boot...

Hmm, I thought this was OK since we are not using this head anywhere. What lists are getting messed up?

The problem is that the current code enqueues the same structure onto up to four different lists, and we don't have a quantum computer, so head.next can't point to four different places. ;-)

Making head be static in all four functions allows four different head.next pointer to point to the four different places, as required.

Quoted 1 line

In any case, I will update this as you suggested.

Very good!

Quoted 67 lines
Quoted 38 lines

kernel/rcu/update.c static void rcu_spawn_tasks_kthread(void) · line 720

Quoted 10 lines
kernel/rcu/update.c +10 -0
+DEFINE_STATIC_SRCU(srcu_struct);
+
+static void test_callback(struct rcu_head *r)
+{
+     rcu_self_test_counter++;
+     pr_info("RCU test callback executed %d\n", rcu_self_test_counter);
+}
+
+static void early_boot_test_call_rcu(void)
+{

... as in:

        static struct rcu_head head;
Quoted 6 lines
kernel/rcu/update.c +6 -0
+     call_rcu(&head, test_callback);
+}
+
+static void early_boot_test_call_rcu_bh(void)
+{
+     call_rcu_bh(&head, test_callback);

kernel/rcu/update.c static void rcu_spawn_tasks_kthread(void) · line 736

Quoted 10 lines
kernel/rcu/update.c +10 -0
+}
+
+static void early_boot_test_call_rcu_sched(void)
+{
+     call_rcu_sched(&head, test_callback);
+}
+
+static void early_boot_test_call_srcu(void)
+{
+     call_srcu(&srcu_struct, &head, test_callback);

This looked like a great idea at first, but unfortunately call_srcu() invokes queue_delayed_work(), which breaks horribly this early in boot. Either this test has to be removed, or call_srcu() has to be updated to handle early-boot invocation. Given that no one is using call_srcu() during early boot, it is probably best to just drop the test.

Quoted 3 lines

(In case you were wondering, TEST06 dies during boot.)

Could you please send an updated patch?

Yup, will do. Please see one question below:

<...>

Quoted 21 lines
Quoted 21 lines
kernel/rcu/update.c +21 -0
+static int rcu_verify_early_boot_tests(void)
+{
+     int ret = 0;
+     int early_boot_test_counter = 0;
+
+     if (rcu_self_test) {
+             early_boot_test_counter++;
+             rcu_barrier();
+     }
+     if (rcu_self_test_bh) {
+             early_boot_test_counter++;
+             rcu_barrier_bh();
+     }
+     if (rcu_self_test_sched) {
+             early_boot_test_counter++;
+             rcu_barrier_sched();
+     }
+     if (rcu_self_test_srcu) {
+             early_boot_test_counter++;
+             srcu_barrier(&srcu_struct);
+     }
Quoted 8 lines
Quoted 3 lines

kernel/rcu/update.c static void rcu_spawn_tasks_kthread(void) · line 776

Quoted 3 lines
kernel/rcu/update.c +3 -0
+
+     if (rcu_self_test_counter != early_boot_test_counter)
+             ret = -1;

So this basically does nothing when it does not match. All we see is the return value when we pass initcall_debug. Should I add a WARN_ON() or some such so that it is more explicit?

Please do!

Thanx, Paul

Quoted 22 lines
Quoted 16 lines
Quoted 15 lines
kernel/rcu/update.c +7 -1
+
+     return ret;
+}
+late_initcall(rcu_verify_early_boot_tests);
+#else
+void rcu_early_boot_tests(void) {}
+#endif /* CONFIG_PROVE_RCU */
--

2.1.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Signature · 1 line
Pranith
#6 lore raw

RFC PATCH 2/3 doc: Document RCU self test boot params

In reply to Pranith Kumar

Document the RCU self test boot parameters in kernel-parameters.txt.

---
 Documentation/kernel-parameters.txt | 12 ++++++++++++
 1 file changed, 12 insertions(+)
Documentation/kernel-parameters.txt +12 -0
index c403957..6f5c01b 100644
@@ -3054,6 +3054,18 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
 			messages.  Disable with a value less than or equal
 			to zero.
 
+	rcupdate.rcu_self_test= [KNL]
+			Run the RCU early boot self tests
+
+	rcupdate.rcu_self_test_bh= [KNL]
+			Run the RCU bh early boot self tests
+
+	rcupdate.rcu_self_test_sched= [KNL]
+			Run the RCU sched early boot self tests
+
+	rcupdate.rcu_self_test_srcu= [KNL]
+			Run the SRCU early boot self tests
+
 	rdinit=		[KNL]
 			Format: <full_path>
 			Run specified binary instead of /init from the ramdisk,
Signature · 1 line
2.1.0
#7 lore raw

RFC PATCH 3/3 rcutorture: Enable RCU self test in configs

In reply to Pranith Kumar

Add config and boot parameters to enable the self tests in rcutorture testing.

---
 tools/testing/selftests/rcutorture/configs/rcu/TINY02      | 2 ++
 tools/testing/selftests/rcutorture/configs/rcu/TINY02.boot | 2 ++
 tools/testing/selftests/rcutorture/configs/rcu/TREE05.boot | 1 +
 tools/testing/selftests/rcutorture/configs/rcu/TREE06.boot | 4 ++++
 tools/testing/selftests/rcutorture/configs/rcu/TREE08      | 2 ++
 tools/testing/selftests/rcutorture/configs/rcu/TREE08.boot | 2 ++
 6 files changed, 13 insertions(+)
 create mode 100644 tools/testing/selftests/rcutorture/configs/rcu/TINY02.boot
 create mode 100644 tools/testing/selftests/rcutorture/configs/rcu/TREE06.boot
tools/testing/selftests/rcutorture/configs/rcu/TINY02 +2 -0
index f4feaee..36e41df 100644
@@ -7,6 +7,8 @@ CONFIG_HZ_PERIODIC=y
 CONFIG_NO_HZ_IDLE=n
 CONFIG_NO_HZ_FULL=n
 CONFIG_RCU_TRACE=y
+CONFIG_PROVE_LOCKING=y
+CONFIG_PROVE_RCU=y
 CONFIG_DEBUG_LOCK_ALLOC=y
 CONFIG_DEBUG_OBJECTS_RCU_HEAD=n
 CONFIG_PREEMPT_COUNT=y
tools/testing/selftests/rcutorture/configs/rcu/TINY02.boot new file +2 -0
new file mode 100644
index 0000000..0f08027
@@ -0,0 +1,2 @@
+rcupdate.rcu_self_test=1
+rcupdate.rcu_self_test_bh=1
tools/testing/selftests/rcutorture/configs/rcu/TREE05.boot +1 -0
index 3b42b8b..15b3e1a 100644
@@ -1 +1,2 @@
 rcutorture.torture_type=sched
+rcupdate.rcu_self_test_sched=1
tools/testing/selftests/rcutorture/configs/rcu/TREE06.boot new file +4 -0
new file mode 100644
index 0000000..0436e07
@@ -0,0 +1,4 @@
+rcupdate.rcu_self_test=1
+rcupdate.rcu_self_test_bh=1
+rcupdate.rcu_self_test_sched=1
+rcupdate.rcu_self_test_srcu=1
tools/testing/selftests/rcutorture/configs/rcu/TREE08 +2 -0
index 316aa6c..1a9303d 100644
@@ -18,6 +18,8 @@ CONFIG_RCU_FANOUT_LEAF=2
 CONFIG_RCU_NOCB_CPU=y
 CONFIG_RCU_NOCB_CPU_ALL=y
 CONFIG_DEBUG_LOCK_ALLOC=n
+CONFIG_PROVE_LOCKING=y
+CONFIG_PROVE_RCU=y
 CONFIG_RCU_CPU_STALL_INFO=n
 CONFIG_RCU_BOOST=n
 CONFIG_DEBUG_OBJECTS_RCU_HEAD=n
tools/testing/selftests/rcutorture/configs/rcu/TREE08.boot +2 -0
index 3b42b8b..2561daf 100644
@@ -1 +1,3 @@
 rcutorture.torture_type=sched
+rcupdate.rcu_self_test=1
+rcupdate.rcu_self_test_sched=1
Signature · 1 line
2.1.0