Skip to contentSkip to conversation

ftrace: Hide a extra entry in stack trace

PATCH In review Tatsuya S 3 participants 6 messages Oct 2, 2024 – Oct 5, 2024 Tracing

lore
Share & tools
lore

Tatsuya S

author
#0 lore raw

PATCH v3 1/1 ftrace: Hide a extra entry in stack trace

A extra entry is shown on stack trace(CONFIG_UNWINDER_ORC=y).

[003] ..... 110.171589: vfs_write <-__x64_sys_write
[003] ..... 110.171600: <stack trace>
=> XXXXXXXXX (Wrong function name)
=> vfs_write
=> ksys_write
=> do_syscall_64
=> entry_SYSCALL_64_after_hwframe

To resolve this, increment skip for __ftrace_trace_stack() in function_stack_trace_call().
The reason why skip is incremented for __ftrace_trace_stack() is because __ftrace_trace_stack() in stack trace is the only function that wasn't skipped from anywhere.

---
V2 -> V3: Changed the place to increment skip number V1 -> V2: Fixed redundant code

 kernel/trace/trace_functions.c | 24 +++++++++++-------------
 1 file changed, 11 insertions(+), 13 deletions(-)
kernel/trace/trace_functions.c +11 -13
index 3b0cea37e029..27089d8e65d4 100644
@@ -203,23 +203,21 @@ function_trace_call(unsigned long ip, unsigned long parent_ip,
 	ftrace_test_recursion_unlock(bit);
 }
 
-#ifdef CONFIG_UNWINDER_ORC
-/*
- * Skip 2:
- *
- *   function_stack_trace_call()
- *   ftrace_call()
- */
-#define STACK_SKIP 2
-#else
 /*
  * Skip 3:
- *   __trace_stack()
- *   function_stack_trace_call()
- *   ftrace_call()
+ *   Skipped functions if CONFIG_UNWINDER_ORC is defined
+ *
+ *     __ftrace_trace_stack()
+ *     function_stack_trace_call()
+ *     ftrace_call()
+ *
+ *   Otherwise
+ *
+ *     __trace_stack()
+ *     function_stack_trace_call()
+ *     ftrace_call()
  */
 #define STACK_SKIP 3
-#endif
 
 static void
 function_stack_trace_call(unsigned long ip, unsigned long parent_ip,
Signature · 1 line
2.46.2
maintainer
#1 lore raw
Quoted 5 lines · On Wed, 2 Oct 2024 14:13:48 +0900 Tatsuya S <[email protected]> wrote:

A extra entry is shown on stack trace(CONFIG_UNWINDER_ORC=y).

[003] ..... 110.171589: vfs_write <-__x64_sys_write
[003] ..... 110.171600: <stack trace>
=> XXXXXXXXX (Wrong function name)

BTW, instead of X'ing it out, can you show what that extra function was. Just saying "Wrong function name" doesn't give me any idea of what happened.

Quoted 10 lines

=> vfs_write
=> ksys_write
=> do_syscall_64
=> entry_SYSCALL_64_after_hwframe

To resolve this, increment skip for __ftrace_trace_stack() in function_stack_trace_call().
The reason why skip is incremented for __ftrace_trace_stack() is because __ftrace_trace_stack() in stack trace is the only function that wasn't skipped from anywhere.

Is that the function that was "wrong"?

-- Steve

Quoted 48 lines

---
V2 -> V3: Changed the place to increment skip number V1 -> V2: Fixed redundant code

 kernel/trace/trace_functions.c | 24 +++++++++++-------------
 1 file changed, 11 insertions(+), 13 deletions(-)
kernel/trace/trace_functions.c +11 -13
index 3b0cea37e029..27089d8e65d4 100644
@@ -203,23 +203,21 @@ function_trace_call(unsigned long ip, unsigned long parent_ip,
 	ftrace_test_recursion_unlock(bit);
 }
 
-#ifdef CONFIG_UNWINDER_ORC
-/*
- * Skip 2:
- *
- *   function_stack_trace_call()
- *   ftrace_call()
- */
-#define STACK_SKIP 2
-#else
 /*
  * Skip 3:
- *   __trace_stack()
- *   function_stack_trace_call()
- *   ftrace_call()
+ *   Skipped functions if CONFIG_UNWINDER_ORC is defined
+ *
+ *     __ftrace_trace_stack()
+ *     function_stack_trace_call()
+ *     ftrace_call()
+ *
+ *   Otherwise
+ *
+ *     __trace_stack()
+ *     function_stack_trace_call()
+ *     ftrace_call()
  */
 #define STACK_SKIP 3
-#endif
 
 static void
 function_stack_trace_call(unsigned long ip, unsigned long parent_ip,
author
#2 lore raw
Quoted 11 lines · Steven Rostedt
Quoted 5 lines · On Wed, 2 Oct 2024 14:13:48 +0900 Tatsuya S <[email protected]> wrote:

A extra entry is shown on stack trace(CONFIG_UNWINDER_ORC=y).

[003] ..... 110.171589: vfs_write <-__x64_sys_write
[003] ..... 110.171600: <stack trace>
=> XXXXXXXXX (Wrong function name)

BTW, instead of X'ing it out, can you show what that extra function was. Just saying "Wrong function name" doesn't give me any idea of what happened.

This is changed each shutdown.
For example, client_init_data, hidpp_driver_init, rfcomm_init.

The same function name was displayed each time if system was not shutdown.

And I added "nokaslr" to the kernel command line and boot, got same result.

Quoted 6 lines
Quoted 6 lines

=> vfs_write
=> ksys_write
=> do_syscall_64
=> entry_SYSCALL_64_after_hwframe

Quoted 7 lines
Quoted 5 lines

To resolve this, increment skip for __ftrace_trace_stack() in function_stack_trace_call().
The reason why skip is incremented for __ftrace_trace_stack() is because __ftrace_trace_stack() in stack trace is the only function that wasn't skipped from anywhere.

Is that the function that was "wrong"?

Unrelated?

Quoted 49 lines

-- Steve

Quoted 46 lines

---
V2 -> V3: Changed the place to increment skip number V1 -> V2: Fixed redundant code

  kernel/trace/trace_functions.c | 24 +++++++++++-------------
  1 file changed, 11 insertions(+), 13 deletions(-)
kernel/trace/trace_functions.c +11 -13
index 3b0cea37e029..27089d8e65d4 100644
@@ -203,23 +203,21 @@ function_trace_call(unsigned long ip, unsigned long parent_ip,
  	ftrace_test_recursion_unlock(bit);
  }
 
-#ifdef CONFIG_UNWINDER_ORC
-/*
- * Skip 2:
- *
- *   function_stack_trace_call()
- *   ftrace_call()
- */
-#define STACK_SKIP 2
-#else
  /*
   * Skip 3:
- *   __trace_stack()
- *   function_stack_trace_call()
- *   ftrace_call()
+ *   Skipped functions if CONFIG_UNWINDER_ORC is defined
+ *
+ *     __ftrace_trace_stack()
+ *     function_stack_trace_call()
+ *     ftrace_call()
+ *
+ *   Otherwise
+ *
+ *     __trace_stack()
+ *     function_stack_trace_call()
+ *     ftrace_call()
   */
  #define STACK_SKIP 3
-#endif
 
Quoted 3 lines

kernel/trace/trace_functions.c function_trace_call(unsigned long ip, unsigned long parent_ip, · line 223

Quoted 2 lines
kernel/trace/trace_functions.c +0 -0
  static void
  function_stack_trace_call(unsigned long ip, unsigned long parent_ip,

thanks

maintainer
#3 lore raw
Quoted 8 lines · On Thu, 3 Oct 2024 00:28:28 +0900 Tatsuya S <[email protected]> wrote:
Quoted 8 lines
Quoted 5 lines · Tatsuya S

A extra entry is shown on stack trace(CONFIG_UNWINDER_ORC=y).

[003] ..... 110.171589: vfs_write <-__x64_sys_write
[003] ..... 110.171600: <stack trace>
=> XXXXXXXXX (Wrong function name)

Quoted 8 lines
Quoted 2 lines

BTW, instead of X'ing it out, can you show what that extra function was. Just saying "Wrong function name" doesn't give me any idea of what happened.

This is changed each shutdown.
For example, client_init_data, hidpp_driver_init, rfcomm_init.

The same function name was displayed each time if system was not shutdown.

And I added "nokaslr" to the kernel command line and boot, got same result.

So I'm trying to understand this part. Where is the function coming from then? The skip is there to skip over the functions that are calling the stack trace. It shouldn't be garbage, as the stack walk shouldn't be giving us that.

Now I'm even more curious to what is going wrong.

-- Steve

#4 lore raw
In reply to Tatsuya S
Quoted 10 lines · On Wed, 2 Oct 2024 14:13:48 +0900 Tatsuya S <[email protected]> wrote:

A extra entry is shown on stack trace(CONFIG_UNWINDER_ORC=y).

[003] ..... 110.171589: vfs_write <-__x64_sys_write
[003] ..... 110.171600: <stack trace>
=> XXXXXXXXX (Wrong function name)
=> vfs_write
=> ksys_write
=> do_syscall_64
=> entry_SYSCALL_64_after_hwframe

Quoted 5 lines

To resolve this, increment skip for __ftrace_trace_stack() in function_stack_trace_call().
The reason why skip is incremented for __ftrace_trace_stack() is because __ftrace_trace_stack() in stack trace is the only function that wasn't skipped from anywhere.

Hi Tatsuya,

Can you focus on making test cases which checks what combinations caused this wrong values and what does not? Also it should be checked with various kconfigs. That is more valuable than making add-hoc fixes.

Thank you,

Quoted 51 lines

---
V2 -> V3: Changed the place to increment skip number V1 -> V2: Fixed redundant code

 kernel/trace/trace_functions.c | 24 +++++++++++-------------
 1 file changed, 11 insertions(+), 13 deletions(-)
kernel/trace/trace_functions.c +11 -13
index 3b0cea37e029..27089d8e65d4 100644
@@ -203,23 +203,21 @@ function_trace_call(unsigned long ip, unsigned long parent_ip,
 	ftrace_test_recursion_unlock(bit);
 }
 
-#ifdef CONFIG_UNWINDER_ORC
-/*
- * Skip 2:
- *
- *   function_stack_trace_call()
- *   ftrace_call()
- */
-#define STACK_SKIP 2
-#else
 /*
  * Skip 3:
- *   __trace_stack()
- *   function_stack_trace_call()
- *   ftrace_call()
+ *   Skipped functions if CONFIG_UNWINDER_ORC is defined
+ *
+ *     __ftrace_trace_stack()
+ *     function_stack_trace_call()
+ *     ftrace_call()
+ *
+ *   Otherwise
+ *
+ *     __trace_stack()
+ *     function_stack_trace_call()
+ *     ftrace_call()
  */
 #define STACK_SKIP 3
-#endif
 
 static void
 function_stack_trace_call(unsigned long ip, unsigned long parent_ip,
Signature · 1 line
2.46.2
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>
author
#5 lore raw
Quoted 19 lines · Masami Hiramatsu (Google)
Quoted 10 lines · On Wed, 2 Oct 2024 14:13:48 +0900 Tatsuya S <[email protected]> wrote:

A extra entry is shown on stack trace(CONFIG_UNWINDER_ORC=y).

[003] ..... 110.171589: vfs_write <-__x64_sys_write
[003] ..... 110.171600: <stack trace>
=> XXXXXXXXX (Wrong function name)
=> vfs_write
=> ksys_write
=> do_syscall_64
=> entry_SYSCALL_64_after_hwframe

Quoted 5 lines

To resolve this, increment skip for __ftrace_trace_stack() in function_stack_trace_call().
The reason why skip is incremented for __ftrace_trace_stack() is because __ftrace_trace_stack() in stack trace is the only function that wasn't skipped from anywhere.

Quoted 7 lines

Hi Tatsuya,

Can you focus on making test cases which checks what combinations caused this wrong values and what does not? Also it should be checked with various kconfigs. That is more valuable than making add-hoc fixes.

Thank you,

OK, thank you for advise.

Curiously, now when test under the same conditions, address(like 0xffffffffa1413099) within trampoline code appears in XXXXXXXXX. Unrelated function name is not displayed now...

The following is the script used:

echo > trace
echo 'vfs_write' > set_ftrace_filter
echo function > current_tracer
echo 1 > options/func_stack_trace
echo 1 > tracing_on
read
echo 0 > tracing_on
cat trace
echo nop > current_tracer
---

Thanks

Quoted 54 lines
Quoted 52 lines

---
V2 -> V3: Changed the place to increment skip number V1 -> V2: Fixed redundant code

  kernel/trace/trace_functions.c | 24 +++++++++++-------------
  1 file changed, 11 insertions(+), 13 deletions(-)
kernel/trace/trace_functions.c +11 -13
index 3b0cea37e029..27089d8e65d4 100644
@@ -203,23 +203,21 @@ function_trace_call(unsigned long ip, unsigned long parent_ip,
  	ftrace_test_recursion_unlock(bit);
  }
 
-#ifdef CONFIG_UNWINDER_ORC
-/*
- * Skip 2:
- *
- *   function_stack_trace_call()
- *   ftrace_call()
- */
-#define STACK_SKIP 2
-#else
  /*
   * Skip 3:
- *   __trace_stack()
- *   function_stack_trace_call()
- *   ftrace_call()
+ *   Skipped functions if CONFIG_UNWINDER_ORC is defined
+ *
+ *     __ftrace_trace_stack()
+ *     function_stack_trace_call()
+ *     ftrace_call()
+ *
+ *   Otherwise
+ *
+ *     __trace_stack()
+ *     function_stack_trace_call()
+ *     ftrace_call()
   */
  #define STACK_SKIP 3
-#endif
 
  static void
  function_stack_trace_call(unsigned long ip, unsigned long parent_ip,
Signature · 1 line
2.46.2