Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

tracing: Add show_event_filters to expose active event filters

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 <atomlin@atomlin.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>

authored by

Aaron Tomlin and committed by
Steven Rostedt (Google)
729757b9 e5136678

+66
+8
Documentation/trace/ftrace.rst
··· 684 684 685 685 See events.rst for more information. 686 686 687 + show_event_filters: 688 + 689 + A list of events that have filters. This shows the 690 + system/event pair along with the filter that is attached to 691 + the event. 692 + 693 + See events.rst for more information. 694 + 687 695 available_events: 688 696 689 697 A list of events that can be enabled in tracing.
+58
kernel/trace/trace_events.c
··· 1662 1662 mutex_unlock(&event_mutex); 1663 1663 } 1664 1664 1665 + /** 1666 + * t_show_filters - seq_file callback to display active event filters 1667 + * @m: The seq_file interface for formatted output 1668 + * @v: The current trace_event_file being iterated 1669 + * 1670 + * Identifies and prints active filters for the current event file in the 1671 + * iteration. If a filter is applied to the current event and, if so, 1672 + * prints the system name, event name, and the filter string. 1673 + */ 1674 + static int t_show_filters(struct seq_file *m, void *v) 1675 + { 1676 + struct trace_event_file *file = v; 1677 + struct trace_event_call *call = file->event_call; 1678 + struct event_filter *filter; 1679 + 1680 + guard(rcu)(); 1681 + filter = rcu_dereference(file->filter); 1682 + if (!filter || !filter->filter_string) 1683 + return 0; 1684 + 1685 + seq_printf(m, "%s:%s\t%s\n", call->class->system, 1686 + trace_event_name(call), filter->filter_string); 1687 + 1688 + return 0; 1689 + } 1690 + 1665 1691 #ifdef CONFIG_MODULES 1666 1692 static int s_show(struct seq_file *m, void *v) 1667 1693 { ··· 2515 2489 2516 2490 static int ftrace_event_avail_open(struct inode *inode, struct file *file); 2517 2491 static int ftrace_event_set_open(struct inode *inode, struct file *file); 2492 + static int ftrace_event_show_filters_open(struct inode *inode, struct file *file); 2518 2493 static int ftrace_event_set_pid_open(struct inode *inode, struct file *file); 2519 2494 static int ftrace_event_set_npid_open(struct inode *inode, struct file *file); 2520 2495 static int ftrace_event_release(struct inode *inode, struct file *file); ··· 2532 2505 .next = s_next, 2533 2506 .show = s_show, 2534 2507 .stop = s_stop, 2508 + }; 2509 + 2510 + static const struct seq_operations show_show_event_filters_seq_ops = { 2511 + .start = t_start, 2512 + .next = t_next, 2513 + .show = t_show_filters, 2514 + .stop = t_stop, 2535 2515 }; 2536 2516 2537 2517 static const struct seq_operations show_set_pid_seq_ops = { ··· 2568 2534 .write = ftrace_event_write, 2569 2535 .llseek = seq_lseek, 2570 2536 .release = ftrace_event_release, 2537 + }; 2538 + 2539 + static const struct file_operations ftrace_show_event_filters_fops = { 2540 + .open = ftrace_event_show_filters_open, 2541 + .read = seq_read, 2542 + .llseek = seq_lseek, 2543 + .release = seq_release, 2571 2544 }; 2572 2545 2573 2546 static const struct file_operations ftrace_set_event_pid_fops = { ··· 2719 2678 if (ret < 0) 2720 2679 trace_array_put(tr); 2721 2680 return ret; 2681 + } 2682 + 2683 + /** 2684 + * ftrace_event_show_filters_open - open interface for set_event_filters 2685 + * @inode: The inode of the file 2686 + * @file: The file being opened 2687 + * 2688 + * Connects the set_event_filters file to the sequence operations 2689 + * required to iterate over and display active event filters. 2690 + */ 2691 + static int 2692 + ftrace_event_show_filters_open(struct inode *inode, struct file *file) 2693 + { 2694 + return ftrace_event_open(inode, file, &show_show_event_filters_seq_ops); 2722 2695 } 2723 2696 2724 2697 static int ··· 4454 4399 tr, &ftrace_set_event_fops); 4455 4400 if (!entry) 4456 4401 return -ENOMEM; 4402 + 4403 + trace_create_file("show_event_filters", TRACE_MODE_READ, parent, tr, 4404 + &ftrace_show_event_filters_fops); 4457 4405 4458 4406 nr_entries = ARRAY_SIZE(events_entries); 4459 4407