]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
tracing: Make undefsyms_base.c a first-class citizen
authorPaolo Bonzini <pbonzini@redhat.com>
Tue, 21 Apr 2026 10:04:55 +0000 (11:04 +0100)
committerSteven Rostedt <rostedt@goodmis.org>
Wed, 22 Apr 2026 15:24:41 +0000 (11:24 -0400)
Linus points out that dumping undefsyms_base.c form the Makefile
is rather ugly, and that a much better course of action would be
to have this file as a first-class citizen in the git tree.

This allows some extra cleanup in the Makefile, and the removal of
the .gitignore file in kernel/trace.

Cc: Marc Zyngier <maz@kernel.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Link: https://lore.kernel.org/r/CAHk-=wieqGd_XKpu8UxDoyADZx8TDe8CF3RmkUXt5N_9t5Pf_w@mail.gmail.com
Link: https://lore.kernel.org/all/20260421095446.2951646-1-maz@kernel.org/
Link: https://patch.msgid.link/20260421100455.324333-1-pbonzini@redhat.com
Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Reviewed-by: Nathan Chancellor <nathan@kernel.org>
Tested-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
kernel/trace/.gitignore [deleted file]
kernel/trace/Makefile
kernel/trace/undefsyms_base.c [new file with mode: 0644]

diff --git a/kernel/trace/.gitignore b/kernel/trace/.gitignore
deleted file mode 100644 (file)
index 6adbb09..0000000
+++ /dev/null
@@ -1 +0,0 @@
-/undefsyms_base.c
index 4d4229e5eec4bc5ceea8b5c4740ebf0c60043626..1decdce8cbef254ea3822c3aa0cdee0fa825be14 100644 (file)
@@ -133,41 +133,14 @@ obj-$(CONFIG_TRACE_REMOTE) += trace_remote.o
 obj-$(CONFIG_SIMPLE_RING_BUFFER) += simple_ring_buffer.o
 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.
-#
-# undefsyms_base generates a set of compiler and tooling-generated symbols that can
-# safely be ignored for simple_ring_buffer.
-#
-filechk_undefsyms_base = \
-       echo '$(pound)include <linux/atomic.h>'; \
-       echo '$(pound)include <linux/string.h>'; \
-       echo '$(pound)include <asm/page.h>'; \
-       echo 'static char page[PAGE_SIZE] __aligned(PAGE_SIZE);'; \
-       echo 'void undefsyms_base(void *p, int n);'; \
-       echo 'void undefsyms_base(void *p, int n) {'; \
-       echo '  char buffer[256] = { 0 };'; \
-       echo '  u32 u = 0;'; \
-       echo '  memset((char * volatile)page, 8, PAGE_SIZE);'; \
-       echo '  memset((char * volatile)buffer, 8, sizeof(buffer));'; \
-       echo '  memcpy((void * volatile)p, buffer, sizeof(buffer));'; \
-       echo '  cmpxchg((u32 * volatile)&u, 0, 8);'; \
-       echo '  WARN_ON(n == 0xdeadbeef);'; \
-       echo '}'
-
-$(obj)/undefsyms_base.c: FORCE
-       $(call filechk,undefsyms_base)
-
-clean-files += undefsyms_base.c
-
-$(obj)/undefsyms_base.o: $(obj)/undefsyms_base.c
 
+# Basic compiler and tooling-generated symbols that can safely be left
+# undefined. Ensure KASAN is enabled to avoid logic that may disable
+# FORTIFY_SOURCE when KASAN is not enabled. undefsyms_base.o does not
+# automatically get KASAN flags because it is not linked into vmlinux.
 targets += undefsyms_base.o
-
-# Ensure KASAN is enabled to avoid logic that may disable FORTIFY_SOURCE when
-# KASAN is not enabled. undefsyms_base.o does not automatically get KASAN flags
-# because it is not linked into vmlinux.
 KASAN_SANITIZE_undefsyms_base.o := y
 
 UNDEFINED_ALLOWLIST = __asan __gcov __kasan __kcsan __hwasan __sancov __sanitizer __tsan __ubsan __x86_indirect_thunk \
diff --git a/kernel/trace/undefsyms_base.c b/kernel/trace/undefsyms_base.c
new file mode 100644 (file)
index 0000000..e65baf5
--- /dev/null
@@ -0,0 +1,28 @@
+// SPDX-License-Identifier: GPL-2.0
+
+/*
+ * simple_ring_buffer is used by the pKVM hypervisor which does not have access
+ * to all kernel symbols.  Whatever is undefined when compiling this file is
+ * compiler and tooling-generated symbols that can safely be ignored for
+ * simple_ring_buffer.
+ */
+
+#include <linux/atomic.h>
+#include <linux/string.h>
+#include <asm/page.h>
+
+void undefsyms_base(void *p, int n);
+
+static char page[PAGE_SIZE] __aligned(PAGE_SIZE);
+
+void undefsyms_base(void *p, int n)
+{
+       char buffer[256] = { 0 };
+
+       u32 u = 0;
+       memset((char * volatile)page, 8, PAGE_SIZE);
+       memset((char * volatile)buffer, 8, sizeof(buffer));
+       memcpy((void * volatile)p, buffer, sizeof(buffer));
+       cmpxchg((u32 * volatile)&u, 0, 8);
+       WARN_ON(n == 0xdeadbeef);
+}