blob: c98a48c861fd33ec4958dccc462ecbccf6856f3b [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Jeremy Fitzhardingecdacc122008-07-08 15:06:46 -07002/*
Juergen Grossedcb5cf2017-08-16 19:31:56 +02003 * Asm versions of Xen pv-ops, suitable for direct use.
Tejun Heo130ace12009-02-06 00:57:48 +09004 *
5 * We only bother with direct forms (ie, vcpu in pda) of the
Juergen Grossedcb5cf2017-08-16 19:31:56 +02006 * operations here; the indirect forms are better handled in C.
Jeremy Fitzhardingecdacc122008-07-08 15:06:46 -07007 */
8
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -07009#include <asm/errno.h>
Brian Gerst9af45652009-01-19 00:38:58 +090010#include <asm/percpu.h>
Jeremy Fitzhardinge53937442009-02-02 13:55:42 -080011#include <asm/processor-flags.h>
12#include <asm/segment.h>
Denys Vlasenko63332a82015-04-24 17:31:33 +020013#include <asm/asm-offsets.h>
Denys Vlasenko3a232082015-04-24 17:31:35 +020014#include <asm/thread_info.h>
Jeremy Fitzhardingecdacc122008-07-08 15:06:46 -070015
16#include <xen/interface/xen.h>
17
Juergen Grossedcb5cf2017-08-16 19:31:56 +020018#include <linux/linkage.h>
Jeremy Fitzhardingecdacc122008-07-08 15:06:46 -070019
Juergen Gross5878d5d2017-08-31 19:42:49 +020020.macro xen_pv_trap name
21ENTRY(xen_\name)
22 pop %rcx
23 pop %r11
24 jmp \name
25END(xen_\name)
26.endm
27
28xen_pv_trap divide_error
29xen_pv_trap debug
30xen_pv_trap xendebug
31xen_pv_trap int3
32xen_pv_trap xenint3
33xen_pv_trap nmi
34xen_pv_trap overflow
35xen_pv_trap bounds
36xen_pv_trap invalid_op
37xen_pv_trap device_not_available
38xen_pv_trap double_fault
39xen_pv_trap coprocessor_segment_overrun
40xen_pv_trap invalid_TSS
41xen_pv_trap segment_not_present
42xen_pv_trap stack_segment
43xen_pv_trap general_protection
44xen_pv_trap page_fault
45xen_pv_trap spurious_interrupt_bug
46xen_pv_trap coprocessor_error
47xen_pv_trap alignment_check
48#ifdef CONFIG_X86_MCE
49xen_pv_trap machine_check
50#endif /* CONFIG_X86_MCE */
51xen_pv_trap simd_coprocessor_error
52#ifdef CONFIG_IA32_EMULATION
53xen_pv_trap entry_INT80_compat
54#endif
55xen_pv_trap hypervisor_callback
Jeremy Fitzhardinge997409d2008-07-08 15:07:00 -070056
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -070057hypercall_iret = hypercall_page + __HYPERVISOR_iret * 32
58/*
Tejun Heo130ace12009-02-06 00:57:48 +090059 * 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 Fitzhardinge6fcac6d2008-07-08 15:07:14 -070072 */
Jeremy Fitzhardingecdacc122008-07-08 15:06:46 -070073ENTRY(xen_iret)
74 pushq $0
Juergen Grossedcb5cf2017-08-16 19:31:56 +020075 jmp hypercall_iret
Jeremy Fitzhardingecdacc122008-07-08 15:06:46 -070076
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -070077ENTRY(xen_sysret64)
Tejun Heo130ace12009-02-06 00:57:48 +090078 /*
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 Molnarc38e5032015-03-17 14:42:59 +010082 movq %rsp, PER_CPU_VAR(rsp_scratch)
Denys Vlasenko3a232082015-04-24 17:31:35 +020083 movq PER_CPU_VAR(cpu_current_top_of_stack), %rsp
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -070084
85 pushq $__USER_DS
Ingo Molnarc38e5032015-03-17 14:42:59 +010086 pushq PER_CPU_VAR(rsp_scratch)
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -070087 pushq %r11
88 pushq $__USER_CS
89 pushq %rcx
90
91 pushq $VGCF_in_syscall
Juergen Grossedcb5cf2017-08-16 19:31:56 +020092 jmp hypercall_iret
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -070093
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -070094/*
Tejun Heo130ace12009-02-06 00:57:48 +090095 * 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 Fitzhardinge6fcac6d2008-07-08 15:07:14 -0700107 */
108
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -0700109/* Normal 64-bit system call target */
110ENTRY(xen_syscall_target)
Andy Lutomirski8a9949b2017-08-07 20:59:21 -0700111 popq %rcx
112 popq %r11
Andy Lutomirskifa2016a2017-08-14 22:36:19 -0700113
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 Lutomirski8a9949b2017-08-07 20:59:21 -0700122 jmp entry_SYSCALL_64_after_hwframe
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -0700123ENDPROC(xen_syscall_target)
124
125#ifdef CONFIG_IA32_EMULATION
126
127/* 32-bit compat syscall target */
128ENTRY(xen_syscall32_target)
Andy Lutomirski8a9949b2017-08-07 20:59:21 -0700129 popq %rcx
130 popq %r11
Andy Lutomirskifa2016a2017-08-14 22:36:19 -0700131
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 Lutomirski8a9949b2017-08-07 20:59:21 -0700140 jmp entry_SYSCALL_compat_after_hwframe
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -0700141ENDPROC(xen_syscall32_target)
142
143/* 32-bit compat sysenter target */
144ENTRY(xen_sysenter_target)
Andy Lutomirski8a9949b2017-08-07 20:59:21 -0700145 mov 0*8(%rsp), %rcx
146 mov 1*8(%rsp), %r11
147 mov 5*8(%rsp), %rsp
Ingo Molnar4c8cd0c2015-06-08 08:33:56 +0200148 jmp entry_SYSENTER_compat
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -0700149ENDPROC(xen_sysenter_target)
150
151#else /* !CONFIG_IA32_EMULATION */
152
153ENTRY(xen_syscall32_target)
154ENTRY(xen_sysenter_target)
Tejun Heo130ace12009-02-06 00:57:48 +0900155 lea 16(%rsp), %rsp /* strip %rcx, %r11 */
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -0700156 mov $-ENOSYS, %rax
Jeremy Fitzhardinge6aaf5d62009-11-25 13:15:38 -0800157 pushq $0
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -0700158 jmp hypercall_iret
159ENDPROC(xen_syscall32_target)
160ENDPROC(xen_sysenter_target)
161
162#endif /* CONFIG_IA32_EMULATION */