linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH RCU -stable] Make need_resched() respond to urgent RCU-QS needs
@ 2018-11-05  2:34 Paul E. McKenney
  2018-11-29 12:39 ` Greg KH
  0 siblings, 1 reply; 2+ messages in thread
From: Paul E. McKenney @ 2018-11-05  2:34 UTC (permalink / raw)
  To: stable
  Cc: mhillenb, dwmw2, peterz, josh, rostedt, mathieu.desnoyers,
	jiangshanlai, linux-kernel

commit 92aa39e9dc77 upstream.

The per-CPU rcu_dynticks.rcu_urgent_qs variable communicates an urgent
need for an RCU quiescent state from the force-quiescent-state processing
within the grace-period kthread to context switches and to cond_resched().
Unfortunately, such urgent needs are not communicated to need_resched(),
which is sometimes used to decide when to invoke cond_resched(), for
but one example, within the KVM vcpu_run() function.  As of v4.15, this
can result in synchronize_sched() being delayed by up to ten seconds,
which can be problematic, to say nothing of annoying.

This commit therefore checks rcu_dynticks.rcu_urgent_qs from within
rcu_check_callbacks(), which is invoked from the scheduling-clock
interrupt handler.  If the current task is not an idle task and is
not executing in usermode, a context switch is forced, and either way,
the rcu_dynticks.rcu_urgent_qs variable is set to false.  If the current
task is an idle task, then RCU's dyntick-idle code will detect the
quiescent state, so no further action is required.  Similarly, if the
task is executing in usermode, other code in rcu_check_callbacks() and
its called functions will report the corresponding quiescent state.

Reported-by: Marius Hillenbrand <mhillenb@amazon.de>
Reported-by: David Woodhouse <dwmw2@infradead.org>
Suggested-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
[ paulmck: Backported to make patch apply cleanly on older versions. ]
Tested-by: Marius Hillenbrand <mhillenb@amazon.de>
Cc: <stable@vger.kernel.org> # 4.12.x - 4.19.x

diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
index 0b760c1369f7..15301ed19da6 100644
--- a/kernel/rcu/tree.c
+++ b/kernel/rcu/tree.c
@@ -2662,6 +2662,15 @@ void rcu_check_callbacks(int user)
 		rcu_bh_qs();
 	}
 	rcu_preempt_check_callbacks();
+	/* The load-acquire pairs with the store-release setting to true. */
+	if (smp_load_acquire(this_cpu_ptr(&rcu_dynticks.rcu_urgent_qs))) {
+		/* Idle and userspace execution already are quiescent states. */
+		if (!rcu_is_cpu_rrupt_from_idle() && !user) {
+			set_tsk_need_resched(current);
+			set_preempt_need_resched();
+		}
+		__this_cpu_write(rcu_dynticks.rcu_urgent_qs, false);
+	}
 	if (rcu_pending())
 		invoke_rcu_core();
 


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH RCU -stable] Make need_resched() respond to urgent RCU-QS needs
  2018-11-05  2:34 [PATCH RCU -stable] Make need_resched() respond to urgent RCU-QS needs Paul E. McKenney
@ 2018-11-29 12:39 ` Greg KH
  0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2018-11-29 12:39 UTC (permalink / raw)
  To: Paul E. McKenney
  Cc: stable, mhillenb, dwmw2, peterz, josh, rostedt,
	mathieu.desnoyers, jiangshanlai, linux-kernel

On Sun, Nov 04, 2018 at 06:34:34PM -0800, Paul E. McKenney wrote:
> commit 92aa39e9dc77 upstream.
> 
> The per-CPU rcu_dynticks.rcu_urgent_qs variable communicates an urgent
> need for an RCU quiescent state from the force-quiescent-state processing
> within the grace-period kthread to context switches and to cond_resched().
> Unfortunately, such urgent needs are not communicated to need_resched(),
> which is sometimes used to decide when to invoke cond_resched(), for
> but one example, within the KVM vcpu_run() function.  As of v4.15, this
> can result in synchronize_sched() being delayed by up to ten seconds,
> which can be problematic, to say nothing of annoying.
> 
> This commit therefore checks rcu_dynticks.rcu_urgent_qs from within
> rcu_check_callbacks(), which is invoked from the scheduling-clock
> interrupt handler.  If the current task is not an idle task and is
> not executing in usermode, a context switch is forced, and either way,
> the rcu_dynticks.rcu_urgent_qs variable is set to false.  If the current
> task is an idle task, then RCU's dyntick-idle code will detect the
> quiescent state, so no further action is required.  Similarly, if the
> task is executing in usermode, other code in rcu_check_callbacks() and
> its called functions will report the corresponding quiescent state.
> 
> Reported-by: Marius Hillenbrand <mhillenb@amazon.de>
> Reported-by: David Woodhouse <dwmw2@infradead.org>
> Suggested-by: Peter Zijlstra <peterz@infradead.org>
> Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
> [ paulmck: Backported to make patch apply cleanly on older versions. ]
> Tested-by: Marius Hillenbrand <mhillenb@amazon.de>
> Cc: <stable@vger.kernel.org> # 4.12.x - 4.19.x
> 

Now queued up, thanks.

greg k-h

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-11-29 12:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-05  2:34 [PATCH RCU -stable] Make need_resched() respond to urgent RCU-QS needs Paul E. McKenney
2018-11-29 12:39 ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).