@@ -27,8 +27,8 @@ use super::definitions::VmxExitReason;
2727use super :: read_vmcs_revision_id;
2828use super :: structs:: { EptpList , IOBitmap , MsrBitmap , VmxRegion } ;
2929use super :: vmcs:: {
30- self , VmcsControl32 , VmcsControl64 , VmcsControlNW , VmcsGuest16 , VmcsGuest32 , VmcsGuest64 ,
31- VmcsGuestNW , VmcsHost16 , VmcsHost32 , VmcsHost64 , VmcsHostNW , exit_qualification,
30+ self , VmcsControl16 , VmcsControl32 , VmcsControl64 , VmcsControlNW , VmcsGuest16 , VmcsGuest32 ,
31+ VmcsGuest64 , VmcsGuestNW , VmcsHost16 , VmcsHost32 , VmcsHost64 , VmcsHostNW , exit_qualification,
3232 interrupt_exit_info,
3333} ;
3434use crate :: LinuxContext ;
@@ -476,6 +476,7 @@ impl<H: AxVCpuHal> VmxVcpu<H> {
476476 }
477477
478478 self . setup_vmcs_control ( ept_root, is_guest) ?;
479+ self . set_vpid ( self . id as u16 + 1 ) ?;
479480 self . unbind_from_current_processor ( ) ?;
480481 Ok ( ( ) )
481482 }
@@ -699,6 +700,9 @@ impl<H: AxVCpuHal> VmxVcpu<H> {
699700 }
700701 }
701702
703+ // Enable VPID to speed up `VMFUNC` operation.
704+ val |= CpuCtrl2 :: ENABLE_VPID ;
705+
702706 vmcs:: set_control (
703707 VmcsControl32 :: SECONDARY_PROCBASED_EXEC_CONTROLS ,
704708 Msr :: IA32_VMX_PROCBASED_CTLS2 ,
@@ -770,6 +774,14 @@ impl<H: AxVCpuHal> VmxVcpu<H> {
770774 Ok ( ( ) )
771775 }
772776
777+ fn set_vpid ( & mut self , vpid : u16 ) -> AxResult {
778+ if vpid == 0 || vpid > 0xfffe {
779+ return ax_err ! ( InvalidInput ) ;
780+ }
781+ VmcsControl16 :: VPID . write ( vpid) ?;
782+ Ok ( ( ) )
783+ }
784+
773785 fn load_vmcs_guest ( & self , linux : & mut LinuxContext ) -> AxResult {
774786 linux. rip = VmcsGuestNW :: RIP . read ( ) ? as _ ;
775787 linux. rsp = VmcsGuestNW :: RSP . read ( ) ? as _ ;
0 commit comments