Skip to content

Commit c812c7d

Browse files
kvaneeshmpe
authored andcommitted
powerpc/mm: Catch usage of cpu/mmu_has_feature() before jump label init
This allows us to catch incorrect usage of cpu_has_feature() and mmu_has_feature() prior to jump labels being initialised. mpe: Use printk() and dump_stack() rather than WARN_ON(), because WARN_ON() may not work this early in boot. Rename the Kconfig. Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
1 parent c12e6f2 commit c812c7d

3 files changed

Lines changed: 26 additions & 0 deletions

File tree

‎arch/powerpc/Kconfig.debug‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ config JUMP_LABEL_FEATURE_CHECKS
6969
feature checks. This should generate more optimal code for those
7070
checks.
7171

72+
config JUMP_LABEL_FEATURE_CHECK_DEBUG
73+
bool "Do extra check on feature fixup calls"
74+
depends on DEBUG_KERNEL && JUMP_LABEL_FEATURE_CHECKS
75+
default n
76+
help
77+
This tries to catch incorrect usage of cpu_has_feature() and
78+
mmu_has_feature() in the code.
79+
80+
If you don't know what this means, say N.
81+
7282
config FTR_FIXUP_SELFTEST
7383
bool "Run self-tests of the feature-fixup code"
7484
depends on DEBUG_KERNEL

‎arch/powerpc/include/asm/cpu_has_feature.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ static __always_inline bool cpu_has_feature(unsigned long feature)
2525

2626
BUILD_BUG_ON(!__builtin_constant_p(feature));
2727

28+
#ifdef CONFIG_JUMP_LABEL_FEATURE_CHECK_DEBUG
29+
if (!static_key_initialized) {
30+
printk("Warning! cpu_has_feature() used prior to jump label init!\n");
31+
dump_stack();
32+
return early_cpu_has_feature(feature);
33+
}
34+
#endif
35+
2836
if (CPU_FTRS_ALWAYS & feature)
2937
return true;
3038

‎arch/powerpc/include/asm/mmu.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,14 @@ static __always_inline bool mmu_has_feature(unsigned long feature)
156156

157157
BUILD_BUG_ON(!__builtin_constant_p(feature));
158158

159+
#ifdef CONFIG_JUMP_LABEL_FEATURE_CHECK_DEBUG
160+
if (!static_key_initialized) {
161+
printk("Warning! mmu_has_feature() used prior to jump label init!\n");
162+
dump_stack();
163+
return early_mmu_has_feature(feature);
164+
}
165+
#endif
166+
159167
if (!(MMU_FTRS_POSSIBLE & feature))
160168
return false;
161169

0 commit comments

Comments
 (0)