From nobody Sat Feb 7 14:51:51 2026 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 D17EF35CBDC for ; Tue, 27 Jan 2026 15:06:06 +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=1769526366; cv=none; b=cmvc3vE65Kx5Nl1eNvudmgBqxrquMaAeMUm3sDWVs1+JUfyi5f7nI1Sd+A/YkLjlne0lGkIdaGQszTGgZuTtdeNEL4edqHLK91/zNgxwobsOVA2MBL90gRzEdEKzn8zk6vsNWuKiVL0QZUuck5TtIUrJY9dU9bX8sO+DTExj4DM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769526366; c=relaxed/simple; bh=b5MKQFmS68tKRRE+nXDVK5jRE7M7qsfMIZZ3cnMYRYc=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=UaHJx/p0cFO68rycSN5M5jwbz4NZBFPn9nJyHugl7AxFXC061CsYot8gl5GqEk4j3OM37b+o0F4VvZo/tshmC4gF0lWtfOgYj6fWocOmiiOtWy93QOBbKjYQH8Yz/46a98ofynm35Z/WyNlhmXJaQUdEEBiw29lvzZI1a9T1AfU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nEmwTmCU; 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="nEmwTmCU" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 80443C116D0; Tue, 27 Jan 2026 15:06:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1769526366; bh=b5MKQFmS68tKRRE+nXDVK5jRE7M7qsfMIZZ3cnMYRYc=; h=Date:From:To:Cc:Subject:References:From; b=nEmwTmCUpl0MWpkINb9g4sMTwML/Ub5TP+3zYaV75nXnH/2uHQg9e1/1svQQII992 LghGb66d7PPmGmQuqXYKzEbLskbB2S3Jhem+So0ub45yLtGIr8Br7DHmVOcBXEmrKT 2RjR5ao1rejXjNP9LuYR6CUUMhB6EMh/Y8VF4ZA62ms9RknsQ7+LdkpIJG4cPxfPWT DipngYfrVOttkZWPJjI2jR6pCiKSVuhLGhWtFgvYPtPyVJUgubfr7YzfbM1GReSfAD a5hX6WXfugRmBQNZyPu8PEJG8yCZtxCAze9uQXAC5hg7iOR57AKng6sihscQyXzFu0 7sL9NXIbaC31Q== Received: from rostedt by gandalf with local (Exim 4.99.1) (envelope-from ) id 1vkkdw-00000000LcY-1Apn; Tue, 27 Jan 2026 10:06:12 -0500 Message-ID: <20260127150612.133372665@kernel.org> User-Agent: quilt/0.68 Date: Tue, 27 Jan 2026 10:06:00 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Aaron Tomlin Subject: [for-next][PATCH 05/15] tracing: Add show_event_filters to expose active event filters References: <20260127150555.840066272@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Aaron Tomlin Currently, to audit active Ftrace event filters, userspace must recursively traverse the events/ directory and read each individual filter file. This is inefficient for monitoring tools and debugging. Introduce "show_event_filters" at the trace root directory. This file displays all events that currently have a filter applied, alongside the actual filter string, in a consolidated system:event [tab] filter format. The implementation reuses the existing trace_event_file iterators to ensure atomic traversal of the event list and utilises guard(rcu)() for automatic, scope-based protection when accessing volatile filter strings. Link: https://patch.msgid.link/20260105142939.2655342-2-atomlin@atomlin.com Signed-off-by: Aaron Tomlin Signed-off-by: Steven Rostedt (Google) --- Documentation/trace/ftrace.rst | 8 +++++ kernel/trace/trace_events.c | 58 ++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/Documentation/trace/ftrace.rst b/Documentation/trace/ftrace.rst index 639f4d95732f..4ce01e726b09 100644 --- a/Documentation/trace/ftrace.rst +++ b/Documentation/trace/ftrace.rst @@ -684,6 +684,14 @@ of ftrace. Here is a list of some of the key files: =20 See events.rst for more information. =20 + show_event_filters: + + A list of events that have filters. This shows the + system/event pair along with the filter that is attached to + the event. + + See events.rst for more information. + available_events: =20 A list of events that can be enabled in tracing. diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c index 137b4d9bb116..6cbd36508368 100644 --- a/kernel/trace/trace_events.c +++ b/kernel/trace/trace_events.c @@ -1662,6 +1662,32 @@ static void t_stop(struct seq_file *m, void *p) mutex_unlock(&event_mutex); } =20 +/** + * t_show_filters - seq_file callback to display active event filters + * @m: The seq_file interface for formatted output + * @v: The current trace_event_file being iterated + * + * Identifies and prints active filters for the current event file in the + * iteration. If a filter is applied to the current event and, if so, + * prints the system name, event name, and the filter string. + */ +static int t_show_filters(struct seq_file *m, void *v) +{ + struct trace_event_file *file =3D v; + struct trace_event_call *call =3D file->event_call; + struct event_filter *filter; + + guard(rcu)(); + filter =3D rcu_dereference(file->filter); + if (!filter || !filter->filter_string) + return 0; + + seq_printf(m, "%s:%s\t%s\n", call->class->system, + trace_event_name(call), filter->filter_string); + + return 0; +} + #ifdef CONFIG_MODULES static int s_show(struct seq_file *m, void *v) { @@ -2489,6 +2515,7 @@ ftrace_event_npid_write(struct file *filp, const char= __user *ubuf, =20 static int ftrace_event_avail_open(struct inode *inode, struct file *file); static int ftrace_event_set_open(struct inode *inode, struct file *file); +static int ftrace_event_show_filters_open(struct inode *inode, struct file= *file); static int ftrace_event_set_pid_open(struct inode *inode, struct file *fil= e); static int ftrace_event_set_npid_open(struct inode *inode, struct file *fi= le); static int ftrace_event_release(struct inode *inode, struct file *file); @@ -2507,6 +2534,13 @@ static const struct seq_operations show_set_event_se= q_ops =3D { .stop =3D s_stop, }; =20 +static const struct seq_operations show_show_event_filters_seq_ops =3D { + .start =3D t_start, + .next =3D t_next, + .show =3D t_show_filters, + .stop =3D t_stop, +}; + static const struct seq_operations show_set_pid_seq_ops =3D { .start =3D p_start, .next =3D p_next, @@ -2536,6 +2570,13 @@ static const struct file_operations ftrace_set_event= _fops =3D { .release =3D ftrace_event_release, }; =20 +static const struct file_operations ftrace_show_event_filters_fops =3D { + .open =3D ftrace_event_show_filters_open, + .read =3D seq_read, + .llseek =3D seq_lseek, + .release =3D seq_release, +}; + static const struct file_operations ftrace_set_event_pid_fops =3D { .open =3D ftrace_event_set_pid_open, .read =3D seq_read, @@ -2680,6 +2721,20 @@ ftrace_event_set_open(struct inode *inode, struct fi= le *file) return ret; } =20 +/** + * ftrace_event_show_filters_open - open interface for set_event_filters + * @inode: The inode of the file + * @file: The file being opened + * + * Connects the set_event_filters file to the sequence operations + * required to iterate over and display active event filters. + */ +static int +ftrace_event_show_filters_open(struct inode *inode, struct file *file) +{ + return ftrace_event_open(inode, file, &show_show_event_filters_seq_ops); +} + static int ftrace_event_set_pid_open(struct inode *inode, struct file *file) { @@ -4400,6 +4455,9 @@ create_event_toplevel_files(struct dentry *parent, st= ruct trace_array *tr) if (!entry) return -ENOMEM; =20 + trace_create_file("show_event_filters", TRACE_MODE_READ, parent, tr, + &ftrace_show_event_filters_fops); + nr_entries =3D ARRAY_SIZE(events_entries); =20 e_events =3D eventfs_create_events_dir("events", parent, events_entries, --=20 2.51.0