qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Glauber Costa <glommer@redhat.com>
To: qemu-devel@nongnu.org
Cc: Ian.Jackson@eu.citrix.com, avi@redhat.com, kvm@vger.kernel.org,
	stefano.stabellini@eu.citrix.com
Subject: [Qemu-devel] [PATCH 2/2] hook into vcpu creation
Date: Tue, 30 Dec 2008 09:52:06 -0500	[thread overview]
Message-ID: <1230648726-17163-3-git-send-email-glommer@redhat.com> (raw)
In-Reply-To: <1230648726-17163-2-git-send-email-glommer@redhat.com>

Allow kvm to override vcpu creation. We need to grab
a minimal amount of code that is shared, but the big
part is highly kvm/tcg specific.

Signed-off-by: Glauber Costa <glommer@redhat.com>
---
 kvm-all.c            |   18 ++++++++++++++----
 kvm.h                |    2 +-
 target-i386/helper.c |   12 +++++++++---
 target-i386/kvm.c    |    5 +++++
 4 files changed, 29 insertions(+), 8 deletions(-)

diff --git a/kvm-all.c b/kvm-all.c
index a279d6c..ebad664 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -104,12 +104,19 @@ static int kvm_set_user_memory_region(KVMState *s, KVMSlot *slot)
 }
 
 
-int kvm_init_vcpu(CPUState *env)
+CPUState *kvm_init_vcpu(const char *cpu_model)
 {
     KVMState *s = kvm_state;
     long mmap_size;
     int ret;
 
+    CPUState *env = qemu_mallocz(sizeof(*env));
+    if (!env)
+        return NULL;
+
+    cpu_exec_init(env);
+    env->cpu_model_str = cpu_model;
+
     dprintf("kvm_init_vcpu\n");
 
     ret = kvm_vm_ioctl(s, KVM_CREATE_VCPU, env->cpu_index);
@@ -135,10 +142,13 @@ int kvm_init_vcpu(CPUState *env)
         goto err;
     }
 
-    ret = kvm_arch_init_vcpu(env);
-
+    if (kvm_arch_init_vcpu(env))
+        goto err;
+    
+    return env;
 err:
-    return ret;
+    qemu_free(env);
+    return NULL;
 }
 
 int kvm_sync_vcpus(void)
diff --git a/kvm.h b/kvm.h
index efce145..4ea679f 100644
--- a/kvm.h
+++ b/kvm.h
@@ -30,7 +30,7 @@ struct kvm_run;
 
 int kvm_init(int smp_cpus);
 
-int kvm_init_vcpu(CPUState *env);
+CPUState *kvm_init_vcpu(const char *cpu_model);
 int kvm_sync_vcpus(void);
 
 int kvm_cpu_exec(CPUState *env);
diff --git a/target-i386/helper.c b/target-i386/helper.c
index 1389a0a..d8bed46 100644
--- a/target-i386/helper.c
+++ b/target-i386/helper.c
@@ -1607,7 +1607,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index,
     }
 }
 
-CPUX86State *cpu_x86_init(const char *cpu_model)
+CPUX86State *cpu_x86_default_init(const char *cpu_model)
 {
     CPUX86State *env;
     static int inited;
@@ -1635,7 +1635,13 @@ CPUX86State *cpu_x86_init(const char *cpu_model)
 #ifdef USE_KQEMU
     kqemu_init(env);
 #endif
-    if (kvm_enabled())
-        kvm_init_vcpu(env);
     return env;
 }
+
+CPUX86State *cpu_x86_init(const char *cpu_model)
+{
+    if (kvm_enabled())
+        return kvm_init_vcpu(cpu_model);
+    else
+        return cpu_x86_default_init(cpu_model);
+}
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 2412ae4..08a4416 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -44,6 +44,11 @@ int kvm_arch_init_vcpu(CPUState *env)
 
     cpuid_i = 0;
 
+    if (cpu_x86_register(env) < 0) {
+        cpu_x86_close(env);
+        return -1;
+    }
+
     cpu_x86_cpuid(env, 0, &eax, &ebx, &ecx, &edx);
     limit = eax;
 
-- 
1.5.6.5

      reply	other threads:[~2008-12-30 14:52 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-30 14:52 [Qemu-devel] [PATCH 0/2] Hook into vcpu creation Glauber Costa
2008-12-30 14:52 ` [Qemu-devel] [PATCH 1/2] simplify cpu_x86_register Glauber Costa
2008-12-30 14:52   ` Glauber Costa [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1230648726-17163-3-git-send-email-glommer@redhat.com \
    --to=glommer@redhat.com \
    --cc=Ian.Jackson@eu.citrix.com \
    --cc=avi@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefano.stabellini@eu.citrix.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).