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=1796386041; b=oy1bxxIMjF6il5sYa7ONcJKYsfvhRG2ASTEMUl3mJhQCCicSxOMHxvGt9OS7EHuVAREN 1D44N8G5/8zh9232T2o642Amo5zVmdE9M4CLl9TzrHkEcQElidKgrFaHOd4q2R8jRasGU oKpdMUm1kwZE+3pbfOt13ipLFQBViwTWgeUWcnw0pMZs3TmWvJ5b4VJEo+HLTu+BMM7SU RWPiOi3AV90jm0izudddHwljBocWjE0y9zMi5RS+7jrjimu5PCRXjXZm9T6f0z6ptftUP MwOiYtaNy+MUT7AEF5aXlsYrXS50s/jbFTZveF0tMEo2Zv4xhr60glMdtRtIA7MtPUg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796386041; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=29fgsjk/bRCnepN3BX5cYj61HI7JiG6zHMIyJ25dedY=; b=eTMBtJJw7YH6jJZ0e3C9Duew2yZBo4wwuv/9ZK2Hn5SiVNFz5oTdgXrsj1TKn2NUcb/h tszTHZykX/tYctmjOWOEMbtnjz32l583p8QdmzMlrtDHqi5FXOt0YNHYekhkCyqcKlND0 UiJNatrZmRbXpfNcqh5XUdzVcmk7szOLDoXQudtksBxMsp55gZg8L6uW/qmL3bJhFs0mQ ADXceCWTbL4vkQpETWdxuM4mjclbxRWMADxpIWPAkOnVa2xgiUXEq+ZZqCE2zFOatua+S HMTfGQoBpZI5OuiYu3oQHQ8Xu28W3xQ8au1I6toXIx8XZ6XZuTROUyVv9ZEsZyG/Mcg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=NEVtPEA8; 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 31D61606A322; Fri, 4 Dec 2026 12:07:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=NEVtPEA8 Received: by smtp.kernel.org (Postfix) with ESMTPSA id A0F501F000CE; Fri, 4 Dec 2026 12:07:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796386041; bh=29fgsjk/bRCnepN3BX5cYj61HI7JiG6zHMIyJ25dedY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=NEVtPEA8n4aB/ArblBYsH5owIbLheqFi1KV5ySWJh11CDAbOINOFgKNZgzxpjxheZ pl955MmqNle9ulj3xOOEy/Xd1u2w9nTMEunws/y6Wf0TYTy+hXl9GkWdJJYaJheQAS hquWG54PhqJifNl8kaYSX9O7fxIMGbDfZxKMqO00= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, "Masami Hiramatsu (Google)" , Sasha Levin Subject: [PATCH 6.6 0800/1167] tracing/probes: Enable newly appended probe when target event is enabled Date: Fri, 4 Dec 2026 19:03:47 +0900 Message-ID: <20261204100722.964457043@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Masami Hiramatsu (Google) [ Upstream commit 72d3a5cb0cd7335553549aaffecc683e3ecc0c43 ] Unlike kprobe events, fprobe and uprobe events only register their underlying probes when the trace event is enabled. When a new probe is appended to an existing multiprobe fprobe or uprobe event that is already enabled, the appended probe is linked into the event's probe list without being registered. As a result, the newly appended probe never fires until the event is disabled and re-enabled. Moreover, disabling an fprobe event calls unregister_fprobe() on the unregistered fprobe, and opening or closing a perf event on an enabled uprobe event dereferences a NULL tu->uprobe in uprobe_apply(). Register and enable the newly appended fprobe or uprobe immediately when the target event is already enabled. Link: https://lore.kernel.org/all/179455849798.403392.135678786198324285.stgit@devnote2/ Fixes: 41af3cf587f4 ("tracing/uprobe: Add multi-probe per uprobe event support") Fixes: 2db832ec9090 ("tracing: fprobe-events: Register fprobe-events only when it is enabled") Cc: stable@vger.kernel.org Signed-off-by: Masami Hiramatsu (Google) [ sashal: Dropped the fprobe hunks, which fix code this tree lacks, and hand-applied the uprobe fix using this tree's tu->inode/uprobe_register() API and three-argument filter_func_t. ] Signed-off-by: Sasha Levin --- kernel/trace/trace_uprobe.c | 71 +++++++++++++++++++++++-------------- 1 file changed, 45 insertions(+), 26 deletions(-) diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c index 9b2348bcea154..3adbf674fca24 100644 --- a/kernel/trace/trace_uprobe.c +++ b/kernel/trace/trace_uprobe.c @@ -434,6 +434,36 @@ static bool trace_uprobe_has_same_uprobe(struct trace_uprobe *orig, return false; } +typedef bool (*filter_func_t)(struct uprobe_consumer *self, + enum uprobe_filter_ctx ctx, + struct mm_struct *mm); + +#ifdef CONFIG_PERF_EVENTS +static bool uprobe_perf_filter(struct uprobe_consumer *uc, + enum uprobe_filter_ctx ctx, struct mm_struct *mm); +#else +#define uprobe_perf_filter NULL +#endif + +static int trace_uprobe_enable(struct trace_uprobe *tu, filter_func_t filter) +{ + int ret; + + tu->consumer.filter = filter; + tu->inode = d_real_inode(tu->path.dentry); + + if (tu->ref_ctr_offset) + ret = uprobe_register_refctr(tu->inode, tu->offset, + tu->ref_ctr_offset, &tu->consumer); + else + ret = uprobe_register(tu->inode, tu->offset, &tu->consumer); + + if (ret) + tu->inode = NULL; + + return ret; +} + static int append_trace_uprobe(struct trace_uprobe *tu, struct trace_uprobe *to) { int ret; @@ -453,10 +483,22 @@ static int append_trace_uprobe(struct trace_uprobe *tu, struct trace_uprobe *to) /* Append to existing event */ ret = trace_probe_append(&tu->tp, &to->tp); - if (!ret) - dyn_event_add(&tu->devent, trace_probe_event_call(&tu->tp)); + if (ret) + return ret; - return ret; + if (trace_probe_is_enabled(&tu->tp)) { + ret = trace_uprobe_enable(tu, + trace_probe_test_flag(&tu->tp, TP_FLAG_PROFILE) ? + uprobe_perf_filter : NULL); + if (ret) { + trace_probe_unlink(&tu->tp); + return ret; + } + } + + dyn_event_add(&tu->devent, trace_probe_event_call(&tu->tp)); + + return 0; } /* @@ -1087,29 +1129,6 @@ print_uprobe_event(struct trace_iterator *iter, int flags, struct trace_event *e return trace_handle_return(s); } -typedef bool (*filter_func_t)(struct uprobe_consumer *self, - enum uprobe_filter_ctx ctx, - struct mm_struct *mm); - -static int trace_uprobe_enable(struct trace_uprobe *tu, filter_func_t filter) -{ - int ret; - - tu->consumer.filter = filter; - tu->inode = d_real_inode(tu->path.dentry); - - if (tu->ref_ctr_offset) - ret = uprobe_register_refctr(tu->inode, tu->offset, - tu->ref_ctr_offset, &tu->consumer); - else - ret = uprobe_register(tu->inode, tu->offset, &tu->consumer); - - if (ret) - tu->inode = NULL; - - return ret; -} - static void __probe_event_disable(struct trace_probe *tp) { struct trace_uprobe *tu; -- 2.53.0