Skip to contentSkip to conversation

ARM: suspend: switch to swapper_pg_dir before using the vmap'ed stack

PATCH In review Ard Biesheuvel 3 participants 5 messages Jan 6, 2022 – Jan 10, 2022 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ARM: suspend: switch to swapper_pg_dir before using the vmap'ed stack

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/[email protected]/

Cc Marek Szyprowski <[email protected]>
Cc Geert Uytterhoeven <[email protected]>
Cc Jon Hunter <[email protected]>

---
Please test with the Kconfig patch [9177/1] reverted.

 arch/arm/kernel/sleep.S | 7 +++++++
 1 file changed, 7 insertions(+)
arch/arm/kernel/sleep.S +7 -0
index b062b3738bc6..6217ef90feb0 100644
@@ -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}
Signature · 7 lines
2.30.2


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Tested-by on v1 1/1
#1 lore raw

Hi Ard,

Quoted 10 lines · Ard Biesheuvel

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].

Quoted 6 lines

[0] https://lore.kernel.org/linux-arm-kernel/[email protected]/

Cc Marek Szyprowski <[email protected]>
Cc Geert Uytterhoeven <[email protected]>
Cc Jon Hunter <[email protected]>

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.

Quoted 14 lines

---
Please test with the Kconfig patch [9177/1] reverted.

 arch/arm/kernel/sleep.S | 7 +++++++
 1 file changed, 7 insertions(+)
arch/arm/kernel/sleep.S +0 -0
index b062b3738bc6..6217ef90feb0 100644
@@ -119,6 +119,13 @@ ENTRY(cpu_resume_mmu)
 ENDPROC(cpu_resume_mmu)
        .popsection
 cpu_resume_after_mmu:

arch/arm/kernel/sleep.S ENTRY(cpu_resume_mmu) · line 131

Quoted 10 lines
arch/arm/kernel/sleep.S +7 -0
+#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 -- [email protected]

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

#2 lore raw
Quoted 21 lines · Geert Uytterhoeven

Hi Ard,

Quoted 10 lines · Ard Biesheuvel

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].

Quoted 6 lines

[0] https://lore.kernel.org/linux-arm-kernel/[email protected]/

Cc Marek Szyprowski <[email protected]>
Cc Geert Uytterhoeven <[email protected]>
Cc Jon Hunter <[email protected]>
Quoted 8 lines

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.

Thanks Geert.

Quoted 35 lines
Quoted 14 lines

---
Please test with the Kconfig patch [9177/1] reverted.

 arch/arm/kernel/sleep.S | 7 +++++++
 1 file changed, 7 insertions(+)
arch/arm/kernel/sleep.S +0 -0
index b062b3738bc6..6217ef90feb0 100644
@@ -119,6 +119,13 @@ ENTRY(cpu_resume_mmu)
 ENDPROC(cpu_resume_mmu)
        .popsection
 cpu_resume_after_mmu:

arch/arm/kernel/sleep.S ENTRY(cpu_resume_mmu) · line 131

Quoted 10 lines
arch/arm/kernel/sleep.S +7 -0
+#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 -- [email protected]

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

Tested-by on v1 1/1
#3 lore raw
In reply to Ard Biesheuvel

Hi Ard,

Quoted 10 lines · Ard Biesheuvel

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].

Quoted 6 lines

[0] https://protect2.fireeye.com/v1/url?k=efa2c314-b039fa16-efa3485b-0cc47a31381a-5dcf992b5d854429&q=1&e=1dac5900-a7aa-40ed-a2f0-9af17ae05bfe&u=https%3A%2F%2Flore.kernel.org%2Flinux-arm-kernel%2F20211122092816.2865873-8-ardb%40kernel.org%2F

Cc Marek Szyprowski <[email protected]>
Cc Geert Uytterhoeven <[email protected]>
Cc Jon Hunter <[email protected]>

This fixes the suspend/resume issue observed on ARM 32bit Exynos based boards. Thanks!

Quoted 14 lines

---
Please test with the Kconfig patch [9177/1] reverted.

  arch/arm/kernel/sleep.S | 7 +++++++
  1 file changed, 7 insertions(+)
arch/arm/kernel/sleep.S +0 -0
index b062b3738bc6..6217ef90feb0 100644
@@ -119,6 +119,13 @@ ENTRY(cpu_resume_mmu)
  ENDPROC(cpu_resume_mmu)
  	.popsection
  cpu_resume_after_mmu:

arch/arm/kernel/sleep.S ENTRY(cpu_resume_mmu) · line 131

Quoted 10 lines
arch/arm/kernel/sleep.S +7 -0
+#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}

Best regards

Signature · 8 lines
Marek Szyprowski, PhD
Samsung R&D Institute Poland


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#4 lore raw
Quoted 21 lines · Marek Szyprowski

Hi Ard,

Quoted 10 lines · Ard Biesheuvel

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].

Quoted 6 lines

[0] https://protect2.fireeye.com/v1/url?k=efa2c314-b039fa16-efa3485b-0cc47a31381a-5dcf992b5d854429&q=1&e=1dac5900-a7aa-40ed-a2f0-9af17ae05bfe&u=https%3A%2F%2Flore.kernel.org%2Flinux-arm-kernel%2F20211122092816.2865873-8-ardb%40kernel.org%2F

Cc Marek Szyprowski <[email protected]>
Cc Geert Uytterhoeven <[email protected]>
Cc Jon Hunter <[email protected]>
Quoted 7 lines

This fixes the suspend/resume issue observed on ARM 32bit Exynos based boards. Thanks!

Thanks Marek.

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel