[PATCH V2 3/6] x86_32/sysenter: switch to the task stack without emptying the entry stack

From: Lai Jiangshan
Date: Mon Jan 25 2021 - 11:43:07 EST


From: Lai Jiangshan <laijs@xxxxxxxxxxxxxxxxx>

Like the way x86_64 uses the "old" stack, we can save the entry stack
pointer to a register and switch to the task stack. So that we have
space on the "old" stack to save more things or scratch registers.

Signed-off-by: Lai Jiangshan <laijs@xxxxxxxxxxxxxxxxx>
---
arch/x86/entry/entry_32.S | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/arch/x86/entry/entry_32.S b/arch/x86/entry/entry_32.S
index 3b4d1a63d1f0..4513702ba45d 100644
--- a/arch/x86/entry/entry_32.S
+++ b/arch/x86/entry/entry_32.S
@@ -905,19 +905,18 @@ SYM_FUNC_START(entry_SYSENTER_32)
pushl %eax
BUG_IF_WRONG_CR3 no_user_check=1
SWITCH_TO_KERNEL_CR3 scratch_reg=%eax
- popl %eax
- popfl

- /* Stack empty again, switch to task stack */
- movl TSS_entry2task_stack(%esp), %esp
+ /* Switch to task stack */
+ movl %esp, %eax
+ movl (2*4+TSS_entry2task_stack)(%esp), %esp

.Lsysenter_past_esp:
pushl $__USER_DS /* pt_regs->ss */
pushl $0 /* pt_regs->sp (placeholder) */
- pushfl /* pt_regs->flags (except IF = 0) */
+ pushl 4(%eax) /* pt_regs->flags (except IF = 0) */
pushl $__USER_CS /* pt_regs->cs */
pushl $0 /* pt_regs->ip = 0 (placeholder) */
- pushl %eax /* pt_regs->orig_ax */
+ pushl (%eax) /* pt_regs->orig_ax */
SAVE_ALL pt_regs_ax=$-ENOSYS /* save rest, stack already switched */

/*
--
2.19.1.6.gb485710b