[PATCH] kernel: trace: do not generate undefsyms_base.c

Paolo Bonzini posted 1 patch 1 month, 3 weeks ago
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
[PATCH] kernel: trace: do not generate undefsyms_base.c
Posted by Paolo Bonzini 1 month, 3 weeks ago
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.

Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 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

diff --git a/kernel/trace/.gitignore b/kernel/trace/.gitignore
deleted file mode 100644
index 6adbb09d6deb..000000000000
--- a/kernel/trace/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-/undefsyms_base.c
diff --git a/kernel/trace/Makefile b/kernel/trace/Makefile
index 4d4229e5eec4..1decdce8cbef 100644
--- a/kernel/trace/Makefile
+++ b/kernel/trace/Makefile
@@ -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
index 000000000000..e65baf58e6ff
--- /dev/null
+++ b/kernel/trace/undefsyms_base.c
@@ -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);
+}
-- 
2.53.0
Re: [PATCH] kernel: trace: do not generate undefsyms_base.c
Posted by Nathan Chancellor 1 month, 3 weeks ago
On Tue, Apr 21, 2026 at 11:04:55AM +0100, Paolo Bonzini 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.
> 
> Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

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

Reviewed-by: Nathan Chancellor <nathan@kernel.org>
Tested-by: Nathan Chancellor <nathan@kernel.org>

> ---
>  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
> 
> diff --git a/kernel/trace/.gitignore b/kernel/trace/.gitignore
> deleted file mode 100644
> index 6adbb09d6deb..000000000000
> --- a/kernel/trace/.gitignore
> +++ /dev/null
> @@ -1 +0,0 @@
> -/undefsyms_base.c
> diff --git a/kernel/trace/Makefile b/kernel/trace/Makefile
> index 4d4229e5eec4..1decdce8cbef 100644
> --- a/kernel/trace/Makefile
> +++ b/kernel/trace/Makefile
> @@ -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
> index 000000000000..e65baf58e6ff
> --- /dev/null
> +++ b/kernel/trace/undefsyms_base.c
> @@ -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);
> +}
> -- 
> 2.53.0
>
Re: [PATCH] kernel: trace: do not generate undefsyms_base.c
Posted by Steven Rostedt 1 month, 3 weeks ago
On Tue, 21 Apr 2026 11:04:55 +0100
Paolo Bonzini <pbonzini@redhat.com> 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.
> 
> Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

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

  https://lore.kernel.org/all/20260421095446.2951646-1-maz@kernel.org/

Although he didn't Cc linux-trace-kernel@vger.kernel.org :-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
Re: [PATCH] kernel: trace: do not generate undefsyms_base.c
Posted by Marc Zyngier 1 month, 3 weeks ago
On Tue, 21 Apr 2026 15:02:09 +0100,
Steven Rostedt <rostedt@goodmis.org> wrote:
> 
> On Tue, 21 Apr 2026 11:04:55 +0100
> Paolo Bonzini <pbonzini@redhat.com> 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.
> > 
> > Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
> > Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> 
> Marc beat you to it by a few minutes ;-)
> 
>   https://lore.kernel.org/all/20260421095446.2951646-1-maz@kernel.org/
> 
> Although he didn't Cc linux-trace-kernel@vger.kernel.org :-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.

-- 
Without deviation from the norm, progress is not possible.
Re: [PATCH] kernel: trace: do not generate undefsyms_base.c
Posted by Paolo Bonzini 1 month, 3 weeks ago
On Tue, Apr 21, 2026 at 3:18 PM Marc Zyngier <maz@kernel.org> wrote:
> On Tue, 21 Apr 2026 15:02:09 +0100, Steven Rostedt <rostedt@goodmis.org> wrote:
> > Marc beat you to it by a few minutes ;-)
> >
> >   https://lore.kernel.org/all/20260421095446.2951646-1-maz@kernel.org/
> >
> > Although he didn't Cc linux-trace-kernel@vger.kernel.org :-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
Re: [PATCH] kernel: trace: do not generate undefsyms_base.c
Posted by Steven Rostedt 1 month, 3 weeks ago
On Tue, 21 Apr 2026 15:21:19 +0100
Paolo Bonzini <pbonzini@redhat.com> wrote:

> On Tue, Apr 21, 2026 at 3:18 PM Marc Zyngier <maz@kernel.org> wrote:
> > On Tue, 21 Apr 2026 15:02:09 +0100, Steven Rostedt <rostedt@goodmis.org> wrote:  
> > > Marc beat you to it by a few minutes ;-)
> > >
> > >   https://lore.kernel.org/all/20260421095446.2951646-1-maz@kernel.org/
> > >
> > > Although he didn't Cc linux-trace-kernel@vger.kernel.org :-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.

> 
> 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