KVM: x86 emulator: add new ->halt() callback
authorAvi Kivity <avi@redhat.com>
Wed, 20 Apr 2011 12:43:05 +0000 (15:43 +0300)
committerAvi Kivity <avi@redhat.com>
Sun, 22 May 2011 12:39:17 +0000 (08:39 -0400)
Instead of reaching into vcpu internals.

Signed-off-by: Avi Kivity <avi@redhat.com>
arch/x86/include/asm/kvm_emulate.h
arch/x86/kvm/emulate.c
arch/x86/kvm/x86.c

index f890769..d30f1e9 100644 (file)
@@ -186,6 +186,7 @@ struct x86_emulate_ops {
        int (*set_dr)(struct x86_emulate_ctxt *ctxt, int dr, ulong value);
        int (*set_msr)(struct x86_emulate_ctxt *ctxt, u32 msr_index, u64 data);
        int (*get_msr)(struct x86_emulate_ctxt *ctxt, u32 msr_index, u64 *pdata);
+       void (*halt)(struct x86_emulate_ctxt *ctxt);
        void (*get_fpu)(struct x86_emulate_ctxt *ctxt); /* disables preempt */
        void (*put_fpu)(struct x86_emulate_ctxt *ctxt); /* reenables preempt */
        int (*intercept)(struct x86_emulate_ctxt *ctxt,
index 5d774e9..210df51 100644 (file)
@@ -3913,7 +3913,7 @@ special_insn:
                c->dst.type = OP_NONE;  /* Disable writeback. */
                break;
        case 0xf4:              /* hlt */
-               ctxt->vcpu->arch.halt_request = 1;
+               ctxt->ops->halt(ctxt);
                break;
        case 0xf5:      /* cmc */
                /* complement carry flag from eflags reg */
index 8af49b3..2246cf1 100644 (file)
@@ -4351,6 +4351,11 @@ static int emulator_set_msr(struct x86_emulate_ctxt *ctxt,
        return kvm_set_msr(emul_to_vcpu(ctxt), msr_index, data);
 }
 
+static void emulator_halt(struct x86_emulate_ctxt *ctxt)
+{
+       emul_to_vcpu(ctxt)->arch.halt_request = 1;
+}
+
 static void emulator_get_fpu(struct x86_emulate_ctxt *ctxt)
 {
        preempt_disable();
@@ -4400,6 +4405,7 @@ static struct x86_emulate_ops emulate_ops = {
        .set_dr              = emulator_set_dr,
        .set_msr             = emulator_set_msr,
        .get_msr             = emulator_get_msr,
+       .halt                = emulator_halt,
        .get_fpu             = emulator_get_fpu,
        .put_fpu             = emulator_put_fpu,
        .intercept           = emulator_intercept,