Skip to contentSkip to conversation

kernel: trace: do not generate undefsyms_base.c

PATCH In review Paolo Bonzini 4 participants 6 messages Apr 21

Subsystems (2)
lore
Share & tools
lore

Paolo Bonzini

author maintainer
#0 lore raw

PATCH 1/1 kernel: trace: do not generate undefsyms_base.c

The code to autogenerate undefsyms_base.c in the Makefile is larger than the file itself.

Remove the "echo" indirection that creates the file, which keeps the build system sane and makes it much easier to edit it if/when new situations arrive.

---
 kernel/trace/.gitignore       |  1 -
 kernel/trace/Makefile         | 35 ++++-------------------------------
 kernel/trace/undefsyms_base.c | 28 ++++++++++++++++++++++++++++
 3 files changed, 32 insertions(+), 32 deletions(-)
 delete mode 100644 kernel/trace/.gitignore
 create mode 100644 kernel/trace/undefsyms_base.c
kernel/trace/.gitignore deleted +0 -1
deleted file mode 100644
index 6adbb09d6deb..000000000000
@@ -1 +0,0 @@
-/undefsyms_base.c
kernel/trace/Makefile +4 -31
index 4d4229e5eec4..1decdce8cbef 100644
@@ -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 \
kernel/trace/undefsyms_base.c new file +28 -0
new file mode 100644
index 000000000000..e65baf58e6ff
@@ -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);
+}
Signature · 1 line
2.53.0
maintainer
#1 lore raw
Quoted 9 lines · On Tue, 21 Apr 2026 11:04:55 +0100 Paolo Bonzini <[email protected]> wrote:

The code to autogenerate undefsyms_base.c in the Makefile is larger than the file itself.

Remove the "echo" indirection that creates the file, which keeps the build system sane and makes it much easier to edit it if/when new situations arrive.

Marc beat you to it by a few minutes ;-)

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

Although he didn't Cc [email protected] :-p

But anyway, it ended up in my internal Patchwork. I'll take his as they are both pretty much the same patch.

Thanks,

-- Steve

#2 lore raw
Quoted 14 lines · Steven Rostedt
Quoted 9 lines · On Tue, 21 Apr 2026 11:04:55 +0100 Paolo Bonzini <[email protected]> wrote:

The code to autogenerate undefsyms_base.c in the Makefile is larger than the file itself.

Remove the "echo" indirection that creates the file, which keeps the build system sane and makes it much easier to edit it if/when new situations arrive.

Quoted 8 lines

Marc beat you to it by a few minutes ;-)

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

Although he didn't Cc [email protected] :-p

But anyway, it ended up in my internal Patchwork. I'll take his as they are both pretty much the same patch.

On the other hand, Paolo's patch has the SPDX tag on the new file, which I forgot to add. Your call, anyway.

Thanks,

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
author maintainer
#3 lore raw
Quoted 5 lines · Marc Zyngier
Quoted 4 lines · Steven Rostedt

Marc beat you to it by a few minutes ;-)

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

Quoted 7 lines
Quoted 4 lines

Although he didn't Cc [email protected] :-p

But anyway, it ended up in my internal Patchwork. I'll take his as they are both pretty much the same patch.

On the other hand, Paolo's patch has the SPDX tag on the new file, which I forgot to add. Your call, anyway.

Yeah if you want to get the best of both worlds, take the commit message from Marc's and the code from mine; he has more complete trailers whereas I have slightly cleaner formatting and more comments. But otherwise it's not a big deal.

Paolo

maintainer
#4 lore raw
Quoted 6 lines · On Tue, 21 Apr 2026 15:21:19 +0100 Paolo Bonzini <[email protected]> wrote:
Quoted 5 lines · Marc Zyngier
Quoted 4 lines · Steven Rostedt

Marc beat you to it by a few minutes ;-)

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

Quoted 7 lines
Quoted 7 lines
Quoted 4 lines

Although he didn't Cc [email protected] :-p

But anyway, it ended up in my internal Patchwork. I'll take his as they are both pretty much the same patch.

On the other hand, Paolo's patch has the SPDX tag on the new file, which I forgot to add. Your call, anyway.

Ah, OK. I'll take Paolo's.

Quoted 5 lines

Yeah if you want to get the best of both worlds, take the commit message from Marc's and the code from mine; he has more complete trailers whereas I have slightly cleaner formatting and more comments. But otherwise it's not a big deal.

I'll update the subject and change log slightly, but otherwise, it's your patch.

-- Steve

Reviewed-by Tested-by on v1 1/1
#5 lore raw
In reply to Paolo Bonzini
Quoted 9 lines · Paolo Bonzini

The code to autogenerate undefsyms_base.c in the Makefile is larger than the file itself.

Remove the "echo" indirection that creates the file, which keeps the build system sane and makes it much easier to edit it if/when new situations arrive.

Yeah, I don't really know how I did not see this originally :/ tunnel vision is real I suppose.

Quoted 102 lines
---
 kernel/trace/.gitignore       |  1 -
 kernel/trace/Makefile         | 35 ++++-------------------------------
 kernel/trace/undefsyms_base.c | 28 ++++++++++++++++++++++++++++
 3 files changed, 32 insertions(+), 32 deletions(-)
 delete mode 100644 kernel/trace/.gitignore
 create mode 100644 kernel/trace/undefsyms_base.c
kernel/trace/.gitignore deleted +0 -1
deleted file mode 100644
index 6adbb09d6deb..000000000000
@@ -1 +0,0 @@
-/undefsyms_base.c
kernel/trace/Makefile +4 -31
index 4d4229e5eec4..1decdce8cbef 100644
@@ -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 \
kernel/trace/undefsyms_base.c new file +28 -0
new file mode 100644
index 000000000000..e65baf58e6ff
@@ -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);
+}
Signature · 1 line
2.53.0