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 53B4C285C91 for ; Sun, 10 May 2026 19:59:57 +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=1778443197; cv=none; b=oWEM3kAk6MFCogp31vBa+1T0mn9bmvKPePtUFkE7351dPvM3ZHZI+wKI+txqKxoNsCrXmG/JbObR14PZmZiLV9xBymku+gVRUAaD8E6t2Y+N2gngiJSMHzrzeWQcmhYTsdvHia5BJBpkc0M8lBExXhWJ0xYIpAUf0OnFxfeTfjg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778443197; c=relaxed/simple; bh=XS1W39PKlfCMii2HUUV0ytBxSMzvWKYYZiIHh1N/sz4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kirHU/7UMWoIBH+wGAllsddaU6i38TbLpldOKTgF/Kjn1AfQmzIbLKBb37P44SSjMr3UvZWteIeigVe5n1VtDnY6YkR5uITT9y39cjfDYiLls+BpSxdhXn1SvtwIIwtm+qwzyZXtTSqrXv99L08FwdQPm+6d6vlEAkEMSaNzhBM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kGXxZPph; 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="kGXxZPph" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 49D4CC2BCC7; Sun, 10 May 2026 19:59:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1778443197; bh=XS1W39PKlfCMii2HUUV0ytBxSMzvWKYYZiIHh1N/sz4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kGXxZPph9BPL/9PivbdKpAeVvxOcZ/OkUhN4LcAxZ4WwpIsD9d4m4IciVHB1PjtJk SjEY5EuZrgs8EKWscFpcdwkl99QKEx7+2le6OVucVunGBWbDO720pNvfPHP/4mmBQL dcUrXCQu7rQPLF/Q1L6g9C5QmW7snMqTWm7oKwYnXhPX6OlcFwSkNImt0QwyDR7DF4 gNJKI+PjP+ARpn9R4GutUoY2TcjHANfbDh7VpJMpFjNNrpt59q+Xj52BKfXP/WubeQ 8UPJOflqZ5zFRu4lC7JYs6lJKRWx+dxaq3xqEQ8A2dLK5geOkAVy3oPFArxWL8dInI AQ19j9ndinnjg== From: Sasha Levin To: stable@vger.kernel.org Cc: David Carlier , Masami Hiramatsu , Mathieu Desnoyers , "Steven Rostedt (Google)" , Sasha Levin Subject: [PATCH 6.6.y] tracepoint: balance regfunc() on func_add() failure in tracepoint_add_func() Date: Sun, 10 May 2026 15:59:53 -0400 Message-ID: <20260510195953.593373-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026050735-vantage-encircle-acad@gregkh> References: <2026050735-vantage-encircle-acad@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- kernel/tracepoint.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/tracepoint.c b/kernel/tracepoint.c index 8d1507dd07246..f7a4210d5d5e2 100644 --- a/kernel/tracepoint.c +++ b/kernel/tracepoint.c @@ -337,6 +337,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->unregfunc && !static_key_enabled(&tp->key)) + tp->unregfunc(); WARN_ON_ONCE(warn && PTR_ERR(old) != -ENOMEM); return PTR_ERR(old); } -- 2.53.0