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

x86/vdso: Remove #ifdeffery around page setup variants

Replace the open-coded ifdefs in C sources files with IS_ENABLED().
This makes the code easier to read and enables the compiler to typecheck
also the disabled parts, before optimizing them away.
To make this work, also remove the ifdefs from declarations of used
variables.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Eric Biederman <ebiederm@xmission.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Kees Cook <kees@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rik van Riel <riel@surriel.com>
Link: https://lore.kernel.org/r/20240910-x86-vdso-ifdef-v1-1-877c9df9b081@linutronix.de

authored by

Thomas Weißschuh and committed by
Ingo Molnar
2ce8043b a33b5a08

+12 -31
+12 -19
arch/x86/entry/vdso/vma.c
··· 227 227 return map_vdso(image, addr); 228 228 } 229 229 230 - #if defined(CONFIG_X86_32) || defined(CONFIG_IA32_EMULATION) 231 230 static int load_vdso32(void) 232 231 { 233 232 if (vdso32_enabled != 1) /* Other values all mean "disabled" */ ··· 234 235 235 236 return map_vdso(&vdso_image_32, 0); 236 237 } 237 - #endif 238 238 239 - #ifdef CONFIG_X86_64 240 239 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp) 241 240 { 242 - if (!vdso64_enabled) 243 - return 0; 241 + if (IS_ENABLED(CONFIG_X86_64)) { 242 + if (!vdso64_enabled) 243 + return 0; 244 244 245 - return map_vdso(&vdso_image_64, 0); 245 + return map_vdso(&vdso_image_64, 0); 246 + } 247 + 248 + return load_vdso32(); 246 249 } 247 250 248 251 #ifdef CONFIG_COMPAT 249 252 int compat_arch_setup_additional_pages(struct linux_binprm *bprm, 250 253 int uses_interp, bool x32) 251 254 { 252 - #ifdef CONFIG_X86_X32_ABI 253 - if (x32) { 255 + if (IS_ENABLED(CONFIG_X86_X32_ABI) && x32) { 254 256 if (!vdso64_enabled) 255 257 return 0; 256 258 return map_vdso(&vdso_image_x32, 0); 257 259 } 258 - #endif 259 - #ifdef CONFIG_IA32_EMULATION 260 - return load_vdso32(); 261 - #else 260 + 261 + if (IS_ENABLED(CONFIG_IA32_EMULATION)) 262 + return load_vdso32(); 263 + 262 264 return 0; 263 - #endif 264 - } 265 - #endif 266 - #else 267 - int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp) 268 - { 269 - return load_vdso32(); 270 265 } 271 266 #endif 272 267
-4
arch/x86/include/asm/elf.h
··· 76 76 77 77 #include <asm/vdso.h> 78 78 79 - #ifdef CONFIG_X86_64 80 79 extern unsigned int vdso64_enabled; 81 - #endif 82 - #if defined(CONFIG_X86_32) || defined(CONFIG_IA32_EMULATION) 83 80 extern unsigned int vdso32_enabled; 84 - #endif 85 81 86 82 /* 87 83 * This is used to ensure we don't load something for the wrong architecture.
-8
arch/x86/include/asm/vdso.h
··· 27 27 long sym_vdso32_rt_sigreturn_landing_pad; 28 28 }; 29 29 30 - #ifdef CONFIG_X86_64 31 30 extern const struct vdso_image vdso_image_64; 32 - #endif 33 - 34 - #ifdef CONFIG_X86_X32_ABI 35 31 extern const struct vdso_image vdso_image_x32; 36 - #endif 37 - 38 - #if defined CONFIG_X86_32 || defined CONFIG_COMPAT 39 32 extern const struct vdso_image vdso_image_32; 40 - #endif 41 33 42 34 extern int __init init_vdso_image(const struct vdso_image *image); 43 35