qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 1/2] kvm: Rework VCPU synchronization
@ 2009-05-23 19:19 Jan Kiszka
  2009-05-23 19:20 ` [Qemu-devel] [PATCH 2/2] Revert "Introduce reset notifier order" Jan Kiszka
  2009-05-28  7:37 ` [Qemu-devel] Re: [PATCH 1/2] kvm: Rework VCPU synchronization Anthony Liguori
  0 siblings, 2 replies; 5+ messages in thread
From: Jan Kiszka @ 2009-05-23 19:19 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 3627 bytes --]

During startup and after reset we have to synchronize user space to the
in-kernel KVM state. Namely, we need to transfer the VCPU registers when
they change due to VCPU as well as APIC reset.

This patch refactors the required hooks so that kvm_init_vcpu registers
its own per-VCPU reset handler and adds a cpu_synchronize_state to the
APIC reset. That way we no longer depend on the new reset order (and can
drop this disliked interface again) and we can even drop a KVM hook in
main().

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---

 hw/apic.c |    3 +++
 kvm-all.c |   36 +++++++++++++-----------------------
 kvm.h     |    1 -
 vl.c      |   11 -----------
 4 files changed, 16 insertions(+), 35 deletions(-)

diff --git a/hw/apic.c b/hw/apic.c
index 8c8b2de..10b8184 100644
--- a/hw/apic.c
+++ b/hw/apic.c
@@ -21,6 +21,7 @@
 #include "pc.h"
 #include "qemu-timer.h"
 #include "host-utils.h"
+#include "kvm.h"

 //#define DEBUG_APIC

@@ -884,6 +885,8 @@ static void apic_reset(void *opaque)
          */
         s->lvt[APIC_LVT_LINT0] = 0x700;
     }
+
+    cpu_synchronize_state(s->cpu_env, 1);
 }

 static CPUReadMemoryFunc *apic_mem_read[3] = {
diff --git a/kvm-all.c b/kvm-all.c
index c89e3b1..1364982 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -143,6 +143,15 @@ static int kvm_set_user_memory_region(KVMState *s,
KVMSlot *slot)
     return kvm_vm_ioctl(s, KVM_SET_USER_MEMORY_REGION, &mem);
 }

+static void kvm_reset_vcpu(void *opaque)
+{
+    CPUState *env = opaque;
+
+    if (kvm_arch_put_registers(env)) {
+        fprintf(stderr, "Fatal: kvm vcpu reset failed\n");
+        abort();
+    }
+}

 int kvm_init_vcpu(CPUState *env)
 {
@@ -176,7 +185,10 @@ int kvm_init_vcpu(CPUState *env)
     }

     ret = kvm_arch_init_vcpu(env);
-
+    if (ret == 0) {
+        qemu_register_reset(kvm_reset_vcpu, 0, env);
+        ret = kvm_arch_put_registers(env);
+    }
 err:
     return ret;
 }
@@ -201,21 +213,6 @@ int kvm_get_mp_state(CPUState *env)
     return 0;
 }

-int kvm_sync_vcpus(void)
-{
-    CPUState *env;
-
-    for (env = first_cpu; env != NULL; env = env->next_cpu) {
-        int ret;
-
-        ret = kvm_arch_put_registers(env);
-        if (ret)
-            return ret;
-    }
-
-    return 0;
-}
-
 /*
  * dirty pages logging control
  */
@@ -397,11 +394,6 @@ int kvm_check_extension(KVMState *s, unsigned int
extension)
     return ret;
 }

-static void kvm_reset_vcpus(void *opaque)
-{
-    kvm_sync_vcpus();
-}
-
 int kvm_init(int smp_cpus)
 {
     KVMState *s;
@@ -488,8 +480,6 @@ int kvm_init(int smp_cpus)
     if (ret < 0)
         goto err;

-    qemu_register_reset(kvm_reset_vcpus, INT_MAX, NULL);
-
     kvm_state = s;

     return 0;
diff --git a/kvm.h b/kvm.h
index 560aef3..96b4d72 100644
--- a/kvm.h
+++ b/kvm.h
@@ -32,7 +32,6 @@ struct kvm_run;
 int kvm_init(int smp_cpus);

 int kvm_init_vcpu(CPUState *env);
-int kvm_sync_vcpus(void);

 int kvm_cpu_exec(CPUState *env);

diff --git a/vl.c b/vl.c
index 090c83d..8b38fd1 100644
--- a/vl.c
+++ b/vl.c
@@ -5918,17 +5918,6 @@ int main(int argc, char **argv, char **envp)

     current_machine = machine;

-    /* Set KVM's vcpu state to qemu's initial CPUState. */
-    if (kvm_enabled()) {
-        int ret;
-
-        ret = kvm_sync_vcpus();
-        if (ret < 0) {
-            fprintf(stderr, "failed to initialize vcpus\n");
-            exit(1);
-        }
-    }
-
     /* init USB devices */
     if (usb_enabled) {
         for(i = 0; i < usb_devices_index; i++) {


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 257 bytes --]

^ permalink raw reply related	[flat|nested] 5+ messages in thread
* [Qemu-devel] [PATCH 1/2] kvm: Rework VCPU synchronization
@ 2009-06-27  7:24 Jan Kiszka
  0 siblings, 0 replies; 5+ messages in thread
From: Jan Kiszka @ 2009-06-27  7:24 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: qemu-devel, Avi Kivity

[-- Attachment #1: Type: text/plain, Size: 3662 bytes --]

During startup and after reset we have to synchronize user space to the
in-kernel KVM state. Namely, we need to transfer the VCPU registers when
they change due to VCPU as well as APIC reset.

This patch refactors the required hooks so that kvm_init_vcpu registers
its own per-VCPU reset handler and adds a cpu_synchronize_state to the
APIC reset. That way we no longer depend on the new reset order (and can
drop this disliked interface again) and we can even drop a KVM hook in
main().

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---

 hw/apic.c |    3 +++
 kvm-all.c |   36 +++++++++++++-----------------------
 kvm.h     |    1 -
 vl.c      |   11 -----------
 4 files changed, 16 insertions(+), 35 deletions(-)

diff --git a/hw/apic.c b/hw/apic.c
index b059185..6256756 100644
--- a/hw/apic.c
+++ b/hw/apic.c
@@ -21,6 +21,7 @@
 #include "pc.h"
 #include "qemu-timer.h"
 #include "host-utils.h"
+#include "kvm.h"
 
 //#define DEBUG_APIC
 
@@ -919,6 +920,8 @@ static void apic_reset(void *opaque)
          */
         s->lvt[APIC_LVT_LINT0] = 0x700;
     }
+
+    cpu_synchronize_state(s->cpu_env, 1);
 }
 
 static CPUReadMemoryFunc *apic_mem_read[3] = {
diff --git a/kvm-all.c b/kvm-all.c
index d843338..017296b 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -143,6 +143,15 @@ static int kvm_set_user_memory_region(KVMState *s, KVMSlot *slot)
     return kvm_vm_ioctl(s, KVM_SET_USER_MEMORY_REGION, &mem);
 }
 
+static void kvm_reset_vcpu(void *opaque)
+{
+    CPUState *env = opaque;
+
+    if (kvm_arch_put_registers(env)) {
+        fprintf(stderr, "Fatal: kvm vcpu reset failed\n");
+        abort();
+    }
+}
 
 int kvm_init_vcpu(CPUState *env)
 {
@@ -176,7 +185,10 @@ int kvm_init_vcpu(CPUState *env)
     }
 
     ret = kvm_arch_init_vcpu(env);
-
+    if (ret == 0) {
+        qemu_register_reset(kvm_reset_vcpu, 0, env);
+        ret = kvm_arch_put_registers(env);
+    }
 err:
     return ret;
 }
@@ -201,21 +213,6 @@ int kvm_get_mp_state(CPUState *env)
     return 0;
 }
 
-int kvm_sync_vcpus(void)
-{
-    CPUState *env;
-
-    for (env = first_cpu; env != NULL; env = env->next_cpu) {
-        int ret;
-
-        ret = kvm_arch_put_registers(env);
-        if (ret)
-            return ret;
-    }
-
-    return 0;
-}
-
 /*
  * dirty pages logging control
  */
@@ -397,11 +394,6 @@ int kvm_check_extension(KVMState *s, unsigned int extension)
     return ret;
 }
 
-static void kvm_reset_vcpus(void *opaque)
-{
-    kvm_sync_vcpus();
-}
-
 int kvm_init(int smp_cpus)
 {
     static const char upgrade_note[] =
@@ -492,8 +484,6 @@ int kvm_init(int smp_cpus)
     if (ret < 0)
         goto err;
 
-    qemu_register_reset(kvm_reset_vcpus, INT_MAX, NULL);
-
     kvm_state = s;
 
     return 0;
diff --git a/kvm.h b/kvm.h
index 560aef3..96b4d72 100644
--- a/kvm.h
+++ b/kvm.h
@@ -32,7 +32,6 @@ struct kvm_run;
 int kvm_init(int smp_cpus);
 
 int kvm_init_vcpu(CPUState *env);
-int kvm_sync_vcpus(void);
 
 int kvm_cpu_exec(CPUState *env);
 
diff --git a/vl.c b/vl.c
index 60a00e1..8e79e31 100644
--- a/vl.c
+++ b/vl.c
@@ -6061,17 +6061,6 @@ int main(int argc, char **argv, char **envp)
 
     current_machine = machine;
 
-    /* Set KVM's vcpu state to qemu's initial CPUState. */
-    if (kvm_enabled()) {
-        int ret;
-
-        ret = kvm_sync_vcpus();
-        if (ret < 0) {
-            fprintf(stderr, "failed to initialize vcpus\n");
-            exit(1);
-        }
-    }
-
     /* init USB devices */
     if (usb_enabled) {
         for(i = 0; i < usb_devices_index; i++) {


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 257 bytes --]

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2009-06-27  7:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-05-23 19:19 [Qemu-devel] [PATCH 1/2] kvm: Rework VCPU synchronization Jan Kiszka
2009-05-23 19:20 ` [Qemu-devel] [PATCH 2/2] Revert "Introduce reset notifier order" Jan Kiszka
2009-05-28  7:37 ` [Qemu-devel] Re: [PATCH 1/2] kvm: Rework VCPU synchronization Anthony Liguori
2009-05-28  7:46   ` Jan Kiszka
  -- strict thread matches above, loose matches on Subject: below --
2009-06-27  7:24 [Qemu-devel] " Jan Kiszka

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).