qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 2/4] cpu model corrections/updates: add kvm_early_init_vcpu()
@ 2010-09-07 12:30 john cooper
  0 siblings, 0 replies; 2+ messages in thread
From: john cooper @ 2010-09-07 12:30 UTC (permalink / raw)
  To: qemu-devel; +Cc: john cooper

Allow an optional qemu_early_init_vcpu() such that
kvm_arch_get_supported_cpuid() can be used from
cpu_x86_register().  Without this minimal setup
kvm_arch_get_supported_cpuid() gags kvm_ioctl() via
passing a NULL initialized KVMState *.

Signed-off-by: john cooper <john.cooper@redhat.com>
---

diff --git a/cpus.c b/cpus.c
index b09f5e3..82a33b4 100644
--- a/cpus.c
+++ b/cpus.c
@@ -252,6 +252,14 @@ void qemu_main_loop_start(void)
 {
 }
 
+void qemu_early_init_vcpu(void *_env)
+{
+    CPUState *env = _env;
+
+    if (kvm_enabled())
+        kvm_early_init_vcpu(env);
+}
+
 void qemu_init_vcpu(void *_env)
 {
     CPUState *env = _env;
diff --git a/kvm-all.c b/kvm-all.c
index 58b0404..9d89d35 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -170,25 +170,48 @@ int kvm_pit_in_kernel(void)
 }
 
 
-int kvm_init_vcpu(CPUState *env)
+/* env->kvm_state is needed early by kvm_check_extension()
+ * break it out so it may be setup early where needed
+ */
+int kvm_early_init_vcpu(CPUState *env)
 {
     KVMState *s = kvm_state;
-    long mmap_size;
     int ret;
 
-    DPRINTF("kvm_init_vcpu\n");
+    DPRINTF("kvm_early_init_vcpu\n");
+
+    if (env->kvm_state) {	/* already setup */
+        return 0;
+    }
 
     ret = kvm_vm_ioctl(s, KVM_CREATE_VCPU, env->cpu_index);
     if (ret < 0) {
         DPRINTF("kvm_create_vcpu failed\n");
-        goto err;
     }
+    else {
+        env->kvm_fd = ret;
+        env->kvm_state = s;
+    }
+    return ret;
+}
 
-    env->kvm_fd = ret;
-    env->kvm_state = s;
+int kvm_init_vcpu(CPUState *env)
+{
+    KVMState *s;
+    long mmap_size;
+    int ret;
+
+    DPRINTF("kvm_init_vcpu\n");
+
+    ret = kvm_early_init_vcpu(env);
+    if (ret < 0) {
+        goto err;
+    }
 
+    s = env->kvm_state;
     mmap_size = kvm_ioctl(s, KVM_GET_VCPU_MMAP_SIZE, 0);
     if (mmap_size < 0) {
+        ret = mmap_size;
         DPRINTF("KVM_GET_VCPU_MMAP_SIZE failed\n");
         goto err;
     }
diff --git a/kvm.h b/kvm.h
index 50b6c01..420c815 100644
--- a/kvm.h
+++ b/kvm.h
@@ -44,6 +44,7 @@ int kvm_has_xsave(void);
 int kvm_has_xcrs(void);
 
 #ifdef NEED_CPU_H
+int kvm_early_init_vcpu(CPUState *env);
 int kvm_init_vcpu(CPUState *env);
 
 int kvm_cpu_exec(CPUState *env);
diff --git a/qemu-common.h b/qemu-common.h
index dfd3dc0..2453778 100644
--- a/qemu-common.h
+++ b/qemu-common.h
@@ -263,8 +263,10 @@ struct qemu_work_item {
 };
 
 #ifdef CONFIG_USER_ONLY
+#define qemu_early_init_vcpu(env) do { } while (0)
 #define qemu_init_vcpu(env) do { } while (0)
 #else
+void qemu_early_init_vcpu(void *env);
 void qemu_init_vcpu(void *env);
 #endif
 
diff --git a/target-i386/helper.c b/target-i386/helper.c
index e134340..b3c0b42 100644
--- a/target-i386/helper.c
+++ b/target-i386/helper.c
@@ -1133,6 +1133,7 @@ CPUX86State *cpu_x86_init(const char *cpu_model)
             cpu_set_debug_excp_handler(breakpoint_handler);
 #endif
     }
+    qemu_early_init_vcpu(env);
     if (cpu_x86_register(env, cpu_model) < 0) {
         cpu_x86_close(env);
         return NULL;

-- 
john.cooper@redhat.com

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

* [Qemu-devel] [PATCH 2/4] cpu model corrections/updates: add kvm_early_init_vcpu()
@ 2010-11-24 22:44 john cooper
  0 siblings, 0 replies; 2+ messages in thread
From: john cooper @ 2010-11-24 22:44 UTC (permalink / raw)
  To: qemu-devel; +Cc: john cooper

Allow an optional qemu_early_init_vcpu() such that
kvm_arch_get_supported_cpuid() can be used from
cpu_x86_register().  Without this minimal setup
kvm_arch_get_supported_cpuid() gags kvm_ioctl() via
passing a NULL initialized KVMState *.

Signed-off-by: john cooper <john.cooper@redhat.com>
---

diff --git a/cpus.c b/cpus.c
index 91a0fb1..a871856 100644
--- a/cpus.c
+++ b/cpus.c
@@ -260,6 +260,14 @@ void qemu_main_loop_start(void)
 {
 }
 
+void qemu_early_init_vcpu(void *_env)
+{
+    CPUState *env = _env;
+
+    if (kvm_enabled())
+        kvm_early_init_vcpu(env);
+}
+
 void qemu_init_vcpu(void *_env)
 {
     CPUState *env = _env;
diff --git a/kvm-all.c b/kvm-all.c
index 37b99c7..5a91353 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -188,25 +188,48 @@ int kvm_pit_in_kernel(void)
 }
 
 
-int kvm_init_vcpu(CPUState *env)
+/* env->kvm_state is needed early by kvm_check_extension()
+ * break it out so it may be setup early where needed
+ */
+int kvm_early_init_vcpu(CPUState *env)
 {
     KVMState *s = kvm_state;
-    long mmap_size;
     int ret;
 
-    DPRINTF("kvm_init_vcpu\n");
+    DPRINTF("kvm_early_init_vcpu\n");
+
+    if (env->kvm_state) {	/* already setup */
+        return 0;
+    }
 
     ret = kvm_vm_ioctl(s, KVM_CREATE_VCPU, env->cpu_index);
     if (ret < 0) {
         DPRINTF("kvm_create_vcpu failed\n");
-        goto err;
     }
+    else {
+        env->kvm_fd = ret;
+        env->kvm_state = s;
+    }
+    return ret;
+}
 
-    env->kvm_fd = ret;
-    env->kvm_state = s;
+int kvm_init_vcpu(CPUState *env)
+{
+    KVMState *s;
+    long mmap_size;
+    int ret;
+
+    DPRINTF("kvm_init_vcpu\n");
+
+    ret = kvm_early_init_vcpu(env);
+    if (ret < 0) {
+        goto err;
+    }
 
+    s = env->kvm_state;
     mmap_size = kvm_ioctl(s, KVM_GET_VCPU_MMAP_SIZE, 0);
     if (mmap_size < 0) {
+        ret = mmap_size;
         DPRINTF("KVM_GET_VCPU_MMAP_SIZE failed\n");
         goto err;
     }
diff --git a/kvm.h b/kvm.h
index 60a9b42..c8548f9 100644
--- a/kvm.h
+++ b/kvm.h
@@ -44,6 +44,7 @@ int kvm_has_xsave(void);
 int kvm_has_xcrs(void);
 
 #ifdef NEED_CPU_H
+int kvm_early_init_vcpu(CPUState *env);
 int kvm_init_vcpu(CPUState *env);
 
 int kvm_cpu_exec(CPUState *env);
diff --git a/qemu-common.h b/qemu-common.h
index b3957f1..7403761 100644
--- a/qemu-common.h
+++ b/qemu-common.h
@@ -285,8 +285,10 @@ struct qemu_work_item {
 };
 
 #ifdef CONFIG_USER_ONLY
+#define qemu_early_init_vcpu(env) do { } while (0)
 #define qemu_init_vcpu(env) do { } while (0)
 #else
+void qemu_early_init_vcpu(void *env);
 void qemu_init_vcpu(void *env);
 #endif
 
diff --git a/target-i386/helper.c b/target-i386/helper.c
index 26ea1e5..057ee90 100644
--- a/target-i386/helper.c
+++ b/target-i386/helper.c
@@ -1139,6 +1139,7 @@ CPUX86State *cpu_x86_init(const char *cpu_model)
             cpu_set_debug_excp_handler(breakpoint_handler);
 #endif
     }
+    qemu_early_init_vcpu(env);
     if (cpu_x86_register(env, cpu_model) < 0) {
         cpu_x86_close(env);
         return NULL;

-- 
john.cooper@redhat.com

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

end of thread, other threads:[~2010-11-24 22:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-09-07 12:30 [Qemu-devel] [PATCH 2/4] cpu model corrections/updates: add kvm_early_init_vcpu() john cooper
  -- strict thread matches above, loose matches on Subject: below --
2010-11-24 22:44 john cooper

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).