public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: Ingo Molnar <mingo@elte.hu>,
	Peter Zijlstra <peterz@infradead.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-kernel@vger.kernel.org, Linus Torvalds <torvalds@osdl.org>,
	Arjan van de Ven <arjan@infradead.org>
Cc: Steven Rostedt <srostedt@redhat.com>
Subject: [PATCH 5/5] ftrace: warn on NMI calling code that may be modified
Date: Tue, 29 Jul 2008 21:29:44 -0400	[thread overview]
Message-ID: <20080730014351.429739409@goodmis.org> (raw)
In-Reply-To: 20080730012939.885172468@goodmis.org

[-- Attachment #1: ftrace-nmi-warning.patch --]
[-- Type: text/plain, Size: 2844 bytes --]

The dynamic ftrace code performs run time modification of the code text
section. This is not safe to do unless all other CPUS are halted. Because
there is no good way to halt NMIs while doing the modification, we must
make sure that the NMIs will not execute code that will be modified.

This patch adds a warning at the location that records code text that
will be modified later by the dynamic ftracer. It also disables the
modification from happening, so that the race with the NMI will not exist.

The kernel command line parameter "ftrace_keep_on_nmi" is defined to let
the user override the disabling of ftrace, at the risk that a very slight
race condition might crash the machine.  The command line still outputs
the warning, but doesn't disable ftrace.

The race that this protects is very hard to hit, but this patch adds detection
that the race exists and disables the code to prevent it.

Signed-off-by: Steven Rostedt <srostedt@redhat.com>
---
 kernel/trace/ftrace.c |   35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

Index: linux-tip.git/kernel/trace/ftrace.c
===================================================================
--- linux-tip.git.orig/kernel/trace/ftrace.c	2008-07-28 20:15:15.000000000 -0400
+++ linux-tip.git/kernel/trace/ftrace.c	2008-07-29 17:06:55.000000000 -0400
@@ -36,6 +36,17 @@
 int ftrace_enabled __read_mostly;
 static int last_ftrace_enabled;
 
+static int ftrace_nmi_disabled __read_mostly;
+
+/* Let the user override disabling ftrace on NMI, at their own risk. */
+static int ftrace_keep_on_nmi __read_mostly;
+static int __init ftrace_keep_on_nmi_setup(char *str)
+{
+	ftrace_keep_on_nmi = 1;
+	return 1;
+}
+__setup("ftrace_keep_on_nmi", ftrace_keep_on_nmi_setup);
+
 /*
  * ftrace_disabled is set when an anomaly is discovered.
  * ftrace_disabled is much stronger than ftrace_enabled.
@@ -341,6 +352,30 @@ ftrace_record_ip(unsigned long ip)
 	int atomic;
 	int cpu;
 
+	if (!ftrace_nmi_disabled && in_nmi()) {
+		ftrace_nmi_disabled = 1;
+		printk(KERN_WARNING
+		       "\n--------------- cut here ---------------\n");
+		printk(KERN_WARNING
+		       "WARNING: ftraced code called from NMI context ");
+		print_symbol("%s\n", ip);
+		printk(KERN_WARNING
+		       "         Please report this to the ftrace maintainer.\n");
+		if (!ftrace_keep_on_nmi) {
+			ftrace_disabled = 1;
+			printk(KERN_WARNING
+			       "         Disabling ftraced. Boot with ftrace_keep_on_nmi"
+			       " to not disable.\n");
+		} else
+			printk(KERN_WARNING
+			       "         \"ftrace_keep_on_nmi\" set. Continuing to use"
+			       " dynamic ftrace,\n"
+			       "         but the system may be unstable\n");
+		dump_stack();
+		printk(KERN_WARNING
+		       "--------------- end cut here ---------------\n");
+	}
+
 	if (!ftrace_enabled || ftrace_disabled)
 		return;
 

-- 

  parent reply	other threads:[~2008-07-30  1:45 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-30  1:29 [PATCH 0/5] ftrace: do not trace NMI handlers Steven Rostedt
2008-07-30  1:29 ` [PATCH 1/5] ftrace: do not trace nmi callers in x86 Steven Rostedt
2008-07-30  1:29 ` [PATCH 2/5] ftrace: do not trace nmi callers in drivers Steven Rostedt
2008-07-30  1:29 ` [PATCH 3/5] ftrace: do not trace nmi callers in RCU Steven Rostedt
2008-07-30  1:29 ` [PATCH 4/5] ftrace: do not trace nmi callers in kernel directory Steven Rostedt
2008-07-30  1:29 ` Steven Rostedt [this message]
2008-07-30  7:28 ` [PATCH 0/5] ftrace: do not trace NMI handlers Peter Zijlstra
2008-07-30 14:04   ` Mathieu Desnoyers
2008-07-30 14:23     ` Mathieu Desnoyers

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=20080730014351.429739409@goodmis.org \
    --to=rostedt@goodmis.org \
    --cc=akpm@linux-foundation.org \
    --cc=arjan@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=peterz@infradead.org \
    --cc=srostedt@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=torvalds@osdl.org \
    /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