blob: c5fee2680abc87989b2b18f7752eb2b5e949c04c [file] [log] [blame]
Jeremy Fitzhardingecdacc122008-07-08 15:06:46 -07001/*
Tejun Heo130ace12009-02-06 00:57:48 +09002 * 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 Fitzhardingecdacc122008-07-08 15:06:46 -070012 */
13
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -070014#include <asm/errno.h>
Brian Gerst9af45652009-01-19 00:38:58 +090015#include <asm/percpu.h>
Jeremy Fitzhardinge53937442009-02-02 13:55:42 -080016#include <asm/processor-flags.h>
17#include <asm/segment.h>
Denys Vlasenko63332a82015-04-24 17:31:33 +020018#include <asm/asm-offsets.h>
Denys Vlasenko3a232082015-04-24 17:31:35 +020019#include <asm/thread_info.h>
Jeremy Fitzhardingecdacc122008-07-08 15:06:46 -070020
21#include <xen/interface/xen.h>
22
Jeremy Fitzhardinge53937442009-02-02 13:55:42 -080023#include "xen-asm.h"
Jeremy Fitzhardingecdacc122008-07-08 15:06:46 -070024
Jeremy Fitzhardinge997409d2008-07-08 15:07:00 -070025ENTRY(xen_adjust_exception_frame)
Tejun Heo130ace12009-02-06 00:57:48 +090026 mov 8+0(%rsp), %rcx
27 mov 8+8(%rsp), %r11
Jeremy Fitzhardinge997409d2008-07-08 15:07:00 -070028 ret $16
Josh Poimboeuf9fd21602016-01-21 16:49:10 -060029ENDPROC(xen_adjust_exception_frame)
Jeremy Fitzhardinge997409d2008-07-08 15:07:00 -070030
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -070031hypercall_iret = hypercall_page + __HYPERVISOR_iret * 32
32/*
Tejun Heo130ace12009-02-06 00:57:48 +090033 * Xen64 iret frame:
34 *
35 * ss
36 * rsp
37 * rflags
38 * cs
39 * rip <-- standard iret frame
40 *
41 * flags
42 *
43 * rcx }
44 * r11 }<-- pushed by hypercall page
45 * rsp->rax }
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -070046 */
Jeremy Fitzhardingecdacc122008-07-08 15:06:46 -070047ENTRY(xen_iret)
48 pushq $0
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -0700491: jmp hypercall_iret
50ENDPATCH(xen_iret)
51RELOC(xen_iret, 1b+1)
Jeremy Fitzhardingecdacc122008-07-08 15:06:46 -070052
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -070053ENTRY(xen_sysret64)
Tejun Heo130ace12009-02-06 00:57:48 +090054 /*
55 * We're already on the usermode stack at this point, but
56 * still with the kernel gs, so we can easily switch back
57 */
Ingo Molnarc38e5032015-03-17 14:42:59 +010058 movq %rsp, PER_CPU_VAR(rsp_scratch)
Denys Vlasenko3a232082015-04-24 17:31:35 +020059 movq PER_CPU_VAR(cpu_current_top_of_stack), %rsp
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -070060
61 pushq $__USER_DS
Ingo Molnarc38e5032015-03-17 14:42:59 +010062 pushq PER_CPU_VAR(rsp_scratch)
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -070063 pushq %r11
64 pushq $__USER_CS
65 pushq %rcx
66
67 pushq $VGCF_in_syscall
681: jmp hypercall_iret
69ENDPATCH(xen_sysret64)
70RELOC(xen_sysret64, 1b+1)
71
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -070072/*
Tejun Heo130ace12009-02-06 00:57:48 +090073 * Xen handles syscall callbacks much like ordinary exceptions, which
74 * means we have:
75 * - kernel gs
76 * - kernel rsp
77 * - an iret-like stack frame on the stack (including rcx and r11):
78 * ss
79 * rsp
80 * rflags
81 * cs
82 * rip
83 * r11
84 * rsp->rcx
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -070085 */
86
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -070087/* Normal 64-bit system call target */
88ENTRY(xen_syscall_target)
Andy Lutomirski8a9949b2017-08-07 20:59:21 -070089 popq %rcx
90 popq %r11
Andy Lutomirskifa2016a2017-08-14 22:36:19 -070091
92 /*
93 * Neither Xen nor the kernel really knows what the old SS and
94 * CS were. The kernel expects __USER_DS and __USER_CS, so
95 * report those values even though Xen will guess its own values.
96 */
97 movq $__USER_DS, 4*8(%rsp)
98 movq $__USER_CS, 1*8(%rsp)
99
Andy Lutomirski8a9949b2017-08-07 20:59:21 -0700100 jmp entry_SYSCALL_64_after_hwframe
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -0700101ENDPROC(xen_syscall_target)
102
103#ifdef CONFIG_IA32_EMULATION
104
105/* 32-bit compat syscall target */
106ENTRY(xen_syscall32_target)
Andy Lutomirski8a9949b2017-08-07 20:59:21 -0700107 popq %rcx
108 popq %r11
Andy Lutomirskifa2016a2017-08-14 22:36:19 -0700109
110 /*
111 * Neither Xen nor the kernel really knows what the old SS and
112 * CS were. The kernel expects __USER32_DS and __USER32_CS, so
113 * report those values even though Xen will guess its own values.
114 */
115 movq $__USER32_DS, 4*8(%rsp)
116 movq $__USER32_CS, 1*8(%rsp)
117
Andy Lutomirski8a9949b2017-08-07 20:59:21 -0700118 jmp entry_SYSCALL_compat_after_hwframe
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -0700119ENDPROC(xen_syscall32_target)
120
121/* 32-bit compat sysenter target */
122ENTRY(xen_sysenter_target)
Andy Lutomirski8a9949b2017-08-07 20:59:21 -0700123 mov 0*8(%rsp), %rcx
124 mov 1*8(%rsp), %r11
125 mov 5*8(%rsp), %rsp
Ingo Molnar4c8cd0c2015-06-08 08:33:56 +0200126 jmp entry_SYSENTER_compat
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -0700127ENDPROC(xen_sysenter_target)
128
129#else /* !CONFIG_IA32_EMULATION */
130
131ENTRY(xen_syscall32_target)
132ENTRY(xen_sysenter_target)
Tejun Heo130ace12009-02-06 00:57:48 +0900133 lea 16(%rsp), %rsp /* strip %rcx, %r11 */
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -0700134 mov $-ENOSYS, %rax
Jeremy Fitzhardinge6aaf5d62009-11-25 13:15:38 -0800135 pushq $0
Jeremy Fitzhardinge6fcac6d2008-07-08 15:07:14 -0700136 jmp hypercall_iret
137ENDPROC(xen_syscall32_target)
138ENDPROC(xen_sysenter_target)
139
140#endif /* CONFIG_IA32_EMULATION */