From patchwork Mon Dec 10 15:05:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 153272 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp3662511ljp; Mon, 10 Dec 2018 07:07:43 -0800 (PST) X-Google-Smtp-Source: AFSGD/UwIdVhMYaFKGFNu1ux0XMqKSnpkfdhk2e6u9BY68DrlHF4eF5gnBCIcM0eudQPRM103hHM X-Received: by 2002:ac8:4818:: with SMTP id g24mr12104843qtq.66.1544454463528; Mon, 10 Dec 2018 07:07:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544454463; cv=none; d=google.com; s=arc-20160816; b=lRiQ7ZRLPuvbSY9j0m6WYtcy76XrN5RKDlssaf6WTQGngotJuhc6w8YcNY7UVahZcl 9md/yR3XFG21PAXvO6yco5yiu0TWUK7jrMaGJH8MV8z0bmfvOV6aUNg5v8XG6xCbndxU 4/Clx1z1qdpOtzn+SYCaSbNstZ6p1Oa5g07du+8H+5zUPiwK4jliJ4PH5bt8k2RQX1Rd tbIMISgPEdUSZmUdLdzTfrOAtDDocsHfjqjTS0d09D2j79o+08E+Pn7VNf8mMCp4rZ9Q I2oJT1MwrnxUi3MviC/3HFJSkyuiSGuJzGKpPW5sMQrg5AlCx6hJCPKI8icIirtl934w ga5w== 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=CkPc61eIpCVWmyDPgstZ8J1bd1SqGM9XNiDjV1wFZ/Q=; b=jbpWMyLBLgvBqQpgzw6CpL4grIGrXSvcWJ9gTJJkgvL72LWUuVSGYPodtq1I1M4pGg VSlDStNK/QoPGZmHpmQmMblain2OVXK+9Y5VU10p+375VtrrJko6dNAD8tvhxECb5jXc 6+upwFLc2FhsfEkQIV0d5Lz5B93U/wJRDa0Uc4S8ZjZoxEqeJqnU2eyDTj9YFMZxDqVN P3wGOt9WYG1AHZ+AjGdssnQLNlKvEuazVr6pcH5RAWF5abfszjYx0eR+u6GKSlj89ZYQ nJMcnBKJaQdiX9moBXX2WRsLna6hOTmniWBfg7N9sO0NAmp9OZb/1Bqo7ch8U4rjbqSl XvRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=RFh4+Zys; 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 21si1846854qki.9.2018.12.10.07.07.43 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 10 Dec 2018 07:07:43 -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=RFh4+Zys; 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]:33216 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gWN9q-0003aj-Lr for patch@linaro.org; Mon, 10 Dec 2018 10:07:42 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34473) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gWN7N-0002gS-Lc for qemu-devel@nongnu.org; Mon, 10 Dec 2018 10:05:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gWN7M-0003jb-8h for qemu-devel@nongnu.org; Mon, 10 Dec 2018 10:05:09 -0500 Received: from mail-oi1-x242.google.com ([2607:f8b0:4864:20::242]:46252) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gWN7M-0003jL-3E for qemu-devel@nongnu.org; Mon, 10 Dec 2018 10:05:08 -0500 Received: by mail-oi1-x242.google.com with SMTP id x202so9156102oif.13 for ; Mon, 10 Dec 2018 07:05:08 -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=CkPc61eIpCVWmyDPgstZ8J1bd1SqGM9XNiDjV1wFZ/Q=; b=RFh4+ZysfxLkhz2WOLTcLpaadSic8XXIzPGSZjRKWMpw3fn6jOjxHdf33++ZkYSdTJ CYUE+HbXLhCy/PEXkgJE9QPgXjB3Z9I6221RQFFp424d1QOzFHro8O/XoVbnSQ3HLYFn XMbTcoupyJTitHDB1tqFShBdDiRCdNy44ZnjY= 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=CkPc61eIpCVWmyDPgstZ8J1bd1SqGM9XNiDjV1wFZ/Q=; b=f4S4jG3WlFav5FYlJBSQTUkYGXhekjggYBFOt3B9X9FGTitbp7KOLo3vWRTqAGH809 3p0oCZEyN3eHsgyT4CTSArI2C4Bmx+cO0lhukhQ2LOtmgOLg45KIqOWJP8M4fRJryquK JgGOsBNwDo3UZjOPjoXUGu7D+AWOZPeSA5hq71yaCMLcDFNfhesvOXEmb/Y9+sR51yej bAa22JOlBHdd4zbVB2jeKOK6/rxWUpFDnmIwS7nvT6hNC8bGYTzsmD5uz5dtqtjvJ96T m9oLkcn3YEuA28VMeAAGp7oKxVrAS6M8Nr5WcSH16/ZGFvWa/NCF7vfz2qK9TLZPGqFe MAhg== X-Gm-Message-State: AA+aEWaY7yt96czoZOEqDg2noW8dPZLqolxiLuiGSPWN/Y8cg5P2nS4b Mxd1eg2f7YrpLZIv7WSpo1a5AssEMtBeSA== X-Received: by 2002:aca:bf06:: with SMTP id p6mr7139085oif.269.1544454306818; Mon, 10 Dec 2018 07:05:06 -0800 (PST) Received: from cloudburst.twiddle.net ([187.217.227.243]) by smtp.gmail.com with ESMTPSA id b18sm5694734oii.51.2018.12.10.07.05.05 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 10 Dec 2018 07:05:06 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 10 Dec 2018 09:05:00 -0600 Message-Id: <20181210150501.7990-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20181210150501.7990-1-richard.henderson@linaro.org> References: <20181210150501.7990-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::242 Subject: [Qemu-devel] [PATCH v4 2/3] 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. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- v3: Do not change regime_translation_disabled. --- target/arm/helper.c | 12 +++++------- target/arm/op_helper.c | 14 ++++++-------- 2 files changed, 11 insertions(+), 15 deletions(-) -- 2.17.2 diff --git a/target/arm/helper.c b/target/arm/helper.c index 95d59e07fb..d6f8be9f4e 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; @@ -4566,8 +4566,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. */ @@ -6216,9 +6215,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; diff --git a/target/arm/op_helper.c b/target/arm/op_helper.c index 0d6e89e474..ef72361a36 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 (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; }