Skip to contentSkip to conversation

QEMU/KVM: PIT no interrupt reinjection support

PATCH In review Marcelo Tosatti 3 participants 6 messages Dec 29, 2008 – Dec 30, 2008 KVM

lore
Share & tools
lore
#0 lore raw

cover QEMU/KVM: PIT no interrupt reinjection support

Userspace support for KVM_PIT_NO_REINJECT.

#1 lore raw

PATCH 1/2 libkvm: pit not reinject support

libkvm/libkvm-x86.c +14 -0
Index: kvm-userspace.pit/libkvm/libkvm-x86.c
===================================================================
@@ -75,6 +75,20 @@ int kvm_create_pit(kvm_context_t kvm)
 	return 0;
 }
 
+int kvm_pit_no_reinjection(kvm_context_t kvm)
+{
+#ifdef KVM_CAP_PIT_NO_REINJECT
+    int r;
+
+    r = ioctl(kvm->fd, KVM_CHECK_EXTENSION, KVM_CAP_PIT_NO_REINJECT);
+    if (r > 0) {
+        r = ioctl(kvm->vm_fd, KVM_PIT_NO_REINJECT);
+        return r;
+    }
+#endif
+    return -1;
+}
+
 int kvm_arch_create(kvm_context_t kvm, unsigned long phys_mem_bytes,
  			void **vm_mem)
 {
libkvm/libkvm.h +2 -0
Index: kvm-userspace.pit/libkvm/libkvm.h
===================================================================
@@ -648,6 +648,8 @@ int kvm_set_pit(kvm_context_t kvm, struc
 
 #endif
 
+int kvm_pit_no_reinjection(kvm_context_t kvm);
+
 #ifdef KVM_CAP_VAPIC
 
 /*!
#2 lore raw

Re: [patch 1/2] libkvm: pit not reinject support

Quoted 14 lines · Marcelo Tosatti

Index: kvm-userspace.pit/libkvm/libkvm-x86.c
===================================================================

libkvm/libkvm-x86.c +4 -0
@@ -75,6 +75,20 @@ int kvm_create_pit(kvm_context_t kvm)
 	return 0;
 }
 
+int kvm_pit_no_reinjection(kvm_context_t kvm)
+{
+#ifdef KVM_CAP_PIT_NO_REINJECT
+    int r;

libkvm/libkvm-x86.c int kvm_create_pit(kvm_context_t kvm) · line 91

Quoted 10 lines
libkvm/libkvm-x86.c +9 -0
+
+    r = ioctl(kvm->fd, KVM_CHECK_EXTENSION, KVM_CAP_PIT_NO_REINJECT);
+    if (r > 0) {
+        r = ioctl(kvm->vm_fd, KVM_PIT_NO_REINJECT);
+        return r;
+    }
+#endif
+    return -1;
+}
 

Most (not all unfortunately) return -errno on error.

libkvm/libkvm-x86.c int kvm_create_pit(kvm_context_t kvm) · line 94

Quoted 4 lines
libkvm/libkvm-x86.c +2 -0
+int kvm_pit_no_reinjection(kvm_context_t kvm);
+
 

Don't use nonpositive logic.

Signature · 1 line
error compiling committee.c: too many arguments to function
#3 lore raw

PATCH 2/2 QEMU/KVM: provide an option to disable in-kernel PIT int reinjection

In reply to Marcelo Tosatti
qemu/qemu-kvm.c +7 -0
Index: kvm-userspace.pit/qemu/qemu-kvm.c
===================================================================
@@ -11,6 +11,7 @@
 int kvm_allowed = 1;
 int kvm_irqchip = 1;
 int kvm_pit = 1;
+int kvm_pit_no_reinject = 0;
 int kvm_nested = 0;
 
 #include <assert.h>
@@ -795,6 +796,12 @@ int kvm_qemu_create_context(void)
     r = kvm_arch_qemu_create_context();
     if(r <0)
 	kvm_qemu_destroy();
+    if (kvm_pit_no_reinject) {
+        if (kvm_pit_no_reinjection(kvm_context)) {
+            fprintf(stderr, "failure to disable in-kernel PIT reinjection\n");
+            return -1;
+        }
+    }
 #ifdef TARGET_I386
     destroy_region_works = kvm_destroy_memory_region_works(kvm_context);
 #endif
qemu/vl.c +8 -0
Index: kvm-userspace.pit/qemu/vl.c
===================================================================
@@ -4071,6 +4071,7 @@ static void help(int exitcode)
 #endif
 	   "-no-kvm-irqchip disable KVM kernel mode PIC/IOAPIC/LAPIC\n"
 	   "-no-kvm-pit	    disable KVM kernel mode PIT\n"
+	   "-kvm-pit-no-reinject disable KVM kernel mode PIT interrupt reinjection\n"
 	   "-enable-nesting enable support for running a VM inside the VM (AMD only)\n"
 #if defined(TARGET_I386) || defined(TARGET_X86_64) || defined(TARGET_IA64) || defined(__linux__)
            "-pcidevice host=bus:dev.func[,dma=none][,name=string]\n"
@@ -4202,6 +4203,7 @@ enum {
     QEMU_OPTION_no_kvm,
     QEMU_OPTION_no_kvm_irqchip,
     QEMU_OPTION_no_kvm_pit,
+    QEMU_OPTION_kvm_pit_no_reinject,
 #if defined(TARGET_I386) || defined(TARGET_X86_64) || defined(TARGET_IA64) || defined(__linux__)
     QEMU_OPTION_pcidevice,
 #endif
@@ -4298,6 +4300,7 @@ static const QEMUOption qemu_options[] =
 #endif
     { "no-kvm-irqchip", 0, QEMU_OPTION_no_kvm_irqchip },
     { "no-kvm-pit", 0, QEMU_OPTION_no_kvm_pit },
+    { "kvm-pit-no-reinject", 0, QEMU_OPTION_kvm_pit_no_reinject },
     { "enable-nesting", 0, QEMU_OPTION_enable_nesting },
 #if defined(TARGET_I386) || defined(TARGET_X86_64) || defined(TARGET_IA64) || defined(__linux__)
     { "pcidevice", HAS_ARG, QEMU_OPTION_pcidevice },
@@ -5267,6 +5270,11 @@ int main(int argc, char **argv, char **e
 		kvm_pit = 0;
 		break;
 	    }
+            case QEMU_OPTION_kvm_pit_no_reinject: {
+                extern int kvm_pit_no_reinject;
+                kvm_pit_no_reinject = 1;
+                break;
+            }
 	    case QEMU_OPTION_enable_nesting: {
 		kvm_nested = 1;
 		break;
#4 lore raw

Re: [patch 2/2] QEMU/KVM: provide an option to disable in-kernel PIT int reinjection

Quoted 7 lines · On Tuesday 30 December 2008 01:42:35 Marcelo Tosatti wrote:

--
#if defined(TARGET_I386) || defined(TARGET_X86_64) || defined(TARGET_IA64)
|| defined(__linux__) { "pcidevice", HAS_ARG, QEMU_OPTION_pcidevice },

qemu/vl.c +0 -0
@@ -5267,6 +5270,11 @@ int main(int argc, char **argv, char **e
 		kvm_pit = 0;

qemu/vl.c int main(int argc, char **argv, char **e · line 5280

Quoted 10 lines
qemu/vl.c +5 -0
 		break;
 	    }
+            case QEMU_OPTION_kvm_pit_no_reinject: {
+                extern int kvm_pit_no_reinject;
+                kvm_pit_no_reinject = 1;
+                break;
+            }
 	    case QEMU_OPTION_enable_nesting: {
 		kvm_nested = 1;
 		break;

Do we need check the conflict of --kvm-pit-no-reinject and --no-kvm-pit/--no- kvm-irqchip? Check it ahead of kvm_qemu_create_context() seems a little better...

Signature · 2 lines
regards
Yang, Sheng
#5 lore raw

Re: [patch 2/2] QEMU/KVM: provide an option to disable in-kernel PIT int reinjection

In reply to Marcelo Tosatti
Quoted 4 lines · Marcelo Tosatti
     { "no-kvm-irqchip", 0, QEMU_OPTION_no_kvm_irqchip },
     { "no-kvm-pit", 0, QEMU_OPTION_no_kvm_pit },

+ { "kvm-pit-no-reinject", 0, QEMU_OPTION_kvm_pit_no_reinject },

no-kvm-pit-reinjection?
no-kvm-pit-compensation?

Hard to find a user friendly name for this.

Signature · 1 line
error compiling committee.c: too many arguments to function