From patchwork Tue Jan 27 23:58:37 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Bellows X-Patchwork-Id: 43867 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f198.google.com (mail-lb0-f198.google.com [209.85.217.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 11B8623FFF for ; Tue, 27 Jan 2015 23:59:59 +0000 (UTC) Received: by mail-lb0-f198.google.com with SMTP id l4sf9255414lbv.1 for ; Tue, 27 Jan 2015 15:59:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:date :message-id:in-reply-to:references: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=1GXtsvznQsofArJhvx1iMPA1oMWGmi5zbWjEYn/pMoc=; b=eP1RO470XiSRRIABOrJAvCRZwXm/jqfbB7bT/TFpB6e4Qut1Rxa61sxlzIg71qH+FK 2edXMngsfGleud88qnbEFQkCUHQg2mP25QEIXfUoQRmIbGVlIMGlHigHXRFJnQ/PMnUR jnaFcQU0iskNvH9t1O0lYctxUMrV2iygJqE9p5JeaHKxqGcHv8UIGhdV4hkMSn9wBYPS y4l70qfEMUsZtpS2ZxenXHKC6IjOqRwnBQU/Lr6hy/c/zH31EOgEgwRI1UE4eFzw9+re 52G5QAMnpnTf4vZuSAYX0nWqa7eu6NOlcy7jL22IeNawqfRJIk5dEjwn8cnc/N8KDmKo CEyA== X-Gm-Message-State: ALoCoQlULcX2NzyacxFGh5+CoOF9h8mOyalofau39tna90PQ51YkUAe0A6c+PH+63JOR1Ep5CTpi X-Received: by 10.113.5.170 with SMTP id cn10mr596250lbd.21.1422403197784; Tue, 27 Jan 2015 15:59:57 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.22.40 with SMTP id a8ls89926laf.66.gmail; Tue, 27 Jan 2015 15:59:57 -0800 (PST) X-Received: by 10.152.3.195 with SMTP id e3mr4868210lae.8.1422403197522; Tue, 27 Jan 2015 15:59:57 -0800 (PST) Received: from mail-la0-f46.google.com (mail-la0-f46.google.com. [209.85.215.46]) by mx.google.com with ESMTPS id ec7si2731195lbc.32.2015.01.27.15.59.57 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 27 Jan 2015 15:59:57 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.46 as permitted sender) client-ip=209.85.215.46; Received: by mail-la0-f46.google.com with SMTP id s18so16237371lam.5 for ; Tue, 27 Jan 2015 15:59:57 -0800 (PST) X-Received: by 10.152.203.230 with SMTP id kt6mr4709199lac.38.1422403197263; Tue, 27 Jan 2015 15:59:57 -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 h5csp1261191lbj; Tue, 27 Jan 2015 15:59:56 -0800 (PST) X-Received: by 10.140.44.134 with SMTP id g6mr6847929qga.85.1422403195961; Tue, 27 Jan 2015 15:59:55 -0800 (PST) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id m8si3273765qat.30.2015.01.27.15.59.55 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 27 Jan 2015 15:59:55 -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]:50580 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YGG31-00087W-6A for patch@linaro.org; Tue, 27 Jan 2015 18:59:55 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35317) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YGG25-0006s9-Fx for qemu-devel@nongnu.org; Tue, 27 Jan 2015 18:59:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YGG22-0005Uh-6N for qemu-devel@nongnu.org; Tue, 27 Jan 2015 18:58:57 -0500 Received: from mail-pa0-f43.google.com ([209.85.220.43]:49494) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YGG22-0005UX-1w for qemu-devel@nongnu.org; Tue, 27 Jan 2015 18:58:54 -0500 Received: by mail-pa0-f43.google.com with SMTP id eu11so21661214pac.2 for ; Tue, 27 Jan 2015 15:58:53 -0800 (PST) X-Received: by 10.66.160.66 with SMTP id xi2mr185357pab.3.1422403133345; Tue, 27 Jan 2015 15:58:53 -0800 (PST) Received: from gbellows-linaro.qualcomm.com (rrcs-67-52-129-61.west.biz.rr.com. [67.52.129.61]) by mx.google.com with ESMTPSA id nu5sm2679909pbb.79.2015.01.27.15.58.51 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 27 Jan 2015 15:58:52 -0800 (PST) From: Greg Bellows To: qemu-devel@nongnu.org, peter.maydell@linaro.org, christoffer.dall@linaro.org, alex.bennee@linaro.org Date: Tue, 27 Jan 2015 17:58:37 -0600 Message-Id: <1422403117-16921-5-git-send-email-greg.bellows@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1422403117-16921-1-git-send-email-greg.bellows@linaro.org> References: <1422403117-16921-1-git-send-email-greg.bellows@linaro.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.220.43 Cc: Greg Bellows Subject: [Qemu-devel] [PATCH v3 4/4] target-arm: Add AArch32 guest support to KVM64 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: greg.bellows@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.46 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 Add 32-bit to/from 64-bit register synchronization on register gets and puts. Set EL1_32BIT feature flag passed to KVM Signed-off-by: Greg Bellows --- v2 -> v3 - Conditionalize sync of 32-bit and 64-bit registers --- target-arm/kvm64.c | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/target-arm/kvm64.c b/target-arm/kvm64.c index ba16821..924b423 100644 --- a/target-arm/kvm64.c +++ b/target-arm/kvm64.c @@ -81,8 +81,7 @@ int kvm_arch_init_vcpu(CPUState *cs) int ret; ARMCPU *cpu = ARM_CPU(cs); - if (cpu->kvm_target == QEMU_KVM_ARM_TARGET_NONE || - !arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) { + if (cpu->kvm_target == QEMU_KVM_ARM_TARGET_NONE) { fprintf(stderr, "KVM is not supported for this guest CPU type\n"); return -EINVAL; } @@ -96,6 +95,9 @@ int kvm_arch_init_vcpu(CPUState *cs) cpu->psci_version = 2; cpu->kvm_init_features[0] |= 1 << KVM_ARM_VCPU_PSCI_0_2; } + if (!arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) { + cpu->kvm_init_features[0] |= 1 << KVM_ARM_VCPU_EL1_32BIT; + } /* Do KVM_ARM_VCPU_INIT ioctl */ ret = kvm_arm_vcpu_init(cs); @@ -133,6 +135,13 @@ int kvm_arch_put_registers(CPUState *cs, int level) ARMCPU *cpu = ARM_CPU(cs); CPUARMState *env = &cpu->env; + /* If we are in AArch32 mode then we need to sync the AArch64 regs with the + * AArch32 regs before pushing them out 64-bit KVM. + */ + if (!is_a64(env)) { + aarch64_sync_32_to_64(env); + } + for (i = 0; i < 31; i++) { reg.id = AARCH64_CORE_REG(regs.regs[i]); reg.addr = (uintptr_t) &env->xregs[i]; @@ -162,7 +171,11 @@ int kvm_arch_put_registers(CPUState *cs, int level) } /* Note that KVM thinks pstate is 64 bit but we use a uint32_t */ - val = pstate_read(env); + if (is_a64(env)) { + val = pstate_read(env); + } else { + val = cpsr_read(env); + } reg.id = AARCH64_CORE_REG(regs.pstate); reg.addr = (uintptr_t) &val; ret = kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, ®); @@ -219,6 +232,13 @@ int kvm_arch_get_registers(CPUState *cs) } } + /* If we are in AArch32 mode then we need to sync the AArch32 regs with the + * incoming AArch64 regs received from 64-bit KVM. + */ + if (!is_a64(env)) { + aarch64_sync_64_to_32(env); + } + reg.id = AARCH64_CORE_REG(regs.sp); reg.addr = (uintptr_t) &env->sp_el[0]; ret = kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, ®); @@ -239,7 +259,12 @@ int kvm_arch_get_registers(CPUState *cs) if (ret) { return ret; } - pstate_write(env, val); + if (is_a64(env)) { + pstate_write(env, val); + } else { + env->uncached_cpsr = val & CPSR_M; + cpsr_write(env, val, 0xffffffff); + } /* KVM puts SP_EL0 in regs.sp and SP_EL1 in regs.sp_el1. On the * QEMU side we keep the current SP in xregs[31] as well.