From: Gleb Natapov <gleb@redhat.com>
To: avi@redhat.com
Cc: kvm@vger.kernel.org
Subject: [PATCH v2] call kvm_cpu_synchronize_state() on target vcpu
Date: Wed, 9 Sep 2009 19:01:46 +0300 [thread overview]
Message-ID: <20090909160146.GF22885@redhat.com> (raw)
regs_modified logic doesn't work if io thread calls
kvm_cpu_synchronize_state() since kvm_arch_get_registers()
returns only after vcpu thread is back to kernel. Setting
regs_modified to 1 at this stage causes loading of wrong vcpu
state on the next vcpu_run().
--
v1->v2:
do not remove kvm_arch_get_registers(). Change it and use it.
Signed-off-by: Gleb Natapov <gleb@redhat.com>
diff --git a/qemu-kvm.c b/qemu-kvm.c
index 06efd41..e2f3b91 100644
--- a/qemu-kvm.c
+++ b/qemu-kvm.c
@@ -874,14 +874,6 @@ int kvm_set_mpstate(kvm_vcpu_context_t vcpu, struct kvm_mp_state *mp_state)
}
#endif
-void kvm_cpu_synchronize_state(CPUState *env)
-{
- if (!env->kvm_cpu_state.regs_modified) {
- kvm_arch_get_registers(env);
- env->kvm_cpu_state.regs_modified = 1;
- }
-}
-
static int handle_mmio(kvm_vcpu_context_t vcpu)
{
unsigned long addr = vcpu->run->mmio.phys_addr;
@@ -1539,6 +1531,21 @@ static void on_vcpu(CPUState *env, void (*func)(void *data), void *data)
qemu_cond_wait(&qemu_work_cond);
}
+static void do_kvm_cpu_synchronize_state(void *_env)
+{
+ CPUState *env = _env;
+ if (!env->kvm_cpu_state.regs_modified) {
+ kvm_arch_get_registers(env);
+ env->kvm_cpu_state.regs_modified = 1;
+ }
+}
+
+void kvm_cpu_synchronize_state(CPUState *env)
+{
+ if (!env->kvm_cpu_state.regs_modified)
+ on_vcpu(env, do_kvm_cpu_synchronize_state, env);
+}
+
static void inject_interrupt(void *data)
{
cpu_interrupt(current_env, (long) data);
diff --git a/qemu-kvm.h b/qemu-kvm.h
index 2c1730b..1c42e82 100644
--- a/qemu-kvm.h
+++ b/qemu-kvm.h
@@ -1155,8 +1155,8 @@ static inline int kvm_sync_vcpus(void)
static inline void kvm_arch_get_registers(CPUState *env)
{
- kvm_save_registers(env);
- kvm_save_mpstate(env);
+ kvm_arch_save_regs(env);
+ kvm_arch_save_mpstate(env);
}
static inline void kvm_arch_put_registers(CPUState *env)
diff --git a/target-i386/helper.c b/target-i386/helper.c
index 4a16887..57c74a2 100644
--- a/target-i386/helper.c
+++ b/target-i386/helper.c
@@ -746,7 +746,7 @@ void cpu_dump_state(CPUState *env, FILE *f,
static const char *seg_name[6] = { "ES", "CS", "SS", "DS", "FS", "GS" };
if (kvm_enabled())
- kvm_arch_get_registers(env);
+ kvm_cpu_synchronize_state(env);
eflags = env->eflags;
#ifdef TARGET_X86_64
--
Gleb.
next reply other threads:[~2009-09-09 16:01 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-09 16:01 Gleb Natapov [this message]
2009-09-09 16:16 ` [PATCH v2] call kvm_cpu_synchronize_state() on target vcpu Avi Kivity
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=20090909160146.GF22885@redhat.com \
--to=gleb@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;
as well as URLs for NNTP newsgroup(s).