From patchwork Mon Mar 16 11:01:55 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: 45828 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f69.google.com (mail-la0-f69.google.com [209.85.215.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 6A46821523 for ; Mon, 16 Mar 2015 11:09:51 +0000 (UTC) Received: by lams18 with SMTP id s18sf26174472lam.2 for ; Mon, 16 Mar 2015 04:09:50 -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=KapVzpKG7/tXzgluq2f2E3CmPxdp4AQVTkW+V6tc/rI=; b=LeQO/Y5iVwVwx4xonZQPXUrk5pLpV36bRZ+2V/ID2FWnDryL+bBUO2loYSpAKZCdsj qRpVN5mbZGKSeFowhXCDthtbrTCGjXdhcQfLu9wHsqar5cqMrKuHagpBGQa+SC5NcNi2 Zv3YY9/8Dyeu1WFDND/cnDY+/AGUR8WZ4eCdc+XMy8kl9QV+TNocRhX7L9dO80p+Cp+0 sduisMOklCBxTvYmd0U6EnxiPMhgig5EJg1iCg58mbq+G+8pbbCf4kTfhfw+uYXmRn0B 6s/TYOIZ1uavtdy+w6oD9pfWTEyecOQT4TxNvfOi2YyR2y8/YDK6BHoVbaj0sM+421F8 PA5w== X-Gm-Message-State: ALoCoQkYzzvSfaffS7LArcLZqMx1tcNTkrmmYEhTdzN8b6jTpLjZkGvbtcwTi+An4kKeYT9/3DKS X-Received: by 10.180.90.169 with SMTP id bx9mr6320303wib.6.1426504190395; Mon, 16 Mar 2015 04:09:50 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.37.227 with SMTP id b3ls564181lak.58.gmail; Mon, 16 Mar 2015 04:09:50 -0700 (PDT) X-Received: by 10.112.157.100 with SMTP id wl4mr55106314lbb.108.1426504190070; Mon, 16 Mar 2015 04:09:50 -0700 (PDT) Received: from mail-la0-f48.google.com (mail-la0-f48.google.com. [209.85.215.48]) by mx.google.com with ESMTPS id da11si7820542lad.115.2015.03.16.04.09.50 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 16 Mar 2015 04:09:50 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.48 as permitted sender) client-ip=209.85.215.48; Received: by lagg8 with SMTP id g8so36536342lag.1 for ; Mon, 16 Mar 2015 04:09:50 -0700 (PDT) X-Received: by 10.152.116.65 with SMTP id ju1mr34983990lab.32.1426504189976; Mon, 16 Mar 2015 04:09:49 -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 h5csp2504833lbj; Mon, 16 Mar 2015 04:09:49 -0700 (PDT) X-Received: by 10.140.81.242 with SMTP id f105mr73659315qgd.33.1426504188671; Mon, 16 Mar 2015 04:09:48 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id 191si9532596qhw.120.2015.03.16.04.09.48 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 16 Mar 2015 04:09:48 -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]:48419 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YXSu3-0003IB-Pm for patch@linaro.org; Mon, 16 Mar 2015 07:09:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50930) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YXSr8-0007Nz-65 for qemu-devel@nongnu.org; Mon, 16 Mar 2015 07:06:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YXSr1-00079c-Fs for qemu-devel@nongnu.org; Mon, 16 Mar 2015 07:06:46 -0400 Received: from static.88-198-71-155.clients.your-server.de ([88.198.71.155]:33330 helo=socrates.bennee.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YXSr1-00078o-8z for qemu-devel@nongnu.org; Mon, 16 Mar 2015 07:06:39 -0400 Received: from localhost ([127.0.0.1] helo=zen.linaroharston) by socrates.bennee.com with esmtp (Exim 4.80) (envelope-from ) id 1YXTtY-0000VG-EW; Mon, 16 Mar 2015 13:13:20 +0100 From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Mon, 16 Mar 2015 11:01:55 +0000 Message-Id: <1426503716-13931-5-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, =?UTF-8?q?Alex=20Benn=C3=A9e?= , kvmarm@lists.cs.columbia.edu, christoffer.dall@linaro.org Subject: [Qemu-devel] [PATCH v4 4/5] target-arm: kvm64 fix save/restore of SPSR regs 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.48 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 From: Christoffer Dall The current code was negatively indexing the cpu state array and not synchronizing banked spsr register state with the current mode's spsr state, causing occasional failures with migration. Some munging is done to take care of the aarch64 mapping and also to ensure the most current value of the spsr is updated to the banked registers (relevant for KVM<->TCG migration). Signed-off-by: Christoffer Dall Signed-off-by: Alex BennĂ©e --- v2 (ajb) - minor tweaks and clarifications v3 - Use the correct bank index function for setting/getting env->spsr - only deal with spsrs in elevated exception levels v4 - try and make commentary clearer - ensure env->banked_spsr[0] = env->spsr before we sync diff --git a/target-arm/kvm64.c b/target-arm/kvm64.c index 8fd0c8d..7ddb1b1 100644 --- a/target-arm/kvm64.c +++ b/target-arm/kvm64.c @@ -140,6 +140,7 @@ int kvm_arch_put_registers(CPUState *cs, int level) uint64_t val; int i; int ret; + unsigned int el; ARMCPU *cpu = ARM_CPU(cs); CPUARMState *env = &cpu->env; @@ -206,9 +207,29 @@ int kvm_arch_put_registers(CPUState *cs, int level) return ret; } + /* Saved Program State Registers + * + * Before we restore from the banked_spsr[] array we need to + * ensure that any modifications to env->spsr are correctly + * reflected and map aarch64 exception levels if required. + */ + el = arm_current_el(env); + if (el > 0) { + if (is_a64(env)) { + g_assert(el == 1); + env->banked_spsr[0] = env->spsr; + /* QEMUs AARCH64 EL1 SPSR is in bank 0, so map it to + * KVM_SPSR_SVC for syncing to KVM */ + env->banked_spsr[1] = env->banked_spsr[0]; + } else { + i = bank_number(env->uncached_cpsr & CPSR_M); + env->banked_spsr[i] = env->spsr; + } + } + for (i = 0; i < KVM_NR_SPSR; i++) { reg.id = AARCH64_CORE_REG(spsr[i]); - reg.addr = (uintptr_t) &env->banked_spsr[i - 1]; + reg.addr = (uintptr_t) &env->banked_spsr[i+1]; ret = kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, ®); if (ret) { return ret; @@ -254,6 +275,7 @@ int kvm_arch_get_registers(CPUState *cs) struct kvm_one_reg reg; uint64_t val; uint32_t fpr; + unsigned int el; int i; int ret; @@ -326,15 +348,34 @@ int kvm_arch_get_registers(CPUState *cs) return ret; } + /* Fetch the SPSR registers + * + * KVM has an array of state indexed for all the possible aarch32 + * privilege levels. These map onto QEMUs aarch32 banks 1 - 4. + */ for (i = 0; i < KVM_NR_SPSR; i++) { reg.id = AARCH64_CORE_REG(spsr[i]); - reg.addr = (uintptr_t) &env->banked_spsr[i - 1]; + reg.addr = (uintptr_t) &env->banked_spsr[i+1]; ret = kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, ®); if (ret) { return ret; } } + el = arm_current_el(env); + if (el > 0) { + if (is_a64(env)) { + g_assert(el == 1); + /* KVM_SPSR_SVC holds the AARCH64 EL1 SPSR which QEMU + * keeps in bank 0 so copy it across. */ + env->banked_spsr[0] = env->banked_spsr[1]; + i = aarch64_banked_spsr_index(el); + } else { + i = bank_number(env->uncached_cpsr & CPSR_M); + } + env->spsr = env->banked_spsr[i]; + } + /* Advanced SIMD and FP registers */ for (i = 0; i < 32; i++) { reg.id = AARCH64_SIMD_CORE_REG(fp_regs.vregs[i]);