Skip to contentSkip to conversation

KVM: IOAPIC/LAPIC: Enable NMI support

RFC PATCH In review Yang, Sheng 1 participant 1 message May 8, 2008

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 2/4 KVM: IOAPIC/LAPIC: Enable NMI support

From 3a5e332c32a2ec585447505e2503d91cf2fb2a54 Mon Sep 17 00:00:00 2001
From: Sheng Yang <[email protected]>
Date: Tue, 1 Apr 2008 14:47:59 +0800
Subject: [PATCH 2/4] KVM: IOAPIC/LAPIC: Enable NMI support

---
 arch/x86/kvm/lapic.c       |    3 ++-
 arch/x86/kvm/x86.c         |    6 ++++++
 include/asm-x86/kvm_host.h |    4 ++++
 virt/kvm/ioapic.c          |   20 ++++++++++++++++++--
 4 files changed, 30 insertions(+), 3 deletions(-)
arch/x86/kvm/lapic.c +0 -0
index 6226fe0..df5aba9 100644
@@ -351,8 +351,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:

arch/x86/kvm/x86.c +0 -0
index 979f983..f95ebdb 100644
@@ -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);

include/asm-x86/kvm_host.h +2 -0
index 1d8cd01..2df8416 100644
@@ -285,6 +285,8 @@ struct kvm_vcpu_arch {
 	struct kvm_vcpu_time_info hv_clock;
 	unsigned int time_offset;
 	struct page *time_page;
+
+	bool nmi_pending;
 };
 
 struct kvm_mem_alias {
@@ -513,6 +515,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,

virt/kvm/ioapic.c +5 -0
index 4232fd7..99a1736 100644
@@ -146,6 +146,11 @@ static void ioapic_inj_irq(struct kvm_ioapic *ioapic,
 	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 void 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);
--
1.5.5

From 3a5e332c32a2ec585447505e2503d91cf2fb2a54 Mon Sep 17 00:00:00 2001
From: Sheng Yang <[email protected]>
Date: Tue, 1 Apr 2008 14:47:59 +0800
Subject: [PATCH 2/4] KVM: IOAPIC/LAPIC: Enable NMI support

---
 arch/x86/kvm/lapic.c       |    3 ++-
 arch/x86/kvm/x86.c         |    6 ++++++
 include/asm-x86/kvm_host.h |    4 ++++
 virt/kvm/ioapic.c          |   20 ++++++++++++++++++--
 4 files changed, 30 insertions(+), 3 deletions(-)
arch/x86/kvm/lapic.c +2 -1
index 6226fe0..df5aba9 100644
@@ -351,8 +351,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:
arch/x86/kvm/x86.c +6 -0
index 979f983..f95ebdb 100644
@@ -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);
include/asm-x86/kvm_host.h +4 -0
index 1d8cd01..2df8416 100644
@@ -285,6 +285,8 @@ struct kvm_vcpu_arch {
 	struct kvm_vcpu_time_info hv_clock;
 	unsigned int time_offset;
 	struct page *time_page;
+
+	bool nmi_pending;
 };
 
 struct kvm_mem_alias {
@@ -513,6 +515,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,
virt/kvm/ioapic.c +18 -2
index 4232fd7..99a1736 100644
@@ -146,6 +146,11 @@ static void ioapic_inj_irq(struct kvm_ioapic *ioapic,
 	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 void 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);
Signature · 1 line
1.5.5

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference Don't miss this year's exciting event. There's still time to save $100. Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone

_______________________________________________
kvm-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/kvm-devel