[PATCH] ftrace: fix address for jmp mode in t_show

Menglong Dong posted 1 patch 1 month, 3 weeks ago
There is a newer version of this series
kernel/trace/ftrace.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
[PATCH] ftrace: fix address for jmp mode in t_show
Posted by Menglong Dong 1 month, 3 weeks ago
The address from ftrace_find_rec_direct() is printed directly in t_show().
This can mislead symbol offsets if it has the "jmp" bit in the last bit.

Fix this by printing the address that returned by ftrace_jmp_get().

Fixes: 25e4e3565d45 ("ftrace: Introduce FTRACE_OPS_FL_JMP")
Signed-off-by: Menglong Dong <dongml2@chinatelecom.cn>
---
 kernel/trace/ftrace.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index bbb37c0f8c6c..d4c41fb76a25 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -4492,8 +4492,12 @@ static int t_show(struct seq_file *m, void *v)
 			unsigned long direct;
 
 			direct = ftrace_find_rec_direct(rec->ip);
-			if (direct)
-				seq_printf(m, "\n\tdirect-->%pS", (void *)direct);
+			if (direct) {
+				seq_printf(m, ftrace_is_jmp(direct) ?
+					      "\n\tdirect(jmp)-->%pS" :
+					      "\n\tdirect-->%pS",
+					   (void *)ftrace_jmp_get(direct));
+			}
 		}
 	}
 
-- 
2.52.0
Re: [PATCH] ftrace: fix address for jmp mode in t_show
Posted by Steven Rostedt 1 month, 3 weeks ago
On Tue, 16 Dec 2025 11:45:33 +0800
Menglong Dong <menglong8.dong@gmail.com> wrote:

> diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
> index bbb37c0f8c6c..d4c41fb76a25 100644
> --- a/kernel/trace/ftrace.c
> +++ b/kernel/trace/ftrace.c
> @@ -4492,8 +4492,12 @@ static int t_show(struct seq_file *m, void *v)
>  			unsigned long direct;
>  
>  			direct = ftrace_find_rec_direct(rec->ip);
> -			if (direct)
> -				seq_printf(m, "\n\tdirect-->%pS", (void *)direct);
> +			if (direct) {
> +				seq_printf(m, ftrace_is_jmp(direct) ?
> +					      "\n\tdirect(jmp)-->%pS" :
> +					      "\n\tdirect-->%pS",
> +					   (void *)ftrace_jmp_get(direct));

A little cleaner way to do the above:

				seq_printf(m, "\n\tdirect%s-->%pS",
					   ftrace_is_jmp(direct) ? "(jmp)" : "",
					   (void *)ftrace_jmp_get(direct));


-- Steve

> +			}
>  		}
>  	}
Re: [PATCH] ftrace: fix address for jmp mode in t_show
Posted by Menglong Dong 1 month, 3 weeks ago
On 2025/12/17 00:28 Steven Rostedt <rostedt@goodmis.org> write:
> On Tue, 16 Dec 2025 11:45:33 +0800
> Menglong Dong <menglong8.dong@gmail.com> wrote:
> 
> > diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
> > index bbb37c0f8c6c..d4c41fb76a25 100644
> > --- a/kernel/trace/ftrace.c
> > +++ b/kernel/trace/ftrace.c
> > @@ -4492,8 +4492,12 @@ static int t_show(struct seq_file *m, void *v)
> >  			unsigned long direct;
> >  
> >  			direct = ftrace_find_rec_direct(rec->ip);
> > -			if (direct)
> > -				seq_printf(m, "\n\tdirect-->%pS", (void *)direct);
> > +			if (direct) {
> > +				seq_printf(m, ftrace_is_jmp(direct) ?
> > +					      "\n\tdirect(jmp)-->%pS" :
> > +					      "\n\tdirect-->%pS",
> > +					   (void *)ftrace_jmp_get(direct));
> 
> A little cleaner way to do the above:
> 
> 				seq_printf(m, "\n\tdirect%s-->%pS",
> 					   ftrace_is_jmp(direct) ? "(jmp)" : "",
> 					   (void *)ftrace_jmp_get(direct));

Yeah, looks better. I'll send a V2 later.

Thanks!
Menglong Dong

> 
> 
> -- Steve
> 
> > +			}
> >  		}
> >  	}
> 
>