From patchwork Mon Dec 3 20:38:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 152747 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp7277762ljp; Mon, 3 Dec 2018 12:49:46 -0800 (PST) X-Google-Smtp-Source: AFSGD/X/iNbGXE1zGYeNI8gZ+yeoM1oxsO0CBEvZWp/ItCoXTJgisYIcxvyPouvuiNso1vhYckfW X-Received: by 2002:a37:1a25:: with SMTP id a37mr16243579qka.197.1543870186267; Mon, 03 Dec 2018 12:49:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543870186; cv=none; d=google.com; s=arc-20160816; b=J9Fw1e5nB4L70Rw8eGv4tfnj/fMXDs1eDf1vbSJAdU6gAjiBSYQ8ivMJU6NJ2qq25j vk/iSfdxYFAuQNaP5M0e+WoMbBN2SRwIN3ajDWDTOsucgpntSHRqpGnT1Dy/dMn02/eH 4ZecVWidMiB9AYrE2Y8rvvsqGw8Xl3ptQs/meN5ld/GqoC6pRO78oifeJFPC/pzbhBVl SKmpxLwNWhpJLzOidGkp4UiqED11C4MVeg+BZceGYeimjbKSZE5tlzuJXSR6OZP0w0sU l66bUFB+4SciVBe2p5vTdXpuWde9EtTksiB3kDEpfeBTDQpVatXeb1m+MCHu+qRRhpjj buBA== 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=6RfiLtXmRtrO+0NSs93kQ3AQ83RCZmslZZ/FXyGURgE=; b=k9ltC1fewIffWhBItXC86mkwDqPar1UznIkm01duPB04BQpy+3TGxEQsOJ0YBClnlI Q6GxjSXjXj7Wb+5a5S8znjf3GZyjaHhuye23lkfVhKRpAgldu+3lDfBeiDfkp6gwkFyV vN/fofPso4UNACKYVOPo3xx9zfyycaLRsSQotnMGx3lXo8gypLWSLEPLLKtXUjW3DD4k /F5M3LOb6XuGsR1hJ/1pK3h7CBjgAMfWd6mrdEWgyQZ1s1Yxo8zWkQKSwArB4TwS3nfy X5rXrqLxXXLGYCF6EjtDsQTxD+GkIjEWqkt5fcr/BRNpbaSFeF+VTiFbCS2sj4QKw7Bq Kp8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=dIKV4CGW; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id k3si4836624qvh.178.2018.12.03.12.49.46 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 03 Dec 2018 12:49:46 -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; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=dIKV4CGW; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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]:52413 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gTvA1-0000Mv-Nm for patch@linaro.org; Mon, 03 Dec 2018 15:49:45 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42367) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gTuzX-00063N-2p for qemu-devel@nongnu.org; Mon, 03 Dec 2018 15:38:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gTuzV-0005mn-OJ for qemu-devel@nongnu.org; Mon, 03 Dec 2018 15:38:55 -0500 Received: from mail-ot1-x342.google.com ([2607:f8b0:4864:20::342]:36332) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gTuzV-0005lT-Fg for qemu-devel@nongnu.org; Mon, 03 Dec 2018 15:38:53 -0500 Received: by mail-ot1-x342.google.com with SMTP id k98so12988772otk.3 for ; Mon, 03 Dec 2018 12:38:53 -0800 (PST) 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=6RfiLtXmRtrO+0NSs93kQ3AQ83RCZmslZZ/FXyGURgE=; b=dIKV4CGWmzcAzloLJ5WTuKaKhz4POEzSoF81vE3X8wk1kJHzVv8V5UvkARuFnjjYCO wYSQglVi6UeMMrjaUmnXZ01eT2zaAYB4V0bn0NBiTOqah/UgwY0rcydBL/ewoebCaRNi utTxuR1RPaI4/ArM5XfbNlo9QWeaTnStIw7r4= 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=6RfiLtXmRtrO+0NSs93kQ3AQ83RCZmslZZ/FXyGURgE=; b=VuU1FMT5P91gE7H4ITJdlwr+NsosE4K0bDTwnXWIDKxa98MiVOQlklhUcPvpnbGJCH iBBI3mS1IfYdUaOuRuDjpAIcV844orEZG/Ibw3TH5FApqAYK9DfTk+1Tl3RPFIXxiJh5 FKrdb4F1jys+49a5esMiRS0i508vaTdxOL4GhBJ4u9u5a8F4ygcYjyjhlIVRlkc1wpL1 c8YhduD7c74MoPG4cdADj36fDz5HL4S/gZESW2W7voXgdQtLwYZMCrPoYEFhI2ZekPoX LJP7zgJOxRipwmJVwLxhIQxpQwUP8h2C/xvMZw8cYlzGGcToT3UUpYSJA+v6jE3CN649 gakg== X-Gm-Message-State: AA+aEWbyEptCQzSpVqnSwnu0wUi55J+geMl39LLc/gTnXHqbMR1ASnBL QL1lMus27MOD6iR5LaeCbYRbviIKza8= X-Received: by 2002:a9d:491e:: with SMTP id e30mr11657639otf.131.1543869532493; Mon, 03 Dec 2018 12:38:52 -0800 (PST) Received: from cloudburst.twiddle.net (172.189-204-159.bestel.com.mx. [189.204.159.172]) by smtp.gmail.com with ESMTPSA id m133sm6330063oib.52.2018.12.03.12.38.50 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 03 Dec 2018 12:38:51 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 3 Dec 2018 14:38:35 -0600 Message-Id: <20181203203839.757-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20181203203839.757-1-richard.henderson@linaro.org> References: <20181203203839.757-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::342 Subject: [Qemu-devel] [PATCH v2 06/10] target/arm: Use arm_hcr_el2_eff more places X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Since arm_hcr_el2_eff includes a check against arm_is_secure_below_el3, we can often remove a nearby check against secure state. In some cases, sort the call to arm_hcr_el2_eff to the end of a short-circuit logical sequence. Signed-off-by: Richard Henderson --- target/arm/helper.c | 22 ++++++++++++---------- target/arm/op_helper.c | 14 ++++++-------- 2 files changed, 18 insertions(+), 18 deletions(-) -- 2.17.2 Reviewed-by: Peter Maydell diff --git a/target/arm/helper.c b/target/arm/helper.c index 5874c5a73f..b248dfcd39 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -448,7 +448,7 @@ static CPAccessResult access_tdosa(CPUARMState *env, const ARMCPRegInfo *ri, int el = arm_current_el(env); bool mdcr_el2_tdosa = (env->cp15.mdcr_el2 & MDCR_TDOSA) || (env->cp15.mdcr_el2 & MDCR_TDE) || - (env->cp15.hcr_el2 & HCR_TGE); + (arm_hcr_el2_eff(env) & HCR_TGE); if (el < 2 && mdcr_el2_tdosa && !arm_is_secure_below_el3(env)) { return CP_ACCESS_TRAP_EL2; @@ -468,7 +468,7 @@ static CPAccessResult access_tdra(CPUARMState *env, const ARMCPRegInfo *ri, int el = arm_current_el(env); bool mdcr_el2_tdra = (env->cp15.mdcr_el2 & MDCR_TDRA) || (env->cp15.mdcr_el2 & MDCR_TDE) || - (env->cp15.hcr_el2 & HCR_TGE); + (arm_hcr_el2_eff(env) & HCR_TGE); if (el < 2 && mdcr_el2_tdra && !arm_is_secure_below_el3(env)) { return CP_ACCESS_TRAP_EL2; @@ -488,7 +488,7 @@ static CPAccessResult access_tda(CPUARMState *env, const ARMCPRegInfo *ri, int el = arm_current_el(env); bool mdcr_el2_tda = (env->cp15.mdcr_el2 & MDCR_TDA) || (env->cp15.mdcr_el2 & MDCR_TDE) || - (env->cp15.hcr_el2 & HCR_TGE); + (arm_hcr_el2_eff(env) & HCR_TGE); if (el < 2 && mdcr_el2_tda && !arm_is_secure_below_el3(env)) { return CP_ACCESS_TRAP_EL2; @@ -4548,8 +4548,7 @@ int sve_exception_el(CPUARMState *env, int el) if (disabled) { /* route_to_el2 */ return (arm_feature(env, ARM_FEATURE_EL2) - && !arm_is_secure(env) - && (env->cp15.hcr_el2 & HCR_TGE) ? 2 : 1); + && (arm_hcr_el2_eff(env) & HCR_TGE) ? 2 : 1); } /* Check CPACR.FPEN. */ @@ -6194,9 +6193,8 @@ static int bad_mode_switch(CPUARMState *env, int mode, CPSRWriteType write_type) * and CPS are treated as illegal mode changes. */ if (write_type == CPSRWriteByInstr && - (env->cp15.hcr_el2 & HCR_TGE) && (env->uncached_cpsr & CPSR_M) == ARM_CPU_MODE_MON && - !arm_is_secure_below_el3(env)) { + (arm_hcr_el2_eff(env) & HCR_TGE)) { return 1; } return 0; @@ -8797,6 +8795,8 @@ static inline uint32_t regime_sctlr(CPUARMState *env, ARMMMUIdx mmu_idx) static inline bool regime_translation_disabled(CPUARMState *env, ARMMMUIdx mmu_idx) { + uint64_t hcr_el2; + if (arm_feature(env, ARM_FEATURE_M)) { switch (env->v7m.mpu_ctrl[regime_is_secure(env, mmu_idx)] & (R_V7M_MPU_CTRL_ENABLE_MASK | R_V7M_MPU_CTRL_HFNMIENA_MASK)) { @@ -8815,19 +8815,21 @@ static inline bool regime_translation_disabled(CPUARMState *env, } } + hcr_el2 = arm_hcr_el2_eff(env); + if (mmu_idx == ARMMMUIdx_S2NS) { /* HCR.DC means HCR.VM behaves as 1 */ - return (env->cp15.hcr_el2 & (HCR_DC | HCR_VM)) == 0; + return (hcr_el2 & (HCR_DC | HCR_VM)) == 0; } - if (env->cp15.hcr_el2 & HCR_TGE) { + if (hcr_el2 & HCR_TGE) { /* TGE means that NS EL0/1 act as if SCTLR_EL1.M is zero */ if (!regime_is_secure(env, mmu_idx) && regime_el(env, mmu_idx) == 1) { return true; } } - if ((env->cp15.hcr_el2 & HCR_DC) && + if ((hcr_el2 & HCR_DC) && (mmu_idx == ARMMMUIdx_S1NSE0 || mmu_idx == ARMMMUIdx_S1NSE1)) { /* HCR.DC means SCTLR_EL1.M behaves as 0 */ return true; diff --git a/target/arm/op_helper.c b/target/arm/op_helper.c index 0d6e89e474..780caf387b 100644 --- a/target/arm/op_helper.c +++ b/target/arm/op_helper.c @@ -33,8 +33,7 @@ void raise_exception(CPUARMState *env, uint32_t excp, { CPUState *cs = CPU(arm_env_get_cpu(env)); - if ((env->cp15.hcr_el2 & HCR_TGE) && - target_el == 1 && !arm_is_secure(env)) { + if (target_el == 1 && (arm_hcr_el2_eff(env) & HCR_TGE)) { /* * Redirect NS EL1 exceptions to NS EL2. These are reported with * their original syndrome register value, with the exception of @@ -428,9 +427,9 @@ static inline int check_wfx_trap(CPUARMState *env, bool is_wfe) * No need for ARM_FEATURE check as if HCR_EL2 doesn't exist the * bits will be zero indicating no trap. */ - if (cur_el < 2 && !arm_is_secure(env)) { - mask = (is_wfe) ? HCR_TWE : HCR_TWI; - if (env->cp15.hcr_el2 & mask) { + if (cur_el < 2) { + mask = is_wfe ? HCR_TWE : HCR_TWI; + if (arm_hcr_el2_eff(env) & mask) { return 2; } } @@ -995,7 +994,7 @@ void HELPER(pre_smc)(CPUARMState *env, uint32_t syndrome) exception_target_el(env)); } - if (!secure && cur_el == 1 && (env->cp15.hcr_el2 & HCR_TSC)) { + if (!secure && cur_el == 1 && (arm_hcr_el2_eff(env) & HCR_TSC)) { /* In NS EL1, HCR controlled routing to EL2 has priority over SMD. * We also want an EL2 guest to be able to forbid its EL1 from * making PSCI calls into QEMU's "firmware" via HCR.TSC. @@ -1098,8 +1097,7 @@ void HELPER(exception_return)(CPUARMState *env) goto illegal_return; } - if (new_el == 1 && (env->cp15.hcr_el2 & HCR_TGE) - && !arm_is_secure_below_el3(env)) { + if (new_el == 1 && (arm_hcr_el2_eff(env) & HCR_TGE)) { goto illegal_return; }