Skip to content

Commit

Permalink
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel…
Browse files Browse the repository at this point in the history
…/git/avi/kvm

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/avi/kvm:
  KVM: Prevent guest fpu state from leaking into the host
  • Loading branch information
Linus Torvalds committed Jun 15, 2007
2 parents 4ff4275 + 7702fd1 commit 3ea88d6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
3 changes: 3 additions & 0 deletions drivers/kvm/kvm.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ struct kvm_vcpu {
char *host_fx_image;
char *guest_fx_image;
int fpu_active;
int guest_fpu_loaded;

int mmio_needed;
int mmio_read_completed;
Expand Down Expand Up @@ -508,6 +509,8 @@ void fx_init(struct kvm_vcpu *vcpu);
void load_msrs(struct vmx_msr_entry *e, int n);
void save_msrs(struct vmx_msr_entry *e, int n);
void kvm_resched(struct kvm_vcpu *vcpu);
void kvm_load_guest_fpu(struct kvm_vcpu *vcpu);
void kvm_put_guest_fpu(struct kvm_vcpu *vcpu);

int kvm_read_guest(struct kvm_vcpu *vcpu,
gva_t addr,
Expand Down
22 changes: 22 additions & 0 deletions drivers/kvm/kvm_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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()
*/
Expand Down
12 changes: 3 additions & 9 deletions drivers/kvm/vmx.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu)

static void vmx_vcpu_put(struct kvm_vcpu *vcpu)
{
kvm_put_guest_fpu(vcpu);
put_cpu();
}

Expand Down Expand Up @@ -1847,10 +1848,8 @@ static int vmx_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
if (vcpu->guest_debug.enabled)
kvm_guest_debug_pre(vcpu);

if (vcpu->fpu_active) {
fx_save(vcpu->host_fx_image);
fx_restore(vcpu->guest_fx_image);
}
kvm_load_guest_fpu(vcpu);

/*
* Loading guest fpu may have cleared host cr0.ts
*/
Expand Down Expand Up @@ -2012,11 +2011,6 @@ static int vmx_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
}
#endif

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));
Expand Down

0 comments on commit 3ea88d6

Please sign in to comment.