From patchwork Mon Apr 4 04:49:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gibson X-Patchwork-Id: 605743 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3qdhNg5bW8z9sD2 for ; Mon, 4 Apr 2016 16:07:47 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.b=ZjslECmn; dkim-atps=neutral Received: from localhost ([::1]:56764 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1amxft-0002Wv-GQ for incoming@patchwork.ozlabs.org; Mon, 04 Apr 2016 02:07:45 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37558) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1amxfP-0001iD-1I for qemu-devel@nongnu.org; Mon, 04 Apr 2016 02:07:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1amxfO-0000aU-60 for qemu-devel@nongnu.org; Mon, 04 Apr 2016 02:07:14 -0400 Received: from ozlabs.org ([2401:3900:2:1::2]:35754) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1amxfN-0000Z9-RW; Mon, 04 Apr 2016 02:07:14 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 3qdhMx49p0z9sRZ; Mon, 4 Apr 2016 16:07:09 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1459750029; bh=SkqKAdmowjqbs60RstO0Vtk7xYgr7biCuCBb+nlmKSk=; h=From:To:Cc:Subject:Date:From; b=ZjslECmnvdmkKwpBwy/88NFC/TZAjMbxm3LE9okOsD1QQT2zNEIS8tUQqQV4OqlR4 fsAu3G8OQK4XuWwVgifRU/BG6BjjgWEFY8E49SXgLOTPhYdL3BP642RsmDAvpWNkHU zwVlSRKb5MLCTnyrQlfl+EaIP6NJ6nWzjP/aG/XM= From: David Gibson To: pbonzini@redhat.com, peter.maydell@linaro.org Date: Mon, 4 Apr 2016 14:49:11 +1000 Message-Id: <1459745351-13138-1-git-send-email-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.5.5 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2401:3900:2:1::2 Cc: lvivier@redhat.com, mtosatti@redhat.com, agraf@suse.de, qemu-devel@nongnu.org, qemu-ppc@nongnu.org, David Gibson Subject: [Qemu-devel] [PATCH] vl: Move cpu_synchronize_all_states() into qemu_system_reset() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org There are currently 3 calls to qemu_system_reset() in vl.c. Two of them are immediately preceded by a cpu_synchronize_all_states9) and the remaining one should be. The one which doesn't is the very first reset called directly from main(). Without a cpu_synchronize_all_states(), kvm_vcpu_dirty is false at this point from the earlier cpu_synchronize_all_post_init(). That's incorrect because the reset path is quite likely to update the CPU state, and that updated state should be pushed back to KVM, not overwritten with stale data pushed to KVM immediately after init. This patch moves the call to cpu_synchronize_all_states() into qemu_system_reset() for safety, so it is always called. AFAICT this should be safe for the handful of callers outside vl.c - these all appear to be in places where the cpu state is already synchronized so the extra call will be a no-op. Signed-off-by: David Gibson Acked-by: Paolo Bonzini Tested-by: Laurent Vivier --- vl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) This fixes a real but on ppc - the incorrect state of kvm_vcpu_dirty means that an extra cpu_synchronize_state() in revised code for updating the MSR is not a no-op as expected and loads a stale MSR value, resulting in an incorrect MSR value on entry to the guest. Therefore, I'm hoping to apply this ASAP to 2.6. Laurent, could you please verify that this does indeed address the problem with an incorrect MSR on entry. diff --git a/vl.c b/vl.c index bd81ea9..3629336 100644 --- a/vl.c +++ b/vl.c @@ -1745,6 +1745,8 @@ void qemu_system_reset(bool report) mc = current_machine ? MACHINE_GET_CLASS(current_machine) : NULL; + cpu_synchronize_all_states(); + if (mc && mc->reset) { mc->reset(); } else { @@ -1893,7 +1895,6 @@ static bool main_loop_should_exit(void) } if (qemu_reset_requested()) { pause_all_vcpus(); - cpu_synchronize_all_states(); qemu_system_reset(VMRESET_REPORT); resume_all_vcpus(); if (!runstate_check(RUN_STATE_RUNNING) && @@ -1903,7 +1904,6 @@ static bool main_loop_should_exit(void) } if (qemu_wakeup_requested()) { pause_all_vcpus(); - cpu_synchronize_all_states(); qemu_system_reset(VMRESET_SILENT); notifier_list_notify(&wakeup_notifiers, &wakeup_reason); wakeup_reason = QEMU_WAKEUP_REASON_NONE;