Re: [PATCH v3] ftrace: Finish removing subops after a hash update failure

From: Weiming Shi

Date: Wed Dec 02 2026 - 11:49:15 EST


Steven Rostedt <rostedt@xxxxxxxxxxx> 于2026年12月1日周二 13:36写道:
>
> On Mon, 30 Nov 2026 20:25:24 -0800
> Weiming Shi <bestswngs@xxxxxxxxx> wrote:
>
> > When other graph operations remain, ftrace_shutdown_subops() removes a
> > subop from the manager list before rebuilding the manager hashes. This
> > non-final hash update only fails on an allocation failure (-ENOMEM) in
> > rebuild_hashes() or ftrace_update_ops(). If rebuild_hashes() fails, the
> > subop remains off the list with FTRACE_OPS_FL_ENABLED and
> > FTRACE_OPS_FL_SUBOP still set. If ftrace_update_ops() fails, it adds
> > the subop back to the list without clearing those flags.
> >
> > unregister_ftrace_graph() has already removed the operation from
> > fgraph_array[] in both cases. In the fprobe path, ftrace_free_filter()
> > then warns and returns because FTRACE_OPS_FL_ENABLED is still set, while
> > __fprobe_graph_unregister() clears fprobe_graph_registered. A later
> > registration follows the stale FTRACE_OPS_FL_SUBOP state into an empty
> > manager list. rebuild_hashes() leaves its output pointers uninitialized
> > for an empty list, so ops_equal() dereferences one of them and crashes.
>
> I'm assuming the above is directly from AI output. AI sucks at making
> readable change logs. Can you please reword this to be readable by humans?
> Feel free to write it somewhere in your native language and have AI
> translate that. I'm sure that would be much easier to read than the above
> text.
>
> >
> > The reproducer hits this by enabling function_graph with a filter on
> > tcp_v4_connect and a return fprobe on udp_sendmsg, then using failslab
> > fault injection to force -ENOMEM in ftrace_shutdown_subops() while
> > disabling the fprobe. Updating the remaining tracer filter to
> > udp_sendmsg, trying to re-enable the fprobe (failing with -EBUSY),
> > disabling function_graph, and enabling the fprobe again crashes in
> > ops_equal().
>
> The above should show the actual commands used. Not a run-on sentence of a
> description. Again, that's very hard to read.
> >
> > Finish non-final subop removal on both -ENOMEM paths by clearing the
> > ENABLED and SUBOP flags and managed pointer, and initialize the
> > rebuild_hashes() outputs to EMPTY_HASH so an empty list is safe. Since
> > the old manager hashes may still include functions needed only by the
> > removed subop, keep direct graph calls disabled on an update failure so
> > each remaining subop filter is checked; restore direct calls after a
> > successful reduction to one graph operation or on a new first
> > registration.
> >
> > Completing removal also lets callers free the subop filter even after a
> > hash update failure, while graph callbacks that entered before removal
> > may still use the operation or its filter with preemption disabled. Split
> > unregister_ftrace_graph() into removal and synchronize_rcu() wait
> > helpers, and clear saved_func only after that grace period. Keep the
> > public API synchronous, and in fprobe remove the graph operation
> > synchronously while deferring the wait and filter free to a worker that
> > is flushed before reuse.
>
> The above also needs to be reworked to something that humans can read and
> not directly from an AI (unless its a translation of something you wrote).
>
> Thanks,
>
> -- Steve
>
> >
> > 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:
> > 0010: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:5096)
> > ftrace_set_hash (kernel/trace/ftrace.c:6007)
> > ftrace_set_filter_ips (kernel/trace/ftrace.c:6021
> > kernel/trace/ftrace.c:6770) 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
> >
> > Fixes: 0ae6b8ce200d ("ftrace: Fix accounting of subop hashes")
> > Reported-by: <co+bba0c6b49150bef3@xxxxxxx>
> > Assisted-by: LLM
> > Signed-off-by: Weiming Shi <bestswngs@xxxxxxxxx>
> > ---
Hi ,

Thanks for your review. I will rewrite the commit message in v4.

Best regards,
Weiming