Skip to content

Commit 9abd515

Browse files
jpbruckerwilldeacon
authored andcommitted
arm64: context: Fix ASID limit in boot messages
Since commit f88f42f ("arm64: context: Free up kernel ASIDs if KPTI is not in use"), the NUM_USER_ASIDS macro doesn't correspond to the effective number of ASIDs when KPTI is enabled. Get an accurate number of available ASIDs in an arch_initcall, once we've discovered all CPUs' capabilities and know if we still need to halve the ASID space for KPTI. Fixes: f88f42f ("arm64: context: Free up kernel ASIDs if KPTI is not in use") Reviewed-by: Vladimir Murzin <[email protected]> Signed-off-by: Jean-Philippe Brucker <[email protected]> Signed-off-by: Will Deacon <[email protected]>
1 parent 3ba52ad commit 9abd515

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

arch/arm64/mm/context.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -260,14 +260,26 @@ asmlinkage void post_ttbr_update_workaround(void)
260260
CONFIG_CAVIUM_ERRATUM_27456));
261261
}
262262

263-
static int asids_init(void)
263+
static int asids_update_limit(void)
264264
{
265-
asid_bits = get_cpu_asid_bits();
265+
unsigned long num_available_asids = NUM_USER_ASIDS;
266+
267+
if (arm64_kernel_unmapped_at_el0())
268+
num_available_asids /= 2;
266269
/*
267270
* Expect allocation after rollover to fail if we don't have at least
268271
* one more ASID than CPUs. ASID #0 is reserved for init_mm.
269272
*/
270-
WARN_ON(NUM_USER_ASIDS - 1 <= num_possible_cpus());
273+
WARN_ON(num_available_asids - 1 <= num_possible_cpus());
274+
pr_info("ASID allocator initialised with %lu entries\n",
275+
num_available_asids);
276+
return 0;
277+
}
278+
arch_initcall(asids_update_limit);
279+
280+
static int asids_init(void)
281+
{
282+
asid_bits = get_cpu_asid_bits();
271283
atomic64_set(&asid_generation, ASID_FIRST_VERSION);
272284
asid_map = kcalloc(BITS_TO_LONGS(NUM_USER_ASIDS), sizeof(*asid_map),
273285
GFP_KERNEL);
@@ -282,8 +294,6 @@ static int asids_init(void)
282294
*/
283295
if (IS_ENABLED(CONFIG_UNMAP_KERNEL_AT_EL0))
284296
set_kpti_asid_bits();
285-
286-
pr_info("ASID allocator initialised with %lu entries\n", NUM_USER_ASIDS);
287297
return 0;
288298
}
289299
early_initcall(asids_init);

0 commit comments

Comments
 (0)