Jeremy Fitzhardinge | cdacc12 | 2008-07-08 15:06:46 -0700 | [diff] [blame] | 1 | /* |
Tejun Heo | 130ace1 | 2009-02-06 00:57:48 +0900 | [diff] [blame] | 2 | * Asm versions of Xen pv-ops, suitable for either direct use or |
| 3 | * inlining. The inline versions are the same as the direct-use |
| 4 | * versions, with the pre- and post-amble chopped off. |
| 5 | * |
| 6 | * This code is encoded for size rather than absolute efficiency, with |
| 7 | * a view to being able to inline as much as possible. |
| 8 | * |
| 9 | * We only bother with direct forms (ie, vcpu in pda) of the |
| 10 | * operations here; the indirect forms are better handled in C, since |
| 11 | * they're generally too large to inline anyway. |
Jeremy Fitzhardinge | cdacc12 | 2008-07-08 15:06:46 -0700 | [diff] [blame] | 12 | */ |
| 13 | |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 14 | #include <asm/errno.h> |
Brian Gerst | 9af4565 | 2009-01-19 00:38:58 +0900 | [diff] [blame] | 15 | #include <asm/percpu.h> |
Jeremy Fitzhardinge | 5393744 | 2009-02-02 13:55:42 -0800 | [diff] [blame] | 16 | #include <asm/processor-flags.h> |
| 17 | #include <asm/segment.h> |
Jeremy Fitzhardinge | cdacc12 | 2008-07-08 15:06:46 -0700 | [diff] [blame] | 18 | |
| 19 | #include <xen/interface/xen.h> |
| 20 | |
Jeremy Fitzhardinge | 5393744 | 2009-02-02 13:55:42 -0800 | [diff] [blame] | 21 | #include "xen-asm.h" |
Jeremy Fitzhardinge | cdacc12 | 2008-07-08 15:06:46 -0700 | [diff] [blame] | 22 | |
Jeremy Fitzhardinge | 997409d | 2008-07-08 15:07:00 -0700 | [diff] [blame] | 23 | ENTRY(xen_adjust_exception_frame) |
Tejun Heo | 130ace1 | 2009-02-06 00:57:48 +0900 | [diff] [blame] | 24 | mov 8+0(%rsp), %rcx |
| 25 | mov 8+8(%rsp), %r11 |
Jeremy Fitzhardinge | 997409d | 2008-07-08 15:07:00 -0700 | [diff] [blame] | 26 | ret $16 |
| 27 | |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 28 | hypercall_iret = hypercall_page + __HYPERVISOR_iret * 32 |
| 29 | /* |
Tejun Heo | 130ace1 | 2009-02-06 00:57:48 +0900 | [diff] [blame] | 30 | * Xen64 iret frame: |
| 31 | * |
| 32 | * ss |
| 33 | * rsp |
| 34 | * rflags |
| 35 | * cs |
| 36 | * rip <-- standard iret frame |
| 37 | * |
| 38 | * flags |
| 39 | * |
| 40 | * rcx } |
| 41 | * r11 }<-- pushed by hypercall page |
| 42 | * rsp->rax } |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 43 | */ |
Jeremy Fitzhardinge | cdacc12 | 2008-07-08 15:06:46 -0700 | [diff] [blame] | 44 | ENTRY(xen_iret) |
| 45 | pushq $0 |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 46 | 1: jmp hypercall_iret |
| 47 | ENDPATCH(xen_iret) |
| 48 | RELOC(xen_iret, 1b+1) |
Jeremy Fitzhardinge | cdacc12 | 2008-07-08 15:06:46 -0700 | [diff] [blame] | 49 | |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 50 | ENTRY(xen_sysret64) |
Tejun Heo | 130ace1 | 2009-02-06 00:57:48 +0900 | [diff] [blame] | 51 | /* |
| 52 | * We're already on the usermode stack at this point, but |
| 53 | * still with the kernel gs, so we can easily switch back |
| 54 | */ |
Ingo Molnar | c38e503 | 2015-03-17 14:42:59 +0100 | [diff] [blame] | 55 | movq %rsp, PER_CPU_VAR(rsp_scratch) |
Tejun Heo | 130ace1 | 2009-02-06 00:57:48 +0900 | [diff] [blame] | 56 | movq PER_CPU_VAR(kernel_stack), %rsp |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 57 | |
| 58 | pushq $__USER_DS |
Ingo Molnar | c38e503 | 2015-03-17 14:42:59 +0100 | [diff] [blame] | 59 | pushq PER_CPU_VAR(rsp_scratch) |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 60 | pushq %r11 |
| 61 | pushq $__USER_CS |
| 62 | pushq %rcx |
| 63 | |
| 64 | pushq $VGCF_in_syscall |
| 65 | 1: jmp hypercall_iret |
| 66 | ENDPATCH(xen_sysret64) |
| 67 | RELOC(xen_sysret64, 1b+1) |
| 68 | |
| 69 | ENTRY(xen_sysret32) |
Tejun Heo | 130ace1 | 2009-02-06 00:57:48 +0900 | [diff] [blame] | 70 | /* |
| 71 | * We're already on the usermode stack at this point, but |
| 72 | * still with the kernel gs, so we can easily switch back |
| 73 | */ |
Ingo Molnar | c38e503 | 2015-03-17 14:42:59 +0100 | [diff] [blame] | 74 | movq %rsp, PER_CPU_VAR(rsp_scratch) |
Brian Gerst | 9af4565 | 2009-01-19 00:38:58 +0900 | [diff] [blame] | 75 | movq PER_CPU_VAR(kernel_stack), %rsp |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 76 | |
| 77 | pushq $__USER32_DS |
Ingo Molnar | c38e503 | 2015-03-17 14:42:59 +0100 | [diff] [blame] | 78 | pushq PER_CPU_VAR(rsp_scratch) |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 79 | pushq %r11 |
| 80 | pushq $__USER32_CS |
| 81 | pushq %rcx |
| 82 | |
Jeremy Fitzhardinge | 6aaf5d6 | 2009-11-25 13:15:38 -0800 | [diff] [blame] | 83 | pushq $0 |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 84 | 1: jmp hypercall_iret |
| 85 | ENDPATCH(xen_sysret32) |
| 86 | RELOC(xen_sysret32, 1b+1) |
| 87 | |
| 88 | /* |
Tejun Heo | 130ace1 | 2009-02-06 00:57:48 +0900 | [diff] [blame] | 89 | * Xen handles syscall callbacks much like ordinary exceptions, which |
| 90 | * means we have: |
| 91 | * - kernel gs |
| 92 | * - kernel rsp |
| 93 | * - an iret-like stack frame on the stack (including rcx and r11): |
| 94 | * ss |
| 95 | * rsp |
| 96 | * rflags |
| 97 | * cs |
| 98 | * rip |
| 99 | * r11 |
| 100 | * rsp->rcx |
| 101 | * |
| 102 | * In all the entrypoints, we undo all that to make it look like a |
| 103 | * CPU-generated syscall/sysenter and jump to the normal entrypoint. |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 104 | */ |
| 105 | |
| 106 | .macro undo_xen_syscall |
Tejun Heo | 130ace1 | 2009-02-06 00:57:48 +0900 | [diff] [blame] | 107 | mov 0*8(%rsp), %rcx |
| 108 | mov 1*8(%rsp), %r11 |
| 109 | mov 5*8(%rsp), %rsp |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 110 | .endm |
| 111 | |
| 112 | /* Normal 64-bit system call target */ |
| 113 | ENTRY(xen_syscall_target) |
| 114 | undo_xen_syscall |
| 115 | jmp system_call_after_swapgs |
| 116 | ENDPROC(xen_syscall_target) |
| 117 | |
| 118 | #ifdef CONFIG_IA32_EMULATION |
| 119 | |
| 120 | /* 32-bit compat syscall target */ |
| 121 | ENTRY(xen_syscall32_target) |
| 122 | undo_xen_syscall |
| 123 | jmp ia32_cstar_target |
| 124 | ENDPROC(xen_syscall32_target) |
| 125 | |
| 126 | /* 32-bit compat sysenter target */ |
| 127 | ENTRY(xen_sysenter_target) |
| 128 | undo_xen_syscall |
| 129 | jmp ia32_sysenter_target |
| 130 | ENDPROC(xen_sysenter_target) |
| 131 | |
| 132 | #else /* !CONFIG_IA32_EMULATION */ |
| 133 | |
| 134 | ENTRY(xen_syscall32_target) |
| 135 | ENTRY(xen_sysenter_target) |
Tejun Heo | 130ace1 | 2009-02-06 00:57:48 +0900 | [diff] [blame] | 136 | lea 16(%rsp), %rsp /* strip %rcx, %r11 */ |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 137 | mov $-ENOSYS, %rax |
Jeremy Fitzhardinge | 6aaf5d6 | 2009-11-25 13:15:38 -0800 | [diff] [blame] | 138 | pushq $0 |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 139 | jmp hypercall_iret |
| 140 | ENDPROC(xen_syscall32_target) |
| 141 | ENDPROC(xen_sysenter_target) |
| 142 | |
| 143 | #endif /* CONFIG_IA32_EMULATION */ |