From patchwork Tue May 4 12:45:23 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 51602 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 1D976B7D2E for ; Tue, 4 May 2010 23:05:08 +1000 (EST) Received: from localhost ([127.0.0.1]:58550 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O9Ho8-0006zI-V5 for incoming@patchwork.ozlabs.org; Tue, 04 May 2010 09:05:04 -0400 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 Received: from int-mx05.intmail.prod.int.phx2.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.18]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o44D3lOg013478 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 4 May 2010 09:03:47 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx05.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o44D3lQB022605; Tue, 4 May 2010 09:03:47 -0400 Received: from amt.cnet (vpn2-10-150.ams2.redhat.com [10.36.10.150]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id o44D20L5023680; Tue, 4 May 2010 09:03:38 -0400 Received: from amt.cnet (amt.cnet [127.0.0.1]) by amt.cnet (Postfix) with ESMTP id 3899368A9C5; Tue, 4 May 2010 09:54:58 -0300 (BRT) Received: (from marcelo@localhost) by amt.cnet (8.14.3/8.14.3/Submit) id o44CsuFR016602; Tue, 4 May 2010 09:54:56 -0300 Message-Id: <20100504124634.399797233@redhat.com> User-Agent: quilt/0.47-1 Date: Tue, 04 May 2010 09:45:23 -0300 From: Marcelo Tosatti To: kvm@vger.kernel.org, qemu-devel@nongnu.org References: <20100504124518.979470863@redhat.com> Content-Disposition: inline; filename=cpu-sync-state-use-run-on-cpu X-Scanned-By: MIMEDefang 2.67 on 10.5.11.18 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: Marcelo Tosatti Subject: [Qemu-devel] [patch uq/master 5/9] kvm: synchronize state from cpu context X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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);