All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Weiming Shi" <bestswngs@gmail.com>
Cc: linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH v2] ftrace: Finish removing subops after a hash update failure
Date: Sun, 22 Nov 2026 16:23:45 +0000	[thread overview]
Message-ID: <sashiko-outbox-228095@kernel.org> (raw)
In-Reply-To: <20261122155620.319722-1-bestswngs@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Low] fgraph: unnecessary Tasks RCU waits in
  unregister_ftrace_graph_finish()
- [Low] ftrace: commit message omits reproduction commands requested on
  v1
--

commit 74af33bd06338337070f4988ba978b843a4c1bea
Author: Weiming Shi <bestswngs@gmail.com>

> ftrace: Finish removing subops after a hash update failure
>
> When removing a non-final graph subop, ftrace_shutdown_subops() first
> detaches it, then rebuilds and installs the manager hashes. If
> rebuild_hashes() fails, the subop stays detached with its ENABLED and
> SUBOP flags and manager pointer intact. If ftrace_update_ops() fails, the
> subop is added back even though unregister_ftrace_graph() has already
> removed its graph slot.
>
> In the fprobe path, ftrace_free_filter() then warns and returns, while
> __fprobe_graph_unregister() marks the shared graph operation unregistered.
> A later registration follows the stale SUBOP state into an empty manager
> list. rebuild_hashes() leaves its output pointers uninitialized in that
> case, and ops_equal() dereferences one of them.
>
> Complete non-final removal on both manager-hash failure paths and
> initialize empty rebuild outputs to EMPTY_HASH. Keep direct dispatch
> disabled after an update failure because the old manager hashes may cover
> functions needed only by the removed subop; normal dispatch still applies
> the remaining subops' filters.
>
> Completing removal also lets the caller free the subop filter. Split graph
> unregistration into removal and callback-wait helpers so Tasks RCU waits
> run before saved_func or the operation can be released. For asynchronous
> fprobe removal, remove the graph operation immediately and defer the wait
> and filter release to a worker that is flushed before reuse. Gate return
> callbacks on fprobe_graph_registered while cleanup is pending.
>
> Oops: general protection fault, probably for non-canonical address 0xdffffc0000000802: 0000 [#1] SMP KASAN NOPTI
> KASAN: probably user-memory-access in range [0x0000000000004010-0x0000000000004017]
> RIP: ops_equal (kernel/trace/trace.h:1011 kernel/trace/ftrace.c:3416)
> Call Trace:
>  ftrace_update_ops (kernel/trace/ftrace.c:3464)
>  ftrace_hash_move_and_update_subops.isra.0 (kernel/trace/ftrace.c:3795)
>  ftrace_hash_move_and_update_ops (kernel/trace/ftrace.c:5095)
>  ftrace_set_hash (kernel/trace/ftrace.c:6006)
>  ftrace_set_filter_ips (kernel/trace/ftrace.c:6020 kernel/trace/ftrace.c:6769)
>  register_fprobe_ips (kernel/trace/fprobe.c:290 kernel/trace/fprobe.c:1020)
>  register_fprobe (kernel/trace/fprobe.c:979)
>  __register_trace_fprobe.part.0 (kernel/trace/trace_fprobe.c:838)
>  enable_trace_fprobe (kernel/trace/trace_fprobe.c:823 kernel/trace/trace_fprobe.c:1483)
>  fprobe_register (kernel/trace/trace_fprobe.c:1553)
>  __ftrace_event_enable_disable (kernel/trace/trace_events.c:913)
>  event_enable_write (kernel/trace/trace_events.c:943 kernel/trace/trace_events.c:1995)
>  vfs_write (fs/read_write.c:665)
>  ksys_write (fs/read_write.c:719)
>  do_syscall_64 (arch/x86/entry/syscall_64.c:61 arch/x86/entry/syscall_64.c:89)
>  entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:121)
> Kernel panic - not syncing: Fatal exception
>
> Cc: stable@vger.kernel.org
> Fixes: 0ae6b8ce200d ("ftrace: Fix accounting of subop hashes")
> Reported-by: <co+bba0c6b49150bef3@bugs.sh>
> Link: https://lore.kernel.org/r/20261103175832.3374540-2-bestswngs@gmail.com
> Assisted-by: LLM
> Signed-off-by: Weiming Shi <bestswngs@gmail.com>

[Severity: Low]
As reported by Steven Rostedt on v1 [1], could the commit message include the
command lines that trigger the stale SUBOP state and the ops_equal() crash?

> diff --git a/kernel/trace/fgraph.c b/kernel/trace/fgraph.c
> index ed455b53513be..92186e7f5d698 100644
> --- a/kernel/trace/fgraph.c
> +++ b/kernel/trace/fgraph.c

[ ... ]

> @@ -1460,7 +1478,28 @@ void unregister_ftrace_graph(struct fgraph_ops *gops)
>  		unregister_pm_notifier(&ftrace_suspend_notifier);
>  		unregister_trace_sched_switch(ftrace_graph_probe_sched_switch, NULL);
>  	}
> -	gops->saved_func = NULL;
>   out:
>  	gops->ops.flags &= ~FTRACE_OPS_FL_GRAPH;
> +	return removed;
> +}
> +
> +/**
> + * unregister_ftrace_graph_finish - wait for callbacks using a removed operation
> + * @gops: graph operation previously removed by unregister_ftrace_graph_start()
> + *
> + * Wait for existing graph readers, then clear the saved callback. This may
> + * sleep. The caller may release @gops and its filter after this returns.
> + */
> +void unregister_ftrace_graph_finish(struct fgraph_ops *gops)
> +{
> +	/* Graph callbacks can run where RCU is not watching. */
> +	synchronize_rcu_tasks_rude();
> +	synchronize_rcu_tasks();
> +	gops->saved_func = NULL;
> +}

[Severity: Low]
As reported by Steven Rostedt on v1 [2], does
unregister_ftrace_graph_finish() need synchronize_rcu_tasks_rude() and
synchronize_rcu_tasks() instead of synchronize_rcu()?

Both function_graph_enter_regs() and __ftrace_return_to_handler() enter via
ftrace_test_recursion_trylock() -> trace_test_and_set_recursion(), which
checks that RCU is watching via trace_warn_on_no_rcu() and disables
preemption across all graph callbacks.  Using Tasks RCU here is inaccurate
and stalls graph unregistration and fprobe cleanup waiting for voluntary
context switches across all runnable tasks.

[1] https://lore.kernel.org/r/20261118134146.3577fcad@gandalf.local.home
[2] https://lore.kernel.org/r/20261118134146.3577fcad@gandalf.local.home

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261122155620.319722-1-bestswngs@gmail.com?part=1

  parent reply	other threads:[~2026-11-22 16:23 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-22 15:56 [PATCH v2] ftrace: Finish removing subops after a hash update failure Weiming Shi
2026-11-22 15:56 ` Weiming Shi
2026-11-22 16:23 ` sashiko-bot [this message]
2026-11-25 15:26 ` Steven Rostedt
2026-11-25 16:34   ` Weiming Shi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-228095@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bestswngs@gmail.com \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.