KVM: IOAPIC/LAPIC: Enable NMI support
authorSheng Yang <sheng.yang@intel.com>
Thu, 15 May 2008 01:52:48 +0000 (09:52 +0800)
committerAvi Kivity <avi@qumranet.com>
Sun, 20 Jul 2008 09:42:25 +0000 (12:42 +0300)
[avi: fix ia64 build breakage]

Signed-off-by: Sheng Yang <sheng.yang@intel.com>
Signed-off-by: Avi Kivity <avi@qumranet.com>
arch/x86/kvm/lapic.c
arch/x86/kvm/x86.c
include/asm-ia64/kvm_host.h
include/asm-x86/kvm_host.h
virt/kvm/ioapic.c

index f9201fbc61d1fcbedfedd33608e9da5aed861141..e48d19394031ebfe48657ca1e84cf9a6af7d008c 100644 (file)
@@ -356,8 +356,9 @@ static int __apic_accept_irq(struct kvm_lapic *apic, int delivery_mode,
        case APIC_DM_SMI:
                printk(KERN_DEBUG "Ignoring guest SMI\n");
                break;
+
        case APIC_DM_NMI:
-               printk(KERN_DEBUG "Ignoring guest NMI\n");
+               kvm_inject_nmi(vcpu);
                break;
 
        case APIC_DM_INIT:
index 5f00c60f0aff4edc612d7f875e28766fdc921024..19974dde65676fa0cfd970b73d6ee6b06180b71e 100644 (file)
@@ -173,6 +173,12 @@ void kvm_inject_page_fault(struct kvm_vcpu *vcpu, unsigned long addr,
        kvm_queue_exception_e(vcpu, PF_VECTOR, error_code);
 }
 
+void kvm_inject_nmi(struct kvm_vcpu *vcpu)
+{
+       vcpu->arch.nmi_pending = 1;
+}
+EXPORT_SYMBOL_GPL(kvm_inject_nmi);
+
 void kvm_queue_exception_e(struct kvm_vcpu *vcpu, unsigned nr, u32 error_code)
 {
        WARN_ON(vcpu->arch.exception.pending);
index c082c208c1f339085208686129da12a7bdf7c6a6..5c958b0c46b18994cf99d6f0f4822abb669e7e3e 100644 (file)
@@ -521,4 +521,6 @@ int kvm_emulate_halt(struct kvm_vcpu *vcpu);
 int kvm_pal_emul(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
 void kvm_sal_emul(struct kvm_vcpu *vcpu);
 
+static inline void kvm_inject_nmi(struct kvm_vcpu *vcpu) {}
+
 #endif
index 4bcdc7de07b56287add2ffe0442d78e4ee424289..b66621935eb7b9d8dce7ad0bff943cd8e5e5e280 100644 (file)
@@ -288,6 +288,8 @@ struct kvm_vcpu_arch {
        unsigned int hv_clock_tsc_khz;
        unsigned int time_offset;
        struct page *time_page;
+
+       bool nmi_pending;
 };
 
 struct kvm_mem_alias {
@@ -515,6 +517,8 @@ void kvm_queue_exception_e(struct kvm_vcpu *vcpu, unsigned nr, u32 error_code);
 void kvm_inject_page_fault(struct kvm_vcpu *vcpu, unsigned long cr2,
                           u32 error_code);
 
+void kvm_inject_nmi(struct kvm_vcpu *vcpu);
+
 void fx_init(struct kvm_vcpu *vcpu);
 
 int emulator_read_std(unsigned long addr,
index 44589088941fa591c9ac2b149a6bab4af20e4994..d0c668c6959e2fc055b1869a88ce44bee2878c9a 100644 (file)
@@ -146,6 +146,11 @@ static int ioapic_inj_irq(struct kvm_ioapic *ioapic,
        return kvm_apic_set_irq(vcpu, vector, trig_mode);
 }
 
+static void ioapic_inj_nmi(struct kvm_vcpu *vcpu)
+{
+       kvm_inject_nmi(vcpu);
+}
+
 static u32 ioapic_get_delivery_bitmask(struct kvm_ioapic *ioapic, u8 dest,
                                       u8 dest_mode)
 {
@@ -239,8 +244,19 @@ static int ioapic_deliver(struct kvm_ioapic *ioapic, int irq)
                        }
                }
                break;
-
-               /* TODO: NMI */
+       case IOAPIC_NMI:
+               for (vcpu_id = 0; deliver_bitmask != 0; vcpu_id++) {
+                       if (!(deliver_bitmask & (1 << vcpu_id)))
+                               continue;
+                       deliver_bitmask &= ~(1 << vcpu_id);
+                       vcpu = ioapic->kvm->vcpus[vcpu_id];
+                       if (vcpu)
+                               ioapic_inj_nmi(vcpu);
+                       else
+                               ioapic_debug("NMI to vcpu %d failed\n",
+                                               vcpu->vcpu_id);
+               }
+               break;
        default:
                printk(KERN_WARNING "Unsupported delivery mode %d\n",
                       delivery_mode);