github.com/jlmucb/cloudproxy@v0.0.0-20170830161738-b5aa0b619bc4/cpvmm/vmm/memory/ept/ept_hw_layer.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_HW_LAYER_H
    16  #define _EPT_HW_LAYER_H
    17  
    18  #include "vmm_defs.h"
    19  #include "vmm_objects.h"
    20  #include "vmm_phys_mem_types.h"
    21  #include "scheduler.h"
    22  
    23  #pragma warning( disable : 4214 ) // enables UINT64 bitfield
    24  
    25  #define EPT_LOG(...)        VMM_LOG(mask_ept, level_trace, __VA_ARGS__)
    26  #define EPT_PRINTERROR(...) VMM_LOG(mask_ept, level_error, __VA_ARGS__)
    27  
    28  #define EPT_NUM_PDPTRS      4
    29  
    30  typedef union _EPTP {
    31      struct {
    32          UINT32
    33              ETMT:3,
    34              GAW:3,
    35              Reserved:6,
    36              AddressSpaceRootLow:20;
    37          UINT32 AddressSpaceRootHigh;
    38      } Bits;
    39      UINT64 Uint64;
    40  } EPTP;
    41  
    42  typedef enum
    43  {
    44      INVEPT_INDIVIDUAL_ADDRESS = 0,
    45      INVEPT_CONTEXT_WIDE,
    46      INVEPT_ALL_CONTEXTS
    47  } INVEPT_CMD_TYPE;
    48  
    49  typedef enum
    50  {
    51  	INVVPID_INDIVIDUAL_ADDRESS = 0,
    52  	INVVPID_SINGLE_CONTEXT,
    53  	INVVPID_ALL_CONTEXTS,
    54  	INVVPID_SINGLE_CONTEXT_GLOBAL
    55  } INVVPID_CMD_TYPE;
    56  
    57  typedef struct _INVEPT_ARG
    58  {
    59      UINT64 eptp;
    60      UINT64 gpa;
    61  } INVEPT_ARG;
    62  
    63  void vmm_asm_invept(INVEPT_ARG *, UINT32, UINT64 *);
    64  
    65  typedef struct _INVVPID_ARG
    66  {
    67  	UINT64 vpid;
    68  	UINT64 gva;
    69  } INVVPID_ARG;
    70  
    71  void vmm_asm_invvpid(INVVPID_ARG *, UINT32, UINT64 *);
    72  
    73  BOOLEAN ept_hw_is_ept_supported(void);
    74  BOOLEAN ept_hw_is_ept_enabled(GUEST_CPU_HANDLE gcpu);
    75  
    76  BOOLEAN ept_hw_enable_ept(GUEST_CPU_HANDLE gcpu);
    77  void ept_hw_disable_ept(GUEST_CPU_HANDLE gcpu);
    78  
    79  UINT64 ept_hw_get_eptp(GUEST_CPU_HANDLE gcpu);
    80  BOOLEAN ept_hw_set_eptp(GUEST_CPU_HANDLE gcpu, HPA ept_root_hpa, UINT32 gaw);
    81  
    82  VMM_PHYS_MEM_TYPE ept_hw_get_ept_memory_type(void);
    83  
    84  UINT32 ept_hw_get_guest_address_width(UINT32 actual_gaw);
    85  UINT32 ept_hw_get_guest_address_width_encoding(UINT32 width);
    86  UINT32 ept_hw_get_guest_address_width_from_encoding(UINT32 gaw_encoding);
    87  
    88  void ept_hw_set_pdtprs(GUEST_CPU_HANDLE gcpu, UINT64 pdptr[]);
    89  #ifdef INCLUDE_UNUSED_CODE
    90  void ept_hw_get_pdtprs(GUEST_CPU_HANDLE gcpu, UINT64 pdptr[]);
    91  #endif
    92  
    93  BOOLEAN ept_hw_is_invept_supported(void);
    94  BOOLEAN ept_hw_invept_all_contexts(void);
    95  BOOLEAN ept_hw_invept_context(UINT64 eptp);
    96  BOOLEAN ept_hw_invept_individual_address(UINT64 eptp, ADDRESS gpa);
    97  BOOLEAN ept_hw_invvpid_single_context(UINT64 vpid);
    98  BOOLEAN ept_hw_invvpid_all_contexts(void);
    99  BOOLEAN ept_hw_is_invvpid_supported(void);
   100  BOOLEAN ept_hw_invvpid_individual_address(UINT64 vpid, ADDRESS gva);
   101  
   102  
   103  #define CHECK_EXECUTION_ON_LOCAL_HOST_CPU(gcpu) \
   104      VMM_DEBUG_CODE (                            \
   105          {                                       \
   106          CPU_ID host_cpu_id = scheduler_get_host_cpu_id(gcpu);   \
   107                                                                  \
   108          VMM_ASSERT(host_cpu_id == hw_cpu_id());                 \
   109          }                                                       \
   110      )                                                           \
   111  
   112  #endif   //_EPT_HW_LAYER_H