From nobody Sat May 4 23:50:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1576151321; cv=none; d=zohomail.com; s=zohoarc; b=hP70TxcNr56rN0SxGR7qJt/zc0Uu5NjAiTAbE5Bv7ZH4qoJ0s4/XqctTz4tVyBjSwHNeedtp6PMLNP7hGcB2rerfS0pxD+/QPcWm8lTOAuQjA02TRJ7d+Dot/RpAocaViqtLCz0C4hDpMYtLHtPHT5yCFWDpelDDGhGfggG3qGY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576151321; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=QM15Kq7l2rtZD3l31WMeE+oAwNwZWxd9GAGGi1JsolM=; b=iSfPy+qG/qemodGJgdcoPRnkvG/QH8rIpfstDnH1clu2yjL6UYS0XDpqi86tezZ9y74rVnLQ2VLLozX69Bh/tVF8t3/6dRgWezenqo45zNs6ecwD6+NgQOpWo7X6ajl3WqkSkqrCmvi8ynsS8SwWbVeTxxi02Zy0LE6oPbJUWSg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1576151321221644.6724197755174; Thu, 12 Dec 2019 03:48:41 -0800 (PST) Received: from localhost ([::1]:58196 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ifMxT-0003Lr-Gx for importer@patchew.org; Thu, 12 Dec 2019 06:48:39 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40093) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ifMwi-0002n9-3Y for qemu-devel@nongnu.org; Thu, 12 Dec 2019 06:47:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ifMwg-0004vc-Kn for qemu-devel@nongnu.org; Thu, 12 Dec 2019 06:47:51 -0500 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:46647) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ifMwg-0004t9-Bz for qemu-devel@nongnu.org; Thu, 12 Dec 2019 06:47:50 -0500 Received: by mail-wr1-x444.google.com with SMTP id z7so2354143wrl.13 for ; Thu, 12 Dec 2019 03:47:50 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id n3sm5492409wrs.8.2019.12.12.03.47.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Dec 2019 03:47:46 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 097061FF87; Thu, 12 Dec 2019 11:47:46 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=QM15Kq7l2rtZD3l31WMeE+oAwNwZWxd9GAGGi1JsolM=; b=ktYEIq46Dpaf+Iz5Q+YGqaYUgueNheaKh7TOKJbh4IbqbZkb2PRw35ImuJn/D9PNeU RGiKQ6YKsydAv5LNThtsZYiUQ0LI+O9AVctG9Tzh7gt2AuTCERReMC0HHimzZ7tM7hdT 9Het8vLiSp6ecOQ9AfFZLHJp1mmRH40mU1P5vjajtJ+pKa9yi/63IAHKluLsshGC38FE vqgv1qfbmzlUiRVbkH7Aom9JdKi2erQS965SaTsQyYB0ySLIVQTty9GXgpnlWpGzEaHT WiHzGA1mFE18E4PX29j/SWOBA6nZ76KJElELBJ2TyXGOBJ/R04iDtLpcrl7lNqzaPioX R0yQ== 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:mime-version :content-transfer-encoding; bh=QM15Kq7l2rtZD3l31WMeE+oAwNwZWxd9GAGGi1JsolM=; b=QLlbL2sWpvm7ouMi3nUFEa67G2iE5q7NjxwDepydp+1AegTMCFHDQ3RGa5A1/o2rWA bPeMxnSBiguK+bG+XyNlQxsCxRBHxTV2Ot6KKp+JqpARXV+ZkoNwoRj9xPy4Kf13IHns /5EYzqD3d4GQNVA8E+0Dp65dMvGAp76Sr9jYgJHdQRahRU2az7zg0/yQ825DY5j7pR08 lcQVxluQwhwNh1XhwFJJURdQgGISWFe1gVG7sXjltP8GfbvvWHSBK+UaGosbT4ZcuGPf KG5M8CQVGfIDgvGR3s/RgKcUyd79G0NzSuxwa4T4L+i6PviYZJ9ZZPz/KusJYcd+fTnE DuYw== X-Gm-Message-State: APjAAAVGnJRUZQ59NzHUSMO8khJlD1p+rL9fCPdx5Tn0F9xs0+3p3vCP HeHVjAn+RBOgSAcsnv/AscTqXw== X-Google-Smtp-Source: APXvYqzF7F77ukhJrmaFi6wsHEfW/RR9wOdyj5fjBaXxqJbxPtwNqqWc1ioSSIm+lZoBtrhmTmGYHA== X-Received: by 2002:adf:df0e:: with SMTP id y14mr5404817wrl.377.1576151268470; Thu, 12 Dec 2019 03:47:48 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v2] target/arm: ensure we use current exception state after SCR update Date: Thu, 12 Dec 2019 11:47:34 +0000 Message-Id: <20191212114734.6962-1-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::444 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: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson , qemu-arm@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Peter Maydell Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) A write to the SCR can change the effective EL by droppping the system from secure to non-secure mode. However if we use a cached current_el from before the change we'll rebuild the flags incorrectly. To fix this we introduce the ARM_CP_NEWEL CP flag to indicate the new EL should be used when recomputing the flags. Signed-off-by: Alex Benn=C3=A9e Tested-by: Philippe Mathieu-Daud=C3=A9 Cc: Richard Henderson Message-Id: <20191209143723.6368-1-alex.bennee@linaro.org> Reviewed-by: Richard Henderson --- v2 - don't override a ARM_CP_SPECIAL, use a new flag --- target/arm/cpu.h | 8 ++++++-- target/arm/helper.h | 1 + target/arm/helper.c | 14 +++++++++++++- target/arm/translate.c | 6 +++++- 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 83a809d4bac..c3ab47d8962 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -2238,6 +2238,9 @@ static inline uint64_t cpreg_to_kvm_id(uint32_t cpreg= id) * RAISES_EXC is for when the read or write hook might raise an exception; * the generated code will synchronize the CPU state before calling the ho= ok * so that it is safe for the hook to call raise_exception(). + * NEWEL is for writes to registers that might change the exception + * level - typically on older ARM chips. For those cases we need to + * re-read the new el when recomputing the translation flags. */ #define ARM_CP_SPECIAL 0x0001 #define ARM_CP_CONST 0x0002 @@ -2257,10 +2260,11 @@ static inline uint64_t cpreg_to_kvm_id(uint32_t cpr= egid) #define ARM_CP_SVE 0x2000 #define ARM_CP_NO_GDB 0x4000 #define ARM_CP_RAISES_EXC 0x8000 +#define ARM_CP_NEWEL 0x10000 /* Used only as a terminator for ARMCPRegInfo lists */ -#define ARM_CP_SENTINEL 0xffff +#define ARM_CP_SENTINEL 0xfffff /* Mask of only the flag bits in a type field */ -#define ARM_CP_FLAG_MASK 0xf0ff +#define ARM_CP_FLAG_MASK 0x1f0ff =20 /* Valid values for ARMCPRegInfo state field, indicating which of * the AArch32 and AArch64 execution states this register is visible in. diff --git a/target/arm/helper.h b/target/arm/helper.h index 3d4ec267a2c..e345bdb726a 100644 --- a/target/arm/helper.h +++ b/target/arm/helper.h @@ -91,6 +91,7 @@ DEF_HELPER_2(get_user_reg, i32, env, i32) DEF_HELPER_3(set_user_reg, void, env, i32, i32) =20 DEF_HELPER_FLAGS_2(rebuild_hflags_m32, TCG_CALL_NO_RWG, void, env, int) +DEF_HELPER_FLAGS_1(rebuild_hflags_a32_newel, TCG_CALL_NO_RWG, void, env) DEF_HELPER_FLAGS_2(rebuild_hflags_a32, TCG_CALL_NO_RWG, void, env, int) DEF_HELPER_FLAGS_2(rebuild_hflags_a64, TCG_CALL_NO_RWG, void, env, int) =20 diff --git a/target/arm/helper.c b/target/arm/helper.c index 0bf8f53d4b8..b92ef9d1905 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -5096,7 +5096,7 @@ static const ARMCPRegInfo el3_cp_reginfo[] =3D { .opc0 =3D 3, .opc1 =3D 6, .crn =3D 1, .crm =3D 1, .opc2 =3D 0, .access =3D PL3_RW, .fieldoffset =3D offsetof(CPUARMState, cp15.scr_= el3), .resetvalue =3D 0, .writefn =3D scr_write }, - { .name =3D "SCR", .type =3D ARM_CP_ALIAS, + { .name =3D "SCR", .type =3D ARM_CP_ALIAS | ARM_CP_NEWEL, .cp =3D 15, .opc1 =3D 0, .crn =3D 1, .crm =3D 1, .opc2 =3D 0, .access =3D PL1_RW, .accessfn =3D access_trap_aa32s_el1, .fieldoffset =3D offsetoflow32(CPUARMState, cp15.scr_el3), @@ -11332,6 +11332,18 @@ void HELPER(rebuild_hflags_m32)(CPUARMState *env, = int el) env->hflags =3D rebuild_hflags_m32(env, fp_el, mmu_idx); } =20 +/* + * If we have triggered a EL state change we can't rely on the + * translator having passed it too us, we need to recompute. + */ +void HELPER(rebuild_hflags_a32_newel)(CPUARMState *env) +{ + int el =3D arm_current_el(env); + int fp_el =3D fp_exception_el(env, el); + ARMMMUIdx mmu_idx =3D arm_mmu_idx_el(env, el); + env->hflags =3D rebuild_hflags_a32(env, fp_el, mmu_idx); +} + void HELPER(rebuild_hflags_a32)(CPUARMState *env, int el) { int fp_el =3D fp_exception_el(env, el); diff --git a/target/arm/translate.c b/target/arm/translate.c index 4d5d4bd8886..83aa331b1ec 100644 --- a/target/arm/translate.c +++ b/target/arm/translate.c @@ -7083,7 +7083,11 @@ static int disas_coproc_insn(DisasContext *s, uint32= _t insn) if (arm_dc_feature(s, ARM_FEATURE_M)) { gen_helper_rebuild_hflags_m32(cpu_env, tcg_el); } else { - gen_helper_rebuild_hflags_a32(cpu_env, tcg_el); + if (ri->type & ARM_CP_NEWEL) { + gen_helper_rebuild_hflags_a32_newel(cpu_env); + } else { + gen_helper_rebuild_hflags_a32(cpu_env, tcg_el); + } } tcg_temp_free_i32(tcg_el); /* --=20 2.20.1