Skip to contentSkip to conversation

x86: Use preempt_disable_notrace() in cycles_2_ns()

PATCH In review Steven Rostedt 4 participants 4 messages Feb 4, 2014 – Feb 10, 2014 x86

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86: Use preempt_disable_notrace() in cycles_2_ns()

When debug preempt is enabled, preempt_disable() can be traced by function and function graph tracing.

There's a place in the function graph tracer that calls trace_clock() which eventually calls cycles_2_ns() outside of the recursion protection. When cycles_2_ns() calls preempt_disable() it gets traced and the graph tracer will go into a recursive loop causing a crash or worse, a triple fault.

Simple fix is to use preempt_disable_notrace() in cycles_2_ns, which makes sense because the preempt_disable() tracing may use that code too, and it tracing it, even with recursion protection is rather pointless.

arch/x86/kernel/tsc.c +2 -2
index 19e5adb..acb3b60 100644
@@ -209,7 +209,7 @@ static inline unsigned long long cycles_2_ns(unsigned long long cyc)
 	 * dance when its actually needed.
 	 */
 
-	preempt_disable();
+	preempt_disable_notrace();
 	data = this_cpu_read(cyc2ns.head);
 	tail = this_cpu_read(cyc2ns.tail);
 
@@ -229,7 +229,7 @@ static inline unsigned long long cycles_2_ns(unsigned long long cyc)
 		if (!--data->__count)
 			this_cpu_write(cyc2ns.tail, data);
 	}
-	preempt_enable();
+	preempt_enable_notrace();
 
 	return ns;
 }
#1 lore raw
Quoted 9 lines · Steven Rostedt

When debug preempt is enabled, preempt_disable() can be traced by function and function graph tracing.

There's a place in the function graph tracer that calls trace_clock() which eventually calls cycles_2_ns() outside of the recursion protection. When cycles_2_ns() calls preempt_disable() it gets traced and the graph tracer will go into a recursive loop causing a crash or worse, a triple fault.

Quoted 6 lines

Simple fix is to use preempt_disable_notrace() in cycles_2_ns, which makes sense because the preempt_disable() tracing may use that code too, and it tracing it, even with recursion protection is rather pointless.

Indeed, thanks!

#2 lore raw
In reply to Steven Rostedt
Quoted 9 lines · Steven Rostedt

When debug preempt is enabled, preempt_disable() can be traced by function and function graph tracing.

There's a place in the function graph tracer that calls trace_clock() which eventually calls cycles_2_ns() outside of the recursion protection. When cycles_2_ns() calls preempt_disable() it gets traced and the graph tracer will go into a recursive loop causing a crash or worse, a triple fault.

Quoted 6 lines

Simple fix is to use preempt_disable_notrace() in cycles_2_ns, which makes sense because the preempt_disable() tracing may use that code too, and it tracing it, even with recursion protection is rather pointless.

Acked-by-me

Quoted 23 lines
arch/x86/kernel/tsc.c +2 -2
index 19e5adb..acb3b60 100644
@@ -209,7 +209,7 @@ static inline unsigned long long cycles_2_ns(unsigned long long cyc)
 	 * dance when its actually needed.
 	 */
 
-	preempt_disable();
+	preempt_disable_notrace();
 	data = this_cpu_read(cyc2ns.head);
 	tail = this_cpu_read(cyc2ns.tail);
 
@@ -229,7 +229,7 @@ static inline unsigned long long cycles_2_ns(unsigned long long cyc)
 		if (!--data->__count)
 			this_cpu_write(cyc2ns.tail, data);
 	}
-	preempt_enable();
+	preempt_enable_notrace();
 
 	return ns;
 }
#3 lore raw
In reply to Steven Rostedt
x86: Use preempt_disable_notrace() in cycles_2_ns()
Commit-ID:  569d6557ab957d6ae7e97a46ae669174be4189e6
Gitweb:     http://git.kernel.org/tip/569d6557ab957d6ae7e97a46ae669174be4189e6
Author:     Steven Rostedt <[email protected]>
AuthorDate: Tue, 4 Feb 2014 14:13:15 -0500
Committer:  Ingo Molnar <[email protected]>
CommitDate: Sun, 9 Feb 2014 13:09:08 +0100

x86: Use preempt_disable_notrace() in cycles_2_ns()

When debug preempt is enabled, preempt_disable() can be traced by function and function graph tracing.

There's a place in the function graph tracer that calls trace_clock() which eventually calls cycles_2_ns() outside of the recursion protection. When cycles_2_ns() calls preempt_disable() it gets traced and the graph tracer will go into a recursive loop causing a crash or worse, a triple fault.

Simple fix is to use preempt_disable_notrace() in cycles_2_ns, which makes sense because the preempt_disable() tracing may use that code too, and it tracing it, even with recursion protection is rather pointless.

---
 arch/x86/kernel/tsc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kernel/tsc.c +2 -2
index 19e5adb..acb3b60 100644
@@ -209,7 +209,7 @@ static inline unsigned long long cycles_2_ns(unsigned long long cyc)
 	 * dance when its actually needed.
 	 */
 
-	preempt_disable();
+	preempt_disable_notrace();
 	data = this_cpu_read(cyc2ns.head);
 	tail = this_cpu_read(cyc2ns.tail);
 
@@ -229,7 +229,7 @@ static inline unsigned long long cycles_2_ns(unsigned long long cyc)
 		if (!--data->__count)
 			this_cpu_write(cyc2ns.tail, data);
 	}
-	preempt_enable();
+	preempt_enable_notrace();
 
 	return ns;
 }