vVMX: use latched VMCS machine address
PATCH v2 1/1 vVMX: use latched VMCS machine address
Instead of calling domain_page_map_to_mfn() over and over, latch the guest VMCS machine address unconditionally (i.e. independent of whether VMCS shadowing is supported by the hardware).
Since this requires altering the parameters of __[gs]et_vmcs{,_real}() (and hence all their callers) anyway, take the opportunity to also drop the bogus double underscores from their names (and from __[gs]et_vmcs_virtual() as well).
---
v2: Correct arguments passed to virtual_vmcs_{enter,exit}() (two
instances each). Move setting/clearing of the latched address out of nvmx_{set,clear}_vmcs_pointer(), allowing to otherwise restore them to the way they were before.
Thanks to Liang Z Li <[email protected]> for the debugging.
xen/arch/x86/hvm/vmx/intr.c +2 -2
@@ -191,13 +191,13 @@ static int nvmx_intr_intercept(struct vcif ( intack.source == hvm_intsrc_pic || intack.source == hvm_intsrc_lapic ) { - ctrl =__get_vvmcs (vcpu_nestedhvm (v).nv_vvmcx,PIN_BASED_VM_EXEC_CONTROL ); + ctrl =get_vvmcs (v,PIN_BASED_VM_EXEC_CONTROL );if ( !(ctrl &PIN_BASED_EXT_INTR_MASK ) )return 0 ;vmx_inject_extint (intack.vector, intack.source); - ctrl =__get_vvmcs (vcpu_nestedhvm (v).nv_vvmcx,VM_EXIT_CONTROLS ); + ctrl =get_vvmcs (v,VM_EXIT_CONTROLS );if ( ctrl &VM_EXIT_ACK_INTR_ON_EXIT ) {/* for now, duplicate the ack path in vmx_intr_assist */
xen/arch/x86/hvm/vmx/vmcs.c +10 -11
@@ -935,37 +935,36 @@ void vmx_vmcs_switch(paddr_t from, paddrspin_unlock (&vmx->vmcs_lock); } -void virtual_vmcs_enter (void *vvmcs) +void virtual_vmcs_enter (const struct vcpu *v) { -__vmptrld (pfn_to_paddr (domain_page_map_to_mfn (vvmcs))); +__vmptrld (v->arch.hvm_vmx.vmcs_shadow_maddr); } -void virtual_vmcs_exit (void *vvmcs) +void virtual_vmcs_exit (const struct vcpu *v) {paddr_t cur =this_cpu (current_vmcs); -__vmpclear (pfn_to_paddr (domain_page_map_to_mfn (vvmcs))); +__vmpclear (v->arch.hvm_vmx.vmcs_shadow_maddr);if ( cur )__vmptrld (cur); - } -u64 virtual_vmcs_vmread (void *vvmcs,u32 vmcs_encoding) +u64 virtual_vmcs_vmread (const struct vcpu *v,u32 vmcs_encoding) {u64 res; -virtual_vmcs_enter (vvmcs); +virtual_vmcs_enter (v);__vmread (vmcs_encoding, &res); -virtual_vmcs_exit (vvmcs); +virtual_vmcs_exit (v);return res; } -void virtual_vmcs_vmwrite (void *vvmcs,u32 vmcs_encoding,u64 val) +void virtual_vmcs_vmwrite (const struct vcpu *v,u32 vmcs_encoding,u64 val) { -virtual_vmcs_enter (vvmcs); +virtual_vmcs_enter (v);__vmwrite (vmcs_encoding, val); -virtual_vmcs_exit (vvmcs); +virtual_vmcs_exit (v); }/*
xen/arch/x86/hvm/vmx/vmx.c +2 -4
@@ -1477,8 +1477,7 @@ void vmx_inject_extint(int trap, uint8_tu32 pin_based_cntrl;if (nestedhvm_vcpu_in_guestmode (v) ) { - pin_based_cntrl =__get_vvmcs (vcpu_nestedhvm (v).nv_vvmcx, -PIN_BASED_VM_EXEC_CONTROL ); + pin_based_cntrl =get_vvmcs (v,PIN_BASED_VM_EXEC_CONTROL );if ( pin_based_cntrl &PIN_BASED_EXT_INTR_MASK ) { nvmx_enqueue_n2_exceptions (v, INTR_INFO_VALID_MASK |
@@ -1498,8 +1497,7 @@ void vmx_inject_nmi(void)u32 pin_based_cntrl;if (nestedhvm_vcpu_in_guestmode (v) ) { - pin_based_cntrl =__get_vvmcs (vcpu_nestedhvm (v).nv_vvmcx, -PIN_BASED_VM_EXEC_CONTROL ); + pin_based_cntrl =get_vvmcs (v,PIN_BASED_VM_EXEC_CONTROL );if ( pin_based_cntrl &PIN_BASED_NMI_EXITING ) { nvmx_enqueue_n2_exceptions (v, INTR_INFO_VALID_MASK |
xen/arch/x86/hvm/vmx/vvmx.c +120 -168
792 lines not on this page · raw message
xen/include/asm-x86/hvm/vmx/vmcs.h +5 -5
@@ -105,7 +105,7 @@ struct arch_vmx_struct {/* Physical address of VMCS. */ paddr_t vmcs_pa;/* VMCS shadow machine address. */ -paddr_t vmcs_shadow_maddr; +paddr_t vmcs_shadow_maddr;/* Protects remote usage of VMCS (VMPTRLD/VMCLEAR). */ spinlock_t vmcs_lock;
@@ -508,10 +508,10 @@ void vmx_vmcs_switch(paddr_t from, paddrvoid vmx_set_eoi_exit_bitmap (struct vcpu *v,u8 vector);void vmx_clear_eoi_exit_bitmap (struct vcpu *v,u8 vector);int vmx_check_msr_bitmap (unsigned long *msr_bitmap,u32 msr,int access_type); -void virtual_vmcs_enter (void *vvmcs); -void virtual_vmcs_exit (void *vvmcs); -u64 virtual_vmcs_vmread (void *vvmcs,u32 vmcs_encoding); -void virtual_vmcs_vmwrite (void *vvmcs,u32 vmcs_encoding,u64 val); +void virtual_vmcs_enter (const struct vcpu *); +void virtual_vmcs_exit (const struct vcpu *); +u64 virtual_vmcs_vmread (const struct vcpu *,u32 encoding); +void virtual_vmcs_vmwrite (const struct vcpu *,u32 encoding,u64 val);static inline int vmx_add_guest_msr (u32 msr) {
xen/include/asm-x86/hvm/vmx/vvmx.h +12 -10
@@ -181,18 +181,20 @@ enum vvmcs_encoding_type { VVMCS_TYPE_HSTATE, }; -u64 __get_vvmcs_virtual (void *vvmcs,u32 vmcs_encoding); -u64 __get_vvmcs_real (void *vvmcs,u32 vmcs_encoding); -void __set_vvmcs_virtual (void *vvmcs,u32 vmcs_encoding,u64 val); -void __set_vvmcs_real (void *vvmcs,u32 vmcs_encoding,u64 val); +u64 get_vvmcs_virtual (void *vvmcs,u32 encoding); +u64 get_vvmcs_real (const struct vcpu *,u32 encoding); +void set_vvmcs_virtual (void *vvmcs,u32 encoding,u64 val); +void set_vvmcs_real (const struct vcpu *,u32 encoding,u64 val); -#define __get_vvmcs (_vvmcs, _vmcs_encoding) \ - (cpu_has_vmx_vmcs_shadowing ? __get_vvmcs_real(_vvmcs, _vmcs_encoding) \ - : __get_vvmcs_virtual(_vvmcs, _vmcs_encoding)) +#define get_vvmcs (vcpu, encoding) \ + (cpu_has_vmx_vmcs_shadowing ? \ + get_vvmcs_real(vcpu, encoding) : \ + get_vvmcs_virtual(vcpu_nestedhvm(vcpu).nv_vvmcx, encoding)) -#define __set_vvmcs (_vvmcs, _vmcs_encoding, _val) \ - (cpu_has_vmx_vmcs_shadowing ? __set_vvmcs_real(_vvmcs, _vmcs_encoding, _val) \ - : __set_vvmcs_virtual(_vvmcs, _vmcs_encoding, _val)) +#define set_vvmcs (vcpu, encoding, val) \ + (cpu_has_vmx_vmcs_shadowing ? \ + set_vvmcs_real(vcpu, encoding, val) : \ + set_vvmcs_virtual(vcpu_nestedhvm(vcpu).nv_vvmcx, encoding, val))uint64_t get_shadow_eptp (struct vcpu *v);
vVMX: use latched VMCS machine address
Instead of calling domain_page_map_to_mfn() over and over, latch the guest VMCS machine address unconditionally (i.e. independent of whether VMCS shadowing is supported by the hardware).
Since this requires altering the parameters of __[gs]et_vmcs{,_real}() (and hence all their callers) anyway, take the opportunity to also drop the bogus double underscores from their names (and from __[gs]et_vmcs_virtual() as well).
---
v2: Correct arguments passed to virtual_vmcs_{enter,exit}() (two
instances each). Move setting/clearing of the latched address out of nvmx_{set,clear}_vmcs_pointer(), allowing to otherwise restore them to the way they were before.
Thanks to Liang Z Li <[email protected]> for the debugging.
xen/arch/x86/hvm/vmx/intr.c +2 -2
@@ -191,13 +191,13 @@ static int nvmx_intr_intercept(struct vcif ( intack.source == hvm_intsrc_pic || intack.source == hvm_intsrc_lapic ) { - ctrl =__get_vvmcs (vcpu_nestedhvm (v).nv_vvmcx,PIN_BASED_VM_EXEC_CONTROL ); + ctrl =get_vvmcs (v,PIN_BASED_VM_EXEC_CONTROL );if ( !(ctrl &PIN_BASED_EXT_INTR_MASK ) )return 0 ;vmx_inject_extint (intack.vector, intack.source); - ctrl =__get_vvmcs (vcpu_nestedhvm (v).nv_vvmcx,VM_EXIT_CONTROLS ); + ctrl =get_vvmcs (v,VM_EXIT_CONTROLS );if ( ctrl &VM_EXIT_ACK_INTR_ON_EXIT ) {/* for now, duplicate the ack path in vmx_intr_assist */
xen/arch/x86/hvm/vmx/vmcs.c +10 -11
@@ -935,37 +935,36 @@ void vmx_vmcs_switch(paddr_t from, paddrspin_unlock (&vmx->vmcs_lock); } -void virtual_vmcs_enter (void *vvmcs) +void virtual_vmcs_enter (const struct vcpu *v) { -__vmptrld (pfn_to_paddr (domain_page_map_to_mfn (vvmcs))); +__vmptrld (v->arch.hvm_vmx.vmcs_shadow_maddr); } -void virtual_vmcs_exit (void *vvmcs) +void virtual_vmcs_exit (const struct vcpu *v) {paddr_t cur =this_cpu (current_vmcs); -__vmpclear (pfn_to_paddr (domain_page_map_to_mfn (vvmcs))); +__vmpclear (v->arch.hvm_vmx.vmcs_shadow_maddr);if ( cur )__vmptrld (cur); - } -u64 virtual_vmcs_vmread (void *vvmcs,u32 vmcs_encoding) +u64 virtual_vmcs_vmread (const struct vcpu *v,u32 vmcs_encoding) {u64 res; -virtual_vmcs_enter (vvmcs); +virtual_vmcs_enter (v);__vmread (vmcs_encoding, &res); -virtual_vmcs_exit (vvmcs); +virtual_vmcs_exit (v);return res; } -void virtual_vmcs_vmwrite (void *vvmcs,u32 vmcs_encoding,u64 val) +void virtual_vmcs_vmwrite (const struct vcpu *v,u32 vmcs_encoding,u64 val) { -virtual_vmcs_enter (vvmcs); +virtual_vmcs_enter (v);__vmwrite (vmcs_encoding, val); -virtual_vmcs_exit (vvmcs); +virtual_vmcs_exit (v); }/*
xen/arch/x86/hvm/vmx/vmx.c +2 -4
@@ -1477,8 +1477,7 @@ void vmx_inject_extint(int trap, uint8_tu32 pin_based_cntrl;if (nestedhvm_vcpu_in_guestmode (v) ) { - pin_based_cntrl =__get_vvmcs (vcpu_nestedhvm (v).nv_vvmcx, -PIN_BASED_VM_EXEC_CONTROL ); + pin_based_cntrl =get_vvmcs (v,PIN_BASED_VM_EXEC_CONTROL );if ( pin_based_cntrl &PIN_BASED_EXT_INTR_MASK ) { nvmx_enqueue_n2_exceptions (v, INTR_INFO_VALID_MASK |
@@ -1498,8 +1497,7 @@ void vmx_inject_nmi(void)u32 pin_based_cntrl;if (nestedhvm_vcpu_in_guestmode (v) ) { - pin_based_cntrl =__get_vvmcs (vcpu_nestedhvm (v).nv_vvmcx, -PIN_BASED_VM_EXEC_CONTROL ); + pin_based_cntrl =get_vvmcs (v,PIN_BASED_VM_EXEC_CONTROL );if ( pin_based_cntrl &PIN_BASED_NMI_EXITING ) { nvmx_enqueue_n2_exceptions (v, INTR_INFO_VALID_MASK |
xen/arch/x86/hvm/vmx/vvmx.c +120 -168
792 lines not on this page · raw message
xen/include/asm-x86/hvm/vmx/vmcs.h +5 -5
@@ -105,7 +105,7 @@ struct arch_vmx_struct {/* Physical address of VMCS. */ paddr_t vmcs_pa;/* VMCS shadow machine address. */ -paddr_t vmcs_shadow_maddr; +paddr_t vmcs_shadow_maddr;/* Protects remote usage of VMCS (VMPTRLD/VMCLEAR). */ spinlock_t vmcs_lock;
@@ -508,10 +508,10 @@ void vmx_vmcs_switch(paddr_t from, paddrvoid vmx_set_eoi_exit_bitmap (struct vcpu *v,u8 vector);void vmx_clear_eoi_exit_bitmap (struct vcpu *v,u8 vector);int vmx_check_msr_bitmap (unsigned long *msr_bitmap,u32 msr,int access_type); -void virtual_vmcs_enter (void *vvmcs); -void virtual_vmcs_exit (void *vvmcs); -u64 virtual_vmcs_vmread (void *vvmcs,u32 vmcs_encoding); -void virtual_vmcs_vmwrite (void *vvmcs,u32 vmcs_encoding,u64 val); +void virtual_vmcs_enter (const struct vcpu *); +void virtual_vmcs_exit (const struct vcpu *); +u64 virtual_vmcs_vmread (const struct vcpu *,u32 encoding); +void virtual_vmcs_vmwrite (const struct vcpu *,u32 encoding,u64 val);static inline int vmx_add_guest_msr (u32 msr) {
xen/include/asm-x86/hvm/vmx/vvmx.h +12 -10
@@ -181,18 +181,20 @@ enum vvmcs_encoding_type { VVMCS_TYPE_HSTATE, }; -u64 __get_vvmcs_virtual (void *vvmcs,u32 vmcs_encoding); -u64 __get_vvmcs_real (void *vvmcs,u32 vmcs_encoding); -void __set_vvmcs_virtual (void *vvmcs,u32 vmcs_encoding,u64 val); -void __set_vvmcs_real (void *vvmcs,u32 vmcs_encoding,u64 val); +u64 get_vvmcs_virtual (void *vvmcs,u32 encoding); +u64 get_vvmcs_real (const struct vcpu *,u32 encoding); +void set_vvmcs_virtual (void *vvmcs,u32 encoding,u64 val); +void set_vvmcs_real (const struct vcpu *,u32 encoding,u64 val); -#define __get_vvmcs (_vvmcs, _vmcs_encoding) \ - (cpu_has_vmx_vmcs_shadowing ? __get_vvmcs_real(_vvmcs, _vmcs_encoding) \ - : __get_vvmcs_virtual(_vvmcs, _vmcs_encoding)) +#define get_vvmcs (vcpu, encoding) \ + (cpu_has_vmx_vmcs_shadowing ? \ + get_vvmcs_real(vcpu, encoding) : \ + get_vvmcs_virtual(vcpu_nestedhvm(vcpu).nv_vvmcx, encoding)) -#define __set_vvmcs (_vvmcs, _vmcs_encoding, _val) \ - (cpu_has_vmx_vmcs_shadowing ? __set_vvmcs_real(_vvmcs, _vmcs_encoding, _val) \ - : __set_vvmcs_virtual(_vvmcs, _vmcs_encoding, _val)) +#define set_vvmcs (vcpu, encoding, val) \ + (cpu_has_vmx_vmcs_shadowing ? \ + set_vvmcs_real(vcpu, encoding, val) : \ + set_vvmcs_virtual(vcpu_nestedhvm(vcpu).nv_vvmcx, encoding, val))uint64_t get_shadow_eptp (struct vcpu *v);
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 7 lines
From: Jan Beulich [mailto:[email protected]]
Sent: Thursday, February 25, 2016 7:58 PMInstead of calling
domain_page_map_to_mfn()over and over, latch the guest VMCS machine address unconditionally (i.e. independent of whether VMCS shadowing is supported by the hardware).
Quoted 7 lines
Since this requires altering the parameters of __[gs]et_vmcs{,_real}() (and hence all their callers) anyway, take the opportunity to also drop the bogus double underscores from their names (and from __[gs]et_vmcs_virtual() as well).
Signed-off-by Jan Beulich <[email protected]>Tested-by Liang Z Li <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel