lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20260203175821.511847-4-brgerst@gmail.com>
Date: Tue,  3 Feb 2026 12:58:20 -0500
From: Brian Gerst <brgerst@...il.com>
To: linux-kernel@...r.kernel.org,
	x86@...nel.org
Cc: Ingo Molnar <mingo@...nel.org>,
	"H . Peter Anvin" <hpa@...or.com>,
	Thomas Gleixner <tglx@...utronix.de>,
	Borislav Petkov <bp@...en8.de>,
	Ard Biesheuvel <ardb@...nel.org>,
	"Rafael J . Wysocki" <rafael@...nel.org>,
	Len Brown <lenb@...nel.org>,
	Pavel Machek <pavel@...nel.org>,
	Brian Gerst <brgerst@...il.com>
Subject: [PATCH v2 3/4] x86/acpi/suspend: Clean up stack usage

Save the stack pointer to current->thread.sp right before calling
x86_acpi_enter_sleep_state().  This allows removal of the temporary stack.
Also remove the extra stack adjustments that are not needed.

Signed-off-by: Brian Gerst <brgerst@...il.com>
---
 arch/x86/kernel/acpi/sleep.c     | 20 --------------------
 arch/x86/kernel/acpi/wakeup_64.S | 18 +++++++-----------
 2 files changed, 7 insertions(+), 31 deletions(-)

diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
index 91fa262f0e30..72b5028feaf2 100644
--- a/arch/x86/kernel/acpi/sleep.c
+++ b/arch/x86/kernel/acpi/sleep.c
@@ -25,10 +25,6 @@
 
 unsigned long acpi_realmode_flags;
 
-#if defined(CONFIG_SMP) && defined(CONFIG_64BIT)
-static char temp_stack[4096];
-#endif
-
 /**
  * acpi_get_wakeup_address - provide physical address for S3 wakeup
  *
@@ -113,22 +109,6 @@ int x86_acpi_suspend_lowlevel(void)
 	saved_magic = 0x12345678;
 #else /* CONFIG_64BIT */
 #ifdef CONFIG_SMP
-	/*
-	 * As each CPU starts up, it will find its own stack pointer
-	 * from its current_task->thread.sp. Typically that will be
-	 * the idle thread for a newly-started AP, or even the boot
-	 * CPU which will find it set to &init_task in the static
-	 * per-cpu data.
-	 *
-	 * Make the resuming CPU use the temporary stack at startup
-	 * by setting current->thread.sp to point to that. The true
-	 * %rsp will be restored with the rest of the CPU context,
-	 * by do_suspend_lowlevel(). And unwinders don't care about
-	 * the abuse of ->thread.sp because it's a dead variable
-	 * while the thread is running on the CPU anyway; the true
-	 * value is in the actual %rsp register.
-	 */
-	current->thread.sp = (unsigned long)temp_stack + sizeof(temp_stack);
 	/*
 	 * Ensure the CPU knows which one it is when it comes back, if
 	 * it isn't in parallel mode and expected to work that out for
diff --git a/arch/x86/kernel/acpi/wakeup_64.S b/arch/x86/kernel/acpi/wakeup_64.S
index 099401ef2ea4..b4bb1ca228b6 100644
--- a/arch/x86/kernel/acpi/wakeup_64.S
+++ b/arch/x86/kernel/acpi/wakeup_64.S
@@ -18,6 +18,10 @@
 	 */
 SYM_FUNC_START(wakeup_long64)
 	ANNOTATE_NOENDBR
+
+	/* pop return address to common_startup_64() */
+	addq	$8, %rsp
+
 	movq	saved_magic(%rip), %rax
 	movq	$0x123456789abcdef0, %rdx
 	cmpq	%rdx, %rax
@@ -28,8 +32,6 @@ SYM_FUNC_START(wakeup_long64)
 1:
 	jmp 1b
 2:
-	movq	saved_rsp(%rip), %rsp
-
 	movq	saved_rbx(%rip), %rbx
 	movq	saved_rdi(%rip), %rdi
 	movq	saved_rsi(%rip), %rsi
@@ -41,12 +43,10 @@ STACK_FRAME_NON_STANDARD wakeup_long64
 
 SYM_FUNC_START(do_suspend_lowlevel)
 	FRAME_BEGIN
-	subq	$8, %rsp
 	xorl	%eax, %eax
 	call	save_processor_state
 
 	movq	$saved_context, %rax
-	movq	%rsp, pt_regs_sp(%rax)
 	movq	%rbp, pt_regs_bp(%rax)
 	movq	%rsi, pt_regs_si(%rax)
 	movq	%rdi, pt_regs_di(%rax)
@@ -64,13 +64,14 @@ SYM_FUNC_START(do_suspend_lowlevel)
 	pushfq
 	popq	pt_regs_flags(%rax)
 
-	movq	%rsp, saved_rsp(%rip)
+	movq	PER_CPU_VAR(current_task), %rax
+	movq	%rsp, TASK_threadsp(%rax)
+
 	movq	%rbp, saved_rbp(%rip)
 	movq	%rbx, saved_rbx(%rip)
 	movq	%rdi, saved_rdi(%rip)
 	movq	%rsi, saved_rsi(%rip)
 
-	addq	$8, %rsp
 	movl	$3, %edi
 	xorl	%eax, %eax
 	call	x86_acpi_enter_sleep_state
@@ -89,7 +90,6 @@ SYM_FUNC_START(do_suspend_lowlevel)
 	movq	%rbx, %cr0
 	pushq	pt_regs_flags(%rax)
 	popfq
-	movq	pt_regs_sp(%rax), %rsp
 	movq	pt_regs_bp(%rax), %rbp
 	movq	pt_regs_si(%rax), %rsi
 	movq	pt_regs_di(%rax), %rdi
@@ -115,11 +115,9 @@ SYM_FUNC_START(do_suspend_lowlevel)
 #endif
 
 	xorl	%eax, %eax
-	addq	$8, %rsp
 	FRAME_END
 	jmp	restore_processor_state
 SYM_FUNC_END(do_suspend_lowlevel)
-STACK_FRAME_NON_STANDARD do_suspend_lowlevel
 
 .data
 saved_rbp:		.quad	0
@@ -127,6 +125,4 @@ saved_rsi:		.quad	0
 saved_rdi:		.quad	0
 saved_rbx:		.quad	0
 
-saved_rsp:		.quad	0
-
 SYM_DATA(saved_magic,	.quad	0)
-- 
2.52.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ