From patchwork Wed Apr 1 15:39:13 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: 46630 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f199.google.com (mail-lb0-f199.google.com [209.85.217.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id CA1F62159A for ; Wed, 1 Apr 2015 15:40:38 +0000 (UTC) Received: by lbdc10 with SMTP id c10sf11393365lbd.0 for ; Wed, 01 Apr 2015 08:40:37 -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=SEX2S/Kg+tiVfcJ255PBdGajpWzcumPjk+O5E5jTmfI=; b=gPS7r53PWZPj7gWVIp5jGZS9xjNWNcUw+prMgv7r4kbEb207zdhXVeoZ2jX+ULbauX N7SxKsesFw4iehQ8Y/wjT06KteNiiPO/9mmJ1Tj88fAtIa9G2fNZTIb47zaPWNqAA/D4 uWqGkGHqpJoCEOOQEGl0IAFag1Pd5CIxYLdQLs3t9WFaSmAMvsqgh4yRvDTF+y0R33Ps /V+7RYveHERT03AyXg8WJj762e0YJHZGbv6fUjVzlOucT5i5cEPfV2jAL5z8CAvyTQol 9fm6UX9wklCE8Qg5mom8vpNIWZmtYcQFov2MkdKtKnbASXtnuqDYNO51qE8mcVqkMNaX vuDw== X-Gm-Message-State: ALoCoQmfHgbamrWtMtny4XLhP5U39sQDKZQwaAUgofJK/EcqUPjMHJMpr9jHKzVs8FFiWbDiW+TY X-Received: by 10.152.163.99 with SMTP id yh3mr9698588lab.8.1427902837807; Wed, 01 Apr 2015 08:40:37 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.21.199 with SMTP id x7ls97132lae.0.gmail; Wed, 01 Apr 2015 08:40:37 -0700 (PDT) X-Received: by 10.152.28.233 with SMTP id e9mr36338572lah.3.1427902837601; Wed, 01 Apr 2015 08:40:37 -0700 (PDT) Received: from mail-la0-f52.google.com (mail-la0-f52.google.com. [209.85.215.52]) by mx.google.com with ESMTPS id yl9si1896153lbb.93.2015.04.01.08.40.37 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Apr 2015 08:40:37 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.52 as permitted sender) client-ip=209.85.215.52; Received: by labe2 with SMTP id e2so39802710lab.3 for ; Wed, 01 Apr 2015 08:40:37 -0700 (PDT) X-Received: by 10.112.212.106 with SMTP id nj10mr36253973lbc.36.1427902837506; Wed, 01 Apr 2015 08:40:37 -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.57.201 with SMTP id k9csp745049lbq; Wed, 1 Apr 2015 08:40:36 -0700 (PDT) X-Received: by 10.140.151.8 with SMTP id 8mr57353355qhx.65.1427902835641; Wed, 01 Apr 2015 08:40:35 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id m20si2153387qhb.107.2015.04.01.08.40.35 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 01 Apr 2015 08:40:35 -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]:53434 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YdKks-0003dV-FU for patch@linaro.org; Wed, 01 Apr 2015 11:40:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54126) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YdKjl-0002Sx-3w for qemu-devel@nongnu.org; Wed, 01 Apr 2015 11:39:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YdKje-0007kr-50 for qemu-devel@nongnu.org; Wed, 01 Apr 2015 11:39:25 -0400 Received: from static.88-198-71-155.clients.your-server.de ([88.198.71.155]:36086 helo=socrates.bennee.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YdKjd-0007km-Uo for qemu-devel@nongnu.org; Wed, 01 Apr 2015 11:39:18 -0400 Received: from localhost ([127.0.0.1] helo=zen.linaroharston) by socrates.bennee.com with esmtp (Exim 4.80) (envelope-from ) id 1YdLq3-0006ck-KC; Wed, 01 Apr 2015 18:49:59 +0200 From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Wed, 1 Apr 2015 16:39:13 +0100 Message-Id: <1427902756-30567-3-git-send-email-alex.bennee@linaro.org> X-Mailer: git-send-email 2.3.4 In-Reply-To: <1427902756-30567-1-git-send-email-alex.bennee@linaro.org> References: <1427902756-30567-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: Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , "open list:Overall" , christoffer.dall@linaro.org, greg.bellows@linaro.org Subject: [Qemu-devel] [PATCH v6 2/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.215.52 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. v6 - cache KVM_CAP_MP_STATE ioctl at start-up - reword commentary, add some apostrophes - invert errno for strerror diff --git a/target-arm/kvm.c b/target-arm/kvm.c index 72c1fa1..17371ca 100644 --- a/target-arm/kvm.c +++ b/target-arm/kvm.c @@ -28,6 +28,8 @@ const KVMCapabilityInfo kvm_arch_required_capabilities[] = { KVM_CAP_LAST_INFO }; +static bool cap_has_mp_state = false; + int kvm_arm_vcpu_init(CPUState *cs) { ARMCPU *cpu = ARM_CPU(cs); @@ -157,6 +159,8 @@ int kvm_arch_init(MachineState *ms, KVMState *s) */ kvm_async_interrupts_allowed = true; + cap_has_mp_state = kvm_check_extension(s, KVM_CAP_MP_STATE); + type_register_static(&host_arm_cpu_type_info); return 0; @@ -458,6 +462,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 (cap_has_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 (cap_has_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..5abd591 100644 --- a/target-arm/kvm_arm.h +++ b/target-arm/kvm_arm.h @@ -162,6 +162,23 @@ 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 QEMU's model. + */ +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 QEMU's model. + */ +int kvm_arm_sync_mpstate_to_qemu(ARMCPU *cpu); + #endif #endif