KVM: x86 emulator: add and use new callbacks set_idt(), set_gdt()
authorAvi Kivity <avi@redhat.com>
Wed, 20 Apr 2011 12:12:00 +0000 (15:12 +0300)
committerAvi Kivity <avi@redhat.com>
Sun, 22 May 2011 12:39:08 +0000 (08:39 -0400)
Replacing direct calls to realmode_lgdt(), realmode_lidt().

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

index e2b082aa32014e5b4077f7fbdae4968df75c111b..4d1546aa610413b2435506e10cf7a2a7b067d429 100644 (file)
@@ -176,6 +176,8 @@ struct x86_emulate_ops {
                                                 int seg);
        void (*get_gdt)(struct x86_emulate_ctxt *ctxt, struct desc_ptr *dt);
        void (*get_idt)(struct x86_emulate_ctxt *ctxt, struct desc_ptr *dt);
+       void (*set_gdt)(struct x86_emulate_ctxt *ctxt, struct desc_ptr *dt);
+       void (*set_idt)(struct x86_emulate_ctxt *ctxt, struct desc_ptr *dt);
        ulong (*get_cr)(struct x86_emulate_ctxt *ctxt, int cr);
        int (*set_cr)(struct x86_emulate_ctxt *ctxt, int cr, ulong val);
        int (*cpl)(struct x86_emulate_ctxt *ctxt);
index e50bffcf3cc0aca9f4f738390d058237ae496aa1..a8616ca8320ed836ae4c4918aabb6e6fbd131104 100644 (file)
@@ -681,9 +681,6 @@ static inline int emulate_instruction(struct kvm_vcpu *vcpu,
        return x86_emulate_instruction(vcpu, 0, emulation_type, NULL, 0);
 }
 
-void realmode_lgdt(struct kvm_vcpu *vcpu, u16 size, unsigned long address);
-void realmode_lidt(struct kvm_vcpu *vcpu, u16 size, unsigned long address);
-
 void kvm_enable_efer_bits(u64);
 int kvm_get_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 *data);
 int kvm_set_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 data);
index 0ff7d4bd1bb277f371acb2b66764c6385a2df08a..57e0e291b38dba407857bce980a2851a4bf99fe5 100644 (file)
@@ -3494,6 +3494,7 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt)
        int rc = X86EMUL_CONTINUE;
        int saved_dst_type = c->dst.type;
        int irq; /* Used for int 3, int, and into */
+       struct desc_ptr desc_ptr;
 
        ctxt->decode.mem_read.pos = 0;
 
@@ -4005,9 +4006,6 @@ twobyte_insn:
        switch (c->b) {
        case 0x01: /* lgdt, lidt, lmsw */
                switch (c->modrm_reg) {
-                       u16 size;
-                       unsigned long address;
-
                case 0: /* vmcall */
                        if (c->modrm_mod != 3 || c->modrm_rm != 1)
                                goto cannot_emulate;
@@ -4023,10 +4021,11 @@ twobyte_insn:
                        break;
                case 2: /* lgdt */
                        rc = read_descriptor(ctxt, ops, c->src.addr.mem,
-                                            &size, &address, c->op_bytes);
+                                            &desc_ptr.size, &desc_ptr.address,
+                                            c->op_bytes);
                        if (rc != X86EMUL_CONTINUE)
                                goto done;
-                       realmode_lgdt(ctxt->vcpu, size, address);
+                       ctxt->ops->set_gdt(ctxt, &desc_ptr);
                        /* Disable writeback. */
                        c->dst.type = OP_NONE;
                        break;
@@ -4041,11 +4040,12 @@ twobyte_insn:
                                }
                        } else {
                                rc = read_descriptor(ctxt, ops, c->src.addr.mem,
-                                                    &size, &address,
+                                                    &desc_ptr.size,
+                                                    &desc_ptr.address,
                                                     c->op_bytes);
                                if (rc != X86EMUL_CONTINUE)
                                        goto done;
-                               realmode_lidt(ctxt->vcpu, size, address);
+                               ctxt->ops->set_idt(ctxt, &desc_ptr);
                        }
                        /* Disable writeback. */
                        c->dst.type = OP_NONE;
index 4f7248ea6cafe60e08da7961c4b6a98ffca6a529..7cd3a3b491dee6e07ff979cf18187fba0d54e406 100644 (file)
@@ -4249,6 +4249,16 @@ static void emulator_get_idt(struct x86_emulate_ctxt *ctxt, struct desc_ptr *dt)
        kvm_x86_ops->get_idt(emul_to_vcpu(ctxt), dt);
 }
 
+static void emulator_set_gdt(struct x86_emulate_ctxt *ctxt, struct desc_ptr *dt)
+{
+       kvm_x86_ops->set_gdt(emul_to_vcpu(ctxt), dt);
+}
+
+static void emulator_set_idt(struct x86_emulate_ctxt *ctxt, struct desc_ptr *dt)
+{
+       kvm_x86_ops->set_idt(emul_to_vcpu(ctxt), dt);
+}
+
 static unsigned long emulator_get_cached_segment_base(
        struct x86_emulate_ctxt *ctxt, int seg)
 {
@@ -4388,6 +4398,8 @@ static struct x86_emulate_ops emulate_ops = {
        .get_cached_segment_base = emulator_get_cached_segment_base,
        .get_gdt             = emulator_get_gdt,
        .get_idt             = emulator_get_idt,
+       .set_gdt             = emulator_set_gdt,
+       .set_idt             = emulator_set_idt,
        .get_cr              = emulator_get_cr,
        .set_cr              = emulator_set_cr,
        .cpl                 = emulator_get_cpl,
@@ -5049,20 +5061,6 @@ int kvm_fix_hypercall(struct kvm_vcpu *vcpu)
                                       rip, instruction, 3, NULL);
 }
 
-void realmode_lgdt(struct kvm_vcpu *vcpu, u16 limit, unsigned long base)
-{
-       struct desc_ptr dt = { limit, base };
-
-       kvm_x86_ops->set_gdt(vcpu, &dt);
-}
-
-void realmode_lidt(struct kvm_vcpu *vcpu, u16 limit, unsigned long base)
-{
-       struct desc_ptr dt = { limit, base };
-
-       kvm_x86_ops->set_idt(vcpu, &dt);
-}
-
 static int move_to_next_stateful_cpuid_entry(struct kvm_vcpu *vcpu, int i)
 {
        struct kvm_cpuid_entry2 *e = &vcpu->arch.cpuid_entries[i];