Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Jeremy Fitzhardinge | cdacc12 | 2008-07-08 15:06:46 -0700 | [diff] [blame] | 2 | /* |
Juergen Gross | edcb5cf | 2017-08-16 19:31:56 +0200 | [diff] [blame] | 3 | * Asm versions of Xen pv-ops, suitable for direct use. |
Tejun Heo | 130ace1 | 2009-02-06 00:57:48 +0900 | [diff] [blame] | 4 | * |
| 5 | * We only bother with direct forms (ie, vcpu in pda) of the |
Juergen Gross | edcb5cf | 2017-08-16 19:31:56 +0200 | [diff] [blame] | 6 | * operations here; the indirect forms are better handled in C. |
Jeremy Fitzhardinge | cdacc12 | 2008-07-08 15:06:46 -0700 | [diff] [blame] | 7 | */ |
| 8 | |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 9 | #include <asm/errno.h> |
Brian Gerst | 9af4565 | 2009-01-19 00:38:58 +0900 | [diff] [blame] | 10 | #include <asm/percpu.h> |
Jeremy Fitzhardinge | 5393744 | 2009-02-02 13:55:42 -0800 | [diff] [blame] | 11 | #include <asm/processor-flags.h> |
| 12 | #include <asm/segment.h> |
Denys Vlasenko | 63332a8 | 2015-04-24 17:31:33 +0200 | [diff] [blame] | 13 | #include <asm/asm-offsets.h> |
Denys Vlasenko | 3a23208 | 2015-04-24 17:31:35 +0200 | [diff] [blame] | 14 | #include <asm/thread_info.h> |
Jeremy Fitzhardinge | cdacc12 | 2008-07-08 15:06:46 -0700 | [diff] [blame] | 15 | |
| 16 | #include <xen/interface/xen.h> |
| 17 | |
Juergen Gross | edcb5cf | 2017-08-16 19:31:56 +0200 | [diff] [blame] | 18 | #include <linux/linkage.h> |
Jeremy Fitzhardinge | cdacc12 | 2008-07-08 15:06:46 -0700 | [diff] [blame] | 19 | |
Juergen Gross | 5878d5d | 2017-08-31 19:42:49 +0200 | [diff] [blame] | 20 | .macro xen_pv_trap name |
| 21 | ENTRY(xen_\name) |
| 22 | pop %rcx |
| 23 | pop %r11 |
| 24 | jmp \name |
| 25 | END(xen_\name) |
| 26 | .endm |
| 27 | |
| 28 | xen_pv_trap divide_error |
| 29 | xen_pv_trap debug |
| 30 | xen_pv_trap xendebug |
| 31 | xen_pv_trap int3 |
| 32 | xen_pv_trap xenint3 |
| 33 | xen_pv_trap nmi |
| 34 | xen_pv_trap overflow |
| 35 | xen_pv_trap bounds |
| 36 | xen_pv_trap invalid_op |
| 37 | xen_pv_trap device_not_available |
| 38 | xen_pv_trap double_fault |
| 39 | xen_pv_trap coprocessor_segment_overrun |
| 40 | xen_pv_trap invalid_TSS |
| 41 | xen_pv_trap segment_not_present |
| 42 | xen_pv_trap stack_segment |
| 43 | xen_pv_trap general_protection |
| 44 | xen_pv_trap page_fault |
| 45 | xen_pv_trap spurious_interrupt_bug |
| 46 | xen_pv_trap coprocessor_error |
| 47 | xen_pv_trap alignment_check |
| 48 | #ifdef CONFIG_X86_MCE |
| 49 | xen_pv_trap machine_check |
| 50 | #endif /* CONFIG_X86_MCE */ |
| 51 | xen_pv_trap simd_coprocessor_error |
| 52 | #ifdef CONFIG_IA32_EMULATION |
| 53 | xen_pv_trap entry_INT80_compat |
| 54 | #endif |
| 55 | xen_pv_trap hypervisor_callback |
Jeremy Fitzhardinge | 997409d | 2008-07-08 15:07:00 -0700 | [diff] [blame] | 56 | |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 57 | hypercall_iret = hypercall_page + __HYPERVISOR_iret * 32 |
| 58 | /* |
Tejun Heo | 130ace1 | 2009-02-06 00:57:48 +0900 | [diff] [blame] | 59 | * Xen64 iret frame: |
| 60 | * |
| 61 | * ss |
| 62 | * rsp |
| 63 | * rflags |
| 64 | * cs |
| 65 | * rip <-- standard iret frame |
| 66 | * |
| 67 | * flags |
| 68 | * |
| 69 | * rcx } |
| 70 | * r11 }<-- pushed by hypercall page |
| 71 | * rsp->rax } |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 72 | */ |
Jeremy Fitzhardinge | cdacc12 | 2008-07-08 15:06:46 -0700 | [diff] [blame] | 73 | ENTRY(xen_iret) |
| 74 | pushq $0 |
Juergen Gross | edcb5cf | 2017-08-16 19:31:56 +0200 | [diff] [blame] | 75 | jmp hypercall_iret |
Jeremy Fitzhardinge | cdacc12 | 2008-07-08 15:06:46 -0700 | [diff] [blame] | 76 | |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 77 | ENTRY(xen_sysret64) |
Tejun Heo | 130ace1 | 2009-02-06 00:57:48 +0900 | [diff] [blame] | 78 | /* |
| 79 | * We're already on the usermode stack at this point, but |
| 80 | * still with the kernel gs, so we can easily switch back |
| 81 | */ |
Ingo Molnar | c38e503 | 2015-03-17 14:42:59 +0100 | [diff] [blame] | 82 | movq %rsp, PER_CPU_VAR(rsp_scratch) |
Denys Vlasenko | 3a23208 | 2015-04-24 17:31:35 +0200 | [diff] [blame] | 83 | movq PER_CPU_VAR(cpu_current_top_of_stack), %rsp |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 84 | |
| 85 | pushq $__USER_DS |
Ingo Molnar | c38e503 | 2015-03-17 14:42:59 +0100 | [diff] [blame] | 86 | pushq PER_CPU_VAR(rsp_scratch) |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 87 | pushq %r11 |
| 88 | pushq $__USER_CS |
| 89 | pushq %rcx |
| 90 | |
| 91 | pushq $VGCF_in_syscall |
Juergen Gross | edcb5cf | 2017-08-16 19:31:56 +0200 | [diff] [blame] | 92 | jmp hypercall_iret |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 93 | |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 94 | /* |
Tejun Heo | 130ace1 | 2009-02-06 00:57:48 +0900 | [diff] [blame] | 95 | * Xen handles syscall callbacks much like ordinary exceptions, which |
| 96 | * means we have: |
| 97 | * - kernel gs |
| 98 | * - kernel rsp |
| 99 | * - an iret-like stack frame on the stack (including rcx and r11): |
| 100 | * ss |
| 101 | * rsp |
| 102 | * rflags |
| 103 | * cs |
| 104 | * rip |
| 105 | * r11 |
| 106 | * rsp->rcx |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 107 | */ |
| 108 | |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 109 | /* Normal 64-bit system call target */ |
| 110 | ENTRY(xen_syscall_target) |
Andy Lutomirski | 8a9949b | 2017-08-07 20:59:21 -0700 | [diff] [blame] | 111 | popq %rcx |
| 112 | popq %r11 |
Andy Lutomirski | fa2016a | 2017-08-14 22:36:19 -0700 | [diff] [blame] | 113 | |
| 114 | /* |
| 115 | * Neither Xen nor the kernel really knows what the old SS and |
| 116 | * CS were. The kernel expects __USER_DS and __USER_CS, so |
| 117 | * report those values even though Xen will guess its own values. |
| 118 | */ |
| 119 | movq $__USER_DS, 4*8(%rsp) |
| 120 | movq $__USER_CS, 1*8(%rsp) |
| 121 | |
Andy Lutomirski | 8a9949b | 2017-08-07 20:59:21 -0700 | [diff] [blame] | 122 | jmp entry_SYSCALL_64_after_hwframe |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 123 | ENDPROC(xen_syscall_target) |
| 124 | |
| 125 | #ifdef CONFIG_IA32_EMULATION |
| 126 | |
| 127 | /* 32-bit compat syscall target */ |
| 128 | ENTRY(xen_syscall32_target) |
Andy Lutomirski | 8a9949b | 2017-08-07 20:59:21 -0700 | [diff] [blame] | 129 | popq %rcx |
| 130 | popq %r11 |
Andy Lutomirski | fa2016a | 2017-08-14 22:36:19 -0700 | [diff] [blame] | 131 | |
| 132 | /* |
| 133 | * Neither Xen nor the kernel really knows what the old SS and |
| 134 | * CS were. The kernel expects __USER32_DS and __USER32_CS, so |
| 135 | * report those values even though Xen will guess its own values. |
| 136 | */ |
| 137 | movq $__USER32_DS, 4*8(%rsp) |
| 138 | movq $__USER32_CS, 1*8(%rsp) |
| 139 | |
Andy Lutomirski | 8a9949b | 2017-08-07 20:59:21 -0700 | [diff] [blame] | 140 | jmp entry_SYSCALL_compat_after_hwframe |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 141 | ENDPROC(xen_syscall32_target) |
| 142 | |
| 143 | /* 32-bit compat sysenter target */ |
| 144 | ENTRY(xen_sysenter_target) |
Andy Lutomirski | 8a9949b | 2017-08-07 20:59:21 -0700 | [diff] [blame] | 145 | mov 0*8(%rsp), %rcx |
| 146 | mov 1*8(%rsp), %r11 |
| 147 | mov 5*8(%rsp), %rsp |
Ingo Molnar | 4c8cd0c | 2015-06-08 08:33:56 +0200 | [diff] [blame] | 148 | jmp entry_SYSENTER_compat |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 149 | ENDPROC(xen_sysenter_target) |
| 150 | |
| 151 | #else /* !CONFIG_IA32_EMULATION */ |
| 152 | |
| 153 | ENTRY(xen_syscall32_target) |
| 154 | ENTRY(xen_sysenter_target) |
Tejun Heo | 130ace1 | 2009-02-06 00:57:48 +0900 | [diff] [blame] | 155 | lea 16(%rsp), %rsp /* strip %rcx, %r11 */ |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 156 | mov $-ENOSYS, %rax |
Jeremy Fitzhardinge | 6aaf5d6 | 2009-11-25 13:15:38 -0800 | [diff] [blame] | 157 | pushq $0 |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 158 | jmp hypercall_iret |
| 159 | ENDPROC(xen_syscall32_target) |
| 160 | ENDPROC(xen_sysenter_target) |
| 161 | |
| 162 | #endif /* CONFIG_IA32_EMULATION */ |