aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/kvm/vmx.c
diff options
context:
space:
mode:
authorNadav Har'El <nyh@il.ibm.com>2011-05-25 16:13:36 -0400
committerAvi Kivity <avi@redhat.com>2011-07-12 04:45:17 -0400
commit0b6ac343fc8e120b7d32fd2d51a8f81354086fa0 (patch)
tree7f5605a9a68c32458e6e744847813277e62fb9c5 /arch/x86/kvm/vmx.c
parentb6f1250edb4462e38d72c7f6cce35911df21d31b (diff)
KVM: nVMX: Correct handling of exception injection
Similar to the previous patch, but concerning injection of exceptions rather than external interrupts. Signed-off-by: Nadav Har'El <nyh@il.ibm.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Diffstat (limited to 'arch/x86/kvm/vmx.c')
-rw-r--r--arch/x86/kvm/vmx.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index ab218da8b956..9604af7675e8 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -1585,6 +1585,25 @@ static void vmx_clear_hlt(struct kvm_vcpu *vcpu)
1585 vmcs_write32(GUEST_ACTIVITY_STATE, GUEST_ACTIVITY_ACTIVE); 1585 vmcs_write32(GUEST_ACTIVITY_STATE, GUEST_ACTIVITY_ACTIVE);
1586} 1586}
1587 1587
1588/*
1589 * KVM wants to inject page-faults which it got to the guest. This function
1590 * checks whether in a nested guest, we need to inject them to L1 or L2.
1591 * This function assumes it is called with the exit reason in vmcs02 being
1592 * a #PF exception (this is the only case in which KVM injects a #PF when L2
1593 * is running).
1594 */
1595static int nested_pf_handled(struct kvm_vcpu *vcpu)
1596{
1597 struct vmcs12 *vmcs12 = get_vmcs12(vcpu);
1598
1599 /* TODO: also check PFEC_MATCH/MASK, not just EB.PF. */
1600 if (!(vmcs12->exception_bitmap & PF_VECTOR))
1601 return 0;
1602
1603 nested_vmx_vmexit(vcpu);
1604 return 1;
1605}
1606
1588static void vmx_queue_exception(struct kvm_vcpu *vcpu, unsigned nr, 1607static void vmx_queue_exception(struct kvm_vcpu *vcpu, unsigned nr,
1589 bool has_error_code, u32 error_code, 1608 bool has_error_code, u32 error_code,
1590 bool reinject) 1609 bool reinject)
@@ -1592,6 +1611,10 @@ static void vmx_queue_exception(struct kvm_vcpu *vcpu, unsigned nr,
1592 struct vcpu_vmx *vmx = to_vmx(vcpu); 1611 struct vcpu_vmx *vmx = to_vmx(vcpu);
1593 u32 intr_info = nr | INTR_INFO_VALID_MASK; 1612 u32 intr_info = nr | INTR_INFO_VALID_MASK;
1594 1613
1614 if (nr == PF_VECTOR && is_guest_mode(vcpu) &&
1615 nested_pf_handled(vcpu))
1616 return;
1617
1595 if (has_error_code) { 1618 if (has_error_code) {
1596 vmcs_write32(VM_ENTRY_EXCEPTION_ERROR_CODE, error_code); 1619 vmcs_write32(VM_ENTRY_EXCEPTION_ERROR_CODE, error_code);
1597 intr_info |= INTR_INFO_DELIVER_CODE_MASK; 1620 intr_info |= INTR_INFO_DELIVER_CODE_MASK;
@@ -3820,6 +3843,9 @@ static void vmx_inject_nmi(struct kvm_vcpu *vcpu)
3820{ 3843{
3821 struct vcpu_vmx *vmx = to_vmx(vcpu); 3844 struct vcpu_vmx *vmx = to_vmx(vcpu);
3822 3845
3846 if (is_guest_mode(vcpu))
3847 return;
3848
3823 if (!cpu_has_virtual_nmis()) { 3849 if (!cpu_has_virtual_nmis()) {
3824 /* 3850 /*
3825 * Tracking the NMI-blocked state in software is built upon 3851 * Tracking the NMI-blocked state in software is built upon