Skip to content

Commit 53e9acc

Browse files
dvlasenkIngo Molnar
authored andcommitted
x86/asm/entry/32: Do not use R9 in SYSCALL32 entry point
SYSENTER and SYSCALL 32-bit entry points differ in handling of arg2 and arg6. SYSENTER: * ecx arg2 * ebp user stack * 0(%ebp) arg6 SYSCALL: * ebp arg2 * esp user stack * 0(%esp) arg6 Sysenter code loads 0(%ebp) to %ebp right away. (This destroys %ebp. It means we do not preserve it on return. It's not causing problems since userspace VDSO code does not depend on it, and SYSENTER insn can't be sanely used outside of VDSO). Syscall code loads 0(%ebp) to %r9. This allows to eliminate one MOV insn (r9 is a register where arg6 should be for 64-bit ABI), but on audit/ptrace code paths this requires juggling of r9 and ebp: (1) ptrace expects arg6 to be in pt_regs->bp; (2) r9 is callee-clobbered register and needs to be saved/restored around calls to C functions. This patch changes syscall code to load 0(%ebp) to %ebp, making it more similar to sysenter code. It's a bit smaller: text data bss dec hex filename 1407 0 0 1407 57f ia32entry.o.before 1391 0 0 1391 56f ia32entry.o To preserve ABI compat, we restore ebp on exit. Run-tested. Signed-off-by: Denys Vlasenko <[email protected]> Cc: Alexei Starovoitov <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Brian Gerst <[email protected]> Cc: Frederic Weisbecker <[email protected]> Cc: H. Peter Anvin <[email protected]> Cc: Kees Cook <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Oleg Nesterov <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Steven Rostedt <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Will Drewry <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent 73cbf68 commit 53e9acc

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

arch/x86/entry/ia32entry.S

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ ENTRY(ia32_cstar_target)
323323
* 32bit zero extended
324324
*/
325325
ASM_STAC
326-
1: movl (%r8),%r9d
326+
1: movl (%r8),%ebp
327327
_ASM_EXTABLE(1b,ia32_badarg)
328328
ASM_CLAC
329329
orl $TS_COMPAT, ASM_THREAD_INFO(TI_status, %rsp, SIZEOF_PTREGS)
@@ -333,7 +333,7 @@ ENTRY(ia32_cstar_target)
333333
cstar_do_call:
334334
/* 32bit syscall -> 64bit C ABI argument conversion */
335335
movl %edi,%r8d /* arg5 */
336-
/* r9 already loaded */ /* arg6 */
336+
movl %ebp,%r9d /* arg6 */
337337
xchg %ecx,%esi /* rsi:arg2, rcx:arg4 */
338338
movl %ebx,%edi /* arg1 */
339339
movl %edx,%edx /* arg3 (zero extension) */
@@ -349,6 +349,7 @@ cstar_dispatch:
349349
jnz sysretl_audit
350350
sysretl_from_sys_call:
351351
andl $~TS_COMPAT, ASM_THREAD_INFO(TI_status, %rsp, SIZEOF_PTREGS)
352+
movl RCX(%rsp), %ebp
352353
RESTORE_RSI_RDI_RDX
353354
movl RIP(%rsp),%ecx
354355
movl EFLAGS(%rsp),%r11d
@@ -375,9 +376,8 @@ sysretl_from_sys_call:
375376

376377
#ifdef CONFIG_AUDITSYSCALL
377378
cstar_auditsys:
378-
movl %r9d,R9(%rsp) /* register to be clobbered by call */
379379
auditsys_entry_common
380-
movl R9(%rsp),%r9d /* reload 6th syscall arg */
380+
movl %ebp, %r9d /* reload 6th syscall arg */
381381
jmp cstar_dispatch
382382

383383
sysretl_audit:
@@ -389,16 +389,14 @@ cstar_tracesys:
389389
testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT), ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS)
390390
jz cstar_auditsys
391391
#endif
392-
xchgl %r9d,%ebp
393392
SAVE_EXTRA_REGS
394393
xorl %eax, %eax /* do not leak kernel information */
395394
movq %rax, R11(%rsp)
396395
movq %rax, R10(%rsp)
397-
movq %r9, R9(%rsp)
396+
movq %rax, R9(%rsp)
398397
movq %rax, R8(%rsp)
399-
movq %rsp,%rdi /* &pt_regs -> arg1 */
400-
call syscall_trace_enter
401-
movl R9(%rsp),%r9d
398+
movq %rsp, %rdi /* &pt_regs -> arg1 */
399+
call syscall_trace_enter
402400

403401
/* Reload arg registers from stack. (see sysenter_tracesys) */
404402
movl RCX(%rsp), %ecx
@@ -408,8 +406,7 @@ cstar_tracesys:
408406
movl %eax, %eax /* zero extension */
409407

410408
RESTORE_EXTRA_REGS
411-
xchgl %ebp,%r9d
412-
jmp cstar_do_call
409+
jmp cstar_do_call
413410
END(ia32_cstar_target)
414411

415412
ia32_badarg:

0 commit comments

Comments
 (0)