KVM: Make unloading of FPU state when putting vcpu arch-independent
[pandora-kernel.git] / drivers / kvm / svm.c
index dbd4e81..fb3721d 100644 (file)
@@ -13,7 +13,7 @@
  * the COPYING file in the top-level directory.
  *
  */
-
+#include "x86.h"
 #include "kvm_svm.h"
 #include "x86_emulate.h"
 #include "irq.h"
@@ -22,7 +22,6 @@
 #include <linux/kernel.h>
 #include <linux/vmalloc.h>
 #include <linux/highmem.h>
-#include <linux/profile.h>
 #include <linux/sched.h>
 
 #include <asm/desc.h>
@@ -50,6 +49,8 @@ MODULE_LICENSE("GPL");
 #define SVM_FEATURE_LBRV (1 << 1)
 #define SVM_DEATURE_SVML (1 << 2)
 
+static void kvm_reput_irq(struct vcpu_svm *svm);
+
 static inline struct vcpu_svm *to_svm(struct kvm_vcpu *vcpu)
 {
        return container_of(vcpu, struct vcpu_svm, vcpu);
@@ -228,12 +229,11 @@ static void skip_emulated_instruction(struct kvm_vcpu *vcpu)
                printk(KERN_DEBUG "%s: NOP\n", __FUNCTION__);
                return;
        }
-       if (svm->next_rip - svm->vmcb->save.rip > MAX_INST_SIZE) {
+       if (svm->next_rip - svm->vmcb->save.rip > MAX_INST_SIZE)
                printk(KERN_ERR "%s: ip 0x%llx next 0x%llx\n",
                       __FUNCTION__,
                       svm->vmcb->save.rip,
                       svm->next_rip);
-       }
 
        vcpu->rip = svm->vmcb->save.rip = svm->next_rip;
        svm->vmcb->control.int_state &= ~SVM_INTERRUPT_SHADOW_MASK;
@@ -289,7 +289,7 @@ static void svm_hardware_enable(void *garbage)
 #ifdef CONFIG_X86_64
        struct desc_ptr gdt_descr;
 #else
-       struct Xgt_desc_struct gdt_descr;
+       struct desc_ptr gdt_descr;
 #endif
        struct desc_struct *gdt;
        int me = raw_smp_processor_id();
@@ -311,7 +311,7 @@ static void svm_hardware_enable(void *garbage)
        svm_data->next_asid = svm_data->max_asid + 1;
        svm_features = cpuid_edx(SVM_CPUID_FUNC);
 
-       asm volatile ( "sgdt %0" : "=m"(gdt_descr) );
+       asm volatile ("sgdt %0" : "=m"(gdt_descr));
        gdt = (struct desc_struct *)gdt_descr.address;
        svm_data->tss_desc = (struct kvm_ldttss_desc *)(gdt + GDT_ENTRY_TSS);
 
@@ -376,8 +376,6 @@ static __init int svm_hardware_setup(void)
        void *iopm_va, *msrpm_va;
        int r;
 
-       kvm_emulator_want_group7_invlpg();
-
        iopm_pages = alloc_pages(GFP_KERNEL, IOPM_ALLOC_ORDER);
 
        if (!iopm_pages)
@@ -477,7 +475,8 @@ static void init_vmcb(struct vmcb *vmcb)
                                        INTERCEPT_DR5_MASK |
                                        INTERCEPT_DR7_MASK;
 
-       control->intercept_exceptions = 1 << PF_VECTOR;
+       control->intercept_exceptions = (1 << PF_VECTOR) |
+                                       (1 << UD_VECTOR);
 
 
        control->intercept =    (1ULL << INTERCEPT_INTR) |
@@ -495,6 +494,7 @@ static void init_vmcb(struct vmcb *vmcb)
                 */
                /*              (1ULL << INTERCEPT_SELECTIVE_CR0) | */
                                (1ULL << INTERCEPT_CPUID) |
+                               (1ULL << INTERCEPT_INVD) |
                                (1ULL << INTERCEPT_HLT) |
                                (1ULL << INTERCEPT_INVLPGA) |
                                (1ULL << INTERCEPT_IOIO_PROT) |
@@ -508,6 +508,7 @@ static void init_vmcb(struct vmcb *vmcb)
                                (1ULL << INTERCEPT_STGI) |
                                (1ULL << INTERCEPT_CLGI) |
                                (1ULL << INTERCEPT_SKINIT) |
+                               (1ULL << INTERCEPT_WBINVD) |
                                (1ULL << INTERCEPT_MONITOR) |
                                (1ULL << INTERCEPT_MWAIT);
 
@@ -542,8 +543,7 @@ static void init_vmcb(struct vmcb *vmcb)
        init_sys_seg(&save->tr, SEG_TYPE_BUSY_TSS16);
 
        save->efer = MSR_EFER_SVME_MASK;
-
-        save->dr6 = 0xffff0ff0;
+       save->dr6 = 0xffff0ff0;
        save->dr7 = 0x400;
        save->rflags = 2;
        save->rip = 0x0000fff0;
@@ -557,6 +557,21 @@ static void init_vmcb(struct vmcb *vmcb)
        /* rdx = ?? */
 }
 
+static int svm_vcpu_reset(struct kvm_vcpu *vcpu)
+{
+       struct vcpu_svm *svm = to_svm(vcpu);
+
+       init_vmcb(svm->vmcb);
+
+       if (vcpu->vcpu_id != 0) {
+               svm->vmcb->save.rip = 0;
+               svm->vmcb->save.cs.base = svm->vcpu.sipi_vector << 12;
+               svm->vmcb->save.cs.selector = svm->vcpu.sipi_vector << 8;
+       }
+
+       return 0;
+}
+
 static struct kvm_vcpu *svm_create_vcpu(struct kvm *kvm, unsigned int id)
 {
        struct vcpu_svm *svm;
@@ -573,12 +588,6 @@ static struct kvm_vcpu *svm_create_vcpu(struct kvm *kvm, unsigned int id)
        if (err)
                goto free_svm;
 
-       if (irqchip_in_kernel(kvm)) {
-               err = kvm_create_lapic(&svm->vcpu);
-               if (err < 0)
-                       goto free_svm;
-       }
-
        page = alloc_page(GFP_KERNEL);
        if (!page) {
                err = -ENOMEM;
@@ -645,6 +654,7 @@ static void svm_vcpu_put(struct kvm_vcpu *vcpu)
        struct vcpu_svm *svm = to_svm(vcpu);
        int i;
 
+       ++vcpu->stat.host_state_reload;
        for (i = 0; i < NR_HOST_SAVE_USER_MSRS; i++)
                wrmsrl(host_save_user_msrs[i], svm->host_user_msrs[i]);
 
@@ -726,14 +736,6 @@ static void svm_get_segment(struct kvm_vcpu *vcpu,
        var->unusable = !var->present;
 }
 
-static void svm_get_cs_db_l_bits(struct kvm_vcpu *vcpu, int *db, int *l)
-{
-       struct vmcb_seg *s = svm_seg(vcpu, VCPU_SREG_CS);
-
-       *db = (s->attrib >> SVM_SELECTOR_DB_SHIFT) & 1;
-       *l = (s->attrib >> SVM_SELECTOR_L_SHIFT) & 1;
-}
-
 static void svm_get_idt(struct kvm_vcpu *vcpu, struct descriptor_table *dt)
 {
        struct vcpu_svm *svm = to_svm(vcpu);
@@ -781,7 +783,7 @@ static void svm_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0)
                        svm->vmcb->save.efer |= KVM_EFER_LMA | KVM_EFER_LME;
                }
 
-               if (is_paging(vcpu) && !(cr0 & X86_CR0_PG) ) {
+               if (is_paging(vcpu) && !(cr0 & X86_CR0_PG)) {
                        vcpu->shadow_efer &= ~KVM_EFER_LMA;
                        svm->vmcb->save.efer &= ~(KVM_EFER_LMA | KVM_EFER_LME);
                }
@@ -931,45 +933,25 @@ static int pf_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run)
        struct kvm *kvm = svm->vcpu.kvm;
        u64 fault_address;
        u32 error_code;
-       enum emulation_result er;
-       int r;
 
        if (!irqchip_in_kernel(kvm) &&
                is_external_interrupt(exit_int_info))
                push_irq(&svm->vcpu, exit_int_info & SVM_EVTINJ_VEC_MASK);
 
-       mutex_lock(&kvm->lock);
-
        fault_address  = svm->vmcb->control.exit_info_2;
        error_code = svm->vmcb->control.exit_info_1;
-       r = kvm_mmu_page_fault(&svm->vcpu, fault_address, error_code);
-       if (r < 0) {
-               mutex_unlock(&kvm->lock);
-               return r;
-       }
-       if (!r) {
-               mutex_unlock(&kvm->lock);
-               return 1;
-       }
-       er = emulate_instruction(&svm->vcpu, kvm_run, fault_address,
-                                error_code);
-       mutex_unlock(&kvm->lock);
+       return kvm_mmu_page_fault(&svm->vcpu, fault_address, error_code);
+}
 
-       switch (er) {
-       case EMULATE_DONE:
-               return 1;
-       case EMULATE_DO_MMIO:
-               ++svm->vcpu.stat.mmio_exits;
-               return 0;
-       case EMULATE_FAIL:
-               vcpu_printf(&svm->vcpu, "%s: emulate fail\n", __FUNCTION__);
-               break;
-       default:
-               BUG();
-       }
+static int ud_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run)
+{
+       int er;
 
-       kvm_run->exit_reason = KVM_EXIT_UNKNOWN;
-       return 0;
+       er = emulate_instruction(&svm->vcpu, kvm_run, 0, 0, 0);
+       if (er != EMULATE_DONE)
+               inject_ud(&svm->vcpu);
+
+       return 1;
 }
 
 static int nm_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run)
@@ -997,7 +979,7 @@ static int shutdown_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run)
 
 static int io_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run)
 {
-       u32 io_info = svm->vmcb->control.exit_info_1; //address size bug?
+       u32 io_info = svm->vmcb->control.exit_info_1; /* address size bug? */
        int size, down, in, string, rep;
        unsigned port;
 
@@ -1008,7 +990,8 @@ static int io_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run)
        string = (io_info & SVM_IOIO_STR_MASK) != 0;
 
        if (string) {
-               if (emulate_instruction(&svm->vcpu, kvm_run, 0, 0) == EMULATE_DO_MMIO)
+               if (emulate_instruction(&svm->vcpu,
+                                       kvm_run, 0, 0, 0) == EMULATE_DO_MMIO)
                        return 0;
                return 1;
        }
@@ -1038,7 +1021,8 @@ static int vmmcall_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run)
 {
        svm->next_rip = svm->vmcb->save.rip + 3;
        skip_emulated_instruction(&svm->vcpu);
-       return kvm_hypercall(&svm->vcpu, kvm_run);
+       kvm_emulate_hypercall(&svm->vcpu);
+       return 1;
 }
 
 static int invalid_op_interception(struct vcpu_svm *svm,
@@ -1066,7 +1050,7 @@ static int cpuid_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run)
 static int emulate_on_interception(struct vcpu_svm *svm,
                                   struct kvm_run *kvm_run)
 {
-       if (emulate_instruction(&svm->vcpu, NULL, 0, 0) != EMULATE_DONE)
+       if (emulate_instruction(&svm->vcpu, NULL, 0, 0, 0) != EMULATE_DONE)
                pr_unimpl(&svm->vcpu, "%s: failed\n", __FUNCTION__);
        return 1;
 }
@@ -1234,6 +1218,7 @@ static int (*svm_exit_handlers[])(struct vcpu_svm *svm,
        [SVM_EXIT_WRITE_DR3]                    = emulate_on_interception,
        [SVM_EXIT_WRITE_DR5]                    = emulate_on_interception,
        [SVM_EXIT_WRITE_DR7]                    = emulate_on_interception,
+       [SVM_EXIT_EXCP_BASE + UD_VECTOR]        = ud_interception,
        [SVM_EXIT_EXCP_BASE + PF_VECTOR]        = pf_interception,
        [SVM_EXIT_EXCP_BASE + NM_VECTOR]        = nm_interception,
        [SVM_EXIT_INTR]                         = nop_on_interception,
@@ -1243,6 +1228,7 @@ static int (*svm_exit_handlers[])(struct vcpu_svm *svm,
        [SVM_EXIT_VINTR]                        = interrupt_window_interception,
        /* [SVM_EXIT_CR0_SEL_WRITE]             = emulate_on_interception, */
        [SVM_EXIT_CPUID]                        = cpuid_interception,
+       [SVM_EXIT_INVD]                         = emulate_on_interception,
        [SVM_EXIT_HLT]                          = halt_interception,
        [SVM_EXIT_INVLPG]                       = emulate_on_interception,
        [SVM_EXIT_INVLPGA]                      = invalid_op_interception,
@@ -1257,15 +1243,26 @@ static int (*svm_exit_handlers[])(struct vcpu_svm *svm,
        [SVM_EXIT_STGI]                         = invalid_op_interception,
        [SVM_EXIT_CLGI]                         = invalid_op_interception,
        [SVM_EXIT_SKINIT]                       = invalid_op_interception,
+       [SVM_EXIT_WBINVD]                       = emulate_on_interception,
        [SVM_EXIT_MONITOR]                      = invalid_op_interception,
        [SVM_EXIT_MWAIT]                        = invalid_op_interception,
 };
 
 
-static int handle_exit(struct vcpu_svm *svm, struct kvm_run *kvm_run)
+static int handle_exit(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
 {
+       struct vcpu_svm *svm = to_svm(vcpu);
        u32 exit_code = svm->vmcb->control.exit_code;
 
+       kvm_reput_irq(svm);
+
+       if (svm->vmcb->control.exit_code == SVM_EXIT_ERR) {
+               kvm_run->exit_reason = KVM_EXIT_FAIL_ENTRY;
+               kvm_run->fail_entry.hardware_entry_failure_reason
+                       = svm->vmcb->control.exit_code;
+               return 0;
+       }
+
        if (is_external_interrupt(svm->vmcb->control.exit_int_info) &&
            exit_code != SVM_EXIT_EXCP_BASE + PF_VECTOR)
                printk(KERN_ERR "%s: unexpected exit_ini_info 0x%x "
@@ -1274,7 +1271,7 @@ static int handle_exit(struct vcpu_svm *svm, struct kvm_run *kvm_run)
                       exit_code);
 
        if (exit_code >= ARRAY_SIZE(svm_exit_handlers)
-           || svm_exit_handlers[exit_code] == 0) {
+           || !svm_exit_handlers[exit_code]) {
                kvm_run->exit_reason = KVM_EXIT_UNKNOWN;
                kvm_run->hw.hardware_exit_reason = exit_code;
                return 0;
@@ -1288,7 +1285,7 @@ static void reload_tss(struct kvm_vcpu *vcpu)
        int cpu = raw_smp_processor_id();
 
        struct svm_cpu_data *svm_data = per_cpu(svm_data, cpu);
-       svm_data->tss_desc->type = 9; //available 32/64-bit TSS
+       svm_data->tss_desc->type = 9; /* available 32/64-bit TSS */
        load_TR_desc();
 }
 
@@ -1323,13 +1320,12 @@ static void svm_set_irq(struct kvm_vcpu *vcpu, int irq)
        svm_inject_irq(svm, irq);
 }
 
-static void svm_intr_assist(struct vcpu_svm *svm)
+static void svm_intr_assist(struct kvm_vcpu *vcpu)
 {
+       struct vcpu_svm *svm = to_svm(vcpu);
        struct vmcb *vmcb = svm->vmcb;
        int intr_vector = -1;
-       struct kvm_vcpu *vcpu = &svm->vcpu;
 
-       kvm_inject_pending_timer_irqs(vcpu);
        if ((vmcb->control.exit_int_info & SVM_EVTINJ_VALID) &&
            ((vmcb->control.exit_int_info & SVM_EVTINJ_TYPE_MASK) == 0)) {
                intr_vector = vmcb->control.exit_int_info &
@@ -1386,9 +1382,10 @@ static void svm_do_inject_vector(struct vcpu_svm *svm)
        svm_inject_irq(svm, irq);
 }
 
-static void do_interrupt_requests(struct vcpu_svm *svm,
+static void do_interrupt_requests(struct kvm_vcpu *vcpu,
                                       struct kvm_run *kvm_run)
 {
+       struct vcpu_svm *svm = to_svm(vcpu);
        struct vmcb_control_area *control = &svm->vmcb->control;
 
        svm->vcpu.interrupt_window_open =
@@ -1405,39 +1402,15 @@ static void do_interrupt_requests(struct vcpu_svm *svm,
         * Interrupts blocked.  Wait for unblock.
         */
        if (!svm->vcpu.interrupt_window_open &&
-           (svm->vcpu.irq_summary || kvm_run->request_interrupt_window)) {
+           (svm->vcpu.irq_summary || kvm_run->request_interrupt_window))
                control->intercept |= 1ULL << INTERCEPT_VINTR;
-       } else
+        else
                control->intercept &= ~(1ULL << INTERCEPT_VINTR);
 }
 
-static void post_kvm_run_save(struct vcpu_svm *svm,
-                             struct kvm_run *kvm_run)
+static int svm_set_tss_addr(struct kvm *kvm, unsigned int addr)
 {
-       if (irqchip_in_kernel(svm->vcpu.kvm))
-               kvm_run->ready_for_interrupt_injection = 1;
-       else
-               kvm_run->ready_for_interrupt_injection =
-                                        (svm->vcpu.interrupt_window_open &&
-                                         svm->vcpu.irq_summary == 0);
-       kvm_run->if_flag = (svm->vmcb->save.rflags & X86_EFLAGS_IF) != 0;
-       kvm_run->cr8 = get_cr8(&svm->vcpu);
-       kvm_run->apic_base = kvm_get_apic_base(&svm->vcpu);
-}
-
-/*
- * Check if userspace requested an interrupt window, and that the
- * interrupt window is open.
- *
- * No need to exit to userspace if we already have an interrupt queued.
- */
-static int dm_request_for_irq_injection(struct vcpu_svm *svm,
-                                         struct kvm_run *kvm_run)
-{
-       return (!svm->vcpu.irq_summary &&
-               kvm_run->request_interrupt_window &&
-               svm->vcpu.interrupt_window_open &&
-               (svm->vmcb->save.rflags & X86_EFLAGS_IF));
+       return 0;
 }
 
 static void save_db_regs(unsigned long *db_regs)
@@ -1461,38 +1434,16 @@ static void svm_flush_tlb(struct kvm_vcpu *vcpu)
        force_new_asid(vcpu);
 }
 
-static int svm_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
+static void svm_prepare_guest_switch(struct kvm_vcpu *vcpu)
+{
+}
+
+static void svm_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
 {
        struct vcpu_svm *svm = to_svm(vcpu);
        u16 fs_selector;
        u16 gs_selector;
        u16 ldt_selector;
-       int r;
-
-again:
-       r = kvm_mmu_reload(vcpu);
-       if (unlikely(r))
-               return r;
-
-       clgi();
-
-       if (signal_pending(current)) {
-               stgi();
-               ++vcpu->stat.signal_exits;
-               post_kvm_run_save(svm, kvm_run);
-               kvm_run->exit_reason = KVM_EXIT_INTR;
-               return -EINTR;
-       }
-
-       if (irqchip_in_kernel(vcpu->kvm))
-               svm_intr_assist(svm);
-       else if (!vcpu->mmio_read_completed)
-               do_interrupt_requests(svm, kvm_run);
-
-       vcpu->guest_mode = 1;
-       if (vcpu->requests)
-               if (test_and_clear_bit(KVM_TLB_FLUSH, &vcpu->requests))
-                   svm_flush_tlb(vcpu);
 
        pre_svm_run(svm);
 
@@ -1511,20 +1462,15 @@ again:
                load_db_regs(svm->db_regs);
        }
 
-       if (vcpu->fpu_active) {
-               fx_save(&vcpu->host_fx_image);
-               fx_restore(&vcpu->guest_fx_image);
-       }
+       clgi();
+
+       local_irq_enable();
 
        asm volatile (
 #ifdef CONFIG_X86_64
-               "push %%rbx; push %%rcx; push %%rdx;"
-               "push %%rsi; push %%rdi; push %%rbp;"
-               "push %%r8;  push %%r9;  push %%r10; push %%r11;"
-               "push %%r12; push %%r13; push %%r14; push %%r15;"
+               "push %%rbp; \n\t"
 #else
-               "push %%ebx; push %%ecx; push %%edx;"
-               "push %%esi; push %%edi; push %%ebp;"
+               "push %%ebp; \n\t"
 #endif
 
 #ifdef CONFIG_X86_64
@@ -1586,10 +1532,7 @@ again:
                "mov %%r14, %c[r14](%[svm]) \n\t"
                "mov %%r15, %c[r15](%[svm]) \n\t"
 
-               "pop  %%r15; pop  %%r14; pop  %%r13; pop  %%r12;"
-               "pop  %%r11; pop  %%r10; pop  %%r9;  pop  %%r8;"
-               "pop  %%rbp; pop  %%rdi; pop  %%rsi;"
-               "pop  %%rdx; pop  %%rcx; pop  %%rbx; \n\t"
+               "pop  %%rbp; \n\t"
 #else
                "mov %%ebx, %c[rbx](%[svm]) \n\t"
                "mov %%ecx, %c[rcx](%[svm]) \n\t"
@@ -1598,36 +1541,35 @@ again:
                "mov %%edi, %c[rdi](%[svm]) \n\t"
                "mov %%ebp, %c[rbp](%[svm]) \n\t"
 
-               "pop  %%ebp; pop  %%edi; pop  %%esi;"
-               "pop  %%edx; pop  %%ecx; pop  %%ebx; \n\t"
+               "pop  %%ebp; \n\t"
 #endif
                :
                : [svm]"a"(svm),
                  [vmcb]"i"(offsetof(struct vcpu_svm, vmcb_pa)),
-                 [rbx]"i"(offsetof(struct vcpu_svm,vcpu.regs[VCPU_REGS_RBX])),
-                 [rcx]"i"(offsetof(struct vcpu_svm,vcpu.regs[VCPU_REGS_RCX])),
-                 [rdx]"i"(offsetof(struct vcpu_svm,vcpu.regs[VCPU_REGS_RDX])),
-                 [rsi]"i"(offsetof(struct vcpu_svm,vcpu.regs[VCPU_REGS_RSI])),
-                 [rdi]"i"(offsetof(struct vcpu_svm,vcpu.regs[VCPU_REGS_RDI])),
-                 [rbp]"i"(offsetof(struct vcpu_svm,vcpu.regs[VCPU_REGS_RBP]))
+                 [rbx]"i"(offsetof(struct vcpu_svm, vcpu.regs[VCPU_REGS_RBX])),
+                 [rcx]"i"(offsetof(struct vcpu_svm, vcpu.regs[VCPU_REGS_RCX])),
+                 [rdx]"i"(offsetof(struct vcpu_svm, vcpu.regs[VCPU_REGS_RDX])),
+                 [rsi]"i"(offsetof(struct vcpu_svm, vcpu.regs[VCPU_REGS_RSI])),
+                 [rdi]"i"(offsetof(struct vcpu_svm, vcpu.regs[VCPU_REGS_RDI])),
+                 [rbp]"i"(offsetof(struct vcpu_svm, vcpu.regs[VCPU_REGS_RBP]))
 #ifdef CONFIG_X86_64
-                 ,[r8 ]"i"(offsetof(struct vcpu_svm,vcpu.regs[VCPU_REGS_R8])),
-                 [r9 ]"i"(offsetof(struct vcpu_svm,vcpu.regs[VCPU_REGS_R9 ])),
-                 [r10]"i"(offsetof(struct vcpu_svm,vcpu.regs[VCPU_REGS_R10])),
-                 [r11]"i"(offsetof(struct vcpu_svm,vcpu.regs[VCPU_REGS_R11])),
-                 [r12]"i"(offsetof(struct vcpu_svm,vcpu.regs[VCPU_REGS_R12])),
-                 [r13]"i"(offsetof(struct vcpu_svm,vcpu.regs[VCPU_REGS_R13])),
-                 [r14]"i"(offsetof(struct vcpu_svm,vcpu.regs[VCPU_REGS_R14])),
-                 [r15]"i"(offsetof(struct vcpu_svm,vcpu.regs[VCPU_REGS_R15]))
+                 , [r8]"i"(offsetof(struct vcpu_svm, vcpu.regs[VCPU_REGS_R8])),
+                 [r9]"i"(offsetof(struct vcpu_svm, vcpu.regs[VCPU_REGS_R9])),
+                 [r10]"i"(offsetof(struct vcpu_svm, vcpu.regs[VCPU_REGS_R10])),
+                 [r11]"i"(offsetof(struct vcpu_svm, vcpu.regs[VCPU_REGS_R11])),
+                 [r12]"i"(offsetof(struct vcpu_svm, vcpu.regs[VCPU_REGS_R12])),
+                 [r13]"i"(offsetof(struct vcpu_svm, vcpu.regs[VCPU_REGS_R13])),
+                 [r14]"i"(offsetof(struct vcpu_svm, vcpu.regs[VCPU_REGS_R14])),
+                 [r15]"i"(offsetof(struct vcpu_svm, vcpu.regs[VCPU_REGS_R15]))
 #endif
-               : "cc", "memory" );
-
-       vcpu->guest_mode = 0;
-
-       if (vcpu->fpu_active) {
-               fx_save(&vcpu->guest_fx_image);
-               fx_restore(&vcpu->host_fx_image);
-       }
+               : "cc", "memory"
+#ifdef CONFIG_X86_64
+               , "rbx", "rcx", "rdx", "rsi", "rdi"
+               , "r8", "r9", "r10", "r11" , "r12", "r13", "r14", "r15"
+#else
+               , "ebx", "ecx", "edx" , "esi", "edi"
+#endif
+               );
 
        if ((svm->vmcb->save.dr7 & 0xff))
                load_db_regs(svm->host_db_regs);
@@ -1645,40 +1587,11 @@ again:
 
        reload_tss(vcpu);
 
-       /*
-        * Profile KVM exit RIPs:
-        */
-       if (unlikely(prof_on == KVM_PROFILING))
-               profile_hit(KVM_PROFILING,
-                       (void *)(unsigned long)svm->vmcb->save.rip);
+       local_irq_disable();
 
        stgi();
 
-       kvm_reput_irq(svm);
-
        svm->next_rip = 0;
-
-       if (svm->vmcb->control.exit_code == SVM_EXIT_ERR) {
-               kvm_run->exit_reason = KVM_EXIT_FAIL_ENTRY;
-               kvm_run->fail_entry.hardware_entry_failure_reason
-                       = svm->vmcb->control.exit_code;
-               post_kvm_run_save(svm, kvm_run);
-               return 0;
-       }
-
-       r = handle_exit(svm, kvm_run);
-       if (r > 0) {
-               if (dm_request_for_irq_injection(svm, kvm_run)) {
-                       ++vcpu->stat.request_irq_exits;
-                       post_kvm_run_save(svm, kvm_run);
-                       kvm_run->exit_reason = KVM_EXIT_INTR;
-                       return -EINTR;
-               }
-               kvm_resched(vcpu);
-               goto again;
-       }
-       post_kvm_run_save(svm, kvm_run);
-       return r;
 }
 
 static void svm_set_cr3(struct kvm_vcpu *vcpu, unsigned long root)
@@ -1743,7 +1656,6 @@ svm_patch_hypercall(struct kvm_vcpu *vcpu, unsigned char *hypercall)
        hypercall[0] = 0x0f;
        hypercall[1] = 0x01;
        hypercall[2] = 0xd9;
-       hypercall[3] = 0xc3;
 }
 
 static void svm_check_processor_compat(void *rtn)
@@ -1751,7 +1663,7 @@ static void svm_check_processor_compat(void *rtn)
        *(int *)rtn = 0;
 }
 
-static struct kvm_arch_ops svm_arch_ops = {
+static struct kvm_x86_ops svm_x86_ops = {
        .cpu_has_kvm_support = has_svm,
        .disabled_by_bios = is_disabled,
        .hardware_setup = svm_hardware_setup,
@@ -1762,7 +1674,9 @@ static struct kvm_arch_ops svm_arch_ops = {
 
        .vcpu_create = svm_create_vcpu,
        .vcpu_free = svm_free_vcpu,
+       .vcpu_reset = svm_vcpu_reset,
 
+       .prepare_guest_switch = svm_prepare_guest_switch,
        .vcpu_load = svm_vcpu_load,
        .vcpu_put = svm_vcpu_put,
        .vcpu_decache = svm_vcpu_decache,
@@ -1773,7 +1687,7 @@ static struct kvm_arch_ops svm_arch_ops = {
        .get_segment_base = svm_get_segment_base,
        .get_segment = svm_get_segment,
        .set_segment = svm_set_segment,
-       .get_cs_db_l_bits = svm_get_cs_db_l_bits,
+       .get_cs_db_l_bits = kvm_get_cs_db_l_bits,
        .decache_cr4_guest_bits = svm_decache_cr4_guest_bits,
        .set_cr0 = svm_set_cr0,
        .set_cr3 = svm_set_cr3,
@@ -1796,21 +1710,26 @@ static struct kvm_arch_ops svm_arch_ops = {
        .inject_gp = svm_inject_gp,
 
        .run = svm_vcpu_run,
+       .handle_exit = handle_exit,
        .skip_emulated_instruction = skip_emulated_instruction,
        .patch_hypercall = svm_patch_hypercall,
        .get_irq = svm_get_irq,
        .set_irq = svm_set_irq,
+       .inject_pending_irq = svm_intr_assist,
+       .inject_pending_vectors = do_interrupt_requests,
+
+       .set_tss_addr = svm_set_tss_addr,
 };
 
 static int __init svm_init(void)
 {
-       return kvm_init_arch(&svm_arch_ops, sizeof(struct vcpu_svm),
+       return kvm_init(&svm_x86_ops, sizeof(struct vcpu_svm),
                              THIS_MODULE);
 }
 
 static void __exit svm_exit(void)
 {
-       kvm_exit_arch();
+       kvm_exit();
 }
 
 module_init(svm_init)