[PATCH V4 3/6] x86/entry/32: Switch to the task stack without emptying the entry stack

From: Lai Jiangshan
Date: Wed Feb 10 2021 - 07:43:02 EST


From: Lai Jiangshan <laijs@xxxxxxxxxxxxxxxxx>

Like the way x86_64 uses the entry stack when switching to the task stack,
entry_SYSENTER_32 can also save the entry stack pointer to a register and
then switch to the task stack. So that it doesn't need to empty the entry
stack by poping contents to registers and it has more space on the entry
stack to save stuffs or scratch registers.

It is a preparation for next patches which need to save user %fs in the
entry stack before restoring kernel %fs and loading the task stack for
stack switching.

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..3e693db0963d 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 %ss: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 %ss:(%eax) /* pt_regs->orig_ax */
SAVE_ALL pt_regs_ax=$-ENOSYS /* save rest, stack already switched */

/*
--
2.19.1.6.gb485710b