diff options
author | Avi Kivity <avi@qumranet.com> | 2007-06-14 16:27:40 +0300 |
---|---|---|
committer | Avi Kivity <avi@qumranet.com> | 2007-06-15 12:30:59 +0300 |
commit | 7702fd1f6fea57921f2e643d27a23a2d0394499c (patch) | |
tree | 9a5275fb2f5eaccc491bfe5d9617c3da7f69aa5a /drivers/kvm/kvm_main.c | |
parent | 22b1a9203ea634ac0ee5240e021613da3328275f (diff) | |
download | lwn-7702fd1f6fea57921f2e643d27a23a2d0394499c.tar.gz lwn-7702fd1f6fea57921f2e643d27a23a2d0394499c.zip |
KVM: Prevent guest fpu state from leaking into the host
The lazy fpu changes did not take into account that some vmexit handlers
can sleep. Move loading the guest state into the inner loop so that it
can be reloaded if necessary, and move loading the host state into
vmx_vcpu_put() so it can be performed whenever we relinquish the vcpu.
Signed-off-by: Avi Kivity <avi@qumranet.com>
Diffstat (limited to 'drivers/kvm/kvm_main.c')
-rw-r--r-- | drivers/kvm/kvm_main.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c index da985b31b17e..8f1f07adb04e 100644 --- a/drivers/kvm/kvm_main.c +++ b/drivers/kvm/kvm_main.c @@ -253,6 +253,28 @@ int kvm_write_guest(struct kvm_vcpu *vcpu, gva_t addr, unsigned long size, } EXPORT_SYMBOL_GPL(kvm_write_guest); +void kvm_load_guest_fpu(struct kvm_vcpu *vcpu) +{ + if (!vcpu->fpu_active || vcpu->guest_fpu_loaded) + return; + + vcpu->guest_fpu_loaded = 1; + fx_save(vcpu->host_fx_image); + fx_restore(vcpu->guest_fx_image); +} +EXPORT_SYMBOL_GPL(kvm_load_guest_fpu); + +void kvm_put_guest_fpu(struct kvm_vcpu *vcpu) +{ + if (!vcpu->guest_fpu_loaded) + return; + + vcpu->guest_fpu_loaded = 0; + fx_save(vcpu->guest_fx_image); + fx_restore(vcpu->host_fx_image); +} +EXPORT_SYMBOL_GPL(kvm_put_guest_fpu); + /* * Switches to specified vcpu, until a matching vcpu_put() */ |