Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Bradley Morgan <brads@mainlining.org>
To: Will Deacon <will@kernel.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>,
	Mark Rutland <mark.rutland@arm.com>,
	James Morse <james.morse@arm.com>, Marc Zyngier <maz@kernel.org>,
	Ard Biesheuvel <ardb@kernel.org>,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, brads@mainlining.org
Subject: [PATCH 4/7] arm64: hibernate: fix _cpu_resume() calling convention
Date: Tue, 25 Aug 2026 20:58:36 +0000	[thread overview]
Message-ID: <20260825205839.14571-5-brads@mainlining.org> (raw)
In-Reply-To: <20260825205839.14571-1-brads@mainlining.org>

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@mainlining.org>
Cc: Ard Biesheuvel <ardb@kernel.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: James Morse <james.morse@arm.com>
Cc: Marc Zyngier <maz@kernel.org>
Cc: Will Deacon <will@kernel.org>
---
 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


  parent reply	other threads:[~2026-08-25 20:59 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-25 20:58 [PATCH 0/7] arm64: hibernate: dust off the suspend/cleanup rework Bradley Morgan
2026-08-25 20:58 ` [PATCH 1/7] arm64: hibernate: pass HVC_SET_VECTORS args to the resume hvc Bradley Morgan
2026-08-25 20:58 ` [PATCH 2/7] arm64: head: correct comment for init_kernel_el() Bradley Morgan
2026-08-25 20:58 ` [PATCH 3/7] arm64: hibernate: free MTE tag pages after saving Bradley Morgan
2026-08-25 20:58 ` Bradley Morgan [this message]
2026-08-25 20:58 ` [PATCH 5/7] arm64: hibernate: use dcache_by_myline_op Bradley Morgan
2026-08-25 20:58 ` [PATCH 6/7] arm64: hibernate: only clean to PoC Bradley Morgan
2026-08-25 20:58 ` [PATCH 7/7] arm64: hibernate: use regular cpu_resume() logic Bradley Morgan
2026-08-28 10:32 ` [PATCH 0/7] arm64: hibernate: dust off the suspend/cleanup rework Ard Biesheuvel
2026-08-28 11:31   ` Bradley Morgan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260825205839.14571-5-brads@mainlining.org \
    --to=brads@mainlining.org \
    --cc=ardb@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=james.morse@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=maz@kernel.org \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox