Skip to content

Commit a278d47

Browse files
paulmckrostedt
authored andcommitted
rcu: Fix dyntick-idle tracing
The tracing subsystem started using rcu_irq_entry() and rcu_irq_exit() (with my blessing) to allow the current _rcuidle alternative tracepoint name to be dispensed with while still maintaining good performance. Unfortunately, this causes RCU's dyntick-idle entry code's tracing to appear to RCU like an interrupt that occurs where RCU is not designed to handle interrupts. This commit fixes this problem by moving the zeroing of ->dynticks_nesting after the offending trace_rcu_dyntick() statement, which narrows the window of vulnerability to a pair of adjacent statements that are now marked with comments to that effect. Link: http://lkml.kernel.org/r/20170405093207.404f8deb@gandalf.local.home Link: http://lkml.kernel.org/r/20170405193928.GM1600@linux.vnet.ibm.com Reported-by: Steven Rostedt <rostedt@goodmis.org> Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
1 parent 8aaf1ee commit a278d47

1 file changed

Lines changed: 23 additions & 25 deletions

File tree

‎kernel/rcu/tree.c‎

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
#include <linux/random.h>
5858
#include <linux/trace_events.h>
5959
#include <linux/suspend.h>
60+
#include <linux/ftrace.h>
6061

6162
#include "tree.h"
6263
#include "rcu.h"
@@ -771,25 +772,24 @@ cpu_needs_another_gp(struct rcu_state *rsp, struct rcu_data *rdp)
771772
}
772773

773774
/*
774-
* rcu_eqs_enter_common - current CPU is moving towards extended quiescent state
775+
* rcu_eqs_enter_common - current CPU is entering an extended quiescent state
775776
*
776-
* If the new value of the ->dynticks_nesting counter now is zero,
777-
* we really have entered idle, and must do the appropriate accounting.
778-
* The caller must have disabled interrupts.
777+
* Enter idle, doing appropriate accounting. The caller must have
778+
* disabled interrupts.
779779
*/
780-
static void rcu_eqs_enter_common(long long oldval, bool user)
780+
static void rcu_eqs_enter_common(bool user)
781781
{
782782
struct rcu_state *rsp;
783783
struct rcu_data *rdp;
784-
RCU_TRACE(struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);)
784+
struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
785785

786-
trace_rcu_dyntick(TPS("Start"), oldval, rdtp->dynticks_nesting);
786+
trace_rcu_dyntick(TPS("Start"), rdtp->dynticks_nesting, 0);
787787
if (IS_ENABLED(CONFIG_RCU_EQS_DEBUG) &&
788788
!user && !is_idle_task(current)) {
789789
struct task_struct *idle __maybe_unused =
790790
idle_task(smp_processor_id());
791791

792-
trace_rcu_dyntick(TPS("Error on entry: not idle task"), oldval, 0);
792+
trace_rcu_dyntick(TPS("Error on entry: not idle task"), rdtp->dynticks_nesting, 0);
793793
rcu_ftrace_dump(DUMP_ORIG);
794794
WARN_ONCE(1, "Current pid: %d comm: %s / Idle pid: %d comm: %s",
795795
current->pid, current->comm,
@@ -800,7 +800,10 @@ static void rcu_eqs_enter_common(long long oldval, bool user)
800800
do_nocb_deferred_wakeup(rdp);
801801
}
802802
rcu_prepare_for_idle();
803-
rcu_dynticks_eqs_enter();
803+
stack_tracer_disable();
804+
rdtp->dynticks_nesting = 0; /* Breaks tracing momentarily. */
805+
rcu_dynticks_eqs_enter(); /* After this, tracing works again. */
806+
stack_tracer_enable();
804807
rcu_dynticks_task_enter();
805808

806809
/*
@@ -821,19 +824,15 @@ static void rcu_eqs_enter_common(long long oldval, bool user)
821824
*/
822825
static void rcu_eqs_enter(bool user)
823826
{
824-
long long oldval;
825827
struct rcu_dynticks *rdtp;
826828

827829
rdtp = this_cpu_ptr(&rcu_dynticks);
828-
oldval = rdtp->dynticks_nesting;
829830
WARN_ON_ONCE(IS_ENABLED(CONFIG_RCU_EQS_DEBUG) &&
830-
(oldval & DYNTICK_TASK_NEST_MASK) == 0);
831-
if ((oldval & DYNTICK_TASK_NEST_MASK) == DYNTICK_TASK_NEST_VALUE) {
832-
rdtp->dynticks_nesting = 0;
833-
rcu_eqs_enter_common(oldval, user);
834-
} else {
831+
(rdtp->dynticks_nesting & DYNTICK_TASK_NEST_MASK) == 0);
832+
if ((rdtp->dynticks_nesting & DYNTICK_TASK_NEST_MASK) == DYNTICK_TASK_NEST_VALUE)
833+
rcu_eqs_enter_common(user);
834+
else
835835
rdtp->dynticks_nesting -= DYNTICK_TASK_NEST_VALUE;
836-
}
837836
}
838837

839838
/**
@@ -892,19 +891,18 @@ void rcu_user_enter(void)
892891
*/
893892
void rcu_irq_exit(void)
894893
{
895-
long long oldval;
896894
struct rcu_dynticks *rdtp;
897895

898896
RCU_LOCKDEP_WARN(!irqs_disabled(), "rcu_irq_exit() invoked with irqs enabled!!!");
899897
rdtp = this_cpu_ptr(&rcu_dynticks);
900-
oldval = rdtp->dynticks_nesting;
901-
rdtp->dynticks_nesting--;
902898
WARN_ON_ONCE(IS_ENABLED(CONFIG_RCU_EQS_DEBUG) &&
903-
rdtp->dynticks_nesting < 0);
904-
if (rdtp->dynticks_nesting)
905-
trace_rcu_dyntick(TPS("--="), oldval, rdtp->dynticks_nesting);
906-
else
907-
rcu_eqs_enter_common(oldval, true);
899+
rdtp->dynticks_nesting < 1);
900+
if (rdtp->dynticks_nesting <= 1) {
901+
rcu_eqs_enter_common(true);
902+
} else {
903+
trace_rcu_dyntick(TPS("--="), rdtp->dynticks_nesting, rdtp->dynticks_nesting - 1);
904+
rdtp->dynticks_nesting--;
905+
}
908906
rcu_sysidle_enter(1);
909907
}
910908

0 commit comments

Comments
 (0)