Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Jeremy Fitzhardinge | 5393744 | 2009-02-02 13:55:42 -0800 | [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 percpu data) 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 | 5393744 | 2009-02-02 13:55:42 -0800 | [diff] [blame] | 7 | */ |
| 8 | |
Juergen Gross | 56415c4 | 2020-07-03 09:16:19 +0200 | [diff] [blame] | 9 | #include <asm/errno.h> |
Jeremy Fitzhardinge | 5393744 | 2009-02-02 13:55:42 -0800 | [diff] [blame] | 10 | #include <asm/asm-offsets.h> |
| 11 | #include <asm/percpu.h> |
| 12 | #include <asm/processor-flags.h> |
Juergen Gross | 56415c4 | 2020-07-03 09:16:19 +0200 | [diff] [blame] | 13 | #include <asm/segment.h> |
| 14 | #include <asm/thread_info.h> |
Peter Zijlstra | 55aeddd | 2019-07-11 13:40:55 +0200 | [diff] [blame] | 15 | #include <asm/asm.h> |
Juergen Gross | 56415c4 | 2020-07-03 09:16:19 +0200 | [diff] [blame] | 16 | #include <asm/frame.h> |
Josh Poimboeuf | cde07a4 | 2021-01-21 15:29:28 -0600 | [diff] [blame] | 17 | #include <asm/unwind_hints.h> |
Jeremy Fitzhardinge | 5393744 | 2009-02-02 13:55:42 -0800 | [diff] [blame] | 18 | |
Juergen Gross | 56415c4 | 2020-07-03 09:16:19 +0200 | [diff] [blame] | 19 | #include <xen/interface/xen.h> |
| 20 | |
| 21 | #include <linux/init.h> |
Juergen Gross | edcb5cf | 2017-08-16 19:31:56 +0200 | [diff] [blame] | 22 | #include <linux/linkage.h> |
Jeremy Fitzhardinge | 5393744 | 2009-02-02 13:55:42 -0800 | [diff] [blame] | 23 | |
| 24 | /* |
Tejun Heo | 130ace1 | 2009-02-06 00:57:48 +0900 | [diff] [blame] | 25 | * Enable events. This clears the event mask and tests the pending |
| 26 | * event status with one and operation. If there are pending events, |
| 27 | * then enter the hypervisor to get them handled. |
Jeremy Fitzhardinge | 5393744 | 2009-02-02 13:55:42 -0800 | [diff] [blame] | 28 | */ |
Jiri Slaby | 6dcc562 | 2019-10-11 13:51:04 +0200 | [diff] [blame] | 29 | SYM_FUNC_START(xen_irq_enable_direct) |
Josh Poimboeuf | 8be0eb7 | 2016-01-21 16:49:11 -0600 | [diff] [blame] | 30 | FRAME_BEGIN |
Jeremy Fitzhardinge | 5393744 | 2009-02-02 13:55:42 -0800 | [diff] [blame] | 31 | /* Unmask events */ |
| 32 | movb $0, PER_CPU_VAR(xen_vcpu_info) + XEN_vcpu_info_mask |
| 33 | |
Tejun Heo | 130ace1 | 2009-02-06 00:57:48 +0900 | [diff] [blame] | 34 | /* |
| 35 | * Preempt here doesn't matter because that will deal with any |
| 36 | * pending interrupts. The pending check may end up being run |
| 37 | * on the wrong CPU, but that doesn't hurt. |
| 38 | */ |
Jeremy Fitzhardinge | 5393744 | 2009-02-02 13:55:42 -0800 | [diff] [blame] | 39 | |
| 40 | /* Test for pending */ |
| 41 | testb $0xff, PER_CPU_VAR(xen_vcpu_info) + XEN_vcpu_info_pending |
| 42 | jz 1f |
| 43 | |
Juergen Gross | edcb5cf | 2017-08-16 19:31:56 +0200 | [diff] [blame] | 44 | call check_events |
Jeremy Fitzhardinge | 5393744 | 2009-02-02 13:55:42 -0800 | [diff] [blame] | 45 | 1: |
Josh Poimboeuf | 8be0eb7 | 2016-01-21 16:49:11 -0600 | [diff] [blame] | 46 | FRAME_END |
Jeremy Fitzhardinge | 5393744 | 2009-02-02 13:55:42 -0800 | [diff] [blame] | 47 | ret |
Jiri Slaby | 6dcc562 | 2019-10-11 13:51:04 +0200 | [diff] [blame] | 48 | SYM_FUNC_END(xen_irq_enable_direct) |
Jeremy Fitzhardinge | 5393744 | 2009-02-02 13:55:42 -0800 | [diff] [blame] | 49 | |
| 50 | |
| 51 | /* |
Tejun Heo | 130ace1 | 2009-02-06 00:57:48 +0900 | [diff] [blame] | 52 | * Disabling events is simply a matter of making the event mask |
| 53 | * non-zero. |
Jeremy Fitzhardinge | 5393744 | 2009-02-02 13:55:42 -0800 | [diff] [blame] | 54 | */ |
Jiri Slaby | 6dcc562 | 2019-10-11 13:51:04 +0200 | [diff] [blame] | 55 | SYM_FUNC_START(xen_irq_disable_direct) |
Jeremy Fitzhardinge | 5393744 | 2009-02-02 13:55:42 -0800 | [diff] [blame] | 56 | movb $1, PER_CPU_VAR(xen_vcpu_info) + XEN_vcpu_info_mask |
Jeremy Fitzhardinge | 5393744 | 2009-02-02 13:55:42 -0800 | [diff] [blame] | 57 | ret |
Jiri Slaby | 6dcc562 | 2019-10-11 13:51:04 +0200 | [diff] [blame] | 58 | SYM_FUNC_END(xen_irq_disable_direct) |
Jeremy Fitzhardinge | 5393744 | 2009-02-02 13:55:42 -0800 | [diff] [blame] | 59 | |
| 60 | /* |
Tejun Heo | 130ace1 | 2009-02-06 00:57:48 +0900 | [diff] [blame] | 61 | * (xen_)save_fl is used to get the current interrupt enable status. |
| 62 | * Callers expect the status to be in X86_EFLAGS_IF, and other bits |
| 63 | * may be set in the return value. We take advantage of this by |
| 64 | * making sure that X86_EFLAGS_IF has the right value (and other bits |
| 65 | * in that byte are 0), but other bits in the return value are |
| 66 | * undefined. We need to toggle the state of the bit, because Xen and |
| 67 | * x86 use opposite senses (mask vs enable). |
Jeremy Fitzhardinge | 5393744 | 2009-02-02 13:55:42 -0800 | [diff] [blame] | 68 | */ |
Jiri Slaby | 6dcc562 | 2019-10-11 13:51:04 +0200 | [diff] [blame] | 69 | SYM_FUNC_START(xen_save_fl_direct) |
Jeremy Fitzhardinge | 5393744 | 2009-02-02 13:55:42 -0800 | [diff] [blame] | 70 | testb $0xff, PER_CPU_VAR(xen_vcpu_info) + XEN_vcpu_info_mask |
| 71 | setz %ah |
Tejun Heo | 130ace1 | 2009-02-06 00:57:48 +0900 | [diff] [blame] | 72 | addb %ah, %ah |
Jeremy Fitzhardinge | 5393744 | 2009-02-02 13:55:42 -0800 | [diff] [blame] | 73 | ret |
Jiri Slaby | 6dcc562 | 2019-10-11 13:51:04 +0200 | [diff] [blame] | 74 | SYM_FUNC_END(xen_save_fl_direct) |
Jeremy Fitzhardinge | 5393744 | 2009-02-02 13:55:42 -0800 | [diff] [blame] | 75 | |
Jeremy Fitzhardinge | 5393744 | 2009-02-02 13:55:42 -0800 | [diff] [blame] | 76 | /* |
Tejun Heo | 130ace1 | 2009-02-06 00:57:48 +0900 | [diff] [blame] | 77 | * Force an event check by making a hypercall, but preserve regs |
| 78 | * before making the call. |
Jeremy Fitzhardinge | 5393744 | 2009-02-02 13:55:42 -0800 | [diff] [blame] | 79 | */ |
Jiri Slaby | 6dcc562 | 2019-10-11 13:51:04 +0200 | [diff] [blame] | 80 | SYM_FUNC_START(check_events) |
Josh Poimboeuf | 8be0eb7 | 2016-01-21 16:49:11 -0600 | [diff] [blame] | 81 | FRAME_BEGIN |
Jeremy Fitzhardinge | 5393744 | 2009-02-02 13:55:42 -0800 | [diff] [blame] | 82 | push %rax |
| 83 | push %rcx |
| 84 | push %rdx |
| 85 | push %rsi |
| 86 | push %rdi |
| 87 | push %r8 |
| 88 | push %r9 |
| 89 | push %r10 |
| 90 | push %r11 |
| 91 | call xen_force_evtchn_callback |
| 92 | pop %r11 |
| 93 | pop %r10 |
| 94 | pop %r9 |
| 95 | pop %r8 |
| 96 | pop %rdi |
| 97 | pop %rsi |
| 98 | pop %rdx |
| 99 | pop %rcx |
| 100 | pop %rax |
Josh Poimboeuf | 8be0eb7 | 2016-01-21 16:49:11 -0600 | [diff] [blame] | 101 | FRAME_END |
Jeremy Fitzhardinge | 5393744 | 2009-02-02 13:55:42 -0800 | [diff] [blame] | 102 | ret |
Jiri Slaby | 6dcc562 | 2019-10-11 13:51:04 +0200 | [diff] [blame] | 103 | SYM_FUNC_END(check_events) |
Peter Zijlstra | 55aeddd | 2019-07-11 13:40:55 +0200 | [diff] [blame] | 104 | |
Jiri Slaby | 6dcc562 | 2019-10-11 13:51:04 +0200 | [diff] [blame] | 105 | SYM_FUNC_START(xen_read_cr2) |
Peter Zijlstra | 55aeddd | 2019-07-11 13:40:55 +0200 | [diff] [blame] | 106 | FRAME_BEGIN |
| 107 | _ASM_MOV PER_CPU_VAR(xen_vcpu), %_ASM_AX |
| 108 | _ASM_MOV XEN_vcpu_info_arch_cr2(%_ASM_AX), %_ASM_AX |
| 109 | FRAME_END |
| 110 | ret |
Jiri Slaby | 6dcc562 | 2019-10-11 13:51:04 +0200 | [diff] [blame] | 111 | SYM_FUNC_END(xen_read_cr2); |
Peter Zijlstra | 55aeddd | 2019-07-11 13:40:55 +0200 | [diff] [blame] | 112 | |
Jiri Slaby | 6dcc562 | 2019-10-11 13:51:04 +0200 | [diff] [blame] | 113 | SYM_FUNC_START(xen_read_cr2_direct) |
Peter Zijlstra | 55aeddd | 2019-07-11 13:40:55 +0200 | [diff] [blame] | 114 | FRAME_BEGIN |
| 115 | _ASM_MOV PER_CPU_VAR(xen_vcpu_info) + XEN_vcpu_info_arch_cr2, %_ASM_AX |
| 116 | FRAME_END |
| 117 | ret |
Jiri Slaby | 6dcc562 | 2019-10-11 13:51:04 +0200 | [diff] [blame] | 118 | SYM_FUNC_END(xen_read_cr2_direct); |
Juergen Gross | 56415c4 | 2020-07-03 09:16:19 +0200 | [diff] [blame] | 119 | |
| 120 | .macro xen_pv_trap name |
| 121 | SYM_CODE_START(xen_\name) |
Josh Poimboeuf | cde07a4 | 2021-01-21 15:29:28 -0600 | [diff] [blame] | 122 | UNWIND_HINT_EMPTY |
Juergen Gross | 56415c4 | 2020-07-03 09:16:19 +0200 | [diff] [blame] | 123 | pop %rcx |
| 124 | pop %r11 |
| 125 | jmp \name |
| 126 | SYM_CODE_END(xen_\name) |
| 127 | _ASM_NOKPROBE(xen_\name) |
| 128 | .endm |
| 129 | |
| 130 | xen_pv_trap asm_exc_divide_error |
| 131 | xen_pv_trap asm_xenpv_exc_debug |
| 132 | xen_pv_trap asm_exc_int3 |
| 133 | xen_pv_trap asm_xenpv_exc_nmi |
| 134 | xen_pv_trap asm_exc_overflow |
| 135 | xen_pv_trap asm_exc_bounds |
| 136 | xen_pv_trap asm_exc_invalid_op |
| 137 | xen_pv_trap asm_exc_device_not_available |
Juergen Gross | 5b4c6d6 | 2021-01-20 14:55:43 +0100 | [diff] [blame] | 138 | xen_pv_trap asm_xenpv_exc_double_fault |
Juergen Gross | 56415c4 | 2020-07-03 09:16:19 +0200 | [diff] [blame] | 139 | xen_pv_trap asm_exc_coproc_segment_overrun |
| 140 | xen_pv_trap asm_exc_invalid_tss |
| 141 | xen_pv_trap asm_exc_segment_not_present |
| 142 | xen_pv_trap asm_exc_stack_segment |
| 143 | xen_pv_trap asm_exc_general_protection |
| 144 | xen_pv_trap asm_exc_page_fault |
| 145 | xen_pv_trap asm_exc_spurious_interrupt_bug |
| 146 | xen_pv_trap asm_exc_coprocessor_error |
| 147 | xen_pv_trap asm_exc_alignment_check |
| 148 | #ifdef CONFIG_X86_MCE |
Juergen Gross | c3d7fa6 | 2021-01-20 14:55:42 +0100 | [diff] [blame] | 149 | xen_pv_trap asm_xenpv_exc_machine_check |
Juergen Gross | 56415c4 | 2020-07-03 09:16:19 +0200 | [diff] [blame] | 150 | #endif /* CONFIG_X86_MCE */ |
| 151 | xen_pv_trap asm_exc_simd_coprocessor_error |
| 152 | #ifdef CONFIG_IA32_EMULATION |
| 153 | xen_pv_trap entry_INT80_compat |
| 154 | #endif |
Juergen Gross | 2e92493 | 2021-01-25 14:42:07 +0100 | [diff] [blame] | 155 | xen_pv_trap asm_exc_xen_unknown_trap |
Juergen Gross | 56415c4 | 2020-07-03 09:16:19 +0200 | [diff] [blame] | 156 | xen_pv_trap asm_exc_xen_hypervisor_callback |
| 157 | |
| 158 | __INIT |
| 159 | SYM_CODE_START(xen_early_idt_handler_array) |
| 160 | i = 0 |
| 161 | .rept NUM_EXCEPTION_VECTORS |
Josh Poimboeuf | cde07a4 | 2021-01-21 15:29:28 -0600 | [diff] [blame] | 162 | UNWIND_HINT_EMPTY |
Juergen Gross | 56415c4 | 2020-07-03 09:16:19 +0200 | [diff] [blame] | 163 | pop %rcx |
| 164 | pop %r11 |
| 165 | jmp early_idt_handler_array + i*EARLY_IDT_HANDLER_SIZE |
| 166 | i = i + 1 |
| 167 | .fill xen_early_idt_handler_array + i*XEN_EARLY_IDT_HANDLER_SIZE - ., 1, 0xcc |
| 168 | .endr |
| 169 | SYM_CODE_END(xen_early_idt_handler_array) |
| 170 | __FINIT |
| 171 | |
| 172 | hypercall_iret = hypercall_page + __HYPERVISOR_iret * 32 |
| 173 | /* |
| 174 | * Xen64 iret frame: |
| 175 | * |
| 176 | * ss |
| 177 | * rsp |
| 178 | * rflags |
| 179 | * cs |
| 180 | * rip <-- standard iret frame |
| 181 | * |
| 182 | * flags |
| 183 | * |
| 184 | * rcx } |
| 185 | * r11 }<-- pushed by hypercall page |
| 186 | * rsp->rax } |
| 187 | */ |
| 188 | SYM_CODE_START(xen_iret) |
Josh Poimboeuf | cde07a4 | 2021-01-21 15:29:28 -0600 | [diff] [blame] | 189 | UNWIND_HINT_EMPTY |
Juergen Gross | 56415c4 | 2020-07-03 09:16:19 +0200 | [diff] [blame] | 190 | pushq $0 |
| 191 | jmp hypercall_iret |
| 192 | SYM_CODE_END(xen_iret) |
| 193 | |
Juergen Gross | 56415c4 | 2020-07-03 09:16:19 +0200 | [diff] [blame] | 194 | /* |
| 195 | * Xen handles syscall callbacks much like ordinary exceptions, which |
| 196 | * means we have: |
| 197 | * - kernel gs |
| 198 | * - kernel rsp |
| 199 | * - an iret-like stack frame on the stack (including rcx and r11): |
| 200 | * ss |
| 201 | * rsp |
| 202 | * rflags |
| 203 | * cs |
| 204 | * rip |
| 205 | * r11 |
| 206 | * rsp->rcx |
| 207 | */ |
| 208 | |
| 209 | /* Normal 64-bit system call target */ |
Josh Poimboeuf | cde07a4 | 2021-01-21 15:29:28 -0600 | [diff] [blame] | 210 | SYM_CODE_START(xen_syscall_target) |
| 211 | UNWIND_HINT_EMPTY |
Juergen Gross | 56415c4 | 2020-07-03 09:16:19 +0200 | [diff] [blame] | 212 | popq %rcx |
| 213 | popq %r11 |
| 214 | |
| 215 | /* |
| 216 | * Neither Xen nor the kernel really knows what the old SS and |
| 217 | * CS were. The kernel expects __USER_DS and __USER_CS, so |
| 218 | * report those values even though Xen will guess its own values. |
| 219 | */ |
| 220 | movq $__USER_DS, 4*8(%rsp) |
| 221 | movq $__USER_CS, 1*8(%rsp) |
| 222 | |
| 223 | jmp entry_SYSCALL_64_after_hwframe |
Josh Poimboeuf | cde07a4 | 2021-01-21 15:29:28 -0600 | [diff] [blame] | 224 | SYM_CODE_END(xen_syscall_target) |
Juergen Gross | 56415c4 | 2020-07-03 09:16:19 +0200 | [diff] [blame] | 225 | |
| 226 | #ifdef CONFIG_IA32_EMULATION |
| 227 | |
| 228 | /* 32-bit compat syscall target */ |
Josh Poimboeuf | cde07a4 | 2021-01-21 15:29:28 -0600 | [diff] [blame] | 229 | SYM_CODE_START(xen_syscall32_target) |
| 230 | UNWIND_HINT_EMPTY |
Juergen Gross | 56415c4 | 2020-07-03 09:16:19 +0200 | [diff] [blame] | 231 | popq %rcx |
| 232 | popq %r11 |
| 233 | |
| 234 | /* |
| 235 | * Neither Xen nor the kernel really knows what the old SS and |
| 236 | * CS were. The kernel expects __USER32_DS and __USER32_CS, so |
| 237 | * report those values even though Xen will guess its own values. |
| 238 | */ |
| 239 | movq $__USER32_DS, 4*8(%rsp) |
| 240 | movq $__USER32_CS, 1*8(%rsp) |
| 241 | |
| 242 | jmp entry_SYSCALL_compat_after_hwframe |
Josh Poimboeuf | cde07a4 | 2021-01-21 15:29:28 -0600 | [diff] [blame] | 243 | SYM_CODE_END(xen_syscall32_target) |
Juergen Gross | 56415c4 | 2020-07-03 09:16:19 +0200 | [diff] [blame] | 244 | |
| 245 | /* 32-bit compat sysenter target */ |
Josh Poimboeuf | cde07a4 | 2021-01-21 15:29:28 -0600 | [diff] [blame] | 246 | SYM_CODE_START(xen_sysenter_target) |
| 247 | UNWIND_HINT_EMPTY |
Juergen Gross | 56415c4 | 2020-07-03 09:16:19 +0200 | [diff] [blame] | 248 | /* |
| 249 | * NB: Xen is polite and clears TF from EFLAGS for us. This means |
| 250 | * that we don't need to guard against single step exceptions here. |
| 251 | */ |
| 252 | popq %rcx |
| 253 | popq %r11 |
| 254 | |
| 255 | /* |
| 256 | * Neither Xen nor the kernel really knows what the old SS and |
| 257 | * CS were. The kernel expects __USER32_DS and __USER32_CS, so |
| 258 | * report those values even though Xen will guess its own values. |
| 259 | */ |
| 260 | movq $__USER32_DS, 4*8(%rsp) |
| 261 | movq $__USER32_CS, 1*8(%rsp) |
| 262 | |
| 263 | jmp entry_SYSENTER_compat_after_hwframe |
Josh Poimboeuf | cde07a4 | 2021-01-21 15:29:28 -0600 | [diff] [blame] | 264 | SYM_CODE_END(xen_sysenter_target) |
Juergen Gross | 56415c4 | 2020-07-03 09:16:19 +0200 | [diff] [blame] | 265 | |
| 266 | #else /* !CONFIG_IA32_EMULATION */ |
| 267 | |
Josh Poimboeuf | cde07a4 | 2021-01-21 15:29:28 -0600 | [diff] [blame] | 268 | SYM_CODE_START(xen_syscall32_target) |
| 269 | SYM_CODE_START(xen_sysenter_target) |
| 270 | UNWIND_HINT_EMPTY |
Juergen Gross | 56415c4 | 2020-07-03 09:16:19 +0200 | [diff] [blame] | 271 | lea 16(%rsp), %rsp /* strip %rcx, %r11 */ |
| 272 | mov $-ENOSYS, %rax |
| 273 | pushq $0 |
| 274 | jmp hypercall_iret |
Josh Poimboeuf | cde07a4 | 2021-01-21 15:29:28 -0600 | [diff] [blame] | 275 | SYM_CODE_END(xen_sysenter_target) |
| 276 | SYM_CODE_END(xen_syscall32_target) |
Juergen Gross | 56415c4 | 2020-07-03 09:16:19 +0200 | [diff] [blame] | 277 | |
| 278 | #endif /* CONFIG_IA32_EMULATION */ |