From: Glauber Costa <glommer@redhat.com>
To: kvm@vger.kernel.org
Cc: avi@redhat.com
Subject: [PATCH 2/4] only execute lapic load when cpu is already initialized
Date: Tue, 26 May 2009 17:32:59 -0400 [thread overview]
Message-ID: <1243373581-18085-3-git-send-email-glommer@redhat.com> (raw)
In-Reply-To: <1243373581-18085-2-git-send-email-glommer@redhat.com>
In a later patch, we will reorder the execution of vcpu initialization.
After that, the first call to KVM_SET_LAPIC ioctl will not find an
existant vcpu. So we introduce a function that tell us that the vcpu
is already initialized, and is it safe to call the ioctl.
This patch is included first rather than after, so nothing breaks,
and we can keep the tree bisectable.
Signed-off-by: Glauber Costa <glommer@redhat.com>
---
hw/apic.c | 21 +++++++++++----------
qemu-kvm.c | 5 +++++
qemu-kvm.h | 4 ++++
3 files changed, 20 insertions(+), 10 deletions(-)
diff --git a/hw/apic.c b/hw/apic.c
index 21aff15..86aa6b6 100644
--- a/hw/apic.c
+++ b/hw/apic.c
@@ -891,6 +891,15 @@ static void kvm_kernel_lapic_load_from_user(APICState *s)
#endif
+void qemu_kvm_load_lapic(CPUState *env)
+{
+#ifdef KVM_CAP_IRQCHIP
+ if (kvm_enabled() && kvm_vcpu_inited(env) && qemu_kvm_irqchip_in_kernel()) {
+ kvm_kernel_lapic_load_from_user(env->apic_state);
+ }
+#endif
+}
+
static void apic_save(QEMUFile *f, void *opaque)
{
APICState *s = opaque;
@@ -965,11 +974,7 @@ static int apic_load(QEMUFile *f, void *opaque, int version_id)
if (version_id >= 2)
qemu_get_timer(f, s->timer);
-#ifdef KVM_CAP_IRQCHIP
- if (kvm_enabled() && qemu_kvm_irqchip_in_kernel()) {
- kvm_kernel_lapic_load_from_user(s);
- }
-#endif
+ qemu_kvm_load_lapic(s->cpu_env);
return 0;
}
@@ -991,11 +996,7 @@ static void apic_reset(void *opaque)
*/
s->lvt[APIC_LVT_LINT0] = 0x700;
}
-#ifdef KVM_CAP_IRQCHIP
- if (kvm_enabled() && qemu_kvm_irqchip_in_kernel()) {
- kvm_kernel_lapic_load_from_user(s);
- }
-#endif
+ qemu_kvm_load_lapic(s->cpu_env);
}
static CPUReadMemoryFunc *apic_mem_read[3] = {
diff --git a/qemu-kvm.c b/qemu-kvm.c
index d16917f..68d3b92 100644
--- a/qemu-kvm.c
+++ b/qemu-kvm.c
@@ -462,6 +462,11 @@ void kvm_init_vcpu(CPUState *env)
qemu_cond_wait(&qemu_vcpu_cond);
}
+int kvm_vcpu_inited(CPUState *env)
+{
+ return env->kvm_cpu_state.created;
+}
+
int kvm_init_ap(void)
{
#ifdef TARGET_I386
diff --git a/qemu-kvm.h b/qemu-kvm.h
index e74ab90..725589b 100644
--- a/qemu-kvm.h
+++ b/qemu-kvm.h
@@ -16,6 +16,7 @@ int kvm_main_loop(void);
int kvm_qemu_init(void);
int kvm_qemu_create_context(void);
int kvm_init_ap(void);
+int kvm_vcpu_inited(CPUState *env);
void kvm_qemu_destroy(void);
void kvm_load_registers(CPUState *env);
void kvm_save_registers(CPUState *env);
@@ -31,6 +32,9 @@ int kvm_update_guest_debug(CPUState *env, unsigned long reinject_trap);
int kvm_qemu_init_env(CPUState *env);
int kvm_qemu_check_extension(int ext);
void kvm_apic_init(CPUState *env);
+/* called from vcpu initialization */
+void qemu_kvm_load_lapic(CPUState *env);
+
int kvm_set_irq(int irq, int level, int *status);
int kvm_physical_memory_set_dirty_tracking(int enable);
--
1.5.6.6
next prev parent reply other threads:[~2009-05-26 21:33 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-05-26 21:32 [PATCH 0/4] Fix cpu hotplug - currently broken Glauber Costa
2009-05-26 21:32 ` [PATCH 1/4] remove duplicated code Glauber Costa
2009-05-26 21:32 ` Glauber Costa [this message]
2009-05-26 21:33 ` [PATCH 3/4] move kvm_trim_features where it belongs Glauber Costa
2009-05-26 21:33 ` [PATCH 4/4] make sure kvm_vpu_init is the last thing called in cpu initialization Glauber Costa
2009-05-31 9:40 ` [PATCH 0/4] Fix cpu hotplug - currently broken Avi Kivity
2009-05-31 13:30 ` Glauber Costa
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=1243373581-18085-3-git-send-email-glommer@redhat.com \
--to=glommer@redhat.com \
--cc=avi@redhat.com \
--cc=kvm@vger.kernel.org \
/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