* [PATCH 0/2] fgraph: fixes for thresh_return return handler
@ 2026-02-21 3:16 hu.shengming
2026-02-21 3:30 ` [PATCH 1/2] fgraph: fix thresh_return clear per-task notrace hu.shengming
2026-02-21 3:33 ` [PATCH 2/2] fgraph: fix thresh_return nosleeptime double-adjust hu.shengming
0 siblings, 2 replies; 5+ messages in thread
From: hu.shengming @ 2026-02-21 3:16 UTC (permalink / raw)
To: rostedt, mhiramat
Cc: mathieu.desnoyers, linux-kernel, linux-trace-kernel, zhang.run,
yang.tao172, yang.yang29, hu.shengming
[-- Attachment #1.1.1: Type: text/plain, Size: 729 bytes --]
From: Shengming Hu <hu.shengming@zte.com.cn>
Hi,
This series fixes two issues in trace_graph_thresh_return(), the function
graph return handler used when tracing_thresh is enabled:
PATCH1: Clear the per-task TRACE_GRAPH_NOTRACE state like
trace_graph_return() does.
PATCH2: Avoid double no-sleep-time adjustment by emitting
the return event directly when the threshold is met.
Patch details are in the individual commit messages.
Shengming Hu (2):
[PATCH 1/2] fgraph: fix thresh_return clear per-task notrace
[PATCH 2/2] fgraph: fix thresh_return nosleeptime double-adjust
kernel/trace/trace_functions_graph.c | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
--
2.25.1
[-- Attachment #1.1.2: Type: text/html , Size: 1619 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] fgraph: fix thresh_return clear per-task notrace
2026-02-21 3:16 [PATCH 0/2] fgraph: fixes for thresh_return return handler hu.shengming
@ 2026-02-21 3:30 ` hu.shengming
2026-02-24 8:33 ` Masami Hiramatsu
2026-02-21 3:33 ` [PATCH 2/2] fgraph: fix thresh_return nosleeptime double-adjust hu.shengming
1 sibling, 1 reply; 5+ messages in thread
From: hu.shengming @ 2026-02-21 3:30 UTC (permalink / raw)
To: hu.shengming
Cc: rostedt, mhiramat, mathieu.desnoyers, linux-kernel,
linux-trace-kernel, zhang.run, yang.tao172, yang.yang29
From: Shengming Hu <hu.shengming@zte.com.cn>
When tracing_thresh is enabled, function graph tracing uses
trace_graph_thresh_return() as the return handler. Unlike
trace_graph_return(), it did not clear the per-task
TRACE_GRAPH_NOTRACE flag set by the entry handler for
set_graph_notrace addresses. This could leave the task
permanently in "notrace" state and effectively disable
function graph tracing for that task.
Mirror trace_graph_return()'s per-task notrace handling by
clearing TRACE_GRAPH_NOTRACE and returning early when set.
Fixes: b84214890a9bc ("function_graph: Move graph notrace bit to
shadow stack global var")
Signed-off-by: Shengming Hu <hu.shengming@zte.com.cn>
---
kernel/trace/trace_functions_graph.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/kernel/trace/trace_functions_graph.c b/kernel/trace/trace_functions_graph.c
index 1de6f1573..cbe43680c 100644
--- a/kernel/trace/trace_functions_graph.c
+++ b/kernel/trace/trace_functions_graph.c
@@ -400,14 +400,15 @@ static void trace_graph_thresh_return(struct ftrace_graph_ret *trace,
struct fgraph_ops *gops,
struct ftrace_regs *fregs)
{
+ unsigned long *task_var = fgraph_get_task_var(gops);
struct fgraph_times *ftimes;
struct trace_array *tr;
int size;
ftrace_graph_addr_finish(gops, trace);
- if (trace_recursion_test(TRACE_GRAPH_NOTRACE_BIT)) {
- trace_recursion_clear(TRACE_GRAPH_NOTRACE_BIT);
+ if (*task_var & TRACE_GRAPH_NOTRACE) {
+ *task_var &= ~TRACE_GRAPH_NOTRACE;
return;
}
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] fgraph: fix thresh_return nosleeptime double-adjust
2026-02-21 3:16 [PATCH 0/2] fgraph: fixes for thresh_return return handler hu.shengming
2026-02-21 3:30 ` [PATCH 1/2] fgraph: fix thresh_return clear per-task notrace hu.shengming
@ 2026-02-21 3:33 ` hu.shengming
2026-02-24 8:36 ` Masami Hiramatsu
1 sibling, 1 reply; 5+ messages in thread
From: hu.shengming @ 2026-02-21 3:33 UTC (permalink / raw)
To: hu.shengming
Cc: rostedt, mhiramat, mathieu.desnoyers, linux-kernel,
linux-trace-kernel, zhang.run, yang.tao172, yang.yang29
From: Shengming Hu <hu.shengming@zte.com.cn>
trace_graph_thresh_return() called handle_nosleeptime() and then
delegated to trace_graph_return(), which calls
handle_nosleeptime() again. When sleep-time accounting is
disabled this double-adjusts calltime and can produce bogus
durations (including underflow).
Fix this by computing rettime once, applying
handle_nosleeptime() only once, using the adjusted calltime
for threshold comparison, and writing the return event
directly via __trace_graph_return() when the threshold is met.
Fixes: 3c9880f3ab52b ("ftrace: Use a running sleeptime instead of
saving on shadow stack")
Signed-off-by: Shengming Hu <hu.shengming@zte.com.cn>
---
kernel/trace/trace_functions_graph.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/kernel/trace/trace_functions_graph.c b/kernel/trace/trace_functions_graph.c
index cbe43680c..b9c81fbd9 100644
--- a/kernel/trace/trace_functions_graph.c
+++ b/kernel/trace/trace_functions_graph.c
@@ -403,8 +403,12 @@ static void trace_graph_thresh_return(struct ftrace_graph_ret *trace,
unsigned long *task_var = fgraph_get_task_var(gops);
struct fgraph_times *ftimes;
struct trace_array *tr;
+ unsigned int trace_ctx;
+ u64 calltime, rettime;
int size;
+ rettime = trace_clock_local();
+
ftrace_graph_addr_finish(gops, trace);
if (*task_var & TRACE_GRAPH_NOTRACE) {
@@ -419,11 +423,13 @@ static void trace_graph_thresh_return(struct ftrace_graph_ret *trace,
tr = gops->private;
handle_nosleeptime(tr, trace, ftimes, size);
- if (tracing_thresh &&
- (trace_clock_local() - ftimes->calltime < tracing_thresh))
+ calltime = ftimes->calltime;
+
+ if (tracing_thresh && (rettime - calltime < tracing_thresh))
return;
- else
- trace_graph_return(trace, gops, fregs);
+
+ trace_ctx = tracing_gen_ctx();
+ __trace_graph_return(tr, trace, trace_ctx, calltime, rettime);
}
static struct fgraph_ops funcgraph_ops = {
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] fgraph: fix thresh_return clear per-task notrace
2026-02-21 3:30 ` [PATCH 1/2] fgraph: fix thresh_return clear per-task notrace hu.shengming
@ 2026-02-24 8:33 ` Masami Hiramatsu
0 siblings, 0 replies; 5+ messages in thread
From: Masami Hiramatsu @ 2026-02-24 8:33 UTC (permalink / raw)
To: hu.shengming
Cc: rostedt, mhiramat, mathieu.desnoyers, linux-kernel,
linux-trace-kernel, zhang.run, yang.tao172, yang.yang29
On Sat, 21 Feb 2026 11:30:07 +0800 (CST)
<hu.shengming@zte.com.cn> wrote:
> From: Shengming Hu <hu.shengming@zte.com.cn>
>
> When tracing_thresh is enabled, function graph tracing uses
> trace_graph_thresh_return() as the return handler. Unlike
> trace_graph_return(), it did not clear the per-task
> TRACE_GRAPH_NOTRACE flag set by the entry handler for
> set_graph_notrace addresses. This could leave the task
> permanently in "notrace" state and effectively disable
> function graph tracing for that task.
>
> Mirror trace_graph_return()'s per-task notrace handling by
> clearing TRACE_GRAPH_NOTRACE and returning early when set.
>
Good catch!
Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Thanks!
> Fixes: b84214890a9bc ("function_graph: Move graph notrace bit to
> shadow stack global var")
> Signed-off-by: Shengming Hu <hu.shengming@zte.com.cn>
> ---
> kernel/trace/trace_functions_graph.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/trace/trace_functions_graph.c b/kernel/trace/trace_functions_graph.c
> index 1de6f1573..cbe43680c 100644
> --- a/kernel/trace/trace_functions_graph.c
> +++ b/kernel/trace/trace_functions_graph.c
> @@ -400,14 +400,15 @@ static void trace_graph_thresh_return(struct ftrace_graph_ret *trace,
> struct fgraph_ops *gops,
> struct ftrace_regs *fregs)
> {
> + unsigned long *task_var = fgraph_get_task_var(gops);
> struct fgraph_times *ftimes;
> struct trace_array *tr;
> int size;
>
> ftrace_graph_addr_finish(gops, trace);
>
> - if (trace_recursion_test(TRACE_GRAPH_NOTRACE_BIT)) {
> - trace_recursion_clear(TRACE_GRAPH_NOTRACE_BIT);
> + if (*task_var & TRACE_GRAPH_NOTRACE) {
> + *task_var &= ~TRACE_GRAPH_NOTRACE;
> return;
> }
>
> --
> 2.25.1
--
Masami Hiramatsu (Google) <mhiramat@kernel.org>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] fgraph: fix thresh_return nosleeptime double-adjust
2026-02-21 3:33 ` [PATCH 2/2] fgraph: fix thresh_return nosleeptime double-adjust hu.shengming
@ 2026-02-24 8:36 ` Masami Hiramatsu
0 siblings, 0 replies; 5+ messages in thread
From: Masami Hiramatsu @ 2026-02-24 8:36 UTC (permalink / raw)
To: hu.shengming
Cc: rostedt, mhiramat, mathieu.desnoyers, linux-kernel,
linux-trace-kernel, zhang.run, yang.tao172, yang.yang29
On Sat, 21 Feb 2026 11:33:14 +0800 (CST)
<hu.shengming@zte.com.cn> wrote:
> From: Shengming Hu <hu.shengming@zte.com.cn>
>
> trace_graph_thresh_return() called handle_nosleeptime() and then
> delegated to trace_graph_return(), which calls
> handle_nosleeptime() again. When sleep-time accounting is
> disabled this double-adjusts calltime and can produce bogus
> durations (including underflow).
>
> Fix this by computing rettime once, applying
> handle_nosleeptime() only once, using the adjusted calltime
> for threshold comparison, and writing the return event
> directly via __trace_graph_return() when the threshold is met.
>
Looks good to me.
Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Thanks!
> Fixes: 3c9880f3ab52b ("ftrace: Use a running sleeptime instead of
> saving on shadow stack")
> Signed-off-by: Shengming Hu <hu.shengming@zte.com.cn>
> ---
> kernel/trace/trace_functions_graph.c | 14 ++++++++++----
> 1 file changed, 10 insertions(+), 4 deletions(-)
>
> diff --git a/kernel/trace/trace_functions_graph.c b/kernel/trace/trace_functions_graph.c
> index cbe43680c..b9c81fbd9 100644
> --- a/kernel/trace/trace_functions_graph.c
> +++ b/kernel/trace/trace_functions_graph.c
> @@ -403,8 +403,12 @@ static void trace_graph_thresh_return(struct ftrace_graph_ret *trace,
> unsigned long *task_var = fgraph_get_task_var(gops);
> struct fgraph_times *ftimes;
> struct trace_array *tr;
> + unsigned int trace_ctx;
> + u64 calltime, rettime;
> int size;
>
> + rettime = trace_clock_local();
> +
> ftrace_graph_addr_finish(gops, trace);
>
> if (*task_var & TRACE_GRAPH_NOTRACE) {
> @@ -419,11 +423,13 @@ static void trace_graph_thresh_return(struct ftrace_graph_ret *trace,
> tr = gops->private;
> handle_nosleeptime(tr, trace, ftimes, size);
>
> - if (tracing_thresh &&
> - (trace_clock_local() - ftimes->calltime < tracing_thresh))
> + calltime = ftimes->calltime;
> +
> + if (tracing_thresh && (rettime - calltime < tracing_thresh))
> return;
> - else
> - trace_graph_return(trace, gops, fregs);
> +
> + trace_ctx = tracing_gen_ctx();
> + __trace_graph_return(tr, trace, trace_ctx, calltime, rettime);
> }
>
> static struct fgraph_ops funcgraph_ops = {
> --
> 2.25.1
>
--
Masami Hiramatsu (Google) <mhiramat@kernel.org>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-02-24 8:37 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-21 3:16 [PATCH 0/2] fgraph: fixes for thresh_return return handler hu.shengming
2026-02-21 3:30 ` [PATCH 1/2] fgraph: fix thresh_return clear per-task notrace hu.shengming
2026-02-24 8:33 ` Masami Hiramatsu
2026-02-21 3:33 ` [PATCH 2/2] fgraph: fix thresh_return nosleeptime double-adjust hu.shengming
2026-02-24 8:36 ` Masami Hiramatsu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox