4_基本框架_VMCS_ControlFields

序言:

  • 本节内容:

    1570958778218

概览 VMCS 在白皮书 3卷 24.1节等

  • 1570961176967

  • 主要讲了需要的环境VMCS(VMM给每个VM的环境(有6部分组成,后面再翻译) );VMCS的状态变化,以及一些操作的指令;VMLAUNCH 必须是一个 clear 状态的 VMCS

  • VMCS的状态变化关系:

  • 1570895617331

  • VMCS的前0xc字节3字段的意义:在 白皮书 3 卷 24.2节

  • 1570962766995

  • 1----VMCS 的组成:白皮书 intel手册 3卷 24.3节

    1570964555976

    • 1.1 guest-state area

 

实施:

前面分配的 4kb 给VMM的; 这里每个VM还需要4kb ;

 

  • 每新开启一个虚拟机;给其申请的4kb 都需要 初始化;VMClear()//拔电源

  • 需要选中虚拟机 vmptrload() // 有很多虚拟机;选中一个虚拟机;后面的操作都是针对此VM

  • 设置 VMCSRegion

    • 设置下面这些寄存器:

    1570965087977

    • 还要设置 VMCS的6个部分中有用的部分(具体各字段的意义;可以查看VMCS.pdf)

  • 如果 VMCS 直接初始化 0 就 运行;会产生 ErrorCode - 0x7;

    在 volume 3 .chapter 30.4 < VM instruction error numbers > 可以查阅错误码

    》 0x7: VM entry invalid control field(s)

    查看 VMCS 的fields:

    1570967854046

  • 好,那填充 Control Fields:

    • VM-Execution Control Fields:

      有两种VM-Execution Controls 组成

      • Pin-Based VM-Execution Controls

        这个就是针脚--硬件断点;这里设置是否拦截虚拟机VM自己的 IDT处理--1;还是传递给VMM 处理

      • Processor-Based VM-Execution Controls

        这个是处理器相关的执行控制:当执行一些特殊的指令或者 一些同步事件的时候(IO、CR3...);就会需要这个控制;来判断时候需要传递出去给VMM。

      阅读 白皮书如下:

      x

      示例: BASIC MSR 480h.[55] == 0; PINBASED_MSR 481h 的信息

    • 1570976774810

  • 如果 这里直接申请VMCS清0 ,不初始化必要的bit位,就运行;会出错的

    // 这里来源我的代码注释,由于中文会有红色波浪,这里就用我蹩脚的ENGLISH吧,也不转译过来了,很简单

    // RUNS BLANK;; 0x7 ERROR CODE THROWS;---★
    // so   -- LOOK FOR ITS REASON AND DEAL: volume 3 .chapter 30.4 < VM instruction error numbers >
    //     --  FOUNDED :  VM entry invalid control field(s)  --  Control Structure  -- VMCS -- < volume 3 . chapter 24 >
  • 所以 这里最简单的demo,先将Control fields 中的default class,和 Exit/Entry Control 初始化

    
    
 1 // 3. VM control fields
 2     // ---- 3.1 VM execution control: 
 3     // ---------1. Pin-Based VM-Execution Control (is Hardware Interruption)
 4     //                : Describes whether hook the the interruption and deals by itself IDT callbacks or pass it to host Machine 
 5     // ---------2. Processor-based VM-Execution Control(synchronous events,specific instructions)
 6     //                : Describes whether JMP-OUT to VMM when execute IO Instructions, store/load cr3 etc...
 7     //                Processor-based VM-E constitute TWO 32-bit vectors: 
 8     //                ---+----primary processor-based VM-execution controls
 9     //                ---+----secondary processor-based VM-execution controls
10     //            * 1Step : set defult1 class bits;  ((DWORD)(BASE_msr_481h>>32) &0) | (DWORD)(BASE_msr_481h&0x00000000ffffffff)
11     //             PS: for pinBASE_msr_481h values include some default class1 --MUST BE 1 bits 1,2,4  == 2 + 4+16 = 0x16
12 
13     Vmx_VmWrite(PIN_BASED_VM_EXEC_CONTROL,VMxAdjustControls(0,MSR_IA32_VMX_PINBASED_CTLS));
14     
15     //            * 2Step : set Msr482 default 1 class...
16     //           Details  see  chapter 24.6.2 and Appendix A.3.2;
17     //             PS: for processorBASE_msr_482h ,there are many default class1 --MUST BE 1 bits .... == .. = 0x401e172
18     Vmx_VmWrite(CPU_BASED_VM_EXEC_CONTROL,VMxAdjustControls(0,MSR_IA32_VMX_PROCBASED_CTLS));
19 
20 
21     // -- 3.2 3.3 is no as important as 3.1; 3.1 control fields  handles much
22     //        They are some default response,when action triggered 
23     // ---- 3.2 VM exit control.. References the Intel Guide books-- Volume 3 chapter 24.7
24     Vmx_VmWrite(VM_EXIT_CONTROLS,VMxAdjustControls(0, MSR_IA32_VMX_EXIT_CTLS));
25 
26     // ---- 3.3 VM entry control.. References the Intel Guide books-- Volume 3 chapter 24.8
27      Vmx_VmWrite(VM_ENTRY_CONTROLS, VMxAdjustControls(0, MSR_IA32_VMX_ENTRY_CTLS));

 

 

  

 

posted @ 2019-10-14 11:36  leibso二狗  阅读(909)  评论(0)    收藏  举报