Received: from eggs.gnu.org ([2001:4830:134:3::10]:50892) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZjWJ2-0003MA-VR for qemu-devel@nongnu.org; Tue, 06 Oct 2015 13:45:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZjWIy-0003Wa-FM for qemu-devel@nongnu.org; Tue, 06 Oct 2015 13:45:40 -0400 Received: from forward19j.cmail.yandex.net ([5.255.227.238]:32938) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZjWIx-0003Vg-N8 for qemu-devel@nongnu.org; Tue, 06 Oct 2015 13:45:36 -0400 From: Sergey Sorokin In-Reply-To: References: <1443792091-12985-1-git-send-email-afarallax@yandex.ru> MIME-Version: 1.0 Message-Id: <72891444153413@web8j.yandex.ru> Date: Tue, 06 Oct 2015 20:43:33 +0300 Content-Type: text/plain; charset=koi8-r Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH] target-arm: Avoid calling arm_el_is_aa64() function for unimplemented EL List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell Cc: "Edgar E. Iglesias" , QEMU Developers That is ok. 06.10.2015, 00:55, "Peter Maydell" : > On 2 October 2015 at 14:21, Sergey Sorokin wrote: >> =9AIt is incorrect to call arm_el_is_aa64() function for unimplemented= EL. >> =9AThis patch fixes several attempts to do so. >> >> =9ASigned-off-by: Sergey Sorokin >> =9A--- >> =9A=9Atarget-arm/cpu.h | 8 +++++--- >> =9A=9Atarget-arm/helper.c | 15 +++++++++++++-- >> =9A=9A2 files changed, 18 insertions(+), 5 deletions(-) >> >> =9Adiff --git a/target-arm/cpu.h b/target-arm/cpu.h >> =9Aindex cc1578c..df456a5 100644 >> =9A--- a/target-arm/cpu.h >> =9A+++ b/target-arm/cpu.h >> =9A@@ -1015,11 +1015,11 @@ static inline bool access_secure_reg(CPUARM= State *env) >> =9A=9A=9A*/ >> =9A=9A#define A32_BANKED_CURRENT_REG_GET(_env, _regname) \ >> =9A=9A=9A=9A=9A=9AA32_BANKED_REG_GET((_env), _regname, \ >> =9A- ((!arm_el_is_aa64((_env), 3) && arm_is_secure(_env)))) >> =9A+ (arm_is_secure(_env) && !arm_el_is_aa64((_env), 3))) >> >> =9A=9A#define A32_BANKED_CURRENT_REG_SET(_env, _regname, _val) \ >> =9A=9A=9A=9A=9A=9AA32_BANKED_REG_SET((_env), _regname, \ >> =9A- ((!arm_el_is_aa64((_env), 3) && arm_is_secure(_env))), \ >> =9A+ (arm_is_secure(_env) && !arm_el_is_aa64((_env), 3)), \ >> =9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A= =9A(_val)) >> >> =9A=9Avoid arm_cpu_list(FILE *f, fprintf_function cpu_fprintf); >> =9A@@ -1586,7 +1586,9 @@ static inline bool arm_excp_unmasked(CPUState= *cs, unsigned int excp_idx, >> =9A=9A=9A=9A=9A=9A=9A* interrupt. >> =9A=9A=9A=9A=9A=9A=9A*/ >> =9A=9A=9A=9A=9A=9Aif ((target_el > cur_el) && (target_el !=3D 1)) { >> =9A- if (arm_el_is_aa64(env, 3) || ((scr || hcr) && (!secure))) { >> =9A+ /* ARM_FEATURE_AARCH64 enabled means the higher EL is AArch64. */ >> =9A+ if (arm_feature(env, ARM_FEATURE_AARCH64) || >> =9A+ ((scr || hcr) && (!secure))) { >> =9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9Aunmasked =3D 1; >> =9A=9A=9A=9A=9A=9A=9A=9A=9A=9A} >> =9A=9A=9A=9A=9A=9A} > > I know we discussed this one before, but having looked more carefully > at it, I think the reason it's weird is that the original code is > only correct if we're not implementing EL2. > > For instance (table D1-14 in the v8 ARMARM rev A.g) > if we're in an all-AArch64 environment executing in Secure EL0 > then the interrupt mask is supposed to have an effect if the interrupt > is targeting EL2. But the current code will always set 'unmasked' to 1 = if > EL3 is 64 bit. > > So I think what the code ought to read is: > > =9A=9A=9A=9Aif ((target_el > cur_el) && (target_el !=3D 1)) { > =9A=9A=9A=9A=9A=9A=9A=9A/* Exceptions targeting a higher EL may not be = maskable */ > =9A=9A=9A=9A=9A=9A=9A=9Aif (arm_feature(env, ARM_FEATURE_AARCH64)) { > =9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A/* 64-bit masking rules are simple:= exceptions to EL3 > =9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A* can't be masked, and exception= s to EL2 can only be > =9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A* masked from Secure state. > =9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A*/ > =9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9Aif (target_el =3D=3D 3 || !secure) = { > =9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9Aunmasked =3D 1; > =9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A} > =9A=9A=9A=9A=9A=9A=9A=9A} else { > =9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A/* The old 32-bit-only environment = has a more complicated > =9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A* masking setup. > =9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A*/ > =9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9Aif ((scr || hcr) && !secure) { > =9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9Aunmasked =3D 1; > =9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A} > =9A=9A=9A=9A=9A=9A=9A=9A} > =9A=9A=9A=9A} > > Except that then for the AArch64 case we've just calculated > scr and hcr and then not needed them. I think most of the > code calculating them ought to move into the else clause here. > > I'll write a patch for this and post it tomorrow. > > In the meantime, we can just make the comment say > > =9A=9A=9A/* ARM_FEATURE_AARCH64 enabled means the highest EL is AArch64= . > =9A=9A=9A=9A* This code currently assumes that EL2 is not implemented > =9A=9A=9A=9A* (and so that highest EL will be 3 and the target_el also = 3). > =9A=9A=9A=9A*/ > >> =9Adiff --git a/target-arm/helper.c b/target-arm/helper.c >> =9Aindex 8367997..1f11dbd 100644 >> =9A--- a/target-arm/helper.c >> =9A+++ b/target-arm/helper.c >> =9A@@ -5220,11 +5220,22 @@ uint32_t arm_phys_excp_target_el(CPUState *= cs, uint32_t excp_idx, >> =9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9A= =9A=9A=9A=9A=9A=9A=9A=9A=9A=9A=9Auint32_t cur_el, bool secure) >> =9A=9A{ >> =9A=9A=9A=9A=9A=9ACPUARMState *env =3D cs->env_ptr; >> =9A- int rw =3D ((env->cp15.scr_el3 & SCR_RW) =3D=3D SCR_RW); >> =9A+ int rw; >> =9A=9A=9A=9A=9A=9Aint scr; >> =9A=9A=9A=9A=9A=9Aint hcr; >> =9A=9A=9A=9A=9A=9Aint target_el; >> =9A- int is64 =3D arm_el_is_aa64(env, 3); >> =9A+ /* Is the higher EL AArch64? */ > > "highest". I pointed this one out before... > >> =9A+ int is64 =3D arm_feature(env, ARM_FEATURE_AARCH64); >> =9A+ >> =9A+ /* If the highest EL is in AArch64 state, and EL3 is not implemen= ted, >> =9A+ * we must behave as if EL3 is implemented and is in AArch64 state= . >> =9A+ * Therefore we need appropriate RW bit. >> =9A+ */ > > I think we could put this comment into the else branch, and > rephrase it a bit: > > + if (arm_feature(env, ARM_FEATURE_EL3)) { > + rw =3D ((env->cp15.scr_el3 & SCR_RW) =3D=3D SCR_RW); > + } else { > + /* Either EL2 is the highest EL (and so the EL2 register width > + * is given by is64); or there is no EL2 or EL3, in which case > + * the value of 'rw' does not affect the table lookup anyway. > + */ > + rw =3D is64; > + } > >> =9A+ if (arm_feature(env, ARM_FEATURE_EL3)) { >> =9A+ rw =3D ((env->cp15.scr_el3 & SCR_RW) =3D=3D SCR_RW); >> =9A+ } else { >> =9A+ rw =3D is64; >> =9A+ } > > What I can do with this patch is: > =9A* make the minor comment tweaks above > =9A* apply the result to target-arm.next > > Is that OK? > >> =9A=9A=9A=9A=9A=9Aswitch (excp_idx) { >> =9A=9A=9A=9A=9A=9Acase EXCP_IRQ: >> =9A-- >> =9A1.9.3 > > thanks > -- PMM