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: 45425 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f197.google.com (mail-lb0-f197.google.com [209.85.217.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 2706421416 for ; Wed, 4 Mar 2015 14:40:33 +0000 (UTC) Received: by lbvp9 with SMTP id p9sf7154573lbv.0 for ; Wed, 04 Mar 2015 06:40:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:mime-version:content-type:content-transfer-encoding:cc :subject:precedence:list-id:list-unsubscribe:list-archive:list-post :list-help:list-subscribe:errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=nX9YW7RKXailFaNJxprvGf7hJz15hWbD7DcZ5z2pJCk=; b=N6RN9ADdcVykwsTeu6BP7zIt/D1c0+jE5+CURdkcpeRyjDk1dNfCrOL+WnIqUn6Siu kPUZSA5NUHpojZXjvjKepHqTTj+2EjCoxa6xWtjduLyChjWoogxOfI+YhOzo7SXDKMrO q2ZnCKFJSkSLpssl7txpIj+rz4o0vCxKtyRLG9pDqMFU5n0SDZ1jj+p3ceNy/4W+vs6i FryQIxsRRhm55OSvPNZ/JDHgZIzr2Wrpuc31Updc9rCt4I63XTOyLf030RJi/EZQRJFS YqQohGlhj1cMKYZBKtOLwBDaqzwceHg38Dz40kKNOIDk/dLg9nWUWR/UaPhgA/dQoOZg pCVw== X-Gm-Message-State: ALoCoQnTrrhwcw/r+8Y6RI8PO1nUOY/y92f2yob5nZOeN5vpdEr9UR03t5xkc8eM5J+nW5bcj/fN X-Received: by 10.180.75.232 with SMTP id f8mr3902854wiw.0.1425480032136; Wed, 04 Mar 2015 06:40:32 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.21.130 with SMTP id v2ls153923lae.98.gmail; Wed, 04 Mar 2015 06:40:31 -0800 (PST) X-Received: by 10.112.92.66 with SMTP id ck2mr3592948lbb.105.1425480031956; Wed, 04 Mar 2015 06:40:31 -0800 (PST) Received: from mail-lb0-f174.google.com (mail-lb0-f174.google.com. [209.85.217.174]) by mx.google.com with ESMTPS id yr7si2681128lbb.26.2015.03.04.06.40.31 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 04 Mar 2015 06:40:31 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.174 as permitted sender) client-ip=209.85.217.174; Received: by lbiz11 with SMTP id z11so18701647lbi.13 for ; Wed, 04 Mar 2015 06:40:31 -0800 (PST) X-Received: by 10.152.120.134 with SMTP id lc6mr3705501lab.72.1425480031863; Wed, 04 Mar 2015 06:40:31 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.35.133 with SMTP id h5csp1260784lbj; Wed, 4 Mar 2015 06:40:31 -0800 (PST) X-Received: by 10.55.21.142 with SMTP id 14mr7930420qkv.30.1425480030503; Wed, 04 Mar 2015 06:40:30 -0800 (PST) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id u45si3546480qgu.115.2015.03.04.06.40.29 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 04 Mar 2015 06:40:30 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Received: from localhost ([::1]:44462 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YTATN-0000nr-LK for patch@linaro.org; Wed, 04 Mar 2015 09:40:29 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58309) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YTAPE-0002I0-9l for qemu-devel@nongnu.org; Wed, 04 Mar 2015 09:36:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YTAP5-0007Jv-5K for qemu-devel@nongnu.org; Wed, 04 Mar 2015 09:36:12 -0500 Received: from static.88-198-71-155.clients.your-server.de ([88.198.71.155]:57772 helo=socrates.bennee.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YTAP4-0007JE-VV for qemu-devel@nongnu.org; Wed, 04 Mar 2015 09:36:03 -0500 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 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-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 88.198.71.155 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 Subject: [Qemu-devel] [PATCH v2 1/6] target-arm: kvm: save/restore mp state 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: alex.bennee@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.174 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 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 Reviewed-by: Greg Bellows ​ --- 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;