From patchwork Wed Sep 9 16:01:46 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gleb Natapov X-Patchwork-Id: 46416 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n89G1q7L003843 for ; Wed, 9 Sep 2009 16:01:52 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753103AbZIIQBr (ORCPT ); Wed, 9 Sep 2009 12:01:47 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1753107AbZIIQBq (ORCPT ); Wed, 9 Sep 2009 12:01:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57066 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752913AbZIIQBq (ORCPT ); Wed, 9 Sep 2009 12:01:46 -0400 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n89G1nPe028253 for ; Wed, 9 Sep 2009 12:01:50 -0400 Received: from dhcp-1-237.tlv.redhat.com (dhcp-1-237.tlv.redhat.com [10.35.1.237]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n89G1l7k027287; Wed, 9 Sep 2009 12:01:48 -0400 Received: by dhcp-1-237.tlv.redhat.com (Postfix, from userid 13519) id BB54918D467; Wed, 9 Sep 2009 19:01:46 +0300 (IDT) Date: Wed, 9 Sep 2009 19:01:46 +0300 From: Gleb Natapov To: avi@redhat.com Cc: kvm@vger.kernel.org Subject: [PATCH v2] call kvm_cpu_synchronize_state() on target vcpu Message-ID: <20090909160146.GF22885@redhat.com> MIME-Version: 1.0 Content-Disposition: inline X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org 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. -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html 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