From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 2C74938B7BD; Thu, 16 Apr 2026 08:41:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776328912; cv=none; b=KZpQyokE6PP/6sHJTI/EijGLBeV7muY/UU7gYeKm+BFNjUeh+d6H3KB8FVe+/ma1euBuXjwYXwrcZ4PMMIRF295tc8nF0Q1hi8WrVjcy5fCO5grXZHIzfyTA5LWAK/02CDCKdbn4dghZGBa0afDDWUPG0UJ5K0r+xxcv41AJXKo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776328912; c=relaxed/simple; bh=0J3tkdy+okol4NtJaMhqlRalobhJ+tasAuRBXeB69KE=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=KFWp2tb8U0sDxPvO9AMhsCJnlM0aKyGe0NF6aDBVp2V2QCocWITT7npGRtvA5fhoksrIsbsR/4EEM9/hRtkIZg06Th8Lr5Fn6ciU8JZ4pdDZnKzqm55tFjq+iKLRgNN8djrZXLC53pZxcbGIjZgIv78SSgxa6vmCkaX9F31zrn4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BAqCuX5O; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="BAqCuX5O" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 02950C2BCAF; Thu, 16 Apr 2026 08:41:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776328912; bh=0J3tkdy+okol4NtJaMhqlRalobhJ+tasAuRBXeB69KE=; h=Date:From:To:Cc:Subject:References:From; b=BAqCuX5ObrqoXZ2lhwVRoGLHYL5uXax1KOCXgXRUiBDBlJcNyU5zw13/UhmWsitFi zOfTm7lakGw8E5GPleS41yW7Kl+jzM2nttpKR5ZKt7miYP+wiRYLTHSnBkFXMuA6er /AJ/a9kTDZCOX/X15HRmJhXjfZDGxbgX/svUD8YxDkBcO2j516DwAamn2wyGj6gJGT nbLXviCYaveHtAmuDLY27xLBlydvOocnLVuW5DhsAJoBVr5n8SeDg9kA4TR+IQA5WY do7K08UNb/x8CXjwYeyZFd8J7ftFW6HVclYpGoWJlhG6D2oQDOLz+1qMYDui+e6ry7 OjI/st2g4gS3g== Received: from rostedt by gandalf with local (Exim 4.99.1) (envelope-from ) id 1wDIJq-00000005avv-1U0h; Thu, 16 Apr 2026 04:43:26 -0400 Message-ID: <20260416084326.223858869@kernel.org> User-Agent: quilt/0.69 Date: Thu, 16 Apr 2026 04:42:57 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , stable@vger.kernel.org, David Carlier Subject: [for-next][PATCH 3/5] tracepoint: balance regfunc() on func_add() failure in tracepoint_add_func() References: <20260416084254.980129867@kernel.org> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 From: David Carlier 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) --- kernel/tracepoint.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/tracepoint.c b/kernel/tracepoint.c index 91905aa19294..dffef52a807b 100644 --- a/kernel/tracepoint.c +++ b/kernel/tracepoint.c @@ -300,6 +300,8 @@ static int tracepoint_add_func(struct tracepoint *tp, lockdep_is_held(&tracepoints_mutex)); old = func_add(&tp_funcs, func, prio); if (IS_ERR(old)) { + if (tp->ext && tp->ext->unregfunc && !static_key_enabled(&tp->key)) + tp->ext->unregfunc(); WARN_ON_ONCE(warn && PTR_ERR(old) != -ENOMEM); return PTR_ERR(old); } -- 2.51.0