From patchwork Thu Oct 8 18:08:49 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 54673 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f199.google.com (mail-wi0-f199.google.com [209.85.212.199]) by patches.linaro.org (Postfix) with ESMTPS id CA4F322FF8 for ; Thu, 8 Oct 2015 18:08:52 +0000 (UTC) Received: by wicgb1 with SMTP id gb1sf15900087wic.3 for ; Thu, 08 Oct 2015 11:08:52 -0700 (PDT) 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:cc:subject :date:message-id:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=ANZXwlD83dkJBVNTEmtpngIOtFrqkfEiTGzkIzFIs5U=; b=eBURxiJ/tD6aQUwknnJeDj5qfx7lewZzdmbIChvz2NN4bwujRmi9SuWefLGjQy43m0 7ZQ6L9vNwhDzHNTagsTbB9qdGOAeRjgIirKSVxV4wvyGSeCN5LyXEj2snlmPEIErscbJ zmPxIEyahlE52AVxz/AQ6DcIGf5p8XBB/QXnpl8bgWHazo18teKwj4OiRNC/8G0gt6Vo RSqyzdfW9Hy9tP1drNGJ2Lxn72PB8whzS54e1gu7ZL74rVtprTVNeuHa8S9Pdh5Osz1f 9YOzOmSqXzO3lOhCG6hYhUfsgVXY4OpwTIoUkgr44BQimlzRBIUzzZjQfFQO/a41WDbX E8IQ== X-Gm-Message-State: ALoCoQkdXwEGVwu4TBG2sPu6Lod0OzvCkLQ0qoB2u/NO4nX1jkqJqa1Wo1U4VafXUhXWAauS5Dpx X-Received: by 10.112.164.1 with SMTP id ym1mr1702086lbb.15.1444327732055; Thu, 08 Oct 2015 11:08:52 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.147.7 with SMTP id v7ls209743lfd.65.gmail; Thu, 08 Oct 2015 11:08:51 -0700 (PDT) X-Received: by 10.112.173.198 with SMTP id bm6mr4347241lbc.43.1444327731922; Thu, 08 Oct 2015 11:08:51 -0700 (PDT) Received: from mail-lb0-f178.google.com (mail-lb0-f178.google.com. [209.85.217.178]) by mx.google.com with ESMTPS id m141si30725889lfb.69.2015.10.08.11.08.51 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Oct 2015 11:08:51 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.178 as permitted sender) client-ip=209.85.217.178; Received: by lbwr8 with SMTP id r8so55741867lbw.2 for ; Thu, 08 Oct 2015 11:08:51 -0700 (PDT) X-Received: by 10.112.163.131 with SMTP id yi3mr4382153lbb.36.1444327731464; Thu, 08 Oct 2015 11:08:51 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.112.59.35 with SMTP id w3csp725350lbq; Thu, 8 Oct 2015 11:08:50 -0700 (PDT) X-Received: by 10.194.221.71 with SMTP id qc7mr9618563wjc.68.1444327730734; Thu, 08 Oct 2015 11:08:50 -0700 (PDT) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id p6si13223537wia.41.2015.10.08.11.08.50 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 08 Oct 2015 11:08:50 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::1 as permitted sender) client-ip=2001:8b0:1d0::1; Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1ZkFcX-00014v-2z; Thu, 08 Oct 2015 19:08:49 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Sergey Sorokin , "Edgar E. Iglesias" Subject: [PATCH] target-arm: Fix "no 64-bit EL2" assumption in arm_excp_unmasked() Date: Thu, 8 Oct 2015 19:08:49 +0100 Message-Id: <1444327729-4120-1-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: peter.maydell@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.217.178 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , The code in arm_excp_unmasked() suppresses the ability of PSTATE.AIF to mask exceptions from a lower EL targeting EL2 or EL3 if the CPU is 64-bit. This is correct for a target of EL3, but not correct for targeting EL2. Further, we go to some effort to calculate scr and hcr values which are not used at all for the 64-bit CPU case. Rearrange the code to correctly implement the 64-bit CPU logic and keep the hcr/scr calculations in the 32-bit CPU codepath. Signed-off-by: Peter Maydell Reviewed-by: Edgar E. Iglesias Tested-by: Edgar E. Iglesias --- As promised, here's the patch that fixes the assumption about 64-bit implying no EL2 in arm_excp_unmasked(). This applies on top of my current target-arm.next tree, since it has Sergey's patch in it which touches the same code. target-arm/cpu.h | 82 +++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 52 insertions(+), 30 deletions(-) diff --git a/target-arm/cpu.h b/target-arm/cpu.h index 99b34c4..6b6e4e0 100644 --- a/target-arm/cpu.h +++ b/target-arm/cpu.h @@ -1524,8 +1524,6 @@ static inline bool arm_excp_unmasked(CPUState *cs, unsigned int excp_idx, CPUARMState *env = cs->env_ptr; unsigned int cur_el = arm_current_el(env); bool secure = arm_is_secure(env); - bool scr; - bool hcr; bool pstate_unmasked; int8_t unmasked = 0; @@ -1539,31 +1537,10 @@ static inline bool arm_excp_unmasked(CPUState *cs, unsigned int excp_idx, switch (excp_idx) { case EXCP_FIQ: - /* If FIQs are routed to EL3 or EL2 then there are cases where we - * override the CPSR.F in determining if the exception is masked or - * not. If neither of these are set then we fall back to the CPSR.F - * setting otherwise we further assess the state below. - */ - hcr = (env->cp15.hcr_el2 & HCR_FMO); - scr = (env->cp15.scr_el3 & SCR_FIQ); - - /* When EL3 is 32-bit, the SCR.FW bit controls whether the CPSR.F bit - * masks FIQ interrupts when taken in non-secure state. If SCR.FW is - * set then FIQs can be masked by CPSR.F when non-secure but only - * when FIQs are only routed to EL3. - */ - scr = scr && !((env->cp15.scr_el3 & SCR_FW) && !hcr); pstate_unmasked = !(env->daif & PSTATE_F); break; case EXCP_IRQ: - /* When EL3 execution state is 32-bit, if HCR.IMO is set then we may - * override the CPSR.I masking when in non-secure state. The SCR.IRQ - * setting has already been taken into consideration when setting the - * target EL, so it does not have a further affect here. - */ - hcr = (env->cp15.hcr_el2 & HCR_IMO); - scr = false; pstate_unmasked = !(env->daif & PSTATE_I); break; @@ -1588,13 +1565,58 @@ static inline bool arm_excp_unmasked(CPUState *cs, unsigned int excp_idx, * interrupt. */ if ((target_el > cur_el) && (target_el != 1)) { - /* ARM_FEATURE_AARCH64 enabled means the highest EL is AArch64. - * This code currently assumes that EL2 is not implemented - * (and so that highest EL will be 3 and the target_el also 3). - */ - if (arm_feature(env, ARM_FEATURE_AARCH64) || - ((scr || hcr) && (!secure))) { - unmasked = 1; + /* Exceptions targeting a higher EL may not be maskable */ + if (arm_feature(env, ARM_FEATURE_AARCH64)) { + /* 64-bit masking rules are simple: exceptions to EL3 + * can't be masked, and exceptions to EL2 can only be + * masked from Secure state. The HCR and SCR settings + * don't affect the masking logic, only the interrupt routing. + */ + if (target_el == 3 || !secure) { + unmasked = 1; + } + } else { + /* The old 32-bit-only environment has a more complicated + * masking setup. HCR and SCR bits not only affect interrupt + * routing but also change the behaviour of masking. + */ + bool hcr, scr; + + switch (excp_idx) { + case EXCP_FIQ: + /* If FIQs are routed to EL3 or EL2 then there are cases where + * we override the CPSR.F in determining if the exception is + * masked or not. If neither of these are set then we fall back + * to the CPSR.F setting otherwise we further assess the state + * below. + */ + hcr = (env->cp15.hcr_el2 & HCR_FMO); + scr = (env->cp15.scr_el3 & SCR_FIQ); + + /* When EL3 is 32-bit, the SCR.FW bit controls whether the + * CPSR.F bit masks FIQ interrupts when taken in non-secure + * state. If SCR.FW is set then FIQs can be masked by CPSR.F + * when non-secure but only when FIQs are only routed to EL3. + */ + scr = scr && !((env->cp15.scr_el3 & SCR_FW) && !hcr); + break; + case EXCP_IRQ: + /* When EL3 execution state is 32-bit, if HCR.IMO is set then + * we may override the CPSR.I masking when in non-secure state. + * The SCR.IRQ setting has already been taken into consideration + * when setting the target EL, so it does not have a further + * affect here. + */ + hcr = (env->cp15.hcr_el2 & HCR_IMO); + scr = false; + break; + default: + g_assert_not_reached(); + } + + if ((scr || hcr) && !secure) { + unmasked = 1; + } } }