Skip to contentSkip to conversation

rcu-tasks: move RCU-tasks initialization out of core_initcall()

PATCH In review Uladzislau Rezki (Sony) 5 participants 32 messages Dec 9, 2020 – Feb 18, 2021

Subsystems (2)
lore
Share & tools
lore

Uladzislau Rezki (Sony)

author maintainer
#0 lore raw

PATCH 1/2 rcu-tasks: move RCU-tasks initialization out of core_initcall()

Initialize the RCU-tasks earlier, before *_initcall() callbacks are invoked. Do it after the workqueue subsytem is up and running. That gives us a possibility to make use of synchronize_rcu_tasks*() wait API in early_initcall() callbacks.

Fixes 36dadef23fcc ("kprobes: Init kprobes in early_initcall")
---
 include/linux/rcupdate.h |  6 ++++++
 init/main.c              |  1 +
 kernel/rcu/tasks.h       | 26 ++++++++++++++++++++++----
 3 files changed, 29 insertions(+), 4 deletions(-)
include/linux/rcupdate.h +6 -0
index 3c3efa4d6ab5..340c7d5344a4 100644
@@ -88,6 +88,12 @@ void rcu_sched_clock_irq(int user);
 void rcu_report_dead(unsigned int cpu);
 void rcutree_migrate_callbacks(int cpu);
 
+#ifdef CONFIG_TASKS_RCU_GENERIC
+void rcu_init_tasks_generic(void);
+#else
+static inline void rcu_init_tasks_generic(void) { }
+#endif
+
 #ifdef CONFIG_RCU_STALL_COMMON
 void rcu_sysrq_start(void);
 void rcu_sysrq_end(void);
init/main.c +1 -0
index 130376ec10ba..e253e87bdf58 100644
@@ -1502,6 +1502,7 @@ static noinline void __init kernel_init_freeable(void)
 
 	init_mm_internals();
 
+	rcu_init_tasks_generic();
 	do_pre_smp_initcalls();
 	lockup_detector_init();
 
kernel/rcu/tasks.h +22 -4
index 35bdcfd84d42..67a162949763 100644
@@ -241,7 +241,7 @@ static int __noreturn rcu_tasks_kthread(void *arg)
 	}
 }
 
-/* Spawn RCU-tasks grace-period kthread, e.g., at core_initcall() time. */
+/* Spawn RCU-tasks grace-period kthread. */
 static void __init rcu_spawn_tasks_kthread_generic(struct rcu_tasks *rtp)
 {
 	struct task_struct *t;
@@ -564,7 +564,6 @@ static int __init rcu_spawn_tasks_kthread(void)
 	rcu_spawn_tasks_kthread_generic(&rcu_tasks);
 	return 0;
 }
-core_initcall(rcu_spawn_tasks_kthread);
 
 #if !defined(CONFIG_TINY_RCU)
 void show_rcu_tasks_classic_gp_kthread(void)
@@ -692,7 +691,6 @@ static int __init rcu_spawn_tasks_rude_kthread(void)
 	rcu_spawn_tasks_kthread_generic(&rcu_tasks_rude);
 	return 0;
 }
-core_initcall(rcu_spawn_tasks_rude_kthread);
 
 #if !defined(CONFIG_TINY_RCU)
 void show_rcu_tasks_rude_gp_kthread(void)
@@ -968,6 +966,12 @@ static void rcu_tasks_trace_pregp_step(void)
 static void rcu_tasks_trace_pertask(struct task_struct *t,
 				    struct list_head *hop)
 {
+	// During early boot when there is only one boot-CPU,
+	// an idle_task is not set for other CPUs. In this case
+	// just revert.
+	if (unlikely(t == NULL))
+		return;
+
 	WRITE_ONCE(t->trc_reader_special.b.need_qs, false);
 	WRITE_ONCE(t->trc_reader_checked, false);
 	t->trc_ipi_to_cpu = -1;
@@ -1193,7 +1197,6 @@ static int __init rcu_spawn_tasks_trace_kthread(void)
 	rcu_spawn_tasks_kthread_generic(&rcu_tasks_trace);
 	return 0;
 }
-core_initcall(rcu_spawn_tasks_trace_kthread);
 
 #if !defined(CONFIG_TINY_RCU)
 void show_rcu_tasks_trace_gp_kthread(void)
@@ -1222,6 +1225,21 @@ void show_rcu_tasks_gp_kthreads(void)
 }
 #endif /* #ifndef CONFIG_TINY_RCU */
 
+void __init rcu_init_tasks_generic(void)
+{
+#ifdef CONFIG_TASKS_RCU
+	rcu_spawn_tasks_kthread();
+#endif
+
+#ifdef CONFIG_TASKS_RUDE_RCU
+	rcu_spawn_tasks_rude_kthread();
+#endif
+
+#ifdef CONFIG_TASKS_TRACE_RCU
+	rcu_spawn_tasks_trace_kthread();
+#endif
+}
+
 #else /* #ifdef CONFIG_TASKS_RCU_GENERIC */
 static inline void rcu_tasks_bootup_oddness(void) {}
 void show_rcu_tasks_gp_kthreads(void) {}
Signature · 1 line
2.20.1
author maintainer
#1 lore raw

PATCH 2/2 rcu-tasks: add RCU-tasks self tests

Add self tests for checking of RCU-tasks API functionality. It covers:
- wait API functions;
- invoking/completion call_rcu_tasks*().

Self-tests are run when CONFIG_PROVE_RCU kernel parameter is set.

---
 kernel/rcu/tasks.h | 44 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)
kernel/rcu/tasks.h +44 -0
index 67a162949763..9407772780c1 100644
@@ -1225,6 +1225,16 @@ void show_rcu_tasks_gp_kthreads(void)
 }
 #endif /* #ifndef CONFIG_TINY_RCU */
 
+static struct rcu_head rhp;
+static int rcu_execurted_test_counter;
+static int rcu_run_test_counter;
+
+static void test_rcu_tasks_callback(struct rcu_head *r)
+{
+	pr_info("RCU-tasks test callback executed %d\n",
+		++rcu_execurted_test_counter);
+}
+
 void __init rcu_init_tasks_generic(void)
 {
 #ifdef CONFIG_TASKS_RCU
@@ -1238,7 +1248,41 @@ void __init rcu_init_tasks_generic(void)
 #ifdef CONFIG_TASKS_TRACE_RCU
 	rcu_spawn_tasks_trace_kthread();
 #endif
+
+	if (IS_ENABLED(CONFIG_PROVE_RCU)) {
+		pr_info("Running RCU-tasks wait API self tests\n");
+#ifdef CONFIG_TASKS_RCU
+		rcu_run_test_counter++;
+		call_rcu_tasks(&rhp, test_rcu_tasks_callback);
+		synchronize_rcu_tasks();
+#endif
+
+#ifdef CONFIG_TASKS_RUDE_RCU
+		rcu_run_test_counter++;
+		call_rcu_tasks_trace(&rhp, test_rcu_tasks_callback);
+		synchronize_rcu_tasks_rude();
+#endif
+
+#ifdef CONFIG_TASKS_TRACE_RCU
+		rcu_run_test_counter++;
+		call_rcu_tasks_trace(&rhp, test_rcu_tasks_callback);
+		synchronize_rcu_tasks_trace();
+#endif
+	}
+}
+
+static int rcu_tasks_verify_self_tests(void)
+{
+	int ret = 0;
+
+	if (rcu_run_test_counter != rcu_execurted_test_counter) {
+		WARN_ON(1);
+		ret = -1;
+	}
+
+	return ret;
 }
+late_initcall(rcu_tasks_verify_self_tests);
 
 #else /* #ifdef CONFIG_TASKS_RCU_GENERIC */
 static inline void rcu_tasks_bootup_oddness(void) {}
Signature · 1 line
2.20.1
author maintainer
#2 lore raw

Re: [PATCH 2/2] rcu-tasks: add RCU-tasks self tests

Quoted 65 lines

Add self tests for checking of RCU-tasks API functionality. It covers:
- wait API functions;
- invoking/completion call_rcu_tasks*().

Self-tests are run when CONFIG_PROVE_RCU kernel parameter is set.

---
 kernel/rcu/tasks.h | 44 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)
kernel/rcu/tasks.h +38 -0
index 67a162949763..9407772780c1 100644
@@ -1225,6 +1225,16 @@ void show_rcu_tasks_gp_kthreads(void)
 }
 #endif /* #ifndef CONFIG_TINY_RCU */
 
+static struct rcu_head rhp;
+static int rcu_execurted_test_counter;
+static int rcu_run_test_counter;
+
+static void test_rcu_tasks_callback(struct rcu_head *r)
+{
+	pr_info("RCU-tasks test callback executed %d\n",
+		++rcu_execurted_test_counter);
+}
+
 void __init rcu_init_tasks_generic(void)
 {
 #ifdef CONFIG_TASKS_RCU
@@ -1238,7 +1248,41 @@ void __init rcu_init_tasks_generic(void)
 #ifdef CONFIG_TASKS_TRACE_RCU
 	rcu_spawn_tasks_trace_kthread();
 #endif
+
+	if (IS_ENABLED(CONFIG_PROVE_RCU)) {
+		pr_info("Running RCU-tasks wait API self tests\n");
+#ifdef CONFIG_TASKS_RCU
+		rcu_run_test_counter++;
+		call_rcu_tasks(&rhp, test_rcu_tasks_callback);
+		synchronize_rcu_tasks();
+#endif
+
+#ifdef CONFIG_TASKS_RUDE_RCU
+		rcu_run_test_counter++;
+		call_rcu_tasks_trace(&rhp, test_rcu_tasks_callback);
+		synchronize_rcu_tasks_rude();
+#endif
+
+#ifdef CONFIG_TASKS_TRACE_RCU
+		rcu_run_test_counter++;
+		call_rcu_tasks_trace(&rhp, test_rcu_tasks_callback);
+		synchronize_rcu_tasks_trace();
+#endif
+	}
+}
+
+static int rcu_tasks_verify_self_tests(void)
+{
+	int ret = 0;
+
+	if (rcu_run_test_counter != rcu_execurted_test_counter) {

kernel/rcu/tasks.h void __init rcu_init_tasks_generic(void) · line 1288

Quoted 10 lines
kernel/rcu/tasks.h +6 -0
+		WARN_ON(1);
+		ret = -1;
+	}
+
+	return ret;
 }
+late_initcall(rcu_tasks_verify_self_tests);
 
 #else /* #ifdef CONFIG_TASKS_RCU_GENERIC */
 static inline void rcu_tasks_bootup_oddness(void) {}

Please find a v2 of the patch that is in question. First version uses the same rhp for all RCU flavors what is wrong. Initially i had three different one per one flavor. But for some reason end up with only one.

From e7c6096af5a7916f29c0b4b05e1644b3b3a6c589 Mon Sep 17 00:00:00 2001
From: "Uladzislau Rezki (Sony)" <[email protected]>
Date: Wed, 9 Dec 2020 21:27:32 +0100
Subject: [PATCH v2 1/1] rcu-tasks: Add RCU-tasks self tests

This commit adds self tests for early-boot use of RCU-tasks grace periods. It tests all three variants (Rude, Tasks, and Tasks Trace) and covers both synchronous (e.g., synchronize_rcu_tasks()) and asynchronous (e.g., call_rcu_tasks()) grace-period APIs.

Self-tests are run only in kernels built with CONFIG_PROVE_RCU=y.

---
 kernel/rcu/tasks.h | 69 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 69 insertions(+)
kernel/rcu/tasks.h +69 -0
index 36607551f966..7478d912734a 100644
@@ -1224,6 +1224,35 @@ void show_rcu_tasks_gp_kthreads(void)
 }
 #endif /* #ifndef CONFIG_TINY_RCU */
 
+struct test_desc {
+       struct rcu_head rh;
+       const char *name;
+       bool run;
+};
+
+static struct test_desc tests[] = {
+       { .name = "call_rcu_tasks()" },
+       { .name = "call_rcu_rude()"  },
+       { .name = "call_rcu_trace()" },
+};
+
+static int rcu_executed_test_counter;
+
+static void test_rcu_tasks_callback(struct rcu_head *rhp)
+{
+       int i;
+
+       pr_info("RCU-tasks test callback executed %d\n",
+               ++rcu_executed_test_counter);
+
+       for (i = 0; i < ARRAY_SIZE(tests); i++) {
+               if (rhp == &tests[i].rh) {
+                       tests[i].run = false;
+                       break;
+               }
+       }
+}
+
 void __init rcu_init_tasks_generic(void)
 {
 #ifdef CONFIG_TASKS_RCU
@@ -1237,7 +1266,47 @@ void __init rcu_init_tasks_generic(void)
 #ifdef CONFIG_TASKS_TRACE_RCU
        rcu_spawn_tasks_trace_kthread();
 #endif
+
+       // Run the self-tests.
+       if (IS_ENABLED(CONFIG_PROVE_RCU)) {
+               pr_info("Running RCU-tasks wait API self tests\n");
+#ifdef CONFIG_TASKS_RCU
+               tests[0].run = true;
+               call_rcu_tasks(&tests[0].rh, test_rcu_tasks_callback);
+               synchronize_rcu_tasks();
+#endif
+
+#ifdef CONFIG_TASKS_RUDE_RCU
+               tests[1].run = true;
+               call_rcu_tasks_rude(&tests[1].rh, test_rcu_tasks_callback);
+               synchronize_rcu_tasks_rude();
+#endif
+
+#ifdef CONFIG_TASKS_TRACE_RCU
+               tests[2].run = true;
+               call_rcu_tasks_trace(&tests[2].rh, test_rcu_tasks_callback);
+               synchronize_rcu_tasks_trace();
+#endif
+       }
+}
+
+static int rcu_tasks_verify_self_tests(void)
+{
+       int ret, i;
+
+       for (i = 0, ret = 0; i < ARRAY_SIZE(tests); i++) {
+               if (tests[i].run) {             // still hanging.
+                       pr_err("%s has been failed.\n", tests[i].name);
+                       ret = -1;
+               }
+       }
+
+       if (ret)
+               WARN_ON(1);
+
+       return ret;
 }
+late_initcall(rcu_tasks_verify_self_tests);
 
 #else /* #ifdef CONFIG_TASKS_RCU_GENERIC */
 static inline void rcu_tasks_bootup_oddness(void) {}
Signature · 4 lines
2.20.1

--
Vlad Rezki
maintainer
#3 lore raw

Re: [PATCH 2/2] rcu-tasks: add RCU-tasks self tests

Quoted 86 lines · Uladzislau Rezki
Quoted 65 lines

Add self tests for checking of RCU-tasks API functionality. It covers:
- wait API functions;
- invoking/completion call_rcu_tasks*().

Self-tests are run when CONFIG_PROVE_RCU kernel parameter is set.

---
 kernel/rcu/tasks.h | 44 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)
kernel/rcu/tasks.h +38 -0
index 67a162949763..9407772780c1 100644
@@ -1225,6 +1225,16 @@ void show_rcu_tasks_gp_kthreads(void)
 }
 #endif /* #ifndef CONFIG_TINY_RCU */
 
+static struct rcu_head rhp;
+static int rcu_execurted_test_counter;
+static int rcu_run_test_counter;
+
+static void test_rcu_tasks_callback(struct rcu_head *r)
+{
+	pr_info("RCU-tasks test callback executed %d\n",
+		++rcu_execurted_test_counter);
+}
+
 void __init rcu_init_tasks_generic(void)
 {
 #ifdef CONFIG_TASKS_RCU
@@ -1238,7 +1248,41 @@ void __init rcu_init_tasks_generic(void)
 #ifdef CONFIG_TASKS_TRACE_RCU
 	rcu_spawn_tasks_trace_kthread();
 #endif
+
+	if (IS_ENABLED(CONFIG_PROVE_RCU)) {
+		pr_info("Running RCU-tasks wait API self tests\n");
+#ifdef CONFIG_TASKS_RCU
+		rcu_run_test_counter++;
+		call_rcu_tasks(&rhp, test_rcu_tasks_callback);
+		synchronize_rcu_tasks();
+#endif
+
+#ifdef CONFIG_TASKS_RUDE_RCU
+		rcu_run_test_counter++;
+		call_rcu_tasks_trace(&rhp, test_rcu_tasks_callback);
+		synchronize_rcu_tasks_rude();
+#endif
+
+#ifdef CONFIG_TASKS_TRACE_RCU
+		rcu_run_test_counter++;
+		call_rcu_tasks_trace(&rhp, test_rcu_tasks_callback);
+		synchronize_rcu_tasks_trace();
+#endif
+	}
+}
+
+static int rcu_tasks_verify_self_tests(void)
+{
+	int ret = 0;
+
+	if (rcu_run_test_counter != rcu_execurted_test_counter) {

kernel/rcu/tasks.h void __init rcu_init_tasks_generic(void) · line 1288

Quoted 10 lines
kernel/rcu/tasks.h +6 -0
+		WARN_ON(1);
+		ret = -1;
+	}
+
+	return ret;
 }
+late_initcall(rcu_tasks_verify_self_tests);
 
 #else /* #ifdef CONFIG_TASKS_RCU_GENERIC */
 static inline void rcu_tasks_bootup_oddness(void) {}

Please find a v2 of the patch that is in question. First version uses the same rhp for all RCU flavors what is wrong. Initially i had three different one per one flavor. But for some reason end up with only one.

Quoted 1 line

From e7c6096af5a7916f29c0b4b05e1644b3b3a6c589 Mon Sep 17 00:00:00 2001

From: "Uladzislau Rezki (Sony)" <[email protected]>
Date: Wed, 9 Dec 2020 21:27:32 +0100
Subject: [PATCH v2 1/1] rcu-tasks: Add RCU-tasks self tests

Quoted 8 lines

This commit adds self tests for early-boot use of RCU-tasks grace periods. It tests all three variants (Rude, Tasks, and Tasks Trace) and covers both synchronous (e.g., synchronize_rcu_tasks()) and asynchronous (e.g., call_rcu_tasks()) grace-period APIs.

Self-tests are run only in kernels built with CONFIG_PROVE_RCU=y.

Much improved, thank you! A few more comments below.

kernel/rcu/tasks.h void show_rcu_tasks_gp_kthreads(void) · line 1227

Quoted 13 lines
---
 kernel/rcu/tasks.h | 69 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 69 insertions(+)
kernel/rcu/tasks.h +1 -0
index 36607551f966..7478d912734a 100644
@@ -1224,6 +1224,35 @@ void show_rcu_tasks_gp_kthreads(void)
 }
 #endif /* #ifndef CONFIG_TINY_RCU */
 
+struct test_desc {

Please use something like "struct rcu_tasks_test_desc" to help the poor people who might need to grep for this. Feel free to shorten it, but please make it descriptive and thus more likely to stay unique.

kernel/rcu/tasks.h void show_rcu_tasks_gp_kthreads(void) · line 1230

Quoted 3 lines
kernel/rcu/tasks.h +3 -0
+       struct rcu_head rh;
+       const char *name;
+       bool run;

If you make this "bool notrun" you don't need to initialize.

kernel/rcu/tasks.h void show_rcu_tasks_gp_kthreads(void) · line 1242

Quoted 12 lines
kernel/rcu/tasks.h +12 -0
+};
+
+static struct test_desc tests[] = {
+       { .name = "call_rcu_tasks()" },
+       { .name = "call_rcu_rude()"  },
+       { .name = "call_rcu_trace()" },
+};
+
+static int rcu_executed_test_counter;
+
+static void test_rcu_tasks_callback(struct rcu_head *rhp)
+{
	struct rcu_tasks_test_desc *rttdp;

kernel/rcu/tasks.h void show_rcu_tasks_gp_kthreads(void) · line 1246

Quoted 4 lines
kernel/rcu/tasks.h +4 -0
+       int i;
+
+       pr_info("RCU-tasks test callback executed %d\n",
+               ++rcu_executed_test_counter);
	rttdp = container_of(rhp, rh, struct rcu_tasks_test_desc);
	rttdp->notrun = true;

Or I suppose:

	container_of(rhp, rh, struct rcu_tasks_test_desc)->notrun = true;

Then the loop below can go away.

Quoted 13 lines
kernel/rcu/tasks.h +9 -0
+
+       for (i = 0; i < ARRAY_SIZE(tests); i++) {
+               if (rhp == &tests[i].rh) {
+                       tests[i].run = false;
+                       break;
+               }
+       }
+}
+
 void __init rcu_init_tasks_generic(void)
 {
 #ifdef CONFIG_TASKS_RCU

kernel/rcu/tasks.h void __init rcu_init_tasks_generic(void) · line 1274

Quoted 9 lines
kernel/rcu/tasks.h +6 -0
@@ -1237,7 +1266,47 @@ void __init rcu_init_tasks_generic(void)
 #ifdef CONFIG_TASKS_TRACE_RCU
        rcu_spawn_tasks_trace_kthread();
 #endif
+
+       // Run the self-tests.
+       if (IS_ENABLED(CONFIG_PROVE_RCU)) {
+               pr_info("Running RCU-tasks wait API self tests\n");
+#ifdef CONFIG_TASKS_RCU
+               tests[0].run = true;

The s/run/notrun/ allows the three initializations of .run to go away.

kernel/rcu/tasks.h void __init rcu_init_tasks_generic(void) · line 1276

Quoted 2 lines
kernel/rcu/tasks.h +2 -0
+               call_rcu_tasks(&tests[0].rh, test_rcu_tasks_callback);
+               synchronize_rcu_tasks();

Why not reverse the order of these two statements? That would test call_rcu_tasks*()'s ability to do a grace period on their own, without help from the corresponding synchronize_rcu_tasks*().

Quoted 9 lines
kernel/rcu/tasks.h +9 -0
+#endif
+
+#ifdef CONFIG_TASKS_RUDE_RCU
+               tests[1].run = true;
+               call_rcu_tasks_rude(&tests[1].rh, test_rcu_tasks_callback);
+               synchronize_rcu_tasks_rude();
+#endif
+
+#ifdef CONFIG_TASKS_TRACE_RCU

kernel/rcu/tasks.h void __init rcu_init_tasks_generic(void) · line 1295

Quoted 10 lines
kernel/rcu/tasks.h +10 -0
+               tests[2].run = true;
+               call_rcu_tasks_trace(&tests[2].rh, test_rcu_tasks_callback);
+               synchronize_rcu_tasks_trace();
+#endif
+       }
+}
+
+static int rcu_tasks_verify_self_tests(void)
+{
+       int ret, i;

Why not initialize "ret" in the declaration?

Quoted 19 lines
kernel/rcu/tasks.h +13 -0
+
+       for (i = 0, ret = 0; i < ARRAY_SIZE(tests); i++) {
+               if (tests[i].run) {             // still hanging.
+                       pr_err("%s has been failed.\n", tests[i].name);
+                       ret = -1;
+               }
+       }
+
+       if (ret)
+               WARN_ON(1);
+
+       return ret;
 }
+late_initcall(rcu_tasks_verify_self_tests);
 
 #else /* #ifdef CONFIG_TASKS_RCU_GENERIC */
 static inline void rcu_tasks_bootup_oddness(void) {}
Signature · 1 line
2.20.1

Again, much improved!

Thanx, Paul

author maintainer
#4 lore raw

Re: [PATCH 2/2] rcu-tasks: add RCU-tasks self tests

Quoted 220 lines · Paul E. McKenney
Quoted 86 lines · Uladzislau Rezki
Quoted 65 lines

Add self tests for checking of RCU-tasks API functionality. It covers:
- wait API functions;
- invoking/completion call_rcu_tasks*().

Self-tests are run when CONFIG_PROVE_RCU kernel parameter is set.

---
 kernel/rcu/tasks.h | 44 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)
kernel/rcu/tasks.h +38 -0
index 67a162949763..9407772780c1 100644
@@ -1225,6 +1225,16 @@ void show_rcu_tasks_gp_kthreads(void)
 }
 #endif /* #ifndef CONFIG_TINY_RCU */
 
+static struct rcu_head rhp;
+static int rcu_execurted_test_counter;
+static int rcu_run_test_counter;
+
+static void test_rcu_tasks_callback(struct rcu_head *r)
+{
+	pr_info("RCU-tasks test callback executed %d\n",
+		++rcu_execurted_test_counter);
+}
+
 void __init rcu_init_tasks_generic(void)
 {
 #ifdef CONFIG_TASKS_RCU
@@ -1238,7 +1248,41 @@ void __init rcu_init_tasks_generic(void)
 #ifdef CONFIG_TASKS_TRACE_RCU
 	rcu_spawn_tasks_trace_kthread();
 #endif
+
+	if (IS_ENABLED(CONFIG_PROVE_RCU)) {
+		pr_info("Running RCU-tasks wait API self tests\n");
+#ifdef CONFIG_TASKS_RCU
+		rcu_run_test_counter++;
+		call_rcu_tasks(&rhp, test_rcu_tasks_callback);
+		synchronize_rcu_tasks();
+#endif
+
+#ifdef CONFIG_TASKS_RUDE_RCU
+		rcu_run_test_counter++;
+		call_rcu_tasks_trace(&rhp, test_rcu_tasks_callback);
+		synchronize_rcu_tasks_rude();
+#endif
+
+#ifdef CONFIG_TASKS_TRACE_RCU
+		rcu_run_test_counter++;
+		call_rcu_tasks_trace(&rhp, test_rcu_tasks_callback);
+		synchronize_rcu_tasks_trace();
+#endif
+	}
+}
+
+static int rcu_tasks_verify_self_tests(void)
+{
+	int ret = 0;
+
+	if (rcu_run_test_counter != rcu_execurted_test_counter) {

kernel/rcu/tasks.h void __init rcu_init_tasks_generic(void) · line 1288

Quoted 10 lines
kernel/rcu/tasks.h +6 -0
+		WARN_ON(1);
+		ret = -1;
+	}
+
+	return ret;
 }
+late_initcall(rcu_tasks_verify_self_tests);
 
 #else /* #ifdef CONFIG_TASKS_RCU_GENERIC */
 static inline void rcu_tasks_bootup_oddness(void) {}

Please find a v2 of the patch that is in question. First version uses the same rhp for all RCU flavors what is wrong. Initially i had three different one per one flavor. But for some reason end up with only one.

Quoted 1 line

From e7c6096af5a7916f29c0b4b05e1644b3b3a6c589 Mon Sep 17 00:00:00 2001

From: "Uladzislau Rezki (Sony)" <[email protected]>
Date: Wed, 9 Dec 2020 21:27:32 +0100
Subject: [PATCH v2 1/1] rcu-tasks: Add RCU-tasks self tests

Quoted 8 lines

This commit adds self tests for early-boot use of RCU-tasks grace periods. It tests all three variants (Rude, Tasks, and Tasks Trace) and covers both synchronous (e.g., synchronize_rcu_tasks()) and asynchronous (e.g., call_rcu_tasks()) grace-period APIs.

Self-tests are run only in kernels built with CONFIG_PROVE_RCU=y.

Much improved, thank you! A few more comments below.

kernel/rcu/tasks.h void show_rcu_tasks_gp_kthreads(void) · line 1227

Quoted 13 lines
---
 kernel/rcu/tasks.h | 69 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 69 insertions(+)
kernel/rcu/tasks.h +1 -0
index 36607551f966..7478d912734a 100644
@@ -1224,6 +1224,35 @@ void show_rcu_tasks_gp_kthreads(void)
 }
 #endif /* #ifndef CONFIG_TINY_RCU */
 
+struct test_desc {

Please use something like "struct rcu_tasks_test_desc" to help the poor people who might need to grep for this. Feel free to shorten it, but please make it descriptive and thus more likely to stay unique.

kernel/rcu/tasks.h void show_rcu_tasks_gp_kthreads(void) · line 1230

Quoted 3 lines
kernel/rcu/tasks.h +3 -0
+       struct rcu_head rh;
+       const char *name;
+       bool run;

If you make this "bool notrun" you don't need to initialize.

kernel/rcu/tasks.h void show_rcu_tasks_gp_kthreads(void) · line 1242

Quoted 12 lines
kernel/rcu/tasks.h +12 -0
+};
+
+static struct test_desc tests[] = {
+       { .name = "call_rcu_tasks()" },
+       { .name = "call_rcu_rude()"  },
+       { .name = "call_rcu_trace()" },
+};
+
+static int rcu_executed_test_counter;
+
+static void test_rcu_tasks_callback(struct rcu_head *rhp)
+{
	struct rcu_tasks_test_desc *rttdp;

kernel/rcu/tasks.h void show_rcu_tasks_gp_kthreads(void) · line 1246

Quoted 4 lines
kernel/rcu/tasks.h +4 -0
+       int i;
+
+       pr_info("RCU-tasks test callback executed %d\n",
+               ++rcu_executed_test_counter);
	rttdp = container_of(rhp, rh, struct rcu_tasks_test_desc);
	rttdp->notrun = true;

Or I suppose:

	container_of(rhp, rh, struct rcu_tasks_test_desc)->notrun = true;

Then the loop below can go away.

Quoted 13 lines
kernel/rcu/tasks.h +9 -0
+
+       for (i = 0; i < ARRAY_SIZE(tests); i++) {
+               if (rhp == &tests[i].rh) {
+                       tests[i].run = false;
+                       break;
+               }
+       }
+}
+
 void __init rcu_init_tasks_generic(void)
 {
 #ifdef CONFIG_TASKS_RCU

kernel/rcu/tasks.h void __init rcu_init_tasks_generic(void) · line 1274

Quoted 9 lines
kernel/rcu/tasks.h +6 -0
@@ -1237,7 +1266,47 @@ void __init rcu_init_tasks_generic(void)
 #ifdef CONFIG_TASKS_TRACE_RCU
        rcu_spawn_tasks_trace_kthread();
 #endif
+
+       // Run the self-tests.
+       if (IS_ENABLED(CONFIG_PROVE_RCU)) {
+               pr_info("Running RCU-tasks wait API self tests\n");
+#ifdef CONFIG_TASKS_RCU
+               tests[0].run = true;

The s/run/notrun/ allows the three initializations of .run to go away.

kernel/rcu/tasks.h void __init rcu_init_tasks_generic(void) · line 1276

Quoted 2 lines
kernel/rcu/tasks.h +2 -0
+               call_rcu_tasks(&tests[0].rh, test_rcu_tasks_callback);
+               synchronize_rcu_tasks();

Why not reverse the order of these two statements? That would test call_rcu_tasks*()'s ability to do a grace period on their own, without help from the corresponding synchronize_rcu_tasks*().

Quoted 9 lines
kernel/rcu/tasks.h +9 -0
+#endif
+
+#ifdef CONFIG_TASKS_RUDE_RCU
+               tests[1].run = true;
+               call_rcu_tasks_rude(&tests[1].rh, test_rcu_tasks_callback);
+               synchronize_rcu_tasks_rude();
+#endif
+
+#ifdef CONFIG_TASKS_TRACE_RCU

kernel/rcu/tasks.h void __init rcu_init_tasks_generic(void) · line 1295

Quoted 10 lines
kernel/rcu/tasks.h +10 -0
+               tests[2].run = true;
+               call_rcu_tasks_trace(&tests[2].rh, test_rcu_tasks_callback);
+               synchronize_rcu_tasks_trace();
+#endif
+       }
+}
+
+static int rcu_tasks_verify_self_tests(void)
+{
+       int ret, i;

Why not initialize "ret" in the declaration?

Quoted 15 lines
kernel/rcu/tasks.h +13 -0
+
+       for (i = 0, ret = 0; i < ARRAY_SIZE(tests); i++) {
+               if (tests[i].run) {             // still hanging.
+                       pr_err("%s has been failed.\n", tests[i].name);
+                       ret = -1;
+               }
+       }
+
+       if (ret)
+               WARN_ON(1);
+
+       return ret;
 }
+late_initcall(rcu_tasks_verify_self_tests);
 
Quoted 7 lines
Quoted 4 lines
kernel/rcu/tasks.h +0 -0
 #else /* #ifdef CONFIG_TASKS_RCU_GENERIC */
 static inline void rcu_tasks_bootup_oddness(void) {}
Signature · 1 line
2.20.1

Again, much improved!

See below the v3 version. I hope i fixed all comments :)

From 06f7adfd84cbb1994d0e2693ee9dcdfd272a9bd0 Mon Sep 17 00:00:00 2001
From: "Uladzislau Rezki (Sony)" <[email protected]>
Date: Wed, 9 Dec 2020 21:27:32 +0100
Subject: [PATCH v3 1/1] rcu-tasks: Add RCU-tasks self tests

This commit adds self tests for early-boot use of RCU-tasks grace periods. It tests all three variants (Rude, Tasks, and Tasks Trace) and covers both synchronous (e.g., synchronize_rcu_tasks()) and asynchronous (e.g., call_rcu_tasks()) grace-period APIs.

Self-tests are run only in kernels built with CONFIG_PROVE_RCU=y.

---
 kernel/rcu/tasks.h | 75 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 75 insertions(+)
kernel/rcu/tasks.h +75 -0
index 36607551f966..670212ed9648 100644
@@ -1224,6 +1224,43 @@ void show_rcu_tasks_gp_kthreads(void)
 }
 #endif /* #ifndef CONFIG_TINY_RCU */
 
+struct rcu_tasks_test_desc {
+	struct rcu_head rh;
+	const char *name;
+	bool notrun;
+};
+
+static struct rcu_tasks_test_desc tests[] = {
+	{
+		.name = "call_rcu_tasks()",
+		/* If not defined, the test is skipped. */
+		.notrun = !IS_ENABLED(CONFIG_TASKS_RCU),
+	},
+	{
+		.name = "call_rcu_tasks_rude()",
+		/* If not defined, the test is skipped. */
+		.notrun = !IS_ENABLED(CONFIG_TASKS_RUDE_RCU),
+	},
+	{
+		.name = "call_rcu_tasks_trace()",
+		/* If not defined, the test is skipped. */
+		.notrun = !IS_ENABLED(CONFIG_TASKS_TRACE_RCU)
+	}
+};
+
+static int rcu_executed_test_counter;
+
+static void test_rcu_tasks_callback(struct rcu_head *rhp)
+{
+	struct rcu_tasks_test_desc *rttd =
+		container_of(rhp, struct rcu_tasks_test_desc, rh);
+
+	pr_info("RCU-tasks test callback executed %d\n",
+		++rcu_executed_test_counter);
+
+	rttd->notrun = true;
+}
+
 void __init rcu_init_tasks_generic(void)
 {
 #ifdef CONFIG_TASKS_RCU
@@ -1237,7 +1274,45 @@ void __init rcu_init_tasks_generic(void)
 #ifdef CONFIG_TASKS_TRACE_RCU
 	rcu_spawn_tasks_trace_kthread();
 #endif
+
+	// Run the self-tests.
+	if (IS_ENABLED(CONFIG_PROVE_RCU)) {
+		pr_info("Running RCU-tasks wait API self tests\n");
+#ifdef CONFIG_TASKS_RCU
+		synchronize_rcu_tasks();
+		call_rcu_tasks(&tests[0].rh, test_rcu_tasks_callback);
+#endif
+
+#ifdef CONFIG_TASKS_RUDE_RCU
+		synchronize_rcu_tasks_rude();
+		call_rcu_tasks_rude(&tests[1].rh, test_rcu_tasks_callback);
+#endif
+
+#ifdef CONFIG_TASKS_TRACE_RCU
+		synchronize_rcu_tasks_trace();
+		call_rcu_tasks_trace(&tests[2].rh, test_rcu_tasks_callback);
+#endif
+	}
+}
+
+static int rcu_tasks_verify_self_tests(void)
+{
+	int ret = 0;
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(tests); i++) {
+		if (!tests[i].notrun) {		// still hanging.
+			pr_err("%s has been failed.\n", tests[i].name);
+			ret = -1;
+		}
+	}
+
+	if (ret)
+		WARN_ON(1);
+
+	return ret;
 }
+late_initcall(rcu_tasks_verify_self_tests);
 
 #else /* #ifdef CONFIG_TASKS_RCU_GENERIC */
 static inline void rcu_tasks_bootup_oddness(void) {}
Signature · 4 lines
2.20.1

--
Vlad Rezki
maintainer
#5 lore raw

Re: [PATCH 2/2] rcu-tasks: add RCU-tasks self tests

Quoted 2 lines · Uladzislau Rezki
Quoted 1 line · Paul E. McKenney

On Wed, Dec 16, 2020 at 04:49:59PM +0100, Uladzislau Rezki wrote:

[ . . . ]

Quoted 11 lines
Quoted 4 lines
Quoted 1 line

2.20.1

Again, much improved!

See below the v3 version. I hope i fixed all comments :)

Quoted 1 line

From 06f7adfd84cbb1994d0e2693ee9dcdfd272a9bd0 Mon Sep 17 00:00:00 2001

From: "Uladzislau Rezki (Sony)" <[email protected]>
Date: Wed, 9 Dec 2020 21:27:32 +0100
Subject: [PATCH v3 1/1] rcu-tasks: Add RCU-tasks self tests

Quoted 8 lines

This commit adds self tests for early-boot use of RCU-tasks grace periods. It tests all three variants (Rude, Tasks, and Tasks Trace) and covers both synchronous (e.g., synchronize_rcu_tasks()) and asynchronous (e.g., call_rcu_tasks()) grace-period APIs.

Self-tests are run only in kernels built with CONFIG_PROVE_RCU=y.

Much better!

I pulled this in, but made one small additional change. Please let me know if this is problematic.

Thanx, Paul

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

commit 93372198b5c9efdfd288aa3b3ee41c1f90866886

Author: Uladzislau Rezki (Sony) <[email protected]>
Date:   Wed Dec 9 21:27:32 2020 +0100

rcu-tasks: Add RCU-tasks self tests

This commit adds self tests for early-boot use of RCU-tasks grace periods. It tests all three variants (Rude, Tasks, and Tasks Trace) and covers both synchronous (e.g., synchronize_rcu_tasks()) and asynchronous (e.g., call_rcu_tasks()) grace-period APIs.

Self-tests are run only in kernels built with CONFIG_PROVE_RCU=y.

kernel/rcu/tasks.h +72 -0
index 3660755..35a2cd5 100644
@@ -1224,6 +1224,40 @@ void show_rcu_tasks_gp_kthreads(void)
 }
 #endif /* #ifndef CONFIG_TINY_RCU */
 
+struct rcu_tasks_test_desc {
+	struct rcu_head rh;
+	const char *name;
+	bool notrun;
+};
+
+static struct rcu_tasks_test_desc tests[] = {
+	{
+		.name = "call_rcu_tasks()",
+		/* If not defined, the test is skipped. */
+		.notrun = !IS_ENABLED(CONFIG_TASKS_RCU),
+	},
+	{
+		.name = "call_rcu_tasks_rude()",
+		/* If not defined, the test is skipped. */
+		.notrun = !IS_ENABLED(CONFIG_TASKS_RUDE_RCU),
+	},
+	{
+		.name = "call_rcu_tasks_trace()",
+		/* If not defined, the test is skipped. */
+		.notrun = !IS_ENABLED(CONFIG_TASKS_TRACE_RCU)
+	}
+};
+
+static void test_rcu_tasks_callback(struct rcu_head *rhp)
+{
+	struct rcu_tasks_test_desc *rttd =
+		container_of(rhp, struct rcu_tasks_test_desc, rh);
+
+	pr_info("Callback from %s invoked.\n", rttd->name);
+
+	rttd->notrun = true;
+}
+
 void __init rcu_init_tasks_generic(void)
 {
 #ifdef CONFIG_TASKS_RCU
@@ -1237,7 +1271,45 @@ void __init rcu_init_tasks_generic(void)
 #ifdef CONFIG_TASKS_TRACE_RCU
 	rcu_spawn_tasks_trace_kthread();
 #endif
+
+	// Run the self-tests.
+	if (IS_ENABLED(CONFIG_PROVE_RCU)) {
+		pr_info("Running RCU-tasks wait API self tests\n");
+#ifdef CONFIG_TASKS_RCU
+		synchronize_rcu_tasks();
+		call_rcu_tasks(&tests[0].rh, test_rcu_tasks_callback);
+#endif
+
+#ifdef CONFIG_TASKS_RUDE_RCU
+		synchronize_rcu_tasks_rude();
+		call_rcu_tasks_rude(&tests[1].rh, test_rcu_tasks_callback);
+#endif
+
+#ifdef CONFIG_TASKS_TRACE_RCU
+		synchronize_rcu_tasks_trace();
+		call_rcu_tasks_trace(&tests[2].rh, test_rcu_tasks_callback);
+#endif
+	}
+}
+
+static int rcu_tasks_verify_self_tests(void)
+{
+	int ret = 0;
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(tests); i++) {
+		if (!tests[i].notrun) {		// still hanging.
+			pr_err("%s has been failed.\n", tests[i].name);
+			ret = -1;
+		}
+	}
+
+	if (ret)
+		WARN_ON(1);
+
+	return ret;
 }
+late_initcall(rcu_tasks_verify_self_tests);
 
 #else /* #ifdef CONFIG_TASKS_RCU_GENERIC */
 static inline void rcu_tasks_bootup_oddness(void) {}
author maintainer
#6 lore raw

Re: [PATCH 2/2] rcu-tasks: add RCU-tasks self tests

Quoted 79 lines · Paul E. McKenney
Quoted 2 lines · Uladzislau Rezki
Quoted 1 line · Paul E. McKenney

On Wed, Dec 16, 2020 at 04:49:59PM +0100, Uladzislau Rezki wrote:

[ . . . ]

Quoted 11 lines
Quoted 4 lines
Quoted 1 line

2.20.1

Again, much improved!

See below the v3 version. I hope i fixed all comments :)

Quoted 1 line

From 06f7adfd84cbb1994d0e2693ee9dcdfd272a9bd0 Mon Sep 17 00:00:00 2001

From: "Uladzislau Rezki (Sony)" <[email protected]>
Date: Wed, 9 Dec 2020 21:27:32 +0100
Subject: [PATCH v3 1/1] rcu-tasks: Add RCU-tasks self tests

Quoted 8 lines

This commit adds self tests for early-boot use of RCU-tasks grace periods. It tests all three variants (Rude, Tasks, and Tasks Trace) and covers both synchronous (e.g., synchronize_rcu_tasks()) and asynchronous (e.g., call_rcu_tasks()) grace-period APIs.

Self-tests are run only in kernels built with CONFIG_PROVE_RCU=y.

Much better!

I pulled this in, but made one small additional change. Please let me know if this is problematic.

Thanx, Paul

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

commit 93372198b5c9efdfd288aa3b3ee41c1f90866886

Author: Uladzislau Rezki (Sony) <[email protected]>
Date:   Wed Dec 9 21:27:32 2020 +0100

rcu-tasks: Add RCU-tasks self tests

This commit adds self tests for early-boot use of RCU-tasks grace periods. It tests all three variants (Rude, Tasks, and Tasks Trace) and covers both synchronous (e.g., synchronize_rcu_tasks()) and asynchronous (e.g., call_rcu_tasks()) grace-period APIs.

Self-tests are run only in kernels built with CONFIG_PROVE_RCU=y.

kernel/rcu/tasks.h +20 -0
index 3660755..35a2cd5 100644
@@ -1224,6 +1224,40 @@ void show_rcu_tasks_gp_kthreads(void)
 }
 #endif /* #ifndef CONFIG_TINY_RCU */
 
+struct rcu_tasks_test_desc {
+	struct rcu_head rh;
+	const char *name;
+	bool notrun;
+};
+
+static struct rcu_tasks_test_desc tests[] = {
+	{
+		.name = "call_rcu_tasks()",
+		/* If not defined, the test is skipped. */
+		.notrun = !IS_ENABLED(CONFIG_TASKS_RCU),
+	},
+	{
+		.name = "call_rcu_tasks_rude()",
+		/* If not defined, the test is skipped. */
+		.notrun = !IS_ENABLED(CONFIG_TASKS_RUDE_RCU),
+	},
+	{
+		.name = "call_rcu_tasks_trace()",
+		/* If not defined, the test is skipped. */

kernel/rcu/tasks.h void show_rcu_tasks_gp_kthreads(void) · line 1256

Quoted 10 lines
kernel/rcu/tasks.h +10 -0
+		.notrun = !IS_ENABLED(CONFIG_TASKS_TRACE_RCU)
+	}
+};
+
+static void test_rcu_tasks_callback(struct rcu_head *rhp)
+{
+	struct rcu_tasks_test_desc *rttd =
+		container_of(rhp, struct rcu_tasks_test_desc, rh);
+
+	pr_info("Callback from %s invoked.\n", rttd->name);

That is fine! We can output the name instead of executed counter. Doing so makes it completely clear who triggers the callback.

--
Vlad Rezki

maintainer
#7 lore raw

Re: [PATCH 2/2] rcu-tasks: add RCU-tasks self tests

Quoted 84 lines · Uladzislau Rezki
Quoted 83 lines · Paul E. McKenney
Quoted 2 lines · Uladzislau Rezki
Quoted 1 line · Paul E. McKenney

On Wed, Dec 16, 2020 at 04:49:59PM +0100, Uladzislau Rezki wrote:

[ . . . ]

Quoted 11 lines
Quoted 4 lines
Quoted 1 line

2.20.1

Again, much improved!

See below the v3 version. I hope i fixed all comments :)

Quoted 1 line

From 06f7adfd84cbb1994d0e2693ee9dcdfd272a9bd0 Mon Sep 17 00:00:00 2001

From: "Uladzislau Rezki (Sony)" <[email protected]>
Date: Wed, 9 Dec 2020 21:27:32 +0100
Subject: [PATCH v3 1/1] rcu-tasks: Add RCU-tasks self tests

Quoted 8 lines

This commit adds self tests for early-boot use of RCU-tasks grace periods. It tests all three variants (Rude, Tasks, and Tasks Trace) and covers both synchronous (e.g., synchronize_rcu_tasks()) and asynchronous (e.g., call_rcu_tasks()) grace-period APIs.

Self-tests are run only in kernels built with CONFIG_PROVE_RCU=y.

Much better!

I pulled this in, but made one small additional change. Please let me know if this is problematic.

Thanx, Paul

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

commit 93372198b5c9efdfd288aa3b3ee41c1f90866886

Author: Uladzislau Rezki (Sony) <[email protected]>
Date:   Wed Dec 9 21:27:32 2020 +0100

rcu-tasks: Add RCU-tasks self tests

This commit adds self tests for early-boot use of RCU-tasks grace periods. It tests all three variants (Rude, Tasks, and Tasks Trace) and covers both synchronous (e.g., synchronize_rcu_tasks()) and asynchronous (e.g., call_rcu_tasks()) grace-period APIs.

Self-tests are run only in kernels built with CONFIG_PROVE_RCU=y.

kernel/rcu/tasks.h +24 -0
index 3660755..35a2cd5 100644
@@ -1224,6 +1224,40 @@ void show_rcu_tasks_gp_kthreads(void)
 }
 #endif /* #ifndef CONFIG_TINY_RCU */
 
+struct rcu_tasks_test_desc {
+	struct rcu_head rh;
+	const char *name;
+	bool notrun;
+};
+
+static struct rcu_tasks_test_desc tests[] = {
+	{
+		.name = "call_rcu_tasks()",
+		/* If not defined, the test is skipped. */
+		.notrun = !IS_ENABLED(CONFIG_TASKS_RCU),
+	},
+	{
+		.name = "call_rcu_tasks_rude()",
+		/* If not defined, the test is skipped. */
+		.notrun = !IS_ENABLED(CONFIG_TASKS_RUDE_RCU),
+	},
+	{
+		.name = "call_rcu_tasks_trace()",
+		/* If not defined, the test is skipped. */
+		.notrun = !IS_ENABLED(CONFIG_TASKS_TRACE_RCU)
+	}
+};
+
Quoted 8 lines

kernel/rcu/tasks.h void show_rcu_tasks_gp_kthreads(void) · line 1256

Quoted 6 lines
kernel/rcu/tasks.h +6 -0
+static void test_rcu_tasks_callback(struct rcu_head *rhp)
+{
+	struct rcu_tasks_test_desc *rttd =
+		container_of(rhp, struct rcu_tasks_test_desc, rh);
+
+	pr_info("Callback from %s invoked.\n", rttd->name);

That is fine! We can output the name instead of executed counter. Doing so makes it completely clear who triggers the callback.

And we also need to make it not trigger when CONFIG_PROVE_RCU=n. While in the area, we might as well leave anything that is needed only by CONFIG_PROVE_RCU=y undefined when CONFIG_PROVE_RCU=n.

How about the following?

Thanx, Paul

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

commit f7a1ac0d3504e0518745da7f98573c1b13587f3e

Author: Uladzislau Rezki (Sony) <[email protected]>
Date:   Wed Dec 9 21:27:32 2020 +0100

rcu-tasks: Add RCU-tasks self tests

This commit adds self tests for early-boot use of RCU-tasks grace periods. It tests all three variants (Rude, Tasks, and Tasks Trace) and covers both synchronous (e.g., synchronize_rcu_tasks()) and asynchronous (e.g., call_rcu_tasks()) grace-period APIs.

Self-tests are run only in kernels built with CONFIG_PROVE_RCU=y.

[ paulmck: Handle CONFIG_PROVE_RCU=n and identify test cases' callbacks. ]
kernel/rcu/tasks.h +79 -0
index 3660755..af7c194 100644
@@ -1224,6 +1224,82 @@ void show_rcu_tasks_gp_kthreads(void)
 }
 #endif /* #ifndef CONFIG_TINY_RCU */
 
+#ifdef CONFIG_PROVE_RCU
+struct rcu_tasks_test_desc {
+	struct rcu_head rh;
+	const char *name;
+	bool notrun;
+};
+
+static struct rcu_tasks_test_desc tests[] = {
+	{
+		.name = "call_rcu_tasks()",
+		/* If not defined, the test is skipped. */
+		.notrun = !IS_ENABLED(CONFIG_TASKS_RCU),
+	},
+	{
+		.name = "call_rcu_tasks_rude()",
+		/* If not defined, the test is skipped. */
+		.notrun = !IS_ENABLED(CONFIG_TASKS_RUDE_RCU),
+	},
+	{
+		.name = "call_rcu_tasks_trace()",
+		/* If not defined, the test is skipped. */
+		.notrun = !IS_ENABLED(CONFIG_TASKS_TRACE_RCU)
+	}
+};
+
+static void test_rcu_tasks_callback(struct rcu_head *rhp)
+{
+	struct rcu_tasks_test_desc *rttd =
+		container_of(rhp, struct rcu_tasks_test_desc, rh);
+
+	pr_info("Callback from %s invoked.\n", rttd->name);
+
+	rttd->notrun = true;
+}
+
+static void rcu_tasks_initiate_self_tests(void)
+{
+	pr_info("Running RCU-tasks wait API self tests\n");
+#ifdef CONFIG_TASKS_RCU
+	synchronize_rcu_tasks();
+	call_rcu_tasks(&tests[0].rh, test_rcu_tasks_callback);
+#endif
+
+#ifdef CONFIG_TASKS_RUDE_RCU
+	synchronize_rcu_tasks_rude();
+	call_rcu_tasks_rude(&tests[1].rh, test_rcu_tasks_callback);
+#endif
+
+#ifdef CONFIG_TASKS_TRACE_RCU
+	synchronize_rcu_tasks_trace();
+	call_rcu_tasks_trace(&tests[2].rh, test_rcu_tasks_callback);
+#endif
+}
+
+static int rcu_tasks_verify_self_tests(void)
+{
+	int ret = 0;
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(tests); i++) {
+		if (!tests[i].notrun) {		// still hanging.
+			pr_err("%s has been failed.\n", tests[i].name);
+			ret = -1;
+		}
+	}
+
+	if (ret)
+		WARN_ON(1);
+
+	return ret;
+}
+late_initcall(rcu_tasks_verify_self_tests);
+#else /* #ifdef CONFIG_PROVE_RCU */
+static void rcu_tasks_initiate_self_tests(void) { }
+#endif /* #else #ifdef CONFIG_PROVE_RCU */
+
 void __init rcu_init_tasks_generic(void)
 {
 #ifdef CONFIG_TASKS_RCU
@@ -1237,6 +1313,9 @@ void __init rcu_init_tasks_generic(void)
 #ifdef CONFIG_TASKS_TRACE_RCU
 	rcu_spawn_tasks_trace_kthread();
 #endif
+
+	// Run the self-tests.
+	rcu_tasks_initiate_self_tests();
 }
 
 #else /* #ifdef CONFIG_TASKS_RCU_GENERIC */
author maintainer
#8 lore raw

Re: [PATCH 2/2] rcu-tasks: add RCU-tasks self tests

Quoted 209 lines · Paul E. McKenney
Quoted 84 lines · Uladzislau Rezki
Quoted 83 lines · Paul E. McKenney
Quoted 2 lines · Uladzislau Rezki
Quoted 1 line · Paul E. McKenney

On Wed, Dec 16, 2020 at 04:49:59PM +0100, Uladzislau Rezki wrote:

[ . . . ]

Quoted 11 lines
Quoted 4 lines
Quoted 1 line

2.20.1

Again, much improved!

See below the v3 version. I hope i fixed all comments :)

Quoted 1 line

From 06f7adfd84cbb1994d0e2693ee9dcdfd272a9bd0 Mon Sep 17 00:00:00 2001

From: "Uladzislau Rezki (Sony)" <[email protected]>
Date: Wed, 9 Dec 2020 21:27:32 +0100
Subject: [PATCH v3 1/1] rcu-tasks: Add RCU-tasks self tests

Quoted 8 lines

This commit adds self tests for early-boot use of RCU-tasks grace periods. It tests all three variants (Rude, Tasks, and Tasks Trace) and covers both synchronous (e.g., synchronize_rcu_tasks()) and asynchronous (e.g., call_rcu_tasks()) grace-period APIs.

Self-tests are run only in kernels built with CONFIG_PROVE_RCU=y.

Much better!

I pulled this in, but made one small additional change. Please let me know if this is problematic.

Thanx, Paul

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

commit 93372198b5c9efdfd288aa3b3ee41c1f90866886

Author: Uladzislau Rezki (Sony) <[email protected]>
Date:   Wed Dec 9 21:27:32 2020 +0100

rcu-tasks: Add RCU-tasks self tests

This commit adds self tests for early-boot use of RCU-tasks grace periods. It tests all three variants (Rude, Tasks, and Tasks Trace) and covers both synchronous (e.g., synchronize_rcu_tasks()) and asynchronous (e.g., call_rcu_tasks()) grace-period APIs.

Self-tests are run only in kernels built with CONFIG_PROVE_RCU=y.

kernel/rcu/tasks.h +24 -0
index 3660755..35a2cd5 100644
@@ -1224,6 +1224,40 @@ void show_rcu_tasks_gp_kthreads(void)
 }
 #endif /* #ifndef CONFIG_TINY_RCU */
 
+struct rcu_tasks_test_desc {
+	struct rcu_head rh;
+	const char *name;
+	bool notrun;
+};
+
+static struct rcu_tasks_test_desc tests[] = {
+	{
+		.name = "call_rcu_tasks()",
+		/* If not defined, the test is skipped. */
+		.notrun = !IS_ENABLED(CONFIG_TASKS_RCU),
+	},
+	{
+		.name = "call_rcu_tasks_rude()",
+		/* If not defined, the test is skipped. */
+		.notrun = !IS_ENABLED(CONFIG_TASKS_RUDE_RCU),
+	},
+	{
+		.name = "call_rcu_tasks_trace()",
+		/* If not defined, the test is skipped. */
+		.notrun = !IS_ENABLED(CONFIG_TASKS_TRACE_RCU)
+	}
+};
+
Quoted 8 lines

kernel/rcu/tasks.h void show_rcu_tasks_gp_kthreads(void) · line 1257

Quoted 6 lines
kernel/rcu/tasks.h +6 -0
+static void test_rcu_tasks_callback(struct rcu_head *rhp)
+{
+	struct rcu_tasks_test_desc *rttd =
+		container_of(rhp, struct rcu_tasks_test_desc, rh);
+
+	pr_info("Callback from %s invoked.\n", rttd->name);

That is fine! We can output the name instead of executed counter. Doing so makes it completely clear who triggers the callback.

And we also need to make it not trigger when CONFIG_PROVE_RCU=n. While in the area, we might as well leave anything that is needed only by CONFIG_PROVE_RCU=y undefined when CONFIG_PROVE_RCU=n.

How about the following?

Thanx, Paul

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

commit f7a1ac0d3504e0518745da7f98573c1b13587f3e

Author: Uladzislau Rezki (Sony) <[email protected]>
Date:   Wed Dec 9 21:27:32 2020 +0100

rcu-tasks: Add RCU-tasks self tests

This commit adds self tests for early-boot use of RCU-tasks grace periods. It tests all three variants (Rude, Tasks, and Tasks Trace) and covers both synchronous (e.g., synchronize_rcu_tasks()) and asynchronous (e.g., call_rcu_tasks()) grace-period APIs.

Self-tests are run only in kernels built with CONFIG_PROVE_RCU=y.

[ paulmck: Handle CONFIG_PROVE_RCU=n and identify test cases' callbacks. ]
kernel/rcu/tasks.h +76 -0
index 3660755..af7c194 100644
@@ -1224,6 +1224,82 @@ void show_rcu_tasks_gp_kthreads(void)
 }
 #endif /* #ifndef CONFIG_TINY_RCU */
 
+#ifdef CONFIG_PROVE_RCU
+struct rcu_tasks_test_desc {
+	struct rcu_head rh;
+	const char *name;
+	bool notrun;
+};
+
+static struct rcu_tasks_test_desc tests[] = {
+	{
+		.name = "call_rcu_tasks()",
+		/* If not defined, the test is skipped. */
+		.notrun = !IS_ENABLED(CONFIG_TASKS_RCU),
+	},
+	{
+		.name = "call_rcu_tasks_rude()",
+		/* If not defined, the test is skipped. */
+		.notrun = !IS_ENABLED(CONFIG_TASKS_RUDE_RCU),
+	},
+	{
+		.name = "call_rcu_tasks_trace()",
+		/* If not defined, the test is skipped. */
+		.notrun = !IS_ENABLED(CONFIG_TASKS_TRACE_RCU)
+	}
+};
+
+static void test_rcu_tasks_callback(struct rcu_head *rhp)
+{
+	struct rcu_tasks_test_desc *rttd =
+		container_of(rhp, struct rcu_tasks_test_desc, rh);
+
+	pr_info("Callback from %s invoked.\n", rttd->name);
+
+	rttd->notrun = true;
+}
+
+static void rcu_tasks_initiate_self_tests(void)
+{
+	pr_info("Running RCU-tasks wait API self tests\n");
+#ifdef CONFIG_TASKS_RCU
+	synchronize_rcu_tasks();
+	call_rcu_tasks(&tests[0].rh, test_rcu_tasks_callback);
+#endif
+
+#ifdef CONFIG_TASKS_RUDE_RCU
+	synchronize_rcu_tasks_rude();
+	call_rcu_tasks_rude(&tests[1].rh, test_rcu_tasks_callback);
+#endif
+
+#ifdef CONFIG_TASKS_TRACE_RCU
+	synchronize_rcu_tasks_trace();
+	call_rcu_tasks_trace(&tests[2].rh, test_rcu_tasks_callback);
+#endif
+}
+
+static int rcu_tasks_verify_self_tests(void)
+{
+	int ret = 0;
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(tests); i++) {
+		if (!tests[i].notrun) {		// still hanging.
+			pr_err("%s has been failed.\n", tests[i].name);
+			ret = -1;
+		}
+	}
+
+	if (ret)
+		WARN_ON(1);
+
+	return ret;
+}
+late_initcall(rcu_tasks_verify_self_tests);
+#else /* #ifdef CONFIG_PROVE_RCU */
+static void rcu_tasks_initiate_self_tests(void) { }
+#endif /* #else #ifdef CONFIG_PROVE_RCU */
+
 void __init rcu_init_tasks_generic(void)
 {
 #ifdef CONFIG_TASKS_RCU

kernel/rcu/tasks.h void __init rcu_init_tasks_generic(void) · line 1321

Quoted 9 lines
kernel/rcu/tasks.h +3 -0
@@ -1237,6 +1313,9 @@ void __init rcu_init_tasks_generic(void)
 #ifdef CONFIG_TASKS_TRACE_RCU
 	rcu_spawn_tasks_trace_kthread();
 #endif
+
+	// Run the self-tests.
+	rcu_tasks_initiate_self_tests();
 }
 
 #else /* #ifdef CONFIG_TASKS_RCU_GENERIC */

That makes sense to me. I missed that point. There is no reason in wasting of extra cycles which affect a boot up time if built without CONFIG_PROVE_RCU.

--
Vlad Rezki

maintainer
#9 lore raw

Re: [PATCH 2/2] rcu-tasks: add RCU-tasks self tests

Quoted 218 lines · Uladzislau Rezki
Quoted 217 lines · Paul E. McKenney
Quoted 84 lines · Uladzislau Rezki
Quoted 83 lines · Paul E. McKenney
Quoted 2 lines · Uladzislau Rezki
Quoted 1 line · Paul E. McKenney

On Wed, Dec 16, 2020 at 04:49:59PM +0100, Uladzislau Rezki wrote:

[ . . . ]

Quoted 11 lines
Quoted 4 lines
Quoted 1 line

2.20.1

Again, much improved!

See below the v3 version. I hope i fixed all comments :)

Quoted 1 line

From 06f7adfd84cbb1994d0e2693ee9dcdfd272a9bd0 Mon Sep 17 00:00:00 2001

From: "Uladzislau Rezki (Sony)" <[email protected]>
Date: Wed, 9 Dec 2020 21:27:32 +0100
Subject: [PATCH v3 1/1] rcu-tasks: Add RCU-tasks self tests

Quoted 8 lines

This commit adds self tests for early-boot use of RCU-tasks grace periods. It tests all three variants (Rude, Tasks, and Tasks Trace) and covers both synchronous (e.g., synchronize_rcu_tasks()) and asynchronous (e.g., call_rcu_tasks()) grace-period APIs.

Self-tests are run only in kernels built with CONFIG_PROVE_RCU=y.

Much better!

I pulled this in, but made one small additional change. Please let me know if this is problematic.

Thanx, Paul

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

commit 93372198b5c9efdfd288aa3b3ee41c1f90866886

Author: Uladzislau Rezki (Sony) <[email protected]>
Date:   Wed Dec 9 21:27:32 2020 +0100

rcu-tasks: Add RCU-tasks self tests

This commit adds self tests for early-boot use of RCU-tasks grace periods. It tests all three variants (Rude, Tasks, and Tasks Trace) and covers both synchronous (e.g., synchronize_rcu_tasks()) and asynchronous (e.g., call_rcu_tasks()) grace-period APIs.

Self-tests are run only in kernels built with CONFIG_PROVE_RCU=y.

kernel/rcu/tasks.h +24 -0
index 3660755..35a2cd5 100644
@@ -1224,6 +1224,40 @@ void show_rcu_tasks_gp_kthreads(void)
 }
 #endif /* #ifndef CONFIG_TINY_RCU */
 
+struct rcu_tasks_test_desc {
+	struct rcu_head rh;
+	const char *name;
+	bool notrun;
+};
+
+static struct rcu_tasks_test_desc tests[] = {
+	{
+		.name = "call_rcu_tasks()",
+		/* If not defined, the test is skipped. */
+		.notrun = !IS_ENABLED(CONFIG_TASKS_RCU),
+	},
+	{
+		.name = "call_rcu_tasks_rude()",
+		/* If not defined, the test is skipped. */
+		.notrun = !IS_ENABLED(CONFIG_TASKS_RUDE_RCU),
+	},
+	{
+		.name = "call_rcu_tasks_trace()",
+		/* If not defined, the test is skipped. */
+		.notrun = !IS_ENABLED(CONFIG_TASKS_TRACE_RCU)
+	}
+};
+
Quoted 8 lines

kernel/rcu/tasks.h void show_rcu_tasks_gp_kthreads(void) · line 1257

Quoted 6 lines
kernel/rcu/tasks.h +6 -0
+static void test_rcu_tasks_callback(struct rcu_head *rhp)
+{
+	struct rcu_tasks_test_desc *rttd =
+		container_of(rhp, struct rcu_tasks_test_desc, rh);
+
+	pr_info("Callback from %s invoked.\n", rttd->name);

That is fine! We can output the name instead of executed counter. Doing so makes it completely clear who triggers the callback.

And we also need to make it not trigger when CONFIG_PROVE_RCU=n. While in the area, we might as well leave anything that is needed only by CONFIG_PROVE_RCU=y undefined when CONFIG_PROVE_RCU=n.

How about the following?

Thanx, Paul

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

commit f7a1ac0d3504e0518745da7f98573c1b13587f3e

Author: Uladzislau Rezki (Sony) <[email protected]>
Date:   Wed Dec 9 21:27:32 2020 +0100

rcu-tasks: Add RCU-tasks self tests

This commit adds self tests for early-boot use of RCU-tasks grace periods. It tests all three variants (Rude, Tasks, and Tasks Trace) and covers both synchronous (e.g., synchronize_rcu_tasks()) and asynchronous (e.g., call_rcu_tasks()) grace-period APIs.

Self-tests are run only in kernels built with CONFIG_PROVE_RCU=y.

[ paulmck: Handle CONFIG_PROVE_RCU=n and identify test cases' callbacks. ]
kernel/rcu/tasks.h +79 -0
index 3660755..af7c194 100644
@@ -1224,6 +1224,82 @@ void show_rcu_tasks_gp_kthreads(void)
 }
 #endif /* #ifndef CONFIG_TINY_RCU */
 
+#ifdef CONFIG_PROVE_RCU
+struct rcu_tasks_test_desc {
+	struct rcu_head rh;
+	const char *name;
+	bool notrun;
+};
+
+static struct rcu_tasks_test_desc tests[] = {
+	{
+		.name = "call_rcu_tasks()",
+		/* If not defined, the test is skipped. */
+		.notrun = !IS_ENABLED(CONFIG_TASKS_RCU),
+	},
+	{
+		.name = "call_rcu_tasks_rude()",
+		/* If not defined, the test is skipped. */
+		.notrun = !IS_ENABLED(CONFIG_TASKS_RUDE_RCU),
+	},
+	{
+		.name = "call_rcu_tasks_trace()",
+		/* If not defined, the test is skipped. */
+		.notrun = !IS_ENABLED(CONFIG_TASKS_TRACE_RCU)
+	}
+};
+
+static void test_rcu_tasks_callback(struct rcu_head *rhp)
+{
+	struct rcu_tasks_test_desc *rttd =
+		container_of(rhp, struct rcu_tasks_test_desc, rh);
+
+	pr_info("Callback from %s invoked.\n", rttd->name);
+
+	rttd->notrun = true;
+}
+
+static void rcu_tasks_initiate_self_tests(void)
+{
+	pr_info("Running RCU-tasks wait API self tests\n");
+#ifdef CONFIG_TASKS_RCU
+	synchronize_rcu_tasks();
+	call_rcu_tasks(&tests[0].rh, test_rcu_tasks_callback);
+#endif
+
+#ifdef CONFIG_TASKS_RUDE_RCU
+	synchronize_rcu_tasks_rude();
+	call_rcu_tasks_rude(&tests[1].rh, test_rcu_tasks_callback);
+#endif
+
+#ifdef CONFIG_TASKS_TRACE_RCU
+	synchronize_rcu_tasks_trace();
+	call_rcu_tasks_trace(&tests[2].rh, test_rcu_tasks_callback);
+#endif
+}
+
+static int rcu_tasks_verify_self_tests(void)
+{
+	int ret = 0;
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(tests); i++) {
+		if (!tests[i].notrun) {		// still hanging.
+			pr_err("%s has been failed.\n", tests[i].name);
+			ret = -1;
+		}
+	}
+
+	if (ret)
+		WARN_ON(1);
+
+	return ret;
+}
+late_initcall(rcu_tasks_verify_self_tests);
+#else /* #ifdef CONFIG_PROVE_RCU */
+static void rcu_tasks_initiate_self_tests(void) { }
+#endif /* #else #ifdef CONFIG_PROVE_RCU */
+
 void __init rcu_init_tasks_generic(void)
 {
 #ifdef CONFIG_TASKS_RCU
@@ -1237,6 +1313,9 @@ void __init rcu_init_tasks_generic(void)
 #ifdef CONFIG_TASKS_TRACE_RCU
 	rcu_spawn_tasks_trace_kthread();
 #endif
+
+	// Run the self-tests.
+	rcu_tasks_initiate_self_tests();
 }
 
Quoted 4 lines

kernel/rcu/tasks.h void __init rcu_init_tasks_generic(void) · line 1321

Quoted 1 line
kernel/rcu/tasks.h +0 -0
 #else /* #ifdef CONFIG_TASKS_RCU_GENERIC */

That makes sense to me. I missed that point. There is no reason in wasting of extra cycles which affect a boot up time if built without CONFIG_PROVE_RCU.

If CONFIG_PROVE_RCU=n, then rcu_tasks_initiate_self_tests is an empty function. So the compiler should be able to eliminate all runtime overhead from rcu_tasks_initiate_self_tests() when CONFIG_PROVE_RCU=n.

Or am I missing your point?

Thanx, Paul

author maintainer
#10 lore raw

Re: [PATCH 2/2] rcu-tasks: add RCU-tasks self tests

Quoted 224 lines · Paul E. McKenney
Quoted 218 lines · Uladzislau Rezki
Quoted 217 lines · Paul E. McKenney
Quoted 84 lines · Uladzislau Rezki
Quoted 83 lines · Paul E. McKenney
Quoted 2 lines · Uladzislau Rezki
Quoted 1 line · Paul E. McKenney

On Wed, Dec 16, 2020 at 04:49:59PM +0100, Uladzislau Rezki wrote:

[ . . . ]

Quoted 11 lines
Quoted 4 lines
Quoted 1 line

2.20.1

Again, much improved!

See below the v3 version. I hope i fixed all comments :)

Quoted 1 line

From 06f7adfd84cbb1994d0e2693ee9dcdfd272a9bd0 Mon Sep 17 00:00:00 2001

From: "Uladzislau Rezki (Sony)" <[email protected]>
Date: Wed, 9 Dec 2020 21:27:32 +0100
Subject: [PATCH v3 1/1] rcu-tasks: Add RCU-tasks self tests

Quoted 8 lines

This commit adds self tests for early-boot use of RCU-tasks grace periods. It tests all three variants (Rude, Tasks, and Tasks Trace) and covers both synchronous (e.g., synchronize_rcu_tasks()) and asynchronous (e.g., call_rcu_tasks()) grace-period APIs.

Self-tests are run only in kernels built with CONFIG_PROVE_RCU=y.

Much better!

I pulled this in, but made one small additional change. Please let me know if this is problematic.

Thanx, Paul

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

commit 93372198b5c9efdfd288aa3b3ee41c1f90866886

Author: Uladzislau Rezki (Sony) <[email protected]>
Date:   Wed Dec 9 21:27:32 2020 +0100

rcu-tasks: Add RCU-tasks self tests

This commit adds self tests for early-boot use of RCU-tasks grace periods. It tests all three variants (Rude, Tasks, and Tasks Trace) and covers both synchronous (e.g., synchronize_rcu_tasks()) and asynchronous (e.g., call_rcu_tasks()) grace-period APIs.

Self-tests are run only in kernels built with CONFIG_PROVE_RCU=y.

kernel/rcu/tasks.h +24 -0
index 3660755..35a2cd5 100644
@@ -1224,6 +1224,40 @@ void show_rcu_tasks_gp_kthreads(void)
 }
 #endif /* #ifndef CONFIG_TINY_RCU */
 
+struct rcu_tasks_test_desc {
+	struct rcu_head rh;
+	const char *name;
+	bool notrun;
+};
+
+static struct rcu_tasks_test_desc tests[] = {
+	{
+		.name = "call_rcu_tasks()",
+		/* If not defined, the test is skipped. */
+		.notrun = !IS_ENABLED(CONFIG_TASKS_RCU),
+	},
+	{
+		.name = "call_rcu_tasks_rude()",
+		/* If not defined, the test is skipped. */
+		.notrun = !IS_ENABLED(CONFIG_TASKS_RUDE_RCU),
+	},
+	{
+		.name = "call_rcu_tasks_trace()",
+		/* If not defined, the test is skipped. */
+		.notrun = !IS_ENABLED(CONFIG_TASKS_TRACE_RCU)
+	}
+};
+
Quoted 8 lines

kernel/rcu/tasks.h void show_rcu_tasks_gp_kthreads(void) · line 1257

Quoted 6 lines
kernel/rcu/tasks.h +6 -0
+static void test_rcu_tasks_callback(struct rcu_head *rhp)
+{
+	struct rcu_tasks_test_desc *rttd =
+		container_of(rhp, struct rcu_tasks_test_desc, rh);
+
+	pr_info("Callback from %s invoked.\n", rttd->name);

That is fine! We can output the name instead of executed counter. Doing so makes it completely clear who triggers the callback.

And we also need to make it not trigger when CONFIG_PROVE_RCU=n. While in the area, we might as well leave anything that is needed only by CONFIG_PROVE_RCU=y undefined when CONFIG_PROVE_RCU=n.

How about the following?

Thanx, Paul

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

commit f7a1ac0d3504e0518745da7f98573c1b13587f3e

Author: Uladzislau Rezki (Sony) <[email protected]>
Date:   Wed Dec 9 21:27:32 2020 +0100

rcu-tasks: Add RCU-tasks self tests

This commit adds self tests for early-boot use of RCU-tasks grace periods. It tests all three variants (Rude, Tasks, and Tasks Trace) and covers both synchronous (e.g., synchronize_rcu_tasks()) and asynchronous (e.g., call_rcu_tasks()) grace-period APIs.

Self-tests are run only in kernels built with CONFIG_PROVE_RCU=y.

[ paulmck: Handle CONFIG_PROVE_RCU=n and identify test cases' callbacks. ]
kernel/rcu/tasks.h +79 -0
index 3660755..af7c194 100644
@@ -1224,6 +1224,82 @@ void show_rcu_tasks_gp_kthreads(void)
 }
 #endif /* #ifndef CONFIG_TINY_RCU */
 
+#ifdef CONFIG_PROVE_RCU
+struct rcu_tasks_test_desc {
+	struct rcu_head rh;
+	const char *name;
+	bool notrun;
+};
+
+static struct rcu_tasks_test_desc tests[] = {
+	{
+		.name = "call_rcu_tasks()",
+		/* If not defined, the test is skipped. */
+		.notrun = !IS_ENABLED(CONFIG_TASKS_RCU),
+	},
+	{
+		.name = "call_rcu_tasks_rude()",
+		/* If not defined, the test is skipped. */
+		.notrun = !IS_ENABLED(CONFIG_TASKS_RUDE_RCU),
+	},
+	{
+		.name = "call_rcu_tasks_trace()",
+		/* If not defined, the test is skipped. */
+		.notrun = !IS_ENABLED(CONFIG_TASKS_TRACE_RCU)
+	}
+};
+
+static void test_rcu_tasks_callback(struct rcu_head *rhp)
+{
+	struct rcu_tasks_test_desc *rttd =
+		container_of(rhp, struct rcu_tasks_test_desc, rh);
+
+	pr_info("Callback from %s invoked.\n", rttd->name);
+
+	rttd->notrun = true;
+}
+
+static void rcu_tasks_initiate_self_tests(void)
+{
+	pr_info("Running RCU-tasks wait API self tests\n");
+#ifdef CONFIG_TASKS_RCU
+	synchronize_rcu_tasks();
+	call_rcu_tasks(&tests[0].rh, test_rcu_tasks_callback);
+#endif
+
+#ifdef CONFIG_TASKS_RUDE_RCU
+	synchronize_rcu_tasks_rude();
+	call_rcu_tasks_rude(&tests[1].rh, test_rcu_tasks_callback);
+#endif
+
+#ifdef CONFIG_TASKS_TRACE_RCU
+	synchronize_rcu_tasks_trace();
+	call_rcu_tasks_trace(&tests[2].rh, test_rcu_tasks_callback);
+#endif
+}
+
+static int rcu_tasks_verify_self_tests(void)
+{
+	int ret = 0;
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(tests); i++) {
+		if (!tests[i].notrun) {		// still hanging.
+			pr_err("%s has been failed.\n", tests[i].name);
+			ret = -1;
+		}
+	}
+
+	if (ret)
+		WARN_ON(1);
+
+	return ret;
+}
+late_initcall(rcu_tasks_verify_self_tests);
+#else /* #ifdef CONFIG_PROVE_RCU */
+static void rcu_tasks_initiate_self_tests(void) { }
+#endif /* #else #ifdef CONFIG_PROVE_RCU */
+
 void __init rcu_init_tasks_generic(void)
 {
 #ifdef CONFIG_TASKS_RCU
@@ -1237,6 +1313,9 @@ void __init rcu_init_tasks_generic(void)
 #ifdef CONFIG_TASKS_TRACE_RCU
 	rcu_spawn_tasks_trace_kthread();
 #endif
+
+	// Run the self-tests.
+	rcu_tasks_initiate_self_tests();
 }
 
Quoted 4 lines

kernel/rcu/tasks.h void __init rcu_init_tasks_generic(void) · line 1321

Quoted 1 line
kernel/rcu/tasks.h +0 -0
 #else /* #ifdef CONFIG_TASKS_RCU_GENERIC */

That makes sense to me. I missed that point. There is no reason in wasting of extra cycles which affect a boot up time if built without CONFIG_PROVE_RCU.

Quoted 6 lines

If CONFIG_PROVE_RCU=n, then rcu_tasks_initiate_self_tests is an empty function. So the compiler should be able to eliminate all runtime overhead from rcu_tasks_initiate_self_tests() when CONFIG_PROVE_RCU=n.

Or am I missing your point?

That is correct, i mean your description. I wanted to underline that the late_initcall(rcu_tasks_verify_self_tests); was called even for CONFIG_PROVE_RCU=n, what would affect a boot time with disabled option. Of-course that extra time would be negligible. From the other hand, why we should introduce it if it can be avoided.

Your last change fixes that :)

--
Vlad Rezki

#11 lore raw

Re: [PATCH 2/2] rcu-tasks: add RCU-tasks self tests

In reply to Uladzislau Rezki (Sony)
Quoted 6 lines · Uladzislau Rezki (Sony)

Add self tests for checking of RCU-tasks API functionality. It covers:
- wait API functions;
- invoking/completion call_rcu_tasks*().

Self-tests are run when CONFIG_PROVE_RCU kernel parameter is set.

I just bisected to this commit. By booting with `threadirqs' I end up with:

[    0.176533] Running RCU-tasks wait API self tests

No stall warning or so.
It boots again with:

init/main.c +2 -0
@@ -1489,6 +1489,7 @@ void __init console_on_rootfs(void)
 	fput(file);
 }
 
+void rcu_tasks_initiate_self_tests(void);
 static noinline void __init kernel_init_freeable(void)
 {
 	/*
@@ -1514,6 +1515,7 @@ static noinline void __init kernel_init_freeable(void)
 
 	rcu_init_tasks_generic();
 	do_pre_smp_initcalls();
+	rcu_tasks_initiate_self_tests();
 	lockup_detector_init();
 
 	smp_init();
kernel/rcu/tasks.h +1 -2
@@ -1266,7 +1266,7 @@ static void test_rcu_tasks_callback(struct rcu_head *rhp)
 	rttd->notrun = true;
 }
 
-static void rcu_tasks_initiate_self_tests(void)
+void rcu_tasks_initiate_self_tests(void)
 {
 	pr_info("Running RCU-tasks wait API self tests\n");
 #ifdef CONFIG_TASKS_RCU
@@ -1322,7 +1322,6 @@ void __init rcu_init_tasks_generic(void)
 #endif
 
 	// Run the self-tests.
-	rcu_tasks_initiate_self_tests();
 }
 
 #else /* #ifdef CONFIG_TASKS_RCU_GENERIC */
Quoted 1 line

Sebastian

author maintainer
#12 lore raw

Re: [PATCH 2/2] rcu-tasks: add RCU-tasks self tests

Quoted 55 lines · Sebastian Andrzej Siewior
Quoted 6 lines · Uladzislau Rezki (Sony)

Add self tests for checking of RCU-tasks API functionality. It covers:
- wait API functions;
- invoking/completion call_rcu_tasks*().

Self-tests are run when CONFIG_PROVE_RCU kernel parameter is set.

I just bisected to this commit. By booting with `threadirqs' I end up with:

[    0.176533] Running RCU-tasks wait API self tests

No stall warning or so.
It boots again with:

init/main.c +2 -0
@@ -1489,6 +1489,7 @@ void __init console_on_rootfs(void)
 	fput(file);
 }
 
+void rcu_tasks_initiate_self_tests(void);
 static noinline void __init kernel_init_freeable(void)
 {
 	/*
@@ -1514,6 +1515,7 @@ static noinline void __init kernel_init_freeable(void)
 
 	rcu_init_tasks_generic();
 	do_pre_smp_initcalls();
+	rcu_tasks_initiate_self_tests();
 	lockup_detector_init();
 
 	smp_init();
kernel/rcu/tasks.h +1 -2
@@ -1266,7 +1266,7 @@ static void test_rcu_tasks_callback(struct rcu_head *rhp)
 	rttd->notrun = true;
 }
 
-static void rcu_tasks_initiate_self_tests(void)
+void rcu_tasks_initiate_self_tests(void)
 {
 	pr_info("Running RCU-tasks wait API self tests\n");
 #ifdef CONFIG_TASKS_RCU
@@ -1322,7 +1322,6 @@ void __init rcu_init_tasks_generic(void)
 #endif
 
 	// Run the self-tests.
-	rcu_tasks_initiate_self_tests();
 }
 
 #else /* #ifdef CONFIG_TASKS_RCU_GENERIC */
Quoted 4 lines
Quoted 1 line

Sebastian

We should be able to use call_rcu_tasks() in the *initcall() callbacks. The problem is that, ksoftirqd threads are not spawned by the time when an rcu_init_tasks_generic() is invoked:

init/main.c +1 -1
index c68d784376ca..e6106bb12b2d 100644
@@ -954,7 +954,6 @@ asmlinkage __visible void __init __no_sanitize_address start_kernel(void)
 	rcu_init_nohz();
 	init_timers();
 	hrtimers_init();
-	softirq_init();
 	timekeeping_init();
 
 	/*
@@ -1512,6 +1511,7 @@ static noinline void __init kernel_init_freeable(void)
 
 	init_mm_internals();
 
+	softirq_init();
 	rcu_init_tasks_generic();
 	do_pre_smp_initcalls();
 	lockup_detector_init();
kernel/softirq.c +1 -1
index 9d71046ea247..cafa55c496d0 100644
@@ -630,6 +630,7 @@ void __init softirq_init(void)
 			&per_cpu(tasklet_hi_vec, cpu).head;
 	}
 
+	spawn_ksoftirqd();
 	open_softirq(TASKLET_SOFTIRQ, tasklet_action);
 	open_softirq(HI_SOFTIRQ, tasklet_hi_action);
 }
@@ -732,7 +733,6 @@ static __init int spawn_ksoftirqd(void)
 
 	return 0;
 }
-early_initcall(spawn_ksoftirqd);
 
 /*
  * [ These __weak aliases are kept in a separate compilation unit, so that

Any thoughts?

--
Vlad Rezki

maintainer
#13 lore raw

Re: [PATCH 2/2] rcu-tasks: add RCU-tasks self tests

Quoted 50 lines · Uladzislau Rezki
Quoted 49 lines · Sebastian Andrzej Siewior
Quoted 6 lines · Uladzislau Rezki (Sony)

Add self tests for checking of RCU-tasks API functionality. It covers:
- wait API functions;
- invoking/completion call_rcu_tasks*().

Self-tests are run when CONFIG_PROVE_RCU kernel parameter is set.

I just bisected to this commit. By booting with `threadirqs' I end up with:

[    0.176533] Running RCU-tasks wait API self tests

No stall warning or so.
It boots again with:

init/main.c +2 -0
@@ -1489,6 +1489,7 @@ void __init console_on_rootfs(void)
 	fput(file);
 }
 
+void rcu_tasks_initiate_self_tests(void);
 static noinline void __init kernel_init_freeable(void)
 {
 	/*
@@ -1514,6 +1515,7 @@ static noinline void __init kernel_init_freeable(void)
 
 	rcu_init_tasks_generic();
 	do_pre_smp_initcalls();
+	rcu_tasks_initiate_self_tests();
 	lockup_detector_init();
 
 	smp_init();
kernel/rcu/tasks.h +1 -1
@@ -1266,7 +1266,7 @@ static void test_rcu_tasks_callback(struct rcu_head *rhp)
 	rttd->notrun = true;
 }
 
-static void rcu_tasks_initiate_self_tests(void)
+void rcu_tasks_initiate_self_tests(void)
 {
 	pr_info("Running RCU-tasks wait API self tests\n");
 #ifdef CONFIG_TASKS_RCU
@@ -1322,7 +1322,6 @@ void __init rcu_init_tasks_generic(void)
 #endif
 
Quoted 7 lines
Quoted 7 lines
kernel/rcu/tasks.h +0 -1
 	// Run the self-tests.
-	rcu_tasks_initiate_self_tests();
 }
 
 #else /* #ifdef CONFIG_TASKS_RCU_GENERIC */
Quoted 2 lines

Apologies for the hassle! My testing clearly missed this combination of CONFIG_PROVE_RCU=y and threadirqs=1. :-(

But at least I can easily reproduce this hang as follows:

tools/testing/selftests/rcutorture/bin/kvm.sh --allcpus --duration 2 --configs "TREE03" --kconfig "CONFIG_DEBUG_LOCK_ALLOC=y CONFIG_PROVE_LOCKING=y" --bootargs "threadirqs=1" --trust-make

Sadly, I cannot take your patch because that simply papers over the fact that early boot use of synchronize_rcu_tasks() is broken in this particular configuration, which will likely eventually bite others now that init_kprobes() has been moved earlier in boot:

1b04fa990026 ("rcu-tasks: Move RCU-tasks initialization to before early_initcall()")

Fixes 36dadef23fcc ("kprobes: Init kprobes in early_initcall")
Quoted 31 lines
Quoted 2 lines

Sebastian

We should be able to use call_rcu_tasks() in the *initcall() callbacks. The problem is that, ksoftirqd threads are not spawned by the time when an rcu_init_tasks_generic() is invoked:

init/main.c +1 -1
index c68d784376ca..e6106bb12b2d 100644
@@ -954,7 +954,6 @@ asmlinkage __visible void __init __no_sanitize_address start_kernel(void)
 	rcu_init_nohz();
 	init_timers();
 	hrtimers_init();
-	softirq_init();
 	timekeeping_init();
 
 	/*
@@ -1512,6 +1511,7 @@ static noinline void __init kernel_init_freeable(void)
 
 	init_mm_internals();
 
+	softirq_init();
 	rcu_init_tasks_generic();
 	do_pre_smp_initcalls();
 	lockup_detector_init();
kernel/softirq.c +0 -0
index 9d71046ea247..cafa55c496d0 100644

kernel/softirq.c void __init softirq_init(void) · line 633

Quoted 4 lines
kernel/softirq.c +1 -0
@@ -630,6 +630,7 @@ void __init softirq_init(void)
 			&per_cpu(tasklet_hi_vec, cpu).head;
 	}
 
+	spawn_ksoftirqd();

We need a forward reference to allow this to build, but with that added, my test case passes. Good show!

Quoted 12 lines
kernel/softirq.c +0 -1
 	open_softirq(TASKLET_SOFTIRQ, tasklet_action);
 	open_softirq(HI_SOFTIRQ, tasklet_hi_action);
 }
@@ -732,7 +733,6 @@ static __init int spawn_ksoftirqd(void)
 
 	return 0;
 }
-early_initcall(spawn_ksoftirqd);
 
 /*
  * [ These __weak aliases are kept in a separate compilation unit, so that
Quoted 1 line

Any thoughts?

One likely problem is that there are almost certainly parts of the kernel that need softirq_init() to stay roughly where it is. So, is it possible to leave softirq_init() where it is, and to arrange for spawn_ksoftirqd() to be invoked just before rcu_init_tasks_generic() is called?

For my part, I will look into what is required to make Tasks RCU do without softirq during boot, for example, by looking carefully at where in boot RCU grace periods are unconditionally expedited. Just in case adjusting softirq has unforeseen side effects.

Thanx, Paul

maintainer
#14 lore raw

Re: [PATCH 2/2] rcu-tasks: add RCU-tasks self tests

Quoted 126 lines · Paul E. McKenney
Quoted 50 lines · Uladzislau Rezki
Quoted 49 lines · Sebastian Andrzej Siewior
Quoted 6 lines · Uladzislau Rezki (Sony)

Add self tests for checking of RCU-tasks API functionality. It covers:
- wait API functions;
- invoking/completion call_rcu_tasks*().

Self-tests are run when CONFIG_PROVE_RCU kernel parameter is set.

I just bisected to this commit. By booting with `threadirqs' I end up with:

[    0.176533] Running RCU-tasks wait API self tests

No stall warning or so.
It boots again with:

init/main.c +2 -0
@@ -1489,6 +1489,7 @@ void __init console_on_rootfs(void)
 	fput(file);
 }
 
+void rcu_tasks_initiate_self_tests(void);
 static noinline void __init kernel_init_freeable(void)
 {
 	/*
@@ -1514,6 +1515,7 @@ static noinline void __init kernel_init_freeable(void)
 
 	rcu_init_tasks_generic();
 	do_pre_smp_initcalls();
+	rcu_tasks_initiate_self_tests();
 	lockup_detector_init();
 
 	smp_init();
kernel/rcu/tasks.h +1 -1
@@ -1266,7 +1266,7 @@ static void test_rcu_tasks_callback(struct rcu_head *rhp)
 	rttd->notrun = true;
 }
 
-static void rcu_tasks_initiate_self_tests(void)
+void rcu_tasks_initiate_self_tests(void)
 {
 	pr_info("Running RCU-tasks wait API self tests\n");
 #ifdef CONFIG_TASKS_RCU
@@ -1322,7 +1322,6 @@ void __init rcu_init_tasks_generic(void)
 #endif
 
Quoted 7 lines
Quoted 7 lines
kernel/rcu/tasks.h +0 -1
 	// Run the self-tests.
-	rcu_tasks_initiate_self_tests();
 }
 
 #else /* #ifdef CONFIG_TASKS_RCU_GENERIC */
Quoted 2 lines

Apologies for the hassle! My testing clearly missed this combination of CONFIG_PROVE_RCU=y and threadirqs=1. :-(

But at least I can easily reproduce this hang as follows:

tools/testing/selftests/rcutorture/bin/kvm.sh --allcpus --duration 2 --configs "TREE03" --kconfig "CONFIG_DEBUG_LOCK_ALLOC=y CONFIG_PROVE_LOCKING=y" --bootargs "threadirqs=1" --trust-make

Sadly, I cannot take your patch because that simply papers over the fact that early boot use of synchronize_rcu_tasks() is broken in this particular configuration, which will likely eventually bite others now that init_kprobes() has been moved earlier in boot:

1b04fa990026 ("rcu-tasks: Move RCU-tasks initialization to before early_initcall()")

Fixes 36dadef23fcc ("kprobes: Init kprobes in early_initcall")
Quoted 31 lines
Quoted 2 lines

Sebastian

We should be able to use call_rcu_tasks() in the *initcall() callbacks. The problem is that, ksoftirqd threads are not spawned by the time when an rcu_init_tasks_generic() is invoked:

init/main.c +1 -1
index c68d784376ca..e6106bb12b2d 100644
@@ -954,7 +954,6 @@ asmlinkage __visible void __init __no_sanitize_address start_kernel(void)
 	rcu_init_nohz();
 	init_timers();
 	hrtimers_init();
-	softirq_init();
 	timekeeping_init();
 
 	/*
@@ -1512,6 +1511,7 @@ static noinline void __init kernel_init_freeable(void)
 
 	init_mm_internals();
 
+	softirq_init();
 	rcu_init_tasks_generic();
 	do_pre_smp_initcalls();
 	lockup_detector_init();
kernel/softirq.c +0 -0
index 9d71046ea247..cafa55c496d0 100644

kernel/softirq.c void __init softirq_init(void) · line 633

Quoted 4 lines
kernel/softirq.c +1 -0
@@ -630,6 +630,7 @@ void __init softirq_init(void)
 			&per_cpu(tasklet_hi_vec, cpu).head;
 	}
 
+	spawn_ksoftirqd();

We need a forward reference to allow this to build, but with that added, my test case passes. Good show!

Quoted 12 lines
kernel/softirq.c +0 -1
 	open_softirq(TASKLET_SOFTIRQ, tasklet_action);
 	open_softirq(HI_SOFTIRQ, tasklet_hi_action);
 }
@@ -732,7 +733,6 @@ static __init int spawn_ksoftirqd(void)
 
 	return 0;
 }
-early_initcall(spawn_ksoftirqd);
 
 /*
  * [ These __weak aliases are kept in a separate compilation unit, so that
Quoted 6 lines
Quoted 1 line

Any thoughts?

One likely problem is that there are almost certainly parts of the kernel that need softirq_init() to stay roughly where it is. So, is it possible to leave softirq_init() where it is, and to arrange for spawn_ksoftirqd() to be invoked just before rcu_init_tasks_generic() is called?

This still seems worth trying (and doing so is next on my list), but just in case there are objections to it, please see below. The advantage of the approach below is that it renders irrelevant the exact point at which ksoftirqd is spawned. The advantage of moving spawn_ksoftirqd() earlier is that it avoids adding checks to the softirq-handler code.

Me, I prefer the robustness of the approach below, but the important thing is of course to solve the problem one way or another.

Quoted 4 lines

For my part, I will look into what is required to make Tasks RCU do without softirq during boot, for example, by looking carefully at where in boot RCU grace periods are unconditionally expedited. Just in case adjusting softirq has unforeseen side effects.

I should hasten to add that my test case sets tree.use_softirq=0, so it is not RCU_SOFTIRQ that is lacking, but rather one of the others. TIMER_SOFTIRQ?

Given that, maybe the code that switches from softirq to ksoftirqd is doing so too early at boot. And the patch below allows my test case to complete successfully. I hope this patch is uncontroversial. After all, unless I am suffering a massive failure of imagination, it is rather difficult to wake up kthreads that have not yet been created, which is what current mainline looks to be doing.

There are three places invoking wakeup_softirqd(), and this patch deals only with the first two. They suffice thus far, and I would like to hear what others think before I pull something like irq-work into raise_softirq_irqoff(). :-/

Thoughts?

Thanx, Paul

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

commit be5b0b6d9c8f22b86ea5591885bf38987ef777d9

Author: Paul E. McKenney <[email protected]>
Date:   Fri Feb 12 16:20:40 2021 -0800

softirq: Don't try waking ksoftirqd before it has been spawned

If there is heavy softirq activity, the softirq system will attempt to awaken ksoftirqd and will stop the traditional back-of-interrupt softirq processing. This is all well and good, but only if the ksoftirqd kthreads already exist, which is not the case during early boot, in which case the system hangs.

One reproducer is as follows:

tools/testing/selftests/rcutorture/bin/kvm.sh --allcpus --duration 2 --configs "TREE03" --kconfig "CONFIG_DEBUG_LOCK_ALLOC=y CONFIG_PROVE_LOCKING=y" --bootargs "threadirqs=1" --trust-make

This commit therefore adds a couple of existence checks for ksoftirqd and forces back-of-interrupt softirq processing when ksoftirqd does not yet exist. With this change, the above test passes.

kernel/softirq.c +3 -3
index 9d71046..ba78e63 100644
@@ -209,7 +209,7 @@ static inline void invoke_softirq(void)
 	if (ksoftirqd_running(local_softirq_pending()))
 		return;
 
-	if (!force_irqthreads) {
+	if (!force_irqthreads || !__this_cpu_read(ksoftirqd)) {
 #ifdef CONFIG_HAVE_IRQ_EXIT_ON_IRQ_STACK
 		/*
 		 * We can safely execute softirq on the current stack if
@@ -358,8 +358,8 @@ asmlinkage __visible void __softirq_entry __do_softirq(void)
 
 	pending = local_softirq_pending();
 	if (pending) {
-		if (time_before(jiffies, end) && !need_resched() &&
-		    --max_restart)
+		if (!__this_cpu_read(ksoftirqd) ||
+		    (time_before(jiffies, end) && !need_resched() && --max_restart))
 			goto restart;
 
 		wakeup_softirqd();
maintainer
#15 lore raw

Re: [PATCH 2/2] rcu-tasks: add RCU-tasks self tests

Quoted 127 lines · Paul E. McKenney
Quoted 126 lines · Paul E. McKenney
Quoted 50 lines · Uladzislau Rezki
Quoted 49 lines · Sebastian Andrzej Siewior
Quoted 6 lines · Uladzislau Rezki (Sony)

Add self tests for checking of RCU-tasks API functionality. It covers:
- wait API functions;
- invoking/completion call_rcu_tasks*().

Self-tests are run when CONFIG_PROVE_RCU kernel parameter is set.

I just bisected to this commit. By booting with `threadirqs' I end up with:

[    0.176533] Running RCU-tasks wait API self tests

No stall warning or so.
It boots again with:

init/main.c +2 -0
@@ -1489,6 +1489,7 @@ void __init console_on_rootfs(void)
 	fput(file);
 }
 
+void rcu_tasks_initiate_self_tests(void);
 static noinline void __init kernel_init_freeable(void)
 {
 	/*
@@ -1514,6 +1515,7 @@ static noinline void __init kernel_init_freeable(void)
 
 	rcu_init_tasks_generic();
 	do_pre_smp_initcalls();
+	rcu_tasks_initiate_self_tests();
 	lockup_detector_init();
 
 	smp_init();
kernel/rcu/tasks.h +1 -1
@@ -1266,7 +1266,7 @@ static void test_rcu_tasks_callback(struct rcu_head *rhp)
 	rttd->notrun = true;
 }
 
-static void rcu_tasks_initiate_self_tests(void)
+void rcu_tasks_initiate_self_tests(void)
 {
 	pr_info("Running RCU-tasks wait API self tests\n");
 #ifdef CONFIG_TASKS_RCU
@@ -1322,7 +1322,6 @@ void __init rcu_init_tasks_generic(void)
 #endif
 
Quoted 7 lines
Quoted 7 lines
kernel/rcu/tasks.h +0 -1
 	// Run the self-tests.
-	rcu_tasks_initiate_self_tests();
 }
 
 #else /* #ifdef CONFIG_TASKS_RCU_GENERIC */
Quoted 2 lines

Apologies for the hassle! My testing clearly missed this combination of CONFIG_PROVE_RCU=y and threadirqs=1. :-(

But at least I can easily reproduce this hang as follows:

tools/testing/selftests/rcutorture/bin/kvm.sh --allcpus --duration 2 --configs "TREE03" --kconfig "CONFIG_DEBUG_LOCK_ALLOC=y CONFIG_PROVE_LOCKING=y" --bootargs "threadirqs=1" --trust-make

Sadly, I cannot take your patch because that simply papers over the fact that early boot use of synchronize_rcu_tasks() is broken in this particular configuration, which will likely eventually bite others now that init_kprobes() has been moved earlier in boot:

1b04fa990026 ("rcu-tasks: Move RCU-tasks initialization to before early_initcall()")

Fixes 36dadef23fcc ("kprobes: Init kprobes in early_initcall")
Quoted 31 lines
Quoted 2 lines

Sebastian

We should be able to use call_rcu_tasks() in the *initcall() callbacks. The problem is that, ksoftirqd threads are not spawned by the time when an rcu_init_tasks_generic() is invoked:

init/main.c +1 -1
index c68d784376ca..e6106bb12b2d 100644
@@ -954,7 +954,6 @@ asmlinkage __visible void __init __no_sanitize_address start_kernel(void)
 	rcu_init_nohz();
 	init_timers();
 	hrtimers_init();
-	softirq_init();
 	timekeeping_init();
 
 	/*
@@ -1512,6 +1511,7 @@ static noinline void __init kernel_init_freeable(void)
 
 	init_mm_internals();
 
+	softirq_init();
 	rcu_init_tasks_generic();
 	do_pre_smp_initcalls();
 	lockup_detector_init();
kernel/softirq.c +0 -0
index 9d71046ea247..cafa55c496d0 100644

kernel/softirq.c void __init softirq_init(void) · line 633

Quoted 4 lines
kernel/softirq.c +1 -0
@@ -630,6 +630,7 @@ void __init softirq_init(void)
 			&per_cpu(tasklet_hi_vec, cpu).head;
 	}
 
+	spawn_ksoftirqd();

We need a forward reference to allow this to build, but with that added, my test case passes. Good show!

Quoted 12 lines
kernel/softirq.c +0 -1
 	open_softirq(TASKLET_SOFTIRQ, tasklet_action);
 	open_softirq(HI_SOFTIRQ, tasklet_hi_action);
 }
@@ -732,7 +733,6 @@ static __init int spawn_ksoftirqd(void)
 
 	return 0;
 }
-early_initcall(spawn_ksoftirqd);
 
 /*
  * [ These __weak aliases are kept in a separate compilation unit, so that
Quoted 8 lines
Quoted 6 lines
Quoted 1 line

Any thoughts?

One likely problem is that there are almost certainly parts of the kernel that need softirq_init() to stay roughly where it is. So, is it possible to leave softirq_init() where it is, and to arrange for spawn_ksoftirqd() to be invoked just before rcu_init_tasks_generic() is called?

This still seems worth trying (and doing so is next on my list), but just

And the patch below takes this approach, which also causes the tests to pass.

Thoughts?

Thanx, Paul

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

commit f4cd768e341486655c8c196e1f2b48a4463541f3

Author: Paul E. McKenney <[email protected]>
Date:   Fri Feb 12 16:41:05 2021 -0800

softirq: Don't try waking ksoftirqd before it has been spawned

If there is heavy softirq activity, the softirq system will attempt to awaken ksoftirqd and will stop the traditional back-of-interrupt softirq processing. This is all well and good, but only if the ksoftirqd kthreads already exist, which is not the case during early boot, in which case the system hangs.

One reproducer is as follows:

tools/testing/selftests/rcutorture/bin/kvm.sh --allcpus --duration 2 --configs "TREE03" --kconfig "CONFIG_DEBUG_LOCK_ALLOC=y CONFIG_PROVE_LOCKING=y" --bootargs "threadirqs=1" --trust-make

This commit therefore moves the spawning of the ksoftirqd kthreads earlier in boot. With this change, the above test passes.

include/linux/interrupt.h +2 -0
index bb8ff90..283a02d 100644
@@ -592,6 +592,8 @@ static inline struct task_struct *this_cpu_ksoftirqd(void)
 	return this_cpu_read(ksoftirqd);
 }
 
+int spawn_ksoftirqd(void);
+
 /* Tasklets --- multithreaded analogue of BHs.
 
    This API is deprecated. Please consider using threaded IRQs instead:
init/main.c +1 -0
index c68d784..99835bb 100644
@@ -1512,6 +1512,7 @@ static noinline void __init kernel_init_freeable(void)
 
 	init_mm_internals();
 
+	spawn_ksoftirqd();
 	rcu_init_tasks_generic();
 	do_pre_smp_initcalls();
 	lockup_detector_init();
kernel/softirq.c +1 -2
index 9d71046..45d50d4 100644
@@ -724,7 +724,7 @@ static struct smp_hotplug_thread softirq_threads = {
 	.thread_comm		= "ksoftirqd/%u",
 };
 
-static __init int spawn_ksoftirqd(void)
+__init int spawn_ksoftirqd(void)
 {
 	cpuhp_setup_state_nocalls(CPUHP_SOFTIRQ_DEAD, "softirq:dead", NULL,
 				  takeover_tasklets);
@@ -732,7 +732,6 @@ static __init int spawn_ksoftirqd(void)
 
 	return 0;
 }
-early_initcall(spawn_ksoftirqd);
 
 /*
  * [ These __weak aliases are kept in a separate compilation unit, so that
author maintainer
#16 lore raw

Re: [PATCH 2/2] rcu-tasks: add RCU-tasks self tests

Quoted 210 lines · Paul E. McKenney
Quoted 127 lines · Paul E. McKenney
Quoted 126 lines · Paul E. McKenney
Quoted 50 lines · Uladzislau Rezki
Quoted 49 lines · Sebastian Andrzej Siewior
Quoted 6 lines · Uladzislau Rezki (Sony)

Add self tests for checking of RCU-tasks API functionality. It covers:
- wait API functions;
- invoking/completion call_rcu_tasks*().

Self-tests are run when CONFIG_PROVE_RCU kernel parameter is set.

I just bisected to this commit. By booting with `threadirqs' I end up with:

[    0.176533] Running RCU-tasks wait API self tests

No stall warning or so.
It boots again with:

init/main.c +2 -0
@@ -1489,6 +1489,7 @@ void __init console_on_rootfs(void)
 	fput(file);
 }
 
+void rcu_tasks_initiate_self_tests(void);
 static noinline void __init kernel_init_freeable(void)
 {
 	/*
@@ -1514,6 +1515,7 @@ static noinline void __init kernel_init_freeable(void)
 
 	rcu_init_tasks_generic();
 	do_pre_smp_initcalls();
+	rcu_tasks_initiate_self_tests();
 	lockup_detector_init();
 
 	smp_init();
kernel/rcu/tasks.h +1 -1
@@ -1266,7 +1266,7 @@ static void test_rcu_tasks_callback(struct rcu_head *rhp)
 	rttd->notrun = true;
 }
 
-static void rcu_tasks_initiate_self_tests(void)
+void rcu_tasks_initiate_self_tests(void)
 {
 	pr_info("Running RCU-tasks wait API self tests\n");
 #ifdef CONFIG_TASKS_RCU
@@ -1322,7 +1322,6 @@ void __init rcu_init_tasks_generic(void)
 #endif
 
Quoted 7 lines
Quoted 7 lines
kernel/rcu/tasks.h +0 -1
 	// Run the self-tests.
-	rcu_tasks_initiate_self_tests();
 }
 
 #else /* #ifdef CONFIG_TASKS_RCU_GENERIC */
Quoted 2 lines

Apologies for the hassle! My testing clearly missed this combination of CONFIG_PROVE_RCU=y and threadirqs=1. :-(

But at least I can easily reproduce this hang as follows:

tools/testing/selftests/rcutorture/bin/kvm.sh --allcpus --duration 2 --configs "TREE03" --kconfig "CONFIG_DEBUG_LOCK_ALLOC=y CONFIG_PROVE_LOCKING=y" --bootargs "threadirqs=1" --trust-make

Sadly, I cannot take your patch because that simply papers over the fact that early boot use of synchronize_rcu_tasks() is broken in this particular configuration, which will likely eventually bite others now that init_kprobes() has been moved earlier in boot:

1b04fa990026 ("rcu-tasks: Move RCU-tasks initialization to before early_initcall()")

Fixes 36dadef23fcc ("kprobes: Init kprobes in early_initcall")
Quoted 31 lines
Quoted 2 lines

Sebastian

We should be able to use call_rcu_tasks() in the *initcall() callbacks. The problem is that, ksoftirqd threads are not spawned by the time when an rcu_init_tasks_generic() is invoked:

init/main.c +1 -1
index c68d784376ca..e6106bb12b2d 100644
@@ -954,7 +954,6 @@ asmlinkage __visible void __init __no_sanitize_address start_kernel(void)
 	rcu_init_nohz();
 	init_timers();
 	hrtimers_init();
-	softirq_init();
 	timekeeping_init();
 
 	/*
@@ -1512,6 +1511,7 @@ static noinline void __init kernel_init_freeable(void)
 
 	init_mm_internals();
 
+	softirq_init();
 	rcu_init_tasks_generic();
 	do_pre_smp_initcalls();
 	lockup_detector_init();
kernel/softirq.c +0 -0
index 9d71046ea247..cafa55c496d0 100644

kernel/softirq.c void __init softirq_init(void) · line 633

Quoted 4 lines
kernel/softirq.c +1 -0
@@ -630,6 +630,7 @@ void __init softirq_init(void)
 			&per_cpu(tasklet_hi_vec, cpu).head;
 	}
 
+	spawn_ksoftirqd();

We need a forward reference to allow this to build, but with that added, my test case passes. Good show!

Quoted 12 lines
kernel/softirq.c +0 -1
 	open_softirq(TASKLET_SOFTIRQ, tasklet_action);
 	open_softirq(HI_SOFTIRQ, tasklet_hi_action);
 }
@@ -732,7 +733,6 @@ static __init int spawn_ksoftirqd(void)
 
 	return 0;
 }
-early_initcall(spawn_ksoftirqd);
 
 /*
  * [ These __weak aliases are kept in a separate compilation unit, so that
Quoted 8 lines
Quoted 6 lines
Quoted 1 line

Any thoughts?

One likely problem is that there are almost certainly parts of the kernel that need softirq_init() to stay roughly where it is. So, is it possible to leave softirq_init() where it is, and to arrange for spawn_ksoftirqd() to be invoked just before rcu_init_tasks_generic() is called?

This still seems worth trying (and doing so is next on my list), but just

And the patch below takes this approach, which also causes the tests to pass.

Thoughts?

Thanx, Paul

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

commit f4cd768e341486655c8c196e1f2b48a4463541f3

Author: Paul E. McKenney <[email protected]>
Date:   Fri Feb 12 16:41:05 2021 -0800

softirq: Don't try waking ksoftirqd before it has been spawned

If there is heavy softirq activity, the softirq system will attempt to awaken ksoftirqd and will stop the traditional back-of-interrupt softirq processing. This is all well and good, but only if the ksoftirqd kthreads already exist, which is not the case during early boot, in which case the system hangs.

One reproducer is as follows:

tools/testing/selftests/rcutorture/bin/kvm.sh --allcpus --duration 2 --configs "TREE03" --kconfig "CONFIG_DEBUG_LOCK_ALLOC=y CONFIG_PROVE_LOCKING=y" --bootargs "threadirqs=1" --trust-make

This commit therefore moves the spawning of the ksoftirqd kthreads earlier in boot. With this change, the above test passes.

include/linux/interrupt.h +2 -0
index bb8ff90..283a02d 100644
@@ -592,6 +592,8 @@ static inline struct task_struct *this_cpu_ksoftirqd(void)
 	return this_cpu_read(ksoftirqd);
 }
 
+int spawn_ksoftirqd(void);
+
 /* Tasklets --- multithreaded analogue of BHs.
 
    This API is deprecated. Please consider using threaded IRQs instead:
init/main.c +1 -0
index c68d784..99835bb 100644
@@ -1512,6 +1512,7 @@ static noinline void __init kernel_init_freeable(void)
 
 	init_mm_internals();
 
+	spawn_ksoftirqd();
 	rcu_init_tasks_generic();
 	do_pre_smp_initcalls();
 	lockup_detector_init();
kernel/softirq.c +1 -1
index 9d71046..45d50d4 100644
@@ -724,7 +724,7 @@ static struct smp_hotplug_thread softirq_threads = {
 	.thread_comm		= "ksoftirqd/%u",
 };
 
-static __init int spawn_ksoftirqd(void)
+__init int spawn_ksoftirqd(void)
 {
 	cpuhp_setup_state_nocalls(CPUHP_SOFTIRQ_DEAD, "softirq:dead", NULL,
 				  takeover_tasklets);

kernel/softirq.c static __init int spawn_ksoftirqd(void) · line 737

Quoted 7 lines
kernel/softirq.c +0 -1
@@ -732,7 +732,6 @@ static __init int spawn_ksoftirqd(void)
 
 	return 0;
 }
-early_initcall(spawn_ksoftirqd);
 
 /*
  * [ These __weak aliases are kept in a separate compilation unit, so that

I thought about this approach as a first step how to fix it, but then came up with moving the spawn_ksoftirqd(void); into the softirq_init() to make it consolidated at one place and not spread.

Then moving the softirq_init() down may cause other drawbacks, like you mentioned if somebody needs it earlier.

I agree with your approach. Invoking the spawn_ksoftirqd() before the rcu_init_tasks_generic() makes it safe. At least it prevents other parts to be broken comparing with touching and moving softirq_init().

--
Vlad Rezki

maintainer
#17 lore raw

Re: [PATCH 2/2] rcu-tasks: add RCU-tasks self tests

Quoted 222 lines · Uladzislau Rezki
Quoted 210 lines · Paul E. McKenney
Quoted 127 lines · Paul E. McKenney
Quoted 126 lines · Paul E. McKenney
Quoted 50 lines · Uladzislau Rezki
Quoted 49 lines · Sebastian Andrzej Siewior
Quoted 6 lines · Uladzislau Rezki (Sony)

Add self tests for checking of RCU-tasks API functionality. It covers:
- wait API functions;
- invoking/completion call_rcu_tasks*().

Self-tests are run when CONFIG_PROVE_RCU kernel parameter is set.

I just bisected to this commit. By booting with `threadirqs' I end up with:

[    0.176533] Running RCU-tasks wait API self tests

No stall warning or so.
It boots again with:

init/main.c +2 -0
@@ -1489,6 +1489,7 @@ void __init console_on_rootfs(void)
 	fput(file);
 }
 
+void rcu_tasks_initiate_self_tests(void);
 static noinline void __init kernel_init_freeable(void)
 {
 	/*
@@ -1514,6 +1515,7 @@ static noinline void __init kernel_init_freeable(void)
 
 	rcu_init_tasks_generic();
 	do_pre_smp_initcalls();
+	rcu_tasks_initiate_self_tests();
 	lockup_detector_init();
 
 	smp_init();
kernel/rcu/tasks.h +1 -1
@@ -1266,7 +1266,7 @@ static void test_rcu_tasks_callback(struct rcu_head *rhp)
 	rttd->notrun = true;
 }
 
-static void rcu_tasks_initiate_self_tests(void)
+void rcu_tasks_initiate_self_tests(void)
 {
 	pr_info("Running RCU-tasks wait API self tests\n");
 #ifdef CONFIG_TASKS_RCU
@@ -1322,7 +1322,6 @@ void __init rcu_init_tasks_generic(void)
 #endif
 
Quoted 7 lines
Quoted 7 lines
kernel/rcu/tasks.h +0 -1
 	// Run the self-tests.
-	rcu_tasks_initiate_self_tests();
 }
 
 #else /* #ifdef CONFIG_TASKS_RCU_GENERIC */
Quoted 2 lines

Apologies for the hassle! My testing clearly missed this combination of CONFIG_PROVE_RCU=y and threadirqs=1. :-(

But at least I can easily reproduce this hang as follows:

tools/testing/selftests/rcutorture/bin/kvm.sh --allcpus --duration 2 --configs "TREE03" --kconfig "CONFIG_DEBUG_LOCK_ALLOC=y CONFIG_PROVE_LOCKING=y" --bootargs "threadirqs=1" --trust-make

Sadly, I cannot take your patch because that simply papers over the fact that early boot use of synchronize_rcu_tasks() is broken in this particular configuration, which will likely eventually bite others now that init_kprobes() has been moved earlier in boot:

1b04fa990026 ("rcu-tasks: Move RCU-tasks initialization to before early_initcall()")

Fixes 36dadef23fcc ("kprobes: Init kprobes in early_initcall")
Quoted 31 lines
Quoted 2 lines

Sebastian

We should be able to use call_rcu_tasks() in the *initcall() callbacks. The problem is that, ksoftirqd threads are not spawned by the time when an rcu_init_tasks_generic() is invoked:

init/main.c +1 -1
index c68d784376ca..e6106bb12b2d 100644
@@ -954,7 +954,6 @@ asmlinkage __visible void __init __no_sanitize_address start_kernel(void)
 	rcu_init_nohz();
 	init_timers();
 	hrtimers_init();
-	softirq_init();
 	timekeeping_init();
 
 	/*
@@ -1512,6 +1511,7 @@ static noinline void __init kernel_init_freeable(void)
 
 	init_mm_internals();
 
+	softirq_init();
 	rcu_init_tasks_generic();
 	do_pre_smp_initcalls();
 	lockup_detector_init();
kernel/softirq.c +0 -0
index 9d71046ea247..cafa55c496d0 100644

kernel/softirq.c void __init softirq_init(void) · line 633

Quoted 4 lines
kernel/softirq.c +1 -0
@@ -630,6 +630,7 @@ void __init softirq_init(void)
 			&per_cpu(tasklet_hi_vec, cpu).head;
 	}
 
+	spawn_ksoftirqd();

We need a forward reference to allow this to build, but with that added, my test case passes. Good show!

Quoted 12 lines
kernel/softirq.c +0 -1
 	open_softirq(TASKLET_SOFTIRQ, tasklet_action);
 	open_softirq(HI_SOFTIRQ, tasklet_hi_action);
 }
@@ -732,7 +733,6 @@ static __init int spawn_ksoftirqd(void)
 
 	return 0;
 }
-early_initcall(spawn_ksoftirqd);
 
 /*
  * [ These __weak aliases are kept in a separate compilation unit, so that
Quoted 8 lines
Quoted 6 lines
Quoted 1 line

Any thoughts?

One likely problem is that there are almost certainly parts of the kernel that need softirq_init() to stay roughly where it is. So, is it possible to leave softirq_init() where it is, and to arrange for spawn_ksoftirqd() to be invoked just before rcu_init_tasks_generic() is called?

This still seems worth trying (and doing so is next on my list), but just

And the patch below takes this approach, which also causes the tests to pass.

Thoughts?

Thanx, Paul

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

commit f4cd768e341486655c8c196e1f2b48a4463541f3

Author: Paul E. McKenney <[email protected]>
Date:   Fri Feb 12 16:41:05 2021 -0800

softirq: Don't try waking ksoftirqd before it has been spawned

If there is heavy softirq activity, the softirq system will attempt to awaken ksoftirqd and will stop the traditional back-of-interrupt softirq processing. This is all well and good, but only if the ksoftirqd kthreads already exist, which is not the case during early boot, in which case the system hangs.

One reproducer is as follows:

tools/testing/selftests/rcutorture/bin/kvm.sh --allcpus --duration 2 --configs "TREE03" --kconfig "CONFIG_DEBUG_LOCK_ALLOC=y CONFIG_PROVE_LOCKING=y" --bootargs "threadirqs=1" --trust-make

This commit therefore moves the spawning of the ksoftirqd kthreads earlier in boot. With this change, the above test passes.

include/linux/interrupt.h +2 -0
index bb8ff90..283a02d 100644
@@ -592,6 +592,8 @@ static inline struct task_struct *this_cpu_ksoftirqd(void)
 	return this_cpu_read(ksoftirqd);
 }
 
+int spawn_ksoftirqd(void);
+
 /* Tasklets --- multithreaded analogue of BHs.
 
    This API is deprecated. Please consider using threaded IRQs instead:
init/main.c +1 -0
index c68d784..99835bb 100644
@@ -1512,6 +1512,7 @@ static noinline void __init kernel_init_freeable(void)
 
 	init_mm_internals();
 
+	spawn_ksoftirqd();
 	rcu_init_tasks_generic();
 	do_pre_smp_initcalls();
 	lockup_detector_init();
kernel/softirq.c +1 -1
index 9d71046..45d50d4 100644
@@ -724,7 +724,7 @@ static struct smp_hotplug_thread softirq_threads = {
 	.thread_comm		= "ksoftirqd/%u",
 };
 
-static __init int spawn_ksoftirqd(void)
+__init int spawn_ksoftirqd(void)
 {
 	cpuhp_setup_state_nocalls(CPUHP_SOFTIRQ_DEAD, "softirq:dead", NULL,
 				  takeover_tasklets);

kernel/softirq.c static __init int spawn_ksoftirqd(void) · line 737

Quoted 7 lines
kernel/softirq.c +0 -1
@@ -732,7 +732,6 @@ static __init int spawn_ksoftirqd(void)
 
 	return 0;
 }
-early_initcall(spawn_ksoftirqd);
 
 /*
  * [ These __weak aliases are kept in a separate compilation unit, so that

I thought about this approach as a first step how to fix it, but then came up with moving the spawn_ksoftirqd(void); into the softirq_init() to make it consolidated at one place and not spread.

Quoted 6 lines

Then moving the softirq_init() down may cause other drawbacks, like you mentioned if somebody needs it earlier.

I agree with your approach. Invoking the spawn_ksoftirqd() before the rcu_init_tasks_generic() makes it safe. At least it prevents other parts to be broken comparing with touching and moving softirq_init().

Glad you like it! But let's see which (if any) of these patches solves the problem for Sebastian.

Thanx, Paul

author maintainer
#18 lore raw

Re: [PATCH 2/2] rcu-tasks: add RCU-tasks self tests

Quoted 226 lines · Paul E. McKenney
Quoted 225 lines · Uladzislau Rezki
Quoted 210 lines · Paul E. McKenney
Quoted 127 lines · Paul E. McKenney
Quoted 126 lines · Paul E. McKenney
Quoted 50 lines · Uladzislau Rezki
Quoted 49 lines · Sebastian Andrzej Siewior
Quoted 6 lines · Uladzislau Rezki (Sony)

Add self tests for checking of RCU-tasks API functionality. It covers:
- wait API functions;
- invoking/completion call_rcu_tasks*().

Self-tests are run when CONFIG_PROVE_RCU kernel parameter is set.

I just bisected to this commit. By booting with `threadirqs' I end up with:

[    0.176533] Running RCU-tasks wait API self tests

No stall warning or so.
It boots again with:

init/main.c +2 -0
@@ -1489,6 +1489,7 @@ void __init console_on_rootfs(void)
 	fput(file);
 }
 
+void rcu_tasks_initiate_self_tests(void);
 static noinline void __init kernel_init_freeable(void)
 {
 	/*
@@ -1514,6 +1515,7 @@ static noinline void __init kernel_init_freeable(void)
 
 	rcu_init_tasks_generic();
 	do_pre_smp_initcalls();
+	rcu_tasks_initiate_self_tests();
 	lockup_detector_init();
 
 	smp_init();
kernel/rcu/tasks.h +1 -1
@@ -1266,7 +1266,7 @@ static void test_rcu_tasks_callback(struct rcu_head *rhp)
 	rttd->notrun = true;
 }
 
-static void rcu_tasks_initiate_self_tests(void)
+void rcu_tasks_initiate_self_tests(void)
 {
 	pr_info("Running RCU-tasks wait API self tests\n");
 #ifdef CONFIG_TASKS_RCU
@@ -1322,7 +1322,6 @@ void __init rcu_init_tasks_generic(void)
 #endif
 
Quoted 7 lines
Quoted 7 lines
kernel/rcu/tasks.h +0 -1
 	// Run the self-tests.
-	rcu_tasks_initiate_self_tests();
 }
 
 #else /* #ifdef CONFIG_TASKS_RCU_GENERIC */
Quoted 2 lines

Apologies for the hassle! My testing clearly missed this combination of CONFIG_PROVE_RCU=y and threadirqs=1. :-(

But at least I can easily reproduce this hang as follows:

tools/testing/selftests/rcutorture/bin/kvm.sh --allcpus --duration 2 --configs "TREE03" --kconfig "CONFIG_DEBUG_LOCK_ALLOC=y CONFIG_PROVE_LOCKING=y" --bootargs "threadirqs=1" --trust-make

Sadly, I cannot take your patch because that simply papers over the fact that early boot use of synchronize_rcu_tasks() is broken in this particular configuration, which will likely eventually bite others now that init_kprobes() has been moved earlier in boot:

1b04fa990026 ("rcu-tasks: Move RCU-tasks initialization to before early_initcall()")

Fixes 36dadef23fcc ("kprobes: Init kprobes in early_initcall")
Quoted 31 lines
Quoted 2 lines

Sebastian

We should be able to use call_rcu_tasks() in the *initcall() callbacks. The problem is that, ksoftirqd threads are not spawned by the time when an rcu_init_tasks_generic() is invoked:

init/main.c +1 -1
index c68d784376ca..e6106bb12b2d 100644
@@ -954,7 +954,6 @@ asmlinkage __visible void __init __no_sanitize_address start_kernel(void)
 	rcu_init_nohz();
 	init_timers();
 	hrtimers_init();
-	softirq_init();
 	timekeeping_init();
 
 	/*
@@ -1512,6 +1511,7 @@ static noinline void __init kernel_init_freeable(void)
 
 	init_mm_internals();
 
+	softirq_init();
 	rcu_init_tasks_generic();
 	do_pre_smp_initcalls();
 	lockup_detector_init();
kernel/softirq.c +0 -0
index 9d71046ea247..cafa55c496d0 100644

kernel/softirq.c void __init softirq_init(void) · line 633

Quoted 4 lines
kernel/softirq.c +1 -0
@@ -630,6 +630,7 @@ void __init softirq_init(void)
 			&per_cpu(tasklet_hi_vec, cpu).head;
 	}
 
+	spawn_ksoftirqd();

We need a forward reference to allow this to build, but with that added, my test case passes. Good show!

Quoted 12 lines
kernel/softirq.c +0 -1
 	open_softirq(TASKLET_SOFTIRQ, tasklet_action);
 	open_softirq(HI_SOFTIRQ, tasklet_hi_action);
 }
@@ -732,7 +733,6 @@ static __init int spawn_ksoftirqd(void)
 
 	return 0;
 }
-early_initcall(spawn_ksoftirqd);
 
 /*
  * [ These __weak aliases are kept in a separate compilation unit, so that
Quoted 8 lines
Quoted 6 lines
Quoted 1 line

Any thoughts?

One likely problem is that there are almost certainly parts of the kernel that need softirq_init() to stay roughly where it is. So, is it possible to leave softirq_init() where it is, and to arrange for spawn_ksoftirqd() to be invoked just before rcu_init_tasks_generic() is called?

This still seems worth trying (and doing so is next on my list), but just

And the patch below takes this approach, which also causes the tests to pass.

Thoughts?

Thanx, Paul

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

commit f4cd768e341486655c8c196e1f2b48a4463541f3

Author: Paul E. McKenney <[email protected]>
Date:   Fri Feb 12 16:41:05 2021 -0800

softirq: Don't try waking ksoftirqd before it has been spawned

If there is heavy softirq activity, the softirq system will attempt to awaken ksoftirqd and will stop the traditional back-of-interrupt softirq processing. This is all well and good, but only if the ksoftirqd kthreads already exist, which is not the case during early boot, in which case the system hangs.

One reproducer is as follows:

tools/testing/selftests/rcutorture/bin/kvm.sh --allcpus --duration 2 --configs "TREE03" --kconfig "CONFIG_DEBUG_LOCK_ALLOC=y CONFIG_PROVE_LOCKING=y" --bootargs "threadirqs=1" --trust-make

This commit therefore moves the spawning of the ksoftirqd kthreads earlier in boot. With this change, the above test passes.

include/linux/interrupt.h +2 -0
index bb8ff90..283a02d 100644
@@ -592,6 +592,8 @@ static inline struct task_struct *this_cpu_ksoftirqd(void)
 	return this_cpu_read(ksoftirqd);
 }
 
+int spawn_ksoftirqd(void);
+
 /* Tasklets --- multithreaded analogue of BHs.
 
    This API is deprecated. Please consider using threaded IRQs instead:
init/main.c +1 -0
index c68d784..99835bb 100644
@@ -1512,6 +1512,7 @@ static noinline void __init kernel_init_freeable(void)
 
 	init_mm_internals();
 
+	spawn_ksoftirqd();
 	rcu_init_tasks_generic();
 	do_pre_smp_initcalls();
 	lockup_detector_init();
kernel/softirq.c +1 -1
index 9d71046..45d50d4 100644
@@ -724,7 +724,7 @@ static struct smp_hotplug_thread softirq_threads = {
 	.thread_comm		= "ksoftirqd/%u",
 };
 
-static __init int spawn_ksoftirqd(void)
+__init int spawn_ksoftirqd(void)
 {
 	cpuhp_setup_state_nocalls(CPUHP_SOFTIRQ_DEAD, "softirq:dead", NULL,
 				  takeover_tasklets);

kernel/softirq.c static __init int spawn_ksoftirqd(void) · line 737

Quoted 7 lines
kernel/softirq.c +0 -1
@@ -732,7 +732,6 @@ static __init int spawn_ksoftirqd(void)
 
 	return 0;
 }
-early_initcall(spawn_ksoftirqd);
 
 /*
  * [ These __weak aliases are kept in a separate compilation unit, so that

I thought about this approach as a first step how to fix it, but then came up with moving the spawn_ksoftirqd(void); into the softirq_init() to make it consolidated at one place and not spread.

Then moving the softirq_init() down may cause other drawbacks, like you mentioned if somebody needs it earlier.

Quoted 7 lines
Quoted 3 lines

I agree with your approach. Invoking the spawn_ksoftirqd() before the rcu_init_tasks_generic() makes it safe. At least it prevents other parts to be broken comparing with touching and moving softirq_init().

Glad you like it! But let's see which (if any) of these patches solves the problem for Sebastian.

I tried to reproduce it on my box and i succeed. Both patches solve it for me. But let's see if it fixes Sebastian setup :)

--
Vlad Rezki

#19 lore raw

Re: [PATCH 2/2] rcu-tasks: add RCU-tasks self tests

In reply to Paul E. McKenney
Quoted 2 lines · Paul E. McKenney

Glad you like it! But let's see which (if any) of these patches solves the problem for Sebastian.

Looking at that, is there any reason for doing this that can not be solved by moving the self-test a little later? Maybe once we reached at least SYSTEM_SCHEDULING?
This happens now even before lockdep is up or the console is registered. So if something bad happens, you end up with a blank terminal.

There is nothing else that early in the boot process that requires working softirq. The only exception to this is wait_task_inactive() which is used while starting a new thread (including the ksoftirqd) which is why it was moved to schedule_hrtimeout().

Quoted 1 line

Thanx, Paul

Sebastian

maintainer
#20 lore raw

Re: [PATCH 2/2] rcu-tasks: add RCU-tasks self tests

Quoted 7 lines · Sebastian Andrzej Siewior
Quoted 2 lines · Paul E. McKenney

Glad you like it! But let's see which (if any) of these patches solves the problem for Sebastian.

Looking at that, is there any reason for doing this that can not be solved by moving the self-test a little later? Maybe once we reached at least SYSTEM_SCHEDULING?

One problem is that ksoftirqd and the kprobes use are early_initcall(), so we cannot count on ksoftirqd being spawned when kprobes first uses synchronize_rcu_tasks(). Moving the selftest later won't fix this problem, but rather just paper it over.

Quoted 2 lines

This happens now even before lockdep is up or the console is registered. So if something bad happens, you end up with a blank terminal.

I was getting a splat, but I could easily believe that there are configurations where the hang is totally silent. In other words, I do agree that this needs a proper fix. All we need do is work out an agreeable value of "proper". ;-)

Quoted 4 lines

There is nothing else that early in the boot process that requires working softirq. The only exception to this is wait_task_inactive() which is used while starting a new thread (including the ksoftirqd) which is why it was moved to schedule_hrtimeout().

Moving kprobes initialization to early_initcall() [1] means that there can be a call to synchronize_rcu_tasks() before the current spawning of ksoftirqd. Because synchronize_rcu_tasks() needs timers to work, it needs softirq to work. I know two straightforward ways to make that happen:

1. Spawn ksoftirqd earlier.

2. Suppress attempts to awaken ksoftirqd before it exists,
forcing all ksoftirq execution on the back of interrupts.

Uladzislau and I each produced patches for #1, and I produced a patch for #2.

The only other option I know of is to push the call to init_kprobes() later in the boot sequence, perhaps to its original subsys_initcall(), or maybe only as late as core_initcall(). I added Masami and Steve on CC for their thoughts on this.

Is there some other proper fix that I am missing?

Thanx, Paul

[1] 36dadef23fcc ("kprobes: Init kprobes in early_initcall")

maintainer
#21 lore raw

Re: [PATCH 2/2] rcu-tasks: add RCU-tasks self tests

Quoted 40 lines · On Tue, 16 Feb 2021 09:30:03 -0800 "Paul E. McKenney" <[email protected]>…
Quoted 7 lines · Sebastian Andrzej Siewior
Quoted 2 lines · Paul E. McKenney

Glad you like it! But let's see which (if any) of these patches solves the problem for Sebastian.

Looking at that, is there any reason for doing this that can not be solved by moving the self-test a little later? Maybe once we reached at least SYSTEM_SCHEDULING?

One problem is that ksoftirqd and the kprobes use are early_initcall(), so we cannot count on ksoftirqd being spawned when kprobes first uses synchronize_rcu_tasks(). Moving the selftest later won't fix this problem, but rather just paper it over.

Quoted 2 lines

This happens now even before lockdep is up or the console is registered. So if something bad happens, you end up with a blank terminal.

I was getting a splat, but I could easily believe that there are configurations where the hang is totally silent. In other words, I do agree that this needs a proper fix. All we need do is work out an agreeable value of "proper". ;-)

Quoted 4 lines

There is nothing else that early in the boot process that requires working softirq. The only exception to this is wait_task_inactive() which is used while starting a new thread (including the ksoftirqd) which is why it was moved to schedule_hrtimeout().

Moving kprobes initialization to early_initcall() [1] means that there can be a call to synchronize_rcu_tasks() before the current spawning of ksoftirqd. Because synchronize_rcu_tasks() needs timers to work, it needs softirq to work. I know two straightforward ways to make that happen:

1. Spawn ksoftirqd earlier.

2. Suppress attempts to awaken ksoftirqd before it exists,
forcing all ksoftirq execution on the back of interrupts.

Uladzislau and I each produced patches for #1, and I produced a patch for #2.

Quoted 6 lines

The only other option I know of is to push the call to init_kprobes() later in the boot sequence, perhaps to its original subsys_initcall(), or maybe only as late as core_initcall(). I added Masami and Steve on CC for their thoughts on this.

Is there some other proper fix that I am missing?

Oh, I missed that the synchronize_rcu_tasks() will be involved the kprobes in early stage. Does the problem only exist in the synchronize_rcu_tasks() instead of synchronize_rcu()? If so I can just stop optimizer in early stage because I just want to enable kprobes in early stage, but not optprobes.

Does the following patch help?

From e5fafcda3ff918cd52619f795a3f22fb95c72b11 Mon Sep 17 00:00:00 2001
From: Masami Hiramatsu <[email protected]>
Date: Wed, 17 Feb 2021 23:35:20 +0900
Subject: [PATCH] kprobes: Fix to delay the kprobes jump optimization

Since the kprobes jump optimization involves synchronize_rcu_tasks() which depends on the ksoftirqd, that can not be enabled at the early_initcall() boot stage. So this makes the kprobe optimization disabled in the early_initcall() and enables it in subsys_initcall().

Note that non-optimized kprobes is still available after early_initcall(). Only jump optimization is delayed.

Fixes 36dadef23fcc ("kprobes: Init kprobes in early_initcall")
---
 kernel/kprobes.c | 31 +++++++++++++++++++++----------
 1 file changed, 21 insertions(+), 10 deletions(-)
kernel/kprobes.c +21 -10
index d5a3eb74a657..779d8322e307 100644
@@ -861,7 +861,6 @@ static void try_to_optimize_kprobe(struct kprobe *p)
 	cpus_read_unlock();
 }
 
-#ifdef CONFIG_SYSCTL
 static void optimize_all_kprobes(void)
 {
 	struct hlist_head *head;
@@ -887,6 +886,7 @@ static void optimize_all_kprobes(void)
 	mutex_unlock(&kprobe_mutex);
 }
 
+#ifdef CONFIG_SYSCTL
 static void unoptimize_all_kprobes(void)
 {
 	struct hlist_head *head;
@@ -2497,18 +2497,14 @@ static int __init init_kprobes(void)
 		}
 	}
 
-#if defined(CONFIG_OPTPROBES)
-#if defined(__ARCH_WANT_KPROBES_INSN_SLOT)
-	/* Init kprobe_optinsn_slots */
-	kprobe_optinsn_slots.insn_size = MAX_OPTINSN_SIZE;
-#endif
-	/* By default, kprobes can be optimized */
-	kprobes_allow_optimization = true;
-#endif
-
 	/* By default, kprobes are armed */
 	kprobes_all_disarmed = false;
 
+#if defined(CONFIG_OPTPROBES) && defined(__ARCH_WANT_KPROBES_INSN_SLOT)
+	/* Init kprobe_optinsn_slots for allocation */
+	kprobe_optinsn_slots.insn_size = MAX_OPTINSN_SIZE;
+#endif
+
 	err = arch_init_kprobes();
 	if (!err)
 		err = register_die_notifier(&kprobe_exceptions_nb);
@@ -2523,6 +2519,21 @@ static int __init init_kprobes(void)
 }
 early_initcall(init_kprobes);
 
+#if defined(CONFIG_OPTPROBES)
+static int __init init_optprobes(void)
+{
+	/*
+	 * Enable kprobe optimization - this kicks the optimizer which
+	 * depends on synchronize_rcu_tasks() and ksoftirqd, that is
+	 * not spawned in early initcall. So delay the optimization.
+	 */
+	optimize_all_kprobes();
+
+	return 0;
+}
+subsys_initcall(init_optprobes);
+#endif
+
 #ifdef CONFIG_DEBUG_FS
 static void report_probe(struct seq_file *pi, struct kprobe *p,
 		const char *sym, int offset, char *modname, struct kprobe *pp)
Signature · 5 lines
2.25.1


-- 
Masami Hiramatsu <[email protected]>
maintainer
#22 lore raw

Re: [PATCH 2/2] rcu-tasks: add RCU-tasks self tests

Quoted 48 lines · Masami Hiramatsu
Quoted 45 lines · On Tue, 16 Feb 2021 09:30:03 -0800 "Paul E. McKenney" <[email protected]>…
Quoted 7 lines · Sebastian Andrzej Siewior
Quoted 2 lines · Paul E. McKenney

Glad you like it! But let's see which (if any) of these patches solves the problem for Sebastian.

Looking at that, is there any reason for doing this that can not be solved by moving the self-test a little later? Maybe once we reached at least SYSTEM_SCHEDULING?

One problem is that ksoftirqd and the kprobes use are early_initcall(), so we cannot count on ksoftirqd being spawned when kprobes first uses synchronize_rcu_tasks(). Moving the selftest later won't fix this problem, but rather just paper it over.

Quoted 2 lines

This happens now even before lockdep is up or the console is registered. So if something bad happens, you end up with a blank terminal.

I was getting a splat, but I could easily believe that there are configurations where the hang is totally silent. In other words, I do agree that this needs a proper fix. All we need do is work out an agreeable value of "proper". ;-)

Quoted 4 lines

There is nothing else that early in the boot process that requires working softirq. The only exception to this is wait_task_inactive() which is used while starting a new thread (including the ksoftirqd) which is why it was moved to schedule_hrtimeout().

Moving kprobes initialization to early_initcall() [1] means that there can be a call to synchronize_rcu_tasks() before the current spawning of ksoftirqd. Because synchronize_rcu_tasks() needs timers to work, it needs softirq to work. I know two straightforward ways to make that happen:

1. Spawn ksoftirqd earlier.

2. Suppress attempts to awaken ksoftirqd before it exists,
forcing all ksoftirq execution on the back of interrupts.

Uladzislau and I each produced patches for #1, and I produced a patch for #2.

The only other option I know of is to push the call to init_kprobes() later in the boot sequence, perhaps to its original subsys_initcall(), or maybe only as late as core_initcall(). I added Masami and Steve on CC for their thoughts on this.

Quoted 8 lines
Quoted 1 line

Is there some other proper fix that I am missing?

Oh, I missed that the synchronize_rcu_tasks() will be involved the kprobes in early stage. Does the problem only exist in the synchronize_rcu_tasks() instead of synchronize_rcu()? If so I can just stop optimizer in early stage because I just want to enable kprobes in early stage, but not optprobes.

Does the following patch help?

It does look to me like it would! I clearly should have asked you about this a couple of months ago. ;-)

The proof of the pudding would be whether the powerpc guys can apply this to v5.10-rc7 and have their kernel come up without hanging at boot.

Thanx, Paul

Quoted 91 lines
Quoted 1 line

From e5fafcda3ff918cd52619f795a3f22fb95c72b11 Mon Sep 17 00:00:00 2001

From: Masami Hiramatsu <[email protected]>
Date: Wed, 17 Feb 2021 23:35:20 +0900
Subject: [PATCH] kprobes: Fix to delay the kprobes jump optimization

Since the kprobes jump optimization involves synchronize_rcu_tasks() which depends on the ksoftirqd, that can not be enabled at the early_initcall() boot stage. So this makes the kprobe optimization disabled in the early_initcall() and enables it in subsys_initcall().

Note that non-optimized kprobes is still available after early_initcall(). Only jump optimization is delayed.

Fixes 36dadef23fcc ("kprobes: Init kprobes in early_initcall")
---
 kernel/kprobes.c | 31 +++++++++++++++++++++----------
 1 file changed, 21 insertions(+), 10 deletions(-)
kernel/kprobes.c +21 -10
index d5a3eb74a657..779d8322e307 100644
@@ -861,7 +861,6 @@ static void try_to_optimize_kprobe(struct kprobe *p)
 	cpus_read_unlock();
 }
 
-#ifdef CONFIG_SYSCTL
 static void optimize_all_kprobes(void)
 {
 	struct hlist_head *head;
@@ -887,6 +886,7 @@ static void optimize_all_kprobes(void)
 	mutex_unlock(&kprobe_mutex);
 }
 
+#ifdef CONFIG_SYSCTL
 static void unoptimize_all_kprobes(void)
 {
 	struct hlist_head *head;
@@ -2497,18 +2497,14 @@ static int __init init_kprobes(void)
 		}
 	}
 
-#if defined(CONFIG_OPTPROBES)
-#if defined(__ARCH_WANT_KPROBES_INSN_SLOT)
-	/* Init kprobe_optinsn_slots */
-	kprobe_optinsn_slots.insn_size = MAX_OPTINSN_SIZE;
-#endif
-	/* By default, kprobes can be optimized */
-	kprobes_allow_optimization = true;
-#endif
-
 	/* By default, kprobes are armed */
 	kprobes_all_disarmed = false;
 
+#if defined(CONFIG_OPTPROBES) && defined(__ARCH_WANT_KPROBES_INSN_SLOT)
+	/* Init kprobe_optinsn_slots for allocation */
+	kprobe_optinsn_slots.insn_size = MAX_OPTINSN_SIZE;
+#endif
+
 	err = arch_init_kprobes();
 	if (!err)
 		err = register_die_notifier(&kprobe_exceptions_nb);
@@ -2523,6 +2519,21 @@ static int __init init_kprobes(void)
 }
 early_initcall(init_kprobes);
 
+#if defined(CONFIG_OPTPROBES)
+static int __init init_optprobes(void)
+{
+	/*
+	 * Enable kprobe optimization - this kicks the optimizer which
+	 * depends on synchronize_rcu_tasks() and ksoftirqd, that is
+	 * not spawned in early initcall. So delay the optimization.
+	 */
+	optimize_all_kprobes();
+
+	return 0;
+}
+subsys_initcall(init_optprobes);
+#endif
+
 #ifdef CONFIG_DEBUG_FS
 static void report_probe(struct seq_file *pi, struct kprobe *p,
 		const char *sym, int offset, char *modname, struct kprobe *pp)
Signature · 5 lines
2.25.1


-- 
Masami Hiramatsu <[email protected]>
maintainer
#23 lore raw

Re: [PATCH 2/2] rcu-tasks: add RCU-tasks self tests

Quoted 20 lines · On Wed, 17 Feb 2021 10:17:38 -0800 "Paul E. McKenney" <[email protected]>…
Quoted 20 lines
Quoted 8 lines

1. Spawn ksoftirqd earlier.

2. Suppress attempts to awaken ksoftirqd before it exists,
forcing all ksoftirq execution on the back of interrupts.

Uladzislau and I each produced patches for #1, and I produced a patch for #2.

Quoted 6 lines

The only other option I know of is to push the call to init_kprobes() later in the boot sequence, perhaps to its original subsys_initcall(), or maybe only as late as core_initcall(). I added Masami and Steve on CC for their thoughts on this.

Is there some other proper fix that I am missing?

Oh, I missed that the synchronize_rcu_tasks() will be involved the kprobes in early stage. Does the problem only exist in the synchronize_rcu_tasks() instead of synchronize_rcu()? If so I can just stop optimizer in early stage because I just want to enable kprobes in early stage, but not optprobes.

Quoted 7 lines
Quoted 1 line

Does the following patch help?

It does look to me like it would! I clearly should have asked you about this a couple of months ago. ;-)

The proof of the pudding would be whether the powerpc guys can apply this to v5.10-rc7 and have their kernel come up without hanging at boot.

Who could I ask for testing this patch, Uladzislau?
I think the test machine which enough slow or the kernel has much initcall to run optimization thread while booting.
In my environment, I could not reproduce that issue because the optimizer was sheduled after some tick passed. At that point, ksoftirqd has already been initialized.

Thank you,

Signature · 1 line
Masami Hiramatsu <[email protected]>
author maintainer
#24 lore raw

Re: [PATCH 2/2] rcu-tasks: add RCU-tasks self tests

Quoted 31 lines · Masami Hiramatsu
Quoted 20 lines · On Wed, 17 Feb 2021 10:17:38 -0800 "Paul E. McKenney" <[email protected]>…
Quoted 20 lines
Quoted 8 lines

1. Spawn ksoftirqd earlier.

2. Suppress attempts to awaken ksoftirqd before it exists,
forcing all ksoftirq execution on the back of interrupts.

Uladzislau and I each produced patches for #1, and I produced a patch for #2.

Quoted 6 lines

The only other option I know of is to push the call to init_kprobes() later in the boot sequence, perhaps to its original subsys_initcall(), or maybe only as late as core_initcall(). I added Masami and Steve on CC for their thoughts on this.

Is there some other proper fix that I am missing?

Oh, I missed that the synchronize_rcu_tasks() will be involved the kprobes in early stage. Does the problem only exist in the synchronize_rcu_tasks() instead of synchronize_rcu()? If so I can just stop optimizer in early stage because I just want to enable kprobes in early stage, but not optprobes.

Quoted 7 lines
Quoted 1 line

Does the following patch help?

It does look to me like it would! I clearly should have asked you about this a couple of months ago. ;-)

The proof of the pudding would be whether the powerpc guys can apply this to v5.10-rc7 and have their kernel come up without hanging at boot.

Quoted 7 lines

Who could I ask for testing this patch, Uladzislau?
I think the test machine which enough slow or the kernel has much initcall to run optimization thread while booting.
In my environment, I could not reproduce that issue because the optimizer was sheduled after some tick passed. At that point, ksoftirqd has already been initialized.

From my end i did some simulation and had a look at your change. So the patch works on my setup. I see that optimization of kprobes is deferred and can be initiated only from the subsys_initcall() phase. So the sequence should be correct for v5.10-rc7:

1. ksoftirq is setup early_initcall();
2. rcu_spawn_tasks_* are setup in the core_initcall();
3. an optimization of kprobes are invoked from subsys_initcall().

For real test on power-pc you can ask Daniel Axtens <[email protected]> for help.

--
Vlad Rezki

maintainer
#25 lore raw

Re: [PATCH 2/2] rcu-tasks: add RCU-tasks self tests

Quoted 39 lines · On Thu, 18 Feb 2021 09:36:36 +0100 Uladzislau Rezki <[email protected]> wrote:
Quoted 31 lines · Masami Hiramatsu
Quoted 20 lines · On Wed, 17 Feb 2021 10:17:38 -0800 "Paul E. McKenney" <[email protected]>…
Quoted 20 lines
Quoted 8 lines

1. Spawn ksoftirqd earlier.

2. Suppress attempts to awaken ksoftirqd before it exists,
forcing all ksoftirq execution on the back of interrupts.

Uladzislau and I each produced patches for #1, and I produced a patch for #2.

Quoted 6 lines

The only other option I know of is to push the call to init_kprobes() later in the boot sequence, perhaps to its original subsys_initcall(), or maybe only as late as core_initcall(). I added Masami and Steve on CC for their thoughts on this.

Is there some other proper fix that I am missing?

Oh, I missed that the synchronize_rcu_tasks() will be involved the kprobes in early stage. Does the problem only exist in the synchronize_rcu_tasks() instead of synchronize_rcu()? If so I can just stop optimizer in early stage because I just want to enable kprobes in early stage, but not optprobes.

Quoted 7 lines
Quoted 1 line

Does the following patch help?

It does look to me like it would! I clearly should have asked you about this a couple of months ago. ;-)

The proof of the pudding would be whether the powerpc guys can apply this to v5.10-rc7 and have their kernel come up without hanging at boot.

Quoted 7 lines

Who could I ask for testing this patch, Uladzislau?
I think the test machine which enough slow or the kernel has much initcall to run optimization thread while booting.
In my environment, I could not reproduce that issue because the optimizer was sheduled after some tick passed. At that point, ksoftirqd has already been initialized.

Quoted 6 lines

From my end i did some simulation and had a look at your change. So the patch works on my setup. I see that optimization of kprobes is deferred and can be initiated only from the subsys_initcall() phase. So the sequence should be correct for v5.10-rc7:

1. ksoftirq is setup early_initcall();

also kprobe framework is initialized in early_initcall() and kprobes smoketest (register/unregister probes) executed.

Quoted 1 line

2. rcu_spawn_tasks_* are setup in the core_initcall();

    and kprobe events are setup in core_initcall_sync() (via trace_boot);
Quoted 1 line

3. an optimization of kprobes are invoked from subsys_initcall().

At this point, all kprobes which can be optimized will be actually optimized.

Quoted 1 line

For real test on power-pc you can ask Daniel Axtens <[email protected]> for help.

OK, I'll CC to Daniel.

Thank you,

Signature · 1 line
Masami Hiramatsu <[email protected]>
author maintainer
#26 lore raw
In reply to Uladzislau Rezki (Sony)
Quoted 5 lines

Initialize the RCU-tasks earlier, before *_initcall() callbacks are invoked. Do it after the workqueue subsytem is up and running. That gives us a possibility to make use of synchronize_rcu_tasks*() wait API in early_initcall() callbacks.

Quoted 8 lines
Fixes 36dadef23fcc ("kprobes: Init kprobes in early_initcall")
---
 include/linux/rcupdate.h |  6 ++++++
 init/main.c              |  1 +
 kernel/rcu/tasks.h       | 26 ++++++++++++++++++++++----
 3 files changed, 29 insertions(+), 4 deletions(-)

I still don't have a powerPC hw so far, even though i have sent a request to the osuosl.org. It would be appreciated if Michael or Daniel could run and verify it.

Thank you in advance!

--
Vlad Rezki

Tested-by
#27 lore raw

Hi Vlad,

Quoted 7 lines
Quoted 7 lines

Initialize the RCU-tasks earlier, before *_initcall() callbacks are invoked. Do it after the workqueue subsytem is up and running. That gives us a possibility to make use of synchronize_rcu_tasks*() wait API in early_initcall() callbacks.

Fixes 36dadef23fcc ("kprobes: Init kprobes in early_initcall")
Quoted 9 lines
Quoted 6 lines
---
 include/linux/rcupdate.h |  6 ++++++
 init/main.c              |  1 +
 kernel/rcu/tasks.h       | 26 ++++++++++++++++++++++----
 3 files changed, 29 insertions(+), 4 deletions(-)

I still don't have a powerPC hw so far, even though i have sent a request to the osuosl.org. It would be appreciated if Michael or Daniel could run and verify it.

Sorry it's taken me so long to get to this. Your patch fixes things for me. Thanks!

BTW, I'm happy to see you taking on the challenge of RCU after your good work on vmalloc - all the best with it!

Kind regards,
Daniel

Quoted 5 lines

Thank you in advance!

--
Vlad Rezki

maintainer
#28 lore raw
Quoted 11 lines · Daniel Axtens

Hi Vlad,

Quoted 7 lines
Quoted 7 lines

Initialize the RCU-tasks earlier, before *_initcall() callbacks are invoked. Do it after the workqueue subsytem is up and running. That gives us a possibility to make use of synchronize_rcu_tasks*() wait API in early_initcall() callbacks.

Fixes 36dadef23fcc ("kprobes: Init kprobes in early_initcall")

I will apply on the next rebase, thank you!

Thanx, Paul

Quoted 24 lines
Quoted 9 lines
Quoted 6 lines
---
 include/linux/rcupdate.h |  6 ++++++
 init/main.c              |  1 +
 kernel/rcu/tasks.h       | 26 ++++++++++++++++++++++----
 3 files changed, 29 insertions(+), 4 deletions(-)

I still don't have a powerPC hw so far, even though i have sent a request to the osuosl.org. It would be appreciated if Michael or Daniel could run and verify it.

Sorry it's taken me so long to get to this. Your patch fixes things for me. Thanks!

BTW, I'm happy to see you taking on the challenge of RCU after your good work on vmalloc - all the best with it!

Kind regards,
Daniel

Quoted 5 lines

Thank you in advance!

--
Vlad Rezki

author maintainer
#29 lore raw
In reply to Daniel Axtens

Hello, Daniel.

Quoted 7 lines

Hi Vlad,

Quoted 5 lines
Quoted 5 lines

Initialize the RCU-tasks earlier, before *_initcall() callbacks are invoked. Do it after the workqueue subsytem is up and running. That gives us a possibility to make use of synchronize_rcu_tasks*() wait API in early_initcall() callbacks.

Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
Fixes 36dadef23fcc ("kprobes: Init kprobes in early_initcall")

Thank you for checking it!

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
---
 include/linux/rcupdate.h |  6 ++++++
 init/main.c              |  1 +
 kernel/rcu/tasks.h       | 26 ++++++++++++++++++++++----
 3 files changed, 29 insertions(+), 4 deletions(-)
Quoted 7 lines
Quoted 3 lines

I still don't have a powerPC hw so far, even though i have sent a request to the osuosl.org. It would be appreciated if Michael or Daniel could run and verify it.

Sorry it's taken me so long to get to this. Your patch fixes things for me. Thanks!

No problem. I fully understand that sometimes we are limited in spare time.

Quoted 4 lines

BTW, I'm happy to see you taking on the challenge of RCU after your good work on vmalloc - all the best with it!

Yep, that work was quite interesting and probably not so easy, at least in the beginning. Thanks for your supportive words and same to you regarding your excellent KASAN work and future challenge :)

--
Vlad Rezki

maintainer
#30 lore raw
In reply to Uladzislau Rezki (Sony)
Quoted 7 lines · Uladzislau Rezki (Sony)

Initialize the RCU-tasks earlier, before *_initcall() callbacks are invoked. Do it after the workqueue subsytem is up and running. That gives us a possibility to make use of synchronize_rcu_tasks*() wait API in early_initcall() callbacks.

Fixes 36dadef23fcc ("kprobes: Init kprobes in early_initcall")

Thank you! I have queued both with the usual editing, so please check and let me know if I messed something up.

Thanx, Paul

Quoted 110 lines
---
 include/linux/rcupdate.h |  6 ++++++
 init/main.c              |  1 +
 kernel/rcu/tasks.h       | 26 ++++++++++++++++++++++----
 3 files changed, 29 insertions(+), 4 deletions(-)
include/linux/rcupdate.h +6 -0
index 3c3efa4d6ab5..340c7d5344a4 100644
@@ -88,6 +88,12 @@ void rcu_sched_clock_irq(int user);
 void rcu_report_dead(unsigned int cpu);
 void rcutree_migrate_callbacks(int cpu);
 
+#ifdef CONFIG_TASKS_RCU_GENERIC
+void rcu_init_tasks_generic(void);
+#else
+static inline void rcu_init_tasks_generic(void) { }
+#endif
+
 #ifdef CONFIG_RCU_STALL_COMMON
 void rcu_sysrq_start(void);
 void rcu_sysrq_end(void);
init/main.c +1 -0
index 130376ec10ba..e253e87bdf58 100644
@@ -1502,6 +1502,7 @@ static noinline void __init kernel_init_freeable(void)
 
 	init_mm_internals();
 
+	rcu_init_tasks_generic();
 	do_pre_smp_initcalls();
 	lockup_detector_init();
 
kernel/rcu/tasks.h +22 -4
index 35bdcfd84d42..67a162949763 100644
@@ -241,7 +241,7 @@ static int __noreturn rcu_tasks_kthread(void *arg)
 	}
 }
 
-/* Spawn RCU-tasks grace-period kthread, e.g., at core_initcall() time. */
+/* Spawn RCU-tasks grace-period kthread. */
 static void __init rcu_spawn_tasks_kthread_generic(struct rcu_tasks *rtp)
 {
 	struct task_struct *t;
@@ -564,7 +564,6 @@ static int __init rcu_spawn_tasks_kthread(void)
 	rcu_spawn_tasks_kthread_generic(&rcu_tasks);
 	return 0;
 }
-core_initcall(rcu_spawn_tasks_kthread);
 
 #if !defined(CONFIG_TINY_RCU)
 void show_rcu_tasks_classic_gp_kthread(void)
@@ -692,7 +691,6 @@ static int __init rcu_spawn_tasks_rude_kthread(void)
 	rcu_spawn_tasks_kthread_generic(&rcu_tasks_rude);
 	return 0;
 }
-core_initcall(rcu_spawn_tasks_rude_kthread);
 
 #if !defined(CONFIG_TINY_RCU)
 void show_rcu_tasks_rude_gp_kthread(void)
@@ -968,6 +966,12 @@ static void rcu_tasks_trace_pregp_step(void)
 static void rcu_tasks_trace_pertask(struct task_struct *t,
 				    struct list_head *hop)
 {
+	// During early boot when there is only one boot-CPU,
+	// an idle_task is not set for other CPUs. In this case
+	// just revert.
+	if (unlikely(t == NULL))
+		return;
+
 	WRITE_ONCE(t->trc_reader_special.b.need_qs, false);
 	WRITE_ONCE(t->trc_reader_checked, false);
 	t->trc_ipi_to_cpu = -1;
@@ -1193,7 +1197,6 @@ static int __init rcu_spawn_tasks_trace_kthread(void)
 	rcu_spawn_tasks_kthread_generic(&rcu_tasks_trace);
 	return 0;
 }
-core_initcall(rcu_spawn_tasks_trace_kthread);
 
 #if !defined(CONFIG_TINY_RCU)
 void show_rcu_tasks_trace_gp_kthread(void)
@@ -1222,6 +1225,21 @@ void show_rcu_tasks_gp_kthreads(void)
 }
 #endif /* #ifndef CONFIG_TINY_RCU */
 
+void __init rcu_init_tasks_generic(void)
+{
+#ifdef CONFIG_TASKS_RCU
+	rcu_spawn_tasks_kthread();
+#endif
+
+#ifdef CONFIG_TASKS_RUDE_RCU
+	rcu_spawn_tasks_rude_kthread();
+#endif
+
+#ifdef CONFIG_TASKS_TRACE_RCU
+	rcu_spawn_tasks_trace_kthread();
+#endif
+}
+
 #else /* #ifdef CONFIG_TASKS_RCU_GENERIC */
 static inline void rcu_tasks_bootup_oddness(void) {}
 void show_rcu_tasks_gp_kthreads(void) {}
Signature · 1 line
2.20.1
author maintainer
#31 lore raw
Quoted 6 lines · Paul E. McKenney
Quoted 5 lines · Uladzislau Rezki (Sony)

Initialize the RCU-tasks earlier, before *_initcall() callbacks are invoked. Do it after the workqueue subsytem is up and running. That gives us a possibility to make use of synchronize_rcu_tasks*() wait API in early_initcall() callbacks.

Quoted 6 lines
Quoted 2 lines
Fixes 36dadef23fcc ("kprobes: Init kprobes in early_initcall")

Thank you! I have queued both with the usual editing, so please check and let me know if I messed something up.

Thanks!

Will have a look at editing.

--
Vlad Rezki