Skip to content

Commit 5335e31

Browse files
bonzinirostedt
authored andcommitted
tracing: Make undefsyms_base.c a first-class citizen
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>
1 parent b4e0758 commit 5335e31

3 files changed

Lines changed: 32 additions & 32 deletions

File tree

kernel/trace/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

kernel/trace/Makefile

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -133,41 +133,14 @@ obj-$(CONFIG_TRACE_REMOTE) += trace_remote.o
133133
obj-$(CONFIG_SIMPLE_RING_BUFFER) += simple_ring_buffer.o
134134
obj-$(CONFIG_TRACE_REMOTE_TEST) += remote_test.o
135135

136-
#
137136
# simple_ring_buffer is used by the pKVM hypervisor which does not have access
138137
# to all kernel symbols. Fail the build if forbidden symbols are found.
139-
#
140-
# undefsyms_base generates a set of compiler and tooling-generated symbols that can
141-
# safely be ignored for simple_ring_buffer.
142-
#
143-
filechk_undefsyms_base = \
144-
echo '$(pound)include <linux/atomic.h>'; \
145-
echo '$(pound)include <linux/string.h>'; \
146-
echo '$(pound)include <asm/page.h>'; \
147-
echo 'static char page[PAGE_SIZE] __aligned(PAGE_SIZE);'; \
148-
echo 'void undefsyms_base(void *p, int n);'; \
149-
echo 'void undefsyms_base(void *p, int n) {'; \
150-
echo ' char buffer[256] = { 0 };'; \
151-
echo ' u32 u = 0;'; \
152-
echo ' memset((char * volatile)page, 8, PAGE_SIZE);'; \
153-
echo ' memset((char * volatile)buffer, 8, sizeof(buffer));'; \
154-
echo ' memcpy((void * volatile)p, buffer, sizeof(buffer));'; \
155-
echo ' cmpxchg((u32 * volatile)&u, 0, 8);'; \
156-
echo ' WARN_ON(n == 0xdeadbeef);'; \
157-
echo '}'
158-
159-
$(obj)/undefsyms_base.c: FORCE
160-
$(call filechk,undefsyms_base)
161-
162-
clean-files += undefsyms_base.c
163-
164-
$(obj)/undefsyms_base.o: $(obj)/undefsyms_base.c
165138

139+
# Basic compiler and tooling-generated symbols that can safely be left
140+
# undefined. Ensure KASAN is enabled to avoid logic that may disable
141+
# FORTIFY_SOURCE when KASAN is not enabled. undefsyms_base.o does not
142+
# automatically get KASAN flags because it is not linked into vmlinux.
166143
targets += undefsyms_base.o
167-
168-
# Ensure KASAN is enabled to avoid logic that may disable FORTIFY_SOURCE when
169-
# KASAN is not enabled. undefsyms_base.o does not automatically get KASAN flags
170-
# because it is not linked into vmlinux.
171144
KASAN_SANITIZE_undefsyms_base.o := y
172145

173146
UNDEFINED_ALLOWLIST = __asan __gcov __kasan __kcsan __hwasan __sancov __sanitizer __tsan __ubsan __x86_indirect_thunk \

kernel/trace/undefsyms_base.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
3+
/*
4+
* simple_ring_buffer is used by the pKVM hypervisor which does not have access
5+
* to all kernel symbols. Whatever is undefined when compiling this file is
6+
* compiler and tooling-generated symbols that can safely be ignored for
7+
* simple_ring_buffer.
8+
*/
9+
10+
#include <linux/atomic.h>
11+
#include <linux/string.h>
12+
#include <asm/page.h>
13+
14+
void undefsyms_base(void *p, int n);
15+
16+
static char page[PAGE_SIZE] __aligned(PAGE_SIZE);
17+
18+
void undefsyms_base(void *p, int n)
19+
{
20+
char buffer[256] = { 0 };
21+
22+
u32 u = 0;
23+
memset((char * volatile)page, 8, PAGE_SIZE);
24+
memset((char * volatile)buffer, 8, sizeof(buffer));
25+
memcpy((void * volatile)p, buffer, sizeof(buffer));
26+
cmpxchg((u32 * volatile)&u, 0, 8);
27+
WARN_ON(n == 0xdeadbeef);
28+
}

0 commit comments

Comments
 (0)