powerpc: Add option to use jump label for mmu_has_feature()
authorKevin Hao <haokexin@gmail.com>
Sat, 23 Jul 2016 09:12:42 +0000 (14:42 +0530)
committerMichael Ellerman <mpe@ellerman.id.au>
Mon, 1 Aug 2016 01:15:06 +0000 (11:15 +1000)
As we just did for CPU features.

Signed-off-by: Kevin Hao <haokexin@gmail.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
arch/powerpc/include/asm/cpu_has_feature.h
arch/powerpc/include/asm/mmu.h
arch/powerpc/kernel/cputable.c
arch/powerpc/lib/feature-fixups.c

index b9ce6425fdea07e9d9a4e27e055862d898370133..039c011b4252ea75827a56e8f2b5ad68cfa5afc0 100644 (file)
@@ -3,6 +3,7 @@
 
 #ifndef __ASSEMBLY__
 
+#include <linux/bug.h>
 #include <asm/cputable.h>
 
 static inline bool early_cpu_has_feature(unsigned long feature)
index 37f55169df3ec0f40dca7fe3031ca8c2407a330b..1bf919aafd50f1912d54d56fd50756280302f48c 100644 (file)
@@ -141,6 +141,43 @@ static inline bool early_mmu_has_feature(unsigned long feature)
        return !!(MMU_FTRS_POSSIBLE & cur_cpu_spec->mmu_features & feature);
 }
 
+#ifdef CONFIG_JUMP_LABEL_FEATURE_CHECKS
+#include <linux/jump_label.h>
+
+#define NUM_MMU_FTR_KEYS       32
+
+extern struct static_key_true mmu_feature_keys[NUM_MMU_FTR_KEYS];
+
+extern void mmu_feature_keys_init(void);
+
+static __always_inline bool mmu_has_feature(unsigned long feature)
+{
+       int i;
+
+       BUILD_BUG_ON(!__builtin_constant_p(feature));
+
+       if (!(MMU_FTRS_POSSIBLE & feature))
+               return false;
+
+       i = __builtin_ctzl(feature);
+       return static_branch_likely(&mmu_feature_keys[i]);
+}
+
+static inline void mmu_clear_feature(unsigned long feature)
+{
+       int i;
+
+       i = __builtin_ctzl(feature);
+       cur_cpu_spec->mmu_features &= ~feature;
+       static_branch_disable(&mmu_feature_keys[i]);
+}
+#else
+
+static inline void mmu_feature_keys_init(void)
+{
+
+}
+
 static inline bool mmu_has_feature(unsigned long feature)
 {
        return early_mmu_has_feature(feature);
@@ -150,6 +187,7 @@ static inline void mmu_clear_feature(unsigned long feature)
 {
        cur_cpu_spec->mmu_features &= ~feature;
 }
+#endif /* CONFIG_JUMP_LABEL */
 
 extern unsigned int __start___mmu_ftr_fixup, __stop___mmu_ftr_fixup;
 
index e3da41f8ef9397459d6c1b50a9b868e0ad8ad521..74248ab18e9895e27d07924fca3c8f52f7733f90 100644 (file)
@@ -2243,4 +2243,21 @@ void __init cpu_feature_keys_init(void)
                        static_branch_disable(&cpu_feature_keys[i]);
        }
 }
+
+struct static_key_true mmu_feature_keys[NUM_MMU_FTR_KEYS] = {
+                       [0 ... NUM_MMU_FTR_KEYS - 1] = STATIC_KEY_TRUE_INIT
+};
+EXPORT_SYMBOL_GPL(mmu_feature_keys);
+
+void __init mmu_feature_keys_init(void)
+{
+       int i;
+
+       for (i = 0; i < NUM_MMU_FTR_KEYS; i++) {
+               unsigned long f = 1ul << i;
+
+               if (!(cur_cpu_spec->mmu_features & f))
+                       static_branch_disable(&mmu_feature_keys[i]);
+       }
+}
 #endif
index 7a6ccbb74d9159eb8a61f6c6dffca1f9c9549f5b..077fa0ce3382c5430773346a631e59cf2ab3aa75 100644 (file)
@@ -196,6 +196,7 @@ void __init apply_feature_fixups(void)
         */
        jump_label_init();
        cpu_feature_keys_init();
+       mmu_feature_keys_init();
 }
 
 static int __init check_features(void)