srcu: use cpu_online() instead custom check
Subsystems (2)
PATCH 1/3 srcu: use cpu_online() instead custom check
The current check via srcu_online is slightly racy because after looking at srcu_online there could be an interrupt that interrupted us long enough until the CPU we checked against went offline.
An alternative would be to hold the hotplug rwsem (so the CPUs don't change their state) and then check based on cpu_online() if we queue it on a specific CPU or not. queue_work_on() itself can handle if something is enqueued on an offline CPU but a timer which is enqueued on an offline CPU won't fire until the CPU is back online.
I am not sure if the removal in rcu_init() is okay or not. I assume that SRCU won't enqueue a work item before SRCU is up and ready.
--- kernel/rcu/srcutree.c | 22 ++++------------------ kernel/rcu/tree.c | 6 ------ 2 files changed, 4 insertions(+), 24 deletions(-)
kernel/rcu/srcutree.c +4 -18
@@ -36,6 +36,7 @@#include <linux/delay.h> #include <linux/module.h> #include <linux/srcu.h> +#include <linux/cpu.h> #include "rcu.h" #include "rcu_segcblist.h"
@@ -424,21 +425,6 @@ static void srcu_gp_start(struct srcu_struct *sp)WARN_ON_ONCE (state !=SRCU_STATE_SCAN1 ); } -/* -* Track online CPUs to guide callback workqueue placement. -*/ -DEFINE_PER_CPU (bool, srcu_online); - -void srcu_online_cpu (unsigned int cpu) -{ -WRITE_ONCE (per_cpu (srcu_online, cpu), true); -} - -void srcu_offline_cpu (unsigned int cpu) -{ -WRITE_ONCE (per_cpu (srcu_online, cpu), false); -} -/* * Place the workqueue handler on the specified CPU if online, otherwise * just run it whereever. This is useful for placing workqueue handlers
@@ -450,12 +436,12 @@ static bool srcu_queue_delayed_work_on(int cpu, struct workqueue_struct *wq, {bool ret; -preempt_disable (); -if (READ_ONCE (per_cpu (srcu_online, cpu))) +cpus_read_lock (); +if (cpu_online (cpu)) ret =queue_delayed_work_on (cpu, wq, dwork, delay);else ret =queue_delayed_work (wq, dwork, delay); -preempt_enable (); +cpus_read_unlock ();return ret; }
kernel/rcu/tree.c +0 -6
@@ -3729,8 +3729,6 @@ int rcutree_online_cpu(unsigned int cpu) {sync_sched_exp_online_cleanup (cpu);rcutree_affinity_setting (cpu,-1 ); -if (IS_ENABLED (CONFIG_TREE_SRCU )) -srcu_online_cpu (cpu);return 0 ; }
@@ -3741,8 +3739,6 @@ int rcutree_online_cpu(unsigned int cpu)int rcutree_offline_cpu (unsigned int cpu) {rcutree_affinity_setting (cpu, cpu); -if (IS_ENABLED (CONFIG_TREE_SRCU )) -srcu_offline_cpu (cpu);return 0 ; }
@@ -4188,8 +4184,6 @@ void __init rcu_init(void)for_each_online_cpu (cpu) {rcutree_prepare_cpu (cpu);rcu_cpu_starting (cpu); -if (IS_ENABLED (CONFIG_TREE_SRCU )) -srcu_online_cpu (cpu); } }
Signature · 1 line
2.14.1
PATCH 2/3 srcu: queue work without holding the lock
On RT we can't invoke queue_delayed_work() within an atomic section (which is provided by raw_spin_lock_irqsave()). srcu_reschedule() invokes queue_delayed_work() outside of the raw_spin_lock_irq_rcu_node() section so this should be fine here, too. If the remaining callers of call_srcu() aren't atomic (spin_lock_irqsave() is fine) then this should work on RT, too.
--- kernel/rcu/srcutree.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
kernel/rcu/srcutree.c +8 -3
@@ -648,12 +648,17 @@ static void srcu_funnel_gp_start(struct srcu_struct *sp, struct srcu_data *sdp,/* If grace period not already done and none in progress, start it. */ if (!rcu_seq_done (&sp->srcu_gp_seq, s) &&rcu_seq_state (sp->srcu_gp_seq) ==SRCU_STATE_IDLE ) { +unsigned long delay; +WARN_ON_ONCE (ULONG_CMP_GE (sp->srcu_gp_seq, sp->srcu_gp_seq_needed));srcu_gp_start (sp); + delay =srcu_get_delay (sp); +raw_spin_unlock_irqrestore_rcu_node (sp, flags); +queue_delayed_work (system_power_efficient_wq, &sp->work, -srcu_get_delay (sp)); - } -raw_spin_unlock_irqrestore_rcu_node (sp, flags); + delay); + }else +raw_spin_unlock_irqrestore_rcu_node (sp, flags); }/*
Signature · 1 line
2.14.1
Re: [PATCH 2/3] srcu: queue work without holding the lock
Quoted 6 lines · Sebastian Andrzej Siewior
On RT we can't invoke
queue_delayed_work()within an atomic section (which is provided byraw_spin_lock_irqsave()).srcu_reschedule()invokesqueue_delayed_work()outside of theraw_spin_lock_irq_rcu_node()section so this should be fine here, too. If the remaining callers ofcall_srcu()aren't atomic (spin_lock_irqsave()is fine) then this should work on RT, too.
Just to make sure I understand... The problem is not the _irqsave,
but rather the raw_?
Thanx, Paul
Quoted 33 lines
Signed-off-by Sebastian Andrzej Siewior <[email protected]>--- kernel/rcu/srcutree.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)kernel/rcu/srcutree.c +8
-3@@ -648,12 +648,17 @@ static void srcu_funnel_gp_start(struct srcu_struct *sp, struct srcu_data *sdp,/* If grace period not already done and none in progress, start it. */ if (!rcu_seq_done (&sp->srcu_gp_seq, s) &&rcu_seq_state (sp->srcu_gp_seq) ==SRCU_STATE_IDLE ) { +unsigned long delay; +WARN_ON_ONCE (ULONG_CMP_GE (sp->srcu_gp_seq, sp->srcu_gp_seq_needed));srcu_gp_start (sp); + delay =srcu_get_delay (sp); +raw_spin_unlock_irqrestore_rcu_node (sp, flags); +queue_delayed_work (system_power_efficient_wq, &sp->work, -srcu_get_delay (sp)); - } -raw_spin_unlock_irqrestore_rcu_node (sp, flags); + delay); + }else +raw_spin_unlock_irqrestore_rcu_node (sp, flags); }/* Signature · 1 line
2.14.1
Re: [PATCH 2/3] srcu: queue work without holding the lock
Quoted 10 lines · Paul E. McKenney
Quoted 6 lines · Sebastian Andrzej Siewior
On RT we can't invoke
queue_delayed_work()within an atomic section (which is provided byraw_spin_lock_irqsave()).srcu_reschedule()invokesqueue_delayed_work()outside of theraw_spin_lock_irq_rcu_node()section so this should be fine here, too. If the remaining callers ofcall_srcu()aren't atomic (spin_lock_irqsave()is fine) then this should work on RT, too.Just to make sure I understand... The problem is not the
_irqsave,
but rather theraw_?
exactly. The _irqsave is translated into a sleeping lock on RT and does not matter. The raw_ ones stay as they are and queue_delayed_work() uses sleeping locks itself and this is where things fall apart.
Quoted 2 lines
Thanx, Paul
Sebastian
Re: [PATCH 2/3] srcu: queue work without holding the lock
Quoted 9 lines · Sebastian Andrzej Siewior
Quoted 8 lines · Paul E. McKenney
Quoted 6 lines · Sebastian Andrzej Siewior
On RT we can't invoke
queue_delayed_work()within an atomic section (which is provided byraw_spin_lock_irqsave()).srcu_reschedule()invokesqueue_delayed_work()outside of theraw_spin_lock_irq_rcu_node()section so this should be fine here, too. If the remaining callers ofcall_srcu()aren't atomic (spin_lock_irqsave()is fine) then this should work on RT, too.
Quoted 6 lines
Quoted 2 lines
Just to make sure I understand... The problem is not the
_irqsave,
but rather theraw_?exactly. The
_irqsaveis translated into a sleeping lock on RT and does not matter. Theraw_ones stay as they are andqueue_delayed_work()uses sleeping locks itself and this is where things fall apart.
OK, internally I could get rid of raw_ at the expense of some code bloat, but in the call_srcu() case, the caller might well hold a raw_ lock.
Thoughts?
Thanx, Paul
Re: [PATCH 2/3] srcu: queue work without holding the lock
Quoted 13 lines · Paul E. McKenney
Quoted 12 lines · Sebastian Andrzej Siewior
Quoted 10 lines · Paul E. McKenney
Quoted 6 lines · Sebastian Andrzej Siewior
On RT we can't invoke
queue_delayed_work()within an atomic section (which is provided byraw_spin_lock_irqsave()).srcu_reschedule()invokesqueue_delayed_work()outside of theraw_spin_lock_irq_rcu_node()section so this should be fine here, too. If the remaining callers ofcall_srcu()aren't atomic (spin_lock_irqsave()is fine) then this should work on RT, too.Just to make sure I understand... The problem is not the
_irqsave,
but rather theraw_?
Quoted 6 lines
Quoted 3 lines
exactly. The
_irqsaveis translated into a sleeping lock on RT and does not matter. Theraw_ones stay as they are andqueue_delayed_work()uses sleeping locks itself and this is where things fall apart.OK, internally I could get rid of
raw_at the expense of some code bloat, but in thecall_srcu()case, the caller might well hold araw_lock.
Except that none currently do, so maybe downgrading from raw_ locks is a reasonable course of action. Does the following patch help?
Thanx, Paul
------------------------------------------------------------------------
commit 7c4b15340e4e23668cb3cadbf4f76795ee495085
Author: Paul E. McKenney <[email protected]> Date: Tue Oct 10 13:52:30 2017 -0700
srcu: Prohibit call_srcu() use under raw spinlocks
Invoking queue_delayed_work() while holding a raw spinlock is forbidden in -rt kernels, which is exactly what __call_srcu() does, indirectly via srcu_funnel_gp_start(). This commit therefore downgrades Tree SRCU's locking from raw to non-raw spinlocks, which works because call_srcu() is not ever called while holding a raw spinlock.
include/linux/srcutree.h +4 -4
@@ -40,7 +40,7 @@ struct srcu_data {unsigned long srcu_unlock_count[2 ];/* Unlocks per CPU. */ /* Update-side state. */ -raw_spinlock_t __private lock____cacheline_internodealigned_in_smp ; +spinlock_t __private lock____cacheline_internodealigned_in_smp ;struct rcu_segcblist srcu_cblist;/* List of callbacks.*/ unsigned long srcu_gp_seq_needed;/* Furthest future GP needed. */ unsigned long srcu_gp_seq_needed_exp;/* Furthest future exp GP. */
@@ -58,7 +58,7 @@ struct srcu_data {* Node in SRCU combining tree, similar in function to rcu_data. */ struct srcu_node { -raw_spinlock_t __private lock; +spinlock_t __private lock;unsigned long srcu_have_cbs[4 ];/* GP seq for children */ /* having CBs, but only */ /* is > ->srcu_gq_seq. */
@@ -78,7 +78,7 @@ struct srcu_struct {struct srcu_node *level[RCU_NUM_LVLS +1 ];/* First node at each level. */ struct mutex srcu_cb_mutex;/* Serialize CB preparation. */ -raw_spinlock_t __private lock;/* Protect counters */ +spinlock_t __private lock;/* Protect counters */ struct mutex srcu_gp_mutex;/* Serialize GP work. */ unsigned int srcu_idx;/* Current rdr array element. */ unsigned long srcu_gp_seq;/* Grace-period seq #. */
@@ -107,7 +107,7 @@ struct srcu_struct {#define __SRCU_STRUCT_INIT (name) \ { \ .sda = &name##_srcu_data, \ - .lock = __RAW_SPIN_LOCK_UNLOCKED(name.lock), \ + .lock = __SPIN_LOCK_UNLOCKED(name.lock), \ .srcu_gp_seq_needed = 0 - 1, \ __SRCU_DEP_MAP_INIT(name) \ }
kernel/rcu/srcutree.c +77 -41
326 lines not on this page · raw message
Re: [PATCH 2/3] srcu: queue work without holding the lock
Quoted 5 lines · Paul E. McKenney
Quoted 2 lines
OK, internally I could get rid of
raw_at the expense of some code bloat, but in thecall_srcu()case, the caller might well hold araw_lock.Except that none currently do, so maybe downgrading from
raw_locks is a reasonable course of action. Does the following patch help?
so you revert the raw_ access, this should work. I will apply it tomorrow and let you know.
Quoted 1 line
Thanx, Paul
Sebastian
Re: [PATCH 2/3] srcu: queue work without holding the lock
Quoted 9 lines · Sebastian Andrzej Siewior
Quoted 5 lines · Paul E. McKenney
Quoted 2 lines
OK, internally I could get rid of
raw_at the expense of some code bloat, but in thecall_srcu()case, the caller might well hold araw_lock.Except that none currently do, so maybe downgrading from
raw_locks is a reasonable course of action. Does the following patch help?so you revert the
raw_access, this should work. I will apply it tomorrow and let you know.
Indeed. I checked and the current callers of call_srcu() are not doing so while holding raw spinlocks. Now, call_rcu() is quite a different story...
Thanx, Paul
Re: [PATCH 2/3] srcu: queue work without holding the lock
In reply to Paul E. McKenneykernel/rcu/srcutree.c void __call_srcu(struct srcu_struct *sp, struct rcu_head *rhp, · line 869
Quoted 10 lines · Paul E. McKenney
kernel/rcu/srcutree.c +1
-1@@ -830,7 +866,7 @@ void __call_srcu(struct srcu_struct *sp, struct rcu_head *rhp, rhp->func = func;local_irq_save (flags); sdp =this_cpu_ptr (sp->sda); -raw_spin_lock_rcu_node (sdp); +spin_lock_rcu_node (sdp);
This and the same thing in srcu_might_be_idle() does not work because
local_irq_save() + spin_lock() != spin_lock_irqsave()
but
local_irq_save() + raw_spinlock = raw_spin_lock_irqsave()
I think that preempt_disable() for a stable this_cpu_ptr() is enough here. I replaced local_irq_save() with local_lock_irqsave() on RT which provides a per-CPU spinlock (for mutual exclusion) and disables interrupts in !RT mode.
I've been testing this for a while and it seems to work. Thank you.
kernel/rcu/srcutree.c void __call_srcu(struct srcu_struct *sp, struct rcu_head *rhp, · line 872
Quoted 3 lines
kernel/rcu/srcutree.c +0
-0rcu_segcblist_enqueue (&sdp->srcu_cblist, rhp, false);rcu_segcblist_advance (&sdp->srcu_cblist,rcu_seq_current (&sp->srcu_gp_seq));
Sebastian
Re: [PATCH 2/3] srcu: queue work without holding the lock
Quoted 17 lines · Sebastian Andrzej Siewior
kernel/rcu/srcutree.c void __call_srcu(struct srcu_struct *sp, struct rcu_head *rhp, · line 869
Quoted 10 lines · Paul E. McKenney
kernel/rcu/srcutree.c +1
-1@@ -830,7 +866,7 @@ void __call_srcu(struct srcu_struct *sp, struct rcu_head *rhp, rhp->func = func;local_irq_save (flags); sdp =this_cpu_ptr (sp->sda); -raw_spin_lock_rcu_node (sdp); +spin_lock_rcu_node (sdp);This and the same thing in
srcu_might_be_idle()does not work because
local_irq_save()+spin_lock()!=spin_lock_irqsave()
but
local_irq_save()+raw_spinlock=raw_spin_lock_irqsave()
Quoted 6 lines
I think that
preempt_disable()for a stablethis_cpu_ptr()is enough here. I replacedlocal_irq_save()withlocal_lock_irqsave()on RT which provides a per-CPU spinlock (for mutual exclusion) and disables interrupts in !RT mode.I've been testing this for a while and it seems to work. Thank you.
So I keep mainline as is, and the local_irq_save()-to-local_lock_irqsave() conversion happens in -rt, given that mainline doesn't have a local_lock_irqsave(), correct?
And just so you know, there is one patchset adding call_srcu() that I am following up on. Looks to me like it is OK with this change, but if not, well, back to the drawing board... :-/
Thanx, Paul
Quoted 7 lines
kernel/rcu/srcutree.c void __call_srcu(struct srcu_struct *sp, struct rcu_head *rhp, · line 872
Quoted 3 lines
kernel/rcu/srcutree.c +0
-0rcu_segcblist_enqueue (&sdp->srcu_cblist, rhp, false);rcu_segcblist_advance (&sdp->srcu_cblist,rcu_seq_current (&sp->srcu_gp_seq));Sebastian
Re: [PATCH 2/3] srcu: queue work without holding the lock
Quoted 3 lines · Paul E. McKenney
So I keep mainline as is, and the local_irq_save()-to-local_lock_irqsave() conversion happens in -rt, given that mainline doesn't have a
local_lock_irqsave(), correct?
yes, that would be nice :)
Quoted 3 lines
And just so you know, there is one patchset adding
call_srcu()that I am following up on. Looks to me like it is OK with this change, but if not, well, back to the drawing board... :-/
okay.
Quoted 1 line
Thanx, Paul
Sebastian
PATCH 3/3 rcu/segcblist: include rcupdate.h
In reply to Sebastian Andrzej SiewiorThe RT build on ARM complains about non-existing ULONG_CMP_LT.
--- kernel/rcu/rcu_segcblist.c | 1 + 1 file changed, 1 insertion(+)
kernel/rcu/rcu_segcblist.c +1 -0
@@ -23,6 +23,7 @@#include <linux/types.h> #include <linux/kernel.h> #include <linux/interrupt.h> +#include <linux/rcupdate.h> #include "rcu_segcblist.h"
Signature · 1 line
2.14.1
Re: [PATCH 3/3] rcu/segcblist: include rcupdate.h
Quoted 3 lines · Sebastian Andrzej Siewior
The RT build on ARM complains about non-existing
ULONG_CMP_LT.Signed-off-by Sebastian Andrzej Siewior <[email protected]>
I have queued this one for review and testing, thank you!
Thanx, Paul
Quoted 19 lines
--- kernel/rcu/rcu_segcblist.c | 1 + 1 file changed, 1 insertion(+)kernel/rcu/rcu_segcblist.c +1
-0@@ -23,6 +23,7 @@#include <linux/types.h> #include <linux/kernel.h> #include <linux/interrupt.h> +#include <linux/rcupdate.h> #include "rcu_segcblist.h" Signature · 1 line
2.14.1
Quoted 3 lines · Sebastian Andrzej Siewior
The current check via
srcu_onlineis slightly racy because after looking atsrcu_onlinethere could be an interrupt that interrupted us long enough until the CPU we checked against went offline.
But in that case, wouldn't the interrupt block the synchronize_sched() later in the offline sequence?
More to the point, are you actually seeing this failure, or is this a theoretical bug?
Quoted 8 lines
An alternative would be to hold the hotplug rwsem (so the CPUs don't change their state) and then check based on
cpu_online()if we queue it on a specific CPU or not.queue_work_on()itself can handle if something is enqueued on an offline CPU but a timer which is enqueued on an offline CPU won't fire until the CPU is back online.I am not sure if the removal in
rcu_init()is okay or not. I assume that SRCU won't enqueue a work item before SRCU is up and ready.
Another alternative would be to disable preemption across the check and the call to queue_delayed_work_on().
Yet another alternative would be to have an SRCU-specific per-CPU lock that is acquired across the setting and clearing of srcu_online, and also across the check and the call to queue_delayed_work_on(). This last would be more consistent with a desire to remove the synchronize_sched() from the offline sequence.
Or am I missing something here?
Thanx, Paul
Quoted 90 lines
Signed-off-by Sebastian Andrzej Siewior <[email protected]>--- kernel/rcu/srcutree.c | 22 ++++------------------ kernel/rcu/tree.c | 6 ------ 2 files changed, 4 insertions(+), 24 deletions(-)kernel/rcu/srcutree.c +4
-18@@ -36,6 +36,7 @@#include <linux/delay.h> #include <linux/module.h> #include <linux/srcu.h> +#include <linux/cpu.h> #include "rcu.h" #include "rcu_segcblist.h" @@ -424,21 +425,6 @@ static void srcu_gp_start(struct srcu_struct *sp)WARN_ON_ONCE (state !=SRCU_STATE_SCAN1 ); } -/* -* Track online CPUs to guide callback workqueue placement. -*/ -DEFINE_PER_CPU (bool, srcu_online); - -void srcu_online_cpu (unsigned int cpu) -{ -WRITE_ONCE (per_cpu (srcu_online, cpu), true); -} - -void srcu_offline_cpu (unsigned int cpu) -{ -WRITE_ONCE (per_cpu (srcu_online, cpu), false); -} -/* * Place the workqueue handler on the specified CPU if online, otherwise * just run it whereever. This is useful for placing workqueue handlers @@ -450,12 +436,12 @@ static bool srcu_queue_delayed_work_on(int cpu, struct workqueue_struct *wq, {bool ret; -preempt_disable (); -if (READ_ONCE (per_cpu (srcu_online, cpu))) +cpus_read_lock (); +if (cpu_online (cpu)) ret =queue_delayed_work_on (cpu, wq, dwork, delay);else ret =queue_delayed_work (wq, dwork, delay); -preempt_enable (); +cpus_read_unlock ();return ret; }kernel/rcu/tree.c +0
-6@@ -3729,8 +3729,6 @@ int rcutree_online_cpu(unsigned int cpu) {sync_sched_exp_online_cleanup (cpu);rcutree_affinity_setting (cpu,-1 ); -if (IS_ENABLED (CONFIG_TREE_SRCU )) -srcu_online_cpu (cpu);return 0 ; }@@ -3741,8 +3739,6 @@ int rcutree_online_cpu(unsigned int cpu)int rcutree_offline_cpu (unsigned int cpu) {rcutree_affinity_setting (cpu, cpu); -if (IS_ENABLED (CONFIG_TREE_SRCU )) -srcu_offline_cpu (cpu);return 0 ; }@@ -4188,8 +4184,6 @@ void __init rcu_init(void)for_each_online_cpu (cpu) {rcutree_prepare_cpu (cpu);rcu_cpu_starting (cpu); -if (IS_ENABLED (CONFIG_TREE_SRCU )) -srcu_online_cpu (cpu); } }Signature · 1 line
2.14.1
Quoted 7 lines · Paul E. McKenney
Quoted 3 lines · Sebastian Andrzej Siewior
The current check via
srcu_onlineis slightly racy because after looking atsrcu_onlinethere could be an interrupt that interrupted us long enough until the CPU we checked against went offline.But in that case, wouldn't the interrupt block the
synchronize_sched()later in the offline sequence?
What I meant is:
CPU0 CPU1
preempt_disable();
if (READ_ONCE(per_cpu(srcu_online, 1)))
*interrupt*
WRITE_ONCE(per_cpu(srcu_online, cpu), false); and CPU is offnline ret = queue_delayed_work_on(1, wq, dwork, delay);
is this possible or are there a safety belt for this?
Quoted 2 lines
More to the point, are you actually seeing this failure, or is this a theoretical bug?
I need to get rid of the preempt_disable() section in which queue_delayed_work*() is invoked for RT.
Quoted 11 lines
Quoted 8 lines
An alternative would be to hold the hotplug rwsem (so the CPUs don't change their state) and then check based on
cpu_online()if we queue it on a specific CPU or not.queue_work_on()itself can handle if something is enqueued on an offline CPU but a timer which is enqueued on an offline CPU won't fire until the CPU is back online.I am not sure if the removal in
rcu_init()is okay or not. I assume that SRCU won't enqueue a work item before SRCU is up and ready.Another alternative would be to disable preemption across the check and the call to
queue_delayed_work_on().
you need to ensure the *other* CPU won't in the middle of checking its status. preempt_disable() won't do this on the other CPU.
Quoted 7 lines
Yet another alternative would be to have an SRCU-specific per-CPU lock that is acquired across the setting and clearing of
srcu_online, and also across the check and the call toqueue_delayed_work_on(). This last would be more consistent with a desire to remove thesynchronize_sched()from the offline sequence.Or am I missing something here?
The perCPU lock should work. And cpus_read_lock() is basically that except that srcu_online_cpu() is not holding it but the CPU-HP code.
So you want keep things as-is or do you prefer a per-CPU rwsem instead?
Sebastian
Quoted 15 lines · Sebastian Andrzej Siewior
Quoted 7 lines · Paul E. McKenney
Quoted 3 lines · Sebastian Andrzej Siewior
The current check via
srcu_onlineis slightly racy because after looking atsrcu_onlinethere could be an interrupt that interrupted us long enough until the CPU we checked against went offline.But in that case, wouldn't the interrupt block the
synchronize_sched()later in the offline sequence?What I meant is:
CPU0 CPU1
preempt_disable();
if (READ_ONCE(per_cpu(srcu_online, 1)))
*interrupt*
Quoted 6 lines
WRITE_ONCE(per_cpu(srcu_online, cpu), false); and CPU is offnline ret = queue_delayed_work_on(1, wq, dwork, delay);is this possible or are there a safety belt for this?
I don't see anything that would prevent this. It is unlikely, but not so unlikely that it should not be fixed.
Quoted 5 lines
Quoted 2 lines
More to the point, are you actually seeing this failure, or is this a theoretical bug?
I need to get rid of the
preempt_disable()section in which queue_delayed_work*() is invoked for RT.
OK, but please see below...
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
An alternative would be to hold the hotplug rwsem (so the CPUs don't change their state) and then check based on
cpu_online()if we queue it on a specific CPU or not.queue_work_on()itself can handle if something is enqueued on an offline CPU but a timer which is enqueued on an offline CPU won't fire until the CPU is back online.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
I am not sure if the removal in
rcu_init()is okay or not. I assume that SRCU won't enqueue a work item before SRCU is up and ready.Another alternative would be to disable preemption across the check and the call to
queue_delayed_work_on().you need to ensure the *other* CPU won't in the middle of checking its status.
preempt_disable()won't do this on the other CPU.
Agreed.
Quoted 11 lines
Quoted 7 lines
Yet another alternative would be to have an SRCU-specific per-CPU lock that is acquired across the setting and clearing of
srcu_online, and also across the check and the call toqueue_delayed_work_on(). This last would be more consistent with a desire to remove thesynchronize_sched()from the offline sequence.Or am I missing something here?
The perCPU lock should work. And
cpus_read_lock()is basically that except thatsrcu_online_cpu()is not holding it but the CPU-HP code.So you want keep things as-is or do you prefer a per-CPU rwsem instead?
The per-CPU rwsem seems like a reasonable approach. Except for the call_srcu() path, given that call_srcu()'s caller might have preemption (or even interrupts) disabled.
Thoughts?
Thanx, Paul