Deleted Added
full compact
vmx_support.S (264619) vmx_support.S (266339)
1/*-
2 * Copyright (c) 2011 NetApp, Inc.
3 * Copyright (c) 2013 Neel Natu <neel@freebsd.org>
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 10 unchanged lines hidden (view full) ---

19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
1/*-
2 * Copyright (c) 2011 NetApp, Inc.
3 * Copyright (c) 2013 Neel Natu <neel@freebsd.org>
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 10 unchanged lines hidden (view full) ---

19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 * $FreeBSD: stable/10/sys/amd64/vmm/intel/vmx_support.S 264619 2014-04-17 18:00:07Z jhb $
27 * $FreeBSD: stable/10/sys/amd64/vmm/intel/vmx_support.S 266339 2014-05-17 19:11:08Z jhb $
28 */
29
30#include <machine/asmacros.h>
31
32#include "vmx_assym.s"
33
34#ifdef SMP
35#define LK lock ;

--- 56 unchanged lines hidden (view full) ---

92 movq VMXCTX_HOST_RSP(%rdi), %rsp; \
93 movq VMXCTX_HOST_RBX(%rdi), %rbx; \
94 movq VMXCTX_HOST_RIP(%rdi), tmpreg; \
95 movq tmpreg, (%rsp) /* return address */
96
97/*
98 * vmx_enter_guest(struct vmxctx *vmxctx, int launched)
99 * %rdi: pointer to the 'vmxctx'
28 */
29
30#include <machine/asmacros.h>
31
32#include "vmx_assym.s"
33
34#ifdef SMP
35#define LK lock ;

--- 56 unchanged lines hidden (view full) ---

92 movq VMXCTX_HOST_RSP(%rdi), %rsp; \
93 movq VMXCTX_HOST_RBX(%rdi), %rbx; \
94 movq VMXCTX_HOST_RIP(%rdi), tmpreg; \
95 movq tmpreg, (%rsp) /* return address */
96
97/*
98 * vmx_enter_guest(struct vmxctx *vmxctx, int launched)
99 * %rdi: pointer to the 'vmxctx'
100 * %esi: launch state of the VMCS
100 * %rsi: pointer to the 'vmx'
101 * %edx: launch state of the VMCS
101 * Interrupts must be disabled on entry.
102 */
103ENTRY(vmx_enter_guest)
104 /*
105 * Save host state before doing anything else.
106 */
107 VMX_HOST_SAVE(%r10)
108
109 /*
110 * Activate guest pmap on this cpu.
111 */
112 movq VMXCTX_PMAP(%rdi), %r11
113 movl PCPU(CPUID), %eax
114 LK btsl %eax, PM_ACTIVE(%r11)
115
116 /*
102 * Interrupts must be disabled on entry.
103 */
104ENTRY(vmx_enter_guest)
105 /*
106 * Save host state before doing anything else.
107 */
108 VMX_HOST_SAVE(%r10)
109
110 /*
111 * Activate guest pmap on this cpu.
112 */
113 movq VMXCTX_PMAP(%rdi), %r11
114 movl PCPU(CPUID), %eax
115 LK btsl %eax, PM_ACTIVE(%r11)
116
117 /*
117 * If 'vmxctx->eptgen[curcpu]' is not identical to 'pmap->pm_eptgen'
118 * If 'vmx->eptgen[curcpu]' is not identical to 'pmap->pm_eptgen'
118 * then we must invalidate all mappings associated with this EPTP.
119 */
120 movq PM_EPTGEN(%r11), %r10
119 * then we must invalidate all mappings associated with this EPTP.
120 */
121 movq PM_EPTGEN(%r11), %r10
121 cmpq %r10, VMXCTX_EPTGEN(%rdi, %rax, 8)
122 cmpq %r10, VMX_EPTGEN(%rsi, %rax, 8)
122 je guest_restore
123
123 je guest_restore
124
124 /* Refresh 'vmxctx->eptgen[curcpu]' */
125 movq %r10, VMXCTX_EPTGEN(%rdi, %rax, 8)
125 /* Refresh 'vmx->eptgen[curcpu]' */
126 movq %r10, VMX_EPTGEN(%rsi, %rax, 8)
126
127 /* Setup the invept descriptor on the host stack */
128 mov %rsp, %r11
127
128 /* Setup the invept descriptor on the host stack */
129 mov %rsp, %r11
129 movq VMXCTX_EPTP(%rdi), %rax
130 movq VMX_EPTP(%rsi), %rax
130 movq %rax, -16(%r11)
131 movq $0x0, -8(%r11)
132 mov $0x1, %eax /* Single context invalidate */
133 invept -16(%r11), %rax
134 jbe invept_error /* Check invept instruction error */
135
136guest_restore:
131 movq %rax, -16(%r11)
132 movq $0x0, -8(%r11)
133 mov $0x1, %eax /* Single context invalidate */
134 invept -16(%r11), %rax
135 jbe invept_error /* Check invept instruction error */
136
137guest_restore:
137 cmpl $0, %esi
138 cmpl $0, %edx
138 je do_launch
139
140 VMX_GUEST_RESTORE
141 vmresume
142 /*
143 * In the common case 'vmresume' returns back to the host through
144 * 'vmx_exit_guest' with %rsp pointing to 'vmxctx'.
145 *

--- 83 unchanged lines hidden (view full) ---

229
230 /*
231 * This will return to the caller of 'vmx_enter_guest()' with a return
232 * value of VMX_GUEST_VMEXIT.
233 */
234 movl $VMX_GUEST_VMEXIT, %eax
235 ret
236END(vmx_exit_guest)
139 je do_launch
140
141 VMX_GUEST_RESTORE
142 vmresume
143 /*
144 * In the common case 'vmresume' returns back to the host through
145 * 'vmx_exit_guest' with %rsp pointing to 'vmxctx'.
146 *

--- 83 unchanged lines hidden (view full) ---

230
231 /*
232 * This will return to the caller of 'vmx_enter_guest()' with a return
233 * value of VMX_GUEST_VMEXIT.
234 */
235 movl $VMX_GUEST_VMEXIT, %eax
236 ret
237END(vmx_exit_guest)
238
239/*
240 * %rdi = interrupt handler entry point
241 *
242 * Calling sequence described in the "Instruction Set Reference" for the "INT"
243 * instruction in Intel SDM, Vol 2.
244 */
245ENTRY(vmx_call_isr)
246 mov %rsp, %r11 /* save %rsp */
247 and $~0xf, %rsp /* align on 16-byte boundary */
248 pushq $KERNEL_SS /* %ss */
249 pushq %r11 /* %rsp */
250 pushfq /* %rflags */
251 pushq $KERNEL_CS /* %cs */
252 cli /* disable interrupts */
253 callq *%rdi /* push %rip and call isr */
254 ret
255END(vmx_call_isr)