Patchwork [01/35] kvm: Enable user space NMI injection for kvm guest

login
register
mail settings
Submitter Marcelo Tosatti
Date Jan. 6, 2011, 5:56 p.m.
Message ID <63d3a773666472fac5ba1923599fee64e2b8b4fc.1294336601.git.mtosatti@redhat.com>
Download mbox | patch
Permalink /patch/77754/
State New
Headers show

Comments

Marcelo Tosatti - Jan. 6, 2011, 5:56 p.m.
From: Lai Jiangshan <laijs@cn.fujitsu.com>

Make use of the new KVM_NMI IOCTL to send NMIs into the KVM guest if the
user space raised them. (example: qemu monitor's "nmi" command)

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Acked-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
---
 configure         |    3 +++
 target-i386/kvm.c |    7 +++++++
 2 files changed, 10 insertions(+), 0 deletions(-)

Patch

diff --git a/configure b/configure
index 47e4cf0..ec37a91 100755
--- a/configure
+++ b/configure
@@ -1674,6 +1674,9 @@  if test "$kvm" != "no" ; then
 #if !defined(KVM_CAP_DESTROY_MEMORY_REGION_WORKS)
 #error Missing KVM capability KVM_CAP_DESTROY_MEMORY_REGION_WORKS
 #endif
+#if !defined(KVM_CAP_USER_NMI)
+#error Missing KVM capability KVM_CAP_USER_NMI
+#endif
 int main(void) { return 0; }
 EOF
   if test "$kerneldir" != "" ; then
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 7dfc357..755f8c9 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -1417,6 +1417,13 @@  int kvm_arch_get_registers(CPUState *env)
 
 int kvm_arch_pre_run(CPUState *env, struct kvm_run *run)
 {
+    /* Inject NMI */
+    if (env->interrupt_request & CPU_INTERRUPT_NMI) {
+        env->interrupt_request &= ~CPU_INTERRUPT_NMI;
+        DPRINTF("injected NMI\n");
+        kvm_vcpu_ioctl(env, KVM_NMI);
+    }
+
     /* Try to inject an interrupt if the guest can accept it */
     if (run->ready_for_interrupt_injection &&
         (env->interrupt_request & CPU_INTERRUPT_HARD) &&