Skip to contentSkip to conversation

kvm: x86: Add support for VCPU event states

PATCH In review Jan Kiszka 3 participants 4 messages Nov 24, 2009 – Dec 8, 2009

lore
Share & tools
lore

Jan Kiszka

author
#0 lore raw

PATCH 1/1 kvm: x86: Add support for VCPU event states

This patch extends the qemu-kvm state sync logic with support for KVM_GET/SET_VCPU_EVENTS, giving access to yet missing exception, interrupt and NMI states.

---
 kvm-all.c             |   11 +++++++
 kvm.h                 |    1 +
 target-i386/cpu.h     |    5 +++
 target-i386/kvm.c     |   77 +++++++++++++++++++++++++++++++++++++++++++++++++
 target-i386/machine.c |    6 ++++
 5 files changed, 100 insertions(+), 0 deletions(-)
kvm-all.c +11 -0
index b605caa..c05e555 100644
@@ -61,6 +61,7 @@ struct KVMState
     int coalesced_mmio;
     int broken_set_mem_region;
     int migration_log;
+    int vcpu_events;
 #ifdef KVM_CAP_SET_GUEST_DEBUG
     struct kvm_sw_breakpoint_head kvm_sw_breakpoints;
 #endif
@@ -479,6 +480,11 @@ int kvm_init(int smp_cpus)
     }
 #endif
 
+    s->vcpu_events = 0;
+#ifdef KVM_CAP_VCPU_EVENTS
+    s->vcpu_events = kvm_check_extension(s, KVM_CAP_VCPU_EVENTS);
+#endif
+
     ret = kvm_arch_init(s, smp_cpus);
     if (ret < 0)
         goto err;
@@ -868,6 +874,11 @@ int kvm_has_sync_mmu(void)
 #endif
 }
 
+int kvm_has_vcpu_events(void)
+{
+    return kvm_state->vcpu_events;
+}
+
 void kvm_setup_guest_memory(void *start, size_t size)
 {
     if (!kvm_has_sync_mmu()) {
kvm.h +1 -0
index e4cbedc..1c93ac5 100644
@@ -47,6 +47,7 @@ int kvm_log_stop(target_phys_addr_t phys_addr, ram_addr_t size);
 int kvm_set_migration_log(int enable);
 
 int kvm_has_sync_mmu(void);
+int kvm_has_vcpu_events(void);
 
 void kvm_setup_guest_memory(void *start, size_t size);
 
target-i386/cpu.h +5 -0
index eb9532a..9c3e905 100644
@@ -693,6 +693,11 @@ typedef struct CPUX86State {
     /* For KVM */
     uint32_t mp_state;
     int32_t interrupt_injected;
+    uint8_t soft_interrupt;
+    uint8_t nmi_injected;
+    uint8_t nmi_pending;
+    uint8_t has_error_code;
+    uint32_t sipi_vector;
 
     /* in order to simplify APIC support, we leave this pointer to the
        user */
target-i386/kvm.c +77 -0

101 lines not on this page · raw message

target-i386/machine.c +6 -0
index c09b049..cdc8898 100644
@@ -448,6 +448,11 @@ static const VMStateDescription vmstate_cpu = {
         VMSTATE_INT32_V(interrupt_injected, CPUState, 9),
         VMSTATE_UINT32_V(mp_state, CPUState, 9),
         VMSTATE_UINT64_V(tsc, CPUState, 9),
+        VMSTATE_UINT8_V(soft_interrupt, CPUState, 11),
+        VMSTATE_UINT8_V(nmi_injected, CPUState, 11),
+        VMSTATE_UINT8_V(nmi_pending, CPUState, 11),
+        VMSTATE_UINT8_V(has_error_code, CPUState, 11),
+        VMSTATE_UINT32_V(sipi_vector, CPUState, 11),
         /* MCE */
         VMSTATE_UINT64_V(mcg_cap, CPUState, 10),
         VMSTATE_UINT64_V(mcg_status, CPUState, 10),
@@ -456,6 +461,7 @@ static const VMStateDescription vmstate_cpu = {
         /* rdtscp */
         VMSTATE_UINT64_V(tsc_aux, CPUState, 11),
         VMSTATE_END_OF_LIST()
+        /* The above list is not sorted /wrt version numbers, watch out! */
     }
 };
 
#1 lore raw
Quoted 4 lines · Jan Kiszka

This patch extends the qemu-kvm state sync logic with support for KVM_GET/SET_VCPU_EVENTS, giving access to yet missing exception, interrupt and NMI states.

Looks good.

Signature · 1 line
error compiling committee.c: too many arguments to function
#2 lore raw
In reply to Jan Kiszka
Quoted 4 lines · Jan Kiszka

This patch extends the qemu-kvm state sync logic with support for KVM_GET/SET_VCPU_EVENTS, giving access to yet missing exception, interrupt and NMI states.

Quoted 8 lines
---
 kvm-all.c             |   11 +++++++
 kvm.h                 |    1 +
 target-i386/cpu.h     |    5 +++
 target-i386/kvm.c     |   77 +++++++++++++++++++++++++++++++++++++++++++++++++
 target-i386/machine.c |    6 ++++
 5 files changed, 100 insertions(+), 0 deletions(-)

Jan,

Where is exception_index in the migration data? I can't see it anywhere.

author
#3 lore raw
Quoted 14 lines · Marcelo Tosatti
Quoted 4 lines · Jan Kiszka

This patch extends the qemu-kvm state sync logic with support for KVM_GET/SET_VCPU_EVENTS, giving access to yet missing exception, interrupt and NMI states.

Quoted 8 lines
---
 kvm-all.c             |   11 +++++++
 kvm.h                 |    1 +
 target-i386/cpu.h     |    5 +++
 target-i386/kvm.c     |   77 +++++++++++++++++++++++++++++++++++++++++++++++++
 target-i386/machine.c |    6 ++++
 5 files changed, 100 insertions(+), 0 deletions(-)
Quoted 4 lines

Jan,

Where is exception_index in the migration data? I can't see it anywhere.

Good point, I missed that it's lacking. Will file an upstream patch for 0.12.

Jan