Skip to content

Commit 606f8e7

Browse files
Suzuki K Poulosewildea01
authored andcommitted
arm64: capabilities: Use linear array for detection and verification
Use the sorted list of capability entries for the detection and verification. Reviewed-by: Vladimir Murzin <[email protected]> Tested-by: Vladimir Murzin <[email protected]> Signed-off-by: Suzuki K Poulose <[email protected]> Signed-off-by: Will Deacon <[email protected]>
1 parent f7bfc14 commit 606f8e7

File tree

1 file changed

+17
-25
lines changed

1 file changed

+17
-25
lines changed

arch/arm64/kernel/cpufeature.c

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,28 +1512,25 @@ static void __init setup_elf_hwcaps(const struct arm64_cpu_capabilities *hwcaps)
15121512
cap_set_elf_hwcap(hwcaps);
15131513
}
15141514

1515-
static void __update_cpu_capabilities(const struct arm64_cpu_capabilities *caps,
1516-
u16 scope_mask, const char *info)
1515+
static void update_cpu_capabilities(u16 scope_mask)
15171516
{
1517+
int i;
1518+
const struct arm64_cpu_capabilities *caps;
1519+
15181520
scope_mask &= ARM64_CPUCAP_SCOPE_MASK;
1519-
for (; caps->matches; caps++) {
1520-
if (!(caps->type & scope_mask) ||
1521+
for (i = 0; i < ARM64_NCAPS; i++) {
1522+
caps = cpu_hwcaps_ptrs[i];
1523+
if (!caps || !(caps->type & scope_mask) ||
1524+
cpus_have_cap(caps->capability) ||
15211525
!caps->matches(caps, cpucap_default_scope(caps)))
15221526
continue;
15231527

1524-
if (!cpus_have_cap(caps->capability) && caps->desc)
1525-
pr_info("%s %s\n", info, caps->desc);
1528+
if (caps->desc)
1529+
pr_info("detected: %s\n", caps->desc);
15261530
cpus_set_cap(caps->capability);
15271531
}
15281532
}
15291533

1530-
static void update_cpu_capabilities(u16 scope_mask)
1531-
{
1532-
__update_cpu_capabilities(arm64_errata, scope_mask,
1533-
"enabling workaround for");
1534-
__update_cpu_capabilities(arm64_features, scope_mask, "detected:");
1535-
}
1536-
15371534
static int __enable_cpu_capability(void *arg)
15381535
{
15391536
const struct arm64_cpu_capabilities *cap = arg;
@@ -1597,16 +1594,17 @@ static void __init enable_cpu_capabilities(u16 scope_mask)
15971594
*
15981595
* Returns "false" on conflicts.
15991596
*/
1600-
static bool
1601-
__verify_local_cpu_caps(const struct arm64_cpu_capabilities *caps,
1602-
u16 scope_mask)
1597+
static bool verify_local_cpu_caps(u16 scope_mask)
16031598
{
1599+
int i;
16041600
bool cpu_has_cap, system_has_cap;
1601+
const struct arm64_cpu_capabilities *caps;
16051602

16061603
scope_mask &= ARM64_CPUCAP_SCOPE_MASK;
16071604

1608-
for (; caps->matches; caps++) {
1609-
if (!(caps->type & scope_mask))
1605+
for (i = 0; i < ARM64_NCAPS; i++) {
1606+
caps = cpu_hwcaps_ptrs[i];
1607+
if (!caps || !(caps->type & scope_mask))
16101608
continue;
16111609

16121610
cpu_has_cap = caps->matches(caps, SCOPE_LOCAL_CPU);
@@ -1637,7 +1635,7 @@ __verify_local_cpu_caps(const struct arm64_cpu_capabilities *caps,
16371635
}
16381636
}
16391637

1640-
if (caps->matches) {
1638+
if (i < ARM64_NCAPS) {
16411639
pr_crit("CPU%d: Detected conflict for capability %d (%s), System: %d, CPU: %d\n",
16421640
smp_processor_id(), caps->capability,
16431641
caps->desc, system_has_cap, cpu_has_cap);
@@ -1647,12 +1645,6 @@ __verify_local_cpu_caps(const struct arm64_cpu_capabilities *caps,
16471645
return true;
16481646
}
16491647

1650-
static bool verify_local_cpu_caps(u16 scope_mask)
1651-
{
1652-
return __verify_local_cpu_caps(arm64_errata, scope_mask) &&
1653-
__verify_local_cpu_caps(arm64_features, scope_mask);
1654-
}
1655-
16561648
/*
16571649
* Check for CPU features that are used in early boot
16581650
* based on the Boot CPU value.

0 commit comments

Comments
 (0)