linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org,
	rostedt@goodmis.org
Cc: peterz@infradead.org, mingo@kernel.org, joel@joelfernandes.org,
	gregkh@linuxfoundation.org, gustavo@embeddedor.com,
	tglx@linutronix.de, paulmck@kernel.org, josh@joshtriplett.org,
	mathieu.desnoyers@efficios.com, jiangshanlai@gmail.com
Subject: [PATCH 3/8] rcu,tracing: Create trace_rcu_{enter,exit}()
Date: Wed, 12 Feb 2020 10:32:13 +0100	[thread overview]
Message-ID: <20200212094107.781220598@infradead.org> (raw)
In-Reply-To: 20200212093210.468391728@infradead.org

To facilitate tracers that need RCU, add some helpers to wrap the
magic required.

The problem is that we can call into tracers (trace events and
function tracing) while RCU isn't watching and this can happen from
any context, including NMI.

It is this latter that is causing most of the trouble; we must make
sure in_nmi() returns true before we land in anything tracing,
otherwise we cannot recover.

These helpers are macros because of header-hell; they're placed here
because of the proximity to nmi_{enter,exit{().

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
 include/linux/hardirq.h |   48 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)

--- a/include/linux/hardirq.h
+++ b/include/linux/hardirq.h
@@ -89,4 +89,52 @@ extern void irq_exit(void);
 		arch_nmi_exit();				\
 	} while (0)
 
+/*
+ * Tracing vs RCU
+ * --------------
+ *
+ * tracepoints and function-tracing can happen when RCU isn't watching (idle,
+ * or early IRQ/NMI entry).
+ *
+ * When it happens during idle or early during IRQ entry, tracing will have
+ * to inform RCU that it ought to pay attention, this is done by calling
+ * rcu_irq_enter_irqsave().
+ *
+ * On NMI entry, we must be very careful that tracing only happens after we've
+ * incremented preempt_count(), otherwise we cannot tell we're in NMI and take
+ * the special path.
+ */
+
+#define __TR_IRQ	1
+#define __TR_NMI	2
+
+#define trace_rcu_enter()					\
+({								\
+	unsigned long state = 0;				\
+	if (!rcu_is_watching())	{				\
+		if (in_nmi()) {					\
+			state = __TR_NMI;			\
+			rcu_nmi_enter();			\
+		} else {					\
+			state = __TR_IRQ;			\
+			rcu_irq_enter_irqsave();		\
+		}						\
+	}							\
+	state;							\
+})
+
+#define trace_rcu_exit(state)					\
+do {								\
+	switch (state) {					\
+	case __TR_IRQ:						\
+		rcu_irq_exit_irqsave();				\
+		break;						\
+	case __TR_NMI:						\
+		rcu_nmi_exit();					\
+		break;						\
+	default:						\
+		break;						\
+	}							\
+} while (0)
+
 #endif /* LINUX_HARDIRQ_H */



  parent reply	other threads:[~2020-02-12  9:43 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-12  9:32 [PATCH 0/8] tracing vs rcu vs nmi Peter Zijlstra
2020-02-12  9:32 ` [PATCH 1/8] rcu: Rename rcu_irq_{enter,exit}_irqson() Peter Zijlstra
2020-02-12  9:32 ` [PATCH 2/8] rcu: Mark rcu_dynticks_curr_cpu_in_eqs() inline Peter Zijlstra
2020-02-12  9:32 ` Peter Zijlstra [this message]
2020-02-12  9:32 ` [PATCH 4/8] sched,rcu,tracing: Mark preempt_count_{add,sub}() notrace Peter Zijlstra
2020-02-12 14:24   ` Steven Rostedt
2020-02-12 15:02     ` Peter Zijlstra
2020-02-12 15:14       ` Steven Rostedt
2020-02-12 15:38         ` Peter Zijlstra
2020-02-12  9:32 ` [PATCH 5/8] x86,tracing: Mark debug_stack_{set_zero,reset)() notrace Peter Zijlstra
2020-02-12 14:25   ` Steven Rostedt
2020-02-12 15:04     ` Peter Zijlstra
2020-02-12 15:18       ` Steven Rostedt
2020-02-12 15:39         ` Peter Zijlstra
2020-02-12  9:32 ` [PATCH 6/8] perf,tracing: Prepare the perf-trace interface for RCU changes Peter Zijlstra
2020-02-12 14:26   ` Steven Rostedt
2020-02-12 15:07     ` Mathieu Desnoyers
2020-02-12  9:32 ` [PATCH 7/8] tracing: Employ trace_rcu_{enter,exit}() Peter Zijlstra
2020-02-12  9:32 ` [PATCH 8/8] tracing: Remove regular RCU context for _rcuidle tracepoints (again) Peter Zijlstra
2020-02-12 14:29   ` Steven Rostedt
2020-02-12 15:12     ` Peter Zijlstra
2020-02-12 10:01 ` [PATCH 0/8] tracing vs rcu vs nmi Peter Zijlstra
2020-02-12 10:56   ` Will Deacon
2020-02-12 11:58     ` Peter Zijlstra
2020-02-12 14:32     ` Steven Rostedt
2020-02-12 15:21       ` Peter Zijlstra
2020-02-12 10:03 ` Peter Zijlstra
2020-02-12 10:07 ` Peter Zijlstra
2020-02-12 10:09 ` Peter Zijlstra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200212094107.781220598@infradead.org \
    --to=peterz@infradead.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=gustavo@embeddedor.com \
    --cc=jiangshanlai@gmail.com \
    --cc=joel@joelfernandes.org \
    --cc=josh@joshtriplett.org \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mingo@kernel.org \
    --cc=paulmck@kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).