Skip to content

Commit 30ef096

Browse files
paulmckrcufbq
authored andcommitted
rcu-tasks: Initialize callback lists at rcu_init() time
In order for RCU Tasks to reliably maintain per-CPU lists of exiting tasks, those lists must be initialized before it is possible for tasks to exit, especially given that the boot CPU is not necessarily CPU 0 (an example being, powerpc kexec() kernels). And at the time that rcu_init_tasks_generic() is called, a task could potentially exit, unconventional though that sort of thing might be. This commit therefore moves the calls to cblist_init_generic() from functions called from rcu_init_tasks_generic() to a new function named tasks_cblist_init_generic() that is invoked from rcu_init(). This constituted a bug in a commit that never went to mainline, so there is no need for any backporting to -stable. Reported-by: Frederic Weisbecker <frederic@kernel.org> Signed-off-by: Paul E. McKenney <paulmck@kernel.org> Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
1 parent bfe9393 commit 30ef096

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

kernel/rcu/rcu.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,12 @@ struct task_struct *get_rcu_tasks_gp_kthread(void);
528528
struct task_struct *get_rcu_tasks_rude_gp_kthread(void);
529529
#endif // # ifdef CONFIG_TASKS_RUDE_RCU
530530

531+
#ifdef CONFIG_TASKS_RCU_GENERIC
532+
void tasks_cblist_init_generic(void);
533+
#else /* #ifdef CONFIG_TASKS_RCU_GENERIC */
534+
static inline void tasks_cblist_init_generic(void) { }
535+
#endif /* #else #ifdef CONFIG_TASKS_RCU_GENERIC */
536+
531537
#define RCU_SCHEDULER_INACTIVE 0
532538
#define RCU_SCHEDULER_INIT 1
533539
#define RCU_SCHEDULER_RUNNING 2

kernel/rcu/tasks.h

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,6 @@ static const char *tasks_gp_state_getname(struct rcu_tasks *rtp)
242242
static void cblist_init_generic(struct rcu_tasks *rtp)
243243
{
244244
int cpu;
245-
unsigned long flags;
246245
int lim;
247246
int shift;
248247

@@ -268,10 +267,8 @@ static void cblist_init_generic(struct rcu_tasks *rtp)
268267
WARN_ON_ONCE(!rtpcp);
269268
if (cpu)
270269
raw_spin_lock_init(&ACCESS_PRIVATE(rtpcp, lock));
271-
local_irq_save(flags); // serialize initialization
272270
if (rcu_segcblist_empty(&rtpcp->cblist))
273271
rcu_segcblist_init(&rtpcp->cblist);
274-
local_irq_restore(flags);
275272
INIT_WORK(&rtpcp->rtp_work, rcu_tasks_invoke_cbs_wq);
276273
rtpcp->cpu = cpu;
277274
rtpcp->rtpp = rtp;
@@ -1120,7 +1117,6 @@ module_param(rcu_tasks_lazy_ms, int, 0444);
11201117

11211118
static int __init rcu_spawn_tasks_kthread(void)
11221119
{
1123-
cblist_init_generic(&rcu_tasks);
11241120
rcu_tasks.gp_sleep = HZ / 10;
11251121
rcu_tasks.init_fract = HZ / 10;
11261122
if (rcu_tasks_lazy_ms >= 0)
@@ -1284,7 +1280,6 @@ module_param(rcu_tasks_rude_lazy_ms, int, 0444);
12841280

12851281
static int __init rcu_spawn_tasks_rude_kthread(void)
12861282
{
1287-
cblist_init_generic(&rcu_tasks_rude);
12881283
rcu_tasks_rude.gp_sleep = HZ / 10;
12891284
if (rcu_tasks_rude_lazy_ms >= 0)
12901285
rcu_tasks_rude.lazy_jiffies = msecs_to_jiffies(rcu_tasks_rude_lazy_ms);
@@ -1916,7 +1911,6 @@ module_param(rcu_tasks_trace_lazy_ms, int, 0444);
19161911

19171912
static int __init rcu_spawn_tasks_trace_kthread(void)
19181913
{
1919-
cblist_init_generic(&rcu_tasks_trace);
19201914
if (IS_ENABLED(CONFIG_TASKS_TRACE_RCU_READ_MB)) {
19211915
rcu_tasks_trace.gp_sleep = HZ / 10;
19221916
rcu_tasks_trace.init_fract = HZ / 10;
@@ -2088,6 +2082,24 @@ late_initcall(rcu_tasks_verify_schedule_work);
20882082
static void rcu_tasks_initiate_self_tests(void) { }
20892083
#endif /* #else #ifdef CONFIG_PROVE_RCU */
20902084

2085+
void __init tasks_cblist_init_generic(void)
2086+
{
2087+
lockdep_assert_irqs_disabled();
2088+
WARN_ON(num_online_cpus() > 1);
2089+
2090+
#ifdef CONFIG_TASKS_RCU
2091+
cblist_init_generic(&rcu_tasks);
2092+
#endif
2093+
2094+
#ifdef CONFIG_TASKS_RUDE_RCU
2095+
cblist_init_generic(&rcu_tasks_rude);
2096+
#endif
2097+
2098+
#ifdef CONFIG_TASKS_TRACE_RCU
2099+
cblist_init_generic(&rcu_tasks_trace);
2100+
#endif
2101+
}
2102+
20912103
void __init rcu_init_tasks_generic(void)
20922104
{
20932105
#ifdef CONFIG_TASKS_RCU

kernel/rcu/tiny.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,4 +261,5 @@ void __init rcu_init(void)
261261
{
262262
open_softirq(RCU_SOFTIRQ, rcu_process_callbacks);
263263
rcu_early_boot_tests();
264+
tasks_cblist_init_generic();
264265
}

kernel/rcu/tree.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5165,6 +5165,8 @@ void __init rcu_init(void)
51655165
(void)start_poll_synchronize_rcu_expedited();
51665166

51675167
rcu_test_sync_prims();
5168+
5169+
tasks_cblist_init_generic();
51685170
}
51695171

51705172
#include "tree_stall.h"

0 commit comments

Comments
 (0)