From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 03A4638C437; Tue, 16 Jun 2026 18:30:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781634630; cv=none; b=W88QWD8uFDsp/vGs8yWoi5twUr3MOCKgiAW8TWA3T8NysFUK+FK5DHq9gqSiSfhW8PC5BBTv/dA0lNccaTOPfRHCg+809UFmJTxxUciwgCOaXT8O5VSGl4qouU6wylqvgM9lLbmCh/WzCym0GoqF+Onnrs/jlQFvVld5G8+upE0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781634630; c=relaxed/simple; bh=odqXIaSL8bNKcEc3VXBmfG+QZBi9hmykJXnIfXCC2p0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lsdOOnNGHJnm1cKZkwtbmbX4/rTfyN9jif9hzNFc7nRgE7WEGgOOF48ur3EW8OlHQofXnUwQBPXWFE6eFCvHjGHoY9LFItqRsw4ev0H/x+7LOTn3BeASDNX0t8OEjytSqlQmKMAAan++9/yKQm02maIq9YMw4bWGr9W3fGxkrpo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=Cf+DvQLm; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="Cf+DvQLm" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 02DEA1F000E9; Tue, 16 Jun 2026 18:30:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1781634628; bh=/5/4OQwFJvHJExDoRk1xnKvFjCgw5q4mlt5dajkCVmk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Cf+DvQLm7b9k5SnHXKIXNOxErSvkbO9ifD8eZKB3ij7mq9EvyWY2os6MpjY83tZ7t N1sKMjVfp7I58lc2ctxPr/p/3uSvf4F9S5C3VhEU21VTMI0DEJ+sfr1d4/HddXxjV8 4du4FyXK8Iak0qw45146DodoUeuEz9J0fwJLcuak= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Masami Hiramatsu , Mathieu Desnoyers , David Carlier , "Steven Rostedt (Google)" , Sasha Levin Subject: [PATCH 5.15 302/411] tracepoint: balance regfunc() on func_add() failure in tracepoint_add_func() Date: Tue, 16 Jun 2026 20:29:00 +0530 Message-ID: <20260616145117.191196213@linuxfoundation.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260616145100.376842714@linuxfoundation.org> References: <20260616145100.376842714@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: David Carlier [ Upstream commit fad217e16fded7f3c09f8637b0f6a224d58b5f2e ] When a tracepoint goes through the 0 -> 1 transition, tracepoint_add_func() invokes the subsystem's ext->regfunc() before attempting to install the new probe via func_add(). If func_add() then fails (for example, when allocate_probes() cannot allocate a new probe array under memory pressure and returns -ENOMEM), the function returns the error without calling the matching ext->unregfunc(), leaving the side effects of regfunc() behind with no installed probe to justify them. For syscall tracepoints this is particularly unpleasant: syscall_regfunc() bumps sys_tracepoint_refcount and sets SYSCALL_TRACEPOINT on every task. After a leaked failure, the refcount is stuck at a non-zero value with no consumer, and every task continues paying the syscall trace entry/exit overhead until reboot. Other subsystems providing regfunc()/unregfunc() pairs exhibit similarly scoped persistent state. Mirror the existing 1 -> 0 cleanup and call ext->unregfunc() in the func_add() error path, gated on the same condition used there so the unwind is symmetric with the registration. Fixes: 8cf868affdc4 ("tracing: Have the reg function allow to fail") Cc: stable@vger.kernel.org Cc: Masami Hiramatsu Cc: Mathieu Desnoyers Link: https://patch.msgid.link/20260413190601.21993-1-devnexen@gmail.com Signed-off-by: David Carlier Signed-off-by: Steven Rostedt (Google) [ changed `tp->ext->unregfunc` to `tp->unregfunc` to match older struct layout ] Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- kernel/tracepoint.c | 2 ++ 1 file changed, 2 insertions(+) --- a/kernel/tracepoint.c +++ b/kernel/tracepoint.c @@ -337,6 +337,8 @@ static int tracepoint_add_func(struct tr lockdep_is_held(&tracepoints_mutex)); old = func_add(&tp_funcs, func, prio); if (IS_ERR(old)) { + if (tp->unregfunc && !static_key_enabled(&tp->key)) + tp->unregfunc(); WARN_ON_ONCE(warn && PTR_ERR(old) != -ENOMEM); return PTR_ERR(old); }