Skip to content

Commit 88053ec

Browse files
ardbiesheuvelctmarinas
authored andcommitted
arm64: mm: limit linear region to 51 bits for KVM in nVHE mode
KVM in nVHE mode divides up its VA space into two equal halves, and picks the half that does not conflict with the HYP ID map to map its linear region. This worked fine when the kernel's linear map itself was guaranteed to cover precisely as many bits of VA space, but this was changed by commit f4693c2 ("arm64: mm: extend linear region for 52-bit VA configurations"). The result is that, depending on the placement of the ID map, kernel-VA to hyp-VA translations may produce addresses that either conflict with other HYP mappings (including the ID map itself) or generate addresses outside of the 52-bit addressable range, neither of which is likely to lead to anything useful. Given that 52-bit capable cores are guaranteed to implement VHE, this only affects configurations such as pKVM where we opt into non-VHE mode even if the hardware is VHE capable. So just for these configurations, let's limit the kernel linear map to 51 bits and work around the problem. Fixes: f4693c2 ("arm64: mm: extend linear region for 52-bit VA configurations") Signed-off-by: Ard Biesheuvel <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Catalin Marinas <[email protected]>
1 parent 65266a7 commit 88053ec

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

arch/arm64/mm/init.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,21 @@ static void __init fdt_enforce_memory_region(void)
282282

283283
void __init arm64_memblock_init(void)
284284
{
285-
const s64 linear_region_size = PAGE_END - _PAGE_OFFSET(vabits_actual);
285+
s64 linear_region_size = PAGE_END - _PAGE_OFFSET(vabits_actual);
286+
287+
/*
288+
* Corner case: 52-bit VA capable systems running KVM in nVHE mode may
289+
* be limited in their ability to support a linear map that exceeds 51
290+
* bits of VA space, depending on the placement of the ID map. Given
291+
* that the placement of the ID map may be randomized, let's simply
292+
* limit the kernel's linear map to 51 bits as well if we detect this
293+
* configuration.
294+
*/
295+
if (IS_ENABLED(CONFIG_KVM) && vabits_actual == 52 &&
296+
is_hyp_mode_available() && !is_kernel_in_hyp_mode()) {
297+
pr_info("Capping linear region to 51 bits for KVM in nVHE mode on LVA capable hardware.\n");
298+
linear_region_size = min_t(u64, linear_region_size, BIT(51));
299+
}
286300

287301
/* Handle linux,usable-memory-range property */
288302
fdt_enforce_memory_region();

0 commit comments

Comments
 (0)