aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAvi Kivity <avi@redhat.com>2011-03-28 10:53:59 -0400
committerAvi Kivity <avi@redhat.com>2011-05-11 07:56:58 -0400
commit5037f6f324cdcc6c9071dc774aba992f96c7e5ff (patch)
tree600ae6a745b1952e2de36d8a7a14034438190041
parent1d6b114f20d06ac0749686e4d7b7c7913d9116db (diff)
KVM: x86 emulator: define callbacks for using the guest fpu within the emulator
Needed for emulating fpu instructions. Signed-off-by: Avi Kivity <avi@redhat.com>
-rw-r--r--arch/x86/include/asm/kvm_emulate.h2
-rw-r--r--arch/x86/kvm/x86.c18
2 files changed, 20 insertions, 0 deletions
diff --git a/arch/x86/include/asm/kvm_emulate.h b/arch/x86/include/asm/kvm_emulate.h
index c00aed12755d..4c0e68226113 100644
--- a/arch/x86/include/asm/kvm_emulate.h
+++ b/arch/x86/include/asm/kvm_emulate.h
@@ -158,6 +158,8 @@ struct x86_emulate_ops {
158 int (*set_dr)(int dr, unsigned long value, struct kvm_vcpu *vcpu); 158 int (*set_dr)(int dr, unsigned long value, struct kvm_vcpu *vcpu);
159 int (*set_msr)(struct kvm_vcpu *vcpu, u32 msr_index, u64 data); 159 int (*set_msr)(struct kvm_vcpu *vcpu, u32 msr_index, u64 data);
160 int (*get_msr)(struct kvm_vcpu *vcpu, u32 msr_index, u64 *pdata); 160 int (*get_msr)(struct kvm_vcpu *vcpu, u32 msr_index, u64 *pdata);
161 void (*get_fpu)(struct x86_emulate_ctxt *ctxt); /* disables preempt */
162 void (*put_fpu)(struct x86_emulate_ctxt *ctxt); /* reenables preempt */
161}; 163};
162 164
163/* Type, address-of, and value of an instruction's operand. */ 165/* Type, address-of, and value of an instruction's operand. */
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 11d692c7018d..5af66515337d 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -4281,6 +4281,22 @@ static void emulator_set_segment_selector(u16 sel, int seg,
4281 kvm_set_segment(vcpu, &kvm_seg, seg); 4281 kvm_set_segment(vcpu, &kvm_seg, seg);
4282} 4282}
4283 4283
4284static void emulator_get_fpu(struct x86_emulate_ctxt *ctxt)
4285{
4286 preempt_disable();
4287 kvm_load_guest_fpu(ctxt->vcpu);
4288 /*
4289 * CR0.TS may reference the host fpu state, not the guest fpu state,
4290 * so it may be clear at this point.
4291 */
4292 clts();
4293}
4294
4295static void emulator_put_fpu(struct x86_emulate_ctxt *ctxt)
4296{
4297 preempt_enable();
4298}
4299
4284static struct x86_emulate_ops emulate_ops = { 4300static struct x86_emulate_ops emulate_ops = {
4285 .read_std = kvm_read_guest_virt_system, 4301 .read_std = kvm_read_guest_virt_system,
4286 .write_std = kvm_write_guest_virt_system, 4302 .write_std = kvm_write_guest_virt_system,
@@ -4304,6 +4320,8 @@ static struct x86_emulate_ops emulate_ops = {
4304 .set_dr = emulator_set_dr, 4320 .set_dr = emulator_set_dr,
4305 .set_msr = kvm_set_msr, 4321 .set_msr = kvm_set_msr,
4306 .get_msr = kvm_get_msr, 4322 .get_msr = kvm_get_msr,
4323 .get_fpu = emulator_get_fpu,
4324 .put_fpu = emulator_put_fpu,
4307}; 4325};
4308 4326
4309static void cache_all_regs(struct kvm_vcpu *vcpu) 4327static void cache_all_regs(struct kvm_vcpu *vcpu)