github.com/jlmucb/cloudproxy@v0.0.0-20170830161738-b5aa0b619bc4/cpvmm/vmm/include/vmx_teardown.h (about) 1 /* 2 * Copyright (c) 2013 Intel Corporation 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * Unless required by applicable law or agreed to in writing, software 9 * distributed under the License is distributed on an "AS IS" BASIS, 10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 * See the License for the specific language governing permissions and 12 * limitations under the License. 13 */ 14 15 #ifndef _VMX_TEARDOWN_H_ 16 #define _VMX_TEARDOWN_H_ 17 18 #include "vmm_defs.h" 19 #include "vmm_objects.h" 20 #include "guest_cpu.h" 21 #include "vmcall_api.h" 22 #include "guest.h" 23 #include "gpm_api.h" 24 #include "guest_cpu.h" 25 #include "hw_vmx_utils.h" 26 #include "em64t_defs.h" 27 #include "hw_utils.h" 28 #include "ia32_defs.h" 29 #include "vmcs_init.h" 30 #include "host_memory_manager_api.h" 31 #include "vtd.h" 32 #include "vmm_dbg.h" 33 #include "hw_interlocked.h" 34 35 //8-Byte aligned 36 typedef struct VMM_TEARDOWN_PARAMS_S { 37 UINT32 padding_four_bytes; 38 UINT8 is_guest_x64_mode; // guest mode: 1: x64 mode, 0: 32bit mode. 39 UINT8 padding; 40 UINT16 size_of_this_structure; // size_of_this_structure 41 42 UINT64 session_id; // IN 43 UINT64 teardownthunk_gva; // IN, teardown thunk entry of guest virtual address. 44 UINT64 teardown_buffer_size; // IN, teardown buffer size. 45 UINT64 teardown_buffer_gva; // IN, teardown buffer virtual address. 46 UINT64 guest_states_storage_virt_addr; // IN, virtual address of this guest states storage. 47 UINT64 cr3_td_sm_32; // IN, CR3 for teardown shared memory for 32 bits mode. 48 UINT64 nonce; 49 } VMM_TEARDOWN_PARAMS; 50 51 // 53 - 8 bytes fields in the structure 52 // 424 bytes per core 53 // So for 80 cores, it requires 9 pages 54 55 typedef struct VMM_TEARDOWN_GUEST_STATES_S{ 56 UINT64 SIZE_OF_THIS_STRUCTURE; 57 58 // gdtr contents 59 // if x64 -> EM64T_GDTR 60 // else ia32 -> IA32_GDTR 61 UINT64 GUEST_GDTR_LO; 62 UINT64 GUEST_GDTR_HI; 63 64 // idtr contents 65 // if x64 -> EM64T_IDT_DESCRIPTOR 66 // else ia32 -> IA32_IDT_DESCRIPTOR 67 UINT64 GUEST_IDTR_LO; 68 UINT64 GUEST_IDTR_HI; 69 70 // temp stack pointer used to switch cs 71 UINT64 TEMP_STACK_POINTER; 72 73 UINT64 ADDR_OF_TEARDOWN_THUNK; 74 75 // general purpose registers 76 UINT64 IA32_GP_RAX; 77 UINT64 IA32_GP_RBX; 78 UINT64 IA32_GP_RCX; 79 UINT64 IA32_GP_RDX; 80 UINT64 IA32_GP_RDI; 81 UINT64 IA32_GP_RSI; 82 UINT64 IA32_GP_RBP; 83 UINT64 IA32_GP_RSP; 84 UINT64 IA32_GP_R8; 85 UINT64 IA32_GP_R9; 86 UINT64 IA32_GP_R10; 87 UINT64 IA32_GP_R11; 88 UINT64 IA32_GP_R12; 89 UINT64 IA32_GP_R13; 90 UINT64 IA32_GP_R14; 91 UINT64 IA32_GP_R15; 92 93 UINT64 IA32_REG_RIP; 94 UINT64 IA32_INSTR_LENTH; // instruction length to the next one. 95 UINT64 IA32_REG_RFLAGS; 96 97 // control registers 98 UINT64 IA32_CR0; 99 UINT64 IA32_CR3; 100 UINT64 IA32_CR4; 101 UINT64 IA32_CR8; 102 103 // debug register 104 UINT64 IA32_DR7; 105 106 // segment 107 UINT64 IA32_ES_SELECTOR; 108 UINT64 IA32_CS_SELECTOR; 109 UINT64 IA32_SS_SELECTOR; 110 UINT64 IA32_DS_SELECTOR; 111 UINT64 IA32_FS_SELECTOR; 112 UINT64 IA32_GS_SELECTOR; 113 UINT64 IA32_LDTR_SELECTOR; 114 UINT64 IA32_TR_SELECTOR; 115 UINT64 IA32_GDTR_BASE; 116 UINT64 IA32_GDTR_LIMIT; 117 UINT64 IA32_IDTR_BASE; 118 UINT64 IA32_IDTR_LIMIT; 119 120 121 UINT64 IA32_MSR_DEBUG_CTL; 122 UINT64 IA32_MSR_SYSENT_CS; 123 UINT64 IA32_MSR_SYSENT_ESP; 124 UINT64 IA32_MSR_SYSENT_EIP; 125 126 //This field is supported only on logical processors that support the 1-setting of the 127 //"load IA32_PERF_GLOBAL_CTRL" VM-entry control. 128 UINT64 IA32_MSR_PERF_GLB_CTL; 129 130 // This field is supported only on logical processors that 131 // support the 1-setting of the "load IA32_PAT" VM-entry control. 132 UINT64 IA32_MSR_PAT_REG; 133 134 //This field is supported only on logical processors that 135 // support the 1-setting of the "load IA32_EFER" VM-entry control. 136 UINT64 IA32_MSR_EFER_REG; 137 138 // smbase 139 UINT64 IA32_SMBASE; 140 141 // fs_base and gs_base 142 UINT64 IA32_FS_BASE; 143 UINT64 IA32_GS_BASE; 144 }VMM_TEARDOWN_GUEST_STATES; 145 146 147 #define COMPATIBILITY_CODE32_CS CODE32_GDT_ENTRY_OFFSET 148 149 // asm function 150 int 151 call_teardown_thunk32( 152 UINT64 current_guest_states_phy_addr, // the virtual addr of storing current guest states. 153 UINT16 compatibility_cs, // code segement selector for compatitiliby mode. 154 UINT64 teardown_thunk_entry_phy_addr, // virtual address of teardown thunk entry. 155 UINT64 cr3_td_sm_32, // CR3 for teardown shared memory for 32 bits mode 156 BOOLEAN cr4_is_pae_on // PAE mode flag 157 ); 158 159 int call_teardown_thunk64( 160 UINT32 current_cpu_idx , // cpuidx 161 UINT64 current_guest_states_hva, // the host virtual address of storing current guest states. 162 UINT64 teardown_thunk_entry_hva // teardown thunk host virtual address 163 ); 164 165 void init_teardown_lock(void); 166 BOOLEAN vmexit_vmm_teardown(GUEST_CPU_HANDLE gcpu, 167 VMM_TEARDOWN_PARAMS *vmm_teardown_params); 168 BOOLEAN vmam_add_to_host_page_table(IN GUEST_CPU_HANDLE gcpu, 169 IN UINT64 start_gva, IN UINT64 num_pages); 170 171 #endif