From: Greg Kroah-Hartman Date: Thu, 21 Mar 2019 17:33:34 +0000 (+0100) Subject: 5.0-stable patches X-Git-Tag: v3.18.137~15 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8e6aea49ca4bc7b43709de6c56c888961a57b010;p=thirdparty%2Fkernel%2Fstable-queue.git 5.0-stable patches added patches: rcu-do-rcu-gp-kthread-self-wakeup-from-softirq-and-interrupt.patch --- diff --git a/queue-5.0/rcu-do-rcu-gp-kthread-self-wakeup-from-softirq-and-interrupt.patch b/queue-5.0/rcu-do-rcu-gp-kthread-self-wakeup-from-softirq-and-interrupt.patch new file mode 100644 index 00000000000..9f8f6d9115a --- /dev/null +++ b/queue-5.0/rcu-do-rcu-gp-kthread-self-wakeup-from-softirq-and-interrupt.patch @@ -0,0 +1,84 @@ +From 1d1f898df6586c5ea9aeaf349f13089c6fa37903 Mon Sep 17 00:00:00 2001 +From: "Zhang, Jun" +Date: Tue, 18 Dec 2018 06:55:01 -0800 +Subject: rcu: Do RCU GP kthread self-wakeup from softirq and interrupt + +From: Zhang, Jun + +commit 1d1f898df6586c5ea9aeaf349f13089c6fa37903 upstream. + +The rcu_gp_kthread_wake() function is invoked when it might be necessary +to wake the RCU grace-period kthread. Because self-wakeups are normally +a useless waste of CPU cycles, if rcu_gp_kthread_wake() is invoked from +this kthread, it naturally refuses to do the wakeup. + +Unfortunately, natural though it might be, this heuristic fails when +rcu_gp_kthread_wake() is invoked from an interrupt or softirq handler +that interrupted the grace-period kthread just after the final check of +the wait-event condition but just before the schedule() call. In this +case, a wakeup is required, even though the call to rcu_gp_kthread_wake() +is within the RCU grace-period kthread's context. Failing to provide +this wakeup can result in grace periods failing to start, which in turn +results in out-of-memory conditions. + +This race window is quite narrow, but it actually did happen during real +testing. It would of course need to be fixed even if it was strictly +theoretical in nature. + +This patch does not Cc stable because it does not apply cleanly to +earlier kernel versions. + +Fixes: 48a7639ce80c ("rcu: Make callers awaken grace-period kthread") +Reported-by: "He, Bo" +Co-developed-by: "Zhang, Jun" +Co-developed-by: "He, Bo" +Co-developed-by: "xiao, jin" +Co-developed-by: Bai, Jie A +Signed-off: "Zhang, Jun" +Signed-off: "He, Bo" +Signed-off: "xiao, jin" +Signed-off: Bai, Jie A +Signed-off-by: "Zhang, Jun" +[ paulmck: Switch from !in_softirq() to "!in_interrupt() && + !in_serving_softirq() to avoid redundant wakeups and to also handle the + interrupt-handler scenario as well as the softirq-handler scenario that + actually occurred in testing. ] +Signed-off-by: Paul E. McKenney +Link: https://lkml.kernel.org/r/CD6925E8781EFD4D8E11882D20FC406D52A11F61@SHSMSX104.ccr.corp.intel.com +Signed-off-by: Greg Kroah-Hartman + +--- + kernel/rcu/tree.c | 19 ++++++++++++++----- + 1 file changed, 14 insertions(+), 5 deletions(-) + +--- a/kernel/rcu/tree.c ++++ b/kernel/rcu/tree.c +@@ -1557,14 +1557,23 @@ static bool rcu_future_gp_cleanup(struct + } + + /* +- * Awaken the grace-period kthread. Don't do a self-awaken, and don't +- * bother awakening when there is nothing for the grace-period kthread +- * to do (as in several CPUs raced to awaken, and we lost), and finally +- * don't try to awaken a kthread that has not yet been created. ++ * Awaken the grace-period kthread. Don't do a self-awaken (unless in ++ * an interrupt or softirq handler), and don't bother awakening when there ++ * is nothing for the grace-period kthread to do (as in several CPUs raced ++ * to awaken, and we lost), and finally don't try to awaken a kthread that ++ * has not yet been created. If all those checks are passed, track some ++ * debug information and awaken. ++ * ++ * So why do the self-wakeup when in an interrupt or softirq handler ++ * in the grace-period kthread's context? Because the kthread might have ++ * been interrupted just as it was going to sleep, and just after the final ++ * pre-sleep check of the awaken condition. In this case, a wakeup really ++ * is required, and is therefore supplied. + */ + static void rcu_gp_kthread_wake(void) + { +- if (current == rcu_state.gp_kthread || ++ if ((current == rcu_state.gp_kthread && ++ !in_interrupt() && !in_serving_softirq()) || + !READ_ONCE(rcu_state.gp_flags) || + !rcu_state.gp_kthread) + return; diff --git a/queue-5.0/series b/queue-5.0/series index 3966210e2af..b86a8107728 100644 --- a/queue-5.0/series +++ b/queue-5.0/series @@ -208,3 +208,4 @@ x86-kvmclock-set-offset-for-kvm-unstable-clock.patch x86-ftrace-fix-warning-and-considate-ftrace_jmp_replace-and-ftrace_call_replace.patch tpm-tpm_crb-avoid-unaligned-reads-in-crb_recv.patch tpm-unify-the-send-callback-behaviour.patch +rcu-do-rcu-gp-kthread-self-wakeup-from-softirq-and-interrupt.patch