Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

tracing: Generate undef symbols allowlist for simple_ring_buffer

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>
Reviewed-by: Nathan Chancellor <nathan@kernel.org>
Tested-by: Nathan Chancellor <nathan@kernel.org>
Acked-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Tested-by: Arnd Bergmann <arnd@arndb.de>
Link: https://patch.msgid.link/20260316092845.3367411-1-vdonnefort@google.com
[maz: added __msan prefix to allowlist as pointed out by Arnd]
Signed-off-by: Marc Zyngier <maz@kernel.org>

authored by

Vincent Donnefort and committed by
Marc Zyngier
1211907a 9e5dd49d

+38 -8
+38 -8
kernel/trace/Makefile
··· 136 136 # simple_ring_buffer is used by the pKVM hypervisor which does not have access 137 137 # to all kernel symbols. Fail the build if forbidden symbols are found. 138 138 # 139 - UNDEFINED_ALLOWLIST := memset alt_cb_patch_nops __x86 __ubsan __asan __kasan __gcov __aeabi_unwind 140 - UNDEFINED_ALLOWLIST += __stack_chk_fail stackleak_track_stack __ref_stack __sanitizer llvm_gcda llvm_gcov 141 - UNDEFINED_ALLOWLIST += .TOC\. __clear_pages_unrolled __memmove copy_page warn_slowpath_fmt 142 - UNDEFINED_ALLOWLIST += ftrace_likely_update __hwasan_load __hwasan_store __hwasan_tag_memory 143 - UNDEFINED_ALLOWLIST += warn_bogus_irq_restore __stack_chk_guard 144 - UNDEFINED_ALLOWLIST := $(addprefix -e , $(UNDEFINED_ALLOWLIST)) 139 + # undefsyms_base generates a set of compiler and tooling-generated symbols that can 140 + # safely be ignored for simple_ring_buffer. 141 + # 142 + filechk_undefsyms_base = \ 143 + echo '$(pound)include <linux/atomic.h>'; \ 144 + echo '$(pound)include <linux/string.h>'; \ 145 + echo '$(pound)include <asm/page.h>'; \ 146 + echo 'static char page[PAGE_SIZE] __aligned(PAGE_SIZE);'; \ 147 + echo 'void undefsyms_base(void *p, int n);'; \ 148 + echo 'void undefsyms_base(void *p, int n) {'; \ 149 + echo ' char buffer[256] = { 0 };'; \ 150 + echo ' u32 u = 0;'; \ 151 + echo ' memset((char * volatile)page, 8, PAGE_SIZE);'; \ 152 + echo ' memset((char * volatile)buffer, 8, sizeof(buffer));'; \ 153 + echo ' memcpy((void * volatile)p, buffer, sizeof(buffer));'; \ 154 + echo ' cmpxchg((u32 * volatile)&u, 0, 8);'; \ 155 + echo ' WARN_ON(n == 0xdeadbeef);'; \ 156 + echo '}' 157 + 158 + $(obj)/undefsyms_base.c: FORCE 159 + $(call filechk,undefsyms_base) 160 + 161 + clean-files += undefsyms_base.c 162 + 163 + $(obj)/undefsyms_base.o: $(obj)/undefsyms_base.c 164 + 165 + targets += undefsyms_base.o 166 + 167 + # Ensure KASAN is enabled to avoid logic that may disable FORTIFY_SOURCE when 168 + # KASAN is not enabled. undefsyms_base.o does not automatically get KASAN flags 169 + # because it is not linked into vmlinux. 170 + KASAN_SANITIZE_undefsyms_base.o := y 171 + 172 + UNDEFINED_ALLOWLIST = __asan __gcov __kasan __kcsan __hwasan __sancov __sanitizer __tsan __ubsan __x86_indirect_thunk \ 173 + __msan simple_ring_buffer \ 174 + $(shell $(NM) -u $(obj)/undefsyms_base.o 2>/dev/null | awk '{print $$2}') 145 175 146 176 quiet_cmd_check_undefined = NM $< 147 - cmd_check_undefined = test -z "`$(NM) -u $< | grep -v $(UNDEFINED_ALLOWLIST)`" 177 + cmd_check_undefined = test -z "`$(NM) -u $< | grep -v $(addprefix -e , $(UNDEFINED_ALLOWLIST))`" 148 178 149 - $(obj)/%.o.checked: $(obj)/%.o FORCE 179 + $(obj)/%.o.checked: $(obj)/%.o $(obj)/undefsyms_base.o FORCE 150 180 $(call if_changed,check_undefined) 151 181 152 182 always-$(CONFIG_SIMPLE_RING_BUFFER) += simple_ring_buffer.o.checked