Skip to content

Commit db25a96

Browse files
committed
powerpc: Check only single values are passed to CPU/MMU feature checks
cpu_has_feature()/mmu_has_feature() are only able to check a single feature at a time, but there is no enforcement of that. In fact, as fixed in the previous commit, there was code that was passing multiple values to cpu_has_feature(). So add a check that only a single feature is passed using popcount. Note that the test allows 0 or 1 bits to be set, because some code relies on cpu_has_feature(0) being false, the check with CPU_FTRS_POSSIBLE ensures that. See for example CPU_FTR_PPC_LE. Signed-off-by: Michael Ellerman <[email protected]> Link: https://msgid.link/[email protected]
1 parent 14196e4 commit db25a96

File tree

2 files changed

+2
-0
lines changed

2 files changed

+2
-0
lines changed

arch/powerpc/include/asm/cpu_has_feature.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ static __always_inline bool cpu_has_feature(unsigned long feature)
2525
int i;
2626

2727
BUILD_BUG_ON(!__builtin_constant_p(feature));
28+
BUILD_BUG_ON(__builtin_popcountl(feature) > 1);
2829

2930
#ifdef CONFIG_JUMP_LABEL_FEATURE_CHECK_DEBUG
3031
if (!static_key_feature_checks_initialized) {

arch/powerpc/include/asm/mmu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ static __always_inline bool mmu_has_feature(unsigned long feature)
240240
int i;
241241

242242
BUILD_BUG_ON(!__builtin_constant_p(feature));
243+
BUILD_BUG_ON(__builtin_popcountl(feature) > 1);
243244

244245
#ifdef CONFIG_JUMP_LABEL_FEATURE_CHECK_DEBUG
245246
if (!static_key_feature_checks_initialized) {

0 commit comments

Comments
 (0)