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 /*
28 * This file and its contents are supplied under the terms of the
29 * Common Development and Distribution License ("CDDL"), version 1.0.
30 * You may only use this file in accordance with the terms of version
31 * 1.0 of the CDDL.
32 *
33 * A full copy of the text of the CDDL should have accompanied this
34 * source. A copy of the CDDL is also available via the Internet at
35 * http://www.illumos.org/license/CDDL.
36 *
37 * Copyright 2013 Pluribus Networks Inc.
38 * Copyright 2018 Joyent, Inc.
39 * Copyright 2022 MNX Cloud, Inc.
40 */
41
42 #include <sys/asm_linkage.h>
43 #include <sys/segments.h>
44
45 /* Porting note: This is named 'vmx_support.S' upstream. */
46
47 #include "vmx_assym.h"
48 #include "vmcs.h"
49
50 /*
51 * Assumes that %rdi holds a pointer to the 'vmxctx'.
52 *
53 * On "return" all registers are updated to reflect guest state. The two
54 * exceptions are %rip and %rsp. These registers are atomically switched
55 * by hardware from the guest area of the vmcs.
56 *
57 * We modify %rsp to point to the 'vmxctx' so we can use it to restore
58 * host context in case of an error with 'vmlaunch' or 'vmresume'.
59 */
209
210 /*
211 * Non-error VM-exit from the guest. Make this a label so it can
212 * be used by C code when setting up the VMCS.
213 * The VMCS-restored %rsp points to the struct vmxctx
214 */
215 .align ASM_ENTRY_ALIGN;
216 ENTRY_NP(vmx_exit_guest)
217 /* Save guest state that is not automatically saved in the vmcs. */
218 VMX_GUEST_SAVE
219
220 VMX_GUEST_FLUSH_SCRATCH
221
222 /*
223 * To prevent malicious branch target predictions from affecting the
224 * host, overwrite all entries in the RSB upon exiting a guest.
225 *
226 * NOTE: If RSB mitigations are disabled (see cpuid.c), this call is
227 * entirely a NOP.
228 */
229 call x86_rsb_stuff
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 movq VMXSTK_RBX(%rsp), %rbx
237 movq VMXSTK_R12(%rsp), %r12
238 movq VMXSTK_R13(%rsp), %r13
239 movq VMXSTK_R14(%rsp), %r14
240 movq VMXSTK_R15(%rsp), %r15
241
242 addq $VMXSTKSIZE, %rsp
243 popq %rbp
244 ret
245 SET_SIZE(vmx_exit_guest)
246
247 /*
248 * %rdi = trapno
249 *
|
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 /*
28 * This file and its contents are supplied under the terms of the
29 * Common Development and Distribution License ("CDDL"), version 1.0.
30 * You may only use this file in accordance with the terms of version
31 * 1.0 of the CDDL.
32 *
33 * A full copy of the text of the CDDL should have accompanied this
34 * source. A copy of the CDDL is also available via the Internet at
35 * http://www.illumos.org/license/CDDL.
36 *
37 * Copyright 2013 Pluribus Networks Inc.
38 * Copyright 2018 Joyent, Inc.
39 * Copyright 2024 MNX Cloud, Inc.
40 */
41
42 #include <sys/asm_linkage.h>
43 #include <sys/segments.h>
44
45 /* Porting note: This is named 'vmx_support.S' upstream. */
46
47 #include "vmx_assym.h"
48 #include "vmcs.h"
49
50 /*
51 * Assumes that %rdi holds a pointer to the 'vmxctx'.
52 *
53 * On "return" all registers are updated to reflect guest state. The two
54 * exceptions are %rip and %rsp. These registers are atomically switched
55 * by hardware from the guest area of the vmcs.
56 *
57 * We modify %rsp to point to the 'vmxctx' so we can use it to restore
58 * host context in case of an error with 'vmlaunch' or 'vmresume'.
59 */
209
210 /*
211 * Non-error VM-exit from the guest. Make this a label so it can
212 * be used by C code when setting up the VMCS.
213 * The VMCS-restored %rsp points to the struct vmxctx
214 */
215 .align ASM_ENTRY_ALIGN;
216 ENTRY_NP(vmx_exit_guest)
217 /* Save guest state that is not automatically saved in the vmcs. */
218 VMX_GUEST_SAVE
219
220 VMX_GUEST_FLUSH_SCRATCH
221
222 /*
223 * To prevent malicious branch target predictions from affecting the
224 * host, overwrite all entries in the RSB upon exiting a guest.
225 *
226 * NOTE: If RSB mitigations are disabled (see cpuid.c), this call is
227 * entirely a NOP.
228 */
229 call x86_rsb_stuff_vmexit
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 movq VMXSTK_RBX(%rsp), %rbx
237 movq VMXSTK_R12(%rsp), %r12
238 movq VMXSTK_R13(%rsp), %r13
239 movq VMXSTK_R14(%rsp), %r14
240 movq VMXSTK_R15(%rsp), %r15
241
242 addq $VMXSTKSIZE, %rsp
243 popq %rbp
244 ret
245 SET_SIZE(vmx_exit_guest)
246
247 /*
248 * %rdi = trapno
249 *
|