public inbox for linux-trace-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tracing: Generate undef symbols allowlist for simple_ring_buffer
@ 2026-03-12 18:20 Vincent Donnefort
  2026-03-12 18:43 ` Steven Rostedt
  2026-03-12 23:51 ` Nathan Chancellor
  0 siblings, 2 replies; 4+ messages in thread
From: Vincent Donnefort @ 2026-03-12 18:20 UTC (permalink / raw)
  To: maz
  Cc: rostedt, arnd, nathan, linux-trace-kernel, kvmarm, kernel-team,
	Vincent Donnefort

Compiler and tooling-generated symbols are difficult to maintain
across all supported architectures. Make the allowlist more robust by
replacing the harcoded list with a mechanism that automatically detects
these symbols.

This mechanism generates a C function designed to trigger common
compiler-inserted symbols.

Signed-off-by: Vincent Donnefort <vdonnefort@google.com>

diff --git a/kernel/trace/Makefile b/kernel/trace/Makefile
index beb15936829d..3b427b76434a 100644
--- a/kernel/trace/Makefile
+++ b/kernel/trace/Makefile
@@ -136,17 +136,37 @@ obj-$(CONFIG_TRACE_REMOTE_TEST) += remote_test.o
 # simple_ring_buffer is used by the pKVM hypervisor which does not have access
 # to all kernel symbols. Fail the build if forbidden symbols are found.
 #
-UNDEFINED_ALLOWLIST := memset alt_cb_patch_nops __x86 __ubsan __asan __kasan __gcov __aeabi_unwind
-UNDEFINED_ALLOWLIST += __stack_chk_fail stackleak_track_stack __ref_stack __sanitizer llvm_gcda llvm_gcov
-UNDEFINED_ALLOWLIST += .TOC\. __clear_pages_unrolled __memmove copy_page warn_slowpath_fmt
-UNDEFINED_ALLOWLIST += ftrace_likely_update __hwasan_load __hwasan_store __hwasan_tag_memory
-UNDEFINED_ALLOWLIST += warn_bogus_irq_restore __stack_chk_guard
-UNDEFINED_ALLOWLIST := $(addprefix -e , $(UNDEFINED_ALLOWLIST))
+# undefsyms_base generates a set of compiler and tooling-generated symbols that can
+# safely be ignored for simple_ring_buffer.
+#
+$(obj)/undefsyms_base.c: FORCE
+	$(Q)echo '#include <asm/page.h>' > $@
+	$(Q)echo '#include <asm/local.h>' >> $@
+	$(Q)echo 'static char page[PAGE_SIZE] __aligned(PAGE_SIZE);' >> $@
+	$(Q)echo 'void undefsyms_base(int n);' >> $@
+	$(Q)echo 'void undefsyms_base(int n) {' >> $@
+	$(Q)echo '	char buffer[256] = { 0 };' >> $@
+	$(Q)echo '	u32 u = 0;' >> $@
+	$(Q)echo '	memset((char * volatile)page, 8, PAGE_SIZE);' >> $@
+	$(Q)echo '	memset((char * volatile)buffer, 8, sizeof(buffer));' >> $@
+	$(Q)echo '	cmpxchg((u32 * volatile)&u, 0, 8);' >> $@
+	$(Q)echo '	WARN_ON(n == 0xdeadbeef);' >> $@
+	$(Q)echo '}' >> $@
+
+clean-files += undefsyms_base.c
+targets += undefsyms_base.c
+
+$(obj)/undefsyms_base.o: $(obj)/undefsyms_base.c
+
+extra-y += undefsyms_base.o
+
+UNDEFINED_ALLOWLIST = __asan __gcov __kasan __kcsan __hwasan __sanitizer __tsan __ubsan __x86_indirect_thunk \
+		       $(shell $(NM) -u $(obj)/undefsyms_base.o 2>/dev/null | awk '{print $$2}')
 
 quiet_cmd_check_undefined = NM      $<
-      cmd_check_undefined = test -z "`$(NM) -u $< | grep -v $(UNDEFINED_ALLOWLIST)`"
+      cmd_check_undefined = test -z "`$(NM) -u $< | grep -v $(addprefix -e ,$(UNDEFINED_ALLOWLIST))`"
 
-$(obj)/%.o.checked: $(obj)/%.o FORCE
+$(obj)/%.o.checked: $(obj)/%.o $(obj)/undefsyms_base.o FORCE
 	$(call if_changed,check_undefined)
 
 always-$(CONFIG_SIMPLE_RING_BUFFER) += simple_ring_buffer.o.checked

base-commit: 33f2e266515717c4b2df585dadefa0525557726c
-- 
2.53.0.851.ga537e3e6e9-goog


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-03-13 10:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-12 18:20 [PATCH] tracing: Generate undef symbols allowlist for simple_ring_buffer Vincent Donnefort
2026-03-12 18:43 ` Steven Rostedt
2026-03-12 23:51 ` Nathan Chancellor
2026-03-13 10:23   ` Vincent Donnefort

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox