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