aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/kvm
diff options
context:
space:
mode:
authorJoerg Roedel <joerg.roedel@amd.com>2009-08-07 05:49:29 -0400
committerAvi Kivity <avi@redhat.com>2009-09-10 01:33:23 -0400
commit33740e4009b7d287538f68f614eb3542df3597e4 (patch)
tree2196949617d94613070f7ae812f41278a392b83a /arch/x86/kvm
parent2af9194d1b683f91ae956afff9afb0b52a241371 (diff)
KVM: SVM: optimize nested #vmexit
It is more efficient to copy only the relevant parts of the vmcb back to the nested vmcb when we emulate an vmexit. Signed-off-by: Joerg Roedel <joerg.roedel@amd.com> Acked-by: Alexander Graf <agraf@suse.de> Signed-off-by: Avi Kivity <avi@redhat.com>
Diffstat (limited to 'arch/x86/kvm')
-rw-r--r--arch/x86/kvm/svm.c68
1 files changed, 33 insertions, 35 deletions
diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index 9f7277273a23..2f5f2236f2a2 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -1572,53 +1572,52 @@ static int nested_svm_vmexit_real(struct vcpu_svm *svm, void *arg1,
1572{ 1572{
1573 struct vmcb *nested_vmcb = (struct vmcb *)arg1; 1573 struct vmcb *nested_vmcb = (struct vmcb *)arg1;
1574 struct vmcb *hsave = svm->hsave; 1574 struct vmcb *hsave = svm->hsave;
1575 u64 nested_save[] = { nested_vmcb->save.cr0, 1575 struct vmcb *vmcb = svm->vmcb;
1576 nested_vmcb->save.cr3,
1577 nested_vmcb->save.cr4,
1578 nested_vmcb->save.efer,
1579 nested_vmcb->control.intercept_cr_read,
1580 nested_vmcb->control.intercept_cr_write,
1581 nested_vmcb->control.intercept_dr_read,
1582 nested_vmcb->control.intercept_dr_write,
1583 nested_vmcb->control.intercept_exceptions,
1584 nested_vmcb->control.intercept,
1585 nested_vmcb->control.msrpm_base_pa,
1586 nested_vmcb->control.iopm_base_pa,
1587 nested_vmcb->control.tsc_offset };
1588 1576
1589 /* Give the current vmcb to the guest */ 1577 /* Give the current vmcb to the guest */
1590 memcpy(nested_vmcb, svm->vmcb, sizeof(struct vmcb)); 1578 disable_gif(svm);
1591 nested_vmcb->save.cr0 = nested_save[0]; 1579
1592 if (!npt_enabled) 1580 nested_vmcb->save.es = vmcb->save.es;
1593 nested_vmcb->save.cr3 = nested_save[1]; 1581 nested_vmcb->save.cs = vmcb->save.cs;
1594 nested_vmcb->save.cr4 = nested_save[2]; 1582 nested_vmcb->save.ss = vmcb->save.ss;
1595 nested_vmcb->save.efer = nested_save[3]; 1583 nested_vmcb->save.ds = vmcb->save.ds;
1596 nested_vmcb->control.intercept_cr_read = nested_save[4]; 1584 nested_vmcb->save.gdtr = vmcb->save.gdtr;
1597 nested_vmcb->control.intercept_cr_write = nested_save[5]; 1585 nested_vmcb->save.idtr = vmcb->save.idtr;
1598 nested_vmcb->control.intercept_dr_read = nested_save[6]; 1586 if (npt_enabled)
1599 nested_vmcb->control.intercept_dr_write = nested_save[7]; 1587 nested_vmcb->save.cr3 = vmcb->save.cr3;
1600 nested_vmcb->control.intercept_exceptions = nested_save[8]; 1588 nested_vmcb->save.cr2 = vmcb->save.cr2;
1601 nested_vmcb->control.intercept = nested_save[9]; 1589 nested_vmcb->save.rflags = vmcb->save.rflags;
1602 nested_vmcb->control.msrpm_base_pa = nested_save[10]; 1590 nested_vmcb->save.rip = vmcb->save.rip;
1603 nested_vmcb->control.iopm_base_pa = nested_save[11]; 1591 nested_vmcb->save.rsp = vmcb->save.rsp;
1604 nested_vmcb->control.tsc_offset = nested_save[12]; 1592 nested_vmcb->save.rax = vmcb->save.rax;
1593 nested_vmcb->save.dr7 = vmcb->save.dr7;
1594 nested_vmcb->save.dr6 = vmcb->save.dr6;
1595 nested_vmcb->save.cpl = vmcb->save.cpl;
1596
1597 nested_vmcb->control.int_ctl = vmcb->control.int_ctl;
1598 nested_vmcb->control.int_vector = vmcb->control.int_vector;
1599 nested_vmcb->control.int_state = vmcb->control.int_state;
1600 nested_vmcb->control.exit_code = vmcb->control.exit_code;
1601 nested_vmcb->control.exit_code_hi = vmcb->control.exit_code_hi;
1602 nested_vmcb->control.exit_info_1 = vmcb->control.exit_info_1;
1603 nested_vmcb->control.exit_info_2 = vmcb->control.exit_info_2;
1604 nested_vmcb->control.exit_int_info = vmcb->control.exit_int_info;
1605 nested_vmcb->control.exit_int_info_err = vmcb->control.exit_int_info_err;
1606 nested_vmcb->control.tlb_ctl = 0;
1607 nested_vmcb->control.event_inj = 0;
1608 nested_vmcb->control.event_inj_err = 0;
1605 1609
1606 /* We always set V_INTR_MASKING and remember the old value in hflags */ 1610 /* We always set V_INTR_MASKING and remember the old value in hflags */
1607 if (!(svm->vcpu.arch.hflags & HF_VINTR_MASK)) 1611 if (!(svm->vcpu.arch.hflags & HF_VINTR_MASK))
1608 nested_vmcb->control.int_ctl &= ~V_INTR_MASKING_MASK; 1612 nested_vmcb->control.int_ctl &= ~V_INTR_MASKING_MASK;
1609 1613
1610 if ((nested_vmcb->control.int_ctl & V_IRQ_MASK) &&
1611 (nested_vmcb->control.int_vector)) {
1612 nsvm_printk("WARNING: IRQ 0x%x still enabled on #VMEXIT\n",
1613 nested_vmcb->control.int_vector);
1614 }
1615
1616 /* Restore the original control entries */ 1614 /* Restore the original control entries */
1617 svm->vmcb->control = hsave->control; 1615 svm->vmcb->control = hsave->control;
1618 1616
1619 /* Kill any pending exceptions */ 1617 /* Kill any pending exceptions */
1620 if (svm->vcpu.arch.exception.pending == true) 1618 if (svm->vcpu.arch.exception.pending == true)
1621 nsvm_printk("WARNING: Pending Exception\n"); 1619 nsvm_printk("WARNING: Pending Exception\n");
1620
1622 kvm_clear_exception_queue(&svm->vcpu); 1621 kvm_clear_exception_queue(&svm->vcpu);
1623 kvm_clear_interrupt_queue(&svm->vcpu); 1622 kvm_clear_interrupt_queue(&svm->vcpu);
1624 1623
@@ -1646,7 +1645,6 @@ static int nested_svm_vmexit_real(struct vcpu_svm *svm, void *arg1,
1646 svm->vmcb->save.cpl = 0; 1645 svm->vmcb->save.cpl = 0;
1647 svm->vmcb->control.exit_int_info = 0; 1646 svm->vmcb->control.exit_int_info = 0;
1648 1647
1649 disable_gif(svm);
1650 /* Exit nested SVM mode */ 1648 /* Exit nested SVM mode */
1651 svm->nested_vmcb = 0; 1649 svm->nested_vmcb = 0;
1652 1650