Skip to content

Commit efd9e03

Browse files
ctmarinaswildea01
authored andcommitted
arm64: Use static keys for CPU features
This patch adds static keys transparently for all the cpu_hwcaps features by implementing an array of default-false static keys and enabling them when detected. The cpus_have_cap() check uses the static keys if the feature being checked is a constant, otherwise the compiler generates the bitmap test. Because of the early call to static_branch_enable() via check_local_cpu_errata() -> update_cpu_capabilities(), the jump labels are initialised in cpuinfo_store_boot_cpu(). Cc: Will Deacon <[email protected]> Cc: Suzuki K. Poulose <[email protected]> Signed-off-by: Catalin Marinas <[email protected]> Signed-off-by: Will Deacon <[email protected]>
1 parent ef0da55 commit efd9e03

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

arch/arm64/include/asm/cpufeature.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#ifndef __ASM_CPUFEATURE_H
1010
#define __ASM_CPUFEATURE_H
1111

12+
#include <linux/jump_label.h>
13+
1214
#include <asm/hwcap.h>
1315
#include <asm/sysreg.h>
1416

@@ -110,6 +112,7 @@ struct arm64_cpu_capabilities {
110112
};
111113

112114
extern DECLARE_BITMAP(cpu_hwcaps, ARM64_NCAPS);
115+
extern struct static_key_false cpu_hwcap_keys[ARM64_NCAPS];
113116

114117
bool this_cpu_has_cap(unsigned int cap);
115118

@@ -122,16 +125,21 @@ static inline bool cpus_have_cap(unsigned int num)
122125
{
123126
if (num >= ARM64_NCAPS)
124127
return false;
125-
return test_bit(num, cpu_hwcaps);
128+
if (__builtin_constant_p(num))
129+
return static_branch_unlikely(&cpu_hwcap_keys[num]);
130+
else
131+
return test_bit(num, cpu_hwcaps);
126132
}
127133

128134
static inline void cpus_set_cap(unsigned int num)
129135
{
130-
if (num >= ARM64_NCAPS)
136+
if (num >= ARM64_NCAPS) {
131137
pr_warn("Attempt to set an illegal CPU capability (%d >= %d)\n",
132138
num, ARM64_NCAPS);
133-
else
139+
} else {
134140
__set_bit(num, cpu_hwcaps);
141+
static_branch_enable(&cpu_hwcap_keys[num]);
142+
}
135143
}
136144

137145
static inline int __attribute_const__

arch/arm64/kernel/cpufeature.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ unsigned int compat_elf_hwcap2 __read_mostly;
4646

4747
DECLARE_BITMAP(cpu_hwcaps, ARM64_NCAPS);
4848

49+
DEFINE_STATIC_KEY_ARRAY_FALSE(cpu_hwcap_keys, ARM64_NCAPS);
50+
EXPORT_SYMBOL(cpu_hwcap_keys);
51+
4952
#define __ARM64_FTR_BITS(SIGNED, STRICT, TYPE, SHIFT, WIDTH, SAFE_VAL) \
5053
{ \
5154
.sign = SIGNED, \

arch/arm64/kernel/smp.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,11 @@ void __init smp_cpus_done(unsigned int max_cpus)
437437
void __init smp_prepare_boot_cpu(void)
438438
{
439439
set_my_cpu_offset(per_cpu_offset(smp_processor_id()));
440+
/*
441+
* Initialise the static keys early as they may be enabled by the
442+
* cpufeature code.
443+
*/
444+
jump_label_init();
440445
cpuinfo_store_boot_cpu();
441446
save_boot_cpu_run_el();
442447
}

0 commit comments

Comments
 (0)