From patchwork Fri Jul 19 21:03:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 169277 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp4325315ilk; Fri, 19 Jul 2019 14:06:06 -0700 (PDT) X-Google-Smtp-Source: APXvYqw+1tv0D86Rp/3/tcmgY/qbadoChvIv0l+rL20ml6Wk/s1zRttuG2Zuvr6sW1GDHB5+BxfL X-Received: by 2002:a17:906:90cf:: with SMTP id v15mr41457988ejw.77.1563570366566; Fri, 19 Jul 2019 14:06:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563570366; cv=none; d=google.com; s=arc-20160816; b=NrlOmgAYshbLRHT+PgcOWm87jZnH9YS8RvsMcK9rIB+Y+r5fIemxfx5V6ZPQakjdkq UzicJ8AbvV2D8iDtamB46sKvHm+Z20f2rBCgMcD4Nsju02wlYxdBovsw+3VajOYYx4fB W7Eb70XboVtF880uofHh8ht9TBIdmlyPMlNaBJt6Bcsrm/Xojr0xWavFPZXND5RdfE8M PTHk09UaU5Ihy+3fzjU9zPpyM9oKzdH/1+/rK2fPsrehDp5p9oDk9uoiZdpb3XAOjgIx kCN6fFtzHzaBC4UMRx/PvTbKpscJ6sU3U12yWjkm+I1KWh4egiZ2gjOnUkvVEwalWn+4 s5DA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=PI1YJc5YjWIF6+6p2IKRfVxeRzTCt2ZI5L41svkHvyA=; b=Kw41ONcu6mnBq3ojbQCv9cGGtC+SZcxSTX0+QwvCQ3BLnHYfZ+jf4svVOYPVXJvYey RySMHQKMtkFKGhsjgu7dNf7aZbo5jCKktyqjarEpUjzQG4aIGXwlE1O2noh8P5mx84hW O1vgYO181vHEoKjSfBD7niltTOn2PJo5Xk9ZepLbqDzMKhvDk1Nytg87w+p5b5DYcyEZ UOJsQECKSd+Yz/EtpQBkY/D661vl2bDcwymDosSLdvgl1Z58/s1Do397WU1YSFdK5xM3 YCQp4Xs2+GZYCb9My/vAPZV4JXZKb3PTviP5bWoLou0jIbjQiYbOSLaRNvlO5vPjjwmm z+Qw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=fSeP84tg; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id k6si426020edd.325.2019.07.19.14.06.06 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 19 Jul 2019 14:06:06 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=fSeP84tg; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:48210 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hoa4r-0004yp-53 for patch@linaro.org; Fri, 19 Jul 2019 17:06:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55101) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hoa3V-0007qF-Lo for qemu-devel@nongnu.org; Fri, 19 Jul 2019 17:04:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hoa3R-0005Vq-Ab for qemu-devel@nongnu.org; Fri, 19 Jul 2019 17:04:40 -0400 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]:38346) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hoa3R-0005Bo-2u for qemu-devel@nongnu.org; Fri, 19 Jul 2019 17:04:37 -0400 Received: by mail-pf1-x441.google.com with SMTP id y15so14687201pfn.5 for ; Fri, 19 Jul 2019 14:03:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=PI1YJc5YjWIF6+6p2IKRfVxeRzTCt2ZI5L41svkHvyA=; b=fSeP84tgg7Nt0wuBvWuN/KQpTt+NTz1zkjNVBd1d3/FCcB8i9G9LUv5hKmDzTGf+/l M/Ql/nTcf+ezfkbd0nRUkAJKUv7I79M1qIBCiuEYuleNkay0p0g8NrEq6c8zTObCAYxC 9OO0YS+Bo1g4/fr7yinlILJbiM7m78LUc5JpV3WYRixuVke8zZ8rdQPQg/1tiH5oe+AI 8RGrudM75eeY5q/s4UekghhcRqIwMHqXxNdWAQf6oMM3dZxWqYEvGRanhkyfstnRePTo +F0AC23PirmkxNulrOUq6xnlxn8Om/mex1eHfiofKc6LCbBmiaPtUhTR7ciqxZqjW4xS a3rg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=PI1YJc5YjWIF6+6p2IKRfVxeRzTCt2ZI5L41svkHvyA=; b=E86ariTWn1uVBbe0coIJlslHXDvEsdJKGwlvwEfgIupN3zyP2xSgBO+CJwoahPkIX5 8Ln9HuQqTLbJcJBQHxobYQF6pK4U34qqn/dAm11ucTuFOEFBmygfvGWFbHb4ZNjVZs19 vtL2WxUa7NBbg1rd/Fw4ZBgOdoqMztCOSoQ290YpTMWHyv8VrsN26klLR2AIaoM8ZHpO 3jjR0Qvbmq9qZwEDAhRSd1bJ05/WnClQSEV7XdLyaVu0218H4WoP+5SS/X2OHqRXmTAy X1FyD3vA0grWfswmxjEqGRSMFN/Tr9LCUj6HcZmSa+6+MRzqTQXaPYEdZrK+TO8f0qVP jWHA== X-Gm-Message-State: APjAAAW8i6VRxdABUQDLhURSAT4W5/vC1LzbQi+R4PVNqhoPPYnAwvGZ foO9QGn7tRFppMSH0muL6H/DwFowFPU= X-Received: by 2002:a63:ec03:: with SMTP id j3mr29545532pgh.325.1563570229038; Fri, 19 Jul 2019 14:03:49 -0700 (PDT) Received: from localhost.localdomain (97-126-117-207.tukw.qwest.net. [97.126.117.207]) by smtp.gmail.com with ESMTPSA id i6sm32724751pgi.40.2019.07.19.14.03.47 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 19 Jul 2019 14:03:48 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 19 Jul 2019 14:03:19 -0700 Message-Id: <20190719210326.15466-18-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190719210326.15466-1-richard.henderson@linaro.org> References: <20190719210326.15466-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::441 Subject: [Qemu-devel] [PATCH for-4.2 17/24] target/arm: Update arm_mmu_idx for VHE X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, beata.michalska@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This covers initial generation in arm_mmu_idx, and reconstruction in core_to_arm_mmu_idx. As a conseqeuence, we also need a bit in TBFLAGS in order to make the latter reliable. Signed-off-by: Richard Henderson --- target/arm/cpu.h | 2 ++ target/arm/helper.c | 42 +++++++++++++++++++++++++++++++----------- 2 files changed, 33 insertions(+), 11 deletions(-) -- 2.17.1 Reviewed-by: Alex Bennée diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 4b537c4613..7310adfd9b 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -3158,6 +3158,8 @@ FIELD(TBFLAG_ANY, PSTATE_SS, 26, 1) /* Target EL if we take a floating-point-disabled exception */ FIELD(TBFLAG_ANY, FPEXC_EL, 24, 2) FIELD(TBFLAG_ANY, BE_DATA, 23, 1) +/* For A profile only, if EL2 is AA64 and HCR_EL2.E2H is set. */ +FIELD(TBFLAG_ANY, E2H, 22, 1) /* Bit usage when in AArch32 state: */ FIELD(TBFLAG_A32, THUMB, 0, 1) diff --git a/target/arm/helper.c b/target/arm/helper.c index 2d5658f9e3..54c328b844 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -11250,21 +11250,29 @@ int fp_exception_el(CPUARMState *env, int cur_el) ARMMMUIdx core_to_arm_mmu_idx(CPUARMState *env, int mmu_idx) { + bool e2h; + if (arm_feature(env, ARM_FEATURE_M)) { return mmu_idx | ARM_MMU_IDX_M; } mmu_idx |= ARM_MMU_IDX_A; + if (mmu_idx & ARM_MMU_IDX_S) { + return mmu_idx; + } + + e2h = (env->cp15.hcr_el2 & HCR_E2H) != 0; + if (!arm_el_is_aa64(env, 2)) { + e2h = false; + } + switch (mmu_idx) { case ARMMMUIdx_E0: - return ARMMMUIdx_EL10_0; + return e2h ? ARMMMUIdx_EL20_0 : ARMMMUIdx_EL10_0; case ARMMMUIdx_E1: return ARMMMUIdx_EL10_1; case ARMMMUIdx_E2: - case ARMMMUIdx_SE0: - case ARMMMUIdx_SE1: - case ARMMMUIdx_SE3: - return mmu_idx; + return e2h ? ARMMMUIdx_EL20_2 : ARMMMUIdx_E2; default: g_assert_not_reached(); } @@ -11292,24 +11300,28 @@ ARMMMUIdx arm_v7m_mmu_idx_for_secstate(CPUARMState *env, bool secstate) ARMMMUIdx arm_mmu_idx(CPUARMState *env) { + bool e2h, sec; int el; if (arm_feature(env, ARM_FEATURE_M)) { return arm_v7m_mmu_idx_for_secstate(env, env->v7m.secure); } + sec = arm_is_secure_below_el3(env); + e2h = (env->cp15.hcr_el2 & HCR_E2H) != 0; + if (!arm_el_is_aa64(env, 2)) { + e2h = false; + } + el = arm_current_el(env); switch (el) { case 0: - /* TODO: ARMv8.1-VHE */ + return sec ? ARMMMUIdx_SE0 : e2h ? ARMMMUIdx_EL20_0 : ARMMMUIdx_EL10_0; case 1: - return (arm_is_secure_below_el3(env) - ? ARMMMUIdx_SE0 + el - : ARMMMUIdx_EL10_0 + el); + return sec ? ARMMMUIdx_SE1 : ARMMMUIdx_EL10_1; case 2: - /* TODO: ARMv8.1-VHE */ /* TODO: ARMv8.4-SecEL2 */ - return ARMMMUIdx_E2; + return e2h ? ARMMMUIdx_EL20_2 : ARMMMUIdx_E2; case 3: return ARMMMUIdx_SE3; default: @@ -11421,6 +11433,14 @@ void cpu_get_tb_cpu_state(CPUARMState *env, target_ulong *pc, flags = FIELD_DP32(flags, TBFLAG_ANY, MMUIDX, arm_to_core_mmu_idx(mmu_idx)); + /* + * Include E2H in TBFLAGS so that core_to_arm_mmu_idx can + * reliably determine E1&0 vs E2&0 regimes. + */ + if (arm_el_is_aa64(env, 2) && (env->cp15.hcr_el2 & HCR_E2H)) { + flags = FIELD_DP32(flags, TBFLAG_ANY, E2H, 1); + } + /* The SS_ACTIVE and PSTATE_SS bits correspond to the state machine * states defined in the ARM ARM for software singlestep: * SS_ACTIVE PSTATE.SS State