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 CDF253B3C03; Wed, 30 Sep 2026 17:54:12 +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=1790790854; cv=none; b=ZmzsDNzPRRSmFqi+4GFauqqIZISNVIs3zbo97lTSs3rXKOqHdPCWQRsyXnkgMD1/2mZ/PG8dyVKmtZ8Jz1rW9rvj3pnXj4VdPINSmN5fwJY5KkOKNgruiGN/kgkmyYZdMOAkNHbD2jQJmeWLrGQjiDiJXNW5pZiWKqS8OPkriM0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790790854; c=relaxed/simple; bh=GNI/IrpFxQX/FHYf3McnXonu+2Sf3jDxaZ3rl/JE+Yc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UmHGXzq9BRPOSyjKUchK6PntASAue7JNZpu7wDB2L/HQG8WotdFjhlhgZLB8mt9UcbE+3Qfnnnp7zwg8IqepNup3wTaOjaHjo7ParL12SKc0lmkk2N7GTtskdCIqBFp23rGjgxHFIQfbAV+MzxaWWMeyWFioab2xC0eJyI1c0o4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=gg1Ca5Kr; 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="gg1Ca5Kr" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 360D31F000FF; Wed, 30 Sep 2026 17:54:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1790790852; bh=y43MmaXms5Z4hruEHZNb/BhbM7ty3AmDzsSCOIOEkpY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=gg1Ca5KrPXPneqnTUVxKZSShntVuD5VvwhNpHegr71duJ7PJSPECzw08v0CtGQRFh V/SEOaAUz/KuBNVXPyQWzZFRbTrzytY0jmV0KQw96yL6ossSXCwzG3iuZPnUOeAS7g BnCEEspS6vw8ty7Yb2d/euwoUKoSvJ4Rh3oFrS60= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Rik van Riel , Steven Rostedt , Sasha Levin Subject: [PATCH 5.15 097/752] perf/ftrace: Fix WARNING in __unregister_ftrace_function Date: Wed, 30 Sep 2026 17:19:27 +0200 Message-ID: <20260930152400.266730391@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260930152358.131179731@linuxfoundation.org> References: <20260930152358.131179731@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: Rik van Riel [ Upstream commit 9581123304b23049437324038698af9fb56ee663 ] perf_ftrace_function_unregister() unconditionally calls unregister_ftrace_function() without checking whether the ftrace_ops was ever successfully registered. This triggers a WARN_ON in __unregister_ftrace_function() when the ops doesn't have FTRACE_OPS_FL_ENABLED set. This can happen during perf_event_alloc() error cleanup when perf_trace_destroy() is called via __free_event() on an event whose ftrace_ops registration failed or was already torn down by perf_try_init_event()'s err_destroy path. The call path is: perf_event_alloc() error cleanup -> __free_event() -> event->destroy() [tp_perf_event_destroy] -> perf_trace_destroy() -> perf_trace_event_close() -> TRACE_REG_PERF_CLOSE -> perf_ftrace_function_unregister() -> unregister_ftrace_function() -> __unregister_ftrace_function() -> WARN_ON(!(ops->flags & FTRACE_OPS_FL_ENABLED)) Fix this by checking FTRACE_OPS_FL_ENABLED before attempting to unregister. If the ops is not enabled, just free the filter and return success. Link: https://patch.msgid.link/20260527111301.2d0d8256@fangorn Signed-off-by: Rik van Riel Signed-off-by: Steven Rostedt Signed-off-by: Sasha Levin --- kernel/trace/trace_event_perf.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/kernel/trace/trace_event_perf.c b/kernel/trace/trace_event_perf.c index f2000cf2b3bba..a7e41eee9a796 100644 --- a/kernel/trace/trace_event_perf.c +++ b/kernel/trace/trace_event_perf.c @@ -501,7 +501,17 @@ static int perf_ftrace_function_register(struct perf_event *event) static int perf_ftrace_function_unregister(struct perf_event *event) { struct ftrace_ops *ops = &event->ftrace_ops; - int ret = unregister_ftrace_function(ops); + int ret = 0; + + /* + * Perf will call this unconditionally even if the ops is not + * enabled. The unregister_ftrace_function() will warn if called + * when not enabled. Just bypass the unregistering if ops isn't + * enabled here. + */ + if (ops->flags & FTRACE_OPS_FL_ENABLED) + ret = unregister_ftrace_function(ops); + ftrace_free_filter(ops); return ret; } -- 2.53.0