From patchwork Tue Jun 7 20:32:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 579347 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5806:0:0:0:0 with SMTP id j6csp5509711max; Tue, 7 Jun 2022 14:04:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwiuLXUhmeh8QQg5b+C6j7Mzcdt1tiCBKWQPsho4nVETuBdFPrkl2RZ0yccOJDrXq3REiyp X-Received: by 2002:ac8:5895:0:b0:304:c4d4:77ae with SMTP id t21-20020ac85895000000b00304c4d477aemr24040123qta.343.1654635844746; Tue, 07 Jun 2022 14:04:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654635844; cv=none; d=google.com; s=arc-20160816; b=AO0rJB/bU5N2M7/QrAhqwHEzR3ULgdsq84+luujJwyvlMiCXE0UMQ3RMBabF2N5gf9 1Jw+ANSu+nC+dyFzlfAhK1zZuRdvFqP4vS5aHh+5wlb36p/P2/kLT4/o9vZVUqRD583t B3jvINh6ILVYC3npZpcGMtwm8IixIuw0i2XatUkH/I7BLh9Ak8G+pakP/xD3fnhWAlnS QajJOpKYuaUIwRIBJ5CuhHEYuCP82XydoUkeTTUcknBxwy4lTTFAq4VTE8p2RLzVQDmu iWmBTqx9Us/ICaHIj2GUzC4eElgsm1bSe3SydAr6KGXC0XM1cm4BEeaGH6i8fWi2XtmC O93g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=cwMIrzdINWrV/sQZ3wz6KuPhrAMN58vwUNHGWXs01ZE=; b=JI2WcWCIca98OhW0vyRnz+VqMDuft5zGQ+s885mfX6uJud2XFC7P0tG3hM7LLm+TiH qriVU1azYjjfZcGHRlRAwszAk3z1g1EioKt+14BBON2/9XHArEYRmlJJCCXoK4dMi3/4 pkeC68l3qt0Yb5j8ueSzhyaJJ64jsyfd9yYsWeVlX2Y3X6YGIard/OP0sTo6PqGw23zK 8L+gSrNHYMoSqpRgcIxgTuzYsdF6VUIDyRCB6aU/lbeV4RySYUh+7uxlPsIpy230is7l 4pWuzg8M3MuOuLpj+0zbvICiP3LvI0wZyrjhMWYk/M/H58yxOFG4kQQ4ih2IujgUYTGR KAmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QKMR5SYL; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id o17-20020a05622a045100b00304f6d6266bsi2154512qtx.610.2022.06.07.14.04.04 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 07 Jun 2022 14:04:04 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QKMR5SYL; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:52670 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nygMu-0005yo-AL for patch@linaro.org; Tue, 07 Jun 2022 17:04:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34062) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nyftP-00082W-Nd for qemu-devel@nongnu.org; Tue, 07 Jun 2022 16:33:35 -0400 Received: from mail-pj1-x1029.google.com ([2607:f8b0:4864:20::1029]:51858) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nyftJ-0007Ln-HG for qemu-devel@nongnu.org; Tue, 07 Jun 2022 16:33:35 -0400 Received: by mail-pj1-x1029.google.com with SMTP id cx11so16669744pjb.1 for ; Tue, 07 Jun 2022 13:33:28 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=cwMIrzdINWrV/sQZ3wz6KuPhrAMN58vwUNHGWXs01ZE=; b=QKMR5SYLvauIOvMxGqZz5lQx7HyhZIObePwQ7I6a+BLJySLKZV+e9/DqjFJceWdwMC K7BsTTNVazex9j0s+lsd78MZzqGaB4K/vOfylXybePBbiL+rrMKP9mw3m50BQrvSSasD Mu1GnrHjg7kB5yPF6/WOcUt0U3b01+EBoCKz5o7PTgppf80hjMYJ0Zh+vGQtKRKYOzD+ O1d09FC2PZeMK2B2eI9YDihtkJG9+yR65uMKV9247z0eVOl6HL0lfCMtWRd0oDQSF/Ou sm6nCIOdHZR6Y1/8e2ZyFxZfIfWUVKDtmOwwpdM5y4pI6YMe4zoMBdU8PpRwi6JKbfsX zQww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cwMIrzdINWrV/sQZ3wz6KuPhrAMN58vwUNHGWXs01ZE=; b=y01ZnUGFCy8S5NHx6BgM0MTqLKsm52Fm1KXiNP6xhdy+4WrLg96/TYH8HTKAQIMB3Y cUpXdO4jFYOG/VxnaMODbMF1ydFvNMLUBHPef868k9jq24qulM7IenrZ3OUupPRHOov5 oF41YFamMTjH5V71HMrjEp7Wk0t69sSDvrG57AeEkSXsRbwJUCbgZstQnAJJg01mds/h VNmEwl7eXHKcjNwyNDRwJ0y/jcW+VoyaMimFca3x9WmW4OMjC8jJ33HVK7Foh3l/ahHG MSZNO11q0tfv5wkHob0fDAJ5H8IVZKbJ8re91VvJforP2suLs/RGTml9I3dE/3yIZwgL ZzwA== X-Gm-Message-State: AOAM533blOxB+huMjE+jXNZ86qNJhSH3GwF9zNSkYGIv6MYGcC9q5zKM FbP+xlNGWsMUiaJ9j0VRQV7Bh3b3BB9sUw== X-Received: by 2002:a17:903:4049:b0:167:515b:3efa with SMTP id n9-20020a170903404900b00167515b3efamr21517813pla.41.1654634007677; Tue, 07 Jun 2022 13:33:27 -0700 (PDT) Received: from stoup.. ([2602:ae:1547:e101:3cf2:c634:5b19:25f6]) by smtp.gmail.com with ESMTPSA id s22-20020a17090aba1600b001d9780b7779sm4227856pjr.15.2022.06.07.13.33.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 13:33:27 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, qemu-arm@nongnu.org Subject: [PATCH v2 22/71] target/arm: Add SMEEXC_EL to TB flags Date: Tue, 7 Jun 2022 13:32:17 -0700 Message-Id: <20220607203306.657998-23-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220607203306.657998-1-richard.henderson@linaro.org> References: <20220607203306.657998-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1029; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1029.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This is CheckSMEAccess, which is the basis for a set of related tests for various SME cpregs and instructions. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- target/arm/cpu.h | 2 ++ target/arm/translate.h | 1 + target/arm/helper.c | 52 ++++++++++++++++++++++++++++++++++++++ target/arm/translate-a64.c | 1 + 4 files changed, 56 insertions(+) diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 31094a9248..511c30d7d7 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -1134,6 +1134,7 @@ void aarch64_sync_64_to_32(CPUARMState *env); int fp_exception_el(CPUARMState *env, int cur_el); int sve_exception_el(CPUARMState *env, int cur_el); +int sme_exception_el(CPUARMState *env, int cur_el); /** * sve_vqm1_for_el: @@ -3272,6 +3273,7 @@ FIELD(TBFLAG_A64, ATA, 15, 1) FIELD(TBFLAG_A64, TCMA, 16, 2) FIELD(TBFLAG_A64, MTE_ACTIVE, 18, 1) FIELD(TBFLAG_A64, MTE0_ACTIVE, 19, 1) +FIELD(TBFLAG_A64, SMEEXC_EL, 20, 2) /* * Helpers for using the above. diff --git a/target/arm/translate.h b/target/arm/translate.h index f473a21ed4..a492e4217b 100644 --- a/target/arm/translate.h +++ b/target/arm/translate.h @@ -42,6 +42,7 @@ typedef struct DisasContext { bool ns; /* Use non-secure CPREG bank on access */ int fp_excp_el; /* FP exception EL or 0 if enabled */ int sve_excp_el; /* SVE exception EL or 0 if enabled */ + int sme_excp_el; /* SME exception EL or 0 if enabled */ int vl; /* current vector length in bytes */ /* Flag indicating that exceptions from secure mode are routed to EL3. */ bool secure_routed_to_el3; diff --git a/target/arm/helper.c b/target/arm/helper.c index 616ea70c9e..e0123dce67 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -6222,6 +6222,55 @@ int sve_exception_el(CPUARMState *env, int el) return 0; } +/* + * Return the exception level to which exceptions should be taken for SME. + * C.f. the ARM pseudocode function CheckSMEAccess. + */ +int sme_exception_el(CPUARMState *env, int el) +{ +#ifndef CONFIG_USER_ONLY + if (el <= 1 && !el_is_in_host(env, el)) { + switch (FIELD_EX64(env->cp15.cpacr_el1, CPACR_EL1, SMEN)) { + case 1: + if (el != 0) { + break; + } + /* fall through */ + case 0: + case 2: + return 1; + } + } + + if (el <= 2 && arm_is_el2_enabled(env)) { + /* CPTR_EL2 changes format with HCR_EL2.E2H (regardless of TGE). */ + if (env->cp15.hcr_el2 & HCR_E2H) { + switch (FIELD_EX64(env->cp15.cptr_el[2], CPTR_EL2, SMEN)) { + case 1: + if (el != 0 || !(env->cp15.hcr_el2 & HCR_TGE)) { + break; + } + /* fall through */ + case 0: + case 2: + return 2; + } + } else { + if (FIELD_EX64(env->cp15.cptr_el[2], CPTR_EL2, TSM)) { + return 2; + } + } + } + + /* CPTR_EL3. Since ESM is negative we must check for EL3. */ + if (arm_feature(env, ARM_FEATURE_EL3) + && !FIELD_EX64(env->cp15.cptr_el[3], CPTR_EL3, ESM)) { + return 3; + } +#endif + return 0; +} + /* * Given that SVE is enabled, return the vector length for EL. */ @@ -13719,6 +13768,9 @@ static CPUARMTBFlags rebuild_hflags_a64(CPUARMState *env, int el, int fp_el, } DP_TBFLAG_A64(flags, SVEEXC_EL, sve_el); } + if (cpu_isar_feature(aa64_sme, env_archcpu(env))) { + DP_TBFLAG_A64(flags, SMEEXC_EL, sme_exception_el(env, el)); + } sctlr = regime_sctlr(env, stage1); diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c index d438fb89e7..8bbd1b7f07 100644 --- a/target/arm/translate-a64.c +++ b/target/arm/translate-a64.c @@ -14608,6 +14608,7 @@ static void aarch64_tr_init_disas_context(DisasContextBase *dcbase, dc->align_mem = EX_TBFLAG_ANY(tb_flags, ALIGN_MEM); dc->pstate_il = EX_TBFLAG_ANY(tb_flags, PSTATE__IL); dc->sve_excp_el = EX_TBFLAG_A64(tb_flags, SVEEXC_EL); + dc->sme_excp_el = EX_TBFLAG_A64(tb_flags, SMEEXC_EL); dc->vl = (EX_TBFLAG_A64(tb_flags, VL) + 1) * 16; dc->pauth_active = EX_TBFLAG_A64(tb_flags, PAUTH_ACTIVE); dc->bt = EX_TBFLAG_A64(tb_flags, BT);