Skip to contentSkip to conversation

tracepoints: Add warnings for unused tracepoints and trace events

PATCH Superseded Steven Rostedt 2 participants 9 messages Jul 22, 2025

Subsystems (3)

v3 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

v3 cover tracepoints: Add warnings for unused tracepoints and trace events

Every trace event can take up to 5K of memory in text and metadata regardless if they are used or not. Trace events should not be created if they are not used. Currently there's over a hundred events in the kernel that are defined but unused, either because their callers were removed without removing the trace event with it, or a config hides the trace event caller but not the trace event itself. And in some cases, trace events were simply added but were never called for whatever reason. The number of unused trace events continues to grow.

This patch series aims to fix this.

The first patch creates a new section called __tracepoint_check, where all callers of a tracepoint creates a variable that is placed in this section with a pointer to the tracepoint they use. Then on boot up, it iterates this section and will modify the tracepoint's "func" field to a value of 1 (all tracepoints "func" fields are initialized to NULL and is only set when they are registered). This takes place before any tracepoint can be registered.

Then each tracepoint is iterated on and if any tracepoint does not have its "func" field set to 1 a warning is triggered and every tracepoint that doesn't have that field set is printed. The "func" field is then reset back to NULL.

The second patch modifies scripts/sorttable.c to read the __tracepoint_check section. It sorts it, and then reads the __tracepoint_ptr section that has all compiled in tracepoints. It makes sure that every tracepoint is found in the check section and if not, it prints a warning message about it. This lists the missing tracepoints at build time.

The third patch updates sorttable to work for arm64 when compiled with gcc. As gcc's arm64 build doesn't put addresses in their section but saves them off in the RELA sections. This mostly takes the work done that was needed to do the mcount sorting at boot up on arm64.

The fourth patch adds EXPORT_TRACEPOINT() to the __tracepoint_check section as well. There was several locations that adds tracepoints in the kernel proper that are only used in modules. It was getting quite complex trying to move things around that I just decided to make any tracepoint in a EXPORT_TRACEPOINT "used". I'm using the analogy of static and global functions. An unused static function gets a warning but an unused global one does not.

The last patch updates the trace_ftrace_test_filter boot up self test. That selftest creates a trace event to run a bunch of filter tests on it without actually calling the tracepoint. To quiet the warning, the selftest tracepoint is called within a if (!trace_<event>_enabled()) section, where it will not be optimized out, nor will it be called.

Changes since v2: https://lore.kernel.org/all/[email protected]/

- Fixed some typos in the above change log, and in comments within patches.

- Have the build warning on unused events be default off. There is still too many events that are unused to make a warning a default. But after all current offenders are fixed, I plan on making it default enabled to prevent new trace events from being added when they are unused.

Steven Rostedt (5):
tracepoints: Add verifier that makes sure all defined tracepoints are used
tracing: sorttable: Add a tracepoint verification check at build time
tracing: sorttable: Find unused tracepoints for arm64 that uses reloc for address
tracepoint: Do not warn for unused event that is exported
tracing: Call trace_ftrace_test_filter() for the event

----

 include/asm-generic/vmlinux.lds.h  |   1 +
 include/linux/tracepoint.h         |  13 ++
 kernel/trace/Kconfig               |  30 +++
 kernel/trace/trace_events_filter.c |   4 +
 kernel/tracepoint.c                |  26 +++
 scripts/Makefile                   |   4 +
 scripts/sorttable.c                | 444 ++++++++++++++++++++++++++++++-------
 7 files changed, 436 insertions(+), 86 deletions(-)
#1 lore raw

PATCH v3 1/5 tracepoints: Add verifier that makes sure all defined tracepoints are used

From: Steven Rostedt <[email protected]>

If a tracepoint is defined via DECLARE_TRACE() or TRACE_EVENT() but never called (via the trace_<tracepoint>() function), its metadata is still around in memory and not discarded.

When created via TRACE_EVENT() the situation is worse because the TRACE_EVENT() creates metadata that can be around 5k per trace event. Having unused trace events causes several thousand of wasted bytes.

Add a verifier that injects a pointer to the tracepoint structure in the functions that are used and added to a section called __tracepoint_check. Then on boot up, iterate over this section and for every tracepoint descriptor that is pointed to, update its ".funcs" field to (void *)1, as the .funcs field is only set when a tracepoint is registered. At this time, no tracepoints should be registered.

Then iterate all tracepoints and if any tracepoints doesn't have its .funcs field set to (void*)1, trigger a warning, and list all tracepoints that are not found.

Enabling this currently with a given config produces:

Tracepoint x86_fpu_before_restore unused
Tracepoint x86_fpu_after_restore unused
Tracepoint x86_fpu_init_state unused
Tracepoint pelt_hw_tp unused
Tracepoint pelt_irq_tp unused
Tracepoint ipi_raise unused
Tracepoint ipi_entry unused
Tracepoint ipi_exit unused
Tracepoint irq_matrix_alloc_reserved unused
Tracepoint psci_domain_idle_enter unused
Tracepoint psci_domain_idle_exit unused
Tracepoint powernv_throttle unused
Tracepoint clock_enable unused
Tracepoint clock_disable unused
Tracepoint clock_set_rate unused
Tracepoint power_domain_target unused
Tracepoint xdp_bulk_tx unused
Tracepoint xdp_redirect_map unused
Tracepoint xdp_redirect_map_err unused
Tracepoint mem_return_failed unused
Tracepoint vma_mas_szero unused
Tracepoint vma_store unused
Tracepoint hugepage_set_pmd unused
Tracepoint hugepage_set_pud unused
Tracepoint hugepage_update_pmd unused
Tracepoint hugepage_update_pud unused
Tracepoint dax_pmd_insert_mapping unused
Tracepoint dax_insert_mapping unused
Tracepoint block_rq_remap unused
Tracepoint xhci_dbc_handle_event unused
Tracepoint xhci_dbc_handle_transfer unused
Tracepoint xhci_dbc_gadget_ep_queue unused
Tracepoint xhci_dbc_alloc_request unused
Tracepoint xhci_dbc_free_request unused
Tracepoint xhci_dbc_queue_request unused
Tracepoint xhci_dbc_giveback_request unused
Tracepoint tcp_ao_wrong_maclen unused
Tracepoint tcp_ao_mismatch unused
Tracepoint tcp_ao_key_not_found unused
Tracepoint tcp_ao_rnext_request unused
Tracepoint tcp_ao_synack_no_key unused
Tracepoint tcp_ao_snd_sne_update unused
Tracepoint tcp_ao_rcv_sne_update unused

Some of the above is totally unused but others are not used due to their "trace_" functions being inside configs, in which case, the defined tracepoints should also be inside those same configs. Others are architecture specific but defined in generic code, where they should either be moved to the architecture or be surrounded by #ifdef for the architectures they are for.

Note, currently this only handles tracepoints that are builtin. This can easily be extended to verify tracepoints used by modules, but it requires a slightly different approach as it needs updates to the module code.

---
 include/asm-generic/vmlinux.lds.h |  1 +
 include/linux/tracepoint.h        | 10 ++++++++++
 kernel/trace/Kconfig              | 19 +++++++++++++++++++
 kernel/tracepoint.c               | 26 ++++++++++++++++++++++++++
 4 files changed, 56 insertions(+)
include/asm-generic/vmlinux.lds.h +1 -0
index fa5f19b8d53a..600d8b51e315 100644
@@ -708,6 +708,7 @@ defined(CONFIG_AUTOFDO_CLANG) || defined(CONFIG_PROPELLER_CLANG)
 	MCOUNT_REC()							\
 	*(.init.rodata .init.rodata.*)					\
 	FTRACE_EVENTS()							\
+	BOUNDED_SECTION_BY(__tracepoint_check, ___tracepoint_check)	\
 	TRACE_SYSCALLS()						\
 	KPROBE_BLACKLIST()						\
 	ERROR_INJECT_WHITELIST()					\
include/linux/tracepoint.h +10 -0
index 826ce3f8e1f8..2b96c7e94c52 100644
@@ -221,6 +221,14 @@ static inline struct tracepoint *tracepoint_ptr_deref(tracepoint_ptr_t *p)
 		__do_trace_##name(args);				\
 	}
 
+#ifdef CONFIG_TRACEPOINT_VERIFY_USED
+# define TRACEPOINT_CHECK(name)						\
+	static void __used __section("__tracepoint_check") *__trace_check = \
+		&__tracepoint_##name;
+#else
+# define TRACEPOINT_CHECK(name)
+#endif
+
 /*
  * Make sure the alignment of the structure in the __tracepoints section will
  * not add unwanted padding between the beginning of the section and the
@@ -270,6 +278,7 @@ static inline struct tracepoint *tracepoint_ptr_deref(tracepoint_ptr_t *p)
 	__DECLARE_TRACE_COMMON(name, PARAMS(proto), PARAMS(args), PARAMS(data_proto)) \
 	static inline void __do_trace_##name(proto)			\
 	{								\
+		TRACEPOINT_CHECK(name)					\
 		if (cond) {						\
 			guard(preempt_notrace)();			\
 			__DO_TRACE_CALL(name, TP_ARGS(args));		\
@@ -289,6 +298,7 @@ static inline struct tracepoint *tracepoint_ptr_deref(tracepoint_ptr_t *p)
 	__DECLARE_TRACE_COMMON(name, PARAMS(proto), PARAMS(args), PARAMS(data_proto)) \
 	static inline void __do_trace_##name(proto)			\
 	{								\
+		TRACEPOINT_CHECK(name)					\
 		guard(rcu_tasks_trace)();				\
 		__DO_TRACE_CALL(name, TP_ARGS(args));			\
 	}								\
kernel/trace/Kconfig +19 -0
index a3f35c7d83b6..e676b802b721 100644
@@ -1044,6 +1044,25 @@ config GCOV_PROFILE_FTRACE
 	  Note that on a kernel compiled with this config, ftrace will
 	  run significantly slower.
 
+config TRACEPOINT_VERIFY_USED
+	bool
+	help
+          This option creates a section when tracepoints are used
+	  that hold a pointer to the tracepoint that is used.
+	  This can be used to test if a defined tracepoint is
+	  used or not.
+
+config TRACEPOINT_WARN_ON_UNUSED
+	bool "Warn if any tracepoint is defined but not used"
+	depends on TRACEPOINTS
+	select TRACEPOINT_VERIFY_USED
+	help
+	  This option checks if every builtin defined tracepoint is
+	  used in the code. If a tracepoint is defined but not used,
+	  it will waste memory as its metadata is still created.
+	  A warning will be triggered if a tracepoint is found and
+	  not used at bootup.
+
 config FTRACE_SELFTEST
 	bool
 
kernel/tracepoint.c +26 -0
index 62719d2941c9..7701a6fed310 100644
@@ -677,10 +677,36 @@ static struct notifier_block tracepoint_module_nb = {
 	.priority = 0,
 };
 
+#ifdef CONFIG_TRACEPOINT_WARN_ON_UNUSED
+extern void * __start___tracepoint_check[];
+extern void * __stop___tracepoint_check[];
+
+#define VERIFIED_TRACEPOINT	((void *)1)
+
+static void check_tracepoint(struct tracepoint *tp, void *priv)
+{
+	if (WARN_ONCE(tp->funcs != VERIFIED_TRACEPOINT, "Unused tracepoints found"))
+		pr_warn("Tracepoint %s unused\n", tp->name);
+
+	tp->funcs = NULL;
+}
+#endif
+
 static __init int init_tracepoints(void)
 {
 	int ret;
 
+#ifdef CONFIG_TRACEPOINT_WARN_ON_UNUSED
+	for (void **ptr = __start___tracepoint_check;
+	     ptr < __stop___tracepoint_check; ptr++) {
+		struct tracepoint *tp = *ptr;
+
+		tp->funcs = VERIFIED_TRACEPOINT;
+	}
+
+	for_each_kernel_tracepoint(check_tracepoint, NULL);
+#endif
+
 	ret = register_module_notifier(&tracepoint_module_nb);
 	if (ret)
 		pr_warn("Failed to register tracepoint module enter notifier\n");
Signature · 1 line
2.47.2
#5 lore raw

PATCH v3 2/5 tracing: sorttable: Add a tracepoint verification check at build time

In reply to Steven Rostedt

From: Steven Rostedt <[email protected]>

Update the sorttable code to check the tracepoint_check and tracepoint_ptr sections to see what trace events have been created but not used. Trace events can take up approximately 5K of memory each regardless if they are called or not.

List the tracepoints that are not used at build time. Note, this currently only handles tracepoints that are builtin and not in modules.

---
Changes since v2: https://lore.kernel.org/[email protected]

- Make default n for now. As there are still tracepoints in the kernel that can be defined but not used, its best to not warn about them until they are fixed.

 kernel/trace/Kconfig |  11 ++
 scripts/Makefile     |   4 +
 scripts/sorttable.c  | 268 +++++++++++++++++++++++++++++++++++++++----
 3 files changed, 260 insertions(+), 23 deletions(-)
kernel/trace/Kconfig +11 -0
index e676b802b721..bf964983d9e2 100644
@@ -1063,6 +1063,17 @@ config TRACEPOINT_WARN_ON_UNUSED
 	  A warning will be triggered if a tracepoint is found and
 	  not used at bootup.
 
+config TRACEPOINT_WARN_ON_UNUSED_BUILD
+	bool "Warn on build if a tracepoint is defined but not used"
+	depends on TRACEPOINTS
+	select TRACEPOINT_VERIFY_USED
+	help
+	  This option checks if every builtin defined tracepoint is
+	  used in the code. If a tracepoint is defined but not used,
+	  it will waste memory as its metadata is still created.
+	  This will cause a warning at build time if the architecture
+	  supports it.
+
 config FTRACE_SELFTEST
 	bool
 
scripts/Makefile +4 -0
index 46f860529df5..f81947ec9486 100644
@@ -42,6 +42,10 @@ HOSTCFLAGS_sorttable.o += -I$(srctree)/tools/arch/$(SRCARCH)/include
 HOSTCFLAGS_sorttable.o += -DUNWINDER_ORC_ENABLED
 endif
 
+ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
+HOSTCFLAGS_sorttable.o += -DPREL32_RELOCATIONS
+endif
+
 ifdef CONFIG_BUILDTIME_MCOUNT_SORT
 HOSTCFLAGS_sorttable.o += -DMCOUNT_SORT_ENABLED
 endif
scripts/sorttable.c +245 -23

342 lines not on this page · raw message

Signature · 1 line
2.47.2
#6 lore raw

PATCH v3 3/5 tracing: sorttable: Find unused tracepoints for arm64 that uses reloc for address

In reply to Steven Rostedt

From: Steven Rostedt <[email protected]>

The addresses in the ARM64 ELF file is stored in the RELA sections similar to the mcount location table. Add support to find the addresses from the RELA section to use to get the actual addresses for checking the tracepoints and the checking variables to show if all tracepoints are used.

---
 scripts/sorttable.c | 186 ++++++++++++++++++++++++++++----------------
 1 file changed, 118 insertions(+), 68 deletions(-)
scripts/sorttable.c +118 -68
index ddcbec22ca96..edca5b06d8ce 100644
@@ -578,6 +578,106 @@ static int compare_values_32(const void *a, const void *b)
 
 static int (*compare_values)(const void *a, const void *b);
 
+static char m_err[ERRSTR_MAXSZ];
+static long rela_type;
+static bool sort_reloc;
+static int reloc_shnum;
+
+/* Fill the array with the content of the relocs */
+static int fill_relocs(void *ptr, uint64_t size, Elf_Ehdr *ehdr, uint64_t start_loc)
+{
+	Elf_Shdr *shdr_start;
+	Elf_Rela *rel;
+	unsigned int shnum;
+	unsigned int count = 0;
+	int shentsize;
+	void *array_end = ptr + size;
+
+	shdr_start = (Elf_Shdr *)((char *)ehdr + ehdr_shoff(ehdr));
+	shentsize = ehdr_shentsize(ehdr);
+
+	shnum = ehdr_shnum(ehdr);
+	if (shnum == SHN_UNDEF)
+		shnum = shdr_size(shdr_start);
+
+	for (int i = 0; i < shnum; i++) {
+		Elf_Shdr *shdr = get_index(shdr_start, shentsize, i);
+		void *end;
+
+		if (shdr_type(shdr) != SHT_RELA)
+			continue;
+
+		reloc_shnum = i;
+
+		rel = (void *)ehdr + shdr_offset(shdr);
+		end = (void *)rel + shdr_size(shdr);
+
+		for (; (void *)rel < end; rel = (void *)rel + shdr_entsize(shdr)) {
+			uint64_t offset = rela_offset(rel);
+
+			if (offset >= start_loc && offset < start_loc + size) {
+				if (ptr + long_size > array_end) {
+					snprintf(m_err, ERRSTR_MAXSZ,
+						 "Too many relocations");
+					return -1;
+				}
+
+				/* Make sure this has the correct type */
+				if (rela_info(rel) != rela_type) {
+					snprintf(m_err, ERRSTR_MAXSZ,
+						"rela has type %lx but expected %lx\n",
+						(long)rela_info(rel), rela_type);
+					return -1;
+				}
+
+				if (long_size == 4)
+					*(uint32_t *)ptr = rela_addend(rel);
+				else
+					*(uint64_t *)ptr = rela_addend(rel);
+				ptr += long_size;
+				count++;
+			}
+		}
+	}
+	return count;
+}
+
+static uint64_t get_addr_reloc(Elf_Ehdr *ehdr, uint64_t addr)
+{
+	Elf_Shdr *shdr_start;
+	Elf_Shdr *shdr;
+	Elf_Rela *rel;
+	unsigned int shnum;
+	int shentsize;
+	void *end;
+
+	shdr_start = (Elf_Shdr *)((char *)ehdr + ehdr_shoff(ehdr));
+	shentsize = ehdr_shentsize(ehdr);
+
+	shnum = ehdr_shnum(ehdr);
+	if (shnum == SHN_UNDEF)
+		shnum = shdr_size(shdr_start);
+
+	shdr = get_index(shdr_start, shentsize, reloc_shnum);
+	if (shdr_type(shdr) != SHT_RELA)
+		return 0;
+
+	rel = (void *)ehdr + shdr_offset(shdr);
+	end = (void *)rel + shdr_size(shdr);
+
+	for (; (void *)rel < end; rel = (void *)rel + shdr_entsize(shdr)) {
+		uint64_t offset = rela_offset(rel);
+
+		if (offset == addr) {
+			if (long_size == 4)
+				return rela_addend(rel);
+			else
+				return rela_addend(rel);
+		}
+	}
+	return 0;
+}
+
 static int fill_addrs(void *ptr, uint64_t size, void *addrs)
 {
 	void *end = ptr + size;
@@ -696,11 +796,6 @@ static int parse_symbols(const char *fname)
 }
 
 static pthread_t mcount_sort_thread;
-static bool sort_reloc;
-
-static long rela_type;
-
-static char m_err[ERRSTR_MAXSZ];
 
 struct elf_mcount_loc {
 	Elf_Ehdr *ehdr;
@@ -708,63 +803,6 @@ struct elf_mcount_loc {
 	uint64_t stop_mcount_loc;
 };
 
-/* Fill the array with the content of the relocs */
-static int fill_relocs(void *ptr, uint64_t size, Elf_Ehdr *ehdr, uint64_t start_loc)
-{
-	Elf_Shdr *shdr_start;
-	Elf_Rela *rel;
-	unsigned int shnum;
-	unsigned int count = 0;
-	int shentsize;
-	void *array_end = ptr + size;
-
-	shdr_start = (Elf_Shdr *)((char *)ehdr + ehdr_shoff(ehdr));
-	shentsize = ehdr_shentsize(ehdr);
-
-	shnum = ehdr_shnum(ehdr);
-	if (shnum == SHN_UNDEF)
-		shnum = shdr_size(shdr_start);
-
-	for (int i = 0; i < shnum; i++) {
-		Elf_Shdr *shdr = get_index(shdr_start, shentsize, i);
-		void *end;
-
-		if (shdr_type(shdr) != SHT_RELA)
-			continue;
-
-		rel = (void *)ehdr + shdr_offset(shdr);
-		end = (void *)rel + shdr_size(shdr);
-
-		for (; (void *)rel < end; rel = (void *)rel + shdr_entsize(shdr)) {
-			uint64_t offset = rela_offset(rel);
-
-			if (offset >= start_loc && offset < start_loc + size) {
-				if (ptr + long_size > array_end) {
-					snprintf(m_err, ERRSTR_MAXSZ,
-						 "Too many relocations");
-					return -1;
-				}
-
-				/* Make sure this has the correct type */
-				if (rela_info(rel) != rela_type) {
-					snprintf(m_err, ERRSTR_MAXSZ,
-						"rela has type %lx but expected %lx\n",
-						(long)rela_info(rel), rela_type);
-					return -1;
-				}
-
-				if (long_size == 4)
-					*(uint32_t *)ptr = rela_addend(rel);
-				else
-					*(uint64_t *)ptr = rela_addend(rel);
-				ptr += long_size;
-				count++;
-			}
-		}
-	}
-	return count;
-}
-
 /* Put the sorted vals back into the relocation elements */
 static void replace_relocs(void *ptr, uint64_t size, Elf_Ehdr *ehdr, uint64_t start_loc)
 {
@@ -957,7 +995,15 @@ static void make_trace_array(struct elf_tracepoint *etrace)
 		return;
 	}
 
-	count = fill_addrs(vals, size, start);
+	if (sort_reloc) {
+		count = fill_relocs(vals, size, ehdr, etrace->start_tracepoint_check);
+		/* gcc may use relocs to save the addresses, but clang does not. */
+		if (!count) {
+			count = fill_addrs(vals, size, start);
+			sort_reloc = 0;
+		}
+	} else
+		count = fill_addrs(vals, size, start);
 
 	compare_values = long_size == 4 ? compare_values_32 : compare_values_64;
 	qsort(vals, count, long_size, compare_values);
@@ -1017,10 +1063,14 @@ static int failed_event(struct elf_tracepoint *etrace, uint64_t addr)
 	if (name_ptr > file_map_end)
 		goto bad_addr;
 
-	if (long_size == 4)
-		addr = r(name_ptr);
-	else
-		addr = r8(name_ptr);
+	if (sort_reloc) {
+		addr = get_addr_reloc(ehdr, addr);
+	} else {
+		if (long_size == 4)
+			addr = r(name_ptr);
+		else
+			addr = r8(name_ptr);
+	}
 
 	sec_addr = shdr_addr(ro_data_sec);
 	sec_offset = shdr_offset(ro_data_sec);
@@ -1473,9 +1523,9 @@ static int do_file(char const *const fname, void *addr)
 
 	switch (r2(&ehdr->e32.e_machine)) {
 	case EM_AARCH64:
-#ifdef MCOUNT_SORT_ENABLED
 		sort_reloc = true;
 		rela_type = 0x403;
+#ifdef MCOUNT_SORT_ENABLED
 		/* arm64 uses patchable function entry placing before function */
 		before_func = 8;
 #endif
Signature · 1 line
2.47.2
#7 lore raw

PATCH v3 4/5 tracepoint: Do not warn for unused event that is exported

In reply to Steven Rostedt

From: Steven Rostedt <[email protected]>

There are a few generic events that may only be used by modules. They are defined and then set with EXPORT_TRACEPOINT*(). Mark events that are exported as being used, even though they still waste memory in the kernel proper.

---
 include/linux/tracepoint.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
include/linux/tracepoint.h +4 -1
index 2b96c7e94c52..8026a0659580 100644
@@ -223,7 +223,8 @@ static inline struct tracepoint *tracepoint_ptr_deref(tracepoint_ptr_t *p)
 
 #ifdef CONFIG_TRACEPOINT_VERIFY_USED
 # define TRACEPOINT_CHECK(name)						\
-	static void __used __section("__tracepoint_check") *__trace_check = \
+	static void __used __section("__tracepoint_check") *		\
+	__trace_check_##name =						\
 		&__tracepoint_##name;
 #else
 # define TRACEPOINT_CHECK(name)
@@ -381,10 +382,12 @@ static inline struct tracepoint *tracepoint_ptr_deref(tracepoint_ptr_t *p)
 	__DEFINE_TRACE_EXT(_name, NULL, PARAMS(_proto), PARAMS(_args));
 
 #define EXPORT_TRACEPOINT_SYMBOL_GPL(name)				\
+	TRACEPOINT_CHECK(name)						\
 	EXPORT_SYMBOL_GPL(__tracepoint_##name);				\
 	EXPORT_SYMBOL_GPL(__traceiter_##name);				\
 	EXPORT_STATIC_CALL_GPL(tp_func_##name)
 #define EXPORT_TRACEPOINT_SYMBOL(name)					\
+	TRACEPOINT_CHECK(name)						\
 	EXPORT_SYMBOL(__tracepoint_##name);				\
 	EXPORT_SYMBOL(__traceiter_##name);				\
 	EXPORT_STATIC_CALL(tp_func_##name)
Signature · 1 line
2.47.2
#8 lore raw

PATCH v3 5/5 tracing: Call trace_ftrace_test_filter() for the event

In reply to Steven Rostedt

From: Steven Rostedt <[email protected]>

The trace event filter bootup self test tests a bunch of filter logic against the ftrace_test_filter event, but does not actually call the event. Work is being done to cause a warning if an event is defined but not used. To quiet the warning call the trace event under an if statement where it is disabled so it doesn't get optimized out.

---
 kernel/trace/trace_events_filter.c | 4 ++++
 1 file changed, 4 insertions(+)
kernel/trace/trace_events_filter.c +4 -0
index 3885aadc434d..e4581e10782b 100644
@@ -2900,6 +2900,10 @@ static __init int ftrace_test_event_filter(void)
 	if (i == DATA_CNT)
 		printk(KERN_CONT "OK\n");
 
+	/* Need to call ftrace_test_filter to prevent a warning */
+	if (!trace_ftrace_test_filter_enabled())
+		trace_ftrace_test_filter(1, 2, 3, 4, 5, 6, 7, 8);
+
 	return 0;
 }
 
Signature · 1 line
2.47.2
#2 lore raw

Re: [PATCH v3 1/5] tracepoints: Add verifier that makes sure all defined tracepoints are used

In reply to Steven Rostedt
Quoted 7 lines · Steven Rostedt

Add a verifier that injects a pointer to the tracepoint structure in the functions that are used and added to a section called __tracepoint_check. Then on boot up, iterate over this section and for every tracepoint descriptor that is pointed to, update its ".funcs" field to (void *)1, as the .funcs field is only set when a tracepoint is registered. At this time, no tracepoints should be registered.

Why?

Doing this at runtime seems completely bass-ackwards.

If you want to do this verification, why don't you do it at build-time?

Linus

#3 lore raw

Re: [PATCH v3 1/5] tracepoints: Add verifier that makes sure all defined tracepoints are used

Quoted 9 lines · On Tue, 22 Jul 2025 09:16:49 -0700 Linus Torvalds…
Quoted 7 lines · Steven Rostedt

Add a verifier that injects a pointer to the tracepoint structure in the functions that are used and added to a section called __tracepoint_check. Then on boot up, iterate over this section and for every tracepoint descriptor that is pointed to, update its ".funcs" field to (void *)1, as the .funcs field is only set when a tracepoint is registered. At this time, no tracepoints should be registered.

Quoted 5 lines

Why?

Doing this at runtime seems completely bass-ackwards.

If you want to do this verification, why don't you do it at build-time?

The second patch does that, but is much more complex due to having to parse the elf file. It hooks into the sorttable code as that already does most of the parsing that was needed. It uses the same trick as the runtime verifier by checking tracepoints against the __tracepoint_check section (but not with the '.func' test, but instead it sorts it and does a binary search).

I kept this to verify that the build time worked too, as the runtime check is so much simpler and easier to implement. Basically, I use this to verify that the build time works. That's why if you enable this it will select the build time version. It was used to catch bugs in the build version as I developed it.

And currently neither tests modules (I run this against an allyesconfig), but the runtime version could easily be modified to test modules too, whereas the build time would require adding another elf parser as the sorttable isn't run on module code.

I can remove the runtime check if you prefer.

-- Steve

#4 lore raw

Re: [PATCH v3 1/5] tracepoints: Add verifier that makes sure all defined tracepoints are used

Quoted 3 lines · Steven Rostedt

I kept this to verify that the build time worked too, as the runtime check is so much simpler and easier to implement.

Honestly, do it for your 8own private verification.

Don't sent out the patch and expect anybody else to care.

The static verification may make sense. Adding code to the kernel just to then do runtime verification does NOT.

This is not a "criticcal correctness" issue. This is a "help make people not waste memory pointlessly by having tracepoints that aren't used"

There is *NO* reason to add kernel code for this. Zero. Nada. None.

Linus