Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Compatibility mode system call entry point for x86-64. |
| 3 | * |
| 4 | * Copyright 2000-2002 Andi Kleen, SuSE Labs. |
| 5 | */ |
| 6 | |
| 7 | #include <asm/dwarf2.h> |
| 8 | #include <asm/calling.h> |
Sam Ravnborg | e2d5df9 | 2005-09-09 21:28:48 +0200 | [diff] [blame] | 9 | #include <asm/asm-offsets.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <asm/current.h> |
| 11 | #include <asm/errno.h> |
| 12 | #include <asm/ia32_unistd.h> |
| 13 | #include <asm/thread_info.h> |
| 14 | #include <asm/segment.h> |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 15 | #include <asm/irqflags.h> |
H. Peter Anvin | 1ce6f86 | 2012-04-20 12:19:50 -0700 | [diff] [blame] | 16 | #include <asm/asm.h> |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 17 | #include <asm/smap.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <linux/linkage.h> |
Eric Paris | d7e7528 | 2012-01-03 14:23:06 -0500 | [diff] [blame] | 19 | #include <linux/err.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 21 | /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */ |
| 22 | #include <linux/elf-em.h> |
| 23 | #define AUDIT_ARCH_I386 (EM_386|__AUDIT_ARCH_LE) |
| 24 | #define __AUDIT_ARCH_LE 0x40000000 |
| 25 | |
| 26 | #ifndef CONFIG_AUDITSYSCALL |
Jan Beulich | 24e3580 | 2009-09-30 11:22:11 +0100 | [diff] [blame] | 27 | #define sysexit_audit ia32_ret_from_sys_call |
| 28 | #define sysretl_audit ia32_ret_from_sys_call |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 29 | #endif |
| 30 | |
Jiri Olsa | ea71454 | 2011-03-07 19:10:39 +0100 | [diff] [blame] | 31 | .section .entry.text, "ax" |
| 32 | |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 33 | /* clobbers %rax */ |
| 34 | .macro CLEAR_RREGS _r9=rax |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | xorl %eax,%eax |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 36 | movq %rax,R11(%rsp) |
| 37 | movq %rax,R10(%rsp) |
| 38 | movq %\_r9,R9(%rsp) |
| 39 | movq %rax,R8(%rsp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | .endm |
| 41 | |
Roland McGrath | d4d6715 | 2008-07-09 02:38:07 -0700 | [diff] [blame] | 42 | /* |
| 43 | * Reload arg registers from stack in case ptrace changed them. |
| 44 | * We don't reload %eax because syscall_trace_enter() returned |
Roland McGrath | eefdca0 | 2010-09-14 12:22:58 -0700 | [diff] [blame] | 45 | * the %rax value we should see. Instead, we just truncate that |
| 46 | * value to 32 bits again as we did on entry from user mode. |
| 47 | * If it's a new value set by user_regset during entry tracing, |
| 48 | * this matches the normal truncation of the user-mode value. |
| 49 | * If it's -1 to make us punt the syscall, then (u32)-1 is still |
| 50 | * an appropriately invalid value. |
Roland McGrath | d4d6715 | 2008-07-09 02:38:07 -0700 | [diff] [blame] | 51 | */ |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 52 | .macro LOAD_ARGS32 _r9=0 |
Jan Beulich | 295286a8 | 2008-08-29 13:21:11 +0100 | [diff] [blame] | 53 | .if \_r9 |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 54 | movl R9(%rsp),%r9d |
Jan Beulich | 295286a8 | 2008-08-29 13:21:11 +0100 | [diff] [blame] | 55 | .endif |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 56 | movl RCX(%rsp),%ecx |
| 57 | movl RDX(%rsp),%edx |
| 58 | movl RSI(%rsp),%esi |
| 59 | movl RDI(%rsp),%edi |
Roland McGrath | eefdca0 | 2010-09-14 12:22:58 -0700 | [diff] [blame] | 60 | movl %eax,%eax /* zero extension */ |
Andi Kleen | 176df24 | 2007-09-21 16:16:18 +0200 | [diff] [blame] | 61 | .endm |
| 62 | |
Jan Beulich | 2765130 | 2006-01-11 22:41:59 +0100 | [diff] [blame] | 63 | .macro CFI_STARTPROC32 simple |
| 64 | CFI_STARTPROC \simple |
| 65 | CFI_UNDEFINED r8 |
| 66 | CFI_UNDEFINED r9 |
| 67 | CFI_UNDEFINED r10 |
| 68 | CFI_UNDEFINED r11 |
| 69 | CFI_UNDEFINED r12 |
| 70 | CFI_UNDEFINED r13 |
| 71 | CFI_UNDEFINED r14 |
| 72 | CFI_UNDEFINED r15 |
| 73 | .endm |
| 74 | |
Jeremy Fitzhardinge | 2be2998 | 2008-06-25 00:19:28 -0400 | [diff] [blame] | 75 | #ifdef CONFIG_PARAVIRT |
| 76 | ENTRY(native_usergs_sysret32) |
| 77 | swapgs |
| 78 | sysretl |
| 79 | ENDPROC(native_usergs_sysret32) |
| 80 | |
| 81 | ENTRY(native_irq_enable_sysexit) |
| 82 | swapgs |
| 83 | sti |
| 84 | sysexit |
| 85 | ENDPROC(native_irq_enable_sysexit) |
| 86 | #endif |
| 87 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | /* |
| 89 | * 32bit SYSENTER instruction entry. |
| 90 | * |
Denys Vlasenko | b87cf63 | 2015-02-26 14:40:32 -0800 | [diff] [blame] | 91 | * SYSENTER loads ss, rsp, cs, and rip from previously programmed MSRs. |
| 92 | * IF and VM in rflags are cleared (IOW: interrupts are off). |
| 93 | * SYSENTER does not save anything on the stack, |
| 94 | * and does not save old rip (!!!) and rflags. |
| 95 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | * Arguments: |
Denys Vlasenko | b87cf63 | 2015-02-26 14:40:32 -0800 | [diff] [blame] | 97 | * eax system call number |
| 98 | * ebx arg1 |
| 99 | * ecx arg2 |
| 100 | * edx arg3 |
| 101 | * esi arg4 |
| 102 | * edi arg5 |
| 103 | * ebp user stack |
| 104 | * 0(%ebp) arg6 |
| 105 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | * This is purely a fast path. For anything complicated we use the int 0x80 |
Denys Vlasenko | b87cf63 | 2015-02-26 14:40:32 -0800 | [diff] [blame] | 107 | * path below. We set up a complete hardware stack frame to share code |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | * with the int 0x80 path. |
Denys Vlasenko | b87cf63 | 2015-02-26 14:40:32 -0800 | [diff] [blame] | 109 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | ENTRY(ia32_sysenter_target) |
Jan Beulich | 2765130 | 2006-01-11 22:41:59 +0100 | [diff] [blame] | 111 | CFI_STARTPROC32 simple |
Jan Beulich | adf1423 | 2006-09-26 10:52:41 +0200 | [diff] [blame] | 112 | CFI_SIGNAL_FRAME |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 113 | CFI_DEF_CFA rsp,0 |
| 114 | CFI_REGISTER rsp,rbp |
Denys Vlasenko | a232e3d | 2015-03-27 11:36:20 +0100 | [diff] [blame] | 115 | |
| 116 | /* |
| 117 | * Interrupts are off on entry. |
| 118 | * We do not frame this tiny irq-off block with TRACE_IRQS_OFF/ON, |
| 119 | * it is too small to ever cause noticeable irq latency. |
| 120 | */ |
Jeremy Fitzhardinge | 457da70 | 2008-06-26 07:28:51 -0700 | [diff] [blame] | 121 | SWAPGS_UNSAFE_STACK |
Andy Lutomirski | 24933b8 | 2015-03-05 19:19:05 -0800 | [diff] [blame] | 122 | movq PER_CPU_VAR(cpu_tss + TSS_sp0), %rsp |
Jeremy Fitzhardinge | 6680415 | 2008-06-25 00:19:29 -0400 | [diff] [blame] | 123 | ENABLE_INTERRUPTS(CLBR_NONE) |
Denys Vlasenko | a232e3d | 2015-03-27 11:36:20 +0100 | [diff] [blame] | 124 | |
Denys Vlasenko | 4ee8ec1 | 2015-03-27 11:36:21 +0100 | [diff] [blame] | 125 | /* Zero-extending 32-bit regs, do not remove */ |
| 126 | movl %ebp, %ebp |
| 127 | movl %eax, %eax |
| 128 | |
Denys Vlasenko | 4c9c0e9 | 2015-03-31 19:00:04 +0200 | [diff] [blame] | 129 | movl ASM_THREAD_INFO(TI_sysenter_return, %rsp, 0), %r10d |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 130 | CFI_REGISTER rip,r10 |
Denys Vlasenko | 4c9c0e9 | 2015-03-31 19:00:04 +0200 | [diff] [blame] | 131 | |
| 132 | /* Construct struct pt_regs on stack */ |
| 133 | pushq_cfi $__USER32_DS /* pt_regs->ss */ |
| 134 | pushq_cfi %rbp /* pt_regs->sp */ |
| 135 | CFI_REL_OFFSET rsp,0 |
| 136 | pushfq_cfi /* pt_regs->flags */ |
| 137 | pushq_cfi $__USER32_CS /* pt_regs->cs */ |
| 138 | pushq_cfi %r10 /* pt_regs->ip = thread_info->sysenter_return */ |
| 139 | CFI_REL_OFFSET rip,0 |
| 140 | pushq_cfi_reg rax /* pt_regs->orig_ax */ |
| 141 | pushq_cfi_reg rdi /* pt_regs->di */ |
| 142 | pushq_cfi_reg rsi /* pt_regs->si */ |
| 143 | pushq_cfi_reg rdx /* pt_regs->dx */ |
| 144 | pushq_cfi_reg rcx /* pt_regs->cx */ |
| 145 | pushq_cfi_reg rax /* pt_regs->ax */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | cld |
Denys Vlasenko | 4c9c0e9 | 2015-03-31 19:00:04 +0200 | [diff] [blame] | 147 | sub $(10*8),%rsp /* pt_regs->r8-11,bp,bx,r12-15 not saved */ |
| 148 | CFI_ADJUST_CFA_OFFSET 10*8 |
| 149 | |
Denys Vlasenko | b87cf63 | 2015-02-26 14:40:32 -0800 | [diff] [blame] | 150 | /* |
| 151 | * no need to do an access_ok check here because rbp has been |
| 152 | * 32bit zero extended |
| 153 | */ |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 154 | ASM_STAC |
Jan Beulich | 295286a8 | 2008-08-29 13:21:11 +0100 | [diff] [blame] | 155 | 1: movl (%rbp),%ebp |
H. Peter Anvin | 1ce6f86 | 2012-04-20 12:19:50 -0700 | [diff] [blame] | 156 | _ASM_EXTABLE(1b,ia32_badarg) |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 157 | ASM_CLAC |
Andy Lutomirski | 8c7aa69 | 2014-10-01 11:49:04 -0700 | [diff] [blame] | 158 | |
| 159 | /* |
| 160 | * Sysenter doesn't filter flags, so we need to clear NT |
| 161 | * ourselves. To save a few cycles, we can check whether |
| 162 | * NT was set instead of doing an unconditional popfq. |
| 163 | */ |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 164 | testl $X86_EFLAGS_NT,EFLAGS(%rsp) |
Andy Lutomirski | 8c7aa69 | 2014-10-01 11:49:04 -0700 | [diff] [blame] | 165 | jnz sysenter_fix_flags |
| 166 | sysenter_flags_fixed: |
| 167 | |
Ingo Molnar | dca5b52 | 2015-03-24 19:44:42 +0100 | [diff] [blame] | 168 | orl $TS_COMPAT, ASM_THREAD_INFO(TI_status, %rsp, SIZEOF_PTREGS) |
| 169 | testl $_TIF_WORK_SYSCALL_ENTRY, ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS) |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 170 | CFI_REMEMBER_STATE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | jnz sysenter_tracesys |
H. Peter Anvin | 36d001c | 2010-09-14 12:42:41 -0700 | [diff] [blame] | 172 | cmpq $(IA32_NR_syscalls-1),%rax |
Andi Kleen | 67d53ea | 2006-04-07 19:50:31 +0200 | [diff] [blame] | 173 | ja ia32_badsys |
Roland McGrath | d4d6715 | 2008-07-09 02:38:07 -0700 | [diff] [blame] | 174 | sysenter_do_call: |
Denys Vlasenko | 14f6e95 | 2015-02-26 14:40:35 -0800 | [diff] [blame] | 175 | /* 32bit syscall -> 64bit C ABI argument conversion */ |
| 176 | movl %edi,%r8d /* arg5 */ |
| 177 | movl %ebp,%r9d /* arg6 */ |
| 178 | xchg %ecx,%esi /* rsi:arg2, rcx:arg4 */ |
| 179 | movl %ebx,%edi /* arg1 */ |
| 180 | movl %edx,%edx /* arg3 (zero extension) */ |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 181 | sysenter_dispatch: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | call *ia32_sys_call_table(,%rax,8) |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 183 | movq %rax,RAX(%rsp) |
Jeremy Fitzhardinge | 6680415 | 2008-06-25 00:19:29 -0400 | [diff] [blame] | 184 | DISABLE_INTERRUPTS(CLBR_NONE) |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 185 | TRACE_IRQS_OFF |
Ingo Molnar | dca5b52 | 2015-03-24 19:44:42 +0100 | [diff] [blame] | 186 | testl $_TIF_ALLWORK_MASK, ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS) |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 187 | jnz sysexit_audit |
| 188 | sysexit_from_sys_call: |
Andy Lutomirski | 4214a16 | 2015-04-02 17:12:12 -0700 | [diff] [blame] | 189 | /* |
| 190 | * NB: SYSEXIT is not obviously safe for 64-bit kernels -- an |
| 191 | * NMI between STI and SYSEXIT has poorly specified behavior, |
| 192 | * and and NMI followed by an IRQ with usergs is fatal. So |
| 193 | * we just pretend we're using SYSEXIT but we really use |
| 194 | * SYSRETL instead. |
| 195 | * |
| 196 | * This code path is still called 'sysexit' because it pairs |
| 197 | * with 'sysenter' and it uses the SYSENTER calling convention. |
| 198 | */ |
Ingo Molnar | dca5b52 | 2015-03-24 19:44:42 +0100 | [diff] [blame] | 199 | andl $~TS_COMPAT,ASM_THREAD_INFO(TI_status, %rsp, SIZEOF_PTREGS) |
Andy Lutomirski | 4214a16 | 2015-04-02 17:12:12 -0700 | [diff] [blame] | 200 | movl RIP(%rsp),%ecx /* User %eip */ |
| 201 | CFI_REGISTER rip,rcx |
Denys Vlasenko | 76f5df4 | 2015-02-26 14:40:27 -0800 | [diff] [blame] | 202 | RESTORE_RSI_RDI |
Andy Lutomirski | 4214a16 | 2015-04-02 17:12:12 -0700 | [diff] [blame] | 203 | xorl %edx,%edx /* avoid info leaks */ |
Jan Beulich | 24e3580 | 2009-09-30 11:22:11 +0100 | [diff] [blame] | 204 | xorq %r8,%r8 |
| 205 | xorq %r9,%r9 |
| 206 | xorq %r10,%r10 |
Andy Lutomirski | 4214a16 | 2015-04-02 17:12:12 -0700 | [diff] [blame] | 207 | movl EFLAGS(%rsp),%r11d /* User eflags */ |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 208 | /*CFI_RESTORE rflags*/ |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 209 | TRACE_IRQS_ON |
Andy Lutomirski | 4214a16 | 2015-04-02 17:12:12 -0700 | [diff] [blame] | 210 | |
Denys Vlasenko | b87cf63 | 2015-02-26 14:40:32 -0800 | [diff] [blame] | 211 | /* |
Andy Lutomirski | 4214a16 | 2015-04-02 17:12:12 -0700 | [diff] [blame] | 212 | * SYSRETL works even on Intel CPUs. Use it in preference to SYSEXIT, |
| 213 | * since it avoids a dicey window with interrupts enabled. |
Denys Vlasenko | b87cf63 | 2015-02-26 14:40:32 -0800 | [diff] [blame] | 214 | */ |
Andy Lutomirski | 4214a16 | 2015-04-02 17:12:12 -0700 | [diff] [blame] | 215 | movl RSP(%rsp),%esp |
| 216 | |
| 217 | /* |
| 218 | * USERGS_SYSRET32 does: |
| 219 | * gsbase = user's gs base |
| 220 | * eip = ecx |
| 221 | * rflags = r11 |
| 222 | * cs = __USER32_CS |
| 223 | * ss = __USER_DS |
| 224 | * |
| 225 | * The prologue set RIP(%rsp) to VDSO32_SYSENTER_RETURN, which does: |
| 226 | * |
| 227 | * pop %ebp |
| 228 | * pop %edx |
| 229 | * pop %ecx |
| 230 | * |
| 231 | * Therefore, we invoke SYSRETL with EDX and R8-R10 zeroed to |
| 232 | * avoid info leaks. R11 ends up with VDSO32_SYSENTER_RETURN's |
| 233 | * address (already known to user code), and R12-R15 are |
| 234 | * callee-saved and therefore don't contain any interesting |
| 235 | * kernel data. |
| 236 | */ |
| 237 | USERGS_SYSRET32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | |
Andy Lutomirski | 8c7aa69 | 2014-10-01 11:49:04 -0700 | [diff] [blame] | 239 | CFI_RESTORE_STATE |
| 240 | |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 241 | #ifdef CONFIG_AUDITSYSCALL |
| 242 | .macro auditsys_entry_common |
Richard Guy Briggs | b4f0d37 | 2014-03-04 10:38:06 -0500 | [diff] [blame] | 243 | movl %esi,%r8d /* 5th arg: 4th syscall arg */ |
| 244 | movl %ecx,%r9d /*swap with edx*/ |
| 245 | movl %edx,%ecx /* 4th arg: 3rd syscall arg */ |
| 246 | movl %r9d,%edx /* 3rd arg: 2nd syscall arg */ |
| 247 | movl %ebx,%esi /* 2nd arg: 1st syscall arg */ |
| 248 | movl %eax,%edi /* 1st arg: syscall number */ |
Eric Paris | b05d844 | 2012-01-03 14:23:06 -0500 | [diff] [blame] | 249 | call __audit_syscall_entry |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 250 | movl RAX(%rsp),%eax /* reload syscall number */ |
H. Peter Anvin | 36d001c | 2010-09-14 12:42:41 -0700 | [diff] [blame] | 251 | cmpq $(IA32_NR_syscalls-1),%rax |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 252 | ja ia32_badsys |
| 253 | movl %ebx,%edi /* reload 1st syscall arg */ |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 254 | movl RCX(%rsp),%esi /* reload 2nd syscall arg */ |
| 255 | movl RDX(%rsp),%edx /* reload 3rd syscall arg */ |
| 256 | movl RSI(%rsp),%ecx /* reload 4th syscall arg */ |
| 257 | movl RDI(%rsp),%r8d /* reload 5th syscall arg */ |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 258 | .endm |
| 259 | |
Jan Beulich | 8176674 | 2009-10-26 15:20:29 +0000 | [diff] [blame] | 260 | .macro auditsys_exit exit |
Ingo Molnar | dca5b52 | 2015-03-24 19:44:42 +0100 | [diff] [blame] | 261 | testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT), ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS) |
Jan Beulich | 24e3580 | 2009-09-30 11:22:11 +0100 | [diff] [blame] | 262 | jnz ia32_ret_from_sys_call |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 263 | TRACE_IRQS_ON |
Jan Beulich | 40a1ef9 | 2013-01-30 07:55:53 +0000 | [diff] [blame] | 264 | ENABLE_INTERRUPTS(CLBR_NONE) |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 265 | movl %eax,%esi /* second arg, syscall return value */ |
Eric Paris | d7e7528 | 2012-01-03 14:23:06 -0500 | [diff] [blame] | 266 | cmpl $-MAX_ERRNO,%eax /* is it an error ? */ |
Eric Paris | f031cd2 | 2012-01-03 14:23:06 -0500 | [diff] [blame] | 267 | jbe 1f |
| 268 | movslq %eax, %rsi /* if error sign extend to 64 bits */ |
| 269 | 1: setbe %al /* 1 if error, 0 if not */ |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 270 | movzbl %al,%edi /* zero-extend that into %edi */ |
Eric Paris | d7e7528 | 2012-01-03 14:23:06 -0500 | [diff] [blame] | 271 | call __audit_syscall_exit |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 272 | movq RAX(%rsp),%rax /* reload syscall return value */ |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 273 | movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi |
Jan Beulich | 40a1ef9 | 2013-01-30 07:55:53 +0000 | [diff] [blame] | 274 | DISABLE_INTERRUPTS(CLBR_NONE) |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 275 | TRACE_IRQS_OFF |
Ingo Molnar | dca5b52 | 2015-03-24 19:44:42 +0100 | [diff] [blame] | 276 | testl %edi, ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS) |
Jan Beulich | 24e3580 | 2009-09-30 11:22:11 +0100 | [diff] [blame] | 277 | jz \exit |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 278 | CLEAR_RREGS |
Jan Beulich | 24e3580 | 2009-09-30 11:22:11 +0100 | [diff] [blame] | 279 | jmp int_with_check |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 280 | .endm |
| 281 | |
| 282 | sysenter_auditsys: |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 283 | auditsys_entry_common |
| 284 | movl %ebp,%r9d /* reload 6th syscall arg */ |
| 285 | jmp sysenter_dispatch |
| 286 | |
| 287 | sysexit_audit: |
| 288 | auditsys_exit sysexit_from_sys_call |
| 289 | #endif |
| 290 | |
Andy Lutomirski | 8c7aa69 | 2014-10-01 11:49:04 -0700 | [diff] [blame] | 291 | sysenter_fix_flags: |
| 292 | pushq_cfi $(X86_EFLAGS_IF|X86_EFLAGS_FIXED) |
| 293 | popfq_cfi |
| 294 | jmp sysenter_flags_fixed |
| 295 | |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 296 | sysenter_tracesys: |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 297 | #ifdef CONFIG_AUDITSYSCALL |
Ingo Molnar | dca5b52 | 2015-03-24 19:44:42 +0100 | [diff] [blame] | 298 | testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT), ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS) |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 299 | jz sysenter_auditsys |
| 300 | #endif |
Denys Vlasenko | 76f5df4 | 2015-02-26 14:40:27 -0800 | [diff] [blame] | 301 | SAVE_EXTRA_REGS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | CLEAR_RREGS |
Roland McGrath | 48ee679 | 2008-03-18 18:23:50 -0700 | [diff] [blame] | 303 | movq $-ENOSYS,RAX(%rsp)/* ptrace can change this for a bad syscall */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | movq %rsp,%rdi /* &pt_regs -> arg1 */ |
| 305 | call syscall_trace_enter |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 306 | LOAD_ARGS32 /* reload args from stack in case ptrace changed it */ |
Denys Vlasenko | 76f5df4 | 2015-02-26 14:40:27 -0800 | [diff] [blame] | 307 | RESTORE_EXTRA_REGS |
H. Peter Anvin | 36d001c | 2010-09-14 12:42:41 -0700 | [diff] [blame] | 308 | cmpq $(IA32_NR_syscalls-1),%rax |
Roland McGrath | 48ee679 | 2008-03-18 18:23:50 -0700 | [diff] [blame] | 309 | ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | jmp sysenter_do_call |
| 311 | CFI_ENDPROC |
Jan Beulich | 4b787e0 | 2006-06-26 13:56:55 +0200 | [diff] [blame] | 312 | ENDPROC(ia32_sysenter_target) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | |
| 314 | /* |
| 315 | * 32bit SYSCALL instruction entry. |
| 316 | * |
Denys Vlasenko | b87cf63 | 2015-02-26 14:40:32 -0800 | [diff] [blame] | 317 | * 32bit SYSCALL saves rip to rcx, clears rflags.RF, then saves rflags to r11, |
| 318 | * then loads new ss, cs, and rip from previously programmed MSRs. |
| 319 | * rflags gets masked by a value from another MSR (so CLD and CLAC |
| 320 | * are not needed). SYSCALL does not save anything on the stack |
| 321 | * and does not change rsp. |
| 322 | * |
| 323 | * Note: rflags saving+masking-with-MSR happens only in Long mode |
| 324 | * (in legacy 32bit mode, IF, RF and VM bits are cleared and that's it). |
| 325 | * Don't get confused: rflags saving+masking depends on Long Mode Active bit |
| 326 | * (EFER.LMA=1), NOT on bitness of userspace where SYSCALL executes |
| 327 | * or target CS descriptor's L bit (SYSCALL does not read segment descriptors). |
| 328 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | * Arguments: |
Denys Vlasenko | b87cf63 | 2015-02-26 14:40:32 -0800 | [diff] [blame] | 330 | * eax system call number |
| 331 | * ecx return address |
| 332 | * ebx arg1 |
| 333 | * ebp arg2 (note: not saved in the stack frame, should not be touched) |
| 334 | * edx arg3 |
| 335 | * esi arg4 |
| 336 | * edi arg5 |
| 337 | * esp user stack |
| 338 | * 0(%esp) arg6 |
| 339 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | * This is purely a fast path. For anything complicated we use the int 0x80 |
Denys Vlasenko | b87cf63 | 2015-02-26 14:40:32 -0800 | [diff] [blame] | 341 | * path below. We set up a complete hardware stack frame to share code |
| 342 | * with the int 0x80 path. |
| 343 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | ENTRY(ia32_cstar_target) |
Jan Beulich | 2765130 | 2006-01-11 22:41:59 +0100 | [diff] [blame] | 345 | CFI_STARTPROC32 simple |
Jan Beulich | adf1423 | 2006-09-26 10:52:41 +0200 | [diff] [blame] | 346 | CFI_SIGNAL_FRAME |
Denys Vlasenko | ef59326 | 2015-03-19 18:17:46 +0100 | [diff] [blame] | 347 | CFI_DEF_CFA rsp,0 |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 348 | CFI_REGISTER rip,rcx |
| 349 | /*CFI_REGISTER rflags,r11*/ |
Denys Vlasenko | a232e3d | 2015-03-27 11:36:20 +0100 | [diff] [blame] | 350 | |
| 351 | /* |
| 352 | * Interrupts are off on entry. |
| 353 | * We do not frame this tiny irq-off block with TRACE_IRQS_OFF/ON, |
| 354 | * it is too small to ever cause noticeable irq latency. |
| 355 | */ |
Jeremy Fitzhardinge | 457da70 | 2008-06-26 07:28:51 -0700 | [diff] [blame] | 356 | SWAPGS_UNSAFE_STACK |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | movl %esp,%r8d |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 358 | CFI_REGISTER rsp,r8 |
Brian Gerst | 9af4565 | 2009-01-19 00:38:58 +0900 | [diff] [blame] | 359 | movq PER_CPU_VAR(kernel_stack),%rsp |
Jeremy Fitzhardinge | 6680415 | 2008-06-25 00:19:29 -0400 | [diff] [blame] | 360 | ENABLE_INTERRUPTS(CLBR_NONE) |
Denys Vlasenko | a232e3d | 2015-03-27 11:36:20 +0100 | [diff] [blame] | 361 | |
Denys Vlasenko | 4ee8ec1 | 2015-03-27 11:36:21 +0100 | [diff] [blame] | 362 | /* Zero-extending 32-bit regs, do not remove */ |
| 363 | movl %eax,%eax |
| 364 | |
Denys Vlasenko | 4c9c0e9 | 2015-03-31 19:00:04 +0200 | [diff] [blame] | 365 | /* Construct struct pt_regs on stack */ |
| 366 | pushq_cfi $__USER32_DS /* pt_regs->ss */ |
| 367 | pushq_cfi %r8 /* pt_regs->sp */ |
| 368 | CFI_REL_OFFSET rsp,0 |
| 369 | pushq_cfi %r11 /* pt_regs->flags */ |
| 370 | pushq_cfi $__USER32_CS /* pt_regs->cs */ |
| 371 | pushq_cfi %rcx /* pt_regs->ip */ |
| 372 | CFI_REL_OFFSET rip,0 |
| 373 | pushq_cfi_reg rax /* pt_regs->orig_ax */ |
| 374 | pushq_cfi_reg rdi /* pt_regs->di */ |
| 375 | pushq_cfi_reg rsi /* pt_regs->si */ |
| 376 | pushq_cfi_reg rdx /* pt_regs->dx */ |
| 377 | pushq_cfi_reg rbp /* pt_regs->cx */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | movl %ebp,%ecx |
Denys Vlasenko | 4c9c0e9 | 2015-03-31 19:00:04 +0200 | [diff] [blame] | 379 | pushq_cfi_reg rax /* pt_regs->ax */ |
| 380 | sub $(10*8),%rsp /* pt_regs->r8-11,bp,bx,r12-15 not saved */ |
| 381 | CFI_ADJUST_CFA_OFFSET 10*8 |
| 382 | |
Denys Vlasenko | b87cf63 | 2015-02-26 14:40:32 -0800 | [diff] [blame] | 383 | /* |
| 384 | * no need to do an access_ok check here because r8 has been |
| 385 | * 32bit zero extended |
| 386 | */ |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 387 | ASM_STAC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | 1: movl (%r8),%r9d |
H. Peter Anvin | a3e859f | 2012-04-20 16:51:50 -0700 | [diff] [blame] | 389 | _ASM_EXTABLE(1b,ia32_badarg) |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 390 | ASM_CLAC |
Ingo Molnar | dca5b52 | 2015-03-24 19:44:42 +0100 | [diff] [blame] | 391 | orl $TS_COMPAT, ASM_THREAD_INFO(TI_status, %rsp, SIZEOF_PTREGS) |
| 392 | testl $_TIF_WORK_SYSCALL_ENTRY, ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS) |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 393 | CFI_REMEMBER_STATE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | jnz cstar_tracesys |
H. Peter Anvin | 36d001c | 2010-09-14 12:42:41 -0700 | [diff] [blame] | 395 | cmpq $IA32_NR_syscalls-1,%rax |
Andi Kleen | 67d53ea | 2006-04-07 19:50:31 +0200 | [diff] [blame] | 396 | ja ia32_badsys |
Jan Beulich | 295286a8 | 2008-08-29 13:21:11 +0100 | [diff] [blame] | 397 | cstar_do_call: |
Denys Vlasenko | 14f6e95 | 2015-02-26 14:40:35 -0800 | [diff] [blame] | 398 | /* 32bit syscall -> 64bit C ABI argument conversion */ |
| 399 | movl %edi,%r8d /* arg5 */ |
| 400 | /* r9 already loaded */ /* arg6 */ |
| 401 | xchg %ecx,%esi /* rsi:arg2, rcx:arg4 */ |
| 402 | movl %ebx,%edi /* arg1 */ |
| 403 | movl %edx,%edx /* arg3 (zero extension) */ |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 404 | cstar_dispatch: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | call *ia32_sys_call_table(,%rax,8) |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 406 | movq %rax,RAX(%rsp) |
Jeremy Fitzhardinge | 6680415 | 2008-06-25 00:19:29 -0400 | [diff] [blame] | 407 | DISABLE_INTERRUPTS(CLBR_NONE) |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 408 | TRACE_IRQS_OFF |
Ingo Molnar | dca5b52 | 2015-03-24 19:44:42 +0100 | [diff] [blame] | 409 | testl $_TIF_ALLWORK_MASK, ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS) |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 410 | jnz sysretl_audit |
| 411 | sysretl_from_sys_call: |
Ingo Molnar | dca5b52 | 2015-03-24 19:44:42 +0100 | [diff] [blame] | 412 | andl $~TS_COMPAT, ASM_THREAD_INFO(TI_status, %rsp, SIZEOF_PTREGS) |
Denys Vlasenko | 76f5df4 | 2015-02-26 14:40:27 -0800 | [diff] [blame] | 413 | RESTORE_RSI_RDI_RDX |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 414 | movl RIP(%rsp),%ecx |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 415 | CFI_REGISTER rip,rcx |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 416 | movl EFLAGS(%rsp),%r11d |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 417 | /*CFI_REGISTER rflags,r11*/ |
Jan Beulich | 24e3580 | 2009-09-30 11:22:11 +0100 | [diff] [blame] | 418 | xorq %r10,%r10 |
| 419 | xorq %r9,%r9 |
| 420 | xorq %r8,%r8 |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 421 | TRACE_IRQS_ON |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 422 | movl RSP(%rsp),%esp |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 423 | CFI_RESTORE rsp |
Denys Vlasenko | b87cf63 | 2015-02-26 14:40:32 -0800 | [diff] [blame] | 424 | /* |
| 425 | * 64bit->32bit SYSRET restores eip from ecx, |
| 426 | * eflags from r11 (but RF and VM bits are forced to 0), |
| 427 | * cs and ss are loaded from MSRs. |
| 428 | * (Note: 32bit->32bit SYSRET is different: since r11 |
| 429 | * does not exist, it merely sets eflags.IF=1). |
Andy Lutomirski | 61f01dd | 2015-04-26 16:47:59 -0700 | [diff] [blame^] | 430 | * |
| 431 | * NB: On AMD CPUs with the X86_BUG_SYSRET_SS_ATTRS bug, the ss |
| 432 | * descriptor is not reinitialized. This means that we must |
| 433 | * avoid SYSRET with SS == NULL, which could happen if we schedule, |
| 434 | * exit the kernel, and re-enter using an interrupt vector. (All |
| 435 | * interrupt entries on x86_64 set SS to NULL.) We prevent that |
| 436 | * from happening by reloading SS in __switch_to. |
Denys Vlasenko | b87cf63 | 2015-02-26 14:40:32 -0800 | [diff] [blame] | 437 | */ |
Jeremy Fitzhardinge | 2be2998 | 2008-06-25 00:19:28 -0400 | [diff] [blame] | 438 | USERGS_SYSRET32 |
Denys Vlasenko | b87cf63 | 2015-02-26 14:40:32 -0800 | [diff] [blame] | 439 | |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 440 | #ifdef CONFIG_AUDITSYSCALL |
| 441 | cstar_auditsys: |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 442 | CFI_RESTORE_STATE |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 443 | movl %r9d,R9(%rsp) /* register to be clobbered by call */ |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 444 | auditsys_entry_common |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 445 | movl R9(%rsp),%r9d /* reload 6th syscall arg */ |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 446 | jmp cstar_dispatch |
| 447 | |
| 448 | sysretl_audit: |
Jan Beulich | 8176674 | 2009-10-26 15:20:29 +0000 | [diff] [blame] | 449 | auditsys_exit sysretl_from_sys_call |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 450 | #endif |
| 451 | |
| 452 | cstar_tracesys: |
| 453 | #ifdef CONFIG_AUDITSYSCALL |
Ingo Molnar | dca5b52 | 2015-03-24 19:44:42 +0100 | [diff] [blame] | 454 | testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT), ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS) |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 455 | jz cstar_auditsys |
| 456 | #endif |
Chuck Ebbert | ecd744e | 2007-11-07 10:48:39 -0500 | [diff] [blame] | 457 | xchgl %r9d,%ebp |
Denys Vlasenko | 76f5df4 | 2015-02-26 14:40:27 -0800 | [diff] [blame] | 458 | SAVE_EXTRA_REGS |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 459 | CLEAR_RREGS r9 |
Roland McGrath | 48ee679 | 2008-03-18 18:23:50 -0700 | [diff] [blame] | 460 | movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | movq %rsp,%rdi /* &pt_regs -> arg1 */ |
| 462 | call syscall_trace_enter |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 463 | LOAD_ARGS32 1 /* reload args from stack in case ptrace changed it */ |
Denys Vlasenko | 76f5df4 | 2015-02-26 14:40:27 -0800 | [diff] [blame] | 464 | RESTORE_EXTRA_REGS |
Chuck Ebbert | ecd744e | 2007-11-07 10:48:39 -0500 | [diff] [blame] | 465 | xchgl %ebp,%r9d |
H. Peter Anvin | 36d001c | 2010-09-14 12:42:41 -0700 | [diff] [blame] | 466 | cmpq $(IA32_NR_syscalls-1),%rax |
Roland McGrath | 48ee679 | 2008-03-18 18:23:50 -0700 | [diff] [blame] | 467 | ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | jmp cstar_do_call |
Jan Beulich | 4b787e0 | 2006-06-26 13:56:55 +0200 | [diff] [blame] | 469 | END(ia32_cstar_target) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | |
| 471 | ia32_badarg: |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 472 | ASM_CLAC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | movq $-EFAULT,%rax |
| 474 | jmp ia32_sysret |
| 475 | CFI_ENDPROC |
| 476 | |
Denys Vlasenko | b87cf63 | 2015-02-26 14:40:32 -0800 | [diff] [blame] | 477 | /* |
| 478 | * Emulated IA32 system calls via int 0x80. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | * |
Denys Vlasenko | b87cf63 | 2015-02-26 14:40:32 -0800 | [diff] [blame] | 480 | * Arguments: |
| 481 | * eax system call number |
| 482 | * ebx arg1 |
| 483 | * ecx arg2 |
| 484 | * edx arg3 |
| 485 | * esi arg4 |
| 486 | * edi arg5 |
| 487 | * ebp arg6 (note: not saved in the stack frame, should not be touched) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | * |
| 489 | * Notes: |
Denys Vlasenko | b87cf63 | 2015-02-26 14:40:32 -0800 | [diff] [blame] | 490 | * Uses the same stack frame as the x86-64 version. |
| 491 | * All registers except eax must be saved (but ptrace may violate that). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | * Arguments are zero extended. For system calls that want sign extension and |
| 493 | * take long arguments a wrapper is needed. Most calls can just be called |
| 494 | * directly. |
Denys Vlasenko | b87cf63 | 2015-02-26 14:40:32 -0800 | [diff] [blame] | 495 | * Assumes it is only called from user space and entered with interrupts off. |
| 496 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | |
| 498 | ENTRY(ia32_syscall) |
Jan Beulich | cdc1793 | 2007-07-21 17:10:20 +0200 | [diff] [blame] | 499 | CFI_STARTPROC32 simple |
Jan Beulich | adf1423 | 2006-09-26 10:52:41 +0200 | [diff] [blame] | 500 | CFI_SIGNAL_FRAME |
Denys Vlasenko | a232e3d | 2015-03-27 11:36:20 +0100 | [diff] [blame] | 501 | CFI_DEF_CFA rsp,5*8 |
| 502 | /*CFI_REL_OFFSET ss,4*8 */ |
| 503 | CFI_REL_OFFSET rsp,3*8 |
| 504 | /*CFI_REL_OFFSET rflags,2*8 */ |
| 505 | /*CFI_REL_OFFSET cs,1*8 */ |
| 506 | CFI_REL_OFFSET rip,0*8 |
| 507 | |
| 508 | /* |
| 509 | * Interrupts are off on entry. |
| 510 | * We do not frame this tiny irq-off block with TRACE_IRQS_OFF/ON, |
| 511 | * it is too small to ever cause noticeable irq latency. |
| 512 | */ |
Jeremy Fitzhardinge | 360c044 | 2008-07-08 15:06:28 -0700 | [diff] [blame] | 513 | PARAVIRT_ADJUST_EXCEPTION_FRAME |
Jeremy Fitzhardinge | 6680415 | 2008-06-25 00:19:29 -0400 | [diff] [blame] | 514 | SWAPGS |
Jeremy Fitzhardinge | 6680415 | 2008-06-25 00:19:29 -0400 | [diff] [blame] | 515 | ENABLE_INTERRUPTS(CLBR_NONE) |
Denys Vlasenko | a232e3d | 2015-03-27 11:36:20 +0100 | [diff] [blame] | 516 | |
Denys Vlasenko | 4ee8ec1 | 2015-03-27 11:36:21 +0100 | [diff] [blame] | 517 | /* Zero-extending 32-bit regs, do not remove */ |
| 518 | movl %eax,%eax |
| 519 | |
Denys Vlasenko | 4c9c0e9 | 2015-03-31 19:00:04 +0200 | [diff] [blame] | 520 | /* Construct struct pt_regs on stack (iret frame is already on stack) */ |
| 521 | pushq_cfi_reg rax /* pt_regs->orig_ax */ |
| 522 | pushq_cfi_reg rdi /* pt_regs->di */ |
| 523 | pushq_cfi_reg rsi /* pt_regs->si */ |
| 524 | pushq_cfi_reg rdx /* pt_regs->dx */ |
| 525 | pushq_cfi_reg rcx /* pt_regs->cx */ |
| 526 | pushq_cfi_reg rax /* pt_regs->ax */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | cld |
Denys Vlasenko | 4c9c0e9 | 2015-03-31 19:00:04 +0200 | [diff] [blame] | 528 | sub $(10*8),%rsp /* pt_regs->r8-11,bp,bx,r12-15 not saved */ |
| 529 | CFI_ADJUST_CFA_OFFSET 10*8 |
| 530 | |
Ingo Molnar | dca5b52 | 2015-03-24 19:44:42 +0100 | [diff] [blame] | 531 | orl $TS_COMPAT, ASM_THREAD_INFO(TI_status, %rsp, SIZEOF_PTREGS) |
| 532 | testl $_TIF_WORK_SYSCALL_ENTRY, ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | jnz ia32_tracesys |
H. Peter Anvin | 36d001c | 2010-09-14 12:42:41 -0700 | [diff] [blame] | 534 | cmpq $(IA32_NR_syscalls-1),%rax |
Roland McGrath | c09249f | 2009-02-06 18:15:18 -0800 | [diff] [blame] | 535 | ja ia32_badsys |
| 536 | ia32_do_call: |
Denys Vlasenko | 14f6e95 | 2015-02-26 14:40:35 -0800 | [diff] [blame] | 537 | /* 32bit syscall -> 64bit C ABI argument conversion */ |
| 538 | movl %edi,%r8d /* arg5 */ |
| 539 | movl %ebp,%r9d /* arg6 */ |
| 540 | xchg %ecx,%esi /* rsi:arg2, rcx:arg4 */ |
| 541 | movl %ebx,%edi /* arg1 */ |
| 542 | movl %edx,%edx /* arg3 (zero extension) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | call *ia32_sys_call_table(,%rax,8) # xxx: rip relative |
| 544 | ia32_sysret: |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 545 | movq %rax,RAX(%rsp) |
Jan Beulich | 24e3580 | 2009-09-30 11:22:11 +0100 | [diff] [blame] | 546 | ia32_ret_from_sys_call: |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 547 | CLEAR_RREGS |
Denys Vlasenko | 76f5df4 | 2015-02-26 14:40:27 -0800 | [diff] [blame] | 548 | jmp int_ret_from_sys_call |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | |
Denys Vlasenko | 76f5df4 | 2015-02-26 14:40:27 -0800 | [diff] [blame] | 550 | ia32_tracesys: |
| 551 | SAVE_EXTRA_REGS |
Jan Beulich | cdc1793 | 2007-07-21 17:10:20 +0200 | [diff] [blame] | 552 | CLEAR_RREGS |
Roland McGrath | 8ab32bb | 2008-03-16 21:57:41 -0700 | [diff] [blame] | 553 | movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | movq %rsp,%rdi /* &pt_regs -> arg1 */ |
| 555 | call syscall_trace_enter |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 556 | LOAD_ARGS32 /* reload args from stack in case ptrace changed it */ |
Denys Vlasenko | 76f5df4 | 2015-02-26 14:40:27 -0800 | [diff] [blame] | 557 | RESTORE_EXTRA_REGS |
H. Peter Anvin | 36d001c | 2010-09-14 12:42:41 -0700 | [diff] [blame] | 558 | cmpq $(IA32_NR_syscalls-1),%rax |
Roland McGrath | c09249f | 2009-02-06 18:15:18 -0800 | [diff] [blame] | 559 | ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */ |
| 560 | jmp ia32_do_call |
Jan Beulich | 4b787e0 | 2006-06-26 13:56:55 +0200 | [diff] [blame] | 561 | END(ia32_syscall) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | |
| 563 | ia32_badsys: |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 564 | movq $0,ORIG_RAX(%rsp) |
Jan Beulich | 24e3580 | 2009-09-30 11:22:11 +0100 | [diff] [blame] | 565 | movq $-ENOSYS,%rax |
| 566 | jmp ia32_sysret |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | CFI_ENDPROC |
| 569 | |
Ramkumar Ramachandra | d2475b8 | 2013-07-10 23:34:28 +0530 | [diff] [blame] | 570 | .macro PTREGSCALL label, func |
Jan Beulich | f6b2bc8 | 2011-11-29 11:24:10 +0000 | [diff] [blame] | 571 | ALIGN |
| 572 | GLOBAL(\label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | leaq \func(%rip),%rax |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | jmp ia32_ptregs_common |
| 575 | .endm |
| 576 | |
Jan Beulich | 2765130 | 2006-01-11 22:41:59 +0100 | [diff] [blame] | 577 | CFI_STARTPROC32 |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 578 | |
Al Viro | 3fe26fa | 2012-11-12 14:32:42 -0500 | [diff] [blame] | 579 | PTREGSCALL stub32_rt_sigreturn, sys32_rt_sigreturn |
| 580 | PTREGSCALL stub32_sigreturn, sys32_sigreturn |
Al Viro | 3fe26fa | 2012-11-12 14:32:42 -0500 | [diff] [blame] | 581 | PTREGSCALL stub32_fork, sys_fork |
| 582 | PTREGSCALL stub32_vfork, sys_vfork |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | |
Jan Beulich | f6b2bc8 | 2011-11-29 11:24:10 +0000 | [diff] [blame] | 584 | ALIGN |
Al Viro | 1d4b4b2 | 2012-10-22 22:34:11 -0400 | [diff] [blame] | 585 | GLOBAL(stub32_clone) |
| 586 | leaq sys_clone(%rip),%rax |
| 587 | mov %r8, %rcx |
| 588 | jmp ia32_ptregs_common |
| 589 | |
| 590 | ALIGN |
Jan Beulich | f6b2bc8 | 2011-11-29 11:24:10 +0000 | [diff] [blame] | 591 | ia32_ptregs_common: |
Jan Beulich | 2765130 | 2006-01-11 22:41:59 +0100 | [diff] [blame] | 592 | CFI_ENDPROC |
| 593 | CFI_STARTPROC32 simple |
Jan Beulich | adf1423 | 2006-09-26 10:52:41 +0200 | [diff] [blame] | 594 | CFI_SIGNAL_FRAME |
Denys Vlasenko | b3ab90b | 2015-02-26 14:40:37 -0800 | [diff] [blame] | 595 | CFI_DEF_CFA rsp,SIZEOF_PTREGS |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 596 | CFI_REL_OFFSET rax,RAX |
| 597 | CFI_REL_OFFSET rcx,RCX |
| 598 | CFI_REL_OFFSET rdx,RDX |
| 599 | CFI_REL_OFFSET rsi,RSI |
| 600 | CFI_REL_OFFSET rdi,RDI |
| 601 | CFI_REL_OFFSET rip,RIP |
| 602 | /* CFI_REL_OFFSET cs,CS*/ |
| 603 | /* CFI_REL_OFFSET rflags,EFLAGS*/ |
| 604 | CFI_REL_OFFSET rsp,RSP |
| 605 | /* CFI_REL_OFFSET ss,SS*/ |
Denys Vlasenko | 76f5df4 | 2015-02-26 14:40:27 -0800 | [diff] [blame] | 606 | SAVE_EXTRA_REGS 8 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | call *%rax |
Denys Vlasenko | 76f5df4 | 2015-02-26 14:40:27 -0800 | [diff] [blame] | 608 | RESTORE_EXTRA_REGS 8 |
| 609 | ret |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | CFI_ENDPROC |
Jan Beulich | 4b787e0 | 2006-06-26 13:56:55 +0200 | [diff] [blame] | 611 | END(ia32_ptregs_common) |