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.

powerpc: Add static_key_feature_checks_initialized flag

JUMP_LABEL_FEATURE_CHECK_DEBUG used static_key_intialized to determine
whether {cpu,mmu}_has_feature() is used before static keys were
initialized. However, {cpu,mmu}_has_feature() should not be used before
setup_feature_keys() is called but static_key_initialized is set well
before this by the call to jump_label_init() in early_init_devtree().
This creates a window in which JUMP_LABEL_FEATURE_CHECK_DEBUG will not
detect misuse and report errors. Add a flag specifically to indicate
when {cpu,mmu}_has_feature() is safe to use.

Signed-off-by: Nicholas Miehlbradt <nicholas@linux.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://msgid.link/20240408052358.5030-1-nicholas@linux.ibm.com

authored by

Nicholas Miehlbradt and committed by
Michael Ellerman
676b2f99 676abf7c

+12 -2
+1 -1
arch/powerpc/include/asm/cpu_has_feature.h
··· 29 29 #endif 30 30 31 31 #ifdef CONFIG_JUMP_LABEL_FEATURE_CHECK_DEBUG 32 - if (!static_key_initialized) { 32 + if (!static_key_feature_checks_initialized) { 33 33 printk("Warning! cpu_has_feature() used prior to jump label init!\n"); 34 34 dump_stack(); 35 35 return early_cpu_has_feature(feature);
+2
arch/powerpc/include/asm/feature-fixups.h
··· 291 291 extern long __start___barrier_nospec_fixup, __stop___barrier_nospec_fixup; 292 292 extern long __start__btb_flush_fixup, __stop__btb_flush_fixup; 293 293 294 + extern bool static_key_feature_checks_initialized; 295 + 294 296 void apply_feature_fixups(void); 295 297 void update_mmu_feature_fixups(unsigned long mask); 296 298 void setup_feature_keys(void);
+1 -1
arch/powerpc/include/asm/mmu.h
··· 251 251 #endif 252 252 253 253 #ifdef CONFIG_JUMP_LABEL_FEATURE_CHECK_DEBUG 254 - if (!static_key_initialized) { 254 + if (!static_key_feature_checks_initialized) { 255 255 printk("Warning! mmu_has_feature() used prior to jump label init!\n"); 256 256 dump_stack(); 257 257 return early_mmu_has_feature(feature);
+8
arch/powerpc/lib/feature-fixups.c
··· 25 25 #include <asm/firmware.h> 26 26 #include <asm/inst.h> 27 27 28 + /* 29 + * Used to generate warnings if mmu or cpu feature check functions that 30 + * use static keys before they are initialized. 31 + */ 32 + bool static_key_feature_checks_initialized __read_mostly; 33 + EXPORT_SYMBOL_GPL(static_key_feature_checks_initialized); 34 + 28 35 struct fixup_entry { 29 36 unsigned long mask; 30 37 unsigned long value; ··· 686 679 jump_label_init(); 687 680 cpu_feature_keys_init(); 688 681 mmu_feature_keys_init(); 682 + static_key_feature_checks_initialized = true; 689 683 } 690 684 691 685 static int __init check_features(void)