* [PATCH v2 1/4] x86/acpi/suspend: Remove indirect jump
2026-02-03 17:58 [PATCH v2 0/4] x86 suspend cleanups Brian Gerst
@ 2026-02-03 17:58 ` Brian Gerst
2026-02-03 17:58 ` [PATCH v2 2/4] x86/acpi/suspend: Remove segment reloads on resume Brian Gerst
` (4 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Brian Gerst @ 2026-02-03 17:58 UTC (permalink / raw)
To: linux-kernel, x86
Cc: Ingo Molnar, H . Peter Anvin, Thomas Gleixner, Borislav Petkov,
Ard Biesheuvel, Rafael J . Wysocki, Len Brown, Pavel Machek,
Brian Gerst
wakeup_long64() is called from common_startup_64() via initial_code, so
it is already running on the normal virtual mapping. There is no need
to use an indirect jump since it is not switching mappings.
Signed-off-by: Brian Gerst <brgerst@gmail.com>
---
arch/x86/kernel/acpi/wakeup_64.S | 11 ++---------
1 file changed, 2 insertions(+), 9 deletions(-)
diff --git a/arch/x86/kernel/acpi/wakeup_64.S b/arch/x86/kernel/acpi/wakeup_64.S
index 04f561f75e99..3d56610f0108 100644
--- a/arch/x86/kernel/acpi/wakeup_64.S
+++ b/arch/x86/kernel/acpi/wakeup_64.S
@@ -41,10 +41,9 @@ SYM_FUNC_START(wakeup_long64)
movq saved_rsi(%rip), %rsi
movq saved_rbp(%rip), %rbp
- movq saved_rip(%rip), %rax
- ANNOTATE_RETPOLINE_SAFE
- jmp *%rax
+ jmp .Lresume_point
SYM_FUNC_END(wakeup_long64)
+STACK_FRAME_NON_STANDARD wakeup_long64
SYM_FUNC_START(do_suspend_lowlevel)
FRAME_BEGIN
@@ -71,8 +70,6 @@ SYM_FUNC_START(do_suspend_lowlevel)
pushfq
popq pt_regs_flags(%rax)
- movq $.Lresume_point, saved_rip(%rip)
-
movq %rsp, saved_rsp(%rip)
movq %rbp, saved_rbp(%rip)
movq %rbx, saved_rbx(%rip)
@@ -84,11 +81,8 @@ SYM_FUNC_START(do_suspend_lowlevel)
xorl %eax, %eax
call x86_acpi_enter_sleep_state
/* in case something went wrong, restore the machine status and go on */
- jmp .Lresume_point
- .align 4
.Lresume_point:
- ANNOTATE_NOENDBR
/* We don't restore %rax, it must be 0 anyway */
movq $saved_context, %rax
movq saved_context_cr4(%rax), %rbx
@@ -139,7 +133,6 @@ saved_rsi: .quad 0
saved_rdi: .quad 0
saved_rbx: .quad 0
-saved_rip: .quad 0
saved_rsp: .quad 0
SYM_DATA(saved_magic, .quad 0)
--
2.52.0
^ permalink raw reply [flat|nested] 8+ messages in thread* [PATCH v2 2/4] x86/acpi/suspend: Remove segment reloads on resume
2026-02-03 17:58 [PATCH v2 0/4] x86 suspend cleanups Brian Gerst
2026-02-03 17:58 ` [PATCH v2 1/4] x86/acpi/suspend: Remove indirect jump Brian Gerst
@ 2026-02-03 17:58 ` Brian Gerst
2026-02-03 17:58 ` [PATCH v2 3/4] x86/acpi/suspend: Clean up stack usage Brian Gerst
` (3 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Brian Gerst @ 2026-02-03 17:58 UTC (permalink / raw)
To: linux-kernel, x86
Cc: Ingo Molnar, H . Peter Anvin, Thomas Gleixner, Borislav Petkov,
Ard Biesheuvel, Rafael J . Wysocki, Len Brown, Pavel Machek,
Brian Gerst
common_startup_64() has set the segments to usable values already, and
they will be restored later in restore_processor_state(). Remove the
redundant segment loads in wakeup_long64()..
Signed-off-by: Brian Gerst <brgerst@gmail.com>
---
arch/x86/kernel/acpi/wakeup_64.S | 6 ------
1 file changed, 6 deletions(-)
diff --git a/arch/x86/kernel/acpi/wakeup_64.S b/arch/x86/kernel/acpi/wakeup_64.S
index 3d56610f0108..099401ef2ea4 100644
--- a/arch/x86/kernel/acpi/wakeup_64.S
+++ b/arch/x86/kernel/acpi/wakeup_64.S
@@ -28,12 +28,6 @@ SYM_FUNC_START(wakeup_long64)
1:
jmp 1b
2:
- movw $__KERNEL_DS, %ax
- movw %ax, %ss
- movw %ax, %ds
- movw %ax, %es
- movw %ax, %fs
- movw %ax, %gs
movq saved_rsp(%rip), %rsp
movq saved_rbx(%rip), %rbx
--
2.52.0
^ permalink raw reply [flat|nested] 8+ messages in thread* [PATCH v2 3/4] x86/acpi/suspend: Clean up stack usage
2026-02-03 17:58 [PATCH v2 0/4] x86 suspend cleanups Brian Gerst
2026-02-03 17:58 ` [PATCH v2 1/4] x86/acpi/suspend: Remove indirect jump Brian Gerst
2026-02-03 17:58 ` [PATCH v2 2/4] x86/acpi/suspend: Remove segment reloads on resume Brian Gerst
@ 2026-02-03 17:58 ` Brian Gerst
2026-02-03 17:58 ` [PATCH v2 4/4] x86/acpi/suspend: Remove redundant register saves Brian Gerst
` (2 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Brian Gerst @ 2026-02-03 17:58 UTC (permalink / raw)
To: linux-kernel, x86
Cc: Ingo Molnar, H . Peter Anvin, Thomas Gleixner, Borislav Petkov,
Ard Biesheuvel, Rafael J . Wysocki, Len Brown, Pavel Machek,
Brian Gerst
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@gmail.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
^ permalink raw reply [flat|nested] 8+ messages in thread* [PATCH v2 4/4] x86/acpi/suspend: Remove redundant register saves
2026-02-03 17:58 [PATCH v2 0/4] x86 suspend cleanups Brian Gerst
` (2 preceding siblings ...)
2026-02-03 17:58 ` [PATCH v2 3/4] x86/acpi/suspend: Clean up stack usage Brian Gerst
@ 2026-02-03 17:58 ` Brian Gerst
2026-02-03 20:31 ` [PATCH v2 0/4] x86 suspend cleanups Rafael J. Wysocki
2026-02-04 9:47 ` Ard Biesheuvel
5 siblings, 0 replies; 8+ messages in thread
From: Brian Gerst @ 2026-02-03 17:58 UTC (permalink / raw)
To: linux-kernel, x86
Cc: Ingo Molnar, H . Peter Anvin, Thomas Gleixner, Borislav Petkov,
Ard Biesheuvel, Rafael J . Wysocki, Len Brown, Pavel Machek,
Brian Gerst
All general purpose registers are saved in save_context. Remove the
redundant saves to local data.
Signed-off-by: Brian Gerst <brgerst@gmail.com>
---
arch/x86/kernel/acpi/wakeup_64.S | 19 +------------------
1 file changed, 1 insertion(+), 18 deletions(-)
diff --git a/arch/x86/kernel/acpi/wakeup_64.S b/arch/x86/kernel/acpi/wakeup_64.S
index b4bb1ca228b6..e8b3d01ba14a 100644
--- a/arch/x86/kernel/acpi/wakeup_64.S
+++ b/arch/x86/kernel/acpi/wakeup_64.S
@@ -25,19 +25,12 @@ SYM_FUNC_START(wakeup_long64)
movq saved_magic(%rip), %rax
movq $0x123456789abcdef0, %rdx
cmpq %rdx, %rax
- je 2f
+ je .Lresume_point
/* stop here on a saved_magic mismatch */
movq $0xbad6d61676963, %rcx
1:
jmp 1b
-2:
- movq saved_rbx(%rip), %rbx
- movq saved_rdi(%rip), %rdi
- movq saved_rsi(%rip), %rsi
- movq saved_rbp(%rip), %rbp
-
- jmp .Lresume_point
SYM_FUNC_END(wakeup_long64)
STACK_FRAME_NON_STANDARD wakeup_long64
@@ -67,11 +60,6 @@ SYM_FUNC_START(do_suspend_lowlevel)
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)
-
movl $3, %edi
xorl %eax, %eax
call x86_acpi_enter_sleep_state
@@ -120,9 +108,4 @@ SYM_FUNC_START(do_suspend_lowlevel)
SYM_FUNC_END(do_suspend_lowlevel)
.data
-saved_rbp: .quad 0
-saved_rsi: .quad 0
-saved_rdi: .quad 0
-saved_rbx: .quad 0
-
SYM_DATA(saved_magic, .quad 0)
--
2.52.0
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH v2 0/4] x86 suspend cleanups
2026-02-03 17:58 [PATCH v2 0/4] x86 suspend cleanups Brian Gerst
` (3 preceding siblings ...)
2026-02-03 17:58 ` [PATCH v2 4/4] x86/acpi/suspend: Remove redundant register saves Brian Gerst
@ 2026-02-03 20:31 ` Rafael J. Wysocki
2026-02-04 9:47 ` Ard Biesheuvel
5 siblings, 0 replies; 8+ messages in thread
From: Rafael J. Wysocki @ 2026-02-03 20:31 UTC (permalink / raw)
To: Brian Gerst
Cc: linux-kernel, x86, Ingo Molnar, H . Peter Anvin, Thomas Gleixner,
Borislav Petkov, Ard Biesheuvel, Rafael J . Wysocki, Len Brown,
Pavel Machek
On Tue, Feb 3, 2026 at 6:59 PM Brian Gerst <brgerst@gmail.com> wrote:
>
> This patchset cleans up the do_suspend_lowlevel() function, removing
> some leftover bits that are no longer necessary since it started
> using the SMP trampoline to resune the kernel.
>
> v2:
> - Reworked the first patch
> - Added more cleanups
>
> Brian Gerst (4):
> x86/acpi/suspend: Remove indirect jump
> x86/acpi/suspend: Remove segment reloads on resume
> x86/acpi/suspend: Clean up stack usage
> x86/acpi/suspend: Remove redundant register saves
>
> arch/x86/kernel/acpi/sleep.c | 20 -------------
> arch/x86/kernel/acpi/wakeup_64.S | 50 +++++---------------------------
> 2 files changed, 8 insertions(+), 62 deletions(-)
Maybe CC linux-acpi@vger.kernel.org.
It would be easier to review somewhat.
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH v2 0/4] x86 suspend cleanups
2026-02-03 17:58 [PATCH v2 0/4] x86 suspend cleanups Brian Gerst
` (4 preceding siblings ...)
2026-02-03 20:31 ` [PATCH v2 0/4] x86 suspend cleanups Rafael J. Wysocki
@ 2026-02-04 9:47 ` Ard Biesheuvel
2026-02-07 18:04 ` Brian Gerst
5 siblings, 1 reply; 8+ messages in thread
From: Ard Biesheuvel @ 2026-02-04 9:47 UTC (permalink / raw)
To: Brian Gerst, linux-kernel, x86
Cc: Ingo Molnar, H . Peter Anvin, Thomas Gleixner, Borislav Petkov,
Rafael J . Wysocki, Len Brown, Pavel Machek
On Tue, 3 Feb 2026, at 18:58, Brian Gerst wrote:
> This patchset cleans up the do_suspend_lowlevel() function, removing
> some leftover bits that are no longer necessary since it started
> using the SMP trampoline to resune the kernel.
>
> v2:
> - Reworked the first patch
> - Added more cleanups
>
> Brian Gerst (4):
> x86/acpi/suspend: Remove indirect jump
> x86/acpi/suspend: Remove segment reloads on resume
> x86/acpi/suspend: Clean up stack usage
> x86/acpi/suspend: Remove redundant register saves
>
This all looks correct to me - the stack changes in patch #3 do result in the stack misalignment to be different than it was before, but it is still 8 byte aligned throughout, which is all we care about in the kernel IIRC?
So
Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
Tested-by: Ard Biesheuvel <ardb@kernel.org> # qemu SMP suspend/resume
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH v2 0/4] x86 suspend cleanups
2026-02-04 9:47 ` Ard Biesheuvel
@ 2026-02-07 18:04 ` Brian Gerst
0 siblings, 0 replies; 8+ messages in thread
From: Brian Gerst @ 2026-02-07 18:04 UTC (permalink / raw)
To: Ard Biesheuvel
Cc: linux-kernel, x86, Ingo Molnar, H . Peter Anvin, Thomas Gleixner,
Borislav Petkov, Rafael J . Wysocki, Len Brown, Pavel Machek
On Wed, Feb 4, 2026 at 4:47 AM Ard Biesheuvel <ardb@kernel.org> wrote:
>
>
> On Tue, 3 Feb 2026, at 18:58, Brian Gerst wrote:
> > This patchset cleans up the do_suspend_lowlevel() function, removing
> > some leftover bits that are no longer necessary since it started
> > using the SMP trampoline to resune the kernel.
> >
> > v2:
> > - Reworked the first patch
> > - Added more cleanups
> >
> > Brian Gerst (4):
> > x86/acpi/suspend: Remove indirect jump
> > x86/acpi/suspend: Remove segment reloads on resume
> > x86/acpi/suspend: Clean up stack usage
> > x86/acpi/suspend: Remove redundant register saves
> >
>
> This all looks correct to me - the stack changes in patch #3 do result in the stack misalignment to be different than it was before, but it is still 8 byte aligned throughout, which is all we care about in the kernel IIRC?
Yes, the kernel uses 8-byte alignment (-mpreferred-stack-boundary=3)
instead of the default 16 for space savings.
^ permalink raw reply [flat|nested] 8+ messages in thread