[RFT PATCH] ARM: suspend: switch to swapper_pg_dir before using the vmap'ed stack

Geert Uytterhoeven geert at linux-m68k.org
Fri Jan 7 01:14:45 PST 2022


Hi Ard,

On Thu, Jan 6, 2022 at 8:27 PM Ard Biesheuvel <ardb at kernel.org> wrote:
> The resume from suspend code switches to the ID map so it can enable the
> MMU. On !LPAE configurations, the ID map carries its own copy of the
> kernel VA range, but this is not kept in sync with swapper_pg_dir, and
> so it may lack the mapping of the kernel mode stack if CONFIG_VMAP_STACK
> is enabled.
>
> So let's switch to swapper_pg_dir right after re-enabling the MMU on
> such configurations. This avoids a crash on resume observed on various
> platforms [0].
>
> [0] https://lore.kernel.org/linux-arm-kernel/20211122092816.2865873-8-ardb@kernel.org/
>
> Cc: Marek Szyprowski <m.szyprowski at samsung.com>
> Cc: Geert Uytterhoeven <geert at linux-m68k.org>
> Cc: Jon Hunter <jonathanh at nvidia.com>
> Signed-off-by: Ard Biesheuvel <ardb at kernel.org>

Thanks for your patch!

This fixes s2ram on r8a7791/koelsch (dual Cortex-A15) with
shmobile_defconfig.
S2ram on sh73a0/kzm9g (dual Cortex-A9) works as before.

Tested-by: Geert Uytterhoeven <geert+renesas at glider.be>

> ---
> Please test with the Kconfig patch [9177/1] reverted.
>
>  arch/arm/kernel/sleep.S | 7 +++++++
>  1 file changed, 7 insertions(+)
>
> diff --git a/arch/arm/kernel/sleep.S b/arch/arm/kernel/sleep.S
> index b062b3738bc6..6217ef90feb0 100644
> --- a/arch/arm/kernel/sleep.S
> +++ b/arch/arm/kernel/sleep.S
> @@ -119,6 +119,13 @@ ENTRY(cpu_resume_mmu)
>  ENDPROC(cpu_resume_mmu)
>         .popsection
>  cpu_resume_after_mmu:
> +#if defined(CONFIG_VMAP_STACK) && !defined(CONFIG_ARM_LPAE)
> +       @ Before using the vmap'ed stack, we have to switch to swapper_pg_dir
> +       @ as the ID map does not cover the vmalloc region.
> +       mrc     p15, 0, ip, c2, c0, 1   @ read TTBR1
> +       mcr     p15, 0, ip, c2, c0, 0   @ set TTBR0
> +       isb
> +#endif
>         bl      cpu_init                @ restore the und/abt/irq banked regs
>         mov     r0, #0                  @ return zero on success
>         ldmfd   sp!, {r4 - r11, pc}

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert at linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds



More information about the linux-arm-kernel mailing list