github.com/jlmucb/cloudproxy@v0.0.0-20170830161738-b5aa0b619bc4/cpvmm/vmm/include/vmm_api.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 _VMM_API_H
    16  #define _VMM_API_H
    17  
    18  #include "vmm_defs.h"
    19  #include "host_memory_manager_api.h"
    20  #include "memory_address_mapper_api.h"
    21  #include "list.h"
    22  #ifdef VTLB_IS_SUPPORT
    23  #include "vtlb_view.h"
    24  #endif
    25  #include "vmm_dbg.h"
    26  #include "lock.h"
    27  #include "fvs.h"
    28  #include "ve.h"
    29  #include "msr_defs.h"
    30  #include "ipc.h"
    31  
    32  // Control States
    33  typedef enum {
    34      VMM_VPID                           = 0, //read/w directly
    35      VMM_EPTP_INDEX,
    36      VMM_CONTROL_VECTOR_PIN_EVENTS,
    37      VMM_CONTROL_VECTOR_PROCESSOR_EVENTS, // Special case - NmiWindow cannot be updated
    38                                       // using this value. Use special APIs to update
    39                                       // NmiWindow setting
    40      VMM_CONTROL2_VECTOR_PROCESSOR_EVENTS,
    41      VMM_EXCEPTION_BITMAP,
    42      VMM_CR3_TARGET_COUNT,
    43      VMM_CR0_MASK,
    44      VMM_CR4_MASK,
    45      VMM_CR0_READ_SHADOW,
    46      VMM_CR4_READ_SHADOW,
    47      VMM_PAGE_FAULT_ERROR_CODE_MASK,
    48      VMM_PAGE_FAULT_ERROR_CODE_MATCH,
    49      VMM_EXIT_CONTROL_VECTOR,
    50      VMM_EXIT_MSR_STORE_COUNT,
    51      VMM_EXIT_MSR_LOAD_COUNT,
    52      VMM_ENTER_CONTROL_VECTOR,
    53      VMM_ENTER_INTERRUPT_INFO,
    54      VMM_ENTER_EXCEPTION_ERROR_CODE,
    55      VMM_ENTER_INSTRUCTION_LENGTH,
    56      VMM_ENTER_MSR_LOAD_COUNT,
    57      VMM_IO_BITMAP_ADDRESS_A,
    58      VMM_IO_BITMAP_ADDRESS_B,
    59      VMM_MSR_BITMAP_ADDRESS,
    60      VMM_EXIT_MSR_STORE_ADDRESS,
    61      VMM_EXIT_MSR_LOAD_ADDRESS,
    62      VMM_ENTER_MSR_LOAD_ADDRESS,
    63      VMM_OSV_CONTROLLING_VMCS_ADDRESS,
    64      VMM_TSC_OFFSET,
    65      VMM_EXIT_INFO_GUEST_PHYSICAL_ADDRESS, //read only
    66      VMM_EXIT_INFO_INSTRUCTION_ERROR_CODE,
    67      VMM_EXIT_INFO_REASON,
    68      VMM_EXIT_INFO_EXCEPTION_INFO,
    69      VMM_EXIT_INFO_EXCEPTION_ERROR_CODE,
    70      VMM_EXIT_INFO_IDT_VECTORING,
    71      VMM_EXIT_INFO_IDT_VECTORING_ERROR_CODE,
    72      VMM_EXIT_INFO_INSTRUCTION_LENGTH,
    73      VMM_EXIT_INFO_INSTRUCTION_INFO,
    74      VMM_EXIT_INFO_QUALIFICATION,
    75      VMM_EXIT_INFO_IO_RCX,
    76      VMM_EXIT_INFO_IO_RSI,
    77      VMM_EXIT_INFO_IO_RDI,
    78      VMM_EXIT_INFO_IO_RIP,
    79      VMM_EXIT_INFO_GUEST_LINEAR_ADDRESS,//read only
    80      VMM_VIRTUAL_APIC_ADDRESS,
    81      VMM_APIC_ACCESS_ADDRESS,
    82      VMM_EXIT_TPR_THRESHOLD,
    83      VMM_EPTP_ADDRESS,
    84      VMM_CR3_TARGET_VALUE_0,
    85      VMM_CR3_TARGET_VALUE_1,
    86      VMM_CR3_TARGET_VALUE_2,
    87      VMM_CR3_TARGET_VALUE_3,
    88  #ifdef FAST_VIEW_SWITCH
    89      VMM_VMFUNC_CONTROL,
    90      VMM_VMFUNC_EPTP_LIST_ADDRESS,
    91  #endif
    92      //last
    93      NUM_OF_VMM_CONTROL_STATE
    94  } VMM_CONTROL_STATE;
    95  
    96  // Guest States
    97  typedef enum {
    98      // START: GPRs
    99      /* GPRs should be at the start of this structure. Their value should match
   100       * the value in VMM_IA32_GP_REGISTERS structure.
   101       */
   102      VMM_GUEST_IA32_GP_RAX = 0,
   103      VMM_GUEST_IA32_GP_RBX,
   104      VMM_GUEST_IA32_GP_RCX,
   105      VMM_GUEST_IA32_GP_RDX,
   106      VMM_GUEST_IA32_GP_RDI,
   107      VMM_GUEST_IA32_GP_RSI,
   108      VMM_GUEST_IA32_GP_RBP,
   109      VMM_GUEST_IA32_GP_RSP,
   110      VMM_GUEST_IA32_GP_R8,
   111      VMM_GUEST_IA32_GP_R9,
   112      VMM_GUEST_IA32_GP_R10,
   113      VMM_GUEST_IA32_GP_R11,
   114      VMM_GUEST_IA32_GP_R12,
   115      VMM_GUEST_IA32_GP_R13,
   116      VMM_GUEST_IA32_GP_R14,
   117      VMM_GUEST_IA32_GP_R15,
   118      // END: GPRs
   119      // START: VMCS GUEST fields
   120      /* The following VMCS fields should match the VMCS_GUEST_xxx fields in
   121       * VMCS_FIELD structure.
   122       */
   123      VMM_GUEST_CR0,
   124      VMM_GUEST_CR3,
   125      VMM_GUEST_CR4,
   126      VMM_GUEST_DR7,
   127      VMM_GUEST_ES_SELECTOR,
   128      VMM_GUEST_ES_BASE,
   129      VMM_GUEST_ES_LIMIT,
   130      VMM_GUEST_ES_AR,
   131      VMM_GUEST_CS_SELECTOR,
   132      VMM_GUEST_CS_BASE,
   133      VMM_GUEST_CS_LIMIT,
   134      VMM_GUEST_CS_AR,
   135      VMM_GUEST_SS_SELECTOR,
   136      VMM_GUEST_SS_BASE,
   137      VMM_GUEST_SS_LIMIT,
   138      VMM_GUEST_SS_AR,
   139      VMM_GUEST_DS_SELECTOR,
   140      VMM_GUEST_DS_BASE,
   141      VMM_GUEST_DS_LIMIT,
   142      VMM_GUEST_DS_AR,
   143      VMM_GUEST_FS_SELECTOR,
   144      VMM_GUEST_FS_BASE,
   145      VMM_GUEST_FS_LIMIT,
   146      VMM_GUEST_FS_AR,
   147      VMM_GUEST_GS_SELECTOR,
   148      VMM_GUEST_GS_BASE,
   149      VMM_GUEST_GS_LIMIT,
   150      VMM_GUEST_GS_AR,
   151      VMM_GUEST_LDTR_SELECTOR,
   152      VMM_GUEST_LDTR_BASE,
   153      VMM_GUEST_LDTR_LIMIT,
   154      VMM_GUEST_LDTR_AR,
   155      VMM_GUEST_TR_SELECTOR,
   156      VMM_GUEST_TR_BASE,
   157      VMM_GUEST_TR_LIMIT,
   158      VMM_GUEST_TR_AR,
   159      VMM_GUEST_GDTR_BASE,
   160      VMM_GUEST_GDTR_LIMIT,
   161      VMM_GUEST_IDTR_BASE,
   162      VMM_GUEST_IDTR_LIMIT,
   163      VMM_GUEST_RSP,
   164      VMM_GUEST_RIP,
   165      VMM_GUEST_RFLAGS,
   166      VMM_GUEST_PEND_DBE,
   167      VMM_GUEST_WORKING_VMCS_PTR,
   168      VMM_GUEST_DEBUG_CONTROL,
   169      VMM_GUEST_INTERRUPTIBILITY,
   170      VMM_GUEST_SLEEP_STATE,
   171      VMM_GUEST_SMBASE,
   172      VMM_GUEST_SYSENTER_CS,
   173      VMM_GUEST_SYSENTER_ESP,
   174      VMM_GUEST_SYSENTER_EIP,
   175      VMM_GUEST_PAT,
   176      VMM_GUEST_EFER,
   177      VMM_GUEST_IA32_PERF_GLOBAL_CTRL,
   178      VMM_GUEST_PDPTR0,
   179      VMM_GUEST_PDPTR1,
   180      VMM_GUEST_PDPTR2,
   181      VMM_GUEST_PDPTR3,
   182      // END: VMCS GUEST fields
   183      // START: Other fields
   184      /* Any new fields independent of GPRs and VMCS should be added here.
   185       */
   186      VMM_GUEST_PREEMPTION_TIMER,
   187      VMM_GUEST_CR8, // Only valid for 64-bit, undefined behavior in 32-bit
   188      // END: Other fields
   189      NUM_OF_VMM_GUEST_STATE
   190  } VMM_GUEST_STATE;
   191  
   192  #ifdef INCLUDE_UNUSED_CODE
   193  typedef enum {
   194      VMM_HOST_CR0              = 0,
   195      VMM_HOST_CR3,
   196      VMM_HOST_CR4,
   197      VMM_HOST_ES_SELECTOR,
   198      VMM_HOST_CS_SELECTOR,
   199      VMM_HOST_SS_SELECTOR,
   200      VMM_HOST_DS_SELECTOR,
   201      VMM_HOST_FS_SELECTOR,
   202      VMM_HOST_FS_BASE,
   203      VMM_HOST_GS_SELECTOR,
   204      VMM_HOST_GS_BASE,
   205      VMM_HOST_TR_SELECTOR,
   206      VMM_HOST_TR_BASE,
   207      VMM_HOST_GDTR_BASE,
   208      VMM_HOST_IDTR_BASE,
   209      VMM_HOST_RSP,
   210      VMM_HOST_RIP,
   211      VMM_HOST_SYSENTER_CS,
   212      VMM_HOST_SYSENTER_ESP,
   213      VMM_HOST_SYSENTER_EIP,
   214      VMM_HOST_PAT,
   215      VMM_HOST_EFER,
   216      VMM_HOST_IA32_PERF_GLOBAL_CTRL,
   217      //last
   218      NUM_OF_VMM_HOST_STATE
   219  } VMM_HOST_STATE;
   220  #endif
   221  
   222  typedef union VMM_CONTROLS_U {
   223      struct {
   224          UINT64 mask;
   225          UINT64 value;
   226      } mask_value;
   227      struct {
   228          UINT64 gaw;
   229          UINT64 ept_root_table_hpa;
   230      } ept_value;
   231  #ifdef INCLUDE_UNUSED_CODE
   232      struct {
   233          UINT64 cr3_count;
   234          UINT64 cr3_value[4];
   235      } cr3;
   236  #endif
   237      UINT64 value;
   238  } VMM_CONTROLS;
   239  
   240  typedef struct _VMM_GUEST_STATE_VALUE {
   241  	BOOLEAN skip_rip;  // For setting RIP
   242  	                   // TRUE to skip instruction;
   243  	                   // FALSE to set RIP to new value
   244  	UINT8   padding[4];
   245  	UINT64  value;
   246  } VMM_GUEST_STATE_VALUE;
   247  
   248  // PURPOSE  : Get the value of given Guest State ID
   249  // ARGUMENTS: gcpu        (IN) -- Guest CPU Handle
   250  //            GuestStateId(IN) -- Guest State ID
   251  //            value       (OUT)-- Pointer of the Guest
   252  //                                State value
   253  // RETURNS  : TRUE
   254  //            FALSE
   255  BOOLEAN vmm_get_vmcs_guest_state(GUEST_CPU_HANDLE gcpu, 
   256              VMM_GUEST_STATE GuestStateId, VMM_GUEST_STATE_VALUE *value);
   257  
   258  // PURPOSE  : Set the value of given Guest State ID to the
   259  //            given value
   260  // ARGUMENTS: gcpu        (IN) -- Guest CPU Handle
   261  //            GuestStateId(IN) -- Guest State ID
   262  //            value       (IN) -- Given Guest State value
   263  // RETURNS  : TRUE
   264  //            FALSE
   265  BOOLEAN vmm_set_vmcs_guest_state(GUEST_CPU_HANDLE gcpu, 
   266              VMM_GUEST_STATE GuestStateId, VMM_GUEST_STATE_VALUE value);
   267  
   268  
   269  // PURPOSE  : Get the value of given Control State ID
   270  // ARGUMENTS: gcpu          (IN) -- Guest CPU Handle
   271  //            ControlStateId(IN) -- Control State ID
   272  //            value         (IN) -- Pointer of the Given
   273  //                                  Control State value
   274  // RETURNS  : TRUE
   275  //            FALSE
   276  BOOLEAN vmm_get_vmcs_control_state(GUEST_CPU_HANDLE gcpu, 
   277              VMM_CONTROL_STATE ControlStateId, VMM_CONTROLS* value);
   278  
   279  
   280  // PURPOSE  : Set the value of given Control State ID to
   281  //            the given value
   282  // ARGUMENTS: gcpu          (IN) -- Guest CPU Handle
   283  //            ControlStateId(IN) -- Control State ID
   284  //            value         (IN) -- Pointer of the Given
   285  //                                  Control State value
   286  // RETURNS  : TRUE
   287  //            FALSE
   288  BOOLEAN vmm_set_vmcs_control_state(GUEST_CPU_HANDLE gcpu, 
   289              VMM_CONTROL_STATE ControlStateId, VMM_CONTROLS* value);
   290  
   291  
   292  // PURPOSE  : Copy the given memory from given gva to
   293  //            given hva
   294  // ARGUMENTS: gcpu(IN) -- Guest CPU Handle
   295  //            gva (IN) -- Guest Virtual Address
   296  //            size(IN) -- size of the range from gva
   297  //            hva (IN) -- Pointer of Host Virtual Address
   298  // RETURNS  : 0 if successful
   299  int copy_from_gva(GUEST_CPU_HANDLE gcpu, UINT64 gva, int size, UINT64 hva);
   300  
   301  #endif //_VMM_API_H
   302