Skip to content

Commit 3ff047f

Browse files
amitdanielkachhapctmarinas
authored andcommitted
arm64: cpufeature: Fix meta-capability cpufeature check
Some existing/future meta cpucaps match need the presence of individual cpucaps. Currently the individual cpucaps checks it via an array based flag and this introduces dependency on the array entry order. This limitation exists only for system scope cpufeature. This patch introduces an internal helper function (__system_matches_cap) to invoke the matching handler for system scope. This helper has to be used during a narrow window when, - The system wide safe registers are set with all the SMP CPUs and, - The SYSTEM_FEATURE cpu_hwcaps may not have been set. Normal users should use the existing cpus_have_{const_}cap() global function. Suggested-by: Suzuki K Poulose <[email protected]> Suggested-by: Catalin Marinas <[email protected]> Signed-off-by: Amit Daniel Kachhap <[email protected]> Reviewed-by: Vincenzo Frascino <[email protected]> Signed-off-by: Catalin Marinas <[email protected]>
1 parent f8788d8 commit 3ff047f

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

arch/arm64/kernel/cpufeature.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ cpufeature_pan_not_uao(const struct arm64_cpu_capabilities *entry, int __unused)
116116

117117
static void cpu_enable_cnp(struct arm64_cpu_capabilities const *cap);
118118

119+
static bool __system_matches_cap(unsigned int n);
120+
119121
/*
120122
* NOTE: Any changes to the visibility of features should be kept in
121123
* sync with the documentation of the CPU feature register ABI.
@@ -2146,6 +2148,23 @@ bool this_cpu_has_cap(unsigned int n)
21462148
return false;
21472149
}
21482150

2151+
/*
2152+
* This helper function is used in a narrow window when,
2153+
* - The system wide safe registers are set with all the SMP CPUs and,
2154+
* - The SYSTEM_FEATURE cpu_hwcaps may not have been set.
2155+
* In all other cases cpus_have_{const_}cap() should be used.
2156+
*/
2157+
static bool __system_matches_cap(unsigned int n)
2158+
{
2159+
if (n < ARM64_NCAPS) {
2160+
const struct arm64_cpu_capabilities *cap = cpu_hwcaps_ptrs[n];
2161+
2162+
if (cap)
2163+
return cap->matches(cap, SCOPE_SYSTEM);
2164+
}
2165+
return false;
2166+
}
2167+
21492168
void cpu_set_feature(unsigned int num)
21502169
{
21512170
WARN_ON(num >= MAX_CPU_FEATURES);
@@ -2218,7 +2237,7 @@ void __init setup_cpu_features(void)
22182237
static bool __maybe_unused
22192238
cpufeature_pan_not_uao(const struct arm64_cpu_capabilities *entry, int __unused)
22202239
{
2221-
return (cpus_have_const_cap(ARM64_HAS_PAN) && !cpus_have_const_cap(ARM64_HAS_UAO));
2240+
return (__system_matches_cap(ARM64_HAS_PAN) && !__system_matches_cap(ARM64_HAS_UAO));
22222241
}
22232242

22242243
static void __maybe_unused cpu_enable_cnp(struct arm64_cpu_capabilities const *cap)

0 commit comments

Comments
 (0)