[PATCH] arm64: Fix 5-level paging support in kexec/hibernate trampoline

Anshuman Khandual anshuman.khandual at arm.com
Sun Jan 12 21:01:30 PST 2025


On 1/10/25 23:21, Ard Biesheuvel wrote:
> From: Ard Biesheuvel <ardb at kernel.org>
> 
> Add the missing code to allocate P4D level page tables when cloning the
> the kernel page tables. This fixes a crash that may be observed when
> attempting to resume from hibernation on an LPA2 capable system with 4k
> pages, which therefore uses 5 levels of paging.
> 
> Presumably, kexec is equally affected.
> 
> Signed-off-by: Ard Biesheuvel <ardb at kernel.org>
> ---
>  arch/arm64/mm/trans_pgd.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/arch/arm64/mm/trans_pgd.c b/arch/arm64/mm/trans_pgd.c
> index 0f7b484cb2ff..84594f02f780 100644
> --- a/arch/arm64/mm/trans_pgd.c
> +++ b/arch/arm64/mm/trans_pgd.c
> @@ -162,6 +162,13 @@ static int copy_p4d(struct trans_pgd_info *info, pgd_t *dst_pgdp,
>  	unsigned long next;
>  	unsigned long addr = start;
>  
> +	if (pgd_none(READ_ONCE(*dst_pgdp))) {
> +		dst_p4dp = trans_alloc(info);
> +		if (!dst_p4dp)
> +			return -ENOMEM;
> +		pgd_populate(NULL, dst_pgdp, dst_p4dp);

Just wondering would not dst_p4dp goes unused (and probably leaked) when
pgtable_l5_enabled() is not enabled ? Similar scenario might also exist
in copy_pud() as well with respect to pgtable_l4_enabled().

pgd_populate()
	__pgd_populate()
		if (pgtable_l5_enabled())
			set_pgd()

> +	}
> +
>  	dst_p4dp = p4d_offset(dst_pgdp, start);
>  	src_p4dp = p4d_offset(src_pgdp, start);
>  	do {



More information about the linux-arm-kernel mailing list