From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796295899; b=g/omImnEXiThMgtpY+6l4x0pG1FBXYF20SsSVV8IRe7aAV09m7HTFDsP3HFKQI+uAUVe JiHdkcbVOq0y4+hBHffd85IuT/tK9NlwWj8BWwh/VVrTiV2s/C2Q74vX0jWxigN0Ml2CA 8ZpsMNuy96l/UkR4q2xMTet4FcjEkAjSzTit23/hqKfuc1jdLpO8rc5mmQD6kIn3V+WKU jsfXIq9eJtN3xbE9iUQvjoPnaUdcGIPC2+jOO8N9VGz0FApbtTIkIfqIfGkS6CRUF7zaP 3GNa6Yl3Yo0dsm8uIlz4JI/TXRl63gRoHrh2sdkekQ584F1G1Vg89z05rOhKO54eR/w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796295899; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=sNK61ec2YwetahmllAWprTklqI4ksCFh+vIYQGJ2nPY=; b=mLfe4ePF4mArqJkTGR+NsALboW0OpbQH9sca/mE3EPklLNFF0Nw3bsXpz1thm5s0Zzjj yDRnA9jb1bJhd8MgGQRrB5iFzNBhO1oaMH3S5Xhl5PKEEPMSDmm82C9+8BFScHKsJg49I VN0uWRZM0/loVsZArZ1LWoobZKokKK2xpvALonD9eQdOvrWVHbHumsbX3i0xyGcWNuIFZ YQ84kuKxE1Hg2cl0WN2cpWb8C0q30BwW05kPRXR+7+Ihf2of3GPfo3SuvRV2Vo9tZZHGp dGfZcuQzkDj+xcqCDmDS7+cXSYbL1m7Pm8nTaDi5Ve6WO5ygwgcHJ8zkBroyMq1Y8WA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=UxswfOQX; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 36480606A332 for ; Thu, 3 Dec 2026 11:04:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=UxswfOQX Received: by smtp.kernel.org (Postfix) with ESMTPSA id F18681F00893; Thu, 3 Dec 2026 11:04:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796295899; bh=sNK61ec2YwetahmllAWprTklqI4ksCFh+vIYQGJ2nPY=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=UxswfOQXdCoiharSaxPQ2xfb6GJYREVweywNatJxUGKB7DSWpoDybzjr2WiNXH9Ez ku9zLcY7R9iuyBiGHmWQVgKlTIz9hJuKEC2dPXuF501+hGNHSeW+X8mZh+WZmkhI35 lt/M3zMWYiV9Bx/SbBT/s78TJZIGd5WVPD88E07+o9eTxOk2yDXfXqjO2Mt9vBy1pe ZkfuX7OB7J5I8V8NRz6F3tG0WlteSNEDDRdQj2ihdgaDpVPhfOdJ7APIb0F+ySOT3/ kxwokwFYvwcNSh4ISxK4DvcLx03u4ERKqTiwS07lltsU7y2M0fJYGRhacR8AgAOjT9 SBkPcblRnjRMw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v4] ftrace: Finish removing subops after a hash update failure Reply-To: sashiko-reviews@lists.linux.dev To: "Weiming Shi" Cc: linux-trace-kernel@vger.kernel.org In-Reply-To: <20261203103722.3018885-3-bestswngs@gmail.com> References: <20261203103722.3018885-3-bestswngs@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 11:04:58 +0000 X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [Medium] ftrace: unregister_ftrace_graph_finish() omits synchronize_rcu_tasks_rude() - [Medium] fprobe: flush_work() on system_percpu_wq under fprobe_mutex can deadlock - [Medium] fprobe: fprobe_graph_add_ips() flushes RCU cleanup work under fprobe_mutex -- commit 56709e03db270d3dcfbc9de74d45ec089fa5e472 Author: Weiming Shi ftrace: Finish removing subops after a hash update failure This commit detaches subops in ftrace_shutdown_subops() even when the manager hash update fails, splits unregister_ftrace_graph() into start and finish helpers with synchronize_rcu(), and defers fprobe graph cleanup to a work item flushed on re-registration. > diff --git a/kernel/trace/fgraph.c b/kernel/trace/fgraph.c > index d1f79a85ed2e9..8dea86a62ff44 100644 > --- a/kernel/trace/fgraph.c > +++ b/kernel/trace/fgraph.c [ ... ] > +void unregister_ftrace_graph_finish(struct fgraph_ops *gops) > +{ > + synchronize_rcu(); > + gops->saved_func =3D NULL; > +} [Severity: Medium] Is synchronize_rcu() alone sufficient to wait for in-flight graph callbacks before clearing gops->saved_func and freeing the filter? On architectures without CONFIG_ARCH_WANTS_NO_INSTR (such as PowerPC), traceable functions like arch_cpu_idle() run after ct_cpuidle_enter() while !rcu_is_watching(). function_graph_enter_regs() only holds preempt_disable_notrace() and does not check rcu_is_watching(). CPU0 (!rcu_is_watching()) CPU1 arch_cpu_idle() function_graph_enter_regs() ftrace_test_recursion_trylock() gops =3D READ_ONCE(...) unregister_ftrace_graph_start(gops) unregister_ftrace_graph_finish(gops) synchronize_rcu() gops->saved_func =3D NULL ftrace_free_filter(&gops->ops) ftrace_ops_test(...) <-- use-after-free Because CPU0 is in an RCU extended quiescent state, synchronize_rcu() returns without waiting for it. CPU0 can then dereference a freed filter hash in ftrace_ops_test() or a NULL gops->saved_func in fgraph_pid_func(). Calling synchronize_rcu_tasks_rude() alongside synchronize_rcu(), as ftrace_shutdown() and ftrace_graph_release() do, waits for these readers on non-noinstr architectures while remaining a no-op when CONFIG_ARCH_WANTS_NO_INSTR is enabled. > diff --git a/kernel/trace/fprobe.c b/kernel/trace/fprobe.c > index 47d565a1e2c56..5bd14c2e738f6 100644 > --- a/kernel/trace/fprobe.c > +++ b/kernel/trace/fprobe.c [ ... ] > @@ -279,6 +281,14 @@ static struct fgraph_ops fprobe_graph_ops =3D { > static int nr_fgraph_fprobes; > /* Is fprobe_graph_ops registered? */ > static bool fprobe_graph_registered; > +static void fprobe_graph_cleanup_workfn(struct work_struct *work); > +static DECLARE_WORK(fprobe_graph_cleanup_work, fprobe_graph_cleanup_work= fn); > + > +static void fprobe_graph_cleanup_workfn(struct work_struct *work) > +{ > + unregister_ftrace_graph_finish(&fprobe_graph_ops); > + ftrace_free_filter(&fprobe_graph_ops.ops); > +} > =20 > /* Add @addrs to the ftrace filter and register fgraph if needed. */ > static int fprobe_graph_add_ips(unsigned long *addrs, int num) > @@ -286,6 +296,7 @@ static int fprobe_graph_add_ips(unsigned long *addrs,= int num) > int ret; > =20 > lockdep_assert_held(&fprobe_mutex); > + flush_work(&fprobe_graph_cleanup_work); [Severity: Medium] Does flushing fprobe_graph_cleanup_work here hold fprobe_mutex across a full RCU grace period? When the last graph-backed fprobe unregisters via unregister_fprobe_async() and a new one registers before fprobe_graph_cleanup_workfn() finishes synchronize_rcu(), register_fprobe_ips() sleeps in flush_work() while holding fprobe_mutex. This stalls concurrent unregister_fprobe_async() calls (such as bpf_kprobe_multi_link_release(), which avoids waiting on an RCU grace period), unrelated fprobe registrations, and module unloads in fprobe_module_callback() for the entire grace period. Since fprobe_graph_cleanup_workfn() does not acquire fprobe_mutex, flushing pending cleanup outside fprobe_mutex (or dropping and re-acquiring it when cleanup is pending) would avoid the stall. [ ... ] > @@ -305,8 +316,8 @@ static int fprobe_graph_add_ips(unsigned long *addrs,= int num) > static void __fprobe_graph_unregister(void) > { > if (fprobe_graph_registered) { > - unregister_ftrace_graph(&fprobe_graph_ops); > - ftrace_free_filter(&fprobe_graph_ops.ops); > + if (unregister_ftrace_graph_start(&fprobe_graph_ops)) > + schedule_work(&fprobe_graph_cleanup_work); > fprobe_graph_registered =3D false; > } > } [Severity: Medium] Can scheduling fprobe_graph_cleanup_work on system_percpu_wq deadlock with fprobe_graph_add_ips() calling flush_work() under fprobe_mutex? bpf_link_put() also queues bpf_link_put_deferred() on system_percpu_wq, and for kprobe_multi links that worker acquires fprobe_mutex via unregister_fprobe_async(). If 1024 such works fill a CPU's percpu_max_active limit, fprobe_graph_cleanup_work stays inactive: CPU1 CPU0 (system_percpu_wq) ---- ---- 1024x bpf_link_put_deferred() active fprobe_graph_cleanup_work inactive register_fprobe_ips() mutex_lock(&fprobe_mutex) fprobe_graph_add_ips() flush_work(...) /* waits for inactive work */ bpf_link_put_deferred() bpf_kprobe_multi_link_release() unregister_fprobe_async() mutex_lock(&fprobe_mutex) <-- deadlock None of the active bpf_link_put_deferred() workers can finish until fprobe_mutex is released, so fprobe_graph_cleanup_work is never activated and fprobe_mutex deadlocks permanently. Using a dedicated workqueue for fprobe_graph_cleanup_work (or flushing outside fprobe_mutex) would break the shared-workqueue dependency. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203103722.3018= 885-3-bestswngs@gmail.com?part=3D1