Skip to contentSkip to conversation

qemu,kvm: Enable NMI support for user space irqchip

PATCH Superseded Lai Jiangshan 3 participants 8 messages Dec 9, 2010 – Dec 20, 2010 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/6 qemu,kvm: Enable NMI support for user space irqchip

Make use of the new KVM_NMI IOCTL to send NMIs into the KVM guest if the user space APIC emulation or some other source raised them.

---

target-i386/kvm.c +8 -0
index 7dfc357..c4ebe28 100644
@@ -1417,6 +1417,14 @@ int kvm_arch_get_registers(CPUState *env)
 
 int kvm_arch_pre_run(CPUState *env, struct kvm_run *run)
 {
+#ifdef KVM_CAP_USER_NMI
+    if (env->interrupt_request & CPU_INTERRUPT_NMI) {
+        env->interrupt_request &= ~CPU_INTERRUPT_NMI;
+        DPRINTF("injected NMI\n");
+        kvm_vcpu_ioctl(env, KVM_NMI);
+    }
+#endif
+
     /* Try to inject an interrupt if the guest can accept it */
     if (run->ready_for_interrupt_injection &&
         (env->interrupt_request & CPU_INTERRUPT_HARD) &&
#1 lore raw
Quoted 3 lines · Lai Jiangshan

Make use of the new KVM_NMI IOCTL to send NMIs into the KVM guest if the user space APIC emulation or some other source raised them.

In that light, the subject is not absolutely correct.

Quoted 12 lines

---

target-i386/kvm.c +1 -0
index 7dfc357..c4ebe28 100644
@@ -1417,6 +1417,14 @@ int kvm_arch_get_registers(CPUState *env)
 
 int kvm_arch_pre_run(CPUState *env, struct kvm_run *run)
 {
+#ifdef KVM_CAP_USER_NMI

target-i386/kvm.c int kvm_arch_get_registers(CPUState *env) · line 1430

Quoted 10 lines
target-i386/kvm.c +7 -0
+    if (env->interrupt_request & CPU_INTERRUPT_NMI) {
+        env->interrupt_request &= ~CPU_INTERRUPT_NMI;
+        DPRINTF("injected NMI\n");
+        kvm_vcpu_ioctl(env, KVM_NMI);
+    }
+#endif
+
     /* Try to inject an interrupt if the guest can accept it */
     if (run->ready_for_interrupt_injection &&
         (env->interrupt_request & CPU_INTERRUPT_HARD) &&

Actually, we already depend on KVM_CAP_DESTROY_MEMORY_REGION_WORKS which was introduced with 2.6.29 as well. I would suggest to simply extend the static configure check and avoid new #ifdefs in the code.

Thanks for pushing this! Was obviously so trivial that it was forgotten...

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux
#2 lore raw
Quoted 7 lines · Jan Kiszka
Quoted 3 lines · Lai Jiangshan

Make use of the new KVM_NMI IOCTL to send NMIs into the KVM guest if the user space APIC emulation or some other source raised them.

In that light, the subject is not absolutely correct.

[...]

Quoted 7 lines

Actually, we already depend on KVM_CAP_DESTROY_MEMORY_REGION_WORKS which was introduced with 2.6.29 as well. I would suggest to simply extend the static configure check and avoid new #ifdefs in the code.

Thanks for pushing this! Was obviously so trivial that it was forgotten...

Thanks. We want to inject nmi to kvm guest via qemu monitor, that's this path's purpose.

But I can't get you means, what I should do to fix this patch? Just remove the #ifdefs OR use kvm_check_extension(KVM_CAP_USER_NMI) ?

+ static int can_user_nmi = -1;
+
+ if (can_user_nmi == -1)
+ can_user_nmi = kvm_check_extension(kvm_state, KVM_CAP_USER_NMI);
+
+ if (can_user_nmi > 0 && env->interrupt_request & CPU_INTERRUPT_NMI) {

+        env->interrupt_request &= ~CPU_INTERRUPT_NMI;
+        DPRINTF("injected NMI\n");
+        kvm_vcpu_ioctl(env, KVM_NMI);

+ }

Thanks,
Lai

#3 lore raw

PATCH v2 1/1 qemu,kvm: Enable user space NMI injection for kvm guest

In reply to Jan Kiszka

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)

---

configure +3 -0
index 2917874..f6f9362 100755
@@ -1646,6 +1646,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
target-i386/kvm.c +7 -0
index 7dfc357..755f8c9 100644
@@ -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) &&
Acked-by on v2 1/1
#4 lore raw

Re: [PATCH V2] qemu,kvm: Enable user space NMI injection for kvm guest

Quoted 11 lines · Lai Jiangshan

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)

---

configure +0 -0
index 2917874..f6f9362 100755

configure if test "$kvm" != "no" ; then · line 1654

Quoted 9 lines
configure +3 -0
@@ -1646,6 +1646,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

That's what I meant.

We also have a runtime check for KVM_CAP_DESTROY_MEMORY_REGION_WORKS on kvm init, but IMHO adding the same for KVM_CAP_USER_NMI would be overkill. So...

Quoted 8 lines
target-i386/kvm.c +0 -0
index 7dfc357..755f8c9 100644
@@ -1417,6 +1417,13 @@ int kvm_arch_get_registers(CPUState *env)
 
 int kvm_arch_pre_run(CPUState *env, struct kvm_run *run)
 {

target-i386/kvm.c int kvm_arch_get_registers(CPUState *env) · line 1429

Quoted 10 lines
target-i386/kvm.c +7 -0
+    /* 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) &&

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux
#5 lore raw

Re: [PATCH V2] qemu,kvm: Enable user space NMI injection for kvm guest

Quoted 34 lines · Jan Kiszka
Quoted 11 lines · Lai Jiangshan

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)

---

configure +0 -0
index 2917874..f6f9362 100755

configure if test "$kvm" != "no" ; then · line 1654

Quoted 9 lines
configure +3 -0
@@ -1646,6 +1646,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

That's what I meant.

We also have a runtime check for KVM_CAP_DESTROY_MEMORY_REGION_WORKS on kvm init, but IMHO adding the same for KVM_CAP_USER_NMI would be overkill. So...

Quoted 6 lines
target-i386/kvm.c +0 -0
index 7dfc357..755f8c9 100644
@@ -1417,6 +1417,13 @@ int kvm_arch_get_registers(CPUState *env)
 
Quoted 15 lines

target-i386/kvm.c int kvm_arch_get_registers(CPUState *env) · line 1429

Quoted 12 lines
target-i386/kvm.c +7 -0
 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) &&

Hi, Avi

Could you apply this patch or give me any comments/suggest?

Thanks,
Lai

#6 lore raw

Re: [PATCH V2] qemu,kvm: Enable user space NMI injection for kvm guest

In reply to Jan Kiszka
Quoted 49 lines · Jan Kiszka
Quoted 11 lines · Lai Jiangshan

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)

---

configure +0 -0
index 2917874..f6f9362 100755

configure if test "$kvm" != "no" ; then · line 1654

Quoted 9 lines
configure +3 -0
@@ -1646,6 +1646,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

That's what I meant.

We also have a runtime check for KVM_CAP_DESTROY_MEMORY_REGION_WORKS on kvm init, but IMHO adding the same for KVM_CAP_USER_NMI would be overkill. So...

Quoted 8 lines
target-i386/kvm.c +0 -0
index 7dfc357..755f8c9 100644
@@ -1417,6 +1417,13 @@ int kvm_arch_get_registers(CPUState *env)
 
 int kvm_arch_pre_run(CPUState *env, struct kvm_run *run)
 {

target-i386/kvm.c int kvm_arch_get_registers(CPUState *env) · line 1429

Quoted 10 lines
target-i386/kvm.c +7 -0
+    /* 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) &&
Quoted 2 lines

Jan

Hi, Avi,

Could you apply this patch?

Thanks,
Lai