From patchwork Wed Mar 4 14:35:48 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 5936831 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id D4111BF440 for ; Wed, 4 Mar 2015 14:42:37 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 728AD2013A for ; Wed, 4 Mar 2015 14:42:36 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CD54420256 for ; Wed, 4 Mar 2015 14:42:33 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1YTARr-0004B2-S1; Wed, 04 Mar 2015 14:38:55 +0000 Received: from merlin.infradead.org ([2001:4978:20e::2]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YTAPw-0002wa-5j for linux-arm-kernel@bombadil.infradead.org; Wed, 04 Mar 2015 14:36:56 +0000 Received: from static.88-198-71-155.clients.your-server.de ([88.198.71.155] helo=socrates.bennee.com) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YTAPs-0003z1-Ti for linux-arm-kernel@lists.infradead.org; Wed, 04 Mar 2015 14:36:54 +0000 Received: from localhost ([127.0.0.1] helo=zen.linaroharston) by socrates.bennee.com with esmtp (Exim 4.80) (envelope-from ) id 1YTBOj-0007Xe-Td; Wed, 04 Mar 2015 16:39:46 +0100 From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v2 1/6] target-arm: kvm: save/restore mp state Date: Wed, 4 Mar 2015 14:35:48 +0000 Message-Id: <1425479753-18349-2-git-send-email-alex.bennee@linaro.org> X-Mailer: git-send-email 2.3.1 In-Reply-To: <1425479753-18349-1-git-send-email-alex.bennee@linaro.org> References: <1425479753-18349-1-git-send-email-alex.bennee@linaro.org> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 127.0.0.1 X-SA-Exim-Mail-From: alex.bennee@linaro.org X-SA-Exim-Scanned: No (on socrates.bennee.com); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150304_093653_129593_ED0E95A2 X-CRM114-Status: GOOD ( 11.99 ) X-Spam-Score: -1.2 (-) Cc: Peter Maydell , kvm@vger.kernel.org, marc.zyngier@arm.com, linux-arm-kernel@lists.infradead.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , kvmarm@lists.cs.columbia.edu, christoffer.dall@linaro.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This adds the saving and restore of the current Multi-Processing state of the machine. While the KVM_GET/SET_MP_STATE API exposes a number of potential states for x86 we only use two for ARM. Either the process is running or not. We then save this state into the cpu_powered TCG state to avoid changing the serialisation format. Signed-off-by: Alex Bennée --- v2 - make mpstate field runtime dependant (kvm_enabled()) - drop initial KVM_CAP_MP_STATE requirement - re-use cpu_powered instead of new field diff --git a/target-arm/machine.c b/target-arm/machine.c index 9446e5a..185f9a2 100644 --- a/target-arm/machine.c +++ b/target-arm/machine.c @@ -161,6 +161,7 @@ static const VMStateInfo vmstate_cpsr = { .put = put_cpsr, }; + static void cpu_pre_save(void *opaque) { ARMCPU *cpu = opaque; @@ -170,6 +171,20 @@ static void cpu_pre_save(void *opaque) /* This should never fail */ abort(); } +#if defined CONFIG_KVM + if (kvm_check_extension(CPU(cpu)->kvm_state, KVM_CAP_MP_STATE)) { + struct kvm_mp_state mp_state; + int ret = kvm_vcpu_ioctl(CPU(cpu), KVM_GET_MP_STATE, &mp_state); + if (ret) { + fprintf(stderr, "%s: failed to get MP_STATE %d/%s\n", + __func__, ret, strerror(ret)); + abort(); + } + cpu->powered_off = + (mp_state.mp_state == KVM_MP_STATE_RUNNABLE) + ? false : true; + } +#endif } else { if (!write_cpustate_to_list(cpu)) { /* This should never fail. */ @@ -222,6 +237,20 @@ static int cpu_post_load(void *opaque, int version_id) * we're using it. */ write_list_to_cpustate(cpu); +#if defined CONFIG_KVM + if (kvm_check_extension(CPU(cpu)->kvm_state, KVM_CAP_MP_STATE)) { + struct kvm_mp_state mp_state = { + .mp_state = + cpu->powered_off ? KVM_MP_STATE_HALTED : KVM_MP_STATE_RUNNABLE + }; + int ret = kvm_vcpu_ioctl(CPU(cpu), KVM_SET_MP_STATE, &mp_state); + if (ret) { + fprintf(stderr, "%s: failed to set MP_STATE %d/%s\n", + __func__, ret, strerror(ret)); + return -1; + } + } +#endif } else { if (!write_list_to_cpustate(cpu)) { return -1;