From patchwork Thu Feb 12 10:29:34 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Bellows X-Patchwork-Id: 439152 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 201E514017B for ; Thu, 12 Feb 2015 21:32:11 +1100 (AEDT) Received: from localhost ([::1]:49476 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YLr45-00041X-Ad for incoming@patchwork.ozlabs.org; Thu, 12 Feb 2015 05:32:09 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48354) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YLr26-0000a3-JB for qemu-devel@nongnu.org; Thu, 12 Feb 2015 05:30:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YLr22-0007NP-6L for qemu-devel@nongnu.org; Thu, 12 Feb 2015 05:30:06 -0500 Received: from mail-ie0-f174.google.com ([209.85.223.174]:34875) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YLr22-0007Kw-2U for qemu-devel@nongnu.org; Thu, 12 Feb 2015 05:30:02 -0500 Received: by iecrl12 with SMTP id rl12so8375772iec.2 for ; Thu, 12 Feb 2015 02:30:01 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=imIw+MbgS4MVRsSuiVcwdUBSyIq2/70VEkS8ttgHu5o=; b=d6TLCNn0UaylKXu+YRgn1k+r/WDiIQUoKSd23801xZCY3x/EqsGEKyjBHSLvXACXKr ulASJ7EyuBv81dCc14dlCUQs3NNubUAYubKj9zPmv+jk0caQ+COYWwfAl0WrpdhkARuw 2+Pmk1WrOR1PzddOlEjBouQlvJc4PwL9pDZLb1aWnjR3K3smF7uW1T5lC85YyU+uIKWC Nh9p1bcehsyW7iJZLqFR6fBFyqIRs8/hRWehQTzBv7mUgqJw4lLw04bbAxelDvFLiIPA Cj/mVRzOwwoIIEiAgVajv5IZUmbYH4lOBlMPItadmtkRiEkqQNoxHTRemVbV6YIfddEY sLNA== X-Gm-Message-State: ALoCoQlnpuy5PSSWIHrnXnGuAHgfDUdBu7I1nzm5we8RYtCQoqXgyjY4RSB0I7NUAiV1ISXVeiiP X-Received: by 10.50.66.170 with SMTP id g10mr2817196igt.49.1423737001677; Thu, 12 Feb 2015 02:30:01 -0800 (PST) Received: from localhost.localdomain ([113.28.134.59]) by mx.google.com with ESMTPSA id p138sm2177027ioe.9.2015.02.12.02.29.59 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 12 Feb 2015 02:30:01 -0800 (PST) From: Greg Bellows To: qemu-devel@nongnu.org, peter.maydell@linaro.org, christoffer.dall@linaro.org, alex.bennee@linaro.org Date: Thu, 12 Feb 2015 18:29:34 +0800 Message-Id: <1423736974-14254-5-git-send-email-greg.bellows@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1423736974-14254-1-git-send-email-greg.bellows@linaro.org> References: <1423736974-14254-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.223.174 Cc: edgar.iglesias@gmail.com, Greg Bellows , a.spyridakis@virtualopensystems.com Subject: [Qemu-devel] [PATCH v8 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- v7 -> v8 - Fix dynamic cast object v4 -> v5 - Fix target check v3 -> v4 - Add check that to make sure KVM64 is only being used on AArch64 family of machines. - Relocate register sync to follow register fetches. - Refresh env->aarch64 prior to use. v2 -> v3 - Conditionalize sync of 32-bit and 64-bit registers --- target-arm/kvm64.c | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/target-arm/kvm64.c b/target-arm/kvm64.c index 033babf..8cf3a62 100644 --- a/target-arm/kvm64.c +++ b/target-arm/kvm64.c @@ -82,7 +82,7 @@ int kvm_arch_init_vcpu(CPUState *cs) ARMCPU *cpu = ARM_CPU(cs); if (cpu->kvm_target == QEMU_KVM_ARM_TARGET_NONE || - !arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) { + !object_dynamic_cast(OBJECT(cpu), TYPE_AARCH64_CPU)) { fprintf(stderr, "KVM is not supported for this guest CPU type\n"); return -EINVAL; } @@ -96,6 +96,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 +136,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 copy the AArch32 regs to the + * AArch64 registers before pushing them out to 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 +172,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, ®); @@ -242,7 +256,14 @@ int kvm_arch_get_registers(CPUState *cs) if (ret) { return ret; } - pstate_write(env, val); + + env->aarch64 = ((val & PSTATE_nRW) == 0); + 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. @@ -256,6 +277,15 @@ int kvm_arch_get_registers(CPUState *cs) return ret; } + /* If we are in AArch32 mode then we need to sync the AArch32 regs with the + * incoming AArch64 regs received from 64-bit KVM. + * We must perform this after all of the registers have been acquired from + * the kernel. + */ + if (!is_a64(env)) { + aarch64_sync_64_to_32(env); + } + reg.id = AARCH64_CORE_REG(elr_el1); reg.addr = (uintptr_t) &env->elr_el[1]; ret = kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, ®);