Skip to content

Commit df95081

Browse files
willdeaconPeter Zijlstra
authored andcommitted
arm64: Prevent offlining first CPU with 32-bit EL0 on mismatched system
If we want to support 32-bit applications, then when we identify a CPU with mismatched 32-bit EL0 support we must ensure that we will always have an active 32-bit CPU available to us from then on. This is important for the scheduler, because is_cpu_allowed() will be constrained to 32-bit CPUs for compat tasks and forced migration due to a hotplug event will hang if no 32-bit CPUs are available. On detecting a mismatch, prevent offlining of either the mismatching CPU if it is 32-bit capable, or find the first active 32-bit capable CPU otherwise. Signed-off-by: Will Deacon <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Reviewed-by: Catalin Marinas <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 08cd8f4 commit df95081

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

arch/arm64/kernel/cpufeature.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2901,15 +2901,38 @@ void __init setup_cpu_features(void)
29012901

29022902
static int enable_mismatched_32bit_el0(unsigned int cpu)
29032903
{
2904+
/*
2905+
* The first 32-bit-capable CPU we detected and so can no longer
2906+
* be offlined by userspace. -1 indicates we haven't yet onlined
2907+
* a 32-bit-capable CPU.
2908+
*/
2909+
static int lucky_winner = -1;
2910+
29042911
struct cpuinfo_arm64 *info = &per_cpu(cpu_data, cpu);
29052912
bool cpu_32bit = id_aa64pfr0_32bit_el0(info->reg_id_aa64pfr0);
29062913

29072914
if (cpu_32bit) {
29082915
cpumask_set_cpu(cpu, cpu_32bit_el0_mask);
29092916
static_branch_enable_cpuslocked(&arm64_mismatched_32bit_el0);
2910-
setup_elf_hwcaps(compat_elf_hwcaps);
29112917
}
29122918

2919+
if (cpumask_test_cpu(0, cpu_32bit_el0_mask) == cpu_32bit)
2920+
return 0;
2921+
2922+
if (lucky_winner >= 0)
2923+
return 0;
2924+
2925+
/*
2926+
* We've detected a mismatch. We need to keep one of our CPUs with
2927+
* 32-bit EL0 online so that is_cpu_allowed() doesn't end up rejecting
2928+
* every CPU in the system for a 32-bit task.
2929+
*/
2930+
lucky_winner = cpu_32bit ? cpu : cpumask_any_and(cpu_32bit_el0_mask,
2931+
cpu_active_mask);
2932+
get_cpu_device(lucky_winner)->offline_disabled = true;
2933+
setup_elf_hwcaps(compat_elf_hwcaps);
2934+
pr_info("Asymmetric 32-bit EL0 support detected on CPU %u; CPU hot-unplug disabled on CPU %u\n",
2935+
cpu, lucky_winner);
29132936
return 0;
29142937
}
29152938

0 commit comments

Comments
 (0)