github.com/jlmucb/cloudproxy@v0.0.0-20170830161738-b5aa0b619bc4/cpvmm/vmm/memory/ept/ept.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 _EPT_H
    16  #define _EPT_H
    17  
    18  #include "vmm_defs.h"
    19  #include "vmm_objects.h"
    20  #include "memory_address_mapper_api.h"
    21  #include "ept_hw_layer.h"
    22  #include "list.h"
    23  #include "lock.h"
    24  
    25  #define ANY_CPU_ID                                   ((CPU_ID) -1)
    26  
    27  // internal data structures
    28  typedef struct _EPT_INVEPT_CMD
    29  {
    30      CPU_ID host_cpu_id;
    31      char padding[2];
    32      INVEPT_CMD_TYPE cmd;
    33      UINT64 eptp; // context
    34      UINT64 gpa;
    35  } EPT_INVEPT_CMD;
    36  
    37  typedef struct _EPT_SET_EPTP_CMD
    38  {
    39      UINT64 ept_root_table_hpa;
    40      UINT32 gaw;
    41      GUEST_ID guest_id;
    42      UINT16 padding;
    43      EPT_INVEPT_CMD *invept_cmd;
    44  } EPT_SET_EPTP_CMD;
    45  
    46  typedef struct _EPT_CPU_STATE
    47  {
    48      UINT64 cr0;
    49      UINT64 cr4;
    50      BOOLEAN is_initialized;
    51      BOOLEAN ept_enabled_save;
    52      UINT64 active_ept_root_table_hpa;
    53      UINT32 active_ept_gaw;
    54      UINT32 padding;
    55  } EPT_GUEST_CPU_STATE;
    56  
    57  typedef struct _EPT_GUEST_STATE
    58  {
    59      MAM_HANDLE address_space;
    60      UINT64 ept_root_table_hpa;
    61      UINT32 gaw;
    62      GUEST_ID guest_id;
    63      UINT16 padding;
    64      EPT_GUEST_CPU_STATE **gcpu_state;
    65      LIST_ELEMENT list[1];
    66  } EPT_GUEST_STATE;
    67  
    68  typedef struct _EPT_STATE
    69  {
    70      LIST_ELEMENT guest_state[1]; //EPT_GUEST_STATE
    71      UINT32 num_of_cpus;
    72      VMM_LOCK lock;
    73      UINT32 lock_count;
    74  } EPT_STATE;
    75  
    76  void ept_release_lock(void);
    77  void ept_acquire_lock(void);
    78  
    79  BOOLEAN ept_is_ept_supported(void);
    80  BOOLEAN ept_is_ept_enabled(IN GUEST_CPU_HANDLE gcpu);
    81  BOOLEAN ept_is_cpu_in_non_paged_mode(GUEST_ID guest_id);
    82  
    83  MAM_HANDLE ept_create_guest_address_space(GPM_HANDLE gpm, BOOLEAN original_perms);
    84  MAM_EPT_SUPER_PAGE_SUPPORT ept_get_mam_super_page_support(void);
    85  MAM_EPT_SUPPORTED_GAW ept_get_mam_supported_gaw(UINT32 gaw);
    86  UINT32 ept_get_guest_address_width(GPM_HANDLE gpm);
    87  
    88  void ept_set_current_ept(GUEST_CPU_HANDLE gcpu, UINT64 ept_root_table_hpa, UINT32 ept_gaw);
    89  void ept_get_default_ept(GUEST_HANDLE guest, UINT64 *ept_root_table_hpa, UINT32 *ept_gaw);
    90  
    91  void ept_set_pdtprs(GUEST_CPU_HANDLE gcpu, UINT64 cr4_value);
    92  UINT64 ept_get_eptp(GUEST_CPU_HANDLE gcpu);
    93  BOOLEAN ept_set_eptp(GUEST_CPU_HANDLE gcpu, UINT64 ept_root_table_hpa, UINT32 gaw);
    94  UINT64 ept_compute_eptp(GUEST_HANDLE guest, UINT64 ept_root_table_hpa, UINT32 gaw);
    95  void ept_invalidate_ept(CPU_ID from, void* arg);
    96  
    97  EPT_GUEST_STATE *ept_find_guest_state(GUEST_ID guest_id);
    98  
    99  BOOLEAN ept_enable(GUEST_CPU_HANDLE gcpu);
   100  void ept_disable(GUEST_CPU_HANDLE gcpu);
   101  
   102  #ifdef DEBUG
   103  void ept_print(IN GUEST_HANDLE guest, IN MAM_HANDLE address_space);
   104  #endif
   105  
   106  #endif