]> Git Repo - linux.git/commitdiff
powerpc: Check only single values are passed to CPU/MMU feature checks
authorMichael Ellerman <[email protected]>
Thu, 9 May 2024 12:12:48 +0000 (22:12 +1000)
committerMichael Ellerman <[email protected]>
Thu, 11 Jul 2024 07:31:55 +0000 (17:31 +1000)
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]
arch/powerpc/include/asm/cpu_has_feature.h
arch/powerpc/include/asm/mmu.h

index 92e24e979954dc0746bfc6821d5eed866e299d8e..bf8a228229fa92589d27ffed9dc0222881e25ac7 100644 (file)
@@ -25,6 +25,7 @@ static __always_inline bool cpu_has_feature(unsigned long feature)
        int i;
 
        BUILD_BUG_ON(!__builtin_constant_p(feature));
+       BUILD_BUG_ON(__builtin_popcountl(feature) > 1);
 
 #ifdef CONFIG_JUMP_LABEL_FEATURE_CHECK_DEBUG
        if (!static_key_feature_checks_initialized) {
index 1d1395b769a88f45719c253bb58cd3c4c6ba81d0..4182d68d9cd179ea298babf9c95d359e7a116624 100644 (file)
@@ -240,6 +240,7 @@ static __always_inline bool mmu_has_feature(unsigned long feature)
        int i;
 
        BUILD_BUG_ON(!__builtin_constant_p(feature));
+       BUILD_BUG_ON(__builtin_popcountl(feature) > 1);
 
 #ifdef CONFIG_JUMP_LABEL_FEATURE_CHECK_DEBUG
        if (!static_key_feature_checks_initialized) {
This page took 0.063841 seconds and 4 git commands to generate.