Skip to contentSkip to conversation

ftrace fixes for PA-RISC

PATCH New Sven Schnelle 1 participant 4 messages Oct 19, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover ftrace fixes for PA-RISC

I tried to enable ftrace, but it didn't work. These are the required fixes to make it work again.

Sven Schnelle (3):
parisc: don't use dereference_function_descriptor() in trace stub parisc/ftrace: use static key to enable function graph
parisc: mark xchg functions notrace

 arch/parisc/kernel/ftrace.c | 13 ++++++-------
 arch/parisc/lib/bitops.c    | 12 ++++++------
 2 files changed, 12 insertions(+), 13 deletions(-)
Signature · 1 line
2.33.0
#1 lore raw

PATCH 1/3 parisc: don't use dereference_function_descriptor() in trace stub

dereference_function_descriptor() calls get_kernel_nofault(), which itself might call into tracing. This leads to a deadlock.

Instead of reverting back to casts to compare whether there's a trace function set, just always call the appropriate trace function. With dynamic ftrace this function shouldn't be called at all when ftrace is disabled. It adds a function call for the non-dynamic case, but people concerned about the costs of ftrace should use dynamic ftrace anyways.

---
 arch/parisc/kernel/ftrace.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
arch/parisc/kernel/ftrace.c +2 -4
index 0a1e75af5382..f5f467ebf94c 100644
@@ -58,10 +58,7 @@ void notrace __hot ftrace_function_trampoline(unsigned long parent,
 #endif
 	extern struct ftrace_ops *function_trace_op;
 
-	if (function_trace_op->flags & FTRACE_OPS_FL_ENABLED &&
-	    ftrace_trace_function != ftrace_stub)
-		ftrace_trace_function(self_addr, parent,
-				function_trace_op, fregs);
+	ftrace_trace_function(self_addr, parent, function_trace_op, fregs);
 
 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
 	if (dereference_function_descriptor(ftrace_graph_return) !=
@@ -101,6 +98,7 @@ int __init ftrace_dyn_arch_init(void)
 }
 int ftrace_update_ftrace_func(ftrace_func_t func)
 {
+	ftrace_trace_function = func;
 	return 0;
 }
 
Signature · 1 line
2.33.0
#2 lore raw

PATCH 2/3 parisc/ftrace: use static key to enable function graph

In reply to Sven Schnelle

Instead of comparing function descriptors add a static branch so the condition gets patched during runtime.

---
 arch/parisc/kernel/ftrace.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
arch/parisc/kernel/ftrace.c +4 -3
index f5f467ebf94c..7a2de664242a 100644
@@ -23,6 +23,7 @@
 
 #define __hot __section(".text.hot")
 
+static DEFINE_STATIC_KEY_FALSE(ftrace_graph_enabled);
 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
 /*
  * Hook the return address and push it in the stack of return addrs
@@ -61,9 +62,7 @@ void notrace __hot ftrace_function_trampoline(unsigned long parent,
 	ftrace_trace_function(self_addr, parent, function_trace_op, fregs);
 
 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
-	if (dereference_function_descriptor(ftrace_graph_return) !=
-	    dereference_function_descriptor(ftrace_stub) ||
-	    ftrace_graph_entry != ftrace_graph_entry_stub) {
+	if (static_branch_unlikely(&ftrace_graph_enabled)) {
 		unsigned long *parent_rp;
 
 		/* calculate pointer to %rp in stack */
@@ -81,11 +80,13 @@ void notrace __hot ftrace_function_trampoline(unsigned long parent,
 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
 int ftrace_enable_ftrace_graph_caller(void)
 {
+	static_key_enable(&ftrace_graph_enabled.key);
 	return 0;
 }
 
 int ftrace_disable_ftrace_graph_caller(void)
 {
+	static_key_disable(&ftrace_graph_enabled.key);
 	return 0;
 }
 #endif
Signature · 1 line
2.33.0
#3 lore raw

PATCH 3/3 parisc: mark xchg functions notrace

In reply to Sven Schnelle

tracing the xchg functions leads to recursion in various places. Therefore mark the function as notrace.

---
 arch/parisc/lib/bitops.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
arch/parisc/lib/bitops.c +6 -6
index 9ac683bf6ae7..36a314199074 100644
@@ -18,7 +18,7 @@ arch_spinlock_t __atomic_hash[ATOMIC_HASH_SIZE] __lock_aligned = {
 #endif
 
 #ifdef CONFIG_64BIT
-unsigned long __xchg64(unsigned long x, volatile unsigned long *ptr)
+unsigned long notrace __xchg64(unsigned long x, volatile unsigned long *ptr)
 {
 	unsigned long temp, flags;
 
@@ -30,7 +30,7 @@ unsigned long __xchg64(unsigned long x, volatile unsigned long *ptr)
 }
 #endif
 
-unsigned long __xchg32(int x, volatile int *ptr)
+unsigned long notrace __xchg32(int x, volatile int *ptr)
 {
 	unsigned long flags;
 	long temp;
@@ -43,7 +43,7 @@ unsigned long __xchg32(int x, volatile int *ptr)
 }
 
 
-unsigned long __xchg8(char x, volatile char *ptr)
+unsigned long notrace __xchg8(char x, volatile char *ptr)
 {
 	unsigned long flags;
 	long temp;
@@ -56,7 +56,7 @@ unsigned long __xchg8(char x, volatile char *ptr)
 }
 
 
-u64 __cmpxchg_u64(volatile u64 *ptr, u64 old, u64 new)
+u64 notrace __cmpxchg_u64(volatile u64 *ptr, u64 old, u64 new)
 {
 	unsigned long flags;
 	u64 prev;
@@ -68,7 +68,7 @@ u64 __cmpxchg_u64(volatile u64 *ptr, u64 old, u64 new)
 	return prev;
 }
 
-unsigned long __cmpxchg_u32(volatile unsigned int *ptr, unsigned int old, unsigned int new)
+unsigned long notrace __cmpxchg_u32(volatile unsigned int *ptr, unsigned int old, unsigned int new)
 {
 	unsigned long flags;
 	unsigned int prev;
@@ -80,7 +80,7 @@ unsigned long __cmpxchg_u32(volatile unsigned int *ptr, unsigned int old, unsign
 	return (unsigned long)prev;
 }
 
-u8 __cmpxchg_u8(volatile u8 *ptr, u8 old, u8 new)
+u8 notrace __cmpxchg_u8(volatile u8 *ptr, u8 old, u8 new)
 {
 	unsigned long flags;
 	u8 prev;
Signature · 1 line
2.33.0