[PATCH 4/7] arm64: hibernate: fix _cpu_resume() calling convention
From: Bradley Morgan
Date: Tue Aug 25 2026 - 16:59:14 EST
The hibernate path borrows bits of the normal idle suspend/resume code
and open codes the rest. It skips cpu_resume() and has
swsusp_arch_suspend_exit() branch straight into _cpu_resume() at the
kernel's native EL with the MMU on.
Commit 82e4958800c01daa ("arm64: head: Move all finalise_el2 calls to
after __enable_mmu") changed the calling convention for _cpu_resume()
to expect EL1 with the boot mode in x19, but we never updated
swsusp_arch_suspend_exit() to match.
So when swsusp_arch_suspend_exit() calls _cpu_resume(), x19 holds the
final struct pbe next pointer, which must be NULL since it marks the
end of the list. _cpu_resume() then passes that to finalise_el2() in
x0, and finalise_el2() only issues an HVC when the value is
BOOT_CPU_MODE_EL2 and we are at EL1, so it happens not to fire. That is
the right outcome, but it is pure luck rather than design.
Split _cpu_resume() so this is less fragile.
__cpu_resume_switched() is the shared part, used by both the idle and
hibernate code. It takes no arguments and issues no HVC. The name is
meant to match __primary_switched and __secondary_switched.
__cpu_resume_switched_finalise_el2() is for the idle path only. It
pulls the boot mode from x19 and calls finalise_el2() before
__cpu_resume_switched(). It is kept local to sleep.S so the odd calling
convention does not leak any further.
Fixes: 82e4958800c01daa ("arm64: head: Move all finalise_el2 calls to after __enable_mmu")
Signed-off-by: Bradley Morgan <brads@xxxxxxxxxxxxxx>
Cc: Ard Biesheuvel <ardb@xxxxxxxxxx>
Cc: Catalin Marinas <catalin.marinas@xxxxxxx>
Cc: James Morse <james.morse@xxxxxxx>
Cc: Marc Zyngier <maz@xxxxxxxxxx>
Cc: Will Deacon <will@xxxxxxxxxx>
---
arch/arm64/include/asm/suspend.h | 2 +-
arch/arm64/kernel/hibernate.c | 2 +-
arch/arm64/kernel/sleep.S | 9 ++++++---
3 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/arch/arm64/include/asm/suspend.h b/arch/arm64/include/asm/suspend.h
index e9ce68d50ba4..1b7570902264 100644
--- a/arch/arm64/include/asm/suspend.h
+++ b/arch/arm64/include/asm/suspend.h
@@ -41,7 +41,7 @@ extern int cpu_suspend(unsigned long arg, int (*fn)(unsigned long));
extern void cpu_resume(void);
int __cpu_suspend_enter(struct sleep_stack_data *state);
void __cpu_suspend_exit(void);
-void _cpu_resume(void);
+void __cpu_resume_switched(void);
int swsusp_arch_suspend(void);
int swsusp_arch_resume(void);
diff --git a/arch/arm64/kernel/hibernate.c b/arch/arm64/kernel/hibernate.c
index 8ac29058a839..30b02e39a397 100644
--- a/arch/arm64/kernel/hibernate.c
+++ b/arch/arm64/kernel/hibernate.c
@@ -114,7 +114,7 @@ int arch_hibernation_header_save(void *addr, unsigned int max_size)
arch_hdr_invariants(&hdr->invariants);
hdr->ttbr1_el1 = __pa_symbol(swapper_pg_dir);
- hdr->reenter_kernel = _cpu_resume;
+ hdr->reenter_kernel = __cpu_resume_switched;
/* We can't use __hyp_get_vectors() because kvm may still be loaded */
if (el2_reset_needed())
diff --git a/arch/arm64/kernel/sleep.S b/arch/arm64/kernel/sleep.S
index f093cdf71be1..da45ab63bd9c 100644
--- a/arch/arm64/kernel/sleep.S
+++ b/arch/arm64/kernel/sleep.S
@@ -107,16 +107,19 @@ SYM_CODE_START(cpu_resume)
adrp x1, swapper_pg_dir
adrp x2, idmap_pg_dir
bl __enable_mmu
- ldr x8, =_cpu_resume
+ ldr x8, =__cpu_resume_switched_finalise_el2
br x8
SYM_CODE_END(cpu_resume)
.ltorg
.popsection
-SYM_FUNC_START(_cpu_resume)
+SYM_FUNC_START_LOCAL(__cpu_resume_switched_finalise_el2)
mov x0, x19
bl finalise_el2
+ b __cpu_resume_switched
+SYM_FUNC_END(__cpu_resume_switched_finalise_el2)
+SYM_FUNC_START(__cpu_resume_switched)
mrs x1, mpidr_el1
adr_l x8, mpidr_hash // x8 = struct mpidr_hash virt address
@@ -152,4 +155,4 @@ SYM_FUNC_START(_cpu_resume)
ldp x29, lr, [x29]
mov x0, #0
ret
-SYM_FUNC_END(_cpu_resume)
+SYM_FUNC_END(__cpu_resume_switched)
--
2.47.3