diff options
author | Avi Kivity <avi@redhat.com> | 2010-05-03 09:05:44 -0400 |
---|---|---|
committer | Avi Kivity <avi@redhat.com> | 2010-08-01 03:35:28 -0400 |
commit | 1c11e713576edf33b95669be9c2dc0ff1e0c90d3 (patch) | |
tree | 9d7cde9a08747e4e633302b418de4b8eedaf1c2b | |
parent | 08acfa187117046f8b5044b4a4cdc910f3ceeeb5 (diff) |
KVM: VMX: Avoid writing HOST_CR0 every entry
cr0.ts may change between entries, so we copy cr0 to HOST_CR0 before each
entry. That is slow, so instead, set HOST_CR0 to have TS set unconditionally
(which is a safe value), and issue a clts() just before exiting vcpu context
if the task indeed owns the fpu.
Saves ~50 cycles/exit.
Signed-off-by: Avi Kivity <avi@redhat.com>
-rw-r--r-- | arch/x86/kvm/vmx.c | 9 | ||||
-rw-r--r-- | arch/x86/kvm/x86.c | 2 |
2 files changed, 4 insertions, 7 deletions
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index 64252075796a..598931734251 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c | |||
@@ -812,6 +812,8 @@ static void __vmx_load_host_state(struct vcpu_vmx *vmx) | |||
812 | wrmsrl(MSR_KERNEL_GS_BASE, vmx->msr_host_kernel_gs_base); | 812 | wrmsrl(MSR_KERNEL_GS_BASE, vmx->msr_host_kernel_gs_base); |
813 | } | 813 | } |
814 | #endif | 814 | #endif |
815 | if (current_thread_info()->status & TS_USEDFPU) | ||
816 | clts(); | ||
815 | } | 817 | } |
816 | 818 | ||
817 | static void vmx_load_host_state(struct vcpu_vmx *vmx) | 819 | static void vmx_load_host_state(struct vcpu_vmx *vmx) |
@@ -2507,7 +2509,7 @@ static int vmx_vcpu_setup(struct vcpu_vmx *vmx) | |||
2507 | vmcs_write32(PAGE_FAULT_ERROR_CODE_MATCH, !!bypass_guest_pf); | 2509 | vmcs_write32(PAGE_FAULT_ERROR_CODE_MATCH, !!bypass_guest_pf); |
2508 | vmcs_write32(CR3_TARGET_COUNT, 0); /* 22.2.1 */ | 2510 | vmcs_write32(CR3_TARGET_COUNT, 0); /* 22.2.1 */ |
2509 | 2511 | ||
2510 | vmcs_writel(HOST_CR0, read_cr0()); /* 22.2.3 */ | 2512 | vmcs_writel(HOST_CR0, read_cr0() | X86_CR0_TS); /* 22.2.3 */ |
2511 | vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */ | 2513 | vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */ |
2512 | vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */ | 2514 | vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */ |
2513 | 2515 | ||
@@ -3859,11 +3861,6 @@ static void vmx_vcpu_run(struct kvm_vcpu *vcpu) | |||
3859 | if (vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP) | 3861 | if (vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP) |
3860 | vmx_set_interrupt_shadow(vcpu, 0); | 3862 | vmx_set_interrupt_shadow(vcpu, 0); |
3861 | 3863 | ||
3862 | /* | ||
3863 | * Loading guest fpu may have cleared host cr0.ts | ||
3864 | */ | ||
3865 | vmcs_writel(HOST_CR0, read_cr0()); | ||
3866 | |||
3867 | asm( | 3864 | asm( |
3868 | /* Store host registers */ | 3865 | /* Store host registers */ |
3869 | "push %%"R"dx; push %%"R"bp;" | 3866 | "push %%"R"dx; push %%"R"bp;" |
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 1b270fd60634..801afc6461ed 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c | |||
@@ -1731,8 +1731,8 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu) | |||
1731 | 1731 | ||
1732 | void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu) | 1732 | void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu) |
1733 | { | 1733 | { |
1734 | kvm_put_guest_fpu(vcpu); | ||
1735 | kvm_x86_ops->vcpu_put(vcpu); | 1734 | kvm_x86_ops->vcpu_put(vcpu); |
1735 | kvm_put_guest_fpu(vcpu); | ||
1736 | } | 1736 | } |
1737 | 1737 | ||
1738 | static int is_efer_nx(void) | 1738 | static int is_efer_nx(void) |