Implement lazy FPU support for KVM
PATCH 2/2 Implement lazy FPU support for KVM
Depends on previous patch in series.
Regards,
Anthony Liguori
From: Anthony Liguori <aliguori-r/[email protected]>
Subject: [PATCH][VT] Add lazy FPU support for VT
Only save/restore the FPU host state when the guest is actually using the FPU.
drivers/kvm/vmx.c +52 -5
@@ -101,6 +101,13 @@ (INTR_TYPE_EXCEPTION |PF_VECTOR |INTR_INFO_VALID_MASK ); } +static inline int is_no_device (u32 intr_info) +{ +return (intr_info & (INTR_INFO_INTR_TYPE_MASK |INTR_INFO_VECTOR_MASK | +INTR_INFO_VALID_MASK )) == + (INTR_TYPE_EXCEPTION |NM_VECTOR |INTR_INFO_VALID_MASK ); +} +static inline int is_external_interrupt (u32 intr_info) {return (intr_info & (INTR_INFO_INTR_TYPE_MASK |INTR_INFO_VALID_MASK ))
@@ -216,6 +223,16 @@#endif } +static void vmcs_clear_bits (unsigned long field,u32 mask) +{ +vmcs_writel (field,vmcs_readl (field) & ~mask); +} + +static void vmcs_set_bits (unsigned long field,u32 mask) +{ +vmcs_writel (field,vmcs_readl (field) | mask); +} +/* * Switches to specified vcpu, until a matching vcpu_put(), but assumes * vcpu mutex is already taken.
@@ -833,6 +850,11 @@ }#endif +if (!(cr0 &CR0_TS_MASK )) { + vcpu->fpu_active =1 ; +vmcs_clear_bits (EXCEPTION_BITMAP ,CR0_TS_MASK ); + } +vmcs_writel (CR0_READ_SHADOW , cr0);vmcs_writel (GUEST_CR0 , (cr0 & ~KVM_GUEST_CR0_MASK ) |KVM_VM_CR0_ALWAYS_ON );
@@ -842,6 +864,12 @@static void vmx_set_cr3 (struct kvm_vcpu *vcpu,unsigned long cr3) {vmcs_writel (GUEST_CR3 , cr3); + +if (!(vcpu->cr0 &CR0_TS_MASK )) { + vcpu->fpu_active =0 ; +vmcs_set_bits (GUEST_CR0 ,CR0_TS_MASK ); +vmcs_set_bits (EXCEPTION_BITMAP ,1 <<NM_VECTOR ); + } }static void vmx_set_cr4 (struct kvm_vcpu *vcpu,unsigned long cr4)
@@ -1368,6 +1396,15 @@ asm ("int $2" );return 1 ; } + +if (is_no_device (intr_info)) { + vcpu->fpu_active =1 ; +vmcs_clear_bits (EXCEPTION_BITMAP ,1 <<NM_VECTOR ); +if (!(vcpu->cr0 &CR0_TS_MASK )) +vmcs_clear_bits (GUEST_CR0 ,CR0_TS_MASK ); +return 1 ; + } + error_code =0 ; rip =vmcs_readl (GUEST_RIP );if (intr_info &INTR_INFO_DELIEVER_CODE_MASK )
@@ -1556,7 +1593,11 @@break ;case 2 :/* clts */ vcpu_load_rsp_rip (vcpu); -set_cr0 (vcpu, vcpu->cr0 & ~CR0_TS_MASK ); + vcpu->fpu_active =1 ; +vmcs_clear_bits (EXCEPTION_BITMAP ,1 <<NM_VECTOR ); +vmcs_clear_bits (GUEST_CR0 ,CR0_TS_MASK ); + vcpu->cr0 &= ~CR0_TS_MASK ; +vmcs_writel (CR0_READ_SHADOW , vcpu->cr0);skip_emulated_instruction (vcpu);return 1 ;case 1 :/*mov from cr*/
@@ -1806,8 +1847,10 @@if (vcpu->guest_debug.enabled)kvm_guest_debug_pre (vcpu); -fx_save (vcpu->host_fx_image); -fx_restore (vcpu->guest_fx_image); +if (vcpu->fpu_active) { +fx_save (vcpu->host_fx_image); +fx_restore (vcpu->guest_fx_image); + }#ifdef CONFIG_X86_64 if (is_long_mode (vcpu)) {
@@ -1965,8 +2008,11 @@ }#endif -fx_save (vcpu->guest_fx_image); -fx_restore (vcpu->host_fx_image); +if (vcpu->fpu_active) { +fx_save (vcpu->guest_fx_image); +fx_restore (vcpu->host_fx_image); + } + vcpu->interrupt_window_open = (vmcs_read32 (GUEST_INTERRUPTIBILITY_INFO ) &3 ) ==0 ; asm ("mov %0, %%ds; mov %0, %%es" : :"r" (__USER_DS));
@@ -2078,6 +2124,7 @@vmcs_clear (vmcs); vcpu->vmcs = vmcs; vcpu->launched =0 ; + vcpu->fpu_active =1 ;return 0 ;
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
kvm-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/kvm-devel
A message that is not in the archive (sent off-list or not yet received): 4630E331.6020308-r/[email protected]
Avi Kivity
AppliedQuoted 2 lines · Anthony Liguori
Depends on previous patch in series.
Applied both, thanks.
Signature · 8 lines
Do not meddle in the internals of kernels, for they are subtle and quick to panic. ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/