Skip to content

Commit eb15d70

Browse files
mrutland-armwilldeacon
authored andcommitted
arm64: Align boot cpucap handling with system cpucap handling
Currently the detection+enablement of boot cpucaps is separate from the patching of boot cpucap alternatives, which means there's a period where cpus_have_cap($CAP) and alternative_has_cap($CAP) may be mismatched. It would be preferable to manage the boot cpucaps in the same way as the system cpucaps, both for clarity and to minimize the risk of accidental usage of code relying upon an alternative which has not yet been patched. This patch aligns the handling of boot cpucaps with the handling of system cpucaps: * The existing setup_boot_cpu_capabilities() function is moved to be closer to the setup_system_capabilities() and setup_system_features() functions so that they're more clearly related and more likely to be updated together in future. * The patching of boot cpucap alternatives is moved into setup_boot_cpu_capabilities(), immediately after boot cpucaps are detected and enabled. * A new setup_boot_cpu_features() function is added to mirror setup_system_features(); this handles initialization of cpucap data structures and calls setup_boot_cpu_capabilities(). This makes init_cpu_features() a closer mirror to update_cpu_features(), and makes smp_prepare_boot_cpu() a closer mirror to smp_cpus_done(). Importantly, while these changes alter the structure of the code, they retain the existing order of calls to: init_cpu_features(); // prefix initializing feature regs init_cpucap_indirect_list(); detect_system_supports_pseudo_nmi(); update_cpu_capabilities(SCOPE_BOOT_CPU | SCOPE_LOCAL_CPU); enable_cpu_capabilities(SCOPE_BOOT_CPU); apply_boot_alternatives(); ... and hence there should be no functional change as a result of this patch; this is purely a structural cleanup. Signed-off-by: Mark Rutland <mark.rutland@arm.com> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Will Deacon <will@kernel.org> Link: https://lore.kernel.org/r/20231212170910.3745497-3-mark.rutland@arm.com Signed-off-by: Will Deacon <will@kernel.org>
1 parent 63a2d92 commit eb15d70

3 files changed

Lines changed: 33 additions & 34 deletions

File tree

arch/arm64/include/asm/cpufeature.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,7 @@ static inline bool id_aa64pfr1_mte(u64 pfr1)
617617
return val >= ID_AA64PFR1_EL1_MTE_MTE2;
618618
}
619619

620+
void __init setup_boot_cpu_features(void);
620621
void __init setup_system_features(void);
621622
void __init setup_user_features(void);
622623

arch/arm64/kernel/cpufeature.c

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,25 +1081,6 @@ void __init init_cpu_features(struct cpuinfo_arm64 *info)
10811081

10821082
if (id_aa64pfr1_mte(info->reg_id_aa64pfr1))
10831083
init_cpu_ftr_reg(SYS_GMID_EL1, info->reg_gmid);
1084-
1085-
/*
1086-
* Initialize the indirect array of CPU capabilities pointers before we
1087-
* handle the boot CPU below.
1088-
*/
1089-
init_cpucap_indirect_list();
1090-
1091-
/*
1092-
* Detect broken pseudo-NMI. Must be called _before_ the call to
1093-
* setup_boot_cpu_capabilities() since it interacts with
1094-
* can_use_gic_priorities().
1095-
*/
1096-
detect_system_supports_pseudo_nmi();
1097-
1098-
/*
1099-
* Detect and enable early CPU capabilities based on the boot CPU,
1100-
* after we have initialised the CPU feature infrastructure.
1101-
*/
1102-
setup_boot_cpu_capabilities();
11031084
}
11041085

11051086
static void update_cpu_ftr_reg(struct arm64_ftr_reg *reg, u64 new)
@@ -3255,14 +3236,6 @@ void check_local_cpu_capabilities(void)
32553236
verify_local_cpu_capabilities();
32563237
}
32573238

3258-
static void __init setup_boot_cpu_capabilities(void)
3259-
{
3260-
/* Detect capabilities with either SCOPE_BOOT_CPU or SCOPE_LOCAL_CPU */
3261-
update_cpu_capabilities(SCOPE_BOOT_CPU | SCOPE_LOCAL_CPU);
3262-
/* Enable the SCOPE_BOOT_CPU capabilities alone right away */
3263-
enable_cpu_capabilities(SCOPE_BOOT_CPU);
3264-
}
3265-
32663239
bool this_cpu_has_cap(unsigned int n)
32673240
{
32683241
if (!WARN_ON(preemptible()) && n < ARM64_NCAPS) {
@@ -3318,6 +3291,36 @@ unsigned long cpu_get_elf_hwcap2(void)
33183291
return elf_hwcap[1];
33193292
}
33203293

3294+
static void __init setup_boot_cpu_capabilities(void)
3295+
{
3296+
/*
3297+
* The boot CPU's feature register values have been recorded. Detect
3298+
* boot cpucaps and local cpucaps for the boot CPU, then enable and
3299+
* patch alternatives for the available boot cpucaps.
3300+
*/
3301+
update_cpu_capabilities(SCOPE_BOOT_CPU | SCOPE_LOCAL_CPU);
3302+
enable_cpu_capabilities(SCOPE_BOOT_CPU);
3303+
apply_boot_alternatives();
3304+
}
3305+
3306+
void __init setup_boot_cpu_features(void)
3307+
{
3308+
/*
3309+
* Initialize the indirect array of CPU capabilities pointers before we
3310+
* handle the boot CPU.
3311+
*/
3312+
init_cpucap_indirect_list();
3313+
3314+
/*
3315+
* Detect broken pseudo-NMI. Must be called _before_ the call to
3316+
* setup_boot_cpu_capabilities() since it interacts with
3317+
* can_use_gic_priorities().
3318+
*/
3319+
detect_system_supports_pseudo_nmi();
3320+
3321+
setup_boot_cpu_capabilities();
3322+
}
3323+
33213324
static void __init setup_system_capabilities(void)
33223325
{
33233326
/*

arch/arm64/kernel/smp.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -453,14 +453,9 @@ void __init smp_prepare_boot_cpu(void)
453453
* freed shortly, so we must move over to the runtime per-cpu area.
454454
*/
455455
set_my_cpu_offset(per_cpu_offset(smp_processor_id()));
456-
cpuinfo_store_boot_cpu();
457456

458-
/*
459-
* We now know enough about the boot CPU to apply the
460-
* alternatives that cannot wait until interrupt handling
461-
* and/or scheduling is enabled.
462-
*/
463-
apply_boot_alternatives();
457+
cpuinfo_store_boot_cpu();
458+
setup_boot_cpu_features();
464459

465460
/* Conditionally switch to GIC PMR for interrupt masking */
466461
if (system_uses_irq_prio_masking())

0 commit comments

Comments
 (0)