rcu: Fix the start_poll_synchronize_rcu_expedited() be invoked very early
PATCH 1/1 rcu: Fix the start_poll_synchronize_rcu_expedited() be invoked very early
Currently, the start_poll_synchronize_rcu_expedited() can be invoked very early. before rcu_init(), the rcu_data structure's->mynode is not initialized, if invoke start_poll_synchronize_rcu_expedited() before rcu_init(), will access to NULL mynode pointer.
This commit therefore add exp_seq_poll_rq member to rcu_state structure to store snap seq number
--- kernel/rcu/tree.c | 3 ++- kernel/rcu/tree.h | 1 + kernel/rcu/tree_exp.h | 6 ++++-- 3 files changed, 7 insertions(+), 3 deletions(-)
kernel/rcu/tree.c +2 -1
@@ -92,6 +92,7 @@ static struct rcu_state rcu_state = { .exp_mutex = __MUTEX_INITIALIZER(rcu_state.exp_mutex), .exp_wake_mutex = __MUTEX_INITIALIZER(rcu_state.exp_wake_mutex), .ofl_lock = __ARCH_SPIN_LOCK_UNLOCKED, + .exp_seq_poll_rq = RCU_GET_STATE_COMPLETED, };/* Dump rcu_node combining tree at boot to verify correct setup. */
@@ -4938,7 +4939,7 @@ void __init rcu_init(void) qovld_calc = qovld;// Kick-start any polled grace periods that started early. -if (!(per_cpu_ptr (&rcu_data, cpu)->mynode->exp_seq_poll_rq &0x1 )) +if (!(rcu_state.exp_seq_poll_rq &0x1 )) (void )start_poll_synchronize_rcu_expedited ();rcu_test_sync_prims ();
kernel/rcu/tree.h +1 -0
@@ -397,6 +397,7 @@ struct rcu_state {/* Synchronize offline with */ /* GP pre-initialization. */ int nocb_is_setup;/* nocb is setup from boot */ +unsigned long exp_seq_poll_rq; };/* Values for rcu_state structure's gp_flags field. */
kernel/rcu/tree_exp.h +4 -2
@@ -1068,9 +1068,11 @@ unsigned long start_poll_synchronize_rcu_expedited(void)if (rcu_init_invoked ())raw_spin_lock_irqsave (&rnp->exp_poll_lock, flags);if (!poll_state_synchronize_rcu (s)) { - rnp->exp_seq_poll_rq = s; -if (rcu_init_invoked ()) +if (rcu_init_invoked ()) { + rnp->exp_seq_poll_rq = s;queue_work (rcu_gp_wq, &rnp->exp_poll_wq); + }else + rcu_state.exp_seq_poll_rq = s; }if (rcu_init_invoked ())raw_spin_unlock_irqrestore (&rnp->exp_poll_lock, flags);
Signature · 1 line
2.25.1
Frederic Weisbecker
maintainerQuoted 7 lines · Zqiang
Currently, the
start_poll_synchronize_rcu_expedited()can be invoked very early. beforercu_init(), thercu_datastructure's->mynode is not initialized, if invokestart_poll_synchronize_rcu_expedited()beforercu_init(), will access to NULL mynode pointer.This commit therefore add
exp_seq_poll_rqmember torcu_statestructure to store snap seq number
Is it even sane to poll that early in the morning? :-)
Quoted 13 lines
Signed-off-by Zqiang <[email protected]>--- kernel/rcu/tree.c | 3 ++- kernel/rcu/tree.h | 1 + kernel/rcu/tree_exp.h | 6 ++++-- 3 files changed, 7 insertions(+), 3 deletions(-)kernel/rcu/tree.c +0
-0
kernel/rcu/tree.c static struct rcu_state rcu_state = { · line 95
Quoted 4 lines
kernel/rcu/tree.c +1
-0@@ -92,6 +92,7 @@ static struct rcu_state rcu_state = { .exp_mutex = __MUTEX_INITIALIZER(rcu_state.exp_mutex), .exp_wake_mutex = __MUTEX_INITIALIZER(rcu_state.exp_wake_mutex), .ofl_lock = __ARCH_SPIN_LOCK_UNLOCKED, + .exp_seq_poll_rq = RCU_GET_STATE_COMPLETED,
I don't know if we really want to fix this, but assuming we do, can we rename it to boot_exp_seq_poll_rq? To avoid later confusion.
Thanks.
Quoted 9 lines · Zqiang
Currently, the
start_poll_synchronize_rcu_expedited()can be invoked very early. beforercu_init(), thercu_datastructure's->mynode is not initialized, if invokestart_poll_synchronize_rcu_expedited()beforercu_init(), will access to NULL mynode pointer.This commit therefore add
exp_seq_poll_rqmember torcu_statestructure to store snap seq numberIs it even sane to poll that early in the morning? :-)
According to d96c52fe4907c ("rcu: Add polled expedited grace-period primitives "), the start_poll_synchronize_rcu_expedited() can be invoked very early, that is to say can be invoked before rcu_init(), the following code snippet also shows that the start_poll_synchronize_rcu_expedited() may be called early.
// Kick-start any polled grace periods that started early.
if (!(per_cpu_ptr(&rcu_data, cpu)->mynode->exp_seq_poll_rq & 0x1))
(void)start_poll_synchronize_rcu_expedited();But before rcu_init(), the rcu_data structure's->mynode is not initialized, so at least, we set rnp->exp_seq_poll_rq should be in case the rcu_init_invoked() returns true in start_poll_synchronize_rcu_expedited() .
Quoted 20 lines
Signed-off-by Zqiang <[email protected]>--- kernel/rcu/tree.c | 3 ++- kernel/rcu/tree.h | 1 + kernel/rcu/tree_exp.h | 6 ++++-- 3 files changed, 7 insertions(+), 3 deletions(-)kernel/rcu/tree.c +1
-0@@ -92,6 +92,7 @@ static struct rcu_state rcu_state = { .exp_mutex = __MUTEX_INITIALIZER(rcu_state.exp_mutex), .exp_wake_mutex = __MUTEX_INITIALIZER(rcu_state.exp_wake_mutex), .ofl_lock = __ARCH_SPIN_LOCK_UNLOCKED, + .exp_seq_poll_rq = RCU_GET_STATE_COMPLETED, I don't know if we really want to fix this, but assuming we do,
Quoted 1 line
can we rename it to
boot_exp_seq_poll_rq? To avoid later confusion.
Will fix in next version.
Thanks
Zqiang
Quoted 2 lines
Thanks.