Address rcutorture issues
Subsystems (3)
cover Address rcutorture issues
With these patches, rcutorture mostly works on PREEMPT_RT_FULL. I still once in a while get forward progress complaints (particularly, rcu_torture_fwd_prog_cr) when a grace period is held up for a few seconds after which point so many callbacks have been enqueued that even making reasonable progress isn't going to beat the timeout. I believe I've only seen this when running heavy loads in addition to rcutorture (though I've done more testing under load than without); I don't know whether the forward progress tests are expected to work under such load.
Scott Wood (4):
rcu: Acquire RCU lock when disabling BHs
sched: migrate_enable: Use sleeping_lock to indicate involuntary sleep
rcu: unlock special: Treat irq and preempt disabled the same
rcutorture: Avoid problematic critical section nesting
include/linux/rcupdate.h | 4 +++ include/linux/sched.h | 4 +-- kernel/rcu/rcutorture.c | 92 ++++++++++++++++++++++++++++++++++++++++-------- kernel/rcu/tree_plugin.h | 12 ++----- kernel/rcu/update.c | 4 +++ kernel/sched/core.c | 2 ++ kernel/softirq.c | 12 +++++-- 7 files changed, 102 insertions(+), 28 deletions(-)
Signature · 1 line
1.8.3.1
PATCH 1/4 rcu: Acquire RCU lock when disabling BHs
A plain local_bh_disable() is documented as creating an RCU critical section, and (at least) rcutorture expects this to be the case. However, in_softirq() doesn't block a grace period on PREEMPT_RT, since RCU checks preempt_count() directly. Even if RCU were changed to check in_softirq(), that wouldn't allow blocked BH disablers to be boosted.
Fix this by calling rcu_read_lock() from local_bh_disable(), and update rcu_read_lock_bh_held() accordingly.
--- include/linux/rcupdate.h | 4 ++++ kernel/rcu/update.c | 4 ++++ kernel/softirq.c | 12 +++++++++--- 3 files changed, 17 insertions(+), 3 deletions(-)
include/linux/rcupdate.h +4 -0
@@ -637,10 +637,12 @@ static inline void rcu_read_unlock(void)static inline void rcu_read_lock_bh (void ) {local_bh_disable (); +#ifndef CONFIG_PREEMPT_RT_FULL __acquire (RCU_BH );rcu_lock_acquire (&rcu_bh_lock_map);RCU_LOCKDEP_WARN (!rcu_is_watching (),"rcu_read_lock_bh() used illegally while idle" ); +#endif }/*
@@ -650,10 +652,12 @@ static inline void rcu_read_lock_bh(void)*/ static inline void rcu_read_unlock_bh (void ) { +#ifndef CONFIG_PREEMPT_RT_FULL RCU_LOCKDEP_WARN (!rcu_is_watching (),"rcu_read_unlock_bh() used illegally while idle" );rcu_lock_release (&rcu_bh_lock_map);__release (RCU_BH ); +#endif local_bh_enable (); }
kernel/rcu/update.c +4 -0
@@ -307,7 +307,11 @@ int rcu_read_lock_bh_held(void)return 0 ;if (!rcu_lockdep_current_cpu_online ())return 0 ; +#ifdef CONFIG_PREEMPT_RT_FULL +return lock_is_held (&rcu_lock_map) ||irqs_disabled (); +#else return in_softirq () ||irqs_disabled (); +#endif }EXPORT_SYMBOL_GPL (rcu_read_lock_bh_held);
kernel/softirq.c +9 -3
@@ -121,8 +121,10 @@ void __local_bh_disable_ip(unsigned long ip, unsigned int cnt)long soft_cnt;WARN_ON_ONCE (in_irq ()); -if (!in_atomic ()) +if (!in_atomic ()) {local_lock (bh_lock); +rcu_read_lock (); + } soft_cnt =this_cpu_inc_return (softirq_counter);WARN_ON_ONCE (soft_cnt ==0 );
@@ -155,8 +157,10 @@ void _local_bh_enable(void)local_irq_restore (flags);#endif -if (!in_atomic ()) +if (!in_atomic ()) { +rcu_read_unlock ();local_unlock (bh_lock); + } }void _local_bh_enable_rt (void )
@@ -189,8 +193,10 @@ void __local_bh_enable_ip(unsigned long ip, unsigned int cnt)WARN_ON_ONCE (count <0 );local_irq_enable (); -if (!in_atomic ()) +if (!in_atomic ()) { +rcu_read_unlock ();local_unlock (bh_lock); + }preempt_check_resched (); }
Signature · 1 line
1.8.3.1
PATCH 2/4 sched: migrate_enable: Use sleeping_lock to indicate involuntary sleep
In reply to Scott WoodWithout this, rcu_note_context_switch() will complain if an RCU read lock is held when migrate_enable() calls stop_one_cpu().
--- include/linux/sched.h | 4 ++-- kernel/rcu/tree_plugin.h | 2 +- kernel/sched/core.c | 2 ++ 3 files changed, 5 insertions(+), 3 deletions(-)
include/linux/sched.h +2 -2
@@ -681,7 +681,7 @@ struct task_struct {int migrate_disable_atomic;# endif #endif -#ifdef CONFIG_PREEMPT_RT_FULL +#ifdef CONFIG_PREEMPT_RT_BASE int sleeping_lock;#endif
@@ -1870,7 +1870,7 @@ static __always_inline bool need_resched(void)return unlikely (tif_need_resched ()); } -#ifdef CONFIG_PREEMPT_RT_FULL +#ifdef CONFIG_PREEMPT_RT_BASE static inline void sleeping_lock_inc (void ) { current->sleeping_lock++;
kernel/rcu/tree_plugin.h +1 -1
@@ -311,7 +311,7 @@ void rcu_note_context_switch(bool preempt)barrier ();/* Avoid RCU read-side critical sections leaking down. */ trace_rcu_utilization (TPS ("Start context switch" ));lockdep_assert_irqs_disabled (); -#if defined(CONFIG_PREEMPT_RT_FULL ) +#if defined(CONFIG_PREEMPT_RT_BASE ) sleeping_l = t->sleeping_lock;#endif WARN_ON_ONCE (!preempt && t->rcu_read_lock_nesting >0 && !sleeping_l);
kernel/sched/core.c +2 -0
@@ -7351,7 +7351,9 @@ void migrate_enable(void)unpin_current_cpu ();preempt_lazy_enable ();preempt_enable (); +sleeping_lock_inc ();stop_one_cpu (task_cpu (p), migration_cpu_stop, &arg); +sleeping_lock_dec ();tlb_migrate_finish (p->mm);return ;
Signature · 1 line
1.8.3.1
RFC PATCH 3/4 rcu: unlock special: Treat irq and preempt disabled the same
In reply to Scott Wood[Note: Just before posting this I noticed that the invoke_rcu_core stuff
is part of the latest RCU pull request, and it has a patch that addresses this in a more complicated way that appears to deal with the bare irq-disabled sequence as well.
Assuming we need/want to support such sequences, is the invoke_rcu_core() call actually going to result in scheduling any sooner? resched_curr() just does the same setting of need_resched when it's the same cpu.
]
Since special should never be getting set inside an irqs-disabled critical section, this is safe as long as there are no sequences of rcu_read_lock()/local_irq_disable()/rcu_read_unlock()/local_irq_enable() (without preempt_disable() wrapped around the IRQ disabling, as spinlocks do). If there are such sequences, then the grace period may be delayed until the next time need_resched is checked.
This is needed because otherwise, in a sequence such as:
1. rcu_read_lock()
2. *preempt*, set rcu_read_unlock_special.b.blocked
3. preempt_disable()
4. rcu_read_unlock()
5. preempt_enable()
...rcu_read_unlock_special.b.blocked will not be cleared during step 4, because of the disabled preemption. If an interrupt is then taken between steps 4 and 5, and that interrupt enters scheduler code that takes pi/rq locks, and an rcu read lock inside that, then when dropping that rcu read lock we will end up in rcu_read_unlock_special() again -- but this time, since irqs are disabled, it will call invoke_rcu_core() in the RT tree (regardless of PREEMPT_RT_FULL), which calls wake_up_process(). This can cause a pi/rq lock deadlock. An example of interrupt code that does this is scheduler_tick().
The above sequence can be found in (at least) __lock_task_sighand() (for !PREEMPT_RT_FULL) and d_alloc_parallel().
It's potentially an issue on non-RT as well. While raise_softirq_irqoff() doesn't call wake_up_process() when in_interrupt() is true, if code between steps 4 and 5 directly calls into scheduler code, and that code uses RCU with pi/rq lock held, wake_up_process() can still be called.
On RT, migrate_enable() is such a codepath, so an in_interrupt() check alone would not work on RT. Instead, keep track of whether we've already had an rcu_read_unlock_special() with preemption disabled but haven't yet scheduled, and rely on the preempt_enable() yet to come instead of calling invoke_rcu_core().
--- kernel/rcu/tree_plugin.h | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)
kernel/rcu/tree_plugin.h +2 -8
@@ -630,14 +630,8 @@ static void rcu_read_unlock_special(struct task_struct *t)if (preempt_bh_were_disabled || irqs_were_disabled) {WRITE_ONCE (t->rcu_read_unlock_special.b.exp_hint, false);/* Need to defer quiescent state until everything is enabled. */ -if (irqs_were_disabled) { -/* Enabling irqs does not reschedule, so... */ -invoke_rcu_core (); - }else { -/* Enabling BH or preempt does reschedule, so... */ -set_tsk_need_resched (current); -set_preempt_need_resched (); - } +set_tsk_need_resched (current); +set_preempt_need_resched ();local_irq_restore (flags);return ; }
Signature · 1 line
1.8.3.1
RFC PATCH 4/4 rcutorture: Avoid problematic critical section nesting
In reply to Scott Woodrcutorture was generating some nesting scenarios that are not reasonable. Constrain the state selection to avoid them.
Example #1:
1. preempt_disable()
2. local_bh_disable()
3. preempt_enable()
4. local_bh_enable()
On PREEMPT_RT, BH disabling takes a local lock only when called in non-atomic context. Thus, atomic context must be retained until after BH is re-enabled. Likewise, if BH is initially disabled in non-atomic context, it cannot be re-enabled in atomic context.
Example #2:
1. rcu_read_lock()
2. local_irq_disable()
3. rcu_read_unlock()
4. local_irq_enable()
If the thread is preempted between steps 1 and 2, rcu_read_unlock_special.b.blocked will be set, but it won't be acted on in step 3 because IRQs are disabled. Thus, reporting of the quiescent state will be delayed beyond the local_irq_enable().
Example #3:
1. preempt_disable()
2. local_irq_disable()
3. preempt_enable()
4. local_irq_enable()
If need_resched is set between steps 1 and 2, then the reschedule in step 3 will not happen.
---
TODO: Document restrictions and add debug checks for invalid sequences.
I had been planning to resolve #1 (only as shown, not the case of disabling preemption while non-atomic and enabling while atomic) by changing how migrate_disable() works to avoid the split behavior, but recently BH disabling was changed to do the same thing. I still plan to send the migrate disable changes as a separate patchset, for the sake of the significant performance improvement I saw.
--- kernel/rcu/rcutorture.c | 92 +++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 78 insertions(+), 14 deletions(-)
kernel/rcu/rcutorture.c +78 -14
@@ -73,10 +73,13 @@#define RCUTORTURE_RDR_RBH 0x08/* ... rcu_read_lock_bh(). */ #define RCUTORTURE_RDR_SCHED 0x10/* ... rcu_read_lock_sched(). */ #define RCUTORTURE_RDR_RCU 0x20/* ... entering another RCU reader. */ -#define RCUTORTURE_RDR_NBITS 6/* Number of bits defined above. */ +#define RCUTORTURE_RDR_ATOM_BH 0x40/* ... disabling bh while atomic */ +#define RCUTORTURE_RDR_ATOM_RBH 0x80/* ... RBH while atomic */ +#define RCUTORTURE_RDR_NBITS 8/* Number of bits defined above. */ #define RCUTORTURE_MAX_EXTEND \ (RCUTORTURE_RDR_BH | RCUTORTURE_RDR_IRQ | RCUTORTURE_RDR_PREEMPT | \ - RCUTORTURE_RDR_RBH | RCUTORTURE_RDR_SCHED) + RCUTORTURE_RDR_RBH | RCUTORTURE_RDR_SCHED | \ + RCUTORTURE_RDR_ATOM_BH | RCUTORTURE_RDR_ATOM_RBH)#define RCUTORTURE_RDR_MAX_LOOPS 0x7/* Maximum reader extensions. */ /* Must be power of two minus one. */ #define RCUTORTURE_RDR_MAX_SEGS (RCUTORTURE_RDR_MAX_LOOPS + 3)
@@ -1111,31 +1114,52 @@ static void rcutorture_one_extend(int *readstate, int newstate,WARN_ON_ONCE ((idxold >>RCUTORTURE_RDR_SHIFT ) >1 ); rtrsp->rt_readstate = newstate; -/* First, put new protection in place to avoid critical-section gap. */ +/* +* First, put new protection in place to avoid critical-section gap. +* Disable preemption around the ATOM disables to ensure that +* in_atomic() is true. +*/ if (statesnew &RCUTORTURE_RDR_BH )local_bh_disable (); +if (statesnew &RCUTORTURE_RDR_RBH ) +rcu_read_lock_bh ();if (statesnew &RCUTORTURE_RDR_IRQ )local_irq_disable ();if (statesnew &RCUTORTURE_RDR_PREEMPT )preempt_disable (); -if (statesnew &RCUTORTURE_RDR_RBH ) -rcu_read_lock_bh ();if (statesnew &RCUTORTURE_RDR_SCHED )rcu_read_lock_sched (); +preempt_disable (); +if (statesnew &RCUTORTURE_RDR_ATOM_BH ) +local_bh_disable (); +if (statesnew &RCUTORTURE_RDR_ATOM_RBH ) +rcu_read_lock_bh (); +preempt_enable ();if (statesnew &RCUTORTURE_RDR_RCU ) idxnew = cur_ops->readlock () <<RCUTORTURE_RDR_SHIFT ; -/* Next, remove old protection, irq first due to bh conflict. */ +/* +* Next, remove old protection, in decreasing order of strength +* to avoid unlock paths that aren't safe in the stronger +* context. Disable preemption around the ATOM enables in +* case the context was only atomic due to IRQ disabling. +*/ +preempt_disable ();if (statesold &RCUTORTURE_RDR_IRQ )local_irq_enable (); -if (statesold &RCUTORTURE_RDR_BH ) +if (statesold &RCUTORTURE_RDR_ATOM_BH )local_bh_enable (); +if (statesold &RCUTORTURE_RDR_ATOM_RBH ) +rcu_read_unlock_bh (); +preempt_enable ();if (statesold &RCUTORTURE_RDR_PREEMPT )preempt_enable (); -if (statesold &RCUTORTURE_RDR_RBH ) -rcu_read_unlock_bh ();if (statesold &RCUTORTURE_RDR_SCHED )rcu_read_unlock_sched (); +if (statesold &RCUTORTURE_RDR_BH ) +local_bh_enable (); +if (statesold &RCUTORTURE_RDR_RBH ) +rcu_read_unlock_bh ();if (statesold &RCUTORTURE_RDR_RCU ) cur_ops->readunlock (idxold >>RCUTORTURE_RDR_SHIFT );
@@ -1171,6 +1195,12 @@ static int rcutorture_extend_mask_max(void)int mask =rcutorture_extend_mask_max ();unsigned long randmask1 =torture_random (trsp) >>8 ;unsigned long randmask2 = randmask1 >>3 ; +unsigned long preempts =RCUTORTURE_RDR_PREEMPT |RCUTORTURE_RDR_SCHED ; +unsigned long preempts_irq = preempts |RCUTORTURE_RDR_IRQ ; +unsigned long nonatomic_bhs =RCUTORTURE_RDR_BH |RCUTORTURE_RDR_RBH ; +unsigned long atomic_bhs =RCUTORTURE_RDR_ATOM_BH | +RCUTORTURE_RDR_ATOM_RBH ; +unsigned long tmp;WARN_ON_ONCE (mask >>RCUTORTURE_RDR_SHIFT );/* Most of the time lots of bits, half the time only one bit. */
@@ -1178,11 +1208,45 @@ static int rcutorture_extend_mask_max(void) mask = mask & randmask2; else mask = mask & (1 << (randmask2 %RCUTORTURE_RDR_NBITS )); -/* Can't enable bh w/irq disabled. */ -if ((mask &RCUTORTURE_RDR_IRQ ) && - ((!(mask &RCUTORTURE_RDR_BH ) && (oldmask &RCUTORTURE_RDR_BH )) || - (!(mask &RCUTORTURE_RDR_RBH ) && (oldmask &RCUTORTURE_RDR_RBH )))) - mask |=RCUTORTURE_RDR_BH |RCUTORTURE_RDR_RBH ; + +/* +* Can't enable bh w/irq disabled. +* +* Can't enable preemption with irqs disabled, if irqs had ever +* been enabled during this preempt critical section (could miss +* a reschedule). +*/ + tmp = atomic_bhs | nonatomic_bhs | preempts; +if (mask &RCUTORTURE_RDR_IRQ ) + mask |= oldmask & tmp; + +/* +* Can't release the outermost rcu lock in an irq disabled +* section without preemption also being disabled, if irqs had +* ever been enabled during this RCU critical section (could leak +* a special flag and delay reporting the qs). +*/ +if ((oldmask &RCUTORTURE_RDR_RCU ) && (mask &RCUTORTURE_RDR_IRQ ) && + !(mask & preempts)) + mask |=RCUTORTURE_RDR_RCU ; + +/* Can't modify atomic bh in non-atomic context */ +if ((oldmask & atomic_bhs) && (mask & atomic_bhs) && + !(mask & preempts_irq)) { + mask |= oldmask & preempts_irq; +if (mask &RCUTORTURE_RDR_IRQ ) + mask |= oldmask & tmp; + } +if ((mask & atomic_bhs) && !(mask & preempts_irq)) + mask |=RCUTORTURE_RDR_PREEMPT ; + +/* Can't modify non-atomic bh in atomic context */ + tmp = nonatomic_bhs; +if (oldmask & preempts_irq) + mask &= ~tmp; +if ((oldmask | mask) & preempts_irq) + mask |= oldmask & tmp; +if ((mask &RCUTORTURE_RDR_IRQ ) && !(mask & cur_ops->ext_irq_conflict) && (oldmask & cur_ops->ext_irq_conflict))
Signature · 1 line
1.8.3.1
Quoted 8 lines · Scott Wood
With these patches, rcutorture mostly works on
PREEMPT_RT_FULL. I still once in a while get forward progress complaints (particularly,rcu_torture_fwd_prog_cr) when a grace period is held up for a few seconds after which point so many callbacks have been enqueued that even making reasonable progress isn't going to beat the timeout. I believe I've only seen this when running heavy loads in addition to rcutorture (though I've done more testing under load than without); I don't know whether the forward progress tests are expected to work under such load.
With current -rcu, the torture tests are ahead of RCU's forward-progress code, so rcu_torture_fwd_prog_cr() failures are expected behavior, particularly in the TREE04 and TREE07 scenarios. This is more of a problem for real-time because of callback offloading, which removes the backpressure that normally exists from callback processing to whatever is running on that same CPU generating so many callbacks. So this issue has been providing me some entertainment. ;-)
If you put lots of load on the system while running rcutorture, but leave the CPU running rcu_torture_fwd_prog_cr() otherwise idle, then yes, you can eventually force rcu_torture_fwd_prog_cr() pretty much no matter what RCU does otherwise. Particularly given that rcutorture is running within a guest OS. There has been some discussion of RCU asking for help from the hypervisor, but it hasn't yet gotten further than discussion.
For another example, if all but one of the CPUs is an no-CBs CPU (or, equivalently, a nohz_full CPU), and all of the rcuo kthreads are constrained to run on the remaining CPU, it is not hard to create workloads that produce more callbacks than that remaining CPU can possibly keep up with. The traditional position has of course been the Spiderman principle "With great power comes great responsibility". ;-)
Thanx, Paul
Quoted 18 lines
Scott Wood (4):
rcu: Acquire RCU lock when disabling BHs
sched:migrate_enable: Usesleeping_lockto indicate involuntary sleep
rcu: unlock special: Treat irq and preempt disabled the same
rcutorture: Avoid problematic critical section nestinginclude/linux/rcupdate.h | 4 +++ include/linux/sched.h | 4 +-- kernel/rcu/rcutorture.c | 92 ++++++++++++++++++++++++++++++++++++++++-------- kernel/rcu/tree_plugin.h | 12 ++----- kernel/rcu/update.c | 4 +++ kernel/sched/core.c | 2 ++ kernel/softirq.c | 12 +++++-- 7 files changed, 102 insertions(+), 28 deletions(-)Signature · 1 line
1.8.3.1
Re: [PATCH RT 1/4] rcu: Acquire RCU lock when disabling BHs
In reply to Scott WoodQuoted 21 lines · Scott Wood
A plain
local_bh_disable()is documented as creating an RCU critical section, and (at least) rcutorture expects this to be the case. However,in_softirq()doesn't block a grace period onPREEMPT_RT, since RCU checkspreempt_count()directly. Even if RCU were changed to checkin_softirq(), that wouldn't allow blocked BH disablers to be boosted.Fix this by calling
rcu_read_lock()fromlocal_bh_disable(), and updatercu_read_lock_bh_held()accordingly.Signed-off-by Scott Wood <[email protected]>--- include/linux/rcupdate.h | 4 ++++ kernel/rcu/update.c | 4 ++++ kernel/softirq.c | 12 +++++++++--- 3 files changed, 17 insertions(+), 3 deletions(-)include/linux/rcupdate.h +0
-0
include/linux/rcupdate.h static inline void rcu_read_unlock(void) · line 640
Quoted 4 lines
include/linux/rcupdate.h +1
-0@@ -637,10 +637,12 @@ static inline void rcu_read_unlock(void)static inline void rcu_read_lock_bh (void ) {local_bh_disable (); +#ifndef CONFIG_PREEMPT_RT_FULL
How about this instead?
if (IS_ENABLED(CONFIG_PREEMPT_RT_FULL)) return;
And similarly below.
Quoted 67 lines
include/linux/rcupdate.h +3
-0__acquire (RCU_BH );rcu_lock_acquire (&rcu_bh_lock_map);RCU_LOCKDEP_WARN (!rcu_is_watching (),"rcu_read_lock_bh() used illegally while idle" ); +#endif }/* @@ -650,10 +652,12 @@ static inline void rcu_read_lock_bh(void)*/ static inline void rcu_read_unlock_bh (void ) { +#ifndef CONFIG_PREEMPT_RT_FULL RCU_LOCKDEP_WARN (!rcu_is_watching (),"rcu_read_unlock_bh() used illegally while idle" );rcu_lock_release (&rcu_bh_lock_map);__release (RCU_BH ); +#endif local_bh_enable (); }kernel/rcu/update.c +4
-0@@ -307,7 +307,11 @@ int rcu_read_lock_bh_held(void)return 0 ;if (!rcu_lockdep_current_cpu_online ())return 0 ; +#ifdef CONFIG_PREEMPT_RT_FULL +return lock_is_held (&rcu_lock_map) ||irqs_disabled (); +#else return in_softirq () ||irqs_disabled (); +#endif }EXPORT_SYMBOL_GPL (rcu_read_lock_bh_held);kernel/softirq.c +6
-2@@ -121,8 +121,10 @@ void __local_bh_disable_ip(unsigned long ip, unsigned int cnt)long soft_cnt;WARN_ON_ONCE (in_irq ()); -if (!in_atomic ()) +if (!in_atomic ()) {local_lock (bh_lock); +rcu_read_lock (); + } soft_cnt =this_cpu_inc_return (softirq_counter);WARN_ON_ONCE (soft_cnt ==0 );@@ -155,8 +157,10 @@ void _local_bh_enable(void)local_irq_restore (flags);#endif -if (!in_atomic ()) +if (!in_atomic ()) { +rcu_read_unlock ();local_unlock (bh_lock); + } }void _local_bh_enable_rt (void )@@ -189,8 +193,10 @@ void __local_bh_enable_ip(unsigned long ip, unsigned int cnt)WARN_ON_ONCE (count <0 );
kernel/softirq.c void __local_bh_enable_ip(unsigned long ip, unsigned int cnt) · line 202
Quoted 10 lines
kernel/softirq.c +3
-1local_irq_enable (); -if (!in_atomic ()) +if (!in_atomic ()) { +rcu_read_unlock ();local_unlock (bh_lock); + }preempt_check_resched (); }
And I have to ask...
What did you do to test this change to kernel/softirq.c? My past attempts to do this sort of thing have always run afoul of open-coded BH transitions.
Thanx, Paul
Re: [PATCH RT 1/4] rcu: Acquire RCU lock when disabling BHs
Quoted 13 lines · Paul E. McKenney
include/linux/rcupdate.h static inline void rcu_read_unlock(void) · line 640
Quoted 9 lines · Scott Wood
include/linux/rcupdate.h +1
-0@@ -637,10 +637,12 @@ static inline void rcu_read_unlock(void)static inline void rcu_read_lock_bh (void ) {local_bh_disable (); +#ifndef CONFIG_PREEMPT_RT_FULL How about this instead?
Quoted 2 lines
if (IS_ENABLED(CONFIG_PREEMPT_RT_FULL)) return;
OK.
Quoted 11 lines
Quoted 11 lines
include/linux/rcupdate.h +3
-1@@ -189,8 +193,10 @@ void __local_bh_enable_ip(unsigned long ip, unsigned int cnt) WARN_ON_ONCE(count < 0);local_irq_enable (); -if (!in_atomic ()) +if (!in_atomic ()) { +rcu_read_unlock ();local_unlock (bh_lock); + }
Quoted 8 lines
Quoted 2 lines
include/linux/rcupdate.h +0
-0preempt_check_resched ();}
And I have to ask...
What did you do to test this change to
kernel/softirq.c? My past attempts to do this sort of thing have always run afoul of open-coded BH transitions.
Mostly rcutorture and loads such as kernel builds, on a debug kernel. By "open-coded BH transition" do you mean directly manipulating the preempt count? That would already be broken on RT.
-Scott
Re: [RFC PATCH RT 3/4] rcu: unlock special: Treat irq and preempt disabled the same
In reply to Scott WoodQuoted 4 lines · Scott Wood
[Note: Just before posting this I noticed that the
invoke_rcu_corestuff
is part of the latest RCU pull request, and it has a patch that addresses this in a more complicated way that appears to deal with the bare irq-disabled sequence as well.
Far easier to deal with it than to debug the lack of it. ;-)
Quoted 5 lines
Assuming we need/want to support such sequences, is the
invoke_rcu_core()call actually going to result in scheduling any sooner?resched_curr()just does the same setting ofneed_reschedwhen it's the same cpu.
]
Yes, invoke_rcu_core() can in some cases invoke the scheduler sooner. Setting the CPU-local bits might not have effect until the next interrupt.
So if -rt wants the simpler and slower approach, the change needs to use IS_ENABLED(CONFIG_PREEMPT_RT_FULL) or similar. Not that this is an issue until CONFIG_PREEMPT_RT_FULL hits mainline.
Thanx, Paul
Quoted 68 lines
Since special should never be getting set inside an irqs-disabled critical section, this is safe as long as there are no sequences of rcu_read_lock()/local_irq_disable()/rcu_read_unlock()/local_irq_enable() (without
preempt_disable()wrapped around the IRQ disabling, as spinlocks do). If there are such sequences, then the grace period may be delayed until the next timeneed_reschedis checked.This is needed because otherwise, in a sequence such as:
1.rcu_read_lock()
2. *preempt*, set rcu_read_unlock_special.b.blocked
3.preempt_disable()
4.rcu_read_unlock()
5.preempt_enable()...rcu_read_unlock_special.b.blocked will not be cleared during step 4, because of the disabled preemption. If an interrupt is then taken between steps 4 and 5, and that interrupt enters scheduler code that takes pi/rq locks, and an rcu read lock inside that, then when dropping that rcu read lock we will end up in
rcu_read_unlock_special()again -- but this time, since irqs are disabled, it will callinvoke_rcu_core()in the RT tree (regardless ofPREEMPT_RT_FULL), which callswake_up_process(). This can cause a pi/rq lock deadlock. An example of interrupt code that does this isscheduler_tick().The above sequence can be found in (at least)
__lock_task_sighand()(for !PREEMPT_RT_FULL) andd_alloc_parallel().It's potentially an issue on non-RT as well. While
raise_softirq_irqoff()doesn't callwake_up_process()whenin_interrupt()is true, if code between steps 4 and 5 directly calls into scheduler code, and that code uses RCU with pi/rq lock held,wake_up_process()can still be called.On RT,
migrate_enable()is such a codepath, so anin_interrupt()check alone would not work on RT. Instead, keep track of whether we've already had anrcu_read_unlock_special()with preemption disabled but haven't yet scheduled, and rely on thepreempt_enable()yet to come instead of callinginvoke_rcu_core().Signed-off-by Scott Wood <[email protected]>--- kernel/rcu/tree_plugin.h | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)kernel/rcu/tree_plugin.h +2
-8@@ -630,14 +630,8 @@ static void rcu_read_unlock_special(struct task_struct *t)if (preempt_bh_were_disabled || irqs_were_disabled) {WRITE_ONCE (t->rcu_read_unlock_special.b.exp_hint, false);/* Need to defer quiescent state until everything is enabled. */ -if (irqs_were_disabled) { -/* Enabling irqs does not reschedule, so... */ -invoke_rcu_core (); - }else { -/* Enabling BH or preempt does reschedule, so... */ -set_tsk_need_resched (current); -set_preempt_need_resched (); - } +set_tsk_need_resched (current); +set_preempt_need_resched ();local_irq_restore (flags);return ; }Signature · 1 line
1.8.3.1
Re: [RFC PATCH RT 4/4] rcutorture: Avoid problematic critical section nesting
In reply to Scott WoodQuoted 34 lines · Scott Wood
rcutorture was generating some nesting scenarios that are not reasonable. Constrain the state selection to avoid them.
Example #1:
1.
preempt_disable()
2.local_bh_disable()
3.preempt_enable()
4.local_bh_enable()On
PREEMPT_RT, BH disabling takes a local lock only when called in non-atomic context. Thus, atomic context must be retained until after BH is re-enabled. Likewise, if BH is initially disabled in non-atomic context, it cannot be re-enabled in atomic context.Example #2:
1.
rcu_read_lock()
2.local_irq_disable()
3.rcu_read_unlock()
4.local_irq_enable()If the thread is preempted between steps 1 and 2, rcu_read_unlock_special.b.blocked will be set, but it won't be acted on in step 3 because IRQs are disabled. Thus, reporting of the quiescent state will be delayed beyond the
local_irq_enable().Example #3:
1.
preempt_disable()
2.local_irq_disable()
3.preempt_enable()
4.local_irq_enable()
Quoted 4 lines
If
need_reschedis set between steps 1 and 2, then the reschedule in step 3 will not happen.Signed-off-by Scott Wood <[email protected]>
OK for -rt, but as long as people can code those sequences without getting their wrists slapped, RCU needs to deal with it. So I cannot accept this in mainline at the current time. Yes, I will know when it is safe to accept it when rcutorture's virtual wrist gets slapped in mainline. Why did you ask? ;-)
But I have to ask... With this elaboration, is it time to make this a data-driven state machine? Or is the complexity not yet to the point where that would constitute a simplification?
Thanx, Paul
Quoted 160 lines
---
TODO: Document restrictions and add debug checks for invalid sequences.I had been planning to resolve #1 (only as shown, not the case of disabling preemption while non-atomic and enabling while atomic) by changing how
migrate_disable()works to avoid the split behavior, but recently BH disabling was changed to do the same thing. I still plan to send the migrate disable changes as a separate patchset, for the sake of the significant performance improvement I saw.--- kernel/rcu/rcutorture.c | 92 +++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 78 insertions(+), 14 deletions(-)kernel/rcu/rcutorture.c +78
-14@@ -73,10 +73,13 @@#define RCUTORTURE_RDR_RBH 0x08/* ... rcu_read_lock_bh(). */ #define RCUTORTURE_RDR_SCHED 0x10/* ... rcu_read_lock_sched(). */ #define RCUTORTURE_RDR_RCU 0x20/* ... entering another RCU reader. */ -#define RCUTORTURE_RDR_NBITS 6/* Number of bits defined above. */ +#define RCUTORTURE_RDR_ATOM_BH 0x40/* ... disabling bh while atomic */ +#define RCUTORTURE_RDR_ATOM_RBH 0x80/* ... RBH while atomic */ +#define RCUTORTURE_RDR_NBITS 8/* Number of bits defined above. */ #define RCUTORTURE_MAX_EXTEND \ (RCUTORTURE_RDR_BH | RCUTORTURE_RDR_IRQ | RCUTORTURE_RDR_PREEMPT | \ - RCUTORTURE_RDR_RBH | RCUTORTURE_RDR_SCHED) + RCUTORTURE_RDR_RBH | RCUTORTURE_RDR_SCHED | \ + RCUTORTURE_RDR_ATOM_BH | RCUTORTURE_RDR_ATOM_RBH)#define RCUTORTURE_RDR_MAX_LOOPS 0x7/* Maximum reader extensions. */ /* Must be power of two minus one. */ #define RCUTORTURE_RDR_MAX_SEGS (RCUTORTURE_RDR_MAX_LOOPS + 3)@@ -1111,31 +1114,52 @@ static void rcutorture_one_extend(int *readstate, int newstate,WARN_ON_ONCE ((idxold >>RCUTORTURE_RDR_SHIFT ) >1 ); rtrsp->rt_readstate = newstate; -/* First, put new protection in place to avoid critical-section gap. */ +/* +* First, put new protection in place to avoid critical-section gap. +* Disable preemption around the ATOM disables to ensure that +* in_atomic() is true. +*/ if (statesnew &RCUTORTURE_RDR_BH )local_bh_disable (); +if (statesnew &RCUTORTURE_RDR_RBH ) +rcu_read_lock_bh ();if (statesnew &RCUTORTURE_RDR_IRQ )local_irq_disable ();if (statesnew &RCUTORTURE_RDR_PREEMPT )preempt_disable (); -if (statesnew &RCUTORTURE_RDR_RBH ) -rcu_read_lock_bh ();if (statesnew &RCUTORTURE_RDR_SCHED )rcu_read_lock_sched (); +preempt_disable (); +if (statesnew &RCUTORTURE_RDR_ATOM_BH ) +local_bh_disable (); +if (statesnew &RCUTORTURE_RDR_ATOM_RBH ) +rcu_read_lock_bh (); +preempt_enable ();if (statesnew &RCUTORTURE_RDR_RCU ) idxnew = cur_ops->readlock () <<RCUTORTURE_RDR_SHIFT ; -/* Next, remove old protection, irq first due to bh conflict. */ +/* +* Next, remove old protection, in decreasing order of strength +* to avoid unlock paths that aren't safe in the stronger +* context. Disable preemption around the ATOM enables in +* case the context was only atomic due to IRQ disabling. +*/ +preempt_disable ();if (statesold &RCUTORTURE_RDR_IRQ )local_irq_enable (); -if (statesold &RCUTORTURE_RDR_BH ) +if (statesold &RCUTORTURE_RDR_ATOM_BH )local_bh_enable (); +if (statesold &RCUTORTURE_RDR_ATOM_RBH ) +rcu_read_unlock_bh (); +preempt_enable ();if (statesold &RCUTORTURE_RDR_PREEMPT )preempt_enable (); -if (statesold &RCUTORTURE_RDR_RBH ) -rcu_read_unlock_bh ();if (statesold &RCUTORTURE_RDR_SCHED )rcu_read_unlock_sched (); +if (statesold &RCUTORTURE_RDR_BH ) +local_bh_enable (); +if (statesold &RCUTORTURE_RDR_RBH ) +rcu_read_unlock_bh ();if (statesold &RCUTORTURE_RDR_RCU ) cur_ops->readunlock (idxold >>RCUTORTURE_RDR_SHIFT );@@ -1171,6 +1195,12 @@ static int rcutorture_extend_mask_max(void)int mask =rcutorture_extend_mask_max ();unsigned long randmask1 =torture_random (trsp) >>8 ;unsigned long randmask2 = randmask1 >>3 ; +unsigned long preempts =RCUTORTURE_RDR_PREEMPT |RCUTORTURE_RDR_SCHED ; +unsigned long preempts_irq = preempts |RCUTORTURE_RDR_IRQ ; +unsigned long nonatomic_bhs =RCUTORTURE_RDR_BH |RCUTORTURE_RDR_RBH ; +unsigned long atomic_bhs =RCUTORTURE_RDR_ATOM_BH | +RCUTORTURE_RDR_ATOM_RBH ; +unsigned long tmp;WARN_ON_ONCE (mask >>RCUTORTURE_RDR_SHIFT );/* Most of the time lots of bits, half the time only one bit. */ @@ -1178,11 +1208,45 @@ static int rcutorture_extend_mask_max(void) mask = mask & randmask2; else mask = mask & (1 << (randmask2 %RCUTORTURE_RDR_NBITS )); -/* Can't enable bh w/irq disabled. */ -if ((mask &RCUTORTURE_RDR_IRQ ) && - ((!(mask &RCUTORTURE_RDR_BH ) && (oldmask &RCUTORTURE_RDR_BH )) || - (!(mask &RCUTORTURE_RDR_RBH ) && (oldmask &RCUTORTURE_RDR_RBH )))) - mask |=RCUTORTURE_RDR_BH |RCUTORTURE_RDR_RBH ; + +/* +* Can't enable bh w/irq disabled. +* +* Can't enable preemption with irqs disabled, if irqs had ever +* been enabled during this preempt critical section (could miss +* a reschedule). +*/ + tmp = atomic_bhs | nonatomic_bhs | preempts; +if (mask &RCUTORTURE_RDR_IRQ ) + mask |= oldmask & tmp; + +/* +* Can't release the outermost rcu lock in an irq disabled +* section without preemption also being disabled, if irqs had +* ever been enabled during this RCU critical section (could leak +* a special flag and delay reporting the qs). +*/ +if ((oldmask &RCUTORTURE_RDR_RCU ) && (mask &RCUTORTURE_RDR_IRQ ) && + !(mask & preempts)) + mask |=RCUTORTURE_RDR_RCU ; + +/* Can't modify atomic bh in non-atomic context */ +if ((oldmask & atomic_bhs) && (mask & atomic_bhs) && + !(mask & preempts_irq)) { + mask |= oldmask & preempts_irq; +if (mask &RCUTORTURE_RDR_IRQ ) + mask |= oldmask & tmp; + } +if ((mask & atomic_bhs) && !(mask & preempts_irq)) + mask |=RCUTORTURE_RDR_PREEMPT ; + +/* Can't modify non-atomic bh in atomic context */ + tmp = nonatomic_bhs; +if (oldmask & preempts_irq) + mask &= ~tmp; +if ((oldmask | mask) & preempts_irq) + mask |= oldmask & tmp; +if ((mask &RCUTORTURE_RDR_IRQ ) && !(mask & cur_ops->ext_irq_conflict) && (oldmask & cur_ops->ext_irq_conflict))Signature · 1 line
1.8.3.1
Re: [PATCH RT 1/4] rcu: Acquire RCU lock when disabling BHs
In reply to Scott WoodQuoted 35 lines · Scott Wood
Quoted 13 lines · Paul E. McKenney
include/linux/rcupdate.h static inline void rcu_read_unlock(void) · line 640
Quoted 9 lines · Scott Wood
include/linux/rcupdate.h +1
-0@@ -637,10 +637,12 @@ static inline void rcu_read_unlock(void)static inline void rcu_read_lock_bh (void ) {local_bh_disable (); +#ifndef CONFIG_PREEMPT_RT_FULL How about this instead?
Quoted 2 lines
if (IS_ENABLED(CONFIG_PREEMPT_RT_FULL)) return;OK.
Quoted 16 lines
Quoted 12 lines
include/linux/rcupdate.h +3
-1@@ -189,8 +193,10 @@ void __local_bh_enable_ip(unsigned long ip, unsigned int cnt) WARN_ON_ONCE(count < 0);local_irq_enable (); -if (!in_atomic ()) +if (!in_atomic ()) { +rcu_read_unlock ();local_unlock (bh_lock); + }preempt_check_resched ();Quoted 1 line
}
And I have to ask...
Quoted 7 lines
Quoted 3 lines
What did you do to test this change to
kernel/softirq.c? My past attempts to do this sort of thing have always run afoul of open-coded BH transitions.Mostly rcutorture and loads such as kernel builds, on a debug kernel. By "open-coded BH transition" do you mean directly manipulating the preempt count? That would already be broken on RT.
OK, then maybe you guys have already done the needed cleanup work. Cool!
But don't the additions of rcu_read_lock() and rcu_read_unlock() want to be protected by "!IS_ENABLED(CONFIG_PREEMPT_RT_FULL)" or similar?
Thanx, Paul
Re: [PATCH RT 1/4] rcu: Acquire RCU lock when disabling BHs
Quoted 9 lines · Paul E. McKenney
Quoted 8 lines · Scott Wood
Quoted 6 lines · Paul E. McKenney
And I have to ask...
What did you do to test this change to
kernel/softirq.c? My past attempts
to do this sort of thing have always run afoul of open-coded BH transitions.
Quoted 6 lines
Quoted 4 lines
Mostly rcutorture and loads such as kernel builds, on a debug kernel. By
"open-coded BH transition" do you mean directly manipulating the preempt count? That would already be broken on RT.OK, then maybe you guys have already done the needed cleanup work. Cool!
Do you remember what code was doing such things? Grepping for the obvious things doesn't turn up anything outside the softirq code, even in the earlier non-RT kernels I checked.
Quoted 2 lines
But don't the additions of
rcu_read_lock()andrcu_read_unlock()want to be protected by "!IS_ENABLED(CONFIG_PREEMPT_RT_FULL)" or similar?
This is already a separate PREEMPT_RT_FULL-specific implementation.
-Scott
Re: [RFC PATCH RT 4/4] rcutorture: Avoid problematic critical section nesting
In reply to Paul E. McKenneyQuoted 39 lines · Paul E. McKenney
Quoted 38 lines · Scott Wood
rcutorture was generating some nesting scenarios that are not reasonable. Constrain the state selection to avoid them.
Example #1:
1.
preempt_disable()
2.local_bh_disable()
3.preempt_enable()
4.local_bh_enable()On
PREEMPT_RT, BH disabling takes a local lock only when called in non-atomic context. Thus, atomic context must be retained until after BH
is re-enabled. Likewise, if BH is initially disabled in non-atomic context, it cannot be re-enabled in atomic context.Example #2:
1.
rcu_read_lock()
2.local_irq_disable()
3.rcu_read_unlock()
4.local_irq_enable()If the thread is preempted between steps 1 and 2, rcu_read_unlock_special.b.blocked will be set, but it won't be acted on in step 3 because IRQs are disabled. Thus, reporting of the quiescent state will be delayed beyond the
local_irq_enable().Example #3:
1.
preempt_disable()
2.local_irq_disable()
3.preempt_enable()
4.local_irq_enable()If
need_reschedis set between steps 1 and 2, then the reschedule in step 3 will not happen.
Quoted 7 lines
Quoted 1 line
Signed-off-by Scott Wood <[email protected]>OK for -rt, but as long as people can code those sequences without getting their wrists slapped, RCU needs to deal with it. So I cannot accept this in mainline at the current time. Yes, I will know when it is safe to accept it when rcutorture's virtual wrist gets slapped in mainline. Why did you ask? ;-)
Hence the "TODO: Document restrictions and add debug checks for invalid sequences". :-)
Quoted 3 lines
But I have to ask... With this elaboration, is it time to make this a data-driven state machine? Or is the complexity not yet to the point where that would constitute a simplification?
Perhaps... Making the entire sequence visible to the constraint enforcement would also allow relaxing some of the constraints that currently have to assume the worst regarding what happened before the most recent state.
-Scott
Re: [RFC PATCH RT 3/4] rcu: unlock special: Treat irq and preempt disabled the same
In reply to Paul E. McKenneyQuoted 8 lines · Paul E. McKenney
Quoted 4 lines · Scott Wood
[Note: Just before posting this I noticed that the
invoke_rcu_corestuff
is part of the latest RCU pull request, and it has a patch that addresses this in a more complicated way that appears to deal with the bare irq-disabled sequence as well.Far easier to deal with it than to debug the lack of it. ;-)
Quoted 8 lines
Quoted 5 lines
Assuming we need/want to support such sequences, is the
invoke_rcu_core()call actually going to result in scheduling any sooner?resched_curr()just does the same setting ofneed_reschedwhen it's the same cpu.
]Yes,
invoke_rcu_core()can in some cases invoke the scheduler sooner. Setting the CPU-local bits might not have effect until the next interrupt.
Maybe I'm missing something, but I don't see how (in the non-use_softirq case). It just calls wake_up_process(), which in resched_curr() will set need_resched but not do an IPI-to-self.
-Scott
Re: [PATCH RT 1/4] rcu: Acquire RCU lock when disabling BHs
In reply to Scott WoodQuoted 15 lines · Scott Wood
Quoted 14 lines · Paul E. McKenney
Quoted 12 lines · Scott Wood
Quoted 6 lines · Paul E. McKenney
And I have to ask...
What did you do to test this change to
kernel/softirq.c? My past attempts
to do this sort of thing have always run afoul of open-coded BH transitions.Mostly rcutorture and loads such as kernel builds, on a debug kernel. By
"open-coded BH transition" do you mean directly manipulating the preempt count? That would already be broken on RT.
Quoted 5 lines
Quoted 1 line
OK, then maybe you guys have already done the needed cleanup work. Cool!
Do you remember what code was doing such things? Grepping for the obvious things doesn't turn up anything outside the softirq code, even in the earlier non-RT kernels I checked.
It was many years ago, and it is quite possible that I am conflating irqs with bh or some such. If it now works, it now works.
Quoted 4 lines
Quoted 2 lines
But don't the additions of
rcu_read_lock()andrcu_read_unlock()want to be protected by "!IS_ENABLED(CONFIG_PREEMPT_RT_FULL)" or similar?This is already a separate PREEMPT_RT_FULL-specific implementation.
Ah, sorry for the noise, then!
Thanx, Paul
Re: [RFC PATCH RT 3/4] rcu: unlock special: Treat irq and preempt disabled the same
In reply to Scott WoodQuoted 15 lines · Scott Wood
Quoted 14 lines · Paul E. McKenney
Quoted 4 lines · Scott Wood
[Note: Just before posting this I noticed that the
invoke_rcu_corestuff
is part of the latest RCU pull request, and it has a patch that addresses this in a more complicated way that appears to deal with the bare irq-disabled sequence as well.Far easier to deal with it than to debug the lack of it. ;-)
Quoted 5 lines
Assuming we need/want to support such sequences, is the
invoke_rcu_core()call actually going to result in scheduling any sooner?resched_curr()just does the same setting ofneed_reschedwhen it's the same cpu.
]
Quoted 6 lines
Quoted 2 lines
Yes,
invoke_rcu_core()can in some cases invoke the scheduler sooner. Setting the CPU-local bits might not have effect until the next interrupt.Maybe I'm missing something, but I don't see how (in the non-use_softirq case). It just calls
wake_up_process(), which inresched_curr()will setneed_reschedbut not do an IPI-to-self.
The common non-rt case will be use_softirq. Or are you referring specifically to this block of code in current -rcu?
} else if (exp && irqs_were_disabled && !use_softirq &&
!t->rcu_read_unlock_special.b.deferred_qs) {
// Safe to awaken and we get no help from enabling
// irqs, unlike bh/preempt.
invoke_rcu_core();
Thanx, PaulRe: [RFC PATCH RT 3/4] rcu: unlock special: Treat irq and preempt disabled the same
Quoted 27 lines · Paul E. McKenney
Quoted 17 lines · Scott Wood
Quoted 16 lines · Paul E. McKenney
Quoted 6 lines · Scott Wood
[Note: Just before posting this I noticed that the
invoke_rcu_corestuff
is part of the latest RCU pull request, and it has a patch that addresses this in a more complicated way that appears to deal with
the
bare irq-disabled sequence as well.Far easier to deal with it than to debug the lack of it. ;-)
Quoted 5 lines
Assuming we need/want to support such sequences, is the
invoke_rcu_core()call actually going to result in scheduling any sooner?resched_curr()just does the same setting ofneed_reschedwhen it's the same cpu.
]Quoted 8 lines
Quoted 3 lines
Yes,
invoke_rcu_core()can in some cases invoke the scheduler sooner. Setting the CPU-local bits might not have effect until the next interrupt.Maybe I'm missing something, but I don't see how (in the non-use_softirq case). It just calls
wake_up_process(), which inresched_curr()will setneed_reschedbut not do an IPI-to-self.
Quoted 8 lines
The common non-rt case will be
use_softirq. Or are you referring specifically to this block of code in current -rcu?} else if (exp && irqs_were_disabled && !use_softirq && !t->rcu_read_unlock_special.b.deferred_qs) { // Safe to awaken and we get no help from enabling // irqs, unlike bh/preempt. invoke_rcu_core();
Yes, that one. If that block is removed the else path should be sufficient, now that an IPI-to-self has been added.
Also, shouldn't the IPI-to-self be conditioned on irqs_were_disabled? Besides that being the problem the IPI was meant to address, if irqs are enabled the IPI is likely to happen before preempt is re-enabled and thus it won't accomplish anything.
-Scott
Re: [RFC PATCH RT 4/4] rcutorture: Avoid problematic critical section nesting
In reply to Paul E. McKenneyQuoted 21 lines · Paul E. McKenney
Quoted 14 lines
Example #1:
1.
preempt_disable()
2.local_bh_disable()
3.preempt_enable()
4.local_bh_enable()Example #2:
1.
rcu_read_lock()
2.local_irq_disable()
3.rcu_read_unlock()
4.local_irq_enable()Quoted 6 lines
Example #3:
1.
preempt_disable()
2.local_irq_disable()
3.preempt_enable()
4.local_irq_enable()
Quoted 4 lines
OK for -rt, but as long as people can code those sequences without getting their wrists slapped, RCU needs to deal with it. So I cannot accept this in mainline at the current time. Yes, I will know when it is safe to accept it when rcutorture's virtual wrist gets slapped in mainline.
All three examples are not symmetrical so if people use this mainline then they should get their wrists slapped. Since RT trips over each one of those I try to get rid of them if I notice something like that.
In example #3 you would lose a scheduling event if TIF_NEED_RESCHED gets set between step 1 and 2 (as local schedule requirement) because the preempt_enable() would trigger schedule() which does not happen due to IRQ-off.
Sebastian
Re: [RFC PATCH RT 4/4] rcutorture: Avoid problematic critical section nesting
Quoted 27 lines · Sebastian Andrzej Siewior
Quoted 21 lines · Paul E. McKenney
Quoted 14 lines
Example #1:
1.
preempt_disable()
2.local_bh_disable()
3.preempt_enable()
4.local_bh_enable()Example #2:
1.
rcu_read_lock()
2.local_irq_disable()
3.rcu_read_unlock()
4.local_irq_enable()Quoted 6 lines
Example #3:
1.
preempt_disable()
2.local_irq_disable()
3.preempt_enable()
4.local_irq_enable()Quoted 4 lines
OK for -rt, but as long as people can code those sequences without getting their wrists slapped, RCU needs to deal with it. So I cannot accept this in mainline at the current time. Yes, I will know when it is safe to accept it when rcutorture's virtual wrist gets slapped in mainline.
Quoted 8 lines
All three examples are not symmetrical so if people use this mainline then they should get their wrists slapped. Since RT trips over each one of those I try to get rid of them if I notice something like that.
In example #3 you would lose a scheduling event if
TIF_NEED_RESCHEDgets set between step 1 and 2 (as local schedule requirement) because thepreempt_enable()would triggerschedule()which does not happen due to IRQ-off.
I have no objection to the outlawing of a number of these sequences in mainline, but am rather pointing out that until they really are outlawed and eliminated, rcutorture must continue to test them in mainline. Of course, an rcutorture running in -rt should avoid testing things that break -rt, including these sequences.
Thanx, Paul
Re: [RFC PATCH RT 3/4] rcu: unlock special: Treat irq and preempt disabled the same
In reply to Scott WoodQuoted 31 lines · Scott Wood
Quoted 30 lines · Paul E. McKenney
Quoted 17 lines · Scott Wood
Quoted 16 lines · Paul E. McKenney
Quoted 6 lines · Scott Wood
[Note: Just before posting this I noticed that the
invoke_rcu_corestuff
is part of the latest RCU pull request, and it has a patch that addresses this in a more complicated way that appears to deal with
the
bare irq-disabled sequence as well.Far easier to deal with it than to debug the lack of it. ;-)
Quoted 5 lines
Assuming we need/want to support such sequences, is the
invoke_rcu_core()call actually going to result in scheduling any sooner?resched_curr()just does the same setting ofneed_reschedwhen it's the same cpu.
]Quoted 8 lines
Quoted 3 lines
Yes,
invoke_rcu_core()can in some cases invoke the scheduler sooner. Setting the CPU-local bits might not have effect until the next interrupt.Maybe I'm missing something, but I don't see how (in the non-use_softirq case). It just calls
wake_up_process(), which inresched_curr()will setneed_reschedbut not do an IPI-to-self.The common non-rt case will be
use_softirq. Or are you referring specifically to this block of code in current -rcu?
Quoted 8 lines
Quoted 5 lines
} else if (exp && irqs_were_disabled && !use_softirq && !t->rcu_read_unlock_special.b.deferred_qs) { // Safe to awaken and we get no help from enabling // irqs, unlike bh/preempt. invoke_rcu_core();Yes, that one. If that block is removed the else path should be sufficient, now that an IPI-to-self has been added.
I will give it a try and let you know what happens.
Quoted 4 lines
Also, shouldn't the IPI-to-self be conditioned on
irqs_were_disabled? Besides that being the problem the IPI was meant to address, if irqs are enabled the IPI is likely to happen before preempt is re-enabled and thus it won't accomplish anything.
Plus if preempt is disabled, the later preempt_enable() will check (ditto for local_bh_enable()). Unless the preempt_enable() is instead a preempt_enable_no_resched(), of course. :-/
Thanx, Paul
Re: [RFC PATCH RT 3/4] rcu: unlock special: Treat irq and preempt disabled the same
Quoted 38 lines · Paul E. McKenney
Quoted 37 lines · Scott Wood
Quoted 35 lines · Paul E. McKenney
Quoted 17 lines · Scott Wood
Quoted 16 lines · Paul E. McKenney
Quoted 6 lines · Scott Wood
[Note: Just before posting this I noticed that the
invoke_rcu_corestuff
is part of the latest RCU pull request, and it has a patch that addresses this in a more complicated way that appears to deal with
the
bare irq-disabled sequence as well.Far easier to deal with it than to debug the lack of it. ;-)
Quoted 5 lines
Assuming we need/want to support such sequences, is the
invoke_rcu_core()call actually going to result in scheduling any sooner?resched_curr()just does the same setting ofneed_reschedwhen it's the same cpu.
]Quoted 8 lines
Quoted 3 lines
Yes,
invoke_rcu_core()can in some cases invoke the scheduler sooner. Setting the CPU-local bits might not have effect until the next interrupt.Maybe I'm missing something, but I don't see how (in the non-use_softirq case). It just calls
wake_up_process(), which inresched_curr()will setneed_reschedbut not do an IPI-to-self.The common non-rt case will be
use_softirq. Or are you referring specifically to this block of code in current -rcu?} else if (exp && irqs_were_disabled && !use_softirq && !t->rcu_read_unlock_special.b.deferred_qs) { // Safe to awaken and we get no help from enabling // irqs, unlike bh/preempt. invoke_rcu_core();
Quoted 4 lines
Quoted 2 lines
Yes, that one. If that block is removed the else path should be sufficient, now that an IPI-to-self has been added.
I will give it a try and let you know what happens.
How about the following?
Thanx, Paul
------------------------------------------------------------------------
commit 2fd23b1b649bf7e0754fa1dfce01e945bc62f4af
Author: Paul E. McKenney <[email protected]> Date: Sat Jun 22 12:05:54 2019 -0700
rcu: Simplify rcu_read_unlock_special() deferred wakeups
In !use_softirq runs, we clearly cannot rely on raise_softirq() and its lightweight bit setting, so we must instead do some form of wakeup. In the absence of a self-IPI when interrupts are disabled, these wakeups can be delayed until the next interrupt occurs. This means that calling invoke_rcu_core() doesn't actually do any expediting.
In this case, it is better to take the "else" clause, which sets the current CPU's resched bits and, if there is an expedited grace period in flight, uses IRQ-work to force the needed self-IPI. This commit therefore removes the "else if" clause that calls invoke_rcu_core().
kernel/rcu/tree_plugin.h +1 -6
@@ -629,17 +629,12 @@ static void rcu_read_unlock_special(struct task_struct *t)// Using softirq, safe to awaken, and we get // no help from enabling irqs, unlike bh/preempt. raise_softirq_irqoff (RCU_SOFTIRQ ); - }else if (exp && irqs_were_disabled && !use_softirq && - !t->rcu_read_unlock_special.b.deferred_qs) { -// Safe to awaken and we get no help from enabling -// irqs, unlike bh/preempt. -invoke_rcu_core (); }else {// Enabling BH or preempt does reschedule, so... // Also if no expediting or NO_HZ_FULL, slow is OK. set_tsk_need_resched (current);set_preempt_need_resched (); -if (IS_ENABLED (CONFIG_IRQ_WORK ) && +if (IS_ENABLED (CONFIG_IRQ_WORK ) && irqs_were_disabled && !rdp->defer_qs_iw_pending && exp) {// Get scheduler to re-evaluate and call hooks. // If !IRQ_WORK, FQS scan will eventually IPI.
Re: [RFC PATCH RT 3/4] rcu: unlock special: Treat irq and preempt disabled the same
Quoted 50 lines · Paul E. McKenney
Quoted 49 lines · Paul E. McKenney
Quoted 48 lines · Scott Wood
Quoted 46 lines · Paul E. McKenney
Quoted 27 lines · Scott Wood
Quoted 21 lines · Paul E. McKenney
Quoted 9 lines · Scott Wood
[Note: Just before posting this I noticed that the
invoke_rcu_core
stuff
is part of the latest RCU pull request, and it has a patch
that
addresses this in a more complicated way that appears to deal
with
the
bare irq-disabled sequence as well.Far easier to deal with it than to debug the lack of it. ;-)
Quoted 7 lines
Assuming we need/want to support such sequences, is the
invoke_rcu_core()call actually going to result in scheduling
any
sooner?resched_curr()just does the same setting ofneed_resched
when it's the same cpu.
]Quoted 4 lines
Yes,
invoke_rcu_core()can in some cases invoke the scheduler sooner.
Setting the CPU-local bits might not have effect until the next interrupt.Quoted 6 lines
Maybe I'm missing something, but I don't see how (in the non-
use_softirq
case). It just callswake_up_process(), which inresched_curr()will
setneed_reschedbut not do an IPI-to-self.The common non-rt case will be
use_softirq. Or are you referring specifically to this block of code in current -rcu?} else if (exp && irqs_were_disabled && !use_softirq && !t-Quoted 1 line
rcu_read_unlock_special.b.deferred_qs) {
// Safe to awaken and we get no help from enabling // irqs, unlike bh/preempt. invoke_rcu_core();
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Yes, that one. If that block is removed the else path should be sufficient,
now that an IPI-to-self has been added.I will give it a try and let you know what happens.
How about the following?
Looks good, thanks.
-Scott
Steven Rostedt
reviewerRe: [RFC PATCH RT 4/4] rcutorture: Avoid problematic critical section nesting
In reply to Paul E. McKenneyQuoted 5 lines · On Fri, 21 Jun 2019 16:59:55 -0700 "Paul E. McKenney" <[email protected]>…
I have no objection to the outlawing of a number of these sequences in mainline, but am rather pointing out that until they really are outlawed and eliminated, rcutorture must continue to test them in mainline. Of course, an rcutorture running in -rt should avoid testing things that break -rt, including these sequences.
We should update lockdep to complain about these sequences. That would "outlaw" them in mainline. That is, after we clean up all the current sequences in the code. And we also need to get Linus's approval of this as I believe he was against enforcing this in the past.
-- Steve
Re: [RFC PATCH RT 4/4] rcutorture: Avoid problematic critical section nesting
Quoted 9 lines · Steven Rostedt
Quoted 5 lines · On Fri, 21 Jun 2019 16:59:55 -0700 "Paul E. McKenney" <[email protected]>…
I have no objection to the outlawing of a number of these sequences in mainline, but am rather pointing out that until they really are outlawed and eliminated, rcutorture must continue to test them in mainline. Of course, an rcutorture running in -rt should avoid testing things that break -rt, including these sequences.
Quoted 4 lines
We should update lockdep to complain about these sequences. That would "outlaw" them in mainline. That is, after we clean up all the current sequences in the code. And we also need to get Linus's approval of this as I believe he was against enforcing this in the past.
Was the opposition to prohibiting some specific sequence? It's only certain misnesting scenarios that are problematic. The rcu_read_lock/ local_irq_disable restriction can be dropped with the IPI-to-self added in Paul's tree. Are there any known instances of the other two (besides rcutorture)?
-Scott
Re: [RFC PATCH RT 4/4] rcutorture: Avoid problematic critical section nesting
Quoted 15 lines · Scott Wood
Quoted 9 lines · Steven Rostedt
Quoted 5 lines · On Fri, 21 Jun 2019 16:59:55 -0700 "Paul E. McKenney" <[email protected]>…
I have no objection to the outlawing of a number of these sequences in mainline, but am rather pointing out that until they really are outlawed and eliminated, rcutorture must continue to test them in mainline. Of course, an rcutorture running in -rt should avoid testing things that break -rt, including these sequences.
Quoted 4 lines
We should update lockdep to complain about these sequences. That would "outlaw" them in mainline. That is, after we clean up all the current sequences in the code. And we also need to get Linus's approval of this as I believe he was against enforcing this in the past.
Quoted 5 lines
Was the opposition to prohibiting some specific sequence? It's only certain misnesting scenarios that are problematic. The rcu_read_lock/
local_irq_disablerestriction can be dropped with the IPI-to-self added in Paul's tree. Are there any known instances of the other two (besides rcutorture)?
Given the failure scenario Sebastian Siewior reported today, there apparently are some, at least when running threaded interrupt handlers.
Thanx, Paul
Re: [RFC PATCH RT 4/4] rcutorture: Avoid problematic critical section nesting
Quoted 28 lines · Paul E. McKenney
Quoted 19 lines · Scott Wood
Quoted 12 lines · Steven Rostedt
Quoted 8 lines · On Fri, 21 Jun 2019 16:59:55 -0700 "Paul E. McKenney" <[email protected]>…
I have no objection to the outlawing of a number of these sequences in
mainline, but am rather pointing out that until they really are outlawed
and eliminated, rcutorture must continue to test them in mainline. Of course, an rcutorture running in -rt should avoid testing things that
break -rt, including these sequences.Quoted 5 lines
We should update lockdep to complain about these sequences. That would "outlaw" them in mainline. That is, after we clean up all the current sequences in the code. And we also need to get Linus's approval of this
as I believe he was against enforcing this in the past.Quoted 7 lines
Was the opposition to prohibiting some specific sequence? It's only certain
misnesting scenarios that are problematic. The rcu_read_lock/local_irq_disablerestriction can be dropped with the IPI-to-self added in
Paul's tree. Are there any known instances of the other two (besides rcutorture)?
Quoted 2 lines
Given the failure scenario Sebastian Siewior reported today, there apparently are some, at least when running threaded interrupt handlers.
That's the rcu misnesting, which it looks like we can allow with the IPI-to- self; I was asking about the other two. I suppose if we really need to, we could work around preempt_disable()/local_irq_disable()/preempt_enable()/ local_irq_enable() by having preempt_enable() do an IPI-to-self if need_resched is set and IRQs are disabled. The RT local_bh_disable() atomic/non-atomic misnesting would be more difficult, but I don't think impossible. I've got lazy migrate disable working (initially as an attempt to deal with misnesting but it turned out to give a huge speedup as well; will send as soon as I take care of a loose end in the deadline scheduler); it's possible that something similar could be done with the softirq lock (and given that I saw a slowdown when that lock was introduced, it may also be worth doing just for performance).
BTW, it's not clear to me whether the failure Sebastian saw was due to the bare irq disabled version, which was what I was talking about prohibiting (he didn't show the context that was interrupted). The version where preempt is disabled (with or without irqs being disabled inside the preempt disabled region) definitely happens and is what I was trying to address with patch 3/4.
-Scott
Re: [RFC PATCH RT 4/4] rcutorture: Avoid problematic critical section nesting
Quoted 21 lines · Scott Wood
Quoted 20 lines · Paul E. McKenney
Quoted 19 lines · Scott Wood
Quoted 17 lines · Steven Rostedt
Quoted 8 lines · On Fri, 21 Jun 2019 16:59:55 -0700 "Paul E. McKenney" <[email protected]>…
I have no objection to the outlawing of a number of these sequences in
mainline, but am rather pointing out that until they really are outlawed
and eliminated, rcutorture must continue to test them in mainline. Of course, an rcutorture running in -rt should avoid testing things that
break -rt, including these sequences.We should update lockdep to complain about these sequences. That would "outlaw" them in mainline. That is, after we clean up all the current sequences in the code. And we also need to get Linus's approval of this
as I believe he was against enforcing this in the past.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Was the opposition to prohibiting some specific sequence? It's only certain
misnesting scenarios that are problematic. The rcu_read_lock/local_irq_disablerestriction can be dropped with the IPI-to-self added in
Paul's tree. Are there any known instances of the other two (besides rcutorture)?
If by IPI-to-self you mean the IRQ work trick, that isn't implemented across all architectures yet, is it?
Quoted 16 lines
Quoted 2 lines
Given the failure scenario Sebastian Siewior reported today, there apparently are some, at least when running threaded interrupt handlers.
That's the rcu misnesting, which it looks like we can allow with the IPI-to- self; I was asking about the other two. I suppose if we really need to, we could work around preempt_disable()/local_irq_disable()/preempt_enable()/
local_irq_enable()by havingpreempt_enable()do an IPI-to-self ifneed_reschedis set and IRQs are disabled. The RTlocal_bh_disable()atomic/non-atomic misnesting would be more difficult, but I don't think impossible. I've got lazy migrate disable working (initially as an attempt to deal with misnesting but it turned out to give a huge speedup as well; will send as soon as I take care of a loose end in the deadline scheduler); it's possible that something similar could be done with the softirq lock (and given that I saw a slowdown when that lock was introduced, it may also be worth doing just for performance).
Quoted 6 lines
BTW, it's not clear to me whether the failure Sebastian saw was due to the bare irq disabled version, which was what I was talking about prohibiting (he didn't show the context that was interrupted). The version where preempt is disabled (with or without irqs being disabled inside the preempt disabled region) definitely happens and is what I was trying to address with patch 3/4.
I don't claim to yet fully understand what Sebastian was seeing, though I am obviously hoping that my local experiments showing it to be fixed in current -rcu hold true.
Why not simply make rcutorture check whether it is running in a PREEMPT_RT_FULL environment and avoid the PREEMPT_RT_FULL-unfriendly testing only in that case? This could be done compatibly with mainline by adding another rcutorture module parameter that suppressed the problematic testing, disabled by default. Such a patch could be accepted into mainline, and then -rt could have a very small patch that changed the default to enabled for CONFIG_PREEMPT_RT_FULL=y kernels.
And should we later get to a place where the PREEMPT_RT_FULL-unfriendly scenarios are prohibited across all kernel configurations, then the module parameter can be removed. Again, until we know (as opposed to suspect) that these scenarios really don't happen, mainline rcutorture must continue testing them.
Thanx, Paul
Re: [RFC PATCH RT 4/4] rcutorture: Avoid problematic critical section nesting
Quoted 33 lines · Paul E. McKenney
Quoted 22 lines · Scott Wood
Quoted 21 lines · Paul E. McKenney
Quoted 20 lines · Scott Wood
Quoted 19 lines
Quoted 11 lines · On Fri, 21 Jun 2019 16:59:55 -0700 "Paul E. McKenney" <[email protected]>…
I have no objection to the outlawing of a number of these sequences
in
mainline, but am rather pointing out that until they really are outlawed
and eliminated, rcutorture must continue to test them in mainline.
Of course, an rcutorture running in -rt should avoid testing things
that
break -rt, including these sequences.sequences in the code. And we also need to get Linus's approval of this
as I believe he was against enforcing this in the past.Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Was the opposition to prohibiting some specific sequence? It's only certain
misnesting scenarios that are problematic. The rcu_read_lock/local_irq_disablerestriction can be dropped with the IPI-to-self added
in
Paul's tree. Are there any known instances of the other two (besides
rcutorture)?
Quoted 2 lines
If by IPI-to-self you mean the IRQ work trick, that isn't implemented across all architectures yet, is it?
Right... smp_send_reschedule() has wider coverage, but even then there's some hardware that just can't do it reasonably (e.g. pre-APIC x86). So I guess the options are:
1. Accept that such hardware might experience delayed grace period completion in certain configurations,
2. Have such hardware check for need_resched in local_irq_enable() (not nice if sharing a kernel build with hardware that doesn't need it), or
3. Forbid the sequence (enforced by debug checks). Again, this would only prohibit rcu_read_lock()/local_irq_disable()/rcu_read_unlock()/ local_irq_enable() *without* preempt disabling around the IRQ-disabled region.
Quoted 9 lines
Why not simply make rcutorture cyheck whether it is running in a
PREEMPT_RT_FULLenvironment and avoid the PREEMPT_RT_FULL-unfriendly testing only in that case?And should we later get to a place where the PREEMPT_RT_FULL-unfriendly scenarios are prohibited across all kernel configurations, then the module parameter can be removed. Again, until we know (as opposed to suspect) that these scenarios really don't happen, mainline rcutorture must continue testing them.
Yes, I already acknowledged that debug checks detecting the sequences should come before the test removal (including this patch as an RFC at this point was mainly meant as a demonstration of what's needed to get rcutorture to pass), but it'd be nice to have some idea of whether there would be opposition to the concept before coding up the checks. I'd rather not continue the state of "these sequences can blow up on RT and we don't know if they exist or not" any longer than necessary. Plus, only one of the sequences is exclusively an RT issue (though it's the one with the worst consequences).
-Scott
Re: [RFC PATCH RT 4/4] rcutorture: Avoid problematic critical section nesting
Quoted 34 lines · Scott Wood
Quoted 33 lines · Paul E. McKenney
Quoted 31 lines · Scott Wood
Quoted 30 lines · Paul E. McKenney
Quoted 29 lines · Scott Wood
Quoted 16 lines
Quoted 11 lines · On Fri, 21 Jun 2019 16:59:55 -0700 "Paul E. McKenney" <[email protected]>…
I have no objection to the outlawing of a number of these sequences
in
mainline, but am rather pointing out that until they really are outlawed
and eliminated, rcutorture must continue to test them in mainline.
Of course, an rcutorture running in -rt should avoid testing things
that
break -rt, including these sequences.Quoted 3 lines
sequences in the code. And we also need to get Linus's approval of this
as I believe he was against enforcing this in the past.Was the opposition to prohibiting some specific sequence? It's only certain
misnesting scenarios that are problematic. The rcu_read_lock/local_irq_disablerestriction can be dropped with the IPI-to-self added
in
Paul's tree. Are there any known instances of the other two (besides
rcutorture)?
Quoted 5 lines
Quoted 2 lines
If by IPI-to-self you mean the IRQ work trick, that isn't implemented across all architectures yet, is it?
Right...
smp_send_reschedule()has wider coverage, but even then there's some hardware that just can't do it reasonably (e.g. pre-APIC x86).
Except that smp_send_reschedule() won't do anything unless the scheduler things something needs to be done, as it its wake list is non-empty. Which might explain why Peter Zijlstra didn't suggest it.
Quoted 11 lines
So I
guess the options are:1. Accept that such hardware might experience delayed grace period completion in certain configurations,
2. Have such hardware check forneed_reschedinlocal_irq_enable()(not nice if sharing a kernel build with hardware that doesn't need it), or
3. Forbid the sequence (enforced by debug checks). Again, this would only prohibit rcu_read_lock()/local_irq_disable()/rcu_read_unlock()/local_irq_enable()*without* preempt disabling around the IRQ-disabled region.
4. If further testing continues to show it to be reliable, continue using the scheme in -rcu.
5. Use a short-duration hrtimer to get a clean environment in short order. Yes, the timer might fire while preemption and/or softirqs are disabled, but then the code can rely on the following preempt_enable(), local_bh_enable(), or whatever. This condition should be sufficiently rare to avoid issues with hrtimer overhead.
6. Use smp_call_function_single() to IPI some other poor slob of a CPU, which then does the same back. Non-waiting version in both cases, of course.
Probably others as well.
Quoted 4 lines
Quoted 4 lines
Why not simply make rcutorture cyheck whether it is running in a
PREEMPT_RT_FULLenvironment and avoid the PREEMPT_RT_FULL-unfriendly testing only in that case?
Quoted 8 lines
Quoted 5 lines
And should we later get to a place where the PREEMPT_RT_FULL-unfriendly scenarios are prohibited across all kernel configurations, then the module parameter can be removed. Again, until we know (as opposed to suspect) that these scenarios really don't happen, mainline rcutorture must continue testing them.
Yes, I already acknowledged that debug checks detecting the sequences should come before the test removal
OK, good to hear. As you may have noticed, I was getting the impression that you might have changed your mind on this point. ;-)
Quoted 8 lines
(including this patch as an RFC at this point
was mainly meant as a demonstration of what's needed to get rcutorture to pass), but it'd be nice to have some idea of whether there would be opposition to the concept before coding up the checks. I'd rather not continue the state of "these sequences can blow up on RT and we don't know if they exist or not" any longer than necessary. Plus, only one of the sequences is exclusively an RT issue (though it's the one with the worst consequences).
Steve Rostedt's point about enlisting the aid of lockdep seems worth looking into.
Thanx, Paul
Re: [RFC PATCH RT 4/4] rcutorture: Avoid problematic critical section nesting
Quoted 11 lines · Paul E. McKenney
Quoted 6 lines · Scott Wood
Quoted 2 lines · Paul E. McKenney
If by IPI-to-self you mean the IRQ work trick, that isn't implemented across all architectures yet, is it?
Right...
smp_send_reschedule()has wider coverage, but even then there's some hardware that just can't do it reasonably (e.g. pre-APIC x86).Except that
smp_send_reschedule()won't do anything unless the scheduler things something needs to be done, as it its wake list is non-empty. Which might explain why Peter Zijlstra didn't suggest it.
The wake list stuff is separate from the original purpose of the IPI, which is to hit the need_resched check on IRQ exit. When that happens, the scheduler will call into RCU, even if it doesn't change threads.
Quoted 13 lines
Quoted 12 lines
So I guess the options are:
1. Accept that such hardware might experience delayed grace period completion in certain configurations,
2. Have such hardware check forneed_reschedinlocal_irq_enable()(not nice
if sharing a kernel build with hardware that doesn't need it), or
3. Forbid the sequence (enforced by debug checks). Again, this would only
prohibit rcu_read_lock()/local_irq_disable()/rcu_read_unlock()/local_irq_enable()*without* preempt disabling around the IRQ-disabled region.
Quoted 2 lines
4. If further testing continues to show it to be reliable, continue using the scheme in -rcu.
If the testing isn't done on machines that can't do the IPI then it's basically option #1. FWIW I don't think option #1 is unreasonable given that we're talking about very old and/or specialized hardware, and we're only talking about delays, not a crash (maybe limit the ability to use nohz_full on such hardware?). Of course if it turns out people are actually trying to run (modern versions of) RT on such hardware, that might be different. :-)
Quoted 5 lines
5. Use a short-duration hrtimer to get a clean environment in short order. Yes, the timer might fire while preemption and/or softirqs are disabled, but then the code can rely on the following
preempt_enable(),local_bh_enable(), or whatever. This condition should be sufficiently rare to avoid issues with hrtimer overhead.
Yeah, I considered that but was hesitant due to overhead -- at least in the case of the example I gave (pre-APIC x86), arming a oneshot timer is pretty slow. Plus, some hardware might entirely lack one-shot timer capability.
Quoted 3 lines
6. Use
smp_call_function_single()to IPI some other poor slob of a CPU, which then does the same back. Non-waiting version in both cases, of course.
I was assuming any hardware that can't do smp_send_reschedule() is not SMP.
Quoted 35 lines
Probably others as well.
Quoted 13 lines
Quoted 4 lines
Why not simply make rcutorture cyheck whether it is running in a
PREEMPT_RT_FULLenvironment and avoid the PREEMPT_RT_FULL-unfriendly testing only in that case?Quoted 8 lines
And should we later get to a place where the PREEMPT_RT_FULL- unfriendly
scenarios are prohibited across all kernel configurations, then the module
parameter can be removed. Again, until we know (as opposed to suspect)
that these scenarios really don't happen, mainline rcutorture must continue testing them.Quoted 3 lines
Yes, I already acknowledged that debug checks detecting the sequences should
come before the test removalOK, good to hear. As you may have noticed, I was getting the impression that you might have changed your mind on this point. ;-)
Quoted 11 lines
(including this patch as an RFC at this
point
was mainly meant as a demonstration of what's needed to get rcutorture to
pass), but it'd be nice to have some idea of whether there would be opposition to the concept before coding up the checks. I'd rather not continue the state of "these sequences can blow up on RT and we don't know
if they exist or not" any longer than necessary. Plus, only one of the sequences is exclusively an RT issue (though it's the one with the worst consequences).
Quoted 2 lines
Steve Rostedt's point about enlisting the aid of lockdep seems worth looking into.
Sure. I was just concerned by the "Linus was against enforcing this in the past" comment and was hoping for more details.
-Scott
Re: [RFC PATCH RT 4/4] rcutorture: Avoid problematic critical section nesting
Quoted 9 lines · Scott Wood
Quoted 8 lines · Paul E. McKenney
Quoted 6 lines · Scott Wood
Quoted 2 lines · Paul E. McKenney
If by IPI-to-self you mean the IRQ work trick, that isn't implemented across all architectures yet, is it?
Right...
smp_send_reschedule()has wider coverage, but even then there's some hardware that just can't do it reasonably (e.g. pre-APIC x86).
Quoted 7 lines
Quoted 3 lines
Except that
smp_send_reschedule()won't do anything unless the scheduler things something needs to be done, as it its wake list is non-empty. Which might explain why Peter Zijlstra didn't suggest it.The wake list stuff is separate from the original purpose of the IPI, which is to hit the
need_reschedcheck on IRQ exit. When that happens, the scheduler will call into RCU, even if it doesn't change threads.
Got it, thank you!
Quoted 16 lines
Quoted 13 lines
Quoted 12 lines
So I guess the options are:
1. Accept that such hardware might experience delayed grace period completion in certain configurations,
2. Have such hardware check forneed_reschedinlocal_irq_enable()(not nice
if sharing a kernel build with hardware that doesn't need it), or
3. Forbid the sequence (enforced by debug checks). Again, this would only
prohibit rcu_read_lock()/local_irq_disable()/rcu_read_unlock()/local_irq_enable()*without* preempt disabling around the IRQ-disabled region.Quoted 2 lines
4. If further testing continues to show it to be reliable, continue using the scheme in -rcu.
Quoted 7 lines
If the testing isn't done on machines that can't do the IPI then it's basically option #1. FWIW I don't think option #1 is unreasonable given that we're talking about very old and/or specialized hardware, and we're only talking about delays, not a crash (maybe limit the ability to use
nohz_fullon such hardware?). Of course if it turns out people are actually trying to run (modern versions of) RT on such hardware, that might be different. :-)
Having tried and failed to remove DEC Alpha support several times, I know which way to bet. Though DEC Alpha support is no longer much of a burden on the non-Alpha portions of Linux, so no longer much motivation for removing its support.
Quoted 9 lines
Quoted 5 lines
5. Use a short-duration hrtimer to get a clean environment in short order. Yes, the timer might fire while preemption and/or softirqs are disabled, but then the code can rely on the following
preempt_enable(),local_bh_enable(), or whatever. This condition should be sufficiently rare to avoid issues with hrtimer overhead.Yeah, I considered that but was hesitant due to overhead -- at least in the case of the example I gave (pre-APIC x86), arming a oneshot timer is pretty slow. Plus, some hardware might entirely lack one-shot timer capability.
The overhead is incurred in a rare case, and on systems lacking oneshot timer it is always possible to fall back on normal timers, albeit with fixed-time added delays. But yes, this does add a bit of complexity.
Alternatively, assuming this case is rare, normal timers might suffice without the need for hrtimers.
Quoted 5 lines
Quoted 3 lines
6. Use
smp_call_function_single()to IPI some other poor slob of a CPU, which then does the same back. Non-waiting version in both cases, of course.I was assuming any hardware that can't do
smp_send_reschedule()is not SMP.
I have no idea either way.
Quoted 34 lines
Quoted 34 lines
Probably others as well.
Quoted 13 lines
Quoted 4 lines
Why not simply make rcutorture cyheck whether it is running in a
PREEMPT_RT_FULLenvironment and avoid the PREEMPT_RT_FULL-unfriendly testing only in that case?Quoted 8 lines
And should we later get to a place where the PREEMPT_RT_FULL- unfriendly
scenarios are prohibited across all kernel configurations, then the module
parameter can be removed. Again, until we know (as opposed to suspect)
that these scenarios really don't happen, mainline rcutorture must continue testing them.Quoted 3 lines
Yes, I already acknowledged that debug checks detecting the sequences should
come before the test removalOK, good to hear. As you may have noticed, I was getting the impression that you might have changed your mind on this point. ;-)
Quoted 11 lines
(including this patch as an RFC at this
point
was mainly meant as a demonstration of what's needed to get rcutorture to
pass), but it'd be nice to have some idea of whether there would be opposition to the concept before coding up the checks. I'd rather not continue the state of "these sequences can blow up on RT and we don't know
if they exist or not" any longer than necessary. Plus, only one of the sequences is exclusively an RT issue (though it's the one with the worst consequences).
Quoted 5 lines
Quoted 2 lines
Steve Rostedt's point about enlisting the aid of lockdep seems worth looking into.
Sure. I was just concerned by the "Linus was against enforcing this in the past" comment and was hoping for more details.
It is sometimes the case that showing that something never happens makes people more comfortable with enforcing that something.
Thanx, Paul