From patchwork Mon Mar 16 11:01:52 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: 45826 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f69.google.com (mail-wg0-f69.google.com [74.125.82.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 09A5B21523 for ; Mon, 16 Mar 2015 11:08:04 +0000 (UTC) Received: by wghk14 with SMTP id k14sf25810733wgh.3 for ; Mon, 16 Mar 2015 04:08:03 -0700 (PDT) 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=vvkMAuEcbN1KnihTmaIY6+w6dF5pPwT7BcgkksAeC3g=; b=Dst9kb9TLMHcq1/1+USCPNYgo9CfHFvBAwM80xvQBR7IyX8i7jXxbeA92MfKNmGiNa tZBsW+o093VFAjCpj3N3TEisIMLi7zXn4Af9kILacGfUN9WJX5uM1eWNT1bWD2IKRq9D SUefuSQuOWMroWHSYsVeNDjSpmEysSirUkmxjRtHEQRwILCZ9cOyFTaP92T2+FFKcR8r OEt5BA5sgyrbar3nA0tS4WhMsmzqkVtg6dwbGDSumwphbopc6dLCMXJVQFFWtTRcQaSB ocXczLkDNBdJDlfHUib8Jb4B3AjKu5C9p/+2yvWiRZx9S+5HC3ryKVC6n03Fhk3bEjPz 7v+Q== X-Gm-Message-State: ALoCoQliWbnmL73JuaFZgUyvzCSL9Y4ZG65Zu5wbT8NPe43kDEB7PtRcv0aLHPxHGLi9Yd9JFeap X-Received: by 10.152.4.229 with SMTP id n5mr9084476lan.1.1426504082312; Mon, 16 Mar 2015 04:08:02 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.228.136 with SMTP id si8ls681851lac.11.gmail; Mon, 16 Mar 2015 04:08:02 -0700 (PDT) X-Received: by 10.112.134.106 with SMTP id pj10mr55964590lbb.58.1426504082021; Mon, 16 Mar 2015 04:08:02 -0700 (PDT) Received: from mail-lb0-f177.google.com (mail-lb0-f177.google.com. [209.85.217.177]) by mx.google.com with ESMTPS id t9si7820774lal.77.2015.03.16.04.08.02 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 16 Mar 2015 04:08:02 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.177 as permitted sender) client-ip=209.85.217.177; Received: by lbcds1 with SMTP id ds1so28755433lbc.3 for ; Mon, 16 Mar 2015 04:08:01 -0700 (PDT) X-Received: by 10.112.8.101 with SMTP id q5mr49061032lba.19.1426504081916; Mon, 16 Mar 2015 04:08:01 -0700 (PDT) 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 h5csp2503828lbj; Mon, 16 Mar 2015 04:08:01 -0700 (PDT) X-Received: by 10.55.23.161 with SMTP id 33mr75425385qkx.62.1426504077338; Mon, 16 Mar 2015 04:07:57 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id 6si9544841qky.111.2015.03.16.04.07.56 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 16 Mar 2015 04:07:57 -0700 (PDT) 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]:48403 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YXSsG-0008Vo-AF for patch@linaro.org; Mon, 16 Mar 2015 07:07:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50921) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YXSr7-0007Nx-Oz for qemu-devel@nongnu.org; Mon, 16 Mar 2015 07:06:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YXSr1-00078r-2h for qemu-devel@nongnu.org; Mon, 16 Mar 2015 07:06:45 -0400 Received: from static.88-198-71-155.clients.your-server.de ([88.198.71.155]:33322 helo=socrates.bennee.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YXSr0-00078G-RX for qemu-devel@nongnu.org; Mon, 16 Mar 2015 07:06:38 -0400 Received: from localhost ([127.0.0.1] helo=zen.linaroharston) by socrates.bennee.com with esmtp (Exim 4.80) (envelope-from ) id 1YXTtW-0000VG-QI; Mon, 16 Mar 2015 13:13:19 +0100 From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Mon, 16 Mar 2015 11:01:52 +0000 Message-Id: <1426503716-13931-2-git-send-email-alex.bennee@linaro.org> X-Mailer: git-send-email 2.3.2 In-Reply-To: <1426503716-13931-1-git-send-email-alex.bennee@linaro.org> References: <1426503716-13931-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, Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , kvmarm@lists.cs.columbia.edu, christoffer.dall@linaro.org Subject: [Qemu-devel] [PATCH v4 1/5] 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.177 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 --- v2 - make mpstate field runtime dependant (kvm_enabled()) - drop initial KVM_CAP_MP_STATE requirement - re-use cpu_powered instead of new field v4 - s/HALTED/STOPPED/ - move code from machine.c to kvm. diff --git a/target-arm/kvm.c b/target-arm/kvm.c index 72c1fa1..a74832c 100644 --- a/target-arm/kvm.c +++ b/target-arm/kvm.c @@ -458,6 +458,46 @@ void kvm_arm_reset_vcpu(ARMCPU *cpu) } } +/* + * Update KVM's MP_STATE based on what QEMU thinks it is + */ +int kvm_arm_sync_mpstate_to_kvm(ARMCPU *cpu) +{ + 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_STOPPED : 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; + } + } + + return 0; +} + +/* + * Sync the KVM MP_STATE into QEMU + */ +int kvm_arm_sync_mpstate_to_qemu(ARMCPU *cpu) +{ + 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_STOPPED); + } + + return 0; +} + void kvm_arch_pre_run(CPUState *cs, struct kvm_run *run) { } diff --git a/target-arm/kvm32.c b/target-arm/kvm32.c index 94030d1..49b6bab 100644 --- a/target-arm/kvm32.c +++ b/target-arm/kvm32.c @@ -356,6 +356,8 @@ int kvm_arch_put_registers(CPUState *cs, int level) return EINVAL; } + kvm_arm_sync_mpstate_to_kvm(cpu); + return ret; } @@ -427,5 +429,7 @@ int kvm_arch_get_registers(CPUState *cs) */ write_list_to_cpustate(cpu); + kvm_arm_sync_mpstate_to_qemu(cpu); + return 0; } diff --git a/target-arm/kvm64.c b/target-arm/kvm64.c index 8cf3a62..fed03f2 100644 --- a/target-arm/kvm64.c +++ b/target-arm/kvm64.c @@ -211,6 +211,8 @@ int kvm_arch_put_registers(CPUState *cs, int level) return EINVAL; } + kvm_arm_sync_mpstate_to_kvm(cpu); + /* TODO: * FP state */ @@ -310,6 +312,8 @@ int kvm_arch_get_registers(CPUState *cs) */ write_list_to_cpustate(cpu); + kvm_arm_sync_mpstate_to_qemu(cpu); + /* TODO: other registers */ return ret; } diff --git a/target-arm/kvm_arm.h b/target-arm/kvm_arm.h index 455dea3..7b75758 100644 --- a/target-arm/kvm_arm.h +++ b/target-arm/kvm_arm.h @@ -162,6 +162,24 @@ typedef struct ARMHostCPUClass { */ bool kvm_arm_get_host_cpu_features(ARMHostCPUClass *ahcc); + +/** + * kvm_arm_sync_mpstate_to_kvm + * @cpu: ARMCPU + * + * If supported set the KVM MP_STATE based on QEMUs migration data. + */ +int kvm_arm_sync_mpstate_to_kvm(ARMCPU *cpu); + +/** + * kvm_arm_sync_mpstate_to_qemu + * @cpu: ARMCPU + * + * If supported get the MP_STATE from KVM and store in QEMUs migration + * data. + */ +int kvm_arm_sync_mpstate_to_qemu(ARMCPU *cpu); + #endif #endif