@@ -65,6 +65,7 @@ pub enum InjectedInterruptType {
6565pub struct VCpu {
6666 pub vm : Arc < RwLock < VirtualMachine > > ,
6767 pub vmcs : vmcs:: ActiveVmcs ,
68+ _local_apic : virtdev:: lapic:: LocalApic ,
6869 pending_interrupts : BTreeMap < u8 , InjectedInterruptType > ,
6970 stack : Vec < u8 > ,
7071}
@@ -85,15 +86,22 @@ impl VCpu {
8586 let mut vcpu = Box :: pin ( Self {
8687 vm : vm,
8788 vmcs : vmcs,
89+ _local_apic : virtdev:: lapic:: LocalApic :: new ( ) ,
8890 stack : stack,
8991 pending_interrupts : BTreeMap :: new ( ) ,
9092 } ) ;
9193
92- // All VCpus in a VM must share the same address space (except for the
93- // local apic)
94+ // All VCpus in a VM must share the same address space
9495 let eptp = vcpu. vm . read ( ) . guest_space . eptp ( ) ;
9596 vcpu. vmcs . write_field ( vmcs:: VmcsField :: EptPointer , eptp) ?;
9697
98+ // Setup access for our local apic
99+ let apic_access_addr = vcpu. vm . read ( ) . apic_access_page . as_ptr ( ) as u64 ;
100+ vcpu. vmcs
101+ . write_field ( vmcs:: VmcsField :: ApicAccessAddr , apic_access_addr) ?;
102+
103+ //TODO: set a per-core virtual apic page
104+
97105 let stack_base = vcpu. stack . as_ptr ( ) as u64 + vcpu. stack . len ( ) as u64
98106 - mem:: size_of :: < * const Self > ( ) as u64 ;
99107
@@ -272,6 +280,7 @@ impl VCpu {
272280 vmcs. write_with_fixed (
273281 vmcs:: VmcsField :: CpuBasedVmExecControl ,
274282 ( vmcs:: CpuBasedCtrlFlags :: UNCOND_IO_EXITING
283+ | vmcs:: CpuBasedCtrlFlags :: TPR_SHADOW
275284 | vmcs:: CpuBasedCtrlFlags :: ACTIVATE_MSR_BITMAP
276285 | vmcs:: CpuBasedCtrlFlags :: ACTIVATE_SECONDARY_CONTROLS )
277286 . bits ( ) ,
@@ -310,7 +319,8 @@ impl VCpu {
310319 vmcs. write_with_fixed (
311320 vmcs:: VmcsField :: VmExitControls ,
312321 ( vmcs:: VmExitCtrlFlags :: IA32E_MODE
313- | vmcs:: VmExitCtrlFlags :: ACK_INTR_ON_EXIT )
322+ | vmcs:: VmExitCtrlFlags :: ACK_INTR_ON_EXIT
323+ | vmcs:: VmExitCtrlFlags :: SAVE_GUEST_EFER )
314324 . bits ( ) ,
315325 msr:: IA32_VMX_EXIT_CTLS ,
316326 ) ?;
@@ -501,6 +511,9 @@ impl VCpu {
501511 }
502512 self . skip_emulated_instruction ( ) ?;
503513 }
514+ vmexit:: ExitInformation :: ApicAccess ( _info) => {
515+ self . skip_emulated_instruction ( ) ?;
516+ }
504517 vmexit:: ExitInformation :: CrAccess ( info) => {
505518 emulate:: controlreg:: emulate_access ( self , guest_cpu, info) ?;
506519 self . skip_emulated_instruction ( ) ?;
0 commit comments