From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marcelo Tosatti Subject: [patch uq/master 5/9] kvm: synchronize state from cpu context Date: Tue, 04 May 2010 09:45:23 -0300 Message-ID: <20100504124634.399797233@redhat.com> References: <20100504124518.979470863@redhat.com> Cc: Marcelo Tosatti To: kvm@vger.kernel.org, qemu-devel@nongnu.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:23210 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932164Ab0EDNDt (ORCPT ); Tue, 4 May 2010 09:03:49 -0400 Content-Disposition: inline; filename=cpu-sync-state-use-run-on-cpu Sender: kvm-owner@vger.kernel.org List-ID: From: Jan Kiszka It is not safe to retrieve the KVM internal state of a given cpu while its potentially modifying it. Queue the request to run on cpu context, similarly to qemu-kvm. Signed-off-by: Marcelo Tosatti Index: qemu/kvm-all.c =================================================================== --- qemu.orig/kvm-all.c +++ qemu/kvm-all.c @@ -796,14 +796,22 @@ void kvm_flush_coalesced_mmio_buffer(voi #endif } -void kvm_cpu_synchronize_state(CPUState *env) +static void do_kvm_cpu_synchronize_state(void *_env) { + CPUState *env = _env; + if (!env->kvm_vcpu_dirty) { kvm_arch_get_registers(env); env->kvm_vcpu_dirty = 1; } } +void kvm_cpu_synchronize_state(CPUState *env) +{ + if (!env->kvm_vcpu_dirty) + run_on_cpu(env, do_kvm_cpu_synchronize_state, env); +} + void kvm_cpu_synchronize_post_reset(CPUState *env) { kvm_arch_put_registers(env, KVM_PUT_RESET_STATE); From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O9Hn0-0006kX-Qw for qemu-devel@nongnu.org; Tue, 04 May 2010 09:03:54 -0400 Received: from [140.186.70.92] (port=52667 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O9Hmx-0006jI-Hq for qemu-devel@nongnu.org; Tue, 04 May 2010 09:03:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O9Hmv-0003BX-JK for qemu-devel@nongnu.org; Tue, 04 May 2010 09:03:51 -0400 Received: from mx1.redhat.com ([209.132.183.28]:21401) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O9Hmv-0003B8-6n for qemu-devel@nongnu.org; Tue, 04 May 2010 09:03:49 -0400 Message-Id: <20100504124634.399797233@redhat.com> Date: Tue, 04 May 2010 09:45:23 -0300 From: Marcelo Tosatti References: <20100504124518.979470863@redhat.com> Content-Disposition: inline; filename=cpu-sync-state-use-run-on-cpu Subject: [Qemu-devel] [patch uq/master 5/9] kvm: synchronize state from cpu context List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: kvm@vger.kernel.org, qemu-devel@nongnu.org Cc: Marcelo Tosatti From: Jan Kiszka It is not safe to retrieve the KVM internal state of a given cpu while its potentially modifying it. Queue the request to run on cpu context, similarly to qemu-kvm. Signed-off-by: Marcelo Tosatti Index: qemu/kvm-all.c =================================================================== --- qemu.orig/kvm-all.c +++ qemu/kvm-all.c @@ -796,14 +796,22 @@ void kvm_flush_coalesced_mmio_buffer(voi #endif } -void kvm_cpu_synchronize_state(CPUState *env) +static void do_kvm_cpu_synchronize_state(void *_env) { + CPUState *env = _env; + if (!env->kvm_vcpu_dirty) { kvm_arch_get_registers(env); env->kvm_vcpu_dirty = 1; } } +void kvm_cpu_synchronize_state(CPUState *env) +{ + if (!env->kvm_vcpu_dirty) + run_on_cpu(env, do_kvm_cpu_synchronize_state, env); +} + void kvm_cpu_synchronize_post_reset(CPUState *env) { kvm_arch_put_registers(env, KVM_PUT_RESET_STATE);