From nobody Fri May 17 05:50:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1654315736; cv=none; d=zohomail.com; s=zohoarc; b=D4qrHpSBjWzDj7U4CRA6hCB2zHPYwzHMr+OKCOJ4RHEkDXmh7J/ZzzUYpJkpTb8VBloa3AtsW0G06jmUrQHHbQ3FMVIfdJ2htORw83YrfgQUZw8Y/0+GTttFn5zJuKr6EQ7oC+e6IPgJJZMFpJ3hmAgqHoUFyEmpSMSwkoCBAZ4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1654315736; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=v1YInfzaAA9SifUwQDUL6mgen5CgObSCAov/OgV6gGs=; b=DwiT39/E6arNW63+hVDDLv9gOkMuxAYTN+HgQoRNlElPntEvuNQwQqyxRjdAx6wN4S474hW32QOPpRTWAIHJiNBzQnlufBWrNGVvwDHg5NQOtiqJodXOrxGBwErT/oarVgKTh4IGlPLmZe2zq0vMONWnvQgXl/qZbVs3oRJ0Zlk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1654315736288732.7668216953344; Fri, 3 Jun 2022 21:08:56 -0700 (PDT) Received: from localhost ([::1]:46148 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nxL5q-0001sY-Dk for importer@patchew.org; Sat, 04 Jun 2022 00:08:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36426) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nxL3G-0007VQ-Fu for qemu-devel@nongnu.org; Sat, 04 Jun 2022 00:06:14 -0400 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]:53097) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nxL3E-0008V3-PC for qemu-devel@nongnu.org; Sat, 04 Jun 2022 00:06:14 -0400 Received: by mail-pj1-x102e.google.com with SMTP id gd1so8715234pjb.2 for ; Fri, 03 Jun 2022 21:06:11 -0700 (PDT) Received: from stoup.. ([2602:ae:1547:e101:3286:cc26:3d5e:3f94]) by smtp.gmail.com with ESMTPSA id a37-20020a631a65000000b003c14af50626sm6093779pgm.62.2022.06.03.21.06.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jun 2022 21:06:10 -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=v1YInfzaAA9SifUwQDUL6mgen5CgObSCAov/OgV6gGs=; b=KShepmRT//gHC2o2e57xF4JmK+vnhCKPzXXsyz+SE+/jLTwQuFOGx9JCR8criEsokW FaND9EWWVQIXnhqXBURUSlxFlUZqP4H3Dldfa4DTjycHIxnTQUlMXMqLI6QPhI3oV4hC 4MznhXwHaFOTw0+cUNkEfdkNb+bd1xwauBZAgvDqwEIBiHYCq7rcvPxUmlKJ7InPcXrn MJbPOekfOhyLKRYMHkGahMY8/QB2eikc7T3uEcM3bPXMfvugxrEnevXApQySMGAv5bxg pUZc4i2MwZMpeDzQUs99GfCZg7YItPkWZ+cUthZndGsAJeZNVX0q9pjT2i+BtRUFUMeO dbtg== 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=v1YInfzaAA9SifUwQDUL6mgen5CgObSCAov/OgV6gGs=; b=lEq2LMWX9y7o4fVdf3V6KF9fbooCnpbBJ5ThJ70MBRWDWYmC1Nf4IFPxcR/veb5sIm Rv46Q3Aj0oN3nFWJ/+K8+HX9ZPYOdV1n84a7QkI1kN9AMDv+t+Drss1LFRYbFLpSf1bB xBGuFqXIemxD7NYbSKFvdkaBsMimeUQ5c9lKkMZf2sYwc+eSEgTcnZ/Bu4/D9vK9nW+z ky5WkNVQCuyZBEDXMYgbBRkgv9Bv29cBly7kOFkHK8MtCf+9ZjGlXdlcBo8UHlhitaQ3 EcfxpZDKtatgxsXkxrd8/bRWHhyzseLCNSR760yoz3M0s9AXGm0pYczXvbavet884s9p V8nQ== X-Gm-Message-State: AOAM533s/RYv8D6zTH9gG+EYNQaVOPto9JTzkEtedBU0VacmP9Eaj+rS my/TkJFr+x5mWEEOszP9kOpzjVEZN5TGMg== X-Google-Smtp-Source: ABdhPJyE03WkoB7ez0ScQYv2HNzFy7OANl9wynIDBOlfiNBzjP59zOPy3rVVWje3zRGGEAphjHXYEA== X-Received: by 2002:a17:90b:4b0a:b0:1e3:1823:ca9f with SMTP id lx10-20020a17090b4b0a00b001e31823ca9fmr28760993pjb.12.1654315570436; Fri, 03 Jun 2022 21:06:10 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Subject: [PATCH 01/28] target/arm: Move stage_1_mmu_idx decl to internals.h Date: Fri, 3 Jun 2022 21:05:40 -0700 Message-Id: <20220604040607.269301-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220604040607.269301-1-richard.henderson@linaro.org> References: <20220604040607.269301-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=2607:f8b0:4864:20::102e; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102e.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=ham 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1654315738360100002 Content-Type: text/plain; charset="utf-8" Move the decl from ptw.h to internals.h. Provide an inline version for user-only, just as we do for arm_stage1_mmu_idx. Move an endif down to make the definition in helper.c be system only. Signed-off-by: Richard Henderson --- target/arm/internals.h | 5 +++++ target/arm/helper.c | 5 ++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/target/arm/internals.h b/target/arm/internals.h index b654bee468..72b6af5559 100644 --- a/target/arm/internals.h +++ b/target/arm/internals.h @@ -979,11 +979,16 @@ ARMMMUIdx arm_mmu_idx(CPUARMState *env); * Return the ARMMMUIdx for the stage1 traversal for the current regime. */ #ifdef CONFIG_USER_ONLY +static inline ARMMMUIdx stage_1_mmu_idx(ARMMMUIdx mmu_idx) +{ + return ARMMMUIdx_Stage1_E0; +} static inline ARMMMUIdx arm_stage1_mmu_idx(CPUARMState *env) { return ARMMMUIdx_Stage1_E0; } #else +ARMMMUIdx stage_1_mmu_idx(ARMMMUIdx mmu_idx); ARMMMUIdx arm_stage1_mmu_idx(CPUARMState *env); #endif =20 diff --git a/target/arm/helper.c b/target/arm/helper.c index 40da63913c..d0460d3a0b 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -10481,12 +10481,10 @@ static inline uint64_t regime_ttbr(CPUARMState *e= nv, ARMMMUIdx mmu_idx, } } =20 -#endif /* !CONFIG_USER_ONLY */ - /* Convert a possible stage1+2 MMU index into the appropriate * stage 1 MMU index */ -static inline ARMMMUIdx stage_1_mmu_idx(ARMMMUIdx mmu_idx) +ARMMMUIdx stage_1_mmu_idx(ARMMMUIdx mmu_idx) { switch (mmu_idx) { case ARMMMUIdx_SE10_0: @@ -10505,6 +10503,7 @@ static inline ARMMMUIdx stage_1_mmu_idx(ARMMMUIdx m= mu_idx) return mmu_idx; } } +#endif /* !CONFIG_USER_ONLY */ =20 /* Return true if the translation regime is using LPAE format page tables = */ static inline bool regime_using_lpae_format(CPUARMState *env, --=20 2.34.1 From nobody Fri May 17 05:50:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1654315745; cv=none; d=zohomail.com; s=zohoarc; b=hzNiiqTQbbDi59sHpVdHO44pSKx8KlX3DTP/t+fvAlO57s47rwf0Y5jfh9Mftm0fItMZ8SLbq43fcH4pr0ZvJUiQwzVhUAZgGNO6NqMExqoWmH025wYZUZ5dAfi43gJNZ3nyxUcTXZH4YdbOPIgO0wnJ5+x7uIBJj+xpQrv7LvQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1654315745; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=8yFI42u/8v7jcA6rxKgyA1YiYWIYU06Izir+elftB6M=; b=NUSWgVtrN3Hzqauu/AowA/rB3QSFZz2K/5xFE39JOB0JZY3jACCiXdEFG+4z7/5+Ji6ZLYH3xP3H9gm7MQc4VxRZR+aEm0dybTCBxaDl3JvE1D4XZEdbRD87LC1Z1GGP7vQ0Wcpa9V9euYyxB++UB1rA3s8KIc9BYMDWvlzBZ6k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1654315745612874.3396953580066; Fri, 3 Jun 2022 21:09:05 -0700 (PDT) Received: from localhost ([::1]:46732 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nxL60-0002JG-92 for importer@patchew.org; Sat, 04 Jun 2022 00:09:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36542) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nxL3J-0007aO-Nj for qemu-devel@nongnu.org; Sat, 04 Jun 2022 00:06:17 -0400 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]:38769) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nxL3E-0008VD-W5 for qemu-devel@nongnu.org; Sat, 04 Jun 2022 00:06:17 -0400 Received: by mail-pl1-x636.google.com with SMTP id n18so8119743plg.5 for ; Fri, 03 Jun 2022 21:06:12 -0700 (PDT) Received: from stoup.. ([2602:ae:1547:e101:3286:cc26:3d5e:3f94]) by smtp.gmail.com with ESMTPSA id a37-20020a631a65000000b003c14af50626sm6093779pgm.62.2022.06.03.21.06.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jun 2022 21:06:11 -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=8yFI42u/8v7jcA6rxKgyA1YiYWIYU06Izir+elftB6M=; b=pf/1uNGwnAvg3jjkjp2sMHV329qrFhNc+giqFWSVNMWCoGp64jU/HqC2/tAV80jKFr CbppFqPZVkHiMdrjGL68B30uxmEUnAhxPHKfpUWIeHLEnyW0NjOOrTFuwe1nX44xsVbq sx6uQeE4XY6bMge1KJNi/8rYi4cRYKGm5j6EhNjz/lUYOQolgWSlhIy/sWBMbPyWYpxe 95LhiMJu6u3IKE+sYhHGkOZNc96V8BqlrYwHqS64zyRuo27K6QJBj78REYBTJveCC4pm Nl3Cl0emZ6LH+gchbPuOPD8NPsLK9o9aSJC7sR70FU5ApkmcMyNzRPTxni9Ge1nlz0lI Tw7g== 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=8yFI42u/8v7jcA6rxKgyA1YiYWIYU06Izir+elftB6M=; b=Dv9AKOztLjzcK25GCWmeGFFBJChRvaz4TuPMdCoUu4cBzhQuSEpfAJnrZ8xOaQKmVQ LvIFjrQ076s0xlF8NH+YZqQS4VU7m4fkB6YVuWIIVMWcGBCS6lzfKEOg4e4kAwrakHzp vUauRVrwtfWwTdL4NhxRe2ineTjFLSnLFwE4Yw0CiI30dECrdm0aXsmIOtOn5mFkzMHM ytSW2hLFevZ4eheRQGmOW1BdD4P/tpr+DhGJ2ag7Z/f1Xe4cVMGxOpJc8vRkAj97yCYm NevDEoo27LQpmVkhodiXt6wmQt3gHiDairiJWtAbZrwT+abIu/sQyq7B44cbnv048FsM O/lQ== X-Gm-Message-State: AOAM532APNuI0oQMu+76eHkNOsST153xkaHDAw/3j2HHV43JDm6/y0aN DGTpf8XeM8AAZVfa2WVds5GD0a2UxZ4nUA== X-Google-Smtp-Source: ABdhPJwTkPRVyR1l7wO+C83/mGbZXTR6d5YZ/N3Qf4EyR2FhFaVMDjVlbHUU2kanpcd7Nwwwxzw2Dg== X-Received: by 2002:a17:90b:3141:b0:1e0:6062:9c10 with SMTP id ip1-20020a17090b314100b001e060629c10mr48996575pjb.84.1654315571477; Fri, 03 Jun 2022 21:06:11 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Subject: [PATCH 02/28] target/arm: Move get_phys_addr to ptw.c Date: Fri, 3 Jun 2022 21:05:41 -0700 Message-Id: <20220604040607.269301-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220604040607.269301-1-richard.henderson@linaro.org> References: <20220604040607.269301-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=2607:f8b0:4864:20::636; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x636.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=ham 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1654315746357100003 Content-Type: text/plain; charset="utf-8" Begin moving all of the page table walking functions out of helper.c, starting with get_phys_addr(). Create a temporary header file, "ptw.h", in which to share declarations between the two C files while we are moving functions. Move a few declarations to "internals.h", which will remain used by multiple C files. Signed-off-by: Richard Henderson --- target/arm/internals.h | 18 ++- target/arm/ptw.h | 51 ++++++ target/arm/helper.c | 344 +++++------------------------------------ target/arm/ptw.c | 267 ++++++++++++++++++++++++++++++++ target/arm/meson.build | 1 + 5 files changed, 372 insertions(+), 309 deletions(-) create mode 100644 target/arm/ptw.h create mode 100644 target/arm/ptw.c diff --git a/target/arm/internals.h b/target/arm/internals.h index 72b6af5559..1e32696055 100644 --- a/target/arm/internals.h +++ b/target/arm/internals.h @@ -613,8 +613,13 @@ ARMMMUIdx arm_v7m_mmu_idx_for_secstate_and_priv(CPUARM= State *env, /* Return the MMU index for a v7M CPU in the specified security state */ ARMMMUIdx arm_v7m_mmu_idx_for_secstate(CPUARMState *env, bool secstate); =20 -/* Return true if the stage 1 translation regime is using LPAE format page - * tables */ +/* Return true if the translation regime is using LPAE format page tables = */ +bool regime_using_lpae_format(CPUARMState *env, ARMMMUIdx mmu_idx); + +/* + * Return true if the stage 1 translation regime is using LPAE + * format page tables + */ bool arm_s1_regime_using_lpae_format(CPUARMState *env, ARMMMUIdx mmu_idx); =20 /* Raise a data fault alignment exception for the specified virtual addres= s */ @@ -777,6 +782,12 @@ static inline uint32_t regime_el(CPUARMState *env, ARM= MMUIdx mmu_idx) } } =20 +/* Return the SCTLR value which controls this address translation regime */ +static inline uint64_t regime_sctlr(CPUARMState *env, ARMMMUIdx mmu_idx) +{ + return env->cp15.sctlr_el[regime_el(env, mmu_idx)]; +} + /* Return the TCR controlling this translation regime */ static inline TCR *regime_tcr(CPUARMState *env, ARMMMUIdx mmu_idx) { @@ -1095,6 +1106,9 @@ typedef struct ARMVAParameters { ARMVAParameters aa64_va_parameters(CPUARMState *env, uint64_t va, ARMMMUIdx mmu_idx, bool data); =20 +int aa64_va_parameter_tbi(uint64_t tcr, ARMMMUIdx mmu_idx); +int aa64_va_parameter_tbid(uint64_t tcr, ARMMMUIdx mmu_idx); + static inline int exception_target_el(CPUARMState *env) { int target_el =3D MAX(1, arm_current_el(env)); diff --git a/target/arm/ptw.h b/target/arm/ptw.h new file mode 100644 index 0000000000..e2023ae750 --- /dev/null +++ b/target/arm/ptw.h @@ -0,0 +1,51 @@ +/* + * ARM page table walking. + * + * This code is licensed under the GNU GPL v2 or later. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef TARGET_ARM_PTW_H +#define TARGET_ARM_PTW_H + +#ifndef CONFIG_USER_ONLY + +bool regime_is_user(CPUARMState *env, ARMMMUIdx mmu_idx); +bool regime_translation_disabled(CPUARMState *env, ARMMMUIdx mmu_idx); +ARMCacheAttrs combine_cacheattrs(CPUARMState *env, + ARMCacheAttrs s1, ARMCacheAttrs s2); + +bool get_phys_addr_v5(CPUARMState *env, uint32_t address, + MMUAccessType access_type, ARMMMUIdx mmu_idx, + hwaddr *phys_ptr, int *prot, + target_ulong *page_size, + ARMMMUFaultInfo *fi); +bool get_phys_addr_pmsav5(CPUARMState *env, uint32_t address, + MMUAccessType access_type, ARMMMUIdx mmu_idx, + hwaddr *phys_ptr, int *prot, + ARMMMUFaultInfo *fi); +bool get_phys_addr_v6(CPUARMState *env, uint32_t address, + MMUAccessType access_type, ARMMMUIdx mmu_idx, + hwaddr *phys_ptr, MemTxAttrs *attrs, int *prot, + target_ulong *page_size, ARMMMUFaultInfo *fi); +bool get_phys_addr_pmsav7(CPUARMState *env, uint32_t address, + MMUAccessType access_type, ARMMMUIdx mmu_idx, + hwaddr *phys_ptr, int *prot, + target_ulong *page_size, + ARMMMUFaultInfo *fi); +bool get_phys_addr_pmsav8(CPUARMState *env, uint32_t address, + MMUAccessType access_type, ARMMMUIdx mmu_idx, + hwaddr *phys_ptr, MemTxAttrs *txattrs, + int *prot, target_ulong *page_size, + ARMMMUFaultInfo *fi); +bool get_phys_addr_lpae(CPUARMState *env, uint64_t address, + MMUAccessType access_type, ARMMMUIdx mmu_idx, + bool s1_is_el0, + hwaddr *phys_ptr, MemTxAttrs *txattrs, int *prot, + target_ulong *page_size_ptr, + ARMMMUFaultInfo *fi, ARMCacheAttrs *cacheattrs) + __attribute__((nonnull)); + +#endif /* !CONFIG_USER_ONLY */ +#endif /* TARGET_ARM_PTW_H */ diff --git a/target/arm/helper.c b/target/arm/helper.c index d0460d3a0b..7015ce4efc 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -37,22 +37,11 @@ #include "semihosting/common-semi.h" #endif #include "cpregs.h" +#include "ptw.h" =20 #define ARM_CPU_FREQ 1000000000 /* FIXME: 1 GHz, should be configurable */ =20 -#ifndef CONFIG_USER_ONLY - -static bool get_phys_addr_lpae(CPUARMState *env, uint64_t address, - MMUAccessType access_type, ARMMMUIdx mmu_id= x, - bool s1_is_el0, - hwaddr *phys_ptr, MemTxAttrs *txattrs, int = *prot, - target_ulong *page_size_ptr, - ARMMMUFaultInfo *fi, ARMCacheAttrs *cacheat= trs) - __attribute__((nonnull)); -#endif - static void switch_mode(CPUARMState *env, int mode); -static int aa64_va_parameter_tbi(uint64_t tcr, ARMMMUIdx mmu_idx); =20 static uint64_t raw_read(CPUARMState *env, const ARMCPRegInfo *ri) { @@ -10404,17 +10393,10 @@ uint64_t arm_sctlr(CPUARMState *env, int el) return env->cp15.sctlr_el[el]; } =20 -/* Return the SCTLR value which controls this address translation regime */ -static inline uint64_t regime_sctlr(CPUARMState *env, ARMMMUIdx mmu_idx) -{ - return env->cp15.sctlr_el[regime_el(env, mmu_idx)]; -} - #ifndef CONFIG_USER_ONLY =20 /* Return true if the specified stage of address translation is disabled */ -static inline bool regime_translation_disabled(CPUARMState *env, - ARMMMUIdx mmu_idx) +bool regime_translation_disabled(CPUARMState *env, ARMMMUIdx mmu_idx) { uint64_t hcr_el2; =20 @@ -10506,8 +10488,7 @@ ARMMMUIdx stage_1_mmu_idx(ARMMMUIdx mmu_idx) #endif /* !CONFIG_USER_ONLY */ =20 /* Return true if the translation regime is using LPAE format page tables = */ -static inline bool regime_using_lpae_format(CPUARMState *env, - ARMMMUIdx mmu_idx) +bool regime_using_lpae_format(CPUARMState *env, ARMMMUIdx mmu_idx) { int el =3D regime_el(env, mmu_idx); if (el =3D=3D 2 || arm_el_is_aa64(env, el)) { @@ -10531,7 +10512,7 @@ bool arm_s1_regime_using_lpae_format(CPUARMState *e= nv, ARMMMUIdx mmu_idx) } =20 #ifndef CONFIG_USER_ONLY -static inline bool regime_is_user(CPUARMState *env, ARMMMUIdx mmu_idx) +bool regime_is_user(CPUARMState *env, ARMMMUIdx mmu_idx) { switch (mmu_idx) { case ARMMMUIdx_SE10_0: @@ -10923,11 +10904,11 @@ static uint64_t arm_ldq_ptw(CPUState *cs, hwaddr = addr, bool is_secure, return 0; } =20 -static bool get_phys_addr_v5(CPUARMState *env, uint32_t address, - MMUAccessType access_type, ARMMMUIdx mmu_idx, - hwaddr *phys_ptr, int *prot, - target_ulong *page_size, - ARMMMUFaultInfo *fi) +bool get_phys_addr_v5(CPUARMState *env, uint32_t address, + MMUAccessType access_type, ARMMMUIdx mmu_idx, + hwaddr *phys_ptr, int *prot, + target_ulong *page_size, + ARMMMUFaultInfo *fi) { CPUState *cs =3D env_cpu(env); int level =3D 1; @@ -11045,10 +11026,10 @@ do_fault: return true; } =20 -static bool get_phys_addr_v6(CPUARMState *env, uint32_t address, - MMUAccessType access_type, ARMMMUIdx mmu_idx, - hwaddr *phys_ptr, MemTxAttrs *attrs, int *pro= t, - target_ulong *page_size, ARMMMUFaultInfo *fi) +bool get_phys_addr_v6(CPUARMState *env, uint32_t address, + MMUAccessType access_type, ARMMMUIdx mmu_idx, + hwaddr *phys_ptr, MemTxAttrs *attrs, int *prot, + target_ulong *page_size, ARMMMUFaultInfo *fi) { CPUState *cs =3D env_cpu(env); ARMCPU *cpu =3D env_archcpu(env); @@ -11324,7 +11305,7 @@ unsigned int arm_pamax(ARMCPU *cpu) return pamax_map[parange]; } =20 -static int aa64_va_parameter_tbi(uint64_t tcr, ARMMMUIdx mmu_idx) +int aa64_va_parameter_tbi(uint64_t tcr, ARMMMUIdx mmu_idx) { if (regime_has_2_ranges(mmu_idx)) { return extract64(tcr, 37, 2); @@ -11336,7 +11317,7 @@ static int aa64_va_parameter_tbi(uint64_t tcr, ARMM= MUIdx mmu_idx) } } =20 -static int aa64_va_parameter_tbid(uint64_t tcr, ARMMMUIdx mmu_idx) +int aa64_va_parameter_tbid(uint64_t tcr, ARMMMUIdx mmu_idx) { if (regime_has_2_ranges(mmu_idx)) { return extract64(tcr, 51, 2); @@ -11566,12 +11547,12 @@ static ARMVAParameters aa32_va_parameters(CPUARMS= tate *env, uint32_t va, * @fi: set to fault info if the translation fails * @cacheattrs: (if non-NULL) set to the cacheability/shareability attribu= tes */ -static bool get_phys_addr_lpae(CPUARMState *env, uint64_t address, - MMUAccessType access_type, ARMMMUIdx mmu_id= x, - bool s1_is_el0, - hwaddr *phys_ptr, MemTxAttrs *txattrs, int = *prot, - target_ulong *page_size_ptr, - ARMMMUFaultInfo *fi, ARMCacheAttrs *cacheat= trs) +bool get_phys_addr_lpae(CPUARMState *env, uint64_t address, + MMUAccessType access_type, ARMMMUIdx mmu_idx, + bool s1_is_el0, + hwaddr *phys_ptr, MemTxAttrs *txattrs, int *prot, + target_ulong *page_size_ptr, + ARMMMUFaultInfo *fi, ARMCacheAttrs *cacheattrs) { ARMCPU *cpu =3D env_archcpu(env); CPUState *cs =3D CPU(cpu); @@ -12019,11 +12000,11 @@ static inline bool m_is_system_region(CPUARMState= *env, uint32_t address) return arm_feature(env, ARM_FEATURE_M) && extract32(address, 29, 3) = =3D=3D 0x7; } =20 -static bool get_phys_addr_pmsav7(CPUARMState *env, uint32_t address, - MMUAccessType access_type, ARMMMUIdx mmu_= idx, - hwaddr *phys_ptr, int *prot, - target_ulong *page_size, - ARMMMUFaultInfo *fi) +bool get_phys_addr_pmsav7(CPUARMState *env, uint32_t address, + MMUAccessType access_type, ARMMMUIdx mmu_idx, + hwaddr *phys_ptr, int *prot, + target_ulong *page_size, + ARMMMUFaultInfo *fi) { ARMCPU *cpu =3D env_archcpu(env); int n; @@ -12465,11 +12446,11 @@ bool pmsav8_mpu_lookup(CPUARMState *env, uint32_t= address, } =20 =20 -static bool get_phys_addr_pmsav8(CPUARMState *env, uint32_t address, - MMUAccessType access_type, ARMMMUIdx mmu_= idx, - hwaddr *phys_ptr, MemTxAttrs *txattrs, - int *prot, target_ulong *page_size, - ARMMMUFaultInfo *fi) +bool get_phys_addr_pmsav8(CPUARMState *env, uint32_t address, + MMUAccessType access_type, ARMMMUIdx mmu_idx, + hwaddr *phys_ptr, MemTxAttrs *txattrs, + int *prot, target_ulong *page_size, + ARMMMUFaultInfo *fi) { uint32_t secure =3D regime_is_secure(env, mmu_idx); V8M_SAttributes sattrs =3D {}; @@ -12539,10 +12520,10 @@ static bool get_phys_addr_pmsav8(CPUARMState *env= , uint32_t address, return ret; } =20 -static bool get_phys_addr_pmsav5(CPUARMState *env, uint32_t address, - MMUAccessType access_type, ARMMMUIdx mmu_= idx, - hwaddr *phys_ptr, int *prot, - ARMMMUFaultInfo *fi) +bool get_phys_addr_pmsav5(CPUARMState *env, uint32_t address, + MMUAccessType access_type, ARMMMUIdx mmu_idx, + hwaddr *phys_ptr, int *prot, + ARMMMUFaultInfo *fi) { int n; uint32_t mask; @@ -12759,8 +12740,8 @@ static uint8_t combined_attrs_fwb(CPUARMState *env, * @s1: Attributes from stage 1 walk * @s2: Attributes from stage 2 walk */ -static ARMCacheAttrs combine_cacheattrs(CPUARMState *env, - ARMCacheAttrs s1, ARMCacheAttrs s2) +ARMCacheAttrs combine_cacheattrs(CPUARMState *env, + ARMCacheAttrs s1, ARMCacheAttrs s2) { ARMCacheAttrs ret; bool tagged =3D false; @@ -12812,256 +12793,6 @@ static ARMCacheAttrs combine_cacheattrs(CPUARMSta= te *env, return ret; } =20 - -/* get_phys_addr - get the physical address for this virtual address - * - * Find the physical address corresponding to the given virtual address, - * by doing a translation table walk on MMU based systems or using the - * MPU state on MPU based systems. - * - * Returns false if the translation was successful. Otherwise, phys_ptr, a= ttrs, - * prot and page_size may not be filled in, and the populated fsr value pr= ovides - * information on why the translation aborted, in the format of a - * DFSR/IFSR fault register, with the following caveats: - * * we honour the short vs long DFSR format differences. - * * the WnR bit is never set (the caller must do this). - * * for PSMAv5 based systems we don't bother to return a full FSR format - * value. - * - * @env: CPUARMState - * @address: virtual address to get physical address for - * @access_type: 0 for read, 1 for write, 2 for execute - * @mmu_idx: MMU index indicating required translation regime - * @phys_ptr: set to the physical address corresponding to the virtual add= ress - * @attrs: set to the memory transaction attributes to use - * @prot: set to the permissions for the page containing phys_ptr - * @page_size: set to the size of the page containing phys_ptr - * @fi: set to fault info if the translation fails - * @cacheattrs: (if non-NULL) set to the cacheability/shareability attribu= tes - */ -bool get_phys_addr(CPUARMState *env, target_ulong address, - MMUAccessType access_type, ARMMMUIdx mmu_idx, - hwaddr *phys_ptr, MemTxAttrs *attrs, int *prot, - target_ulong *page_size, - ARMMMUFaultInfo *fi, ARMCacheAttrs *cacheattrs) -{ - ARMMMUIdx s1_mmu_idx =3D stage_1_mmu_idx(mmu_idx); - - if (mmu_idx !=3D s1_mmu_idx) { - /* Call ourselves recursively to do the stage 1 and then stage 2 - * translations if mmu_idx is a two-stage regime. - */ - if (arm_feature(env, ARM_FEATURE_EL2)) { - hwaddr ipa; - int s2_prot; - int ret; - bool ipa_secure; - ARMCacheAttrs cacheattrs2 =3D {}; - ARMMMUIdx s2_mmu_idx; - bool is_el0; - - ret =3D get_phys_addr(env, address, access_type, s1_mmu_idx, &= ipa, - attrs, prot, page_size, fi, cacheattrs); - - /* If S1 fails or S2 is disabled, return early. */ - if (ret || regime_translation_disabled(env, ARMMMUIdx_Stage2))= { - *phys_ptr =3D ipa; - return ret; - } - - ipa_secure =3D attrs->secure; - if (arm_is_secure_below_el3(env)) { - if (ipa_secure) { - attrs->secure =3D !(env->cp15.vstcr_el2.raw_tcr & VSTC= R_SW); - } else { - attrs->secure =3D !(env->cp15.vtcr_el2.raw_tcr & VTCR_= NSW); - } - } else { - assert(!ipa_secure); - } - - s2_mmu_idx =3D attrs->secure ? ARMMMUIdx_Stage2_S : ARMMMUIdx_= Stage2; - is_el0 =3D mmu_idx =3D=3D ARMMMUIdx_E10_0 || mmu_idx =3D=3D AR= MMMUIdx_SE10_0; - - /* S1 is done. Now do S2 translation. */ - ret =3D get_phys_addr_lpae(env, ipa, access_type, s2_mmu_idx, = is_el0, - phys_ptr, attrs, &s2_prot, - page_size, fi, &cacheattrs2); - fi->s2addr =3D ipa; - /* Combine the S1 and S2 perms. */ - *prot &=3D s2_prot; - - /* If S2 fails, return early. */ - if (ret) { - return ret; - } - - /* Combine the S1 and S2 cache attributes. */ - if (arm_hcr_el2_eff(env) & HCR_DC) { - /* - * HCR.DC forces the first stage attributes to - * Normal Non-Shareable, - * Inner Write-Back Read-Allocate Write-Allocate, - * Outer Write-Back Read-Allocate Write-Allocate. - * Do not overwrite Tagged within attrs. - */ - if (cacheattrs->attrs !=3D 0xf0) { - cacheattrs->attrs =3D 0xff; - } - cacheattrs->shareability =3D 0; - } - *cacheattrs =3D combine_cacheattrs(env, *cacheattrs, cacheattr= s2); - - /* Check if IPA translates to secure or non-secure PA space. */ - if (arm_is_secure_below_el3(env)) { - if (ipa_secure) { - attrs->secure =3D - !(env->cp15.vstcr_el2.raw_tcr & (VSTCR_SA | VSTCR_= SW)); - } else { - attrs->secure =3D - !((env->cp15.vtcr_el2.raw_tcr & (VTCR_NSA | VTCR_N= SW)) - || (env->cp15.vstcr_el2.raw_tcr & (VSTCR_SA | VSTC= R_SW))); - } - } - return 0; - } else { - /* - * For non-EL2 CPUs a stage1+stage2 translation is just stage = 1. - */ - mmu_idx =3D stage_1_mmu_idx(mmu_idx); - } - } - - /* The page table entries may downgrade secure to non-secure, but - * cannot upgrade an non-secure translation regime's attributes - * to secure. - */ - attrs->secure =3D regime_is_secure(env, mmu_idx); - attrs->user =3D regime_is_user(env, mmu_idx); - - /* Fast Context Switch Extension. This doesn't exist at all in v8. - * In v7 and earlier it affects all stage 1 translations. - */ - if (address < 0x02000000 && mmu_idx !=3D ARMMMUIdx_Stage2 - && !arm_feature(env, ARM_FEATURE_V8)) { - if (regime_el(env, mmu_idx) =3D=3D 3) { - address +=3D env->cp15.fcseidr_s; - } else { - address +=3D env->cp15.fcseidr_ns; - } - } - - if (arm_feature(env, ARM_FEATURE_PMSA)) { - bool ret; - *page_size =3D TARGET_PAGE_SIZE; - - if (arm_feature(env, ARM_FEATURE_V8)) { - /* PMSAv8 */ - ret =3D get_phys_addr_pmsav8(env, address, access_type, mmu_id= x, - phys_ptr, attrs, prot, page_size, f= i); - } else if (arm_feature(env, ARM_FEATURE_V7)) { - /* PMSAv7 */ - ret =3D get_phys_addr_pmsav7(env, address, access_type, mmu_id= x, - phys_ptr, prot, page_size, fi); - } else { - /* Pre-v7 MPU */ - ret =3D get_phys_addr_pmsav5(env, address, access_type, mmu_id= x, - phys_ptr, prot, fi); - } - qemu_log_mask(CPU_LOG_MMU, "PMSA MPU lookup for %s at 0x%08" PRIx32 - " mmu_idx %u -> %s (prot %c%c%c)\n", - access_type =3D=3D MMU_DATA_LOAD ? "reading" : - (access_type =3D=3D MMU_DATA_STORE ? "writing" : "ex= ecute"), - (uint32_t)address, mmu_idx, - ret ? "Miss" : "Hit", - *prot & PAGE_READ ? 'r' : '-', - *prot & PAGE_WRITE ? 'w' : '-', - *prot & PAGE_EXEC ? 'x' : '-'); - - return ret; - } - - /* Definitely a real MMU, not an MPU */ - - if (regime_translation_disabled(env, mmu_idx)) { - uint64_t hcr; - uint8_t memattr; - - /* - * MMU disabled. S1 addresses within aa64 translation regimes are - * still checked for bounds -- see AArch64.TranslateAddressS1Off. - */ - if (mmu_idx !=3D ARMMMUIdx_Stage2 && mmu_idx !=3D ARMMMUIdx_Stage2= _S) { - int r_el =3D regime_el(env, mmu_idx); - if (arm_el_is_aa64(env, r_el)) { - int pamax =3D arm_pamax(env_archcpu(env)); - uint64_t tcr =3D env->cp15.tcr_el[r_el].raw_tcr; - int addrtop, tbi; - - tbi =3D aa64_va_parameter_tbi(tcr, mmu_idx); - if (access_type =3D=3D MMU_INST_FETCH) { - tbi &=3D ~aa64_va_parameter_tbid(tcr, mmu_idx); - } - tbi =3D (tbi >> extract64(address, 55, 1)) & 1; - addrtop =3D (tbi ? 55 : 63); - - if (extract64(address, pamax, addrtop - pamax + 1) !=3D 0)= { - fi->type =3D ARMFault_AddressSize; - fi->level =3D 0; - fi->stage2 =3D false; - return 1; - } - - /* - * When TBI is disabled, we've just validated that all of = the - * bits above PAMax are zero, so logically we only need to - * clear the top byte for TBI. But it's clearer to follow - * the pseudocode set of addrdesc.paddress. - */ - address =3D extract64(address, 0, 52); - } - } - *phys_ptr =3D address; - *prot =3D PAGE_READ | PAGE_WRITE | PAGE_EXEC; - *page_size =3D TARGET_PAGE_SIZE; - - /* Fill in cacheattr a-la AArch64.TranslateAddressS1Off. */ - hcr =3D arm_hcr_el2_eff(env); - cacheattrs->shareability =3D 0; - cacheattrs->is_s2_format =3D false; - if (hcr & HCR_DC) { - if (hcr & HCR_DCT) { - memattr =3D 0xf0; /* Tagged, Normal, WB, RWA */ - } else { - memattr =3D 0xff; /* Normal, WB, RWA */ - } - } else if (access_type =3D=3D MMU_INST_FETCH) { - if (regime_sctlr(env, mmu_idx) & SCTLR_I) { - memattr =3D 0xee; /* Normal, WT, RA, NT */ - } else { - memattr =3D 0x44; /* Normal, NC, No */ - } - cacheattrs->shareability =3D 2; /* outer sharable */ - } else { - memattr =3D 0x00; /* Device, nGnRnE */ - } - cacheattrs->attrs =3D memattr; - return 0; - } - - if (regime_using_lpae_format(env, mmu_idx)) { - return get_phys_addr_lpae(env, address, access_type, mmu_idx, fals= e, - phys_ptr, attrs, prot, page_size, - fi, cacheattrs); - } else if (regime_sctlr(env, mmu_idx) & SCTLR_XP) { - return get_phys_addr_v6(env, address, access_type, mmu_idx, - phys_ptr, attrs, prot, page_size, fi); - } else { - return get_phys_addr_v5(env, address, access_type, mmu_idx, - phys_ptr, prot, page_size, fi); - } -} - hwaddr arm_cpu_get_phys_page_attrs_debug(CPUState *cs, vaddr addr, MemTxAttrs *attrs) { @@ -13085,7 +12816,6 @@ hwaddr arm_cpu_get_phys_page_attrs_debug(CPUState *= cs, vaddr addr, } return phys_addr; } - #endif =20 /* Note that signed overflow is undefined in C. The following routines are diff --git a/target/arm/ptw.c b/target/arm/ptw.c new file mode 100644 index 0000000000..318000f6d9 --- /dev/null +++ b/target/arm/ptw.c @@ -0,0 +1,267 @@ +/* + * ARM page table walking. + * + * This code is licensed under the GNU GPL v2 or later. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "qemu/log.h" +#include "cpu.h" +#include "internals.h" +#include "ptw.h" + + +/** + * get_phys_addr - get the physical address for this virtual address + * + * Find the physical address corresponding to the given virtual address, + * by doing a translation table walk on MMU based systems or using the + * MPU state on MPU based systems. + * + * Returns false if the translation was successful. Otherwise, phys_ptr, a= ttrs, + * prot and page_size may not be filled in, and the populated fsr value pr= ovides + * information on why the translation aborted, in the format of a + * DFSR/IFSR fault register, with the following caveats: + * * we honour the short vs long DFSR format differences. + * * the WnR bit is never set (the caller must do this). + * * for PSMAv5 based systems we don't bother to return a full FSR format + * value. + * + * @env: CPUARMState + * @address: virtual address to get physical address for + * @access_type: 0 for read, 1 for write, 2 for execute + * @mmu_idx: MMU index indicating required translation regime + * @phys_ptr: set to the physical address corresponding to the virtual add= ress + * @attrs: set to the memory transaction attributes to use + * @prot: set to the permissions for the page containing phys_ptr + * @page_size: set to the size of the page containing phys_ptr + * @fi: set to fault info if the translation fails + * @cacheattrs: (if non-NULL) set to the cacheability/shareability attribu= tes + */ +bool get_phys_addr(CPUARMState *env, target_ulong address, + MMUAccessType access_type, ARMMMUIdx mmu_idx, + hwaddr *phys_ptr, MemTxAttrs *attrs, int *prot, + target_ulong *page_size, + ARMMMUFaultInfo *fi, ARMCacheAttrs *cacheattrs) +{ + ARMMMUIdx s1_mmu_idx =3D stage_1_mmu_idx(mmu_idx); + + if (mmu_idx !=3D s1_mmu_idx) { + /* + * Call ourselves recursively to do the stage 1 and then stage 2 + * translations if mmu_idx is a two-stage regime. + */ + if (arm_feature(env, ARM_FEATURE_EL2)) { + hwaddr ipa; + int s2_prot; + int ret; + bool ipa_secure; + ARMCacheAttrs cacheattrs2 =3D {}; + ARMMMUIdx s2_mmu_idx; + bool is_el0; + + ret =3D get_phys_addr(env, address, access_type, s1_mmu_idx, &= ipa, + attrs, prot, page_size, fi, cacheattrs); + + /* If S1 fails or S2 is disabled, return early. */ + if (ret || regime_translation_disabled(env, ARMMMUIdx_Stage2))= { + *phys_ptr =3D ipa; + return ret; + } + + ipa_secure =3D attrs->secure; + if (arm_is_secure_below_el3(env)) { + if (ipa_secure) { + attrs->secure =3D !(env->cp15.vstcr_el2.raw_tcr & VSTC= R_SW); + } else { + attrs->secure =3D !(env->cp15.vtcr_el2.raw_tcr & VTCR_= NSW); + } + } else { + assert(!ipa_secure); + } + + s2_mmu_idx =3D attrs->secure ? ARMMMUIdx_Stage2_S : ARMMMUIdx_= Stage2; + is_el0 =3D mmu_idx =3D=3D ARMMMUIdx_E10_0 || mmu_idx =3D=3D AR= MMMUIdx_SE10_0; + + /* S1 is done. Now do S2 translation. */ + ret =3D get_phys_addr_lpae(env, ipa, access_type, s2_mmu_idx, = is_el0, + phys_ptr, attrs, &s2_prot, + page_size, fi, &cacheattrs2); + fi->s2addr =3D ipa; + /* Combine the S1 and S2 perms. */ + *prot &=3D s2_prot; + + /* If S2 fails, return early. */ + if (ret) { + return ret; + } + + /* Combine the S1 and S2 cache attributes. */ + if (arm_hcr_el2_eff(env) & HCR_DC) { + /* + * HCR.DC forces the first stage attributes to + * Normal Non-Shareable, + * Inner Write-Back Read-Allocate Write-Allocate, + * Outer Write-Back Read-Allocate Write-Allocate. + * Do not overwrite Tagged within attrs. + */ + if (cacheattrs->attrs !=3D 0xf0) { + cacheattrs->attrs =3D 0xff; + } + cacheattrs->shareability =3D 0; + } + *cacheattrs =3D combine_cacheattrs(env, *cacheattrs, cacheattr= s2); + + /* Check if IPA translates to secure or non-secure PA space. */ + if (arm_is_secure_below_el3(env)) { + if (ipa_secure) { + attrs->secure =3D + !(env->cp15.vstcr_el2.raw_tcr & (VSTCR_SA | VSTCR_= SW)); + } else { + attrs->secure =3D + !((env->cp15.vtcr_el2.raw_tcr & (VTCR_NSA | VTCR_N= SW)) + || (env->cp15.vstcr_el2.raw_tcr & (VSTCR_SA | VSTC= R_SW))); + } + } + return 0; + } else { + /* + * For non-EL2 CPUs a stage1+stage2 translation is just stage = 1. + */ + mmu_idx =3D stage_1_mmu_idx(mmu_idx); + } + } + + /* + * The page table entries may downgrade secure to non-secure, but + * cannot upgrade an non-secure translation regime's attributes + * to secure. + */ + attrs->secure =3D regime_is_secure(env, mmu_idx); + attrs->user =3D regime_is_user(env, mmu_idx); + + /* + * Fast Context Switch Extension. This doesn't exist at all in v8. + * In v7 and earlier it affects all stage 1 translations. + */ + if (address < 0x02000000 && mmu_idx !=3D ARMMMUIdx_Stage2 + && !arm_feature(env, ARM_FEATURE_V8)) { + if (regime_el(env, mmu_idx) =3D=3D 3) { + address +=3D env->cp15.fcseidr_s; + } else { + address +=3D env->cp15.fcseidr_ns; + } + } + + if (arm_feature(env, ARM_FEATURE_PMSA)) { + bool ret; + *page_size =3D TARGET_PAGE_SIZE; + + if (arm_feature(env, ARM_FEATURE_V8)) { + /* PMSAv8 */ + ret =3D get_phys_addr_pmsav8(env, address, access_type, mmu_id= x, + phys_ptr, attrs, prot, page_size, f= i); + } else if (arm_feature(env, ARM_FEATURE_V7)) { + /* PMSAv7 */ + ret =3D get_phys_addr_pmsav7(env, address, access_type, mmu_id= x, + phys_ptr, prot, page_size, fi); + } else { + /* Pre-v7 MPU */ + ret =3D get_phys_addr_pmsav5(env, address, access_type, mmu_id= x, + phys_ptr, prot, fi); + } + qemu_log_mask(CPU_LOG_MMU, "PMSA MPU lookup for %s at 0x%08" PRIx32 + " mmu_idx %u -> %s (prot %c%c%c)\n", + access_type =3D=3D MMU_DATA_LOAD ? "reading" : + (access_type =3D=3D MMU_DATA_STORE ? "writing" : "ex= ecute"), + (uint32_t)address, mmu_idx, + ret ? "Miss" : "Hit", + *prot & PAGE_READ ? 'r' : '-', + *prot & PAGE_WRITE ? 'w' : '-', + *prot & PAGE_EXEC ? 'x' : '-'); + + return ret; + } + + /* Definitely a real MMU, not an MPU */ + + if (regime_translation_disabled(env, mmu_idx)) { + uint64_t hcr; + uint8_t memattr; + + /* + * MMU disabled. S1 addresses within aa64 translation regimes are + * still checked for bounds -- see AArch64.TranslateAddressS1Off. + */ + if (mmu_idx !=3D ARMMMUIdx_Stage2 && mmu_idx !=3D ARMMMUIdx_Stage2= _S) { + int r_el =3D regime_el(env, mmu_idx); + if (arm_el_is_aa64(env, r_el)) { + int pamax =3D arm_pamax(env_archcpu(env)); + uint64_t tcr =3D env->cp15.tcr_el[r_el].raw_tcr; + int addrtop, tbi; + + tbi =3D aa64_va_parameter_tbi(tcr, mmu_idx); + if (access_type =3D=3D MMU_INST_FETCH) { + tbi &=3D ~aa64_va_parameter_tbid(tcr, mmu_idx); + } + tbi =3D (tbi >> extract64(address, 55, 1)) & 1; + addrtop =3D (tbi ? 55 : 63); + + if (extract64(address, pamax, addrtop - pamax + 1) !=3D 0)= { + fi->type =3D ARMFault_AddressSize; + fi->level =3D 0; + fi->stage2 =3D false; + return 1; + } + + /* + * When TBI is disabled, we've just validated that all of = the + * bits above PAMax are zero, so logically we only need to + * clear the top byte for TBI. But it's clearer to follow + * the pseudocode set of addrdesc.paddress. + */ + address =3D extract64(address, 0, 52); + } + } + *phys_ptr =3D address; + *prot =3D PAGE_READ | PAGE_WRITE | PAGE_EXEC; + *page_size =3D TARGET_PAGE_SIZE; + + /* Fill in cacheattr a-la AArch64.TranslateAddressS1Off. */ + hcr =3D arm_hcr_el2_eff(env); + cacheattrs->shareability =3D 0; + cacheattrs->is_s2_format =3D false; + if (hcr & HCR_DC) { + if (hcr & HCR_DCT) { + memattr =3D 0xf0; /* Tagged, Normal, WB, RWA */ + } else { + memattr =3D 0xff; /* Normal, WB, RWA */ + } + } else if (access_type =3D=3D MMU_INST_FETCH) { + if (regime_sctlr(env, mmu_idx) & SCTLR_I) { + memattr =3D 0xee; /* Normal, WT, RA, NT */ + } else { + memattr =3D 0x44; /* Normal, NC, No */ + } + cacheattrs->shareability =3D 2; /* outer sharable */ + } else { + memattr =3D 0x00; /* Device, nGnRnE */ + } + cacheattrs->attrs =3D memattr; + return 0; + } + + if (regime_using_lpae_format(env, mmu_idx)) { + return get_phys_addr_lpae(env, address, access_type, mmu_idx, fals= e, + phys_ptr, attrs, prot, page_size, + fi, cacheattrs); + } else if (regime_sctlr(env, mmu_idx) & SCTLR_XP) { + return get_phys_addr_v6(env, address, access_type, mmu_idx, + phys_ptr, attrs, prot, page_size, fi); + } else { + return get_phys_addr_v5(env, address, access_type, mmu_idx, + phys_ptr, prot, page_size, fi); + } +} diff --git a/target/arm/meson.build b/target/arm/meson.build index 50f152214a..ac571fc45d 100644 --- a/target/arm/meson.build +++ b/target/arm/meson.build @@ -58,6 +58,7 @@ arm_softmmu_ss.add(files( 'machine.c', 'monitor.c', 'psci.c', + 'ptw.c', )) =20 subdir('hvf') --=20 2.34.1 From nobody Fri May 17 05:50:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1654315742; cv=none; d=zohomail.com; s=zohoarc; b=irpGm++xuVXWjQDJnfa/dbNQp2Hx7YTYk12I+byVlj6mN8rNMPiamH72Hzaj1WreJ5Mv9LyGjiszU5U8lz7uafEq8BhT9W/A9MgP24y5gq11t1rAc4sZo/d/LvOCIjevJcFFIETVJNsItCCK1RFrb5x7dYXSw2kngdo+lk2hhNU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1654315742; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=piEshlp2jFC/OdebizTApyzI+JWPnaYL97UZKb5EMwo=; b=mv30+gN3WcwNcUIR+AHNqOvavnlK4eaFCD6Ogns0NpwfCWXi8Zw4XmWz2Frmq6JNQrNr+VvJqQ2iN8iU19gj8hqn9XOo+sP1Ee/g0G2WM0BPoFI9tBb9+8y7EgRqneA8GlW2gukpSpiQBXmcyThpFEKTQNh5TfB3415buHbGHn0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1654315742786619.4101169306476; Fri, 3 Jun 2022 21:09:02 -0700 (PDT) Received: from localhost ([::1]:46602 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nxL5x-0002Br-Lr for importer@patchew.org; Sat, 04 Jun 2022 00:09:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36488) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nxL3I-0007XS-Br for qemu-devel@nongnu.org; Sat, 04 Jun 2022 00:06:16 -0400 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]:37460) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nxL3F-0008VL-Sa for qemu-devel@nongnu.org; Sat, 04 Jun 2022 00:06:16 -0400 Received: by mail-pl1-x636.google.com with SMTP id t2so8119464pld.4 for ; Fri, 03 Jun 2022 21:06:13 -0700 (PDT) Received: from stoup.. ([2602:ae:1547:e101:3286:cc26:3d5e:3f94]) by smtp.gmail.com with ESMTPSA id a37-20020a631a65000000b003c14af50626sm6093779pgm.62.2022.06.03.21.06.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jun 2022 21:06:12 -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=piEshlp2jFC/OdebizTApyzI+JWPnaYL97UZKb5EMwo=; b=ZOVyZY3zM+X0gWHSRF36liR71y5ocMuRMXEoxov7pwXvBW5rwnUjnIkufJNfNPyJ0e wZUZTCWQ+7TQ8CrJdl/lBAjuZGRNjA1NWIkJtD0oO9sRk7I+VAlW3ICwqvSl808Qpnra G1Wde5zN0Js0uhaZH13EO/ohFFdYPT/R8zPXPrhoMjDi6Ke2vmCdwFfGYa9ya2z49H2W NZcD97jyd881E0EV/Qr6E/D+omTaVmcmyvOvLct833Tq6CmwAj4Qq0Ywh5uBPXRBgWNg tOyZt8kz/reiPnXHbSVU272e9K5jvzdkbe3aWG6sltcLoswldXHNZVIg7A9oLiYT4hk5 pwZQ== 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=piEshlp2jFC/OdebizTApyzI+JWPnaYL97UZKb5EMwo=; b=5kQgCXdVG3ST61QCIS37QR/iS2WMpuPHkoDTezTIKMeqRi0kEHlSDWrpPHnq/eKE+4 AF1/zPHVx8p3vtMlKO/EVhlMZ/qOU7LSNUqzt/a589qOjyD1aesSqS5OK8NigmeMrAcx LSYLyHVBXzuoZzLFxyW0mLB3NNrXQIcHm7V1psac4WqiUFqV+g4DgZ/29yV3Fir5xmdY Lgc3bX9ncATG9jBj1CA2zN0PxziOTa2EkQkqX7rXiclc5xfPFXbCZ/XShEzowxypzado HqWyg+awjE8LQyrxVrN85TXT0UkzD3CPu0ZZiPyV4Fhv++5oILEv2a4yMp5gDkoCfqeb AFXA== X-Gm-Message-State: AOAM5312tzeKo135bDiJrJHvSI7e/xHQPcPeoFHpOZpRb6GlBgQD54Sx 71qSlxOOWNnNUbTtos2S/dPxAr1c7wcONw== X-Google-Smtp-Source: ABdhPJz9tMaaBeKSOyb1U0SxhMt9ADCWpENVc+rEKJLZoqtCBX8QkSHUKHlEU9U0jz0nIUQ9HLTeiQ== X-Received: by 2002:a17:90a:680d:b0:1e2:ff55:da6 with SMTP id p13-20020a17090a680d00b001e2ff550da6mr31346548pjj.133.1654315572447; Fri, 03 Jun 2022 21:06:12 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Subject: [PATCH 03/28] target/arm: Move get_phys_addr_v5 to ptw.c Date: Fri, 3 Jun 2022 21:05:42 -0700 Message-Id: <20220604040607.269301-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220604040607.269301-1-richard.henderson@linaro.org> References: <20220604040607.269301-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=2607:f8b0:4864:20::636; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x636.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=ham 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1654315744358100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Richard Henderson --- target/arm/ptw.h | 15 +++-- target/arm/helper.c | 137 +++----------------------------------------- target/arm/ptw.c | 123 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 140 insertions(+), 135 deletions(-) diff --git a/target/arm/ptw.h b/target/arm/ptw.h index e2023ae750..2dbd97b8cb 100644 --- a/target/arm/ptw.h +++ b/target/arm/ptw.h @@ -11,16 +11,21 @@ =20 #ifndef CONFIG_USER_ONLY =20 +uint32_t arm_ldl_ptw(CPUState *cs, hwaddr addr, bool is_secure, + ARMMMUIdx mmu_idx, ARMMMUFaultInfo *fi); +uint64_t arm_ldq_ptw(CPUState *cs, hwaddr addr, bool is_secure, + ARMMMUIdx mmu_idx, ARMMMUFaultInfo *fi); + bool regime_is_user(CPUARMState *env, ARMMMUIdx mmu_idx); bool regime_translation_disabled(CPUARMState *env, ARMMMUIdx mmu_idx); ARMCacheAttrs combine_cacheattrs(CPUARMState *env, ARMCacheAttrs s1, ARMCacheAttrs s2); =20 -bool get_phys_addr_v5(CPUARMState *env, uint32_t address, - MMUAccessType access_type, ARMMMUIdx mmu_idx, - hwaddr *phys_ptr, int *prot, - target_ulong *page_size, - ARMMMUFaultInfo *fi); +bool get_level1_table_address(CPUARMState *env, ARMMMUIdx mmu_idx, + uint32_t *table, uint32_t address); +int ap_to_rw_prot(CPUARMState *env, ARMMMUIdx mmu_idx, + int ap, int domain_prot); + bool get_phys_addr_pmsav5(CPUARMState *env, uint32_t address, MMUAccessType access_type, ARMMMUIdx mmu_idx, hwaddr *phys_ptr, int *prot, diff --git a/target/arm/helper.c b/target/arm/helper.c index 7015ce4efc..48294cb87c 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -10542,8 +10542,7 @@ bool regime_is_user(CPUARMState *env, ARMMMUIdx mmu= _idx) * @ap: The 3-bit access permissions (AP[2:0]) * @domain_prot: The 2-bit domain access permissions */ -static inline int ap_to_rw_prot(CPUARMState *env, ARMMMUIdx mmu_idx, - int ap, int domain_prot) +int ap_to_rw_prot(CPUARMState *env, ARMMMUIdx mmu_idx, int ap, int domain_= prot) { bool is_user =3D regime_is_user(env, mmu_idx); =20 @@ -10746,8 +10745,8 @@ static int get_S1prot(CPUARMState *env, ARMMMUIdx m= mu_idx, bool is_aa64, return prot_rw | PAGE_EXEC; } =20 -static bool get_level1_table_address(CPUARMState *env, ARMMMUIdx mmu_idx, - uint32_t *table, uint32_t address) +bool get_level1_table_address(CPUARMState *env, ARMMMUIdx mmu_idx, + uint32_t *table, uint32_t address) { /* Note that we can only get here for an AArch32 PL0/PL1 lookup */ TCR *tcr =3D regime_tcr(env, mmu_idx); @@ -10846,8 +10845,8 @@ static hwaddr S1_ptw_translate(CPUARMState *env, AR= MMMUIdx mmu_idx, } =20 /* All loads done in the course of a page table walk go through here. */ -static uint32_t arm_ldl_ptw(CPUState *cs, hwaddr addr, bool is_secure, - ARMMMUIdx mmu_idx, ARMMMUFaultInfo *fi) +uint32_t arm_ldl_ptw(CPUState *cs, hwaddr addr, bool is_secure, + ARMMMUIdx mmu_idx, ARMMMUFaultInfo *fi) { ARMCPU *cpu =3D ARM_CPU(cs); CPUARMState *env =3D &cpu->env; @@ -10875,8 +10874,8 @@ static uint32_t arm_ldl_ptw(CPUState *cs, hwaddr ad= dr, bool is_secure, return 0; } =20 -static uint64_t arm_ldq_ptw(CPUState *cs, hwaddr addr, bool is_secure, - ARMMMUIdx mmu_idx, ARMMMUFaultInfo *fi) +uint64_t arm_ldq_ptw(CPUState *cs, hwaddr addr, bool is_secure, + ARMMMUIdx mmu_idx, ARMMMUFaultInfo *fi) { ARMCPU *cpu =3D ARM_CPU(cs); CPUARMState *env =3D &cpu->env; @@ -10904,128 +10903,6 @@ static uint64_t arm_ldq_ptw(CPUState *cs, hwaddr = addr, bool is_secure, return 0; } =20 -bool get_phys_addr_v5(CPUARMState *env, uint32_t address, - MMUAccessType access_type, ARMMMUIdx mmu_idx, - hwaddr *phys_ptr, int *prot, - target_ulong *page_size, - ARMMMUFaultInfo *fi) -{ - CPUState *cs =3D env_cpu(env); - int level =3D 1; - uint32_t table; - uint32_t desc; - int type; - int ap; - int domain =3D 0; - int domain_prot; - hwaddr phys_addr; - uint32_t dacr; - - /* Pagetable walk. */ - /* Lookup l1 descriptor. */ - if (!get_level1_table_address(env, mmu_idx, &table, address)) { - /* Section translation fault if page walk is disabled by PD0 or PD= 1 */ - fi->type =3D ARMFault_Translation; - goto do_fault; - } - desc =3D arm_ldl_ptw(cs, table, regime_is_secure(env, mmu_idx), - mmu_idx, fi); - if (fi->type !=3D ARMFault_None) { - goto do_fault; - } - type =3D (desc & 3); - domain =3D (desc >> 5) & 0x0f; - if (regime_el(env, mmu_idx) =3D=3D 1) { - dacr =3D env->cp15.dacr_ns; - } else { - dacr =3D env->cp15.dacr_s; - } - domain_prot =3D (dacr >> (domain * 2)) & 3; - if (type =3D=3D 0) { - /* Section translation fault. */ - fi->type =3D ARMFault_Translation; - goto do_fault; - } - if (type !=3D 2) { - level =3D 2; - } - if (domain_prot =3D=3D 0 || domain_prot =3D=3D 2) { - fi->type =3D ARMFault_Domain; - goto do_fault; - } - if (type =3D=3D 2) { - /* 1Mb section. */ - phys_addr =3D (desc & 0xfff00000) | (address & 0x000fffff); - ap =3D (desc >> 10) & 3; - *page_size =3D 1024 * 1024; - } else { - /* Lookup l2 entry. */ - if (type =3D=3D 1) { - /* Coarse pagetable. */ - table =3D (desc & 0xfffffc00) | ((address >> 10) & 0x3fc); - } else { - /* Fine pagetable. */ - table =3D (desc & 0xfffff000) | ((address >> 8) & 0xffc); - } - desc =3D arm_ldl_ptw(cs, table, regime_is_secure(env, mmu_idx), - mmu_idx, fi); - if (fi->type !=3D ARMFault_None) { - goto do_fault; - } - switch (desc & 3) { - case 0: /* Page translation fault. */ - fi->type =3D ARMFault_Translation; - goto do_fault; - case 1: /* 64k page. */ - phys_addr =3D (desc & 0xffff0000) | (address & 0xffff); - ap =3D (desc >> (4 + ((address >> 13) & 6))) & 3; - *page_size =3D 0x10000; - break; - case 2: /* 4k page. */ - phys_addr =3D (desc & 0xfffff000) | (address & 0xfff); - ap =3D (desc >> (4 + ((address >> 9) & 6))) & 3; - *page_size =3D 0x1000; - break; - case 3: /* 1k page, or ARMv6/XScale "extended small (4k) page" */ - if (type =3D=3D 1) { - /* ARMv6/XScale extended small page format */ - if (arm_feature(env, ARM_FEATURE_XSCALE) - || arm_feature(env, ARM_FEATURE_V6)) { - phys_addr =3D (desc & 0xfffff000) | (address & 0xfff); - *page_size =3D 0x1000; - } else { - /* UNPREDICTABLE in ARMv5; we choose to take a - * page translation fault. - */ - fi->type =3D ARMFault_Translation; - goto do_fault; - } - } else { - phys_addr =3D (desc & 0xfffffc00) | (address & 0x3ff); - *page_size =3D 0x400; - } - ap =3D (desc >> 4) & 3; - break; - default: - /* Never happens, but compiler isn't smart enough to tell. */ - g_assert_not_reached(); - } - } - *prot =3D ap_to_rw_prot(env, mmu_idx, ap, domain_prot); - *prot |=3D *prot ? PAGE_EXEC : 0; - if (!(*prot & (1 << access_type))) { - /* Access permission fault. */ - fi->type =3D ARMFault_Permission; - goto do_fault; - } - *phys_ptr =3D phys_addr; - return false; -do_fault: - fi->domain =3D domain; - fi->level =3D level; - return true; -} - bool get_phys_addr_v6(CPUARMState *env, uint32_t address, MMUAccessType access_type, ARMMMUIdx mmu_idx, hwaddr *phys_ptr, MemTxAttrs *attrs, int *prot, diff --git a/target/arm/ptw.c b/target/arm/ptw.c index 318000f6d9..09c4472628 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -13,6 +13,129 @@ #include "ptw.h" =20 =20 +static bool get_phys_addr_v5(CPUARMState *env, uint32_t address, + MMUAccessType access_type, ARMMMUIdx mmu_idx, + hwaddr *phys_ptr, int *prot, + target_ulong *page_size, + ARMMMUFaultInfo *fi) +{ + CPUState *cs =3D env_cpu(env); + int level =3D 1; + uint32_t table; + uint32_t desc; + int type; + int ap; + int domain =3D 0; + int domain_prot; + hwaddr phys_addr; + uint32_t dacr; + + /* Pagetable walk. */ + /* Lookup l1 descriptor. */ + if (!get_level1_table_address(env, mmu_idx, &table, address)) { + /* Section translation fault if page walk is disabled by PD0 or PD= 1 */ + fi->type =3D ARMFault_Translation; + goto do_fault; + } + desc =3D arm_ldl_ptw(cs, table, regime_is_secure(env, mmu_idx), + mmu_idx, fi); + if (fi->type !=3D ARMFault_None) { + goto do_fault; + } + type =3D (desc & 3); + domain =3D (desc >> 5) & 0x0f; + if (regime_el(env, mmu_idx) =3D=3D 1) { + dacr =3D env->cp15.dacr_ns; + } else { + dacr =3D env->cp15.dacr_s; + } + domain_prot =3D (dacr >> (domain * 2)) & 3; + if (type =3D=3D 0) { + /* Section translation fault. */ + fi->type =3D ARMFault_Translation; + goto do_fault; + } + if (type !=3D 2) { + level =3D 2; + } + if (domain_prot =3D=3D 0 || domain_prot =3D=3D 2) { + fi->type =3D ARMFault_Domain; + goto do_fault; + } + if (type =3D=3D 2) { + /* 1Mb section. */ + phys_addr =3D (desc & 0xfff00000) | (address & 0x000fffff); + ap =3D (desc >> 10) & 3; + *page_size =3D 1024 * 1024; + } else { + /* Lookup l2 entry. */ + if (type =3D=3D 1) { + /* Coarse pagetable. */ + table =3D (desc & 0xfffffc00) | ((address >> 10) & 0x3fc); + } else { + /* Fine pagetable. */ + table =3D (desc & 0xfffff000) | ((address >> 8) & 0xffc); + } + desc =3D arm_ldl_ptw(cs, table, regime_is_secure(env, mmu_idx), + mmu_idx, fi); + if (fi->type !=3D ARMFault_None) { + goto do_fault; + } + switch (desc & 3) { + case 0: /* Page translation fault. */ + fi->type =3D ARMFault_Translation; + goto do_fault; + case 1: /* 64k page. */ + phys_addr =3D (desc & 0xffff0000) | (address & 0xffff); + ap =3D (desc >> (4 + ((address >> 13) & 6))) & 3; + *page_size =3D 0x10000; + break; + case 2: /* 4k page. */ + phys_addr =3D (desc & 0xfffff000) | (address & 0xfff); + ap =3D (desc >> (4 + ((address >> 9) & 6))) & 3; + *page_size =3D 0x1000; + break; + case 3: /* 1k page, or ARMv6/XScale "extended small (4k) page" */ + if (type =3D=3D 1) { + /* ARMv6/XScale extended small page format */ + if (arm_feature(env, ARM_FEATURE_XSCALE) + || arm_feature(env, ARM_FEATURE_V6)) { + phys_addr =3D (desc & 0xfffff000) | (address & 0xfff); + *page_size =3D 0x1000; + } else { + /* + * UNPREDICTABLE in ARMv5; we choose to take a + * page translation fault. + */ + fi->type =3D ARMFault_Translation; + goto do_fault; + } + } else { + phys_addr =3D (desc & 0xfffffc00) | (address & 0x3ff); + *page_size =3D 0x400; + } + ap =3D (desc >> 4) & 3; + break; + default: + /* Never happens, but compiler isn't smart enough to tell. */ + g_assert_not_reached(); + } + } + *prot =3D ap_to_rw_prot(env, mmu_idx, ap, domain_prot); + *prot |=3D *prot ? PAGE_EXEC : 0; + if (!(*prot & (1 << access_type))) { + /* Access permission fault. */ + fi->type =3D ARMFault_Permission; + goto do_fault; + } + *phys_ptr =3D phys_addr; + return false; +do_fault: + fi->domain =3D domain; + fi->level =3D level; + return true; +} + /** * get_phys_addr - get the physical address for this virtual address * --=20 2.34.1 From nobody Fri May 17 05:50:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1654316079; cv=none; d=zohomail.com; s=zohoarc; b=FaIylgBCBzc9FD5/4GdqtcDmk2CXPQ9kQkscga+R1f2CxKCFH3Fdfdgnb2jd98G9icUJ0UJ84seeUPj25AENPoG5un4fV6xMzFaWHvYqzlW5OjU9iue+/5TkE8tewhUY2Ts89LluOHPdn3guM/V2mJmIF6p9ESGnw4f/CdmczFs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1654316079; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=gnR4IBqxCOqfpDMygtcCF64wR9vV6kPJ7YUAwjHoSb8=; b=B2/VaKipuUq+WJDDO07g8R9yBuh3RMG1u+MEdko243qRlpnjFal2RVDnCqu1LxGIA2g6fZ+EVB4McJxuMPhGdvLQHTofWqVWcm0lZSPFzizNDA43ULebgfVAEGJLaLqu2GC/ULA+4LIXNcDr+Y9UQ1slA7ow+IBYkQIo91QBRrk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1654316079874855.7205572852298; Fri, 3 Jun 2022 21:14:39 -0700 (PDT) Received: from localhost ([::1]:58608 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nxLBN-00023w-Sp for importer@patchew.org; Sat, 04 Jun 2022 00:14:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36576) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nxL3K-0007c8-8o for qemu-devel@nongnu.org; Sat, 04 Jun 2022 00:06:18 -0400 Received: from mail-pj1-x102f.google.com ([2607:f8b0:4864:20::102f]:40565) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nxL3G-0008Vn-U3 for qemu-devel@nongnu.org; Sat, 04 Jun 2022 00:06:17 -0400 Received: by mail-pj1-x102f.google.com with SMTP id n13-20020a17090a394d00b001e30a60f82dso13502997pjf.5 for ; Fri, 03 Jun 2022 21:06:14 -0700 (PDT) Received: from stoup.. ([2602:ae:1547:e101:3286:cc26:3d5e:3f94]) by smtp.gmail.com with ESMTPSA id a37-20020a631a65000000b003c14af50626sm6093779pgm.62.2022.06.03.21.06.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jun 2022 21:06:13 -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=gnR4IBqxCOqfpDMygtcCF64wR9vV6kPJ7YUAwjHoSb8=; b=K72C18LGtlrmbh2trvrBujjKRg1SA6OEUWlet02ug9gQXzWDgSBo4hvhLonwC1CN4L eN1YIMjk/bjlNJeRWxT1suo3SsYv2q3I3tE8W0iWA18C621Kqg/HNJBmLNwLp6let8kw O86D+vTRZj6QG9qjZfElIHVoMNgTEF5k8X7zUrLHa3L6ddhZxP2IVGDq8ZoPD32jTY9l qjD4P3vCSw82UefwffWtQ1eVnkBNOdB81g6f4dSPE0lvv1Bjq9UkIUoUwO9u0VQOJyVh itTNzy/lllA/mu3QlcLwR6UBc3Vj9iLOdnplcq2EFxdmSWDCGFok+YZTmUb8bPhCZ8QZ Jssw== 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=gnR4IBqxCOqfpDMygtcCF64wR9vV6kPJ7YUAwjHoSb8=; b=3imIWwToChnt7MD0+T+Pg+oDaEb9XVb/haDZxcueQ3G38bUetowiHX8icPtehWCte5 tBBMKsGdVvff2zlj7DkNnz+vvbXorSNanAS3ILG5WdIgcoZCspkUIaQ8bjuJjezH7vHw LC+EtD+OvHYr3sQWH82rDWK3ExFTqI8h6GIr4jDx+yCqM9bgZDjyVQStRj+vw4Z5Pzdc wget1QeuC9SSUulg3OL/8VC4V7yGnWmN1ZqyW3IKwvm5c2YFRo3ygozt1/CK3Hk5RqoQ b6p7esYNt1m2l/Ys5CBCOwZl60mcKjuL5LlpsODreTuDe/Ex6HTqJxjdvirKWBHRtGm9 xHRg== X-Gm-Message-State: AOAM5321UUKFo4Puw6yQPSsp2A93zOInxVv8/zm9fQfMaoGRWT6pjB1O 3m0yQ6W/qPy5/vYF0m//fquCWl1+8oETsQ== X-Google-Smtp-Source: ABdhPJys0hyDaC+tkUcIOcyko59t3jKII22CqpDoPOctuvayHb2GsGM3p7WRssU85u0xWTnDTrh0iw== X-Received: by 2002:a17:90b:388f:b0:1e8:5df5:b2a3 with SMTP id mu15-20020a17090b388f00b001e85df5b2a3mr12445pjb.70.1654315573492; Fri, 03 Jun 2022 21:06:13 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Subject: [PATCH 04/28] target/arm: Move get_phys_addr_v6 to ptw.c Date: Fri, 3 Jun 2022 21:05:43 -0700 Message-Id: <20220604040607.269301-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220604040607.269301-1-richard.henderson@linaro.org> References: <20220604040607.269301-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=2607:f8b0:4864:20::102f; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102f.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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1654316080301100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Richard Henderson --- target/arm/ptw.h | 11 +-- target/arm/helper.c | 161 +------------------------------------------- target/arm/ptw.c | 153 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 161 insertions(+), 164 deletions(-) diff --git a/target/arm/ptw.h b/target/arm/ptw.h index 2dbd97b8cb..349b842d3c 100644 --- a/target/arm/ptw.h +++ b/target/arm/ptw.h @@ -25,15 +25,18 @@ bool get_level1_table_address(CPUARMState *env, ARMMMUI= dx mmu_idx, uint32_t *table, uint32_t address); int ap_to_rw_prot(CPUARMState *env, ARMMMUIdx mmu_idx, int ap, int domain_prot); +int simple_ap_to_rw_prot_is_user(int ap, bool is_user); + +static inline int +simple_ap_to_rw_prot(CPUARMState *env, ARMMMUIdx mmu_idx, int ap) +{ + return simple_ap_to_rw_prot_is_user(ap, regime_is_user(env, mmu_idx)); +} =20 bool get_phys_addr_pmsav5(CPUARMState *env, uint32_t address, MMUAccessType access_type, ARMMMUIdx mmu_idx, hwaddr *phys_ptr, int *prot, ARMMMUFaultInfo *fi); -bool get_phys_addr_v6(CPUARMState *env, uint32_t address, - MMUAccessType access_type, ARMMMUIdx mmu_idx, - hwaddr *phys_ptr, MemTxAttrs *attrs, int *prot, - target_ulong *page_size, ARMMMUFaultInfo *fi); bool get_phys_addr_pmsav7(CPUARMState *env, uint32_t address, MMUAccessType access_type, ARMMMUIdx mmu_idx, hwaddr *phys_ptr, int *prot, diff --git a/target/arm/helper.c b/target/arm/helper.c index 48294cb87c..fab91f823a 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -10595,7 +10595,7 @@ int ap_to_rw_prot(CPUARMState *env, ARMMMUIdx mmu_i= dx, int ap, int domain_prot) * @ap: The 2-bit simple AP (AP[2:1]) * @is_user: TRUE if accessing from PL0 */ -static inline int simple_ap_to_rw_prot_is_user(int ap, bool is_user) +int simple_ap_to_rw_prot_is_user(int ap, bool is_user) { switch (ap) { case 0: @@ -10611,12 +10611,6 @@ static inline int simple_ap_to_rw_prot_is_user(int= ap, bool is_user) } } =20 -static inline int -simple_ap_to_rw_prot(CPUARMState *env, ARMMMUIdx mmu_idx, int ap) -{ - return simple_ap_to_rw_prot_is_user(ap, regime_is_user(env, mmu_idx)); -} - /* Translate S2 section/page access permissions to protection flags * * @env: CPUARMState @@ -10903,159 +10897,6 @@ uint64_t arm_ldq_ptw(CPUState *cs, hwaddr addr, b= ool is_secure, return 0; } =20 -bool get_phys_addr_v6(CPUARMState *env, uint32_t address, - MMUAccessType access_type, ARMMMUIdx mmu_idx, - hwaddr *phys_ptr, MemTxAttrs *attrs, int *prot, - target_ulong *page_size, ARMMMUFaultInfo *fi) -{ - CPUState *cs =3D env_cpu(env); - ARMCPU *cpu =3D env_archcpu(env); - int level =3D 1; - uint32_t table; - uint32_t desc; - uint32_t xn; - uint32_t pxn =3D 0; - int type; - int ap; - int domain =3D 0; - int domain_prot; - hwaddr phys_addr; - uint32_t dacr; - bool ns; - - /* Pagetable walk. */ - /* Lookup l1 descriptor. */ - if (!get_level1_table_address(env, mmu_idx, &table, address)) { - /* Section translation fault if page walk is disabled by PD0 or PD= 1 */ - fi->type =3D ARMFault_Translation; - goto do_fault; - } - desc =3D arm_ldl_ptw(cs, table, regime_is_secure(env, mmu_idx), - mmu_idx, fi); - if (fi->type !=3D ARMFault_None) { - goto do_fault; - } - type =3D (desc & 3); - if (type =3D=3D 0 || (type =3D=3D 3 && !cpu_isar_feature(aa32_pxn, cpu= ))) { - /* Section translation fault, or attempt to use the encoding - * which is Reserved on implementations without PXN. - */ - fi->type =3D ARMFault_Translation; - goto do_fault; - } - if ((type =3D=3D 1) || !(desc & (1 << 18))) { - /* Page or Section. */ - domain =3D (desc >> 5) & 0x0f; - } - if (regime_el(env, mmu_idx) =3D=3D 1) { - dacr =3D env->cp15.dacr_ns; - } else { - dacr =3D env->cp15.dacr_s; - } - if (type =3D=3D 1) { - level =3D 2; - } - domain_prot =3D (dacr >> (domain * 2)) & 3; - if (domain_prot =3D=3D 0 || domain_prot =3D=3D 2) { - /* Section or Page domain fault */ - fi->type =3D ARMFault_Domain; - goto do_fault; - } - if (type !=3D 1) { - if (desc & (1 << 18)) { - /* Supersection. */ - phys_addr =3D (desc & 0xff000000) | (address & 0x00ffffff); - phys_addr |=3D (uint64_t)extract32(desc, 20, 4) << 32; - phys_addr |=3D (uint64_t)extract32(desc, 5, 4) << 36; - *page_size =3D 0x1000000; - } else { - /* Section. */ - phys_addr =3D (desc & 0xfff00000) | (address & 0x000fffff); - *page_size =3D 0x100000; - } - ap =3D ((desc >> 10) & 3) | ((desc >> 13) & 4); - xn =3D desc & (1 << 4); - pxn =3D desc & 1; - ns =3D extract32(desc, 19, 1); - } else { - if (cpu_isar_feature(aa32_pxn, cpu)) { - pxn =3D (desc >> 2) & 1; - } - ns =3D extract32(desc, 3, 1); - /* Lookup l2 entry. */ - table =3D (desc & 0xfffffc00) | ((address >> 10) & 0x3fc); - desc =3D arm_ldl_ptw(cs, table, regime_is_secure(env, mmu_idx), - mmu_idx, fi); - if (fi->type !=3D ARMFault_None) { - goto do_fault; - } - ap =3D ((desc >> 4) & 3) | ((desc >> 7) & 4); - switch (desc & 3) { - case 0: /* Page translation fault. */ - fi->type =3D ARMFault_Translation; - goto do_fault; - case 1: /* 64k page. */ - phys_addr =3D (desc & 0xffff0000) | (address & 0xffff); - xn =3D desc & (1 << 15); - *page_size =3D 0x10000; - break; - case 2: case 3: /* 4k page. */ - phys_addr =3D (desc & 0xfffff000) | (address & 0xfff); - xn =3D desc & 1; - *page_size =3D 0x1000; - break; - default: - /* Never happens, but compiler isn't smart enough to tell. */ - g_assert_not_reached(); - } - } - if (domain_prot =3D=3D 3) { - *prot =3D PAGE_READ | PAGE_WRITE | PAGE_EXEC; - } else { - if (pxn && !regime_is_user(env, mmu_idx)) { - xn =3D 1; - } - if (xn && access_type =3D=3D MMU_INST_FETCH) { - fi->type =3D ARMFault_Permission; - goto do_fault; - } - - if (arm_feature(env, ARM_FEATURE_V6K) && - (regime_sctlr(env, mmu_idx) & SCTLR_AFE)) { - /* The simplified model uses AP[0] as an access control bit. = */ - if ((ap & 1) =3D=3D 0) { - /* Access flag fault. */ - fi->type =3D ARMFault_AccessFlag; - goto do_fault; - } - *prot =3D simple_ap_to_rw_prot(env, mmu_idx, ap >> 1); - } else { - *prot =3D ap_to_rw_prot(env, mmu_idx, ap, domain_prot); - } - if (*prot && !xn) { - *prot |=3D PAGE_EXEC; - } - if (!(*prot & (1 << access_type))) { - /* Access permission fault. */ - fi->type =3D ARMFault_Permission; - goto do_fault; - } - } - if (ns) { - /* The NS bit will (as required by the architecture) have no effec= t if - * the CPU doesn't support TZ or this is a non-secure translation - * regime, because the attribute will already be non-secure. - */ - attrs->secure =3D false; - } - *phys_ptr =3D phys_addr; - return false; -do_fault: - fi->domain =3D domain; - fi->level =3D level; - return true; -} - /* * check_s2_mmu_setup * @cpu: ARMCPU diff --git a/target/arm/ptw.c b/target/arm/ptw.c index 09c4472628..6a1f4b549d 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -136,6 +136,159 @@ do_fault: return true; } =20 +static bool get_phys_addr_v6(CPUARMState *env, uint32_t address, + MMUAccessType access_type, ARMMMUIdx mmu_idx, + hwaddr *phys_ptr, MemTxAttrs *attrs, int *pro= t, + target_ulong *page_size, ARMMMUFaultInfo *fi) +{ + CPUState *cs =3D env_cpu(env); + ARMCPU *cpu =3D env_archcpu(env); + int level =3D 1; + uint32_t table; + uint32_t desc; + uint32_t xn; + uint32_t pxn =3D 0; + int type; + int ap; + int domain =3D 0; + int domain_prot; + hwaddr phys_addr; + uint32_t dacr; + bool ns; + + /* Pagetable walk. */ + /* Lookup l1 descriptor. */ + if (!get_level1_table_address(env, mmu_idx, &table, address)) { + /* Section translation fault if page walk is disabled by PD0 or PD= 1 */ + fi->type =3D ARMFault_Translation; + goto do_fault; + } + desc =3D arm_ldl_ptw(cs, table, regime_is_secure(env, mmu_idx), + mmu_idx, fi); + if (fi->type !=3D ARMFault_None) { + goto do_fault; + } + type =3D (desc & 3); + if (type =3D=3D 0 || (type =3D=3D 3 && !cpu_isar_feature(aa32_pxn, cpu= ))) { + /* Section translation fault, or attempt to use the encoding + * which is Reserved on implementations without PXN. + */ + fi->type =3D ARMFault_Translation; + goto do_fault; + } + if ((type =3D=3D 1) || !(desc & (1 << 18))) { + /* Page or Section. */ + domain =3D (desc >> 5) & 0x0f; + } + if (regime_el(env, mmu_idx) =3D=3D 1) { + dacr =3D env->cp15.dacr_ns; + } else { + dacr =3D env->cp15.dacr_s; + } + if (type =3D=3D 1) { + level =3D 2; + } + domain_prot =3D (dacr >> (domain * 2)) & 3; + if (domain_prot =3D=3D 0 || domain_prot =3D=3D 2) { + /* Section or Page domain fault */ + fi->type =3D ARMFault_Domain; + goto do_fault; + } + if (type !=3D 1) { + if (desc & (1 << 18)) { + /* Supersection. */ + phys_addr =3D (desc & 0xff000000) | (address & 0x00ffffff); + phys_addr |=3D (uint64_t)extract32(desc, 20, 4) << 32; + phys_addr |=3D (uint64_t)extract32(desc, 5, 4) << 36; + *page_size =3D 0x1000000; + } else { + /* Section. */ + phys_addr =3D (desc & 0xfff00000) | (address & 0x000fffff); + *page_size =3D 0x100000; + } + ap =3D ((desc >> 10) & 3) | ((desc >> 13) & 4); + xn =3D desc & (1 << 4); + pxn =3D desc & 1; + ns =3D extract32(desc, 19, 1); + } else { + if (cpu_isar_feature(aa32_pxn, cpu)) { + pxn =3D (desc >> 2) & 1; + } + ns =3D extract32(desc, 3, 1); + /* Lookup l2 entry. */ + table =3D (desc & 0xfffffc00) | ((address >> 10) & 0x3fc); + desc =3D arm_ldl_ptw(cs, table, regime_is_secure(env, mmu_idx), + mmu_idx, fi); + if (fi->type !=3D ARMFault_None) { + goto do_fault; + } + ap =3D ((desc >> 4) & 3) | ((desc >> 7) & 4); + switch (desc & 3) { + case 0: /* Page translation fault. */ + fi->type =3D ARMFault_Translation; + goto do_fault; + case 1: /* 64k page. */ + phys_addr =3D (desc & 0xffff0000) | (address & 0xffff); + xn =3D desc & (1 << 15); + *page_size =3D 0x10000; + break; + case 2: case 3: /* 4k page. */ + phys_addr =3D (desc & 0xfffff000) | (address & 0xfff); + xn =3D desc & 1; + *page_size =3D 0x1000; + break; + default: + /* Never happens, but compiler isn't smart enough to tell. */ + g_assert_not_reached(); + } + } + if (domain_prot =3D=3D 3) { + *prot =3D PAGE_READ | PAGE_WRITE | PAGE_EXEC; + } else { + if (pxn && !regime_is_user(env, mmu_idx)) { + xn =3D 1; + } + if (xn && access_type =3D=3D MMU_INST_FETCH) { + fi->type =3D ARMFault_Permission; + goto do_fault; + } + + if (arm_feature(env, ARM_FEATURE_V6K) && + (regime_sctlr(env, mmu_idx) & SCTLR_AFE)) { + /* The simplified model uses AP[0] as an access control bit. = */ + if ((ap & 1) =3D=3D 0) { + /* Access flag fault. */ + fi->type =3D ARMFault_AccessFlag; + goto do_fault; + } + *prot =3D simple_ap_to_rw_prot(env, mmu_idx, ap >> 1); + } else { + *prot =3D ap_to_rw_prot(env, mmu_idx, ap, domain_prot); + } + if (*prot && !xn) { + *prot |=3D PAGE_EXEC; + } + if (!(*prot & (1 << access_type))) { + /* Access permission fault. */ + fi->type =3D ARMFault_Permission; + goto do_fault; + } + } + if (ns) { + /* The NS bit will (as required by the architecture) have no effec= t if + * the CPU doesn't support TZ or this is a non-secure translation + * regime, because the attribute will already be non-secure. + */ + attrs->secure =3D false; + } + *phys_ptr =3D phys_addr; + return false; +do_fault: + fi->domain =3D domain; + fi->level =3D level; + return true; +} + /** * get_phys_addr - get the physical address for this virtual address * --=20 2.34.1 From nobody Fri May 17 05:50:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1654316022; cv=none; d=zohomail.com; s=zohoarc; b=BhZlsVJ6YYB1+m4QUy59PdpfxNvkDXcG54xOglw7G4L/evWZNoza4vHCBPj4vFgDKZd5x59Vo9+WR85vQJ5dSIx3XlNF2FVoS8yWVDHH+r4qrRKyuksRwbeW23YE0V5L4v4mnaJ0JbceROFysJWAWJvNokUzh49pViuuF2QTC0Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1654316022; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=IfCuj2+ZK81PcqSyuUrPk3wYk32Me+jVf6nfUPCq22M=; b=kq2ais5dDQ1AkecMcSanKtBv210P1OcKOOAZkHUQuI48zWuWsojeRqP9RRnGxmemxh18fgznOZIQylq0N7ER8ijA8uhWeaJFrj5API5zgLSeS7n+pmM4hOOQ+M7AA/HJwb636DT0dNYXkMeTYOXbE6qotkTRe0aP5O1l8hinFis= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1654316022967778.718157541026; Fri, 3 Jun 2022 21:13:42 -0700 (PDT) Received: from localhost ([::1]:56466 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nxLAT-0000dT-SF for importer@patchew.org; Sat, 04 Jun 2022 00:13:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36616) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nxL3L-0007ek-ER for qemu-devel@nongnu.org; Sat, 04 Jun 2022 00:06:19 -0400 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]:40670) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nxL3H-0008WA-LU for qemu-devel@nongnu.org; Sat, 04 Jun 2022 00:06:18 -0400 Received: by mail-pl1-x62e.google.com with SMTP id i1so8113218plg.7 for ; Fri, 03 Jun 2022 21:06:15 -0700 (PDT) Received: from stoup.. ([2602:ae:1547:e101:3286:cc26:3d5e:3f94]) by smtp.gmail.com with ESMTPSA id a37-20020a631a65000000b003c14af50626sm6093779pgm.62.2022.06.03.21.06.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jun 2022 21:06:13 -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=IfCuj2+ZK81PcqSyuUrPk3wYk32Me+jVf6nfUPCq22M=; b=SRkuTUTOOdU1xaCN0L5a3BKpyG39z4DEbvKtyBu8PsNLUMtg4HMn1b4j2lnfp8j4o4 xPfVh0fj0ihFP3idEeTS6KxIsPsg3of0RMUrNIK+8pj+v6IstFp7klxzgi3LSyye0ON2 1zoWFRjGS/ye8S+o9OrI2KMkIdaDJapUE7zZODRZw4D0Cz6qcCsjOqg00h37SwW5PG9V ulICrrWK81ZLCskWv3g06d3gSe+ovcrYYy1V3AqmOAMLqIl6KiCIULnP1mPZpm6xb8/t SD8UZP2s/OfgQjAAMk1ARWhftE5c5rtXC0BpmWsI/R0rlyP8KZtRoFdgfMVGHDY5BDCZ IMZA== 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=IfCuj2+ZK81PcqSyuUrPk3wYk32Me+jVf6nfUPCq22M=; b=0bdXS8g9eU/Z+JyVKWD8adTrRxnbObNJ8xBmCPlufTn2vgrwORrnvpWnOMKaF05HHS h3SQLhN62/jPdD2vevsBDjiax6HKErO+CADzuz8tIXGpUoKGqz4qVQzBljd3gkA4Uf/S JDUJKORY5GzwH/b2YUH9srZ+rW2fKfWxecLldoqRhb+QC3Nm2OnR7IYkSe+UxOMTwqGV jEaLGQ5LunZtw+Lp10ou6ER3/bXXXUgNLkPWivE7pALadl4SXam4PEw0WB7T2qAWfJLi sWLzXD+nJxWGmeme0hmdov9d3ddMitEFAORWMTiwy+oW7ktNk1Guc4T4bsqlAXSuLnA1 fjhA== X-Gm-Message-State: AOAM530YH4zfKczhvXZDHPpBBUO6iB3FWG5EO5Osb1r2xhWV2kE5aYn4 OQI+vXfO39vNlxKo4TFinHQe5V6PedOtdg== X-Google-Smtp-Source: ABdhPJzEaGlm+aj0lr1F4U+XhkNd1BZJC1m3ueMlw62NKE1w7UIvSwGjOY+ljMgtN8Lec8Dz6ABFrQ== X-Received: by 2002:a17:90a:fa5:b0:1e2:ee1b:8f85 with SMTP id 34-20020a17090a0fa500b001e2ee1b8f85mr14118200pjz.216.1654315574322; Fri, 03 Jun 2022 21:06:14 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Subject: [PATCH 05/28] target/arm: Move get_phys_addr_pmsav5 to ptw.c Date: Fri, 3 Jun 2022 21:05:44 -0700 Message-Id: <20220604040607.269301-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220604040607.269301-1-richard.henderson@linaro.org> References: <20220604040607.269301-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=2607:f8b0:4864:20::62e; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62e.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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1654316024035100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Richard Henderson --- target/arm/ptw.h | 4 --- target/arm/helper.c | 85 --------------------------------------------- target/arm/ptw.c | 85 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+), 89 deletions(-) diff --git a/target/arm/ptw.h b/target/arm/ptw.h index 349b842d3c..324a9dde14 100644 --- a/target/arm/ptw.h +++ b/target/arm/ptw.h @@ -33,10 +33,6 @@ simple_ap_to_rw_prot(CPUARMState *env, ARMMMUIdx mmu_idx= , int ap) return simple_ap_to_rw_prot_is_user(ap, regime_is_user(env, mmu_idx)); } =20 -bool get_phys_addr_pmsav5(CPUARMState *env, uint32_t address, - MMUAccessType access_type, ARMMMUIdx mmu_idx, - hwaddr *phys_ptr, int *prot, - ARMMMUFaultInfo *fi); bool get_phys_addr_pmsav7(CPUARMState *env, uint32_t address, MMUAccessType access_type, ARMMMUIdx mmu_idx, hwaddr *phys_ptr, int *prot, diff --git a/target/arm/helper.c b/target/arm/helper.c index fab91f823a..31abcf6fc9 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -12238,91 +12238,6 @@ bool get_phys_addr_pmsav8(CPUARMState *env, uint32= _t address, return ret; } =20 -bool get_phys_addr_pmsav5(CPUARMState *env, uint32_t address, - MMUAccessType access_type, ARMMMUIdx mmu_idx, - hwaddr *phys_ptr, int *prot, - ARMMMUFaultInfo *fi) -{ - int n; - uint32_t mask; - uint32_t base; - bool is_user =3D regime_is_user(env, mmu_idx); - - if (regime_translation_disabled(env, mmu_idx)) { - /* MPU disabled. */ - *phys_ptr =3D address; - *prot =3D PAGE_READ | PAGE_WRITE | PAGE_EXEC; - return false; - } - - *phys_ptr =3D address; - for (n =3D 7; n >=3D 0; n--) { - base =3D env->cp15.c6_region[n]; - if ((base & 1) =3D=3D 0) { - continue; - } - mask =3D 1 << ((base >> 1) & 0x1f); - /* Keep this shift separate from the above to avoid an - (undefined) << 32. */ - mask =3D (mask << 1) - 1; - if (((base ^ address) & ~mask) =3D=3D 0) { - break; - } - } - if (n < 0) { - fi->type =3D ARMFault_Background; - return true; - } - - if (access_type =3D=3D MMU_INST_FETCH) { - mask =3D env->cp15.pmsav5_insn_ap; - } else { - mask =3D env->cp15.pmsav5_data_ap; - } - mask =3D (mask >> (n * 4)) & 0xf; - switch (mask) { - case 0: - fi->type =3D ARMFault_Permission; - fi->level =3D 1; - return true; - case 1: - if (is_user) { - fi->type =3D ARMFault_Permission; - fi->level =3D 1; - return true; - } - *prot =3D PAGE_READ | PAGE_WRITE; - break; - case 2: - *prot =3D PAGE_READ; - if (!is_user) { - *prot |=3D PAGE_WRITE; - } - break; - case 3: - *prot =3D PAGE_READ | PAGE_WRITE; - break; - case 5: - if (is_user) { - fi->type =3D ARMFault_Permission; - fi->level =3D 1; - return true; - } - *prot =3D PAGE_READ; - break; - case 6: - *prot =3D PAGE_READ; - break; - default: - /* Bad permission. */ - fi->type =3D ARMFault_Permission; - fi->level =3D 1; - return true; - } - *prot |=3D PAGE_EXEC; - return false; -} - /* Combine either inner or outer cacheability attributes for normal * memory, according to table D4-42 and pseudocode procedure * CombineS1S2AttrHints() of ARM DDI 0487B.b (the ARMv8 ARM). diff --git a/target/arm/ptw.c b/target/arm/ptw.c index 6a1f4b549d..5c32648a16 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -289,6 +289,91 @@ do_fault: return true; } =20 +static bool get_phys_addr_pmsav5(CPUARMState *env, uint32_t address, + MMUAccessType access_type, ARMMMUIdx mmu_= idx, + hwaddr *phys_ptr, int *prot, + ARMMMUFaultInfo *fi) +{ + int n; + uint32_t mask; + uint32_t base; + bool is_user =3D regime_is_user(env, mmu_idx); + + if (regime_translation_disabled(env, mmu_idx)) { + /* MPU disabled. */ + *phys_ptr =3D address; + *prot =3D PAGE_READ | PAGE_WRITE | PAGE_EXEC; + return false; + } + + *phys_ptr =3D address; + for (n =3D 7; n >=3D 0; n--) { + base =3D env->cp15.c6_region[n]; + if ((base & 1) =3D=3D 0) { + continue; + } + mask =3D 1 << ((base >> 1) & 0x1f); + /* Keep this shift separate from the above to avoid an + (undefined) << 32. */ + mask =3D (mask << 1) - 1; + if (((base ^ address) & ~mask) =3D=3D 0) { + break; + } + } + if (n < 0) { + fi->type =3D ARMFault_Background; + return true; + } + + if (access_type =3D=3D MMU_INST_FETCH) { + mask =3D env->cp15.pmsav5_insn_ap; + } else { + mask =3D env->cp15.pmsav5_data_ap; + } + mask =3D (mask >> (n * 4)) & 0xf; + switch (mask) { + case 0: + fi->type =3D ARMFault_Permission; + fi->level =3D 1; + return true; + case 1: + if (is_user) { + fi->type =3D ARMFault_Permission; + fi->level =3D 1; + return true; + } + *prot =3D PAGE_READ | PAGE_WRITE; + break; + case 2: + *prot =3D PAGE_READ; + if (!is_user) { + *prot |=3D PAGE_WRITE; + } + break; + case 3: + *prot =3D PAGE_READ | PAGE_WRITE; + break; + case 5: + if (is_user) { + fi->type =3D ARMFault_Permission; + fi->level =3D 1; + return true; + } + *prot =3D PAGE_READ; + break; + case 6: + *prot =3D PAGE_READ; + break; + default: + /* Bad permission. */ + fi->type =3D ARMFault_Permission; + fi->level =3D 1; + return true; + } + *prot |=3D PAGE_EXEC; + return false; +} + /** * get_phys_addr - get the physical address for this virtual address * --=20 2.34.1 From nobody Fri May 17 05:50:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1654316257; cv=none; d=zohomail.com; s=zohoarc; b=ZruMzi+qM+dYe1LfqgLE3srpwVnDL0ENYRIKy0rl6zl+fSWq/7rm8sgqxiuhYFI1raBkBttmsUTjHffDRdPcC6VrnKlJjXto/J36G2zP7dKeqlDAoO2hr9kylM0D5db03eJn/I+5Xm8gNPQU1K4zAwqcVF0LkR9zfaK3ACNCBrA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1654316257; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=j4IKm5/6a1/dcANetGpDLVd36P90uuIasmbq4QESC+o=; b=hPRjd7usoqpvyCg9J4ArKrjasyMSwK7F6loSzu/VbZMbDdjeCrmnlYweNYUUto+Y/xHS+JH+Jr3cpnxLHwkZ/nb30ul0nLT7jOiuAE3TB+y8EpN3WRtAxQGyhTbDhZ7vSh9Z6Y9jgUtEOPA3aiQpPE89MP7Mjbk0/0+TMN76vYQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1654316257596731.7251119914911; Fri, 3 Jun 2022 21:17:37 -0700 (PDT) Received: from localhost ([::1]:39392 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nxLEG-000870-IE for importer@patchew.org; Sat, 04 Jun 2022 00:17:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36614) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nxL3L-0007ee-DU for qemu-devel@nongnu.org; Sat, 04 Jun 2022 00:06:19 -0400 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]:39472) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nxL3I-0008Ux-34 for qemu-devel@nongnu.org; Sat, 04 Jun 2022 00:06:18 -0400 Received: by mail-pl1-x62f.google.com with SMTP id o17so8116373pla.6 for ; Fri, 03 Jun 2022 21:06:15 -0700 (PDT) Received: from stoup.. ([2602:ae:1547:e101:3286:cc26:3d5e:3f94]) by smtp.gmail.com with ESMTPSA id a37-20020a631a65000000b003c14af50626sm6093779pgm.62.2022.06.03.21.06.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jun 2022 21:06:14 -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=j4IKm5/6a1/dcANetGpDLVd36P90uuIasmbq4QESC+o=; b=Blo+DeoiQ3IjHCO2/54jrU6SiQ+zmKnaa0809zl3p/loNdwM4dXpAsPkkfCrb9sePI TBU1A290/lxAKcsu7cEoDNBDUKYZsKfL943qEjwzAwDtg2DC9ijFEQlbrSfSuSuuUrhf CTBS3RQGtfzeS4ELxNnkCazKdboa8jWtZPnCLP8zNrNvXkPNuH45Ley7oyiaH3Tbjcmj OzHL383jYJCt5R/jpAa4xaZGgX8cNf7VduN7HoV742IIJORGvLbV6RPfpNxVV2emOEsg aVmLYFeoErdR15YClUSMevEvZ9MUFH7wRV4uZpuCMHep2PuQucLfyVTODyT3U30KzATn T1cQ== 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=j4IKm5/6a1/dcANetGpDLVd36P90uuIasmbq4QESC+o=; b=cStvc8BB24NsZWck/DHZm0NUVG4DmQwGbZ492ecZVtYocPFt4EZwhraSBzw3qV8Z5e 9seL4zWzCmz+yl0xMApkq/grJq1NqwPCFF/Cd8u0vV/+FRcjuLeHGUO3nju0jedEmKKs dKmlT0AUkCYT3JjhlX6bnbIHz5MrTo6A7zj0hSh7+wxJPT7OgPiuuiYbbu6Ce4B9oFwF qm+IZIMix0rN1E1WSm9JFyFvwhYxw/LJnQW0W99od9Zg6B0utxCntexFUXJVdS5SK8GS GIDA0olkAuHEsDe3cxWbIGqu4wvCcBYiU6pyle3p032QuVuyZAn8n/JPF3UJfwlJUSPu m43A== X-Gm-Message-State: AOAM530vtYv5G61OV0fwNrqxxKnTduvwKMsmGz+kFSxIkNpksdEdaYWA VR7grG2+hOSR0gSVhtWXrn9/JwyuGOJTcw== X-Google-Smtp-Source: ABdhPJzdJpJZ4SrqqzK158FaCI+9PqD0fRJXn3vlLmbNEF3d8VZEVU8tR0+ssdJ7oumZocEFyZkvIQ== X-Received: by 2002:a17:902:9b8a:b0:163:d0ad:f9e8 with SMTP id y10-20020a1709029b8a00b00163d0adf9e8mr12889714plp.79.1654315575256; Fri, 03 Jun 2022 21:06:15 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Subject: [PATCH 06/28] target/arm: Move get_phys_addr_pmsav7_default to ptw.c Date: Fri, 3 Jun 2022 21:05:45 -0700 Message-Id: <20220604040607.269301-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220604040607.269301-1-richard.henderson@linaro.org> References: <20220604040607.269301-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=2607:f8b0:4864:20::62f; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62f.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=ham 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1654316259506100002 Content-Type: text/plain; charset="utf-8" Signed-off-by: Richard Henderson --- target/arm/ptw.h | 3 +++ target/arm/helper.c | 41 ----------------------------------------- target/arm/ptw.c | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 41 deletions(-) diff --git a/target/arm/ptw.h b/target/arm/ptw.h index 324a9dde14..d6e3fee152 100644 --- a/target/arm/ptw.h +++ b/target/arm/ptw.h @@ -33,6 +33,9 @@ simple_ap_to_rw_prot(CPUARMState *env, ARMMMUIdx mmu_idx,= int ap) return simple_ap_to_rw_prot_is_user(ap, regime_is_user(env, mmu_idx)); } =20 +void get_phys_addr_pmsav7_default(CPUARMState *env, + ARMMMUIdx mmu_idx, + int32_t address, int *prot); bool get_phys_addr_pmsav7(CPUARMState *env, uint32_t address, MMUAccessType access_type, ARMMMUIdx mmu_idx, hwaddr *phys_ptr, int *prot, diff --git a/target/arm/helper.c b/target/arm/helper.c index 31abcf6fc9..7dd54c1863 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -11642,47 +11642,6 @@ do_fault: return true; } =20 -static inline void get_phys_addr_pmsav7_default(CPUARMState *env, - ARMMMUIdx mmu_idx, - int32_t address, int *prot) -{ - if (!arm_feature(env, ARM_FEATURE_M)) { - *prot =3D PAGE_READ | PAGE_WRITE; - switch (address) { - case 0xF0000000 ... 0xFFFFFFFF: - if (regime_sctlr(env, mmu_idx) & SCTLR_V) { - /* hivecs execing is ok */ - *prot |=3D PAGE_EXEC; - } - break; - case 0x00000000 ... 0x7FFFFFFF: - *prot |=3D PAGE_EXEC; - break; - } - } else { - /* Default system address map for M profile cores. - * The architecture specifies which regions are execute-never; - * at the MPU level no other checks are defined. - */ - switch (address) { - case 0x00000000 ... 0x1fffffff: /* ROM */ - case 0x20000000 ... 0x3fffffff: /* SRAM */ - case 0x60000000 ... 0x7fffffff: /* RAM */ - case 0x80000000 ... 0x9fffffff: /* RAM */ - *prot =3D PAGE_READ | PAGE_WRITE | PAGE_EXEC; - break; - case 0x40000000 ... 0x5fffffff: /* Peripheral */ - case 0xa0000000 ... 0xbfffffff: /* Device */ - case 0xc0000000 ... 0xdfffffff: /* Device */ - case 0xe0000000 ... 0xffffffff: /* System */ - *prot =3D PAGE_READ | PAGE_WRITE; - break; - default: - g_assert_not_reached(); - } - } -} - static bool pmsav7_use_background_region(ARMCPU *cpu, ARMMMUIdx mmu_idx, bool is_user) { diff --git a/target/arm/ptw.c b/target/arm/ptw.c index 5c32648a16..74650c6c52 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -374,6 +374,47 @@ static bool get_phys_addr_pmsav5(CPUARMState *env, uin= t32_t address, return false; } =20 +void get_phys_addr_pmsav7_default(CPUARMState *env, + ARMMMUIdx mmu_idx, + int32_t address, int *prot) +{ + if (!arm_feature(env, ARM_FEATURE_M)) { + *prot =3D PAGE_READ | PAGE_WRITE; + switch (address) { + case 0xF0000000 ... 0xFFFFFFFF: + if (regime_sctlr(env, mmu_idx) & SCTLR_V) { + /* hivecs execing is ok */ + *prot |=3D PAGE_EXEC; + } + break; + case 0x00000000 ... 0x7FFFFFFF: + *prot |=3D PAGE_EXEC; + break; + } + } else { + /* Default system address map for M profile cores. + * The architecture specifies which regions are execute-never; + * at the MPU level no other checks are defined. + */ + switch (address) { + case 0x00000000 ... 0x1fffffff: /* ROM */ + case 0x20000000 ... 0x3fffffff: /* SRAM */ + case 0x60000000 ... 0x7fffffff: /* RAM */ + case 0x80000000 ... 0x9fffffff: /* RAM */ + *prot =3D PAGE_READ | PAGE_WRITE | PAGE_EXEC; + break; + case 0x40000000 ... 0x5fffffff: /* Peripheral */ + case 0xa0000000 ... 0xbfffffff: /* Device */ + case 0xc0000000 ... 0xdfffffff: /* Device */ + case 0xe0000000 ... 0xffffffff: /* System */ + *prot =3D PAGE_READ | PAGE_WRITE; + break; + default: + g_assert_not_reached(); + } + } +} + /** * get_phys_addr - get the physical address for this virtual address * --=20 2.34.1 From nobody Fri May 17 05:50:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1654316086; cv=none; d=zohomail.com; s=zohoarc; b=SizLqf5K/q4XaXjnYHRN5JamGCOwxjA+g2EROvYz7FLfsJtuNiELak/85/jBk23BZJVqYffm+uuyEn7sXXCguUPZ7KCHk8Rha4cRNU17qgFEXtaXWoL65+Oi1MUT5Zrjlys4scnFbMcJTlkikwBLB9wl0F46B/E5ITnM0Id2I5s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1654316086; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=NctaESQkS6SHggf4ezkVBbUsKRRYeqf7q0h0PynyYk0=; b=XcTs2pXq67SC91hbXi4I2lcN3KR427BlpLVd454UKf/jflLACDFEaUMCzcmDaboii5WVZz3TO7pPQtPXUUcCBK4ETZLVzaYZo5Y5sFkHt6OCOgWJIuIe6foQ5+1eg3Q9nQOtNaBbZdUkf+Oy4Flyh9QSO+g8iG0gFfeY2cb4pXs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1654316086106634.4380953662532; Fri, 3 Jun 2022 21:14:46 -0700 (PDT) Received: from localhost ([::1]:59078 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nxLBU-0002No-Iv for importer@patchew.org; Sat, 04 Jun 2022 00:14:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36746) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nxL3O-0007mk-Av for qemu-devel@nongnu.org; Sat, 04 Jun 2022 00:06:22 -0400 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]:33456) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nxL3J-00005A-LC for qemu-devel@nongnu.org; Sat, 04 Jun 2022 00:06:21 -0400 Received: by mail-pl1-x629.google.com with SMTP id s12so8162795plp.0 for ; Fri, 03 Jun 2022 21:06:17 -0700 (PDT) Received: from stoup.. ([2602:ae:1547:e101:3286:cc26:3d5e:3f94]) by smtp.gmail.com with ESMTPSA id a37-20020a631a65000000b003c14af50626sm6093779pgm.62.2022.06.03.21.06.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jun 2022 21:06:15 -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=NctaESQkS6SHggf4ezkVBbUsKRRYeqf7q0h0PynyYk0=; b=C12WMYnxVgWf7iIBSuFZ+EpmGdJKktMSUGw88p7VWTjBmc+eMzHoTdX7miwWNCix6M xbgDe1v9bxgZZN4M3mKvTFgaioFu+tCWjY6U1dzTBQse8cj4CkmarGgyhXurU2cUs/FJ uQoADpzpdSpBW5vmYlv1bPkkPrutgND6uMOeljw1jjKivYDwWdkQlpCwS91j2sQlHiSZ 5lxtxnplEiQDYDcQoegAjbjB4seMP0PE2huKohOvm9gXTgCewqX2Yu70sENr8crrnjbJ O2GotYSnnOF5uBqq6cg6EdBjGM1VgY/ZOURt/vjrx+QLCTv/rJW4Ox9Tlln1xKG2/9Y+ QPaw== 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=NctaESQkS6SHggf4ezkVBbUsKRRYeqf7q0h0PynyYk0=; b=IPPtWdA+qCMsSrg0eKHAYhnHJ2kJAXPaji9WbF0Uvsy84sMUz5M17XypmprmNO32Dw hCresIt7z7ZvFqJIjXSksdk+XR774bXOcLh3VHyD+DJac1NbH3vUb2wenEUP3RdTqmdr 6PA6YH9jSke0gDikjyBnMaTy9c+5gR/ralgUePmdoFmq9zppkgViV4O90Gz7dlykQPB5 Y8M+ivXOLaD0yfQ2jMhfiZwY43niI5poftEDreedJYFE4F6aw9P7B4XtmLqsBnPbF/oV baa3/4URkQCS8miO82oy8OvnfDME95UkfsffclvAgjL+RLCsQFgG3PXJU1+06hiobDvb bIKw== X-Gm-Message-State: AOAM530E5TRrXMzqml2vz0IS/DlSPzsLUZBqztbP3oYwfOrLhFS1bzXy UJzGNVdYAZYhyCMHbuXPuAHVpfd0JFnSyw== X-Google-Smtp-Source: ABdhPJzvI7JWTi7GE2fURc+tn3syWDFsFmqUxOfWAOn28V2lj2UWvXRDsjrj1WKQUxIOFVfV/XmONA== X-Received: by 2002:a17:902:bb90:b0:163:ad4c:624b with SMTP id m16-20020a170902bb9000b00163ad4c624bmr12894373pls.87.1654315576054; Fri, 03 Jun 2022 21:06:16 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Subject: [PATCH 07/28] target/arm: Move get_phys_addr_pmsav7 to ptw.c Date: Fri, 3 Jun 2022 21:05:46 -0700 Message-Id: <20220604040607.269301-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220604040607.269301-1-richard.henderson@linaro.org> References: <20220604040607.269301-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=2607:f8b0:4864:20::629; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x629.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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1654316086424100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Richard Henderson --- target/arm/ptw.h | 10 +-- target/arm/helper.c | 194 +------------------------------------------- target/arm/ptw.c | 190 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 198 insertions(+), 196 deletions(-) diff --git a/target/arm/ptw.h b/target/arm/ptw.h index d6e3fee152..d24b7c263a 100644 --- a/target/arm/ptw.h +++ b/target/arm/ptw.h @@ -33,14 +33,14 @@ simple_ap_to_rw_prot(CPUARMState *env, ARMMMUIdx mmu_id= x, int ap) return simple_ap_to_rw_prot_is_user(ap, regime_is_user(env, mmu_idx)); } =20 +bool m_is_ppb_region(CPUARMState *env, uint32_t address); +bool m_is_system_region(CPUARMState *env, uint32_t address); + void get_phys_addr_pmsav7_default(CPUARMState *env, ARMMMUIdx mmu_idx, int32_t address, int *prot); -bool get_phys_addr_pmsav7(CPUARMState *env, uint32_t address, - MMUAccessType access_type, ARMMMUIdx mmu_idx, - hwaddr *phys_ptr, int *prot, - target_ulong *page_size, - ARMMMUFaultInfo *fi); +bool pmsav7_use_background_region(ARMCPU *cpu, ARMMMUIdx mmu_idx, bool is_= user); + bool get_phys_addr_pmsav8(CPUARMState *env, uint32_t address, MMUAccessType access_type, ARMMMUIdx mmu_idx, hwaddr *phys_ptr, MemTxAttrs *txattrs, diff --git a/target/arm/helper.c b/target/arm/helper.c index 7dd54c1863..9cbf3422ec 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -11642,8 +11642,7 @@ do_fault: return true; } =20 -static bool pmsav7_use_background_region(ARMCPU *cpu, - ARMMMUIdx mmu_idx, bool is_user) +bool pmsav7_use_background_region(ARMCPU *cpu, ARMMMUIdx mmu_idx, bool is_= user) { /* Return true if we should use the default memory map as a * "background" region if there are no hits against any MPU regions. @@ -11662,14 +11661,14 @@ static bool pmsav7_use_background_region(ARMCPU *= cpu, } } =20 -static inline bool m_is_ppb_region(CPUARMState *env, uint32_t address) +bool m_is_ppb_region(CPUARMState *env, uint32_t address) { /* True if address is in the M profile PPB region 0xe0000000 - 0xe00ff= fff */ return arm_feature(env, ARM_FEATURE_M) && extract32(address, 20, 12) =3D=3D 0xe00; } =20 -static inline bool m_is_system_region(CPUARMState *env, uint32_t address) +bool m_is_system_region(CPUARMState *env, uint32_t address) { /* True if address is in the M profile system region * 0xe0000000 - 0xffffffff @@ -11677,193 +11676,6 @@ static inline bool m_is_system_region(CPUARMState= *env, uint32_t address) return arm_feature(env, ARM_FEATURE_M) && extract32(address, 29, 3) = =3D=3D 0x7; } =20 -bool get_phys_addr_pmsav7(CPUARMState *env, uint32_t address, - MMUAccessType access_type, ARMMMUIdx mmu_idx, - hwaddr *phys_ptr, int *prot, - target_ulong *page_size, - ARMMMUFaultInfo *fi) -{ - ARMCPU *cpu =3D env_archcpu(env); - int n; - bool is_user =3D regime_is_user(env, mmu_idx); - - *phys_ptr =3D address; - *page_size =3D TARGET_PAGE_SIZE; - *prot =3D 0; - - if (regime_translation_disabled(env, mmu_idx) || - m_is_ppb_region(env, address)) { - /* MPU disabled or M profile PPB access: use default memory map. - * The other case which uses the default memory map in the - * v7M ARM ARM pseudocode is exception vector reads from the vector - * table. In QEMU those accesses are done in arm_v7m_load_vector(), - * which always does a direct read using address_space_ldl(), rath= er - * than going via this function, so we don't need to check that he= re. - */ - get_phys_addr_pmsav7_default(env, mmu_idx, address, prot); - } else { /* MPU enabled */ - for (n =3D (int)cpu->pmsav7_dregion - 1; n >=3D 0; n--) { - /* region search */ - uint32_t base =3D env->pmsav7.drbar[n]; - uint32_t rsize =3D extract32(env->pmsav7.drsr[n], 1, 5); - uint32_t rmask; - bool srdis =3D false; - - if (!(env->pmsav7.drsr[n] & 0x1)) { - continue; - } - - if (!rsize) { - qemu_log_mask(LOG_GUEST_ERROR, - "DRSR[%d]: Rsize field cannot be 0\n", n); - continue; - } - rsize++; - rmask =3D (1ull << rsize) - 1; - - if (base & rmask) { - qemu_log_mask(LOG_GUEST_ERROR, - "DRBAR[%d]: 0x%" PRIx32 " misaligned " - "to DRSR region size, mask =3D 0x%" PRIx32 "= \n", - n, base, rmask); - continue; - } - - if (address < base || address > base + rmask) { - /* - * Address not in this region. We must check whether the - * region covers addresses in the same page as our address. - * In that case we must not report a size that covers the - * whole page for a subsequent hit against a different MPU - * region or the background region, because it would resul= t in - * incorrect TLB hits for subsequent accesses to addresses= that - * are in this MPU region. - */ - if (ranges_overlap(base, rmask, - address & TARGET_PAGE_MASK, - TARGET_PAGE_SIZE)) { - *page_size =3D 1; - } - continue; - } - - /* Region matched */ - - if (rsize >=3D 8) { /* no subregions for regions < 256 bytes */ - int i, snd; - uint32_t srdis_mask; - - rsize -=3D 3; /* sub region size (power of 2) */ - snd =3D ((address - base) >> rsize) & 0x7; - srdis =3D extract32(env->pmsav7.drsr[n], snd + 8, 1); - - srdis_mask =3D srdis ? 0x3 : 0x0; - for (i =3D 2; i <=3D 8 && rsize < TARGET_PAGE_BITS; i *=3D= 2) { - /* This will check in groups of 2, 4 and then 8, wheth= er - * the subregion bits are consistent. rsize is increme= nted - * back up to give the region size, considering consis= tent - * adjacent subregions as one region. Stop testing if = rsize - * is already big enough for an entire QEMU page. - */ - int snd_rounded =3D snd & ~(i - 1); - uint32_t srdis_multi =3D extract32(env->pmsav7.drsr[n], - snd_rounded + 8, i); - if (srdis_mask ^ srdis_multi) { - break; - } - srdis_mask =3D (srdis_mask << i) | srdis_mask; - rsize++; - } - } - if (srdis) { - continue; - } - if (rsize < TARGET_PAGE_BITS) { - *page_size =3D 1 << rsize; - } - break; - } - - if (n =3D=3D -1) { /* no hits */ - if (!pmsav7_use_background_region(cpu, mmu_idx, is_user)) { - /* background fault */ - fi->type =3D ARMFault_Background; - return true; - } - get_phys_addr_pmsav7_default(env, mmu_idx, address, prot); - } else { /* a MPU hit! */ - uint32_t ap =3D extract32(env->pmsav7.dracr[n], 8, 3); - uint32_t xn =3D extract32(env->pmsav7.dracr[n], 12, 1); - - if (m_is_system_region(env, address)) { - /* System space is always execute never */ - xn =3D 1; - } - - if (is_user) { /* User mode AP bit decoding */ - switch (ap) { - case 0: - case 1: - case 5: - break; /* no access */ - case 3: - *prot |=3D PAGE_WRITE; - /* fall through */ - case 2: - case 6: - *prot |=3D PAGE_READ | PAGE_EXEC; - break; - case 7: - /* for v7M, same as 6; for R profile a reserved value = */ - if (arm_feature(env, ARM_FEATURE_M)) { - *prot |=3D PAGE_READ | PAGE_EXEC; - break; - } - /* fall through */ - default: - qemu_log_mask(LOG_GUEST_ERROR, - "DRACR[%d]: Bad value for AP bits: 0x%" - PRIx32 "\n", n, ap); - } - } else { /* Priv. mode AP bits decoding */ - switch (ap) { - case 0: - break; /* no access */ - case 1: - case 2: - case 3: - *prot |=3D PAGE_WRITE; - /* fall through */ - case 5: - case 6: - *prot |=3D PAGE_READ | PAGE_EXEC; - break; - case 7: - /* for v7M, same as 6; for R profile a reserved value = */ - if (arm_feature(env, ARM_FEATURE_M)) { - *prot |=3D PAGE_READ | PAGE_EXEC; - break; - } - /* fall through */ - default: - qemu_log_mask(LOG_GUEST_ERROR, - "DRACR[%d]: Bad value for AP bits: 0x%" - PRIx32 "\n", n, ap); - } - } - - /* execute never */ - if (xn) { - *prot &=3D ~PAGE_EXEC; - } - } - } - - fi->type =3D ARMFault_Permission; - fi->level =3D 1; - return !(*prot & (1 << access_type)); -} - static bool v8m_is_sau_exempt(CPUARMState *env, uint32_t address, MMUAccessType access_type) { diff --git a/target/arm/ptw.c b/target/arm/ptw.c index 74650c6c52..27715dbfa8 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -8,6 +8,7 @@ =20 #include "qemu/osdep.h" #include "qemu/log.h" +#include "qemu/range.h" #include "cpu.h" #include "internals.h" #include "ptw.h" @@ -415,6 +416,195 @@ void get_phys_addr_pmsav7_default(CPUARMState *env, } } =20 +static bool get_phys_addr_pmsav7(CPUARMState *env, uint32_t address, + MMUAccessType access_type, ARMMMUIdx mmu_= idx, + hwaddr *phys_ptr, int *prot, + target_ulong *page_size, + ARMMMUFaultInfo *fi) +{ + ARMCPU *cpu =3D env_archcpu(env); + int n; + bool is_user =3D regime_is_user(env, mmu_idx); + + *phys_ptr =3D address; + *page_size =3D TARGET_PAGE_SIZE; + *prot =3D 0; + + if (regime_translation_disabled(env, mmu_idx) || + m_is_ppb_region(env, address)) { + /* + * MPU disabled or M profile PPB access: use default memory map. + * The other case which uses the default memory map in the + * v7M ARM ARM pseudocode is exception vector reads from the vector + * table. In QEMU those accesses are done in arm_v7m_load_vector(), + * which always does a direct read using address_space_ldl(), rath= er + * than going via this function, so we don't need to check that he= re. + */ + get_phys_addr_pmsav7_default(env, mmu_idx, address, prot); + } else { /* MPU enabled */ + for (n =3D (int)cpu->pmsav7_dregion - 1; n >=3D 0; n--) { + /* region search */ + uint32_t base =3D env->pmsav7.drbar[n]; + uint32_t rsize =3D extract32(env->pmsav7.drsr[n], 1, 5); + uint32_t rmask; + bool srdis =3D false; + + if (!(env->pmsav7.drsr[n] & 0x1)) { + continue; + } + + if (!rsize) { + qemu_log_mask(LOG_GUEST_ERROR, + "DRSR[%d]: Rsize field cannot be 0\n", n); + continue; + } + rsize++; + rmask =3D (1ull << rsize) - 1; + + if (base & rmask) { + qemu_log_mask(LOG_GUEST_ERROR, + "DRBAR[%d]: 0x%" PRIx32 " misaligned " + "to DRSR region size, mask =3D 0x%" PRIx32 "= \n", + n, base, rmask); + continue; + } + + if (address < base || address > base + rmask) { + /* + * Address not in this region. We must check whether the + * region covers addresses in the same page as our address. + * In that case we must not report a size that covers the + * whole page for a subsequent hit against a different MPU + * region or the background region, because it would resul= t in + * incorrect TLB hits for subsequent accesses to addresses= that + * are in this MPU region. + */ + if (ranges_overlap(base, rmask, + address & TARGET_PAGE_MASK, + TARGET_PAGE_SIZE)) { + *page_size =3D 1; + } + continue; + } + + /* Region matched */ + + if (rsize >=3D 8) { /* no subregions for regions < 256 bytes */ + int i, snd; + uint32_t srdis_mask; + + rsize -=3D 3; /* sub region size (power of 2) */ + snd =3D ((address - base) >> rsize) & 0x7; + srdis =3D extract32(env->pmsav7.drsr[n], snd + 8, 1); + + srdis_mask =3D srdis ? 0x3 : 0x0; + for (i =3D 2; i <=3D 8 && rsize < TARGET_PAGE_BITS; i *=3D= 2) { + /* + * This will check in groups of 2, 4 and then 8, wheth= er + * the subregion bits are consistent. rsize is increme= nted + * back up to give the region size, considering consis= tent + * adjacent subregions as one region. Stop testing if = rsize + * is already big enough for an entire QEMU page. + */ + int snd_rounded =3D snd & ~(i - 1); + uint32_t srdis_multi =3D extract32(env->pmsav7.drsr[n], + snd_rounded + 8, i); + if (srdis_mask ^ srdis_multi) { + break; + } + srdis_mask =3D (srdis_mask << i) | srdis_mask; + rsize++; + } + } + if (srdis) { + continue; + } + if (rsize < TARGET_PAGE_BITS) { + *page_size =3D 1 << rsize; + } + break; + } + + if (n =3D=3D -1) { /* no hits */ + if (!pmsav7_use_background_region(cpu, mmu_idx, is_user)) { + /* background fault */ + fi->type =3D ARMFault_Background; + return true; + } + get_phys_addr_pmsav7_default(env, mmu_idx, address, prot); + } else { /* a MPU hit! */ + uint32_t ap =3D extract32(env->pmsav7.dracr[n], 8, 3); + uint32_t xn =3D extract32(env->pmsav7.dracr[n], 12, 1); + + if (m_is_system_region(env, address)) { + /* System space is always execute never */ + xn =3D 1; + } + + if (is_user) { /* User mode AP bit decoding */ + switch (ap) { + case 0: + case 1: + case 5: + break; /* no access */ + case 3: + *prot |=3D PAGE_WRITE; + /* fall through */ + case 2: + case 6: + *prot |=3D PAGE_READ | PAGE_EXEC; + break; + case 7: + /* for v7M, same as 6; for R profile a reserved value = */ + if (arm_feature(env, ARM_FEATURE_M)) { + *prot |=3D PAGE_READ | PAGE_EXEC; + break; + } + /* fall through */ + default: + qemu_log_mask(LOG_GUEST_ERROR, + "DRACR[%d]: Bad value for AP bits: 0x%" + PRIx32 "\n", n, ap); + } + } else { /* Priv. mode AP bits decoding */ + switch (ap) { + case 0: + break; /* no access */ + case 1: + case 2: + case 3: + *prot |=3D PAGE_WRITE; + /* fall through */ + case 5: + case 6: + *prot |=3D PAGE_READ | PAGE_EXEC; + break; + case 7: + /* for v7M, same as 6; for R profile a reserved value = */ + if (arm_feature(env, ARM_FEATURE_M)) { + *prot |=3D PAGE_READ | PAGE_EXEC; + break; + } + /* fall through */ + default: + qemu_log_mask(LOG_GUEST_ERROR, + "DRACR[%d]: Bad value for AP bits: 0x%" + PRIx32 "\n", n, ap); + } + } + + /* execute never */ + if (xn) { + *prot &=3D ~PAGE_EXEC; + } + } + } + + fi->type =3D ARMFault_Permission; + fi->level =3D 1; + return !(*prot & (1 << access_type)); +} + /** * get_phys_addr - get the physical address for this virtual address * --=20 2.34.1 From nobody Fri May 17 05:50:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1654316518; cv=none; d=zohomail.com; s=zohoarc; b=akzIBblC9GW6MRztMtKVqp8ylc8WjKtp7FiqIVXusK3HivEjTRM3Smc0K26GGRshqnFqZwybfG9y6UpGaS75WD7qv98iokf18P+xKSQk6GjKY/+n73Ngqyk7A4EaQj+NXYDZTlvlbJ09EIjeoS4+IaPftWYZ94xbOjjwVcOKXx0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1654316518; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=imn8BMnL3CE4pofCY4yxiePLLdSnSVld4nZ1ecZHC48=; b=Sfb6rohAk5qwQbiDdJ9XBMHmS22A2PgSl16pvOMHRr21EMIDnaw0xLckDdAsOrNvGehxt5cVePrbFGrU0Ov/Lrg2yCfGJb429jl1cgnyGweDNbPKnODt6hN2t69h8OUglkPHQ7H3BWmDcSZ9JItwQh69TCND67oN5Yz4lNooiLU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1654316518914459.1948077714526; Fri, 3 Jun 2022 21:21:58 -0700 (PDT) Received: from localhost ([::1]:48320 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nxLIS-0005n2-0f for importer@patchew.org; Sat, 04 Jun 2022 00:21:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36678) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nxL3M-0007iw-PY for qemu-devel@nongnu.org; Sat, 04 Jun 2022 00:06:20 -0400 Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]:36412) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nxL3K-00005b-B2 for qemu-devel@nongnu.org; Sat, 04 Jun 2022 00:06:20 -0400 Received: by mail-pj1-x1035.google.com with SMTP id u12-20020a17090a1d4c00b001df78c7c209so13537362pju.1 for ; Fri, 03 Jun 2022 21:06:17 -0700 (PDT) Received: from stoup.. ([2602:ae:1547:e101:3286:cc26:3d5e:3f94]) by smtp.gmail.com with ESMTPSA id a37-20020a631a65000000b003c14af50626sm6093779pgm.62.2022.06.03.21.06.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jun 2022 21:06:16 -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=imn8BMnL3CE4pofCY4yxiePLLdSnSVld4nZ1ecZHC48=; b=oBuqIIcekf5lv9ER91tzkrbcNXEAOpl4Hzh88GsWOAeztZFqxssfaI74sV335pPXwx wXztPNcmw6vPJLH+HYm32XMTG+j/RZGd+kpmi/K0Il6zBlINC3F4udAnyTjBi5b3mY+C /I3C3cZYGe4pZ5WUMcZpfoInBkhOIr4UdQG5VLsag6kS8YfM4SEsk0/fGxH/G4Hg2ylU IjsWiRSIgL+3HFaniZ+GENn0WQwEjGi17VazXJfrhw5PxCuVcIXcwdIKGYfKALLpHGr3 VDy3GtqCEqtzvK4T/0s/coY5KH0yaLyg03gu33VVpL8zomJZAW8s1gMvTn7VVit9oWVG VroA== 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=imn8BMnL3CE4pofCY4yxiePLLdSnSVld4nZ1ecZHC48=; b=zBD9+zIBlrIkE9Ez1sf0YFi25MYf8w3J6/1OzoRahnMrWRRNeCDDSR+Ckx7RPnNI/s qPN5tDD2EFcVMYUkQJEvcZZ1JiKxeyULwkK/26/dXpAj+uW6whC6ehbR7JDgjmvWItK3 +DICPAGMo5IQjvDKFawGWDvVl9IDsxQxG+JUyjDgV4fV5mKQyQvGWv82gu9pPheSQk4R ggMOkGHG6pThgr0V4zhFD0GWMSdSovSdzHjtPIN2EJTT6ls91L9KD8n1YutRw2SREqTb NCDaLi4Plj9rhntJkm5mixasms7GzmfmWh3bbG/GZ7W3YxGMyFeMQb6Gots8qBh6Kd8m ewyQ== X-Gm-Message-State: AOAM533yJj7l+wyUaLnQ3DsqiUzqbj7okgo/IYlGrf6jLq2bWjnfpcxn 0fEH9MVOUcMJTQVCV2r72Kr0PqTow1LR2w== X-Google-Smtp-Source: ABdhPJynJYvstX2X8/Y4ZwgT4VU9sShElsn9+E31WJ5GLF2EzEh+yPuALSrMBPASgVBejvLuzZQxwg== X-Received: by 2002:a17:90b:4c88:b0:1e6:71da:5eb0 with SMTP id my8-20020a17090b4c8800b001e671da5eb0mr15634390pjb.185.1654315576951; Fri, 03 Jun 2022 21:06:16 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Subject: [PATCH 08/28] target/arm: Move get_phys_addr_pmsav8 to ptw.c Date: Fri, 3 Jun 2022 21:05:47 -0700 Message-Id: <20220604040607.269301-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220604040607.269301-1-richard.henderson@linaro.org> References: <20220604040607.269301-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=2607:f8b0:4864:20::1035; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1035.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=ham 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1654316519942100002 Content-Type: text/plain; charset="utf-8" Signed-off-by: Richard Henderson --- target/arm/ptw.h | 5 --- target/arm/helper.c | 75 ------------------------------------------- target/arm/ptw.c | 77 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 80 deletions(-) diff --git a/target/arm/ptw.h b/target/arm/ptw.h index d24b7c263a..d569507951 100644 --- a/target/arm/ptw.h +++ b/target/arm/ptw.h @@ -41,11 +41,6 @@ void get_phys_addr_pmsav7_default(CPUARMState *env, int32_t address, int *prot); bool pmsav7_use_background_region(ARMCPU *cpu, ARMMMUIdx mmu_idx, bool is_= user); =20 -bool get_phys_addr_pmsav8(CPUARMState *env, uint32_t address, - MMUAccessType access_type, ARMMMUIdx mmu_idx, - hwaddr *phys_ptr, MemTxAttrs *txattrs, - int *prot, target_ulong *page_size, - ARMMMUFaultInfo *fi); bool get_phys_addr_lpae(CPUARMState *env, uint64_t address, MMUAccessType access_type, ARMMMUIdx mmu_idx, bool s1_is_el0, diff --git a/target/arm/helper.c b/target/arm/helper.c index 9cbf3422ec..c1d0726464 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -11934,81 +11934,6 @@ bool pmsav8_mpu_lookup(CPUARMState *env, uint32_t = address, return !(*prot & (1 << access_type)); } =20 - -bool get_phys_addr_pmsav8(CPUARMState *env, uint32_t address, - MMUAccessType access_type, ARMMMUIdx mmu_idx, - hwaddr *phys_ptr, MemTxAttrs *txattrs, - int *prot, target_ulong *page_size, - ARMMMUFaultInfo *fi) -{ - uint32_t secure =3D regime_is_secure(env, mmu_idx); - V8M_SAttributes sattrs =3D {}; - bool ret; - bool mpu_is_subpage; - - if (arm_feature(env, ARM_FEATURE_M_SECURITY)) { - v8m_security_lookup(env, address, access_type, mmu_idx, &sattrs); - if (access_type =3D=3D MMU_INST_FETCH) { - /* Instruction fetches always use the MMU bank and the - * transaction attribute determined by the fetch address, - * regardless of CPU state. This is painful for QEMU - * to handle, because it would mean we need to encode - * into the mmu_idx not just the (user, negpri) information - * for the current security state but also that for the - * other security state, which would balloon the number - * of mmu_idx values needed alarmingly. - * Fortunately we can avoid this because it's not actually - * possible to arbitrarily execute code from memory with - * the wrong security attribute: it will always generate - * an exception of some kind or another, apart from the - * special case of an NS CPU executing an SG instruction - * in S&NSC memory. So we always just fail the translation - * here and sort things out in the exception handler - * (including possibly emulating an SG instruction). - */ - if (sattrs.ns !=3D !secure) { - if (sattrs.nsc) { - fi->type =3D ARMFault_QEMU_NSCExec; - } else { - fi->type =3D ARMFault_QEMU_SFault; - } - *page_size =3D sattrs.subpage ? 1 : TARGET_PAGE_SIZE; - *phys_ptr =3D address; - *prot =3D 0; - return true; - } - } else { - /* For data accesses we always use the MMU bank indicated - * by the current CPU state, but the security attributes - * might downgrade a secure access to nonsecure. - */ - if (sattrs.ns) { - txattrs->secure =3D false; - } else if (!secure) { - /* NS access to S memory must fault. - * Architecturally we should first check whether the - * MPU information for this address indicates that we - * are doing an unaligned access to Device memory, which - * should generate a UsageFault instead. QEMU does not - * currently check for that kind of unaligned access thoug= h. - * If we added it we would need to do so as a special case - * for M_FAKE_FSR_SFAULT in arm_v7m_cpu_do_interrupt(). - */ - fi->type =3D ARMFault_QEMU_SFault; - *page_size =3D sattrs.subpage ? 1 : TARGET_PAGE_SIZE; - *phys_ptr =3D address; - *prot =3D 0; - return true; - } - } - } - - ret =3D pmsav8_mpu_lookup(env, address, access_type, mmu_idx, phys_ptr, - txattrs, prot, &mpu_is_subpage, fi, NULL); - *page_size =3D sattrs.subpage || mpu_is_subpage ? 1 : TARGET_PAGE_SIZE; - return ret; -} - /* Combine either inner or outer cacheability attributes for normal * memory, according to table D4-42 and pseudocode procedure * CombineS1S2AttrHints() of ARM DDI 0487B.b (the ARMv8 ARM). diff --git a/target/arm/ptw.c b/target/arm/ptw.c index 27715dbfa8..28caa7a7ae 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -605,6 +605,83 @@ static bool get_phys_addr_pmsav7(CPUARMState *env, uin= t32_t address, return !(*prot & (1 << access_type)); } =20 +static bool get_phys_addr_pmsav8(CPUARMState *env, uint32_t address, + MMUAccessType access_type, ARMMMUIdx mmu_= idx, + hwaddr *phys_ptr, MemTxAttrs *txattrs, + int *prot, target_ulong *page_size, + ARMMMUFaultInfo *fi) +{ + uint32_t secure =3D regime_is_secure(env, mmu_idx); + V8M_SAttributes sattrs =3D {}; + bool ret; + bool mpu_is_subpage; + + if (arm_feature(env, ARM_FEATURE_M_SECURITY)) { + v8m_security_lookup(env, address, access_type, mmu_idx, &sattrs); + if (access_type =3D=3D MMU_INST_FETCH) { + /* + * Instruction fetches always use the MMU bank and the + * transaction attribute determined by the fetch address, + * regardless of CPU state. This is painful for QEMU + * to handle, because it would mean we need to encode + * into the mmu_idx not just the (user, negpri) information + * for the current security state but also that for the + * other security state, which would balloon the number + * of mmu_idx values needed alarmingly. + * Fortunately we can avoid this because it's not actually + * possible to arbitrarily execute code from memory with + * the wrong security attribute: it will always generate + * an exception of some kind or another, apart from the + * special case of an NS CPU executing an SG instruction + * in S&NSC memory. So we always just fail the translation + * here and sort things out in the exception handler + * (including possibly emulating an SG instruction). + */ + if (sattrs.ns !=3D !secure) { + if (sattrs.nsc) { + fi->type =3D ARMFault_QEMU_NSCExec; + } else { + fi->type =3D ARMFault_QEMU_SFault; + } + *page_size =3D sattrs.subpage ? 1 : TARGET_PAGE_SIZE; + *phys_ptr =3D address; + *prot =3D 0; + return true; + } + } else { + /* + * For data accesses we always use the MMU bank indicated + * by the current CPU state, but the security attributes + * might downgrade a secure access to nonsecure. + */ + if (sattrs.ns) { + txattrs->secure =3D false; + } else if (!secure) { + /* + * NS access to S memory must fault. + * Architecturally we should first check whether the + * MPU information for this address indicates that we + * are doing an unaligned access to Device memory, which + * should generate a UsageFault instead. QEMU does not + * currently check for that kind of unaligned access thoug= h. + * If we added it we would need to do so as a special case + * for M_FAKE_FSR_SFAULT in arm_v7m_cpu_do_interrupt(). + */ + fi->type =3D ARMFault_QEMU_SFault; + *page_size =3D sattrs.subpage ? 1 : TARGET_PAGE_SIZE; + *phys_ptr =3D address; + *prot =3D 0; + return true; + } + } + } + + ret =3D pmsav8_mpu_lookup(env, address, access_type, mmu_idx, phys_ptr, + txattrs, prot, &mpu_is_subpage, fi, NULL); + *page_size =3D sattrs.subpage || mpu_is_subpage ? 1 : TARGET_PAGE_SIZE; + return ret; +} + /** * get_phys_addr - get the physical address for this virtual address * --=20 2.34.1 From nobody Fri May 17 05:50:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1654316805; cv=none; d=zohomail.com; s=zohoarc; b=eWup5S2caOwGPvS43vT0Bonl0yKae92MZdIcEjXNfdNORDPxeOQxFZtcqjkgqVBTz/8RaFRDBC3kmXFOoIQjhe/rOiiW1ssHryZhXUvuY6WttzuQEnsNaR/rZ2Iy306QEd1KkpdxucHrzPHxn0hPhrXp2507CJez91uT67G83Lk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1654316805; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=VEJJ2C6mFESBNlktiX2W24iu4e0DcpTQfDtyrXSkg6s=; b=lPn6YVr8EAL9yn3qB2zbnvehU22WnP4aowIVIW3QRXs1Hd0sXU70w/qMafyarVCQzI0Q3/GPeo1yYcJhlXTGeycJ9f1f2O6Z1IZX9IvjvA+R87jtqqLICldz8e7HnvKfUg7ojoJf8ie0mPYcK78+RxRlOCtLRg1qeDIqqOVf4/g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1654316805953777.0488031368126; Fri, 3 Jun 2022 21:26:45 -0700 (PDT) Received: from localhost ([::1]:55062 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nxLN6-0002BH-Nn for importer@patchew.org; Sat, 04 Jun 2022 00:26:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36730) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nxL3O-0007ls-11 for qemu-devel@nongnu.org; Sat, 04 Jun 2022 00:06:22 -0400 Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]:54159) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nxL3L-00006C-BK for qemu-devel@nongnu.org; Sat, 04 Jun 2022 00:06:21 -0400 Received: by mail-pj1-x1032.google.com with SMTP id a10so8694786pju.3 for ; Fri, 03 Jun 2022 21:06:18 -0700 (PDT) Received: from stoup.. ([2602:ae:1547:e101:3286:cc26:3d5e:3f94]) by smtp.gmail.com with ESMTPSA id a37-20020a631a65000000b003c14af50626sm6093779pgm.62.2022.06.03.21.06.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jun 2022 21:06:17 -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=VEJJ2C6mFESBNlktiX2W24iu4e0DcpTQfDtyrXSkg6s=; b=gU98MvMybyBvqxOZGfj/GvLTT+3jKFulN+zkpsC/+TYb4r0TJR5UQ1YZGVzm9GRCCg 0kLwuF59jG6zowsicZSGvwEwcQlvOUpGfO+L48jYr5JCPW+hxgVU9O6ddfkiEaxCkqMc INQCylBErw+PjDzkpLYLHUQC9/EAePnHd6yhRcplbo4gHi/DvqcaiuDz/S+h+FfpQPoG 37+T/9s0c4UVDFjVzfSGGHoRWfiyW84YmzY9GEI9k1V+0aekuFMEQ/yw/e6+IlRMyUkA 9d5QJUPQz0O6eyApS2qZegdPJvLVlAC7OSIuxV54zSwZLXF5MByAtvCRX/IOjP6ABu73 ZHVA== 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=VEJJ2C6mFESBNlktiX2W24iu4e0DcpTQfDtyrXSkg6s=; b=tnFctS4PI6ejLrxAX3By35rfQfGXzpRDdB9f00GgFUymH9BDG8H755dOXsRKJGvCgB R5n7Tlh7Lqv3vvLbArVqlmx425Un3s9vmdgqZgGdvi3wGIyEPyTmyZi5W83qKNvgytuW tpSgbIjm3J12h3Fh9DfAl3rw0BSA7BFmJclTJBJnKbZZgKfw/HJq0PEA7FJXLQIO9mX8 u7RKqu39Z6sdLhXEErkTUp8CvsmcXRqH3hF8y3ZqtI6cnSSSmOa2w2EslXQccN2UVc74 HTRnrk1AXaEgaltSMFQHqt/pVKjJy3ISgt7N9SZELAMlByI58sGOBaXnEzfjqYAK+Srs 2Jxg== X-Gm-Message-State: AOAM531qpnVixO3nG2iu1u0VfAseImvJcWYfGerXYYKSRftmGKyVPSs3 4r8fMcVTu0vg0I+UUwvGteKMBqOzCHu4Mg== X-Google-Smtp-Source: ABdhPJwpbsN6G0KeqYwl+jKZsRQz7CJ8k+mV1Dv8D0V+zLE/UxgjDXjVX2pUZLp9dX+c8nmP37coGg== X-Received: by 2002:a17:902:9f96:b0:163:dc33:6b72 with SMTP id g22-20020a1709029f9600b00163dc336b72mr13240235plq.34.1654315577767; Fri, 03 Jun 2022 21:06:17 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Subject: [PATCH 09/28] target/arm: Move pmsav8_mpu_lookup to ptw.c Date: Fri, 3 Jun 2022 21:05:48 -0700 Message-Id: <20220604040607.269301-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220604040607.269301-1-richard.henderson@linaro.org> References: <20220604040607.269301-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=2607:f8b0:4864:20::1032; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1032.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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1654316807174100001 Content-Type: text/plain; charset="utf-8" This is the final user of get_phys_addr_pmsav7_default within helper.c, so make it static within ptw.c. Signed-off-by: Richard Henderson --- target/arm/ptw.h | 3 - target/arm/helper.c | 136 ----------------------------------------- target/arm/ptw.c | 146 +++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 143 insertions(+), 142 deletions(-) diff --git a/target/arm/ptw.h b/target/arm/ptw.h index d569507951..8d2e239714 100644 --- a/target/arm/ptw.h +++ b/target/arm/ptw.h @@ -36,9 +36,6 @@ simple_ap_to_rw_prot(CPUARMState *env, ARMMMUIdx mmu_idx,= int ap) bool m_is_ppb_region(CPUARMState *env, uint32_t address); bool m_is_system_region(CPUARMState *env, uint32_t address); =20 -void get_phys_addr_pmsav7_default(CPUARMState *env, - ARMMMUIdx mmu_idx, - int32_t address, int *prot); bool pmsav7_use_background_region(ARMCPU *cpu, ARMMMUIdx mmu_idx, bool is_= user); =20 bool get_phys_addr_lpae(CPUARMState *env, uint64_t address, diff --git a/target/arm/helper.c b/target/arm/helper.c index c1d0726464..a8186ac138 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -11798,142 +11798,6 @@ void v8m_security_lookup(CPUARMState *env, uint32= _t address, } } =20 -bool pmsav8_mpu_lookup(CPUARMState *env, uint32_t address, - MMUAccessType access_type, ARMMMUIdx mmu_idx, - hwaddr *phys_ptr, MemTxAttrs *txattrs, - int *prot, bool *is_subpage, - ARMMMUFaultInfo *fi, uint32_t *mregion) -{ - /* Perform a PMSAv8 MPU lookup (without also doing the SAU check - * that a full phys-to-virt translation does). - * mregion is (if not NULL) set to the region number which matched, - * or -1 if no region number is returned (MPU off, address did not - * hit a region, address hit in multiple regions). - * We set is_subpage to true if the region hit doesn't cover the - * entire TARGET_PAGE the address is within. - */ - ARMCPU *cpu =3D env_archcpu(env); - bool is_user =3D regime_is_user(env, mmu_idx); - uint32_t secure =3D regime_is_secure(env, mmu_idx); - int n; - int matchregion =3D -1; - bool hit =3D false; - uint32_t addr_page_base =3D address & TARGET_PAGE_MASK; - uint32_t addr_page_limit =3D addr_page_base + (TARGET_PAGE_SIZE - 1); - - *is_subpage =3D false; - *phys_ptr =3D address; - *prot =3D 0; - if (mregion) { - *mregion =3D -1; - } - - /* Unlike the ARM ARM pseudocode, we don't need to check whether this - * was an exception vector read from the vector table (which is always - * done using the default system address map), because those accesses - * are done in arm_v7m_load_vector(), which always does a direct - * read using address_space_ldl(), rather than going via this function. - */ - if (regime_translation_disabled(env, mmu_idx)) { /* MPU disabled */ - hit =3D true; - } else if (m_is_ppb_region(env, address)) { - hit =3D true; - } else { - if (pmsav7_use_background_region(cpu, mmu_idx, is_user)) { - hit =3D true; - } - - for (n =3D (int)cpu->pmsav7_dregion - 1; n >=3D 0; n--) { - /* region search */ - /* Note that the base address is bits [31:5] from the register - * with bits [4:0] all zeroes, but the limit address is bits - * [31:5] from the register with bits [4:0] all ones. - */ - uint32_t base =3D env->pmsav8.rbar[secure][n] & ~0x1f; - uint32_t limit =3D env->pmsav8.rlar[secure][n] | 0x1f; - - if (!(env->pmsav8.rlar[secure][n] & 0x1)) { - /* Region disabled */ - continue; - } - - if (address < base || address > limit) { - /* - * Address not in this region. We must check whether the - * region covers addresses in the same page as our address. - * In that case we must not report a size that covers the - * whole page for a subsequent hit against a different MPU - * region or the background region, because it would resul= t in - * incorrect TLB hits for subsequent accesses to addresses= that - * are in this MPU region. - */ - if (limit >=3D base && - ranges_overlap(base, limit - base + 1, - addr_page_base, - TARGET_PAGE_SIZE)) { - *is_subpage =3D true; - } - continue; - } - - if (base > addr_page_base || limit < addr_page_limit) { - *is_subpage =3D true; - } - - if (matchregion !=3D -1) { - /* Multiple regions match -- always a failure (unlike - * PMSAv7 where highest-numbered-region wins) - */ - fi->type =3D ARMFault_Permission; - fi->level =3D 1; - return true; - } - - matchregion =3D n; - hit =3D true; - } - } - - if (!hit) { - /* background fault */ - fi->type =3D ARMFault_Background; - return true; - } - - if (matchregion =3D=3D -1) { - /* hit using the background region */ - get_phys_addr_pmsav7_default(env, mmu_idx, address, prot); - } else { - uint32_t ap =3D extract32(env->pmsav8.rbar[secure][matchregion], 1= , 2); - uint32_t xn =3D extract32(env->pmsav8.rbar[secure][matchregion], 0= , 1); - bool pxn =3D false; - - if (arm_feature(env, ARM_FEATURE_V8_1M)) { - pxn =3D extract32(env->pmsav8.rlar[secure][matchregion], 4, 1); - } - - if (m_is_system_region(env, address)) { - /* System space is always execute never */ - xn =3D 1; - } - - *prot =3D simple_ap_to_rw_prot(env, mmu_idx, ap); - if (*prot && !xn && !(pxn && !is_user)) { - *prot |=3D PAGE_EXEC; - } - /* We don't need to look the attribute up in the MAIR0/MAIR1 - * registers because that only tells us about cacheability. - */ - if (mregion) { - *mregion =3D matchregion; - } - } - - fi->type =3D ARMFault_Permission; - fi->level =3D 1; - return !(*prot & (1 << access_type)); -} - /* Combine either inner or outer cacheability attributes for normal * memory, according to table D4-42 and pseudocode procedure * CombineS1S2AttrHints() of ARM DDI 0487B.b (the ARMv8 ARM). diff --git a/target/arm/ptw.c b/target/arm/ptw.c index 28caa7a7ae..989e783cce 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -375,9 +375,8 @@ static bool get_phys_addr_pmsav5(CPUARMState *env, uint= 32_t address, return false; } =20 -void get_phys_addr_pmsav7_default(CPUARMState *env, - ARMMMUIdx mmu_idx, - int32_t address, int *prot) +static void get_phys_addr_pmsav7_default(CPUARMState *env, ARMMMUIdx mmu_i= dx, + int32_t address, int *prot) { if (!arm_feature(env, ARM_FEATURE_M)) { *prot =3D PAGE_READ | PAGE_WRITE; @@ -605,6 +604,147 @@ static bool get_phys_addr_pmsav7(CPUARMState *env, ui= nt32_t address, return !(*prot & (1 << access_type)); } =20 +bool pmsav8_mpu_lookup(CPUARMState *env, uint32_t address, + MMUAccessType access_type, ARMMMUIdx mmu_idx, + hwaddr *phys_ptr, MemTxAttrs *txattrs, + int *prot, bool *is_subpage, + ARMMMUFaultInfo *fi, uint32_t *mregion) +{ + /* + * Perform a PMSAv8 MPU lookup (without also doing the SAU check + * that a full phys-to-virt translation does). + * mregion is (if not NULL) set to the region number which matched, + * or -1 if no region number is returned (MPU off, address did not + * hit a region, address hit in multiple regions). + * We set is_subpage to true if the region hit doesn't cover the + * entire TARGET_PAGE the address is within. + */ + ARMCPU *cpu =3D env_archcpu(env); + bool is_user =3D regime_is_user(env, mmu_idx); + uint32_t secure =3D regime_is_secure(env, mmu_idx); + int n; + int matchregion =3D -1; + bool hit =3D false; + uint32_t addr_page_base =3D address & TARGET_PAGE_MASK; + uint32_t addr_page_limit =3D addr_page_base + (TARGET_PAGE_SIZE - 1); + + *is_subpage =3D false; + *phys_ptr =3D address; + *prot =3D 0; + if (mregion) { + *mregion =3D -1; + } + + /* + * Unlike the ARM ARM pseudocode, we don't need to check whether this + * was an exception vector read from the vector table (which is always + * done using the default system address map), because those accesses + * are done in arm_v7m_load_vector(), which always does a direct + * read using address_space_ldl(), rather than going via this function. + */ + if (regime_translation_disabled(env, mmu_idx)) { /* MPU disabled */ + hit =3D true; + } else if (m_is_ppb_region(env, address)) { + hit =3D true; + } else { + if (pmsav7_use_background_region(cpu, mmu_idx, is_user)) { + hit =3D true; + } + + for (n =3D (int)cpu->pmsav7_dregion - 1; n >=3D 0; n--) { + /* region search */ + /* + * Note that the base address is bits [31:5] from the register + * with bits [4:0] all zeroes, but the limit address is bits + * [31:5] from the register with bits [4:0] all ones. + */ + uint32_t base =3D env->pmsav8.rbar[secure][n] & ~0x1f; + uint32_t limit =3D env->pmsav8.rlar[secure][n] | 0x1f; + + if (!(env->pmsav8.rlar[secure][n] & 0x1)) { + /* Region disabled */ + continue; + } + + if (address < base || address > limit) { + /* + * Address not in this region. We must check whether the + * region covers addresses in the same page as our address. + * In that case we must not report a size that covers the + * whole page for a subsequent hit against a different MPU + * region or the background region, because it would resul= t in + * incorrect TLB hits for subsequent accesses to addresses= that + * are in this MPU region. + */ + if (limit >=3D base && + ranges_overlap(base, limit - base + 1, + addr_page_base, + TARGET_PAGE_SIZE)) { + *is_subpage =3D true; + } + continue; + } + + if (base > addr_page_base || limit < addr_page_limit) { + *is_subpage =3D true; + } + + if (matchregion !=3D -1) { + /* + * Multiple regions match -- always a failure (unlike + * PMSAv7 where highest-numbered-region wins) + */ + fi->type =3D ARMFault_Permission; + fi->level =3D 1; + return true; + } + + matchregion =3D n; + hit =3D true; + } + } + + if (!hit) { + /* background fault */ + fi->type =3D ARMFault_Background; + return true; + } + + if (matchregion =3D=3D -1) { + /* hit using the background region */ + get_phys_addr_pmsav7_default(env, mmu_idx, address, prot); + } else { + uint32_t ap =3D extract32(env->pmsav8.rbar[secure][matchregion], 1= , 2); + uint32_t xn =3D extract32(env->pmsav8.rbar[secure][matchregion], 0= , 1); + bool pxn =3D false; + + if (arm_feature(env, ARM_FEATURE_V8_1M)) { + pxn =3D extract32(env->pmsav8.rlar[secure][matchregion], 4, 1); + } + + if (m_is_system_region(env, address)) { + /* System space is always execute never */ + xn =3D 1; + } + + *prot =3D simple_ap_to_rw_prot(env, mmu_idx, ap); + if (*prot && !xn && !(pxn && !is_user)) { + *prot |=3D PAGE_EXEC; + } + /* + * We don't need to look the attribute up in the MAIR0/MAIR1 + * registers because that only tells us about cacheability. + */ + if (mregion) { + *mregion =3D matchregion; + } + } + + fi->type =3D ARMFault_Permission; + fi->level =3D 1; + return !(*prot & (1 << access_type)); +} + static bool get_phys_addr_pmsav8(CPUARMState *env, uint32_t address, MMUAccessType access_type, ARMMMUIdx mmu_= idx, hwaddr *phys_ptr, MemTxAttrs *txattrs, --=20 2.34.1 From nobody Fri May 17 05:50:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1654316258; cv=none; d=zohomail.com; s=zohoarc; b=JJBZW51hFMj7hIJnTIrg1+OYRkxgQvBI67g3b1muyA/JySGpJ4kBufgs5L5RG3E5QETI4LH0Mbj5oiCjY72DhyoSj8otbOqDHWVHCBQ/5wozZjr/bjIoEKDm0T/helTMN7vVjBZBO6LFieuALfCNZTnY019UuSFzQ1kev70P20Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1654316258; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=CLpDKm/Mr+ImE4VlqPmzYYKgYIlmztKlFv2bSQEVDKk=; b=PNBzM9hHbsP8GH365MB6U+FRyFZZlNQJg+ke8VBJni1L1SO1I04e7Qv0GCX6xvW1euXelV7N2jA/mCPEK9mTFLxPFsW6LXOCNpMQkei8F0CvsNKNxwjeSHEBQrklX7st2L9f2YpRFzTWInswsmVvF98Ye4i9uTuj9ZA8mx5tTZs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1654316258915592.2613105152013; Fri, 3 Jun 2022 21:17:38 -0700 (PDT) Received: from localhost ([::1]:39506 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nxLEH-0008Bm-Tz for importer@patchew.org; Sat, 04 Jun 2022 00:17:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36744) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nxL3O-0007mW-Ba for qemu-devel@nongnu.org; Sat, 04 Jun 2022 00:06:22 -0400 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]:39599) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nxL3M-00006R-14 for qemu-devel@nongnu.org; Sat, 04 Jun 2022 00:06:21 -0400 Received: by mail-pj1-x102e.google.com with SMTP id q12-20020a17090a304c00b001e2d4fb0eb4so13499671pjl.4 for ; Fri, 03 Jun 2022 21:06:19 -0700 (PDT) Received: from stoup.. ([2602:ae:1547:e101:3286:cc26:3d5e:3f94]) by smtp.gmail.com with ESMTPSA id a37-20020a631a65000000b003c14af50626sm6093779pgm.62.2022.06.03.21.06.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jun 2022 21:06:18 -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=CLpDKm/Mr+ImE4VlqPmzYYKgYIlmztKlFv2bSQEVDKk=; b=n0jdkkYIBnOFhx7edV9so0HoaCEvJftfX4BhQ4CpEkhnfHoWqX1nibIjS5r++tfOog UKv2eUYh23durCqFAzsWQZIpOM3BvpNj72YEJJBJVkS82eU/tHuBdqM/igTYFqPJoSFO fgGBVQI5tnlLDfBT9BMBxMcq64fgpJnUaYbSM8ISaefeKFM+B7+Bm7G8jnP6HSAVxzzl oN8BiKc8fVrhjGOoJuKrYVZXvn7WXMYKVIMo4JOADVtKaayix3bhKFzzb+Z5d+6VBDl0 DKR8sB/Loxdt6tvfT0G9Wn74Gjso64MEb/lGOCkQ1jDrzkBjkfR4AeFKdjsKCJL1J5Md /TTA== 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=CLpDKm/Mr+ImE4VlqPmzYYKgYIlmztKlFv2bSQEVDKk=; b=0p80f7Ue9Z5a7NQn8kRUy9+lT20ulVVVnevvcSWV+Z2Ie9uQPVTNXzLv0EFNvZ4oQp ruH35k3aKKqk1AqNQQyRQIe4YybIThTQ0bBeGY4oc0k1bXI5WVQe076w2nLTtrhH+dI9 PHBf/9PhSgwsXqvWESv83zYW8IohtjF9/XdtkCWEkGnipZpaCCtPqIlirnhvqf3ncyzq VamflB1O6qgG9e3Fa3QwyB+ptq2kIOmoSTeLdJPp6nFUzMxzvZCoEOdbobY1LHhloJJp jSV/o7p/S9XpY8JvgVLJsf1KAUDOkNrkF+Rp4mBj8V8837iyZo+0GRdBWK3MV1zgh+XY xEAQ== X-Gm-Message-State: AOAM5302q2KVKPFgP2x26CMOljw85cV0CgcE+chrj+KCTnwpJR/UwrFN 96Y34fU9KzIRyZ73PlAeXu8l0pGS5G6Dkw== X-Google-Smtp-Source: ABdhPJxp8MOoeG9HFM+FFPW60UmJIXO49yrAxzocsYpM5tj4K0anpqF+Z5sK8rSAxbHCZHFhRqMW4w== X-Received: by 2002:a17:902:7005:b0:163:ffe7:32eb with SMTP id y5-20020a170902700500b00163ffe732ebmr13257599plk.18.1654315578692; Fri, 03 Jun 2022 21:06:18 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Subject: [PATCH 10/28] target/arm: Move pmsav7_use_background_region to ptw.c Date: Fri, 3 Jun 2022 21:05:49 -0700 Message-Id: <20220604040607.269301-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220604040607.269301-1-richard.henderson@linaro.org> References: <20220604040607.269301-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=2607:f8b0:4864:20::102e; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102e.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=ham 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1654316259494100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Richard Henderson --- target/arm/ptw.h | 2 -- target/arm/helper.c | 19 ------------------- target/arm/ptw.c | 21 +++++++++++++++++++++ 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/target/arm/ptw.h b/target/arm/ptw.h index 8d2e239714..d2d2711908 100644 --- a/target/arm/ptw.h +++ b/target/arm/ptw.h @@ -36,8 +36,6 @@ simple_ap_to_rw_prot(CPUARMState *env, ARMMMUIdx mmu_idx,= int ap) bool m_is_ppb_region(CPUARMState *env, uint32_t address); bool m_is_system_region(CPUARMState *env, uint32_t address); =20 -bool pmsav7_use_background_region(ARMCPU *cpu, ARMMMUIdx mmu_idx, bool is_= user); - bool get_phys_addr_lpae(CPUARMState *env, uint64_t address, MMUAccessType access_type, ARMMMUIdx mmu_idx, bool s1_is_el0, diff --git a/target/arm/helper.c b/target/arm/helper.c index a8186ac138..a2a5dab969 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -11642,25 +11642,6 @@ do_fault: return true; } =20 -bool pmsav7_use_background_region(ARMCPU *cpu, ARMMMUIdx mmu_idx, bool is_= user) -{ - /* Return true if we should use the default memory map as a - * "background" region if there are no hits against any MPU regions. - */ - CPUARMState *env =3D &cpu->env; - - if (is_user) { - return false; - } - - if (arm_feature(env, ARM_FEATURE_M)) { - return env->v7m.mpu_ctrl[regime_is_secure(env, mmu_idx)] - & R_V7M_MPU_CTRL_PRIVDEFENA_MASK; - } else { - return regime_sctlr(env, mmu_idx) & SCTLR_BR; - } -} - bool m_is_ppb_region(CPUARMState *env, uint32_t address) { /* True if address is in the M profile PPB region 0xe0000000 - 0xe00ff= fff */ diff --git a/target/arm/ptw.c b/target/arm/ptw.c index 989e783cce..b82638b5a0 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -415,6 +415,27 @@ static void get_phys_addr_pmsav7_default(CPUARMState *= env, ARMMMUIdx mmu_idx, } } =20 +static bool pmsav7_use_background_region(ARMCPU *cpu, ARMMMUIdx mmu_idx, + bool is_user) +{ + /* + * Return true if we should use the default memory map as a + * "background" region if there are no hits against any MPU regions. + */ + CPUARMState *env =3D &cpu->env; + + if (is_user) { + return false; + } + + if (arm_feature(env, ARM_FEATURE_M)) { + return env->v7m.mpu_ctrl[regime_is_secure(env, mmu_idx)] + & R_V7M_MPU_CTRL_PRIVDEFENA_MASK; + } else { + return regime_sctlr(env, mmu_idx) & SCTLR_BR; + } +} + static bool get_phys_addr_pmsav7(CPUARMState *env, uint32_t address, MMUAccessType access_type, ARMMMUIdx mmu_= idx, hwaddr *phys_ptr, int *prot, --=20 2.34.1 From nobody Fri May 17 05:50:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1654316268; cv=none; d=zohomail.com; s=zohoarc; b=ELgPGShPwlyArcLkDdDrU+OkuieIKbE0703I1i2t3P3WnVItD/wHHTF4Q/XMTB9SHMLVcsQKGUU2g2GwNeLY0s+fdD52JOSRZhaE6F0r50bMOQGmBGuSAB815p1EJr/r4gLZ+inED6tNQWM9T2q+sJ6DidLQpzS7Qtorq3F8R04= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1654316268; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=F5967HU6ZDcdq/w7bIRWwPsJ0i/7AnNCaM6zuiPdJ7g=; b=WK/UWtYPgi7Ra4DugibAI3IXM1N8N/vDL9535g0WRP7KMUSabTzgWc7ZoBcwbJDFBSm2vi3KRS0sZQ81xt/uKXmq9G7FlzuciCTQlg10SwnWeP9I7QZ9TgqVKcl7mRX8AFWa4cVtWlSYQbauaU5TzU5j5z8/jsOyngzASTWCtkY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1654316268106537.8808294134852; Fri, 3 Jun 2022 21:17:48 -0700 (PDT) Received: from localhost ([::1]:40214 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nxLEQ-0000DK-I0 for importer@patchew.org; Sat, 04 Jun 2022 00:17:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36820) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nxL3P-0007ru-SO for qemu-devel@nongnu.org; Sat, 04 Jun 2022 00:06:23 -0400 Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]:53095) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nxL3M-00006t-UG for qemu-devel@nongnu.org; Sat, 04 Jun 2022 00:06:23 -0400 Received: by mail-pj1-x102b.google.com with SMTP id gd1so8715418pjb.2 for ; Fri, 03 Jun 2022 21:06:20 -0700 (PDT) Received: from stoup.. ([2602:ae:1547:e101:3286:cc26:3d5e:3f94]) by smtp.gmail.com with ESMTPSA id a37-20020a631a65000000b003c14af50626sm6093779pgm.62.2022.06.03.21.06.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jun 2022 21:06:19 -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=F5967HU6ZDcdq/w7bIRWwPsJ0i/7AnNCaM6zuiPdJ7g=; b=lJrBryHARAPRxHJyZF9HnUx1nq1aF87miciwks4OXd4fmYfdlzIuSu4prPknoLVO9S dlmbihyKM87MnJlpIJJe52n7EM9iv59ejxOsJuknPofVf8uvfpXKF/4rgx/JGYYcmMIA Cg3PMzMVQC9CF8zsGeMHcwGDU3V14LcslrqNW4Um+q03wUJZRPS6qCYJG3l5I86F/gW7 Yegkifv7PENWY23R2E7hXgV6XZH2k4SW48zLwaAeTih54GkcBTvrXfBQ+WIO5B7iM2tK u5rOIkpMvUKuAU2ruwwvWIA5EudI6xqa8Bjt1hTDW36NJcOvDFFsdKSeVC7Z+gDvDIFv eD0A== 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=F5967HU6ZDcdq/w7bIRWwPsJ0i/7AnNCaM6zuiPdJ7g=; b=7gKhJ/Ct2vzm8TNOUSqhYCtNG4Wv56XuCD1L54VQLrppiN6VtquDSJeOvHv6VBFV6A 0nZQS10QLXj3wPFxKCek79+nG59ViLseGBz+N37Bt/rv6+81Xq6dxu/af6q+t25ejGoF mWHVe0bXqygJqW3tMctRG+kNmAZ5nGRajbXbHvyfGjG6UbkiqvWgWOXQBMc4aEUVg7ky vmhregr4tbfXpCZPBQ/3ugLgrTOo8tpfEi2YmrkaZNKR4OECTDPIsUpOsDNIefFYOL6T kW8e0PUC/6OEL6FGPNFaKgWmWnohY2MMCvkmkbIsTznSTIx8zvrjvEg8fRRSqYM5Bdso j4xw== X-Gm-Message-State: AOAM5316hDsfErGAU9wqSA7s67Aj2XczVWZ+umKvvMA9L63aymVhPHuO HNNz6R8ZkqFfmY8wq9k/4sbIqEaOFmWSzQ== X-Google-Smtp-Source: ABdhPJwIB/T+I6CuD7vbIGgG2QGjWGjdedJXn9Hsf/yh+RDw3m0S9lkH/HafZI9F8DTPe2fQpLFF9g== X-Received: by 2002:a17:90a:de15:b0:1df:63dd:9cfc with SMTP id m21-20020a17090ade1500b001df63dd9cfcmr14317056pjv.200.1654315579607; Fri, 03 Jun 2022 21:06:19 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Subject: [PATCH 11/28] target/arm: Move v8m_security_lookup to ptw.c Date: Fri, 3 Jun 2022 21:05:50 -0700 Message-Id: <20220604040607.269301-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220604040607.269301-1-richard.henderson@linaro.org> References: <20220604040607.269301-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=2607:f8b0:4864:20::102b; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102b.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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1654316269394100001 Content-Type: text/plain; charset="utf-8" This function has one private helper, v8m_is_sau_exempt, so move that at the same time. Signed-off-by: Richard Henderson --- target/arm/helper.c | 123 ------------------------------------------ target/arm/ptw.c | 126 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 126 insertions(+), 123 deletions(-) diff --git a/target/arm/helper.c b/target/arm/helper.c index a2a5dab969..52655bbdf1 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -9,7 +9,6 @@ #include "qemu/osdep.h" #include "qemu/units.h" #include "qemu/log.h" -#include "target/arm/idau.h" #include "trace.h" #include "cpu.h" #include "internals.h" @@ -11657,128 +11656,6 @@ bool m_is_system_region(CPUARMState *env, uint32_= t address) return arm_feature(env, ARM_FEATURE_M) && extract32(address, 29, 3) = =3D=3D 0x7; } =20 -static bool v8m_is_sau_exempt(CPUARMState *env, - uint32_t address, MMUAccessType access_type) -{ - /* The architecture specifies that certain address ranges are - * exempt from v8M SAU/IDAU checks. - */ - return - (access_type =3D=3D MMU_INST_FETCH && m_is_system_region(env, addr= ess)) || - (address >=3D 0xe0000000 && address <=3D 0xe0002fff) || - (address >=3D 0xe000e000 && address <=3D 0xe000efff) || - (address >=3D 0xe002e000 && address <=3D 0xe002efff) || - (address >=3D 0xe0040000 && address <=3D 0xe0041fff) || - (address >=3D 0xe00ff000 && address <=3D 0xe00fffff); -} - -void v8m_security_lookup(CPUARMState *env, uint32_t address, - MMUAccessType access_type, ARMMMUIdx mmu_i= dx, - V8M_SAttributes *sattrs) -{ - /* Look up the security attributes for this address. Compare the - * pseudocode SecurityCheck() function. - * We assume the caller has zero-initialized *sattrs. - */ - ARMCPU *cpu =3D env_archcpu(env); - int r; - bool idau_exempt =3D false, idau_ns =3D true, idau_nsc =3D true; - int idau_region =3D IREGION_NOTVALID; - uint32_t addr_page_base =3D address & TARGET_PAGE_MASK; - uint32_t addr_page_limit =3D addr_page_base + (TARGET_PAGE_SIZE - 1); - - if (cpu->idau) { - IDAUInterfaceClass *iic =3D IDAU_INTERFACE_GET_CLASS(cpu->idau); - IDAUInterface *ii =3D IDAU_INTERFACE(cpu->idau); - - iic->check(ii, address, &idau_region, &idau_exempt, &idau_ns, - &idau_nsc); - } - - if (access_type =3D=3D MMU_INST_FETCH && extract32(address, 28, 4) =3D= =3D 0xf) { - /* 0xf0000000..0xffffffff is always S for insn fetches */ - return; - } - - if (idau_exempt || v8m_is_sau_exempt(env, address, access_type)) { - sattrs->ns =3D !regime_is_secure(env, mmu_idx); - return; - } - - if (idau_region !=3D IREGION_NOTVALID) { - sattrs->irvalid =3D true; - sattrs->iregion =3D idau_region; - } - - switch (env->sau.ctrl & 3) { - case 0: /* SAU.ENABLE =3D=3D 0, SAU.ALLNS =3D=3D 0 */ - break; - case 2: /* SAU.ENABLE =3D=3D 0, SAU.ALLNS =3D=3D 1 */ - sattrs->ns =3D true; - break; - default: /* SAU.ENABLE =3D=3D 1 */ - for (r =3D 0; r < cpu->sau_sregion; r++) { - if (env->sau.rlar[r] & 1) { - uint32_t base =3D env->sau.rbar[r] & ~0x1f; - uint32_t limit =3D env->sau.rlar[r] | 0x1f; - - if (base <=3D address && limit >=3D address) { - if (base > addr_page_base || limit < addr_page_limit) { - sattrs->subpage =3D true; - } - if (sattrs->srvalid) { - /* If we hit in more than one region then we must = report - * as Secure, not NS-Callable, with no valid region - * number info. - */ - sattrs->ns =3D false; - sattrs->nsc =3D false; - sattrs->sregion =3D 0; - sattrs->srvalid =3D false; - break; - } else { - if (env->sau.rlar[r] & 2) { - sattrs->nsc =3D true; - } else { - sattrs->ns =3D true; - } - sattrs->srvalid =3D true; - sattrs->sregion =3D r; - } - } else { - /* - * Address not in this region. We must check whether t= he - * region covers addresses in the same page as our add= ress. - * In that case we must not report a size that covers = the - * whole page for a subsequent hit against a different= MPU - * region or the background region, because it would r= esult - * in incorrect TLB hits for subsequent accesses to - * addresses that are in this MPU region. - */ - if (limit >=3D base && - ranges_overlap(base, limit - base + 1, - addr_page_base, - TARGET_PAGE_SIZE)) { - sattrs->subpage =3D true; - } - } - } - } - break; - } - - /* - * The IDAU will override the SAU lookup results if it specifies - * higher security than the SAU does. - */ - if (!idau_ns) { - if (sattrs->ns || (!idau_nsc && sattrs->nsc)) { - sattrs->ns =3D false; - sattrs->nsc =3D idau_nsc; - } - } -} - /* Combine either inner or outer cacheability attributes for normal * memory, according to table D4-42 and pseudocode procedure * CombineS1S2AttrHints() of ARM DDI 0487B.b (the ARMv8 ARM). diff --git a/target/arm/ptw.c b/target/arm/ptw.c index b82638b5a0..c15fba43c3 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -11,6 +11,7 @@ #include "qemu/range.h" #include "cpu.h" #include "internals.h" +#include "idau.h" #include "ptw.h" =20 =20 @@ -766,6 +767,131 @@ bool pmsav8_mpu_lookup(CPUARMState *env, uint32_t add= ress, return !(*prot & (1 << access_type)); } =20 +static bool v8m_is_sau_exempt(CPUARMState *env, + uint32_t address, MMUAccessType access_type) +{ + /* + * The architecture specifies that certain address ranges are + * exempt from v8M SAU/IDAU checks. + */ + return + (access_type =3D=3D MMU_INST_FETCH && m_is_system_region(env, addr= ess)) || + (address >=3D 0xe0000000 && address <=3D 0xe0002fff) || + (address >=3D 0xe000e000 && address <=3D 0xe000efff) || + (address >=3D 0xe002e000 && address <=3D 0xe002efff) || + (address >=3D 0xe0040000 && address <=3D 0xe0041fff) || + (address >=3D 0xe00ff000 && address <=3D 0xe00fffff); +} + +void v8m_security_lookup(CPUARMState *env, uint32_t address, + MMUAccessType access_type, ARMMMUIdx mmu_i= dx, + V8M_SAttributes *sattrs) +{ + /* + * Look up the security attributes for this address. Compare the + * pseudocode SecurityCheck() function. + * We assume the caller has zero-initialized *sattrs. + */ + ARMCPU *cpu =3D env_archcpu(env); + int r; + bool idau_exempt =3D false, idau_ns =3D true, idau_nsc =3D true; + int idau_region =3D IREGION_NOTVALID; + uint32_t addr_page_base =3D address & TARGET_PAGE_MASK; + uint32_t addr_page_limit =3D addr_page_base + (TARGET_PAGE_SIZE - 1); + + if (cpu->idau) { + IDAUInterfaceClass *iic =3D IDAU_INTERFACE_GET_CLASS(cpu->idau); + IDAUInterface *ii =3D IDAU_INTERFACE(cpu->idau); + + iic->check(ii, address, &idau_region, &idau_exempt, &idau_ns, + &idau_nsc); + } + + if (access_type =3D=3D MMU_INST_FETCH && extract32(address, 28, 4) =3D= =3D 0xf) { + /* 0xf0000000..0xffffffff is always S for insn fetches */ + return; + } + + if (idau_exempt || v8m_is_sau_exempt(env, address, access_type)) { + sattrs->ns =3D !regime_is_secure(env, mmu_idx); + return; + } + + if (idau_region !=3D IREGION_NOTVALID) { + sattrs->irvalid =3D true; + sattrs->iregion =3D idau_region; + } + + switch (env->sau.ctrl & 3) { + case 0: /* SAU.ENABLE =3D=3D 0, SAU.ALLNS =3D=3D 0 */ + break; + case 2: /* SAU.ENABLE =3D=3D 0, SAU.ALLNS =3D=3D 1 */ + sattrs->ns =3D true; + break; + default: /* SAU.ENABLE =3D=3D 1 */ + for (r =3D 0; r < cpu->sau_sregion; r++) { + if (env->sau.rlar[r] & 1) { + uint32_t base =3D env->sau.rbar[r] & ~0x1f; + uint32_t limit =3D env->sau.rlar[r] | 0x1f; + + if (base <=3D address && limit >=3D address) { + if (base > addr_page_base || limit < addr_page_limit) { + sattrs->subpage =3D true; + } + if (sattrs->srvalid) { + /* + * If we hit in more than one region then we must = report + * as Secure, not NS-Callable, with no valid region + * number info. + */ + sattrs->ns =3D false; + sattrs->nsc =3D false; + sattrs->sregion =3D 0; + sattrs->srvalid =3D false; + break; + } else { + if (env->sau.rlar[r] & 2) { + sattrs->nsc =3D true; + } else { + sattrs->ns =3D true; + } + sattrs->srvalid =3D true; + sattrs->sregion =3D r; + } + } else { + /* + * Address not in this region. We must check whether t= he + * region covers addresses in the same page as our add= ress. + * In that case we must not report a size that covers = the + * whole page for a subsequent hit against a different= MPU + * region or the background region, because it would r= esult + * in incorrect TLB hits for subsequent accesses to + * addresses that are in this MPU region. + */ + if (limit >=3D base && + ranges_overlap(base, limit - base + 1, + addr_page_base, + TARGET_PAGE_SIZE)) { + sattrs->subpage =3D true; + } + } + } + } + break; + } + + /* + * The IDAU will override the SAU lookup results if it specifies + * higher security than the SAU does. + */ + if (!idau_ns) { + if (sattrs->ns || (!idau_nsc && sattrs->nsc)) { + sattrs->ns =3D false; + sattrs->nsc =3D idau_nsc; + } + } +} + static bool get_phys_addr_pmsav8(CPUARMState *env, uint32_t address, MMUAccessType access_type, ARMMMUIdx mmu_= idx, hwaddr *phys_ptr, MemTxAttrs *txattrs, --=20 2.34.1 From nobody Fri May 17 05:50:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1654316519; cv=none; d=zohomail.com; s=zohoarc; b=ceCQbkQ+RwR5x8S2exmr6IhA0GbyqTYh4DKinavDjf88tWR4EB3comsRqA5ybnc4ehBnteBOg3/7EzH/ezS0c3P+gd7uhRqwKYZ+D0HNc1Mk0ZxSwyvy+BRql2mGi3/lvvRXyY9z1LRyvFOBsRgC9PE4iycq4vNSue41tSbpRaI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1654316519; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=e3tM2x5Geh/0C+lNtCDw6ji3/cajAOAo6f5xAef+ZfI=; b=Gg2P5qnsAg90MDCtw+2RWGaKKLr52JuI96aDYLiJ7gF2ThU/xqXtedgx+WUQoCvSi9vlgElWxC/94dJvZKa8AETSbVI5wnYb4KfPaNpP61AIbopKpdGWChx8QM2qWH38BNAu9I9Nhjka6JiZ/5vGg7yvn/E0pV0DrBSzIwog6gQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1654316519727157.00469699219036; Fri, 3 Jun 2022 21:21:59 -0700 (PDT) Received: from localhost ([::1]:48298 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nxLIT-0005m2-TJ for importer@patchew.org; Sat, 04 Jun 2022 00:21:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36810) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nxL3P-0007rL-Kx for qemu-devel@nongnu.org; Sat, 04 Jun 2022 00:06:23 -0400 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]:46639) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nxL3N-00007F-MO for qemu-devel@nongnu.org; Sat, 04 Jun 2022 00:06:23 -0400 Received: by mail-pl1-x62c.google.com with SMTP id w3so8084941plp.13 for ; Fri, 03 Jun 2022 21:06:21 -0700 (PDT) Received: from stoup.. ([2602:ae:1547:e101:3286:cc26:3d5e:3f94]) by smtp.gmail.com with ESMTPSA id a37-20020a631a65000000b003c14af50626sm6093779pgm.62.2022.06.03.21.06.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jun 2022 21:06:20 -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=e3tM2x5Geh/0C+lNtCDw6ji3/cajAOAo6f5xAef+ZfI=; b=pXy8v+mODdY6WcFaeuftszjQsCRkZfg+JbZHfB+GfwWhU6GaVE4yTRS4fCt06MwQYm /XPK54LIeLckdnQpVokmBuiJSiqZMv2ulSuPDy7el83Equ2vH1WVNw7qWwqaRZGwUduA HMfp+FT0tPALxDBxkowV1FvnsCnim3SJ3yFUw/vkAsMf+zWHBqozf00TWLX2rCBOzJCr drwPYYGaVEjAhjUfbfBBiukFVsNVfzJMAzLZgcaYkMFVyoIi7r4iHYRYf3eJSLGyi54i lFqzt8UkKgwqiphI9uD91sLYgOeCDqWsMRpWjN/LYvMHxqAt++gPnaDgombqMQe44kOU kNNw== 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=e3tM2x5Geh/0C+lNtCDw6ji3/cajAOAo6f5xAef+ZfI=; b=I6DvQRQ+YABycOoY7YNyueehjRsM6ZYg+KvOGYEW+02D9VGyyaJZlPwZZrdXD0JMal qElkixsGVBsFpp3CRVeqK5Mc/aZZcL/ARswFm0z3GQOXBhrSTc71Se7ksNBJdp7L83JV MfchFEcai6mlGWfcd5ONVhUv30AigmhAYwgMACPbRN5tXPDSc6/4rQuhNy8JSrUyAgkJ WfjNyEFblZRvqk49YvQ5IlhJ9v1LU6QWVUckunlwOwwRsb41kL8TpPXwKAHBZb+Zg1vH OlG92Pdl9MshX/zYtuWk0SImyUTlf8FFUD53wljVytTEhXmPDMNu7F35d7N1ctCpoVlL IRUw== X-Gm-Message-State: AOAM530lU8bFkD+y0rxG2bM3udNh2tXBQ7U73utcWo0zdVk1+5pLXBmV vXCQoEGNqLPCtBFS3ZdcIDn/tuP6ywJUvA== X-Google-Smtp-Source: ABdhPJyL39PsM7X4cg/W8j12D7ktceivenfTf8YUpmEk0dLCufh8GEkXiJhRxgdQfgzctEGDB5Y3dg== X-Received: by 2002:a17:902:b703:b0:158:2667:7447 with SMTP id d3-20020a170902b70300b0015826677447mr12871233pls.92.1654315580425; Fri, 03 Jun 2022 21:06:20 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Subject: [PATCH 12/28] target/arm: Move m_is_{ppb,system}_region to ptw.c Date: Fri, 3 Jun 2022 21:05:51 -0700 Message-Id: <20220604040607.269301-13-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220604040607.269301-1-richard.henderson@linaro.org> References: <20220604040607.269301-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=2607:f8b0:4864:20::62c; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62c.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=ham 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1654316519903100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Richard Henderson --- target/arm/ptw.h | 3 --- target/arm/helper.c | 15 --------------- target/arm/ptw.c | 16 ++++++++++++++++ 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/target/arm/ptw.h b/target/arm/ptw.h index d2d2711908..6c47a57599 100644 --- a/target/arm/ptw.h +++ b/target/arm/ptw.h @@ -33,9 +33,6 @@ simple_ap_to_rw_prot(CPUARMState *env, ARMMMUIdx mmu_idx,= int ap) return simple_ap_to_rw_prot_is_user(ap, regime_is_user(env, mmu_idx)); } =20 -bool m_is_ppb_region(CPUARMState *env, uint32_t address); -bool m_is_system_region(CPUARMState *env, uint32_t address); - bool get_phys_addr_lpae(CPUARMState *env, uint64_t address, MMUAccessType access_type, ARMMMUIdx mmu_idx, bool s1_is_el0, diff --git a/target/arm/helper.c b/target/arm/helper.c index 52655bbdf1..937971730c 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -11641,21 +11641,6 @@ do_fault: return true; } =20 -bool m_is_ppb_region(CPUARMState *env, uint32_t address) -{ - /* True if address is in the M profile PPB region 0xe0000000 - 0xe00ff= fff */ - return arm_feature(env, ARM_FEATURE_M) && - extract32(address, 20, 12) =3D=3D 0xe00; -} - -bool m_is_system_region(CPUARMState *env, uint32_t address) -{ - /* True if address is in the M profile system region - * 0xe0000000 - 0xffffffff - */ - return arm_feature(env, ARM_FEATURE_M) && extract32(address, 29, 3) = =3D=3D 0x7; -} - /* Combine either inner or outer cacheability attributes for normal * memory, according to table D4-42 and pseudocode procedure * CombineS1S2AttrHints() of ARM DDI 0487B.b (the ARMv8 ARM). diff --git a/target/arm/ptw.c b/target/arm/ptw.c index c15fba43c3..32ba2e5e8b 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -416,6 +416,22 @@ static void get_phys_addr_pmsav7_default(CPUARMState *= env, ARMMMUIdx mmu_idx, } } =20 +static bool m_is_ppb_region(CPUARMState *env, uint32_t address) +{ + /* True if address is in the M profile PPB region 0xe0000000 - 0xe00ff= fff */ + return arm_feature(env, ARM_FEATURE_M) && + extract32(address, 20, 12) =3D=3D 0xe00; +} + +static bool m_is_system_region(CPUARMState *env, uint32_t address) +{ + /* + * True if address is in the M profile system region + * 0xe0000000 - 0xffffffff + */ + return arm_feature(env, ARM_FEATURE_M) && extract32(address, 29, 3) = =3D=3D 0x7; +} + static bool pmsav7_use_background_region(ARMCPU *cpu, ARMMMUIdx mmu_idx, bool is_user) { --=20 2.34.1 From nobody Fri May 17 05:50:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1654316513; cv=none; d=zohomail.com; s=zohoarc; b=OwIkg/SioaX2PN+hVrcNvnMrL9dKuzsVyDedZOFrZ3DU3Oom+y2ikY6Qs4nTsW6JvSVqb3vB+7SQzt1p+WUn2J0bT4s836TLzrJ8ljaOLVvUHdh3mKI03Q7tMyb3eLwrgH9mFASi3nVqSPi+1WyAF+sIE+W24Nf7RVBh+MkAgZM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1654316513; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=yFIaCaxXJf8mp665jzJyOMjbEY0cC7z6g35E7VMLSz0=; b=HE8Evl0PAaYSovsv/OhF50wyRXE7AhRBa6fSX1+c57PTNAoDXYk+z0lL5dgigyGiq3b7RUzLVpR5TFYo4gVa1rqrImrMBWZM88+5GX1BPyMGFpnrSnnU8btQpPFDa2wGDTFfdPRxsywKXyy618z7BeneBxqoZT3fhZEGDZHvPT8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1654316513572517.8750450355934; Fri, 3 Jun 2022 21:21:53 -0700 (PDT) Received: from localhost ([::1]:48128 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nxLIO-0005fC-6U for importer@patchew.org; Sat, 04 Jun 2022 00:21:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36824) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nxL3Q-0007ug-Fg for qemu-devel@nongnu.org; Sat, 04 Jun 2022 00:06:24 -0400 Received: from mail-pg1-x52c.google.com ([2607:f8b0:4864:20::52c]:42617) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nxL3O-00007Z-ME for qemu-devel@nongnu.org; Sat, 04 Jun 2022 00:06:24 -0400 Received: by mail-pg1-x52c.google.com with SMTP id d129so8635287pgc.9 for ; Fri, 03 Jun 2022 21:06:22 -0700 (PDT) Received: from stoup.. ([2602:ae:1547:e101:3286:cc26:3d5e:3f94]) by smtp.gmail.com with ESMTPSA id a37-20020a631a65000000b003c14af50626sm6093779pgm.62.2022.06.03.21.06.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jun 2022 21:06:20 -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=yFIaCaxXJf8mp665jzJyOMjbEY0cC7z6g35E7VMLSz0=; b=XeYvK6wUz5IM9HZS1fDpgg0uPKNX/Oq4NoOYkuscT1mjn/CaevBl3gHHB6tSL0Ugg9 nEMOUYMg5ni6SaGvFTSO3pdGHsS7nyG5nZCKqmf7/54Raz8dfzbGf7YRGwUPQuDqxA8a +dqr45kIY8DFJLhZWl2a0DW1aAw7AvHG9lregVwoaDPeCtuy44pdBu1etW2kpGD80Xsl Y+sYOiw322G3VVRofzEE+YxwGnTu7wJOQRoC1ViBXTr+gRfhTd15CrGYU2K0oHG0kYIl IE8omKj07tQBNI9AaGW70lzfRbhED5kFw+PaYhkMIoN+q6Ed+mdqvhNeou2H9im8+udl f2dQ== 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=yFIaCaxXJf8mp665jzJyOMjbEY0cC7z6g35E7VMLSz0=; b=AhSinZQEarYnXJMv3F4xGfI8fNBQeIcw/ykOPvLU/v/olXQIK2tdF5APU2zXicbFTL 4MoNXNNFSiBDSJ/Pl3pvC8a02WOkX7fC9Jq0hptY3PK8CXA6WvSBVCdukpti8rl4gUod y/cxtu3bjlMsjNof64ZmygsyAQCn5bggKyXBxPvDJy+PaEJEfSSu3dvoN9MRrHMevXLI bqceT3+YrzlEqgt7JCvzvkjx5KnyNdWuX4NdEbKAwKD9GR6AooAIsbPFDuaK6NR9bZXv Dw6b/VUY+zT9DFvJz6ScZW0B5iHgo6iv67UVdyYAPsIjWtS4viLNBmbLlB872/jVXL3O CbdA== X-Gm-Message-State: AOAM531xKs2tNYjyDY12s63Uspu3fEWvIcCmyP5Dvl0EbmgcV7Ilw+W0 5kMiVxoRQ1GQVLT3EuJmAlrbwEoX57YdAQ== X-Google-Smtp-Source: ABdhPJyxucJyVJIC1BYi5xw7YbVgblAqJoqodBnpZ6qR0iYzc4xsA7DYoi7LgSzYz/HJQniS7GiLGA== X-Received: by 2002:a63:6bc7:0:b0:3fd:1b8d:d114 with SMTP id g190-20020a636bc7000000b003fd1b8dd114mr6163703pgc.308.1654315581244; Fri, 03 Jun 2022 21:06:21 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Subject: [PATCH 13/28] target/arm: Move get_level1_table_address to ptw.c Date: Fri, 3 Jun 2022 21:05:52 -0700 Message-Id: <20220604040607.269301-14-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220604040607.269301-1-richard.henderson@linaro.org> References: <20220604040607.269301-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=2607:f8b0:4864:20::52c; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52c.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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1654316514014100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Richard Henderson --- target/arm/ptw.h | 4 ++-- target/arm/helper.c | 26 +------------------------- target/arm/ptw.c | 23 +++++++++++++++++++++++ 3 files changed, 26 insertions(+), 27 deletions(-) diff --git a/target/arm/ptw.h b/target/arm/ptw.h index 6c47a57599..dd6fb93f33 100644 --- a/target/arm/ptw.h +++ b/target/arm/ptw.h @@ -18,11 +18,11 @@ uint64_t arm_ldq_ptw(CPUState *cs, hwaddr addr, bool is= _secure, =20 bool regime_is_user(CPUARMState *env, ARMMMUIdx mmu_idx); bool regime_translation_disabled(CPUARMState *env, ARMMMUIdx mmu_idx); +uint64_t regime_ttbr(CPUARMState *env, ARMMMUIdx mmu_idx, int ttbrn); + ARMCacheAttrs combine_cacheattrs(CPUARMState *env, ARMCacheAttrs s1, ARMCacheAttrs s2); =20 -bool get_level1_table_address(CPUARMState *env, ARMMMUIdx mmu_idx, - uint32_t *table, uint32_t address); int ap_to_rw_prot(CPUARMState *env, ARMMMUIdx mmu_idx, int ap, int domain_prot); int simple_ap_to_rw_prot_is_user(int ap, bool is_user); diff --git a/target/arm/helper.c b/target/arm/helper.c index 937971730c..50c4576544 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -10446,8 +10446,7 @@ static inline bool regime_translation_big_endian(CP= UARMState *env, } =20 /* Return the TTBR associated with this translation regime */ -static inline uint64_t regime_ttbr(CPUARMState *env, ARMMMUIdx mmu_idx, - int ttbrn) +uint64_t regime_ttbr(CPUARMState *env, ARMMMUIdx mmu_idx, int ttbrn) { if (mmu_idx =3D=3D ARMMMUIdx_Stage2) { return env->cp15.vttbr_el2; @@ -10738,29 +10737,6 @@ static int get_S1prot(CPUARMState *env, ARMMMUIdx = mmu_idx, bool is_aa64, return prot_rw | PAGE_EXEC; } =20 -bool get_level1_table_address(CPUARMState *env, ARMMMUIdx mmu_idx, - uint32_t *table, uint32_t address) -{ - /* Note that we can only get here for an AArch32 PL0/PL1 lookup */ - TCR *tcr =3D regime_tcr(env, mmu_idx); - - if (address & tcr->mask) { - if (tcr->raw_tcr & TTBCR_PD1) { - /* Translation table walk disabled for TTBR1 */ - return false; - } - *table =3D regime_ttbr(env, mmu_idx, 1) & 0xffffc000; - } else { - if (tcr->raw_tcr & TTBCR_PD0) { - /* Translation table walk disabled for TTBR0 */ - return false; - } - *table =3D regime_ttbr(env, mmu_idx, 0) & tcr->base_mask; - } - *table |=3D (address >> 18) & 0x3ffc; - return true; -} - static bool ptw_attrs_are_device(CPUARMState *env, ARMCacheAttrs cacheattr= s) { /* diff --git a/target/arm/ptw.c b/target/arm/ptw.c index 32ba2e5e8b..5737a3976b 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -15,6 +15,29 @@ #include "ptw.h" =20 =20 +static bool get_level1_table_address(CPUARMState *env, ARMMMUIdx mmu_idx, + uint32_t *table, uint32_t address) +{ + /* Note that we can only get here for an AArch32 PL0/PL1 lookup */ + TCR *tcr =3D regime_tcr(env, mmu_idx); + + if (address & tcr->mask) { + if (tcr->raw_tcr & TTBCR_PD1) { + /* Translation table walk disabled for TTBR1 */ + return false; + } + *table =3D regime_ttbr(env, mmu_idx, 1) & 0xffffc000; + } else { + if (tcr->raw_tcr & TTBCR_PD0) { + /* Translation table walk disabled for TTBR0 */ + return false; + } + *table =3D regime_ttbr(env, mmu_idx, 0) & tcr->base_mask; + } + *table |=3D (address >> 18) & 0x3ffc; + return true; +} + static bool get_phys_addr_v5(CPUARMState *env, uint32_t address, MMUAccessType access_type, ARMMMUIdx mmu_idx, hwaddr *phys_ptr, int *prot, --=20 2.34.1 From nobody Fri May 17 05:50:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1654316039; cv=none; d=zohomail.com; s=zohoarc; b=IrJjXHCD0Bs0y/+RG1pNhbZ0hJisZlSlxvf7IFG1pFEpm89cC8WpwlsYGCRmmnvU7+L0xa1Iy8VKaCQEDzbbLerw/sd3b0R2bQ4Vy9MPliH/B67Nr3cxR57Q5EQw/zTtgnspBDRwN1ZRIsvXk3NxtTl2PVT7jj5DI8Z6AF6zoPA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1654316039; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=42KGxt0e56Jwm+KUmBLbaDfA0/L/Jc+cpx0rRd0m44o=; b=itYMdmsJTfaQgVCRVoC2UNt3KIX+cuF5ZQaf6jj1ldkeGjOj3xAPJvF0gZNpe1dEh0VBoQmto7DQYZRSS5rzVOqmdHM+ABQoMYZBKgTc4EeHbyLS4uOMEWhhgb4ZmwNmYN0unibPOjVs4embsevFm+A0MKQzIY0zYr1tshLc+zU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1654316039397643.3536305745134; Fri, 3 Jun 2022 21:13:59 -0700 (PDT) Received: from localhost ([::1]:57024 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nxLAk-00010Q-4u for importer@patchew.org; Sat, 04 Jun 2022 00:13:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36866) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nxL3R-0007yo-PX for qemu-devel@nongnu.org; Sat, 04 Jun 2022 00:06:25 -0400 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]:35385) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nxL3P-0008WU-90 for qemu-devel@nongnu.org; Sat, 04 Jun 2022 00:06:25 -0400 Received: by mail-pj1-x102d.google.com with SMTP id o6-20020a17090a0a0600b001e2c6566046so13546760pjo.0 for ; Fri, 03 Jun 2022 21:06:22 -0700 (PDT) Received: from stoup.. ([2602:ae:1547:e101:3286:cc26:3d5e:3f94]) by smtp.gmail.com with ESMTPSA id a37-20020a631a65000000b003c14af50626sm6093779pgm.62.2022.06.03.21.06.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jun 2022 21:06:21 -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=42KGxt0e56Jwm+KUmBLbaDfA0/L/Jc+cpx0rRd0m44o=; b=pF430RL+9nQpj2tKPEVdsIKPrydD+nqhc3PCG+g2+NTaLIPR/v0jncywE6ZbIvgOKK 94s+O14pFelCw2sctaHCtPL0NNUPWSrX/ecr/qND4wkbWWkTs9I0FmNG00DhXPd793Ca YgC748Mj0FzN7u6Bt0PJO9MqHt22XlfxGSa8IlhBr3lS1YVF3Ley/9iwJzDezvdbGORM OgtS0dDgSRz1DBcZw3Pnwo/4Q+jAzGSCDtN0UC2/l57jWMTnplF83VIyH/DFHUGoa/13 weWehzLl8VCSluD8bgKCQwD2I2vP125ZOSoAj9DGk3Ygo1dmYDFAM91rhopvJJlHEIM8 iEeQ== 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=42KGxt0e56Jwm+KUmBLbaDfA0/L/Jc+cpx0rRd0m44o=; b=slOe/7o3t9youzcrKzrUqgEi8TXQLYDuBSGmMivQdJdbXpjAjqA7ziHL3XDVYK1jah xNd0M7owPQ8suMZ4DblUYBOnNbzdThVcNYrR35w0zCcyk5FBVHsdBqCOf/KdAZU1He/N 82Y78awMp44prE0jdtRNUjCR5wS0i80NuPPvpQYyFn4GEPSdGcX43nSM7D21ypr2o45L f39KyYZrk0MgUZrJa3jL/WgNRIllri0WCnq4n19U3c7P61HS/M3j8M+vZWZ9ihMr1/Ei 5zLo5e8ELUDVM2eBtw5eztux7eBsOldaXF1Ir0X+vu6KvNyQj8/UgwWHEszGnd9FzOVK QKgg== X-Gm-Message-State: AOAM531dVBuU9mmfJ5SSjY0Rn/UwKSK1cUj2NEGMqycRN8sPcEczY8zP xct3YUqjIz8T7yqOf8gNmWJd6QnAz5hWqw== X-Google-Smtp-Source: ABdhPJwKHYfBfgozm5OJH1dyX1HhDgz6IsKtQ5+Saqge25wDapS2rRJbIdVWdAcBfr2IJYWB8wOjcw== X-Received: by 2002:a17:903:40c9:b0:167:5411:3536 with SMTP id t9-20020a17090340c900b0016754113536mr3991241pld.2.1654315582313; Fri, 03 Jun 2022 21:06:22 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Subject: [PATCH 14/28] target/arm: Move combine_cacheattrs and subroutines to ptw.c Date: Fri, 3 Jun 2022 21:05:53 -0700 Message-Id: <20220604040607.269301-15-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220604040607.269301-1-richard.henderson@linaro.org> References: <20220604040607.269301-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=2607:f8b0:4864:20::102d; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102d.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=ham 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1654316040201100001 Content-Type: text/plain; charset="utf-8" There are a handful of helpers for combine_cacheattrs that we can move at the same time as the main entry point. Signed-off-by: Richard Henderson --- target/arm/ptw.h | 3 - target/arm/helper.c | 218 ------------------------------------------- target/arm/ptw.c | 221 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 221 insertions(+), 221 deletions(-) diff --git a/target/arm/ptw.h b/target/arm/ptw.h index dd6fb93f33..b2dfe489bb 100644 --- a/target/arm/ptw.h +++ b/target/arm/ptw.h @@ -20,9 +20,6 @@ bool regime_is_user(CPUARMState *env, ARMMMUIdx mmu_idx); bool regime_translation_disabled(CPUARMState *env, ARMMMUIdx mmu_idx); uint64_t regime_ttbr(CPUARMState *env, ARMMMUIdx mmu_idx, int ttbrn); =20 -ARMCacheAttrs combine_cacheattrs(CPUARMState *env, - ARMCacheAttrs s1, ARMCacheAttrs s2); - int ap_to_rw_prot(CPUARMState *env, ARMMMUIdx mmu_idx, int ap, int domain_prot); int simple_ap_to_rw_prot_is_user(int ap, bool is_user); diff --git a/target/arm/helper.c b/target/arm/helper.c index 50c4576544..83aba35cfd 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -10941,36 +10941,6 @@ static bool check_s2_mmu_setup(ARMCPU *cpu, bool i= s_aa64, int level, } return true; } - -/* Translate from the 4-bit stage 2 representation of - * memory attributes (without cache-allocation hints) to - * the 8-bit representation of the stage 1 MAIR registers - * (which includes allocation hints). - * - * ref: shared/translation/attrs/S2AttrDecode() - * .../S2ConvertAttrsHints() - */ -static uint8_t convert_stage2_attrs(CPUARMState *env, uint8_t s2attrs) -{ - uint8_t hiattr =3D extract32(s2attrs, 2, 2); - uint8_t loattr =3D extract32(s2attrs, 0, 2); - uint8_t hihint =3D 0, lohint =3D 0; - - if (hiattr !=3D 0) { /* normal memory */ - if (arm_hcr_el2_eff(env) & HCR_CD) { /* cache disabled */ - hiattr =3D loattr =3D 1; /* non-cacheable */ - } else { - if (hiattr !=3D 1) { /* Write-through or write-back */ - hihint =3D 3; /* RW allocate */ - } - if (loattr !=3D 1) { /* Write-through or write-back */ - lohint =3D 3; /* RW allocate */ - } - } - } - - return (hiattr << 6) | (hihint << 4) | (loattr << 2) | lohint; -} #endif /* !CONFIG_USER_ONLY */ =20 /* This mapping is common between ID_AA64MMFR0.PARANGE and TCR_ELx.{I}PS. = */ @@ -11617,194 +11587,6 @@ do_fault: return true; } =20 -/* Combine either inner or outer cacheability attributes for normal - * memory, according to table D4-42 and pseudocode procedure - * CombineS1S2AttrHints() of ARM DDI 0487B.b (the ARMv8 ARM). - * - * NB: only stage 1 includes allocation hints (RW bits), leading to - * some asymmetry. - */ -static uint8_t combine_cacheattr_nibble(uint8_t s1, uint8_t s2) -{ - if (s1 =3D=3D 4 || s2 =3D=3D 4) { - /* non-cacheable has precedence */ - return 4; - } else if (extract32(s1, 2, 2) =3D=3D 0 || extract32(s1, 2, 2) =3D=3D = 2) { - /* stage 1 write-through takes precedence */ - return s1; - } else if (extract32(s2, 2, 2) =3D=3D 2) { - /* stage 2 write-through takes precedence, but the allocation hint - * is still taken from stage 1 - */ - return (2 << 2) | extract32(s1, 0, 2); - } else { /* write-back */ - return s1; - } -} - -/* - * Combine the memory type and cacheability attributes of - * s1 and s2 for the HCR_EL2.FWB =3D=3D 0 case, returning the - * combined attributes in MAIR_EL1 format. - */ -static uint8_t combined_attrs_nofwb(CPUARMState *env, - ARMCacheAttrs s1, ARMCacheAttrs s2) -{ - uint8_t s1lo, s2lo, s1hi, s2hi, s2_mair_attrs, ret_attrs; - - s2_mair_attrs =3D convert_stage2_attrs(env, s2.attrs); - - s1lo =3D extract32(s1.attrs, 0, 4); - s2lo =3D extract32(s2_mair_attrs, 0, 4); - s1hi =3D extract32(s1.attrs, 4, 4); - s2hi =3D extract32(s2_mair_attrs, 4, 4); - - /* Combine memory type and cacheability attributes */ - if (s1hi =3D=3D 0 || s2hi =3D=3D 0) { - /* Device has precedence over normal */ - if (s1lo =3D=3D 0 || s2lo =3D=3D 0) { - /* nGnRnE has precedence over anything */ - ret_attrs =3D 0; - } else if (s1lo =3D=3D 4 || s2lo =3D=3D 4) { - /* non-Reordering has precedence over Reordering */ - ret_attrs =3D 4; /* nGnRE */ - } else if (s1lo =3D=3D 8 || s2lo =3D=3D 8) { - /* non-Gathering has precedence over Gathering */ - ret_attrs =3D 8; /* nGRE */ - } else { - ret_attrs =3D 0xc; /* GRE */ - } - } else { /* Normal memory */ - /* Outer/inner cacheability combine independently */ - ret_attrs =3D combine_cacheattr_nibble(s1hi, s2hi) << 4 - | combine_cacheattr_nibble(s1lo, s2lo); - } - return ret_attrs; -} - -static uint8_t force_cacheattr_nibble_wb(uint8_t attr) -{ - /* - * Given the 4 bits specifying the outer or inner cacheability - * in MAIR format, return a value specifying Normal Write-Back, - * with the allocation and transient hints taken from the input - * if the input specified some kind of cacheable attribute. - */ - if (attr =3D=3D 0 || attr =3D=3D 4) { - /* - * 0 =3D=3D an UNPREDICTABLE encoding - * 4 =3D=3D Non-cacheable - * Either way, force Write-Back RW allocate non-transient - */ - return 0xf; - } - /* Change WriteThrough to WriteBack, keep allocation and transient hin= ts */ - return attr | 4; -} - -/* - * Combine the memory type and cacheability attributes of - * s1 and s2 for the HCR_EL2.FWB =3D=3D 1 case, returning the - * combined attributes in MAIR_EL1 format. - */ -static uint8_t combined_attrs_fwb(CPUARMState *env, - ARMCacheAttrs s1, ARMCacheAttrs s2) -{ - switch (s2.attrs) { - case 7: - /* Use stage 1 attributes */ - return s1.attrs; - case 6: - /* - * Force Normal Write-Back. Note that if S1 is Normal cacheable - * then we take the allocation hints from it; otherwise it is - * RW allocate, non-transient. - */ - if ((s1.attrs & 0xf0) =3D=3D 0) { - /* S1 is Device */ - return 0xff; - } - /* Need to check the Inner and Outer nibbles separately */ - return force_cacheattr_nibble_wb(s1.attrs & 0xf) | - force_cacheattr_nibble_wb(s1.attrs >> 4) << 4; - case 5: - /* If S1 attrs are Device, use them; otherwise Normal Non-cacheabl= e */ - if ((s1.attrs & 0xf0) =3D=3D 0) { - return s1.attrs; - } - return 0x44; - case 0 ... 3: - /* Force Device, of subtype specified by S2 */ - return s2.attrs << 2; - default: - /* - * RESERVED values (including RES0 descriptor bit [5] being nonzer= o); - * arbitrarily force Device. - */ - return 0; - } -} - -/* Combine S1 and S2 cacheability/shareability attributes, per D4.5.4 - * and CombineS1S2Desc() - * - * @env: CPUARMState - * @s1: Attributes from stage 1 walk - * @s2: Attributes from stage 2 walk - */ -ARMCacheAttrs combine_cacheattrs(CPUARMState *env, - ARMCacheAttrs s1, ARMCacheAttrs s2) -{ - ARMCacheAttrs ret; - bool tagged =3D false; - - assert(s2.is_s2_format && !s1.is_s2_format); - ret.is_s2_format =3D false; - - if (s1.attrs =3D=3D 0xf0) { - tagged =3D true; - s1.attrs =3D 0xff; - } - - /* Combine shareability attributes (table D4-43) */ - if (s1.shareability =3D=3D 2 || s2.shareability =3D=3D 2) { - /* if either are outer-shareable, the result is outer-shareable */ - ret.shareability =3D 2; - } else if (s1.shareability =3D=3D 3 || s2.shareability =3D=3D 3) { - /* if either are inner-shareable, the result is inner-shareable */ - ret.shareability =3D 3; - } else { - /* both non-shareable */ - ret.shareability =3D 0; - } - - /* Combine memory type and cacheability attributes */ - if (arm_hcr_el2_eff(env) & HCR_FWB) { - ret.attrs =3D combined_attrs_fwb(env, s1, s2); - } else { - ret.attrs =3D combined_attrs_nofwb(env, s1, s2); - } - - /* - * Any location for which the resultant memory type is any - * type of Device memory is always treated as Outer Shareable. - * Any location for which the resultant memory type is Normal - * Inner Non-cacheable, Outer Non-cacheable is always treated - * as Outer Shareable. - * TODO: FEAT_XS adds another value (0x40) also meaning iNCoNC - */ - if ((ret.attrs & 0xf0) =3D=3D 0 || ret.attrs =3D=3D 0x44) { - ret.shareability =3D 2; - } - - /* TODO: CombineS1S2Desc does not consider transient, only WB, RWA. */ - if (tagged && ret.attrs =3D=3D 0xff) { - ret.attrs =3D 0xf0; - } - - return ret; -} - hwaddr arm_cpu_get_phys_page_attrs_debug(CPUState *cs, vaddr addr, MemTxAttrs *attrs) { diff --git a/target/arm/ptw.c b/target/arm/ptw.c index 5737a3976b..f2ca2bb8fe 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -1008,6 +1008,227 @@ static bool get_phys_addr_pmsav8(CPUARMState *env, = uint32_t address, return ret; } =20 +/* + * Translate from the 4-bit stage 2 representation of + * memory attributes (without cache-allocation hints) to + * the 8-bit representation of the stage 1 MAIR registers + * (which includes allocation hints). + * + * ref: shared/translation/attrs/S2AttrDecode() + * .../S2ConvertAttrsHints() + */ +static uint8_t convert_stage2_attrs(CPUARMState *env, uint8_t s2attrs) +{ + uint8_t hiattr =3D extract32(s2attrs, 2, 2); + uint8_t loattr =3D extract32(s2attrs, 0, 2); + uint8_t hihint =3D 0, lohint =3D 0; + + if (hiattr !=3D 0) { /* normal memory */ + if (arm_hcr_el2_eff(env) & HCR_CD) { /* cache disabled */ + hiattr =3D loattr =3D 1; /* non-cacheable */ + } else { + if (hiattr !=3D 1) { /* Write-through or write-back */ + hihint =3D 3; /* RW allocate */ + } + if (loattr !=3D 1) { /* Write-through or write-back */ + lohint =3D 3; /* RW allocate */ + } + } + } + + return (hiattr << 6) | (hihint << 4) | (loattr << 2) | lohint; +} + +/* + * Combine either inner or outer cacheability attributes for normal + * memory, according to table D4-42 and pseudocode procedure + * CombineS1S2AttrHints() of ARM DDI 0487B.b (the ARMv8 ARM). + * + * NB: only stage 1 includes allocation hints (RW bits), leading to + * some asymmetry. + */ +static uint8_t combine_cacheattr_nibble(uint8_t s1, uint8_t s2) +{ + if (s1 =3D=3D 4 || s2 =3D=3D 4) { + /* non-cacheable has precedence */ + return 4; + } else if (extract32(s1, 2, 2) =3D=3D 0 || extract32(s1, 2, 2) =3D=3D = 2) { + /* stage 1 write-through takes precedence */ + return s1; + } else if (extract32(s2, 2, 2) =3D=3D 2) { + /* stage 2 write-through takes precedence, but the allocation hint + * is still taken from stage 1 + */ + return (2 << 2) | extract32(s1, 0, 2); + } else { /* write-back */ + return s1; + } +} + +/* + * Combine the memory type and cacheability attributes of + * s1 and s2 for the HCR_EL2.FWB =3D=3D 0 case, returning the + * combined attributes in MAIR_EL1 format. + */ +static uint8_t combined_attrs_nofwb(CPUARMState *env, + ARMCacheAttrs s1, ARMCacheAttrs s2) +{ + uint8_t s1lo, s2lo, s1hi, s2hi, s2_mair_attrs, ret_attrs; + + s2_mair_attrs =3D convert_stage2_attrs(env, s2.attrs); + + s1lo =3D extract32(s1.attrs, 0, 4); + s2lo =3D extract32(s2_mair_attrs, 0, 4); + s1hi =3D extract32(s1.attrs, 4, 4); + s2hi =3D extract32(s2_mair_attrs, 4, 4); + + /* Combine memory type and cacheability attributes */ + if (s1hi =3D=3D 0 || s2hi =3D=3D 0) { + /* Device has precedence over normal */ + if (s1lo =3D=3D 0 || s2lo =3D=3D 0) { + /* nGnRnE has precedence over anything */ + ret_attrs =3D 0; + } else if (s1lo =3D=3D 4 || s2lo =3D=3D 4) { + /* non-Reordering has precedence over Reordering */ + ret_attrs =3D 4; /* nGnRE */ + } else if (s1lo =3D=3D 8 || s2lo =3D=3D 8) { + /* non-Gathering has precedence over Gathering */ + ret_attrs =3D 8; /* nGRE */ + } else { + ret_attrs =3D 0xc; /* GRE */ + } + } else { /* Normal memory */ + /* Outer/inner cacheability combine independently */ + ret_attrs =3D combine_cacheattr_nibble(s1hi, s2hi) << 4 + | combine_cacheattr_nibble(s1lo, s2lo); + } + return ret_attrs; +} + +static uint8_t force_cacheattr_nibble_wb(uint8_t attr) +{ + /* + * Given the 4 bits specifying the outer or inner cacheability + * in MAIR format, return a value specifying Normal Write-Back, + * with the allocation and transient hints taken from the input + * if the input specified some kind of cacheable attribute. + */ + if (attr =3D=3D 0 || attr =3D=3D 4) { + /* + * 0 =3D=3D an UNPREDICTABLE encoding + * 4 =3D=3D Non-cacheable + * Either way, force Write-Back RW allocate non-transient + */ + return 0xf; + } + /* Change WriteThrough to WriteBack, keep allocation and transient hin= ts */ + return attr | 4; +} + +/* + * Combine the memory type and cacheability attributes of + * s1 and s2 for the HCR_EL2.FWB =3D=3D 1 case, returning the + * combined attributes in MAIR_EL1 format. + */ +static uint8_t combined_attrs_fwb(CPUARMState *env, + ARMCacheAttrs s1, ARMCacheAttrs s2) +{ + switch (s2.attrs) { + case 7: + /* Use stage 1 attributes */ + return s1.attrs; + case 6: + /* + * Force Normal Write-Back. Note that if S1 is Normal cacheable + * then we take the allocation hints from it; otherwise it is + * RW allocate, non-transient. + */ + if ((s1.attrs & 0xf0) =3D=3D 0) { + /* S1 is Device */ + return 0xff; + } + /* Need to check the Inner and Outer nibbles separately */ + return force_cacheattr_nibble_wb(s1.attrs & 0xf) | + force_cacheattr_nibble_wb(s1.attrs >> 4) << 4; + case 5: + /* If S1 attrs are Device, use them; otherwise Normal Non-cacheabl= e */ + if ((s1.attrs & 0xf0) =3D=3D 0) { + return s1.attrs; + } + return 0x44; + case 0 ... 3: + /* Force Device, of subtype specified by S2 */ + return s2.attrs << 2; + default: + /* + * RESERVED values (including RES0 descriptor bit [5] being nonzer= o); + * arbitrarily force Device. + */ + return 0; + } +} + +/* + * Combine S1 and S2 cacheability/shareability attributes, per D4.5.4 + * and CombineS1S2Desc() + * + * @env: CPUARMState + * @s1: Attributes from stage 1 walk + * @s2: Attributes from stage 2 walk + */ +static ARMCacheAttrs combine_cacheattrs(CPUARMState *env, + ARMCacheAttrs s1, ARMCacheAttrs s2) +{ + ARMCacheAttrs ret; + bool tagged =3D false; + + assert(s2.is_s2_format && !s1.is_s2_format); + ret.is_s2_format =3D false; + + if (s1.attrs =3D=3D 0xf0) { + tagged =3D true; + s1.attrs =3D 0xff; + } + + /* Combine shareability attributes (table D4-43) */ + if (s1.shareability =3D=3D 2 || s2.shareability =3D=3D 2) { + /* if either are outer-shareable, the result is outer-shareable */ + ret.shareability =3D 2; + } else if (s1.shareability =3D=3D 3 || s2.shareability =3D=3D 3) { + /* if either are inner-shareable, the result is inner-shareable */ + ret.shareability =3D 3; + } else { + /* both non-shareable */ + ret.shareability =3D 0; + } + + /* Combine memory type and cacheability attributes */ + if (arm_hcr_el2_eff(env) & HCR_FWB) { + ret.attrs =3D combined_attrs_fwb(env, s1, s2); + } else { + ret.attrs =3D combined_attrs_nofwb(env, s1, s2); + } + + /* + * Any location for which the resultant memory type is any + * type of Device memory is always treated as Outer Shareable. + * Any location for which the resultant memory type is Normal + * Inner Non-cacheable, Outer Non-cacheable is always treated + * as Outer Shareable. + * TODO: FEAT_XS adds another value (0x40) also meaning iNCoNC + */ + if ((ret.attrs & 0xf0) =3D=3D 0 || ret.attrs =3D=3D 0x44) { + ret.shareability =3D 2; + } + + /* TODO: CombineS1S2Desc does not consider transient, only WB, RWA. */ + if (tagged && ret.attrs =3D=3D 0xff) { + ret.attrs =3D 0xf0; + } + + return ret; +} + /** * get_phys_addr - get the physical address for this virtual address * --=20 2.34.1 From nobody Fri May 17 05:50:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1654317139; cv=none; d=zohomail.com; s=zohoarc; b=nOodKf5TUL8rn7PPgUneR0Xuw3Iu9jAAKrlbuXNtMkCOYKPRM5Di5OXpMZ7raRA1Q4m8f64Sp1EvUccdsyjni/xAauRGacXYV0yefVevZPYz8aZfOY39D6SIJfeAPrhAs8gOUvp+FQdxnd9yLocoSJWJTRgHzhNpd3r4+X/ub1k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1654317139; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=SnE1S/vvGNQjeXuS6ida3CxRaL0HwGQioTUCPGVLrSM=; b=BRYAcwUiA1y8G5ytQ0EjXQOAIj5c4RFgvBbiCrnX967NzKfwXjoWkMRLmrOpxwzimOyQfW+RZpmrj2srgAa4igjuO7E3cu3xfaGhpgPPgShCrMqWrMNRq9+CG18Tp8XmgSo57XAYJrkMebYGY3WJCxZyJe5V2NOoYGcqZQZtOHU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1654317139609576.2801384812408; Fri, 3 Jun 2022 21:32:19 -0700 (PDT) Received: from localhost ([::1]:35650 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nxLSU-0008OP-BN for importer@patchew.org; Sat, 04 Jun 2022 00:32:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36998) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nxL3V-0008BL-1z for qemu-devel@nongnu.org; Sat, 04 Jun 2022 00:06:29 -0400 Received: from mail-pg1-x534.google.com ([2607:f8b0:4864:20::534]:43605) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nxL3R-00008Z-5K for qemu-devel@nongnu.org; Sat, 04 Jun 2022 00:06:28 -0400 Received: by mail-pg1-x534.google.com with SMTP id s68so8641211pgs.10 for ; Fri, 03 Jun 2022 21:06:24 -0700 (PDT) Received: from stoup.. ([2602:ae:1547:e101:3286:cc26:3d5e:3f94]) by smtp.gmail.com with ESMTPSA id a37-20020a631a65000000b003c14af50626sm6093779pgm.62.2022.06.03.21.06.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jun 2022 21:06:22 -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=SnE1S/vvGNQjeXuS6ida3CxRaL0HwGQioTUCPGVLrSM=; b=Js6x6arkDlM8NGhYfM1+8DJOl3DIe6vYsBKDYOgR1Mj7VLIOKVnB7xlfzEaXDcmUOa 9Wzdm4ELX4NXCa9RWypEOcRkZnSy90Cm2bYzqPREn4sKREdukLIMqh2IKNZu1+6n/HPg bPdFSlxu18Rp47LX230ihUZUSCJxKs+2R9+/u7OD1H3G0u4jL5gfAr+6+4t+lzHOMXMV FbubsKExv67gHk0Kzxw5yKdxrVJBX0Xm0/VDP3LipMEV8PVR0AghfoPm1ObNJKBG/shU r2/nyeO0b629wDvpUVgKs3FIXfUgFkhSw31Jm6rQglEyMEgWvLcQHeILK9GxC4va11Ea iJyg== 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=SnE1S/vvGNQjeXuS6ida3CxRaL0HwGQioTUCPGVLrSM=; b=MRDSCQ7pKBOCgYQUU9gSJ+8VWMiOulCQSdO9gS0r3ftiDjVGWgi55WMawd2Mlt6lsZ RNPVi+etCNec7tLp0RLN4A+Wy9Th0Krgg7Ox3RwFp+xe3tUG4HpH9a0/G0gwPzTjzVdL UqMmM7ru9eo1WklHVkwLlGc/tgkog1iYFZftHw3sgqz7sk7kj4lPqVlSn11YLK0kgNvW Uv1JGAY/HNY1b7MH+scWHihpFkdfn7rh6i8KE3qth9lKDA3Wzf10TEOED1SDKZFv3IrU SsVBn3DOEvxDs1S4jt0ZOQPnWEufeSGCgT8e3ghwHL/MSccSCvdq3/MTBvH5f2FFVowp SXiA== X-Gm-Message-State: AOAM533lsXgRuU1f1fdTpuFGtYiaUwVnZ7ITtIRwZZOFiqD0sGeWrqiN aX8cyC531h7a1JPBim3GnjlC/L2DdDie8g== X-Google-Smtp-Source: ABdhPJw5hJ//2dmwoxxzIfIQBMUIuT2JwGlW0qI+PrRl3sni2JTozD+XO+g2D2IYn4JU+V6PJ+oyjg== X-Received: by 2002:a63:488:0:b0:3fc:d244:2cde with SMTP id 130-20020a630488000000b003fcd2442cdemr11152262pge.426.1654315583348; Fri, 03 Jun 2022 21:06:23 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Subject: [PATCH 15/28] target/arm: Move get_phys_addr_lpae to ptw.c Date: Fri, 3 Jun 2022 21:05:54 -0700 Message-Id: <20220604040607.269301-16-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220604040607.269301-1-richard.henderson@linaro.org> References: <20220604040607.269301-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=2607:f8b0:4864:20::534; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x534.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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1654317140553100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Richard Henderson --- target/arm/ptw.h | 10 ++ target/arm/helper.c | 416 +------------------------------------------- target/arm/ptw.c | 411 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 429 insertions(+), 408 deletions(-) diff --git a/target/arm/ptw.h b/target/arm/ptw.h index b2dfe489bb..31744df664 100644 --- a/target/arm/ptw.h +++ b/target/arm/ptw.h @@ -11,6 +11,8 @@ =20 #ifndef CONFIG_USER_ONLY =20 +extern const uint8_t pamax_map[7]; + uint32_t arm_ldl_ptw(CPUState *cs, hwaddr addr, bool is_secure, ARMMMUIdx mmu_idx, ARMMMUFaultInfo *fi); uint64_t arm_ldq_ptw(CPUState *cs, hwaddr addr, bool is_secure, @@ -30,6 +32,14 @@ simple_ap_to_rw_prot(CPUARMState *env, ARMMMUIdx mmu_idx= , int ap) return simple_ap_to_rw_prot_is_user(ap, regime_is_user(env, mmu_idx)); } =20 +ARMVAParameters aa32_va_parameters(CPUARMState *env, uint32_t va, + ARMMMUIdx mmu_idx); +bool check_s2_mmu_setup(ARMCPU *cpu, bool is_aa64, int level, + int inputsize, int stride, int outputsize); +int get_S2prot(CPUARMState *env, int s2ap, int xn, bool s1_is_el0); +int get_S1prot(CPUARMState *env, ARMMMUIdx mmu_idx, bool is_aa64, + int ap, int ns, int xn, int pxn); + bool get_phys_addr_lpae(CPUARMState *env, uint64_t address, MMUAccessType access_type, ARMMMUIdx mmu_idx, bool s1_is_el0, diff --git a/target/arm/helper.c b/target/arm/helper.c index 83aba35cfd..416e155a0f 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -10616,7 +10616,7 @@ int simple_ap_to_rw_prot_is_user(int ap, bool is_us= er) * @xn: XN (execute-never) bits * @s1_is_el0: true if this is S2 of an S1+2 walk for EL0 */ -static int get_S2prot(CPUARMState *env, int s2ap, int xn, bool s1_is_el0) +int get_S2prot(CPUARMState *env, int s2ap, int xn, bool s1_is_el0) { int prot =3D 0; =20 @@ -10667,8 +10667,8 @@ static int get_S2prot(CPUARMState *env, int s2ap, i= nt xn, bool s1_is_el0) * @xn: XN (execute-never) bit * @pxn: PXN (privileged execute-never) bit */ -static int get_S1prot(CPUARMState *env, ARMMMUIdx mmu_idx, bool is_aa64, - int ap, int ns, int xn, int pxn) +int get_S1prot(CPUARMState *env, ARMMMUIdx mmu_idx, bool is_aa64, + int ap, int ns, int xn, int pxn) { bool is_user =3D regime_is_user(env, mmu_idx); int prot_rw, user_rw; @@ -10883,8 +10883,8 @@ uint64_t arm_ldq_ptw(CPUState *cs, hwaddr addr, boo= l is_secure, * Returns true if the suggested S2 translation parameters are OK and * false otherwise. */ -static bool check_s2_mmu_setup(ARMCPU *cpu, bool is_aa64, int level, - int inputsize, int stride, int outputsize) +bool check_s2_mmu_setup(ARMCPU *cpu, bool is_aa64, int level, + int inputsize, int stride, int outputsize) { const int grainsize =3D stride + 3; int startsizecheck; @@ -10944,7 +10944,7 @@ static bool check_s2_mmu_setup(ARMCPU *cpu, bool is= _aa64, int level, #endif /* !CONFIG_USER_ONLY */ =20 /* This mapping is common between ID_AA64MMFR0.PARANGE and TCR_ELx.{I}PS. = */ -static const uint8_t pamax_map[] =3D { +const uint8_t pamax_map[] =3D { [0] =3D 32, [1] =3D 36, [2] =3D 40, @@ -11123,8 +11123,8 @@ ARMVAParameters aa64_va_parameters(CPUARMState *env= , uint64_t va, } =20 #ifndef CONFIG_USER_ONLY -static ARMVAParameters aa32_va_parameters(CPUARMState *env, uint32_t va, - ARMMMUIdx mmu_idx) +ARMVAParameters aa32_va_parameters(CPUARMState *env, uint32_t va, + ARMMMUIdx mmu_idx) { uint64_t tcr =3D regime_tcr(env, mmu_idx)->raw_tcr; uint32_t el =3D regime_el(env, mmu_idx); @@ -11187,406 +11187,6 @@ static ARMVAParameters aa32_va_parameters(CPUARMS= tate *env, uint32_t va, }; } =20 -/** - * get_phys_addr_lpae: perform one stage of page table walk, LPAE format - * - * Returns false if the translation was successful. Otherwise, phys_ptr, a= ttrs, - * prot and page_size may not be filled in, and the populated fsr value pr= ovides - * information on why the translation aborted, in the format of a long-for= mat - * DFSR/IFSR fault register, with the following caveats: - * * the WnR bit is never set (the caller must do this). - * - * @env: CPUARMState - * @address: virtual address to get physical address for - * @access_type: MMU_DATA_LOAD, MMU_DATA_STORE or MMU_INST_FETCH - * @mmu_idx: MMU index indicating required translation regime - * @s1_is_el0: if @mmu_idx is ARMMMUIdx_Stage2 (so this is a stage 2 page = table - * walk), must be true if this is stage 2 of a stage 1+2 walk = for an - * EL0 access). If @mmu_idx is anything else, @s1_is_el0 is ig= nored. - * @phys_ptr: set to the physical address corresponding to the virtual add= ress - * @attrs: set to the memory transaction attributes to use - * @prot: set to the permissions for the page containing phys_ptr - * @page_size_ptr: set to the size of the page containing phys_ptr - * @fi: set to fault info if the translation fails - * @cacheattrs: (if non-NULL) set to the cacheability/shareability attribu= tes - */ -bool get_phys_addr_lpae(CPUARMState *env, uint64_t address, - MMUAccessType access_type, ARMMMUIdx mmu_idx, - bool s1_is_el0, - hwaddr *phys_ptr, MemTxAttrs *txattrs, int *prot, - target_ulong *page_size_ptr, - ARMMMUFaultInfo *fi, ARMCacheAttrs *cacheattrs) -{ - ARMCPU *cpu =3D env_archcpu(env); - CPUState *cs =3D CPU(cpu); - /* Read an LPAE long-descriptor translation table. */ - ARMFaultType fault_type =3D ARMFault_Translation; - uint32_t level; - ARMVAParameters param; - uint64_t ttbr; - hwaddr descaddr, indexmask, indexmask_grainsize; - uint32_t tableattrs; - target_ulong page_size; - uint32_t attrs; - int32_t stride; - int addrsize, inputsize, outputsize; - TCR *tcr =3D regime_tcr(env, mmu_idx); - int ap, ns, xn, pxn; - uint32_t el =3D regime_el(env, mmu_idx); - uint64_t descaddrmask; - bool aarch64 =3D arm_el_is_aa64(env, el); - bool guarded =3D false; - - /* TODO: This code does not support shareability levels. */ - if (aarch64) { - int ps; - - param =3D aa64_va_parameters(env, address, mmu_idx, - access_type !=3D MMU_INST_FETCH); - level =3D 0; - - /* - * If TxSZ is programmed to a value larger than the maximum, - * or smaller than the effective minimum, it is IMPLEMENTATION - * DEFINED whether we behave as if the field were programmed - * within bounds, or if a level 0 Translation fault is generated. - * - * With FEAT_LVA, fault on less than minimum becomes required, - * so our choice is to always raise the fault. - */ - if (param.tsz_oob) { - fault_type =3D ARMFault_Translation; - goto do_fault; - } - - addrsize =3D 64 - 8 * param.tbi; - inputsize =3D 64 - param.tsz; - - /* - * Bound PS by PARANGE to find the effective output address size. - * ID_AA64MMFR0 is a read-only register so values outside of the - * supported mappings can be considered an implementation error. - */ - ps =3D FIELD_EX64(cpu->isar.id_aa64mmfr0, ID_AA64MMFR0, PARANGE); - ps =3D MIN(ps, param.ps); - assert(ps < ARRAY_SIZE(pamax_map)); - outputsize =3D pamax_map[ps]; - } else { - param =3D aa32_va_parameters(env, address, mmu_idx); - level =3D 1; - addrsize =3D (mmu_idx =3D=3D ARMMMUIdx_Stage2 ? 40 : 32); - inputsize =3D addrsize - param.tsz; - outputsize =3D 40; - } - - /* - * We determined the region when collecting the parameters, but we - * have not yet validated that the address is valid for the region. - * Extract the top bits and verify that they all match select. - * - * For aa32, if inputsize =3D=3D addrsize, then we have selected the - * region by exclusion in aa32_va_parameters and there is no more - * validation to do here. - */ - if (inputsize < addrsize) { - target_ulong top_bits =3D sextract64(address, inputsize, - addrsize - inputsize); - if (-top_bits !=3D param.select) { - /* The gap between the two regions is a Translation fault */ - fault_type =3D ARMFault_Translation; - goto do_fault; - } - } - - if (param.using64k) { - stride =3D 13; - } else if (param.using16k) { - stride =3D 11; - } else { - stride =3D 9; - } - - /* Note that QEMU ignores shareability and cacheability attributes, - * so we don't need to do anything with the SH, ORGN, IRGN fields - * in the TTBCR. Similarly, TTBCR:A1 selects whether we get the - * ASID from TTBR0 or TTBR1, but QEMU's TLB doesn't currently - * implement any ASID-like capability so we can ignore it (instead - * we will always flush the TLB any time the ASID is changed). - */ - ttbr =3D regime_ttbr(env, mmu_idx, param.select); - - /* Here we should have set up all the parameters for the translation: - * inputsize, ttbr, epd, stride, tbi - */ - - if (param.epd) { - /* Translation table walk disabled =3D> Translation fault on TLB m= iss - * Note: This is always 0 on 64-bit EL2 and EL3. - */ - goto do_fault; - } - - if (mmu_idx !=3D ARMMMUIdx_Stage2 && mmu_idx !=3D ARMMMUIdx_Stage2_S) { - /* The starting level depends on the virtual address size (which c= an - * be up to 48 bits) and the translation granule size. It indicates - * the number of strides (stride bits at a time) needed to - * consume the bits of the input address. In the pseudocode this i= s: - * level =3D 4 - RoundUp((inputsize - grainsize) / stride) - * where their 'inputsize' is our 'inputsize', 'grainsize' is - * our 'stride + 3' and 'stride' is our 'stride'. - * Applying the usual "rounded up m/n is (m+n-1)/n" and simplifyin= g: - * =3D 4 - (inputsize - stride - 3 + stride - 1) / stride - * =3D 4 - (inputsize - 4) / stride; - */ - level =3D 4 - (inputsize - 4) / stride; - } else { - /* For stage 2 translations the starting level is specified by the - * VTCR_EL2.SL0 field (whose interpretation depends on the page si= ze) - */ - uint32_t sl0 =3D extract32(tcr->raw_tcr, 6, 2); - uint32_t sl2 =3D extract64(tcr->raw_tcr, 33, 1); - uint32_t startlevel; - bool ok; - - /* SL2 is RES0 unless DS=3D1 & 4kb granule. */ - if (param.ds && stride =3D=3D 9 && sl2) { - if (sl0 !=3D 0) { - level =3D 0; - fault_type =3D ARMFault_Translation; - goto do_fault; - } - startlevel =3D -1; - } else if (!aarch64 || stride =3D=3D 9) { - /* AArch32 or 4KB pages */ - startlevel =3D 2 - sl0; - - if (cpu_isar_feature(aa64_st, cpu)) { - startlevel &=3D 3; - } - } else { - /* 16KB or 64KB pages */ - startlevel =3D 3 - sl0; - } - - /* Check that the starting level is valid. */ - ok =3D check_s2_mmu_setup(cpu, aarch64, startlevel, - inputsize, stride, outputsize); - if (!ok) { - fault_type =3D ARMFault_Translation; - goto do_fault; - } - level =3D startlevel; - } - - indexmask_grainsize =3D MAKE_64BIT_MASK(0, stride + 3); - indexmask =3D MAKE_64BIT_MASK(0, inputsize - (stride * (4 - level))); - - /* Now we can extract the actual base address from the TTBR */ - descaddr =3D extract64(ttbr, 0, 48); - - /* - * For FEAT_LPA and PS=3D6, bits [51:48] of descaddr are in [5:2] of T= TBR. - * - * Otherwise, if the base address is out of range, raise AddressSizeFa= ult. - * In the pseudocode, this is !IsZero(baseregister<47:outputsize>), - * but we've just cleared the bits above 47, so simplify the test. - */ - if (outputsize > 48) { - descaddr |=3D extract64(ttbr, 2, 4) << 48; - } else if (descaddr >> outputsize) { - level =3D 0; - fault_type =3D ARMFault_AddressSize; - goto do_fault; - } - - /* - * We rely on this masking to clear the RES0 bits at the bottom of the= TTBR - * and also to mask out CnP (bit 0) which could validly be non-zero. - */ - descaddr &=3D ~indexmask; - - /* - * For AArch32, the address field in the descriptor goes up to bit 39 - * for both v7 and v8. However, for v8 the SBZ bits [47:40] must be 0 - * or an AddressSize fault is raised. So for v8 we extract those SBZ - * bits as part of the address, which will be checked via outputsize. - * For AArch64, the address field goes up to bit 47, or 49 with FEAT_L= PA2; - * the highest bits of a 52-bit output are placed elsewhere. - */ - if (param.ds) { - descaddrmask =3D MAKE_64BIT_MASK(0, 50); - } else if (arm_feature(env, ARM_FEATURE_V8)) { - descaddrmask =3D MAKE_64BIT_MASK(0, 48); - } else { - descaddrmask =3D MAKE_64BIT_MASK(0, 40); - } - descaddrmask &=3D ~indexmask_grainsize; - - /* Secure accesses start with the page table in secure memory and - * can be downgraded to non-secure at any step. Non-secure accesses - * remain non-secure. We implement this by just ORing in the NSTable/NS - * bits at each step. - */ - tableattrs =3D regime_is_secure(env, mmu_idx) ? 0 : (1 << 4); - for (;;) { - uint64_t descriptor; - bool nstable; - - descaddr |=3D (address >> (stride * (4 - level))) & indexmask; - descaddr &=3D ~7ULL; - nstable =3D extract32(tableattrs, 4, 1); - descriptor =3D arm_ldq_ptw(cs, descaddr, !nstable, mmu_idx, fi); - if (fi->type !=3D ARMFault_None) { - goto do_fault; - } - - if (!(descriptor & 1) || - (!(descriptor & 2) && (level =3D=3D 3))) { - /* Invalid, or the Reserved level 3 encoding */ - goto do_fault; - } - - descaddr =3D descriptor & descaddrmask; - - /* - * For FEAT_LPA and PS=3D6, bits [51:48] of descaddr are in [15:12] - * of descriptor. For FEAT_LPA2 and effective DS, bits [51:50] of - * descaddr are in [9:8]. Otherwise, if descaddr is out of range, - * raise AddressSizeFault. - */ - if (outputsize > 48) { - if (param.ds) { - descaddr |=3D extract64(descriptor, 8, 2) << 50; - } else { - descaddr |=3D extract64(descriptor, 12, 4) << 48; - } - } else if (descaddr >> outputsize) { - fault_type =3D ARMFault_AddressSize; - goto do_fault; - } - - if ((descriptor & 2) && (level < 3)) { - /* Table entry. The top five bits are attributes which may - * propagate down through lower levels of the table (and - * which are all arranged so that 0 means "no effect", so - * we can gather them up by ORing in the bits at each level). - */ - tableattrs |=3D extract64(descriptor, 59, 5); - level++; - indexmask =3D indexmask_grainsize; - continue; - } - /* - * Block entry at level 1 or 2, or page entry at level 3. - * These are basically the same thing, although the number - * of bits we pull in from the vaddr varies. Note that although - * descaddrmask masks enough of the low bits of the descriptor - * to give a correct page or table address, the address field - * in a block descriptor is smaller; so we need to explicitly - * clear the lower bits here before ORing in the low vaddr bits. - */ - page_size =3D (1ULL << ((stride * (4 - level)) + 3)); - descaddr &=3D ~(page_size - 1); - descaddr |=3D (address & (page_size - 1)); - /* Extract attributes from the descriptor */ - attrs =3D extract64(descriptor, 2, 10) - | (extract64(descriptor, 52, 12) << 10); - - if (mmu_idx =3D=3D ARMMMUIdx_Stage2 || mmu_idx =3D=3D ARMMMUIdx_St= age2_S) { - /* Stage 2 table descriptors do not include any attribute fiel= ds */ - break; - } - /* Merge in attributes from table descriptors */ - attrs |=3D nstable << 3; /* NS */ - guarded =3D extract64(descriptor, 50, 1); /* GP */ - if (param.hpd) { - /* HPD disables all the table attributes except NSTable. */ - break; - } - attrs |=3D extract32(tableattrs, 0, 2) << 11; /* XN, PXN */ - /* The sense of AP[1] vs APTable[0] is reversed, as APTable[0] =3D= =3D 1 - * means "force PL1 access only", which means forcing AP[1] to 0. - */ - attrs &=3D ~(extract32(tableattrs, 2, 1) << 4); /* !APT[0] =3D> = AP[1] */ - attrs |=3D extract32(tableattrs, 3, 1) << 5; /* APT[1] =3D> A= P[2] */ - break; - } - /* Here descaddr is the final physical address, and attributes - * are all in attrs. - */ - fault_type =3D ARMFault_AccessFlag; - if ((attrs & (1 << 8)) =3D=3D 0) { - /* Access flag */ - goto do_fault; - } - - ap =3D extract32(attrs, 4, 2); - - if (mmu_idx =3D=3D ARMMMUIdx_Stage2 || mmu_idx =3D=3D ARMMMUIdx_Stage2= _S) { - ns =3D mmu_idx =3D=3D ARMMMUIdx_Stage2; - xn =3D extract32(attrs, 11, 2); - *prot =3D get_S2prot(env, ap, xn, s1_is_el0); - } else { - ns =3D extract32(attrs, 3, 1); - xn =3D extract32(attrs, 12, 1); - pxn =3D extract32(attrs, 11, 1); - *prot =3D get_S1prot(env, mmu_idx, aarch64, ap, ns, xn, pxn); - } - - fault_type =3D ARMFault_Permission; - if (!(*prot & (1 << access_type))) { - goto do_fault; - } - - if (ns) { - /* The NS bit will (as required by the architecture) have no effec= t if - * the CPU doesn't support TZ or this is a non-secure translation - * regime, because the attribute will already be non-secure. - */ - txattrs->secure =3D false; - } - /* When in aarch64 mode, and BTI is enabled, remember GP in the IOTLB.= */ - if (aarch64 && guarded && cpu_isar_feature(aa64_bti, cpu)) { - arm_tlb_bti_gp(txattrs) =3D true; - } - - if (mmu_idx =3D=3D ARMMMUIdx_Stage2 || mmu_idx =3D=3D ARMMMUIdx_Stage2= _S) { - cacheattrs->is_s2_format =3D true; - cacheattrs->attrs =3D extract32(attrs, 0, 4); - } else { - /* Index into MAIR registers for cache attributes */ - uint8_t attrindx =3D extract32(attrs, 0, 3); - uint64_t mair =3D env->cp15.mair_el[regime_el(env, mmu_idx)]; - assert(attrindx <=3D 7); - cacheattrs->is_s2_format =3D false; - cacheattrs->attrs =3D extract64(mair, attrindx * 8, 8); - } - - /* - * For FEAT_LPA2 and effective DS, the SH field in the attributes - * was re-purposed for output address bits. The SH attribute in - * that case comes from TCR_ELx, which we extracted earlier. - */ - if (param.ds) { - cacheattrs->shareability =3D param.sh; - } else { - cacheattrs->shareability =3D extract32(attrs, 6, 2); - } - - *phys_ptr =3D descaddr; - *page_size_ptr =3D page_size; - return false; - -do_fault: - fi->type =3D fault_type; - fi->level =3D level; - /* Tag the error as S2 for failed S1 PTW at S2 or ordinary S2. */ - fi->stage2 =3D fi->s1ptw || (mmu_idx =3D=3D ARMMMUIdx_Stage2 || - mmu_idx =3D=3D ARMMMUIdx_Stage2_S); - fi->s1ns =3D mmu_idx =3D=3D ARMMMUIdx_Stage2; - return true; -} - hwaddr arm_cpu_get_phys_page_attrs_debug(CPUState *cs, vaddr addr, MemTxAttrs *attrs) { diff --git a/target/arm/ptw.c b/target/arm/ptw.c index f2ca2bb8fe..cbccf91b13 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -314,6 +314,417 @@ do_fault: return true; } =20 +/** + * get_phys_addr_lpae: perform one stage of page table walk, LPAE format + * + * Returns false if the translation was successful. Otherwise, phys_ptr, + * attrs, prot and page_size may not be filled in, and the populated fsr + * value provides information on why the translation aborted, in the format + * of a long-format DFSR/IFSR fault register, with the following caveat: + * the WnR bit is never set (the caller must do this). + * + * @env: CPUARMState + * @address: virtual address to get physical address for + * @access_type: MMU_DATA_LOAD, MMU_DATA_STORE or MMU_INST_FETCH + * @mmu_idx: MMU index indicating required translation regime + * @s1_is_el0: if @mmu_idx is ARMMMUIdx_Stage2 (so this is a stage 2 page + * table walk), must be true if this is stage 2 of a stage 1+2 + * walk for an EL0 access. If @mmu_idx is anything else, + * @s1_is_el0 is ignored. + * @phys_ptr: set to the physical address corresponding to the virtual add= ress + * @attrs: set to the memory transaction attributes to use + * @prot: set to the permissions for the page containing phys_ptr + * @page_size_ptr: set to the size of the page containing phys_ptr + * @fi: set to fault info if the translation fails + * @cacheattrs: (if non-NULL) set to the cacheability/shareability attribu= tes + */ +bool get_phys_addr_lpae(CPUARMState *env, uint64_t address, + MMUAccessType access_type, ARMMMUIdx mmu_idx, + bool s1_is_el0, + hwaddr *phys_ptr, MemTxAttrs *txattrs, int *prot, + target_ulong *page_size_ptr, + ARMMMUFaultInfo *fi, ARMCacheAttrs *cacheattrs) +{ + ARMCPU *cpu =3D env_archcpu(env); + CPUState *cs =3D CPU(cpu); + /* Read an LPAE long-descriptor translation table. */ + ARMFaultType fault_type =3D ARMFault_Translation; + uint32_t level; + ARMVAParameters param; + uint64_t ttbr; + hwaddr descaddr, indexmask, indexmask_grainsize; + uint32_t tableattrs; + target_ulong page_size; + uint32_t attrs; + int32_t stride; + int addrsize, inputsize, outputsize; + TCR *tcr =3D regime_tcr(env, mmu_idx); + int ap, ns, xn, pxn; + uint32_t el =3D regime_el(env, mmu_idx); + uint64_t descaddrmask; + bool aarch64 =3D arm_el_is_aa64(env, el); + bool guarded =3D false; + + /* TODO: This code does not support shareability levels. */ + if (aarch64) { + int ps; + + param =3D aa64_va_parameters(env, address, mmu_idx, + access_type !=3D MMU_INST_FETCH); + level =3D 0; + + /* + * If TxSZ is programmed to a value larger than the maximum, + * or smaller than the effective minimum, it is IMPLEMENTATION + * DEFINED whether we behave as if the field were programmed + * within bounds, or if a level 0 Translation fault is generated. + * + * With FEAT_LVA, fault on less than minimum becomes required, + * so our choice is to always raise the fault. + */ + if (param.tsz_oob) { + fault_type =3D ARMFault_Translation; + goto do_fault; + } + + addrsize =3D 64 - 8 * param.tbi; + inputsize =3D 64 - param.tsz; + + /* + * Bound PS by PARANGE to find the effective output address size. + * ID_AA64MMFR0 is a read-only register so values outside of the + * supported mappings can be considered an implementation error. + */ + ps =3D FIELD_EX64(cpu->isar.id_aa64mmfr0, ID_AA64MMFR0, PARANGE); + ps =3D MIN(ps, param.ps); + assert(ps < ARRAY_SIZE(pamax_map)); + outputsize =3D pamax_map[ps]; + } else { + param =3D aa32_va_parameters(env, address, mmu_idx); + level =3D 1; + addrsize =3D (mmu_idx =3D=3D ARMMMUIdx_Stage2 ? 40 : 32); + inputsize =3D addrsize - param.tsz; + outputsize =3D 40; + } + + /* + * We determined the region when collecting the parameters, but we + * have not yet validated that the address is valid for the region. + * Extract the top bits and verify that they all match select. + * + * For aa32, if inputsize =3D=3D addrsize, then we have selected the + * region by exclusion in aa32_va_parameters and there is no more + * validation to do here. + */ + if (inputsize < addrsize) { + target_ulong top_bits =3D sextract64(address, inputsize, + addrsize - inputsize); + if (-top_bits !=3D param.select) { + /* The gap between the two regions is a Translation fault */ + fault_type =3D ARMFault_Translation; + goto do_fault; + } + } + + if (param.using64k) { + stride =3D 13; + } else if (param.using16k) { + stride =3D 11; + } else { + stride =3D 9; + } + + /* + * Note that QEMU ignores shareability and cacheability attributes, + * so we don't need to do anything with the SH, ORGN, IRGN fields + * in the TTBCR. Similarly, TTBCR:A1 selects whether we get the + * ASID from TTBR0 or TTBR1, but QEMU's TLB doesn't currently + * implement any ASID-like capability so we can ignore it (instead + * we will always flush the TLB any time the ASID is changed). + */ + ttbr =3D regime_ttbr(env, mmu_idx, param.select); + + /* + * Here we should have set up all the parameters for the translation: + * inputsize, ttbr, epd, stride, tbi + */ + + if (param.epd) { + /* + * Translation table walk disabled =3D> Translation fault on TLB m= iss + * Note: This is always 0 on 64-bit EL2 and EL3. + */ + goto do_fault; + } + + if (mmu_idx !=3D ARMMMUIdx_Stage2 && mmu_idx !=3D ARMMMUIdx_Stage2_S) { + /* + * The starting level depends on the virtual address size (which c= an + * be up to 48 bits) and the translation granule size. It indicates + * the number of strides (stride bits at a time) needed to + * consume the bits of the input address. In the pseudocode this i= s: + * level =3D 4 - RoundUp((inputsize - grainsize) / stride) + * where their 'inputsize' is our 'inputsize', 'grainsize' is + * our 'stride + 3' and 'stride' is our 'stride'. + * Applying the usual "rounded up m/n is (m+n-1)/n" and simplifyin= g: + * =3D 4 - (inputsize - stride - 3 + stride - 1) / stride + * =3D 4 - (inputsize - 4) / stride; + */ + level =3D 4 - (inputsize - 4) / stride; + } else { + /* + * For stage 2 translations the starting level is specified by the + * VTCR_EL2.SL0 field (whose interpretation depends on the page si= ze) + */ + uint32_t sl0 =3D extract32(tcr->raw_tcr, 6, 2); + uint32_t sl2 =3D extract64(tcr->raw_tcr, 33, 1); + uint32_t startlevel; + bool ok; + + /* SL2 is RES0 unless DS=3D1 & 4kb granule. */ + if (param.ds && stride =3D=3D 9 && sl2) { + if (sl0 !=3D 0) { + level =3D 0; + fault_type =3D ARMFault_Translation; + goto do_fault; + } + startlevel =3D -1; + } else if (!aarch64 || stride =3D=3D 9) { + /* AArch32 or 4KB pages */ + startlevel =3D 2 - sl0; + + if (cpu_isar_feature(aa64_st, cpu)) { + startlevel &=3D 3; + } + } else { + /* 16KB or 64KB pages */ + startlevel =3D 3 - sl0; + } + + /* Check that the starting level is valid. */ + ok =3D check_s2_mmu_setup(cpu, aarch64, startlevel, + inputsize, stride, outputsize); + if (!ok) { + fault_type =3D ARMFault_Translation; + goto do_fault; + } + level =3D startlevel; + } + + indexmask_grainsize =3D MAKE_64BIT_MASK(0, stride + 3); + indexmask =3D MAKE_64BIT_MASK(0, inputsize - (stride * (4 - level))); + + /* Now we can extract the actual base address from the TTBR */ + descaddr =3D extract64(ttbr, 0, 48); + + /* + * For FEAT_LPA and PS=3D6, bits [51:48] of descaddr are in [5:2] of T= TBR. + * + * Otherwise, if the base address is out of range, raise AddressSizeFa= ult. + * In the pseudocode, this is !IsZero(baseregister<47:outputsize>), + * but we've just cleared the bits above 47, so simplify the test. + */ + if (outputsize > 48) { + descaddr |=3D extract64(ttbr, 2, 4) << 48; + } else if (descaddr >> outputsize) { + level =3D 0; + fault_type =3D ARMFault_AddressSize; + goto do_fault; + } + + /* + * We rely on this masking to clear the RES0 bits at the bottom of the= TTBR + * and also to mask out CnP (bit 0) which could validly be non-zero. + */ + descaddr &=3D ~indexmask; + + /* + * For AArch32, the address field in the descriptor goes up to bit 39 + * for both v7 and v8. However, for v8 the SBZ bits [47:40] must be 0 + * or an AddressSize fault is raised. So for v8 we extract those SBZ + * bits as part of the address, which will be checked via outputsize. + * For AArch64, the address field goes up to bit 47, or 49 with FEAT_L= PA2; + * the highest bits of a 52-bit output are placed elsewhere. + */ + if (param.ds) { + descaddrmask =3D MAKE_64BIT_MASK(0, 50); + } else if (arm_feature(env, ARM_FEATURE_V8)) { + descaddrmask =3D MAKE_64BIT_MASK(0, 48); + } else { + descaddrmask =3D MAKE_64BIT_MASK(0, 40); + } + descaddrmask &=3D ~indexmask_grainsize; + + /* + * Secure accesses start with the page table in secure memory and + * can be downgraded to non-secure at any step. Non-secure accesses + * remain non-secure. We implement this by just ORing in the NSTable/NS + * bits at each step. + */ + tableattrs =3D regime_is_secure(env, mmu_idx) ? 0 : (1 << 4); + for (;;) { + uint64_t descriptor; + bool nstable; + + descaddr |=3D (address >> (stride * (4 - level))) & indexmask; + descaddr &=3D ~7ULL; + nstable =3D extract32(tableattrs, 4, 1); + descriptor =3D arm_ldq_ptw(cs, descaddr, !nstable, mmu_idx, fi); + if (fi->type !=3D ARMFault_None) { + goto do_fault; + } + + if (!(descriptor & 1) || + (!(descriptor & 2) && (level =3D=3D 3))) { + /* Invalid, or the Reserved level 3 encoding */ + goto do_fault; + } + + descaddr =3D descriptor & descaddrmask; + + /* + * For FEAT_LPA and PS=3D6, bits [51:48] of descaddr are in [15:12] + * of descriptor. For FEAT_LPA2 and effective DS, bits [51:50] of + * descaddr are in [9:8]. Otherwise, if descaddr is out of range, + * raise AddressSizeFault. + */ + if (outputsize > 48) { + if (param.ds) { + descaddr |=3D extract64(descriptor, 8, 2) << 50; + } else { + descaddr |=3D extract64(descriptor, 12, 4) << 48; + } + } else if (descaddr >> outputsize) { + fault_type =3D ARMFault_AddressSize; + goto do_fault; + } + + if ((descriptor & 2) && (level < 3)) { + /* + * Table entry. The top five bits are attributes which may + * propagate down through lower levels of the table (and + * which are all arranged so that 0 means "no effect", so + * we can gather them up by ORing in the bits at each level). + */ + tableattrs |=3D extract64(descriptor, 59, 5); + level++; + indexmask =3D indexmask_grainsize; + continue; + } + /* + * Block entry at level 1 or 2, or page entry at level 3. + * These are basically the same thing, although the number + * of bits we pull in from the vaddr varies. Note that although + * descaddrmask masks enough of the low bits of the descriptor + * to give a correct page or table address, the address field + * in a block descriptor is smaller; so we need to explicitly + * clear the lower bits here before ORing in the low vaddr bits. + */ + page_size =3D (1ULL << ((stride * (4 - level)) + 3)); + descaddr &=3D ~(page_size - 1); + descaddr |=3D (address & (page_size - 1)); + /* Extract attributes from the descriptor */ + attrs =3D extract64(descriptor, 2, 10) + | (extract64(descriptor, 52, 12) << 10); + + if (mmu_idx =3D=3D ARMMMUIdx_Stage2 || mmu_idx =3D=3D ARMMMUIdx_St= age2_S) { + /* Stage 2 table descriptors do not include any attribute fiel= ds */ + break; + } + /* Merge in attributes from table descriptors */ + attrs |=3D nstable << 3; /* NS */ + guarded =3D extract64(descriptor, 50, 1); /* GP */ + if (param.hpd) { + /* HPD disables all the table attributes except NSTable. */ + break; + } + attrs |=3D extract32(tableattrs, 0, 2) << 11; /* XN, PXN */ + /* + * The sense of AP[1] vs APTable[0] is reversed, as APTable[0] =3D= =3D 1 + * means "force PL1 access only", which means forcing AP[1] to 0. + */ + attrs &=3D ~(extract32(tableattrs, 2, 1) << 4); /* !APT[0] =3D> = AP[1] */ + attrs |=3D extract32(tableattrs, 3, 1) << 5; /* APT[1] =3D> A= P[2] */ + break; + } + /* + * Here descaddr is the final physical address, and attributes + * are all in attrs. + */ + fault_type =3D ARMFault_AccessFlag; + if ((attrs & (1 << 8)) =3D=3D 0) { + /* Access flag */ + goto do_fault; + } + + ap =3D extract32(attrs, 4, 2); + + if (mmu_idx =3D=3D ARMMMUIdx_Stage2 || mmu_idx =3D=3D ARMMMUIdx_Stage2= _S) { + ns =3D mmu_idx =3D=3D ARMMMUIdx_Stage2; + xn =3D extract32(attrs, 11, 2); + *prot =3D get_S2prot(env, ap, xn, s1_is_el0); + } else { + ns =3D extract32(attrs, 3, 1); + xn =3D extract32(attrs, 12, 1); + pxn =3D extract32(attrs, 11, 1); + *prot =3D get_S1prot(env, mmu_idx, aarch64, ap, ns, xn, pxn); + } + + fault_type =3D ARMFault_Permission; + if (!(*prot & (1 << access_type))) { + goto do_fault; + } + + if (ns) { + /* + * The NS bit will (as required by the architecture) have no effec= t if + * the CPU doesn't support TZ or this is a non-secure translation + * regime, because the attribute will already be non-secure. + */ + txattrs->secure =3D false; + } + /* When in aarch64 mode, and BTI is enabled, remember GP in the IOTLB.= */ + if (aarch64 && guarded && cpu_isar_feature(aa64_bti, cpu)) { + arm_tlb_bti_gp(txattrs) =3D true; + } + + if (mmu_idx =3D=3D ARMMMUIdx_Stage2 || mmu_idx =3D=3D ARMMMUIdx_Stage2= _S) { + cacheattrs->is_s2_format =3D true; + cacheattrs->attrs =3D extract32(attrs, 0, 4); + } else { + /* Index into MAIR registers for cache attributes */ + uint8_t attrindx =3D extract32(attrs, 0, 3); + uint64_t mair =3D env->cp15.mair_el[regime_el(env, mmu_idx)]; + assert(attrindx <=3D 7); + cacheattrs->is_s2_format =3D false; + cacheattrs->attrs =3D extract64(mair, attrindx * 8, 8); + } + + /* + * For FEAT_LPA2 and effective DS, the SH field in the attributes + * was re-purposed for output address bits. The SH attribute in + * that case comes from TCR_ELx, which we extracted earlier. + */ + if (param.ds) { + cacheattrs->shareability =3D param.sh; + } else { + cacheattrs->shareability =3D extract32(attrs, 6, 2); + } + + *phys_ptr =3D descaddr; + *page_size_ptr =3D page_size; + return false; + +do_fault: + fi->type =3D fault_type; + fi->level =3D level; + /* Tag the error as S2 for failed S1 PTW at S2 or ordinary S2. */ + fi->stage2 =3D fi->s1ptw || (mmu_idx =3D=3D ARMMMUIdx_Stage2 || + mmu_idx =3D=3D ARMMMUIdx_Stage2_S); + fi->s1ns =3D mmu_idx =3D=3D ARMMMUIdx_Stage2; + return true; +} + static bool get_phys_addr_pmsav5(CPUARMState *env, uint32_t address, MMUAccessType access_type, ARMMMUIdx mmu_= idx, hwaddr *phys_ptr, int *prot, --=20 2.34.1 From nobody Fri May 17 05:50:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1654316872; cv=none; d=zohomail.com; s=zohoarc; b=BrztOIwKtdRjXytTN1Guq64oNDD5zxPcvhtWtP6HL5YPXXRV3MI8/TyprOQ99n962NJ9VizHQuINlKQICQIz5a0sAPVjTjOepdf3AS7k1Jqxl+PHmAsUVNt2m3fT1iAnp7D4QjnDMOkYDTojRLnlYljgG75VJP0faKrRBTmJ4Yw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1654316872; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=MlDbZJ4tTAYIMhlSiDFHC8cjPSfeu4cSmYSRMTelt2s=; b=Vb6aBovZepvujpdPDAH/qaYR5f/VMxCsXIb/5lqLEdCTXoM3QeJ5ZNbilp9wkbJ8QtZ72y56TM5128jRiPl9bgYzI8hFwnvO4uoPLgbtFVDr3mIoRdrstZ0olfSaOvLFqxjzqKK9RP3fTPGHFZD+G8PbebSB6GJhip9PSSq4jRk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1654316872612601.982708429359; Fri, 3 Jun 2022 21:27:52 -0700 (PDT) Received: from localhost ([::1]:56906 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nxLOB-0003YO-Au for importer@patchew.org; Sat, 04 Jun 2022 00:27:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36950) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nxL3T-00086Z-Ul for qemu-devel@nongnu.org; Sat, 04 Jun 2022 00:06:27 -0400 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]:35545) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nxL3R-00008i-Hl for qemu-devel@nongnu.org; Sat, 04 Jun 2022 00:06:27 -0400 Received: by mail-pl1-x62b.google.com with SMTP id o6so3033649plg.2 for ; Fri, 03 Jun 2022 21:06:25 -0700 (PDT) Received: from stoup.. ([2602:ae:1547:e101:3286:cc26:3d5e:3f94]) by smtp.gmail.com with ESMTPSA id a37-20020a631a65000000b003c14af50626sm6093779pgm.62.2022.06.03.21.06.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jun 2022 21:06:23 -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=MlDbZJ4tTAYIMhlSiDFHC8cjPSfeu4cSmYSRMTelt2s=; b=Jc8MTvtP6IPNdFxh9Gw2NDm3GvsnUmFQFzR5d+FWQ+QPJXBFdPfxHLsoL7ORU//aMR zMbHtG+HwnE9cMVg+BbD6LwCwiFdmk6Dgz6WmjYWT14QqOq9CFsuOgvrF2wQ3dw7aNLl mtKoQhqImBpXT0FCht256r5Ew2VtomU16+oGmB/MhysuqXXjt1BTWj4Zc171BFoY1NZR 3a8VFvMh23fRpT0OEcu3saj5vGvAj6PHqGSo5dUTioIb2cQUd4hmiqWDvqFCEJbupOts xWx17Upv01Pr5/z6EWEniO92Bm/09JPcLJpkz6L3En7QyhLK1L94thRitqVeXmX35gTe OEwA== 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=MlDbZJ4tTAYIMhlSiDFHC8cjPSfeu4cSmYSRMTelt2s=; b=vPdaWeNtHaWwR0rVLy4YMXi+eSC8j/FP/8/u+AQ0wCJ0zbCXzaWPEbrRE3qHXs9MA8 0Hw6Yh+sU3+LyJzDDMBtC7uQPCF9i6CsQTrKWcMh2lE7bRLcB02Q7+h5mNW6FGmOrl4L eQ6xhWq32XjCRAMRJ3MF8SSZ7EcNWg7d0L6agTkEFbLp/09Ax5UlEPbLNHGeqcqG/rOd o1e6Yd0WCDUJvuEQCQrrNpY+6/JqDqYrzd1GvAaWCMf3kiYyq51VRL5fnHd+6QCYaOpr q0qvWwTyrQo68UwwKON7vQsLF3NAnq6AcGQ1VaPieCO2dvZxrkNS7EdvqqX7Tt9TAuGN nGWA== X-Gm-Message-State: AOAM533feipLThvdqKxdj8CNBVbBWuE26ZejsdDB7g72Fzd8VAMxABlp 7UAJ4CXh2QM8KsCYex2ba2KjwjEMUG5sBQ== X-Google-Smtp-Source: ABdhPJx1PYRraOWLH0GL7C/Gvij/t0MMNfjtzHQs0dw/XlEu2Z/Zf4bNv/lCLJu5s4Tddnsdkl6m/g== X-Received: by 2002:a17:902:f789:b0:163:935d:aa69 with SMTP id q9-20020a170902f78900b00163935daa69mr12977826pln.165.1654315584086; Fri, 03 Jun 2022 21:06:24 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Subject: [PATCH 16/28] target/arm: Move arm_{ldl,ldq}_ptw to ptw.c Date: Fri, 3 Jun 2022 21:05:55 -0700 Message-Id: <20220604040607.269301-17-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220604040607.269301-1-richard.henderson@linaro.org> References: <20220604040607.269301-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=2607:f8b0:4864:20::62b; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62b.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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1654316873489100001 Content-Type: text/plain; charset="utf-8" Move the ptw load functions, plus 3 common subroutines: S1_ptw_translate, ptw_attrs_are_device, and regime_translation_big_endian. This also allows get_phys_addr_lpae to become static again. Signed-off-by: Richard Henderson --- target/arm/ptw.h | 13 ---- target/arm/helper.c | 141 -------------------------------------- target/arm/ptw.c | 160 ++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 154 insertions(+), 160 deletions(-) diff --git a/target/arm/ptw.h b/target/arm/ptw.h index 31744df664..28b8cb9fb8 100644 --- a/target/arm/ptw.h +++ b/target/arm/ptw.h @@ -13,11 +13,6 @@ =20 extern const uint8_t pamax_map[7]; =20 -uint32_t arm_ldl_ptw(CPUState *cs, hwaddr addr, bool is_secure, - ARMMMUIdx mmu_idx, ARMMMUFaultInfo *fi); -uint64_t arm_ldq_ptw(CPUState *cs, hwaddr addr, bool is_secure, - ARMMMUIdx mmu_idx, ARMMMUFaultInfo *fi); - bool regime_is_user(CPUARMState *env, ARMMMUIdx mmu_idx); bool regime_translation_disabled(CPUARMState *env, ARMMMUIdx mmu_idx); uint64_t regime_ttbr(CPUARMState *env, ARMMMUIdx mmu_idx, int ttbrn); @@ -40,13 +35,5 @@ int get_S2prot(CPUARMState *env, int s2ap, int xn, bool = s1_is_el0); int get_S1prot(CPUARMState *env, ARMMMUIdx mmu_idx, bool is_aa64, int ap, int ns, int xn, int pxn); =20 -bool get_phys_addr_lpae(CPUARMState *env, uint64_t address, - MMUAccessType access_type, ARMMMUIdx mmu_idx, - bool s1_is_el0, - hwaddr *phys_ptr, MemTxAttrs *txattrs, int *prot, - target_ulong *page_size_ptr, - ARMMMUFaultInfo *fi, ARMCacheAttrs *cacheattrs) - __attribute__((nonnull)); - #endif /* !CONFIG_USER_ONLY */ #endif /* TARGET_ARM_PTW_H */ diff --git a/target/arm/helper.c b/target/arm/helper.c index 416e155a0f..f6931237fe 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -10439,12 +10439,6 @@ bool regime_translation_disabled(CPUARMState *env,= ARMMMUIdx mmu_idx) return (regime_sctlr(env, mmu_idx) & SCTLR_M) =3D=3D 0; } =20 -static inline bool regime_translation_big_endian(CPUARMState *env, - ARMMMUIdx mmu_idx) -{ - return (regime_sctlr(env, mmu_idx) & SCTLR_EE) !=3D 0; -} - /* Return the TTBR associated with this translation regime */ uint64_t regime_ttbr(CPUARMState *env, ARMMMUIdx mmu_idx, int ttbrn) { @@ -10737,141 +10731,6 @@ int get_S1prot(CPUARMState *env, ARMMMUIdx mmu_id= x, bool is_aa64, return prot_rw | PAGE_EXEC; } =20 -static bool ptw_attrs_are_device(CPUARMState *env, ARMCacheAttrs cacheattr= s) -{ - /* - * For an S1 page table walk, the stage 1 attributes are always - * some form of "this is Normal memory". The combined S1+S2 - * attributes are therefore only Device if stage 2 specifies Device. - * With HCR_EL2.FWB =3D=3D 0 this is when descriptor bits [5:4] are 0b= 00, - * ie when cacheattrs.attrs bits [3:2] are 0b00. - * With HCR_EL2.FWB =3D=3D 1 this is when descriptor bit [4] is 0, ie - * when cacheattrs.attrs bit [2] is 0. - */ - assert(cacheattrs.is_s2_format); - if (arm_hcr_el2_eff(env) & HCR_FWB) { - return (cacheattrs.attrs & 0x4) =3D=3D 0; - } else { - return (cacheattrs.attrs & 0xc) =3D=3D 0; - } -} - -/* Translate a S1 pagetable walk through S2 if needed. */ -static hwaddr S1_ptw_translate(CPUARMState *env, ARMMMUIdx mmu_idx, - hwaddr addr, bool *is_secure, - ARMMMUFaultInfo *fi) -{ - if (arm_mmu_idx_is_stage1_of_2(mmu_idx) && - !regime_translation_disabled(env, ARMMMUIdx_Stage2)) { - target_ulong s2size; - hwaddr s2pa; - int s2prot; - int ret; - ARMMMUIdx s2_mmu_idx =3D *is_secure ? ARMMMUIdx_Stage2_S - : ARMMMUIdx_Stage2; - ARMCacheAttrs cacheattrs =3D {}; - MemTxAttrs txattrs =3D {}; - - ret =3D get_phys_addr_lpae(env, addr, MMU_DATA_LOAD, s2_mmu_idx, f= alse, - &s2pa, &txattrs, &s2prot, &s2size, fi, - &cacheattrs); - if (ret) { - assert(fi->type !=3D ARMFault_None); - fi->s2addr =3D addr; - fi->stage2 =3D true; - fi->s1ptw =3D true; - fi->s1ns =3D !*is_secure; - return ~0; - } - if ((arm_hcr_el2_eff(env) & HCR_PTW) && - ptw_attrs_are_device(env, cacheattrs)) { - /* - * PTW set and S1 walk touched S2 Device memory: - * generate Permission fault. - */ - fi->type =3D ARMFault_Permission; - fi->s2addr =3D addr; - fi->stage2 =3D true; - fi->s1ptw =3D true; - fi->s1ns =3D !*is_secure; - return ~0; - } - - if (arm_is_secure_below_el3(env)) { - /* Check if page table walk is to secure or non-secure PA spac= e. */ - if (*is_secure) { - *is_secure =3D !(env->cp15.vstcr_el2.raw_tcr & VSTCR_SW); - } else { - *is_secure =3D !(env->cp15.vtcr_el2.raw_tcr & VTCR_NSW); - } - } else { - assert(!*is_secure); - } - - addr =3D s2pa; - } - return addr; -} - -/* All loads done in the course of a page table walk go through here. */ -uint32_t arm_ldl_ptw(CPUState *cs, hwaddr addr, bool is_secure, - ARMMMUIdx mmu_idx, ARMMMUFaultInfo *fi) -{ - ARMCPU *cpu =3D ARM_CPU(cs); - CPUARMState *env =3D &cpu->env; - MemTxAttrs attrs =3D {}; - MemTxResult result =3D MEMTX_OK; - AddressSpace *as; - uint32_t data; - - addr =3D S1_ptw_translate(env, mmu_idx, addr, &is_secure, fi); - attrs.secure =3D is_secure; - as =3D arm_addressspace(cs, attrs); - if (fi->s1ptw) { - return 0; - } - if (regime_translation_big_endian(env, mmu_idx)) { - data =3D address_space_ldl_be(as, addr, attrs, &result); - } else { - data =3D address_space_ldl_le(as, addr, attrs, &result); - } - if (result =3D=3D MEMTX_OK) { - return data; - } - fi->type =3D ARMFault_SyncExternalOnWalk; - fi->ea =3D arm_extabort_type(result); - return 0; -} - -uint64_t arm_ldq_ptw(CPUState *cs, hwaddr addr, bool is_secure, - ARMMMUIdx mmu_idx, ARMMMUFaultInfo *fi) -{ - ARMCPU *cpu =3D ARM_CPU(cs); - CPUARMState *env =3D &cpu->env; - MemTxAttrs attrs =3D {}; - MemTxResult result =3D MEMTX_OK; - AddressSpace *as; - uint64_t data; - - addr =3D S1_ptw_translate(env, mmu_idx, addr, &is_secure, fi); - attrs.secure =3D is_secure; - as =3D arm_addressspace(cs, attrs); - if (fi->s1ptw) { - return 0; - } - if (regime_translation_big_endian(env, mmu_idx)) { - data =3D address_space_ldq_be(as, addr, attrs, &result); - } else { - data =3D address_space_ldq_le(as, addr, attrs, &result); - } - if (result =3D=3D MEMTX_OK) { - return data; - } - fi->type =3D ARMFault_SyncExternalOnWalk; - fi->ea =3D arm_extabort_type(result); - return 0; -} - /* * check_s2_mmu_setup * @cpu: ARMCPU diff --git a/target/arm/ptw.c b/target/arm/ptw.c index cbccf91b13..e4b860d2ae 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -15,6 +15,154 @@ #include "ptw.h" =20 =20 +static bool get_phys_addr_lpae(CPUARMState *env, uint64_t address, + MMUAccessType access_type, ARMMMUIdx mmu_id= x, + bool s1_is_el0, hwaddr *phys_ptr, + MemTxAttrs *txattrs, int *prot, + target_ulong *page_size_ptr, + ARMMMUFaultInfo *fi, ARMCacheAttrs *cacheat= trs) + __attribute__((nonnull)); + +static bool regime_translation_big_endian(CPUARMState *env, ARMMMUIdx mmu_= idx) +{ + return (regime_sctlr(env, mmu_idx) & SCTLR_EE) !=3D 0; +} + +static bool ptw_attrs_are_device(CPUARMState *env, ARMCacheAttrs cacheattr= s) +{ + /* + * For an S1 page table walk, the stage 1 attributes are always + * some form of "this is Normal memory". The combined S1+S2 + * attributes are therefore only Device if stage 2 specifies Device. + * With HCR_EL2.FWB =3D=3D 0 this is when descriptor bits [5:4] are 0b= 00, + * ie when cacheattrs.attrs bits [3:2] are 0b00. + * With HCR_EL2.FWB =3D=3D 1 this is when descriptor bit [4] is 0, ie + * when cacheattrs.attrs bit [2] is 0. + */ + assert(cacheattrs.is_s2_format); + if (arm_hcr_el2_eff(env) & HCR_FWB) { + return (cacheattrs.attrs & 0x4) =3D=3D 0; + } else { + return (cacheattrs.attrs & 0xc) =3D=3D 0; + } +} + +/* Translate a S1 pagetable walk through S2 if needed. */ +static hwaddr S1_ptw_translate(CPUARMState *env, ARMMMUIdx mmu_idx, + hwaddr addr, bool *is_secure, + ARMMMUFaultInfo *fi) +{ + if (arm_mmu_idx_is_stage1_of_2(mmu_idx) && + !regime_translation_disabled(env, ARMMMUIdx_Stage2)) { + target_ulong s2size; + hwaddr s2pa; + int s2prot; + int ret; + ARMMMUIdx s2_mmu_idx =3D *is_secure ? ARMMMUIdx_Stage2_S + : ARMMMUIdx_Stage2; + ARMCacheAttrs cacheattrs =3D {}; + MemTxAttrs txattrs =3D {}; + + ret =3D get_phys_addr_lpae(env, addr, MMU_DATA_LOAD, s2_mmu_idx, f= alse, + &s2pa, &txattrs, &s2prot, &s2size, fi, + &cacheattrs); + if (ret) { + assert(fi->type !=3D ARMFault_None); + fi->s2addr =3D addr; + fi->stage2 =3D true; + fi->s1ptw =3D true; + fi->s1ns =3D !*is_secure; + return ~0; + } + if ((arm_hcr_el2_eff(env) & HCR_PTW) && + ptw_attrs_are_device(env, cacheattrs)) { + /* + * PTW set and S1 walk touched S2 Device memory: + * generate Permission fault. + */ + fi->type =3D ARMFault_Permission; + fi->s2addr =3D addr; + fi->stage2 =3D true; + fi->s1ptw =3D true; + fi->s1ns =3D !*is_secure; + return ~0; + } + + if (arm_is_secure_below_el3(env)) { + /* Check if page table walk is to secure or non-secure PA spac= e. */ + if (*is_secure) { + *is_secure =3D !(env->cp15.vstcr_el2.raw_tcr & VSTCR_SW); + } else { + *is_secure =3D !(env->cp15.vtcr_el2.raw_tcr & VTCR_NSW); + } + } else { + assert(!*is_secure); + } + + addr =3D s2pa; + } + return addr; +} + +/* All loads done in the course of a page table walk go through here. */ +static uint32_t arm_ldl_ptw(CPUState *cs, hwaddr addr, bool is_secure, + ARMMMUIdx mmu_idx, ARMMMUFaultInfo *fi) +{ + ARMCPU *cpu =3D ARM_CPU(cs); + CPUARMState *env =3D &cpu->env; + MemTxAttrs attrs =3D {}; + MemTxResult result =3D MEMTX_OK; + AddressSpace *as; + uint32_t data; + + addr =3D S1_ptw_translate(env, mmu_idx, addr, &is_secure, fi); + attrs.secure =3D is_secure; + as =3D arm_addressspace(cs, attrs); + if (fi->s1ptw) { + return 0; + } + if (regime_translation_big_endian(env, mmu_idx)) { + data =3D address_space_ldl_be(as, addr, attrs, &result); + } else { + data =3D address_space_ldl_le(as, addr, attrs, &result); + } + if (result =3D=3D MEMTX_OK) { + return data; + } + fi->type =3D ARMFault_SyncExternalOnWalk; + fi->ea =3D arm_extabort_type(result); + return 0; +} + +static uint64_t arm_ldq_ptw(CPUState *cs, hwaddr addr, bool is_secure, + ARMMMUIdx mmu_idx, ARMMMUFaultInfo *fi) +{ + ARMCPU *cpu =3D ARM_CPU(cs); + CPUARMState *env =3D &cpu->env; + MemTxAttrs attrs =3D {}; + MemTxResult result =3D MEMTX_OK; + AddressSpace *as; + uint64_t data; + + addr =3D S1_ptw_translate(env, mmu_idx, addr, &is_secure, fi); + attrs.secure =3D is_secure; + as =3D arm_addressspace(cs, attrs); + if (fi->s1ptw) { + return 0; + } + if (regime_translation_big_endian(env, mmu_idx)) { + data =3D address_space_ldq_be(as, addr, attrs, &result); + } else { + data =3D address_space_ldq_le(as, addr, attrs, &result); + } + if (result =3D=3D MEMTX_OK) { + return data; + } + fi->type =3D ARMFault_SyncExternalOnWalk; + fi->ea =3D arm_extabort_type(result); + return 0; +} + static bool get_level1_table_address(CPUARMState *env, ARMMMUIdx mmu_idx, uint32_t *table, uint32_t address) { @@ -338,12 +486,12 @@ do_fault: * @fi: set to fault info if the translation fails * @cacheattrs: (if non-NULL) set to the cacheability/shareability attribu= tes */ -bool get_phys_addr_lpae(CPUARMState *env, uint64_t address, - MMUAccessType access_type, ARMMMUIdx mmu_idx, - bool s1_is_el0, - hwaddr *phys_ptr, MemTxAttrs *txattrs, int *prot, - target_ulong *page_size_ptr, - ARMMMUFaultInfo *fi, ARMCacheAttrs *cacheattrs) +static bool get_phys_addr_lpae(CPUARMState *env, uint64_t address, + MMUAccessType access_type, ARMMMUIdx mmu_id= x, + bool s1_is_el0, hwaddr *phys_ptr, + MemTxAttrs *txattrs, int *prot, + target_ulong *page_size_ptr, + ARMMMUFaultInfo *fi, ARMCacheAttrs *cacheat= trs) { ARMCPU *cpu =3D env_archcpu(env); CPUState *cs =3D CPU(cpu); --=20 2.34.1 From nobody Fri May 17 05:50:22 2024 Delivered-To: importer@patchew.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1654316865931102.34720041789069; Fri, 3 Jun 2022 21:27:45 -0700 (PDT) Received: from localhost ([::1]:56672 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nxLO4-0003PG-Nl for importer@patchew.org; Sat, 04 Jun 2022 00:27:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36988) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nxL3U-00089P-JG for qemu-devel@nongnu.org; Sat, 04 Jun 2022 00:06:28 -0400 Received: from mail-pj1-x102f.google.com ([2607:f8b0:4864:20::102f]:34444) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nxL3S-00008v-6a for qemu-devel@nongnu.org; Sat, 04 Jun 2022 00:06:28 -0400 Received: by mail-pj1-x102f.google.com with SMTP id mh16-20020a17090b4ad000b001e8313301f1so2134065pjb.1 for ; Fri, 03 Jun 2022 21:06:25 -0700 (PDT) Received: from stoup.. ([2602:ae:1547:e101:3286:cc26:3d5e:3f94]) by smtp.gmail.com with ESMTPSA id a37-20020a631a65000000b003c14af50626sm6093779pgm.62.2022.06.03.21.06.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jun 2022 21:06:24 -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=nCpPYzkqKBbtVTXM2HIOkXh0U56y2kxPZvGE1Att9+k=; b=x2Bq1b7BF7ezoCoiQIxx8OO0eEtDzeLKispcxBwXaFoc/qkSOct81dvV2mkZkjvX+t 3sBHrdZukvZGq5LDoXwjdlhd12uRJHwpWgmKgrgOWyKG2XBBl/LXEB518DEzI+lxQeUD VVMsgsN7+WUXEXP7Ax1E+02XotZw4RfgdGD6xNiJe6liTPrUTmsvc6ESfxfG71JG7bGR 2FEKI/N5K25I4zkh/L8ULTGuf5n2Z3B/ShhkN5pTGRy8oiVXQs83X8akiWJtoHus7bTi sB1Fjaht2IbrtywwprYqY4u+RW2/23JVStPjChA6YPyg64rVhF4sj/8PX6LGYchUcxem yDdg== 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=nCpPYzkqKBbtVTXM2HIOkXh0U56y2kxPZvGE1Att9+k=; b=JpXdHZGau6kkZggPGC4q4O/z/JBIbdoYMUBSrbeP2o9oEBT54IZGfAESJQFBWFYfdJ l1SpXdw2FwcMxWznDjTsnpLYbAAEDZO/JqJKMH6NfDSz8HGaX4MS0YoMqfpzscg0F6sf W69JuhBbD/N6F6DliPPTWq+6mY9oOq6DS0v5/KNAA1FaFgmCFydmv2WEu435iSvKzPOV bA+msowUonWU9OfkPLelQfVAAs/56U4h8fdh6AP0y33mg7aSn5Vkt0UxRohRpBRMe+UN C8gYuCK0aMCRsrk69nmkh34PBkfgAU32Wj7/m42XPYhZ+uyDB7Rd6VPMc47aqeLAWZQE ShMQ== X-Gm-Message-State: AOAM532ZAHp5TbZtz6sYaPdBiuMDwe395sXyaGns+j96VW+QPp1o+/0H RY97w26SM7FwQNRFtI56Nf8xraCFrA5z9A== X-Google-Smtp-Source: ABdhPJyVlWteZvtTX4+EvbjpFhKGrzz724mYzxGJ7RI/1/PBMkiBrUt1YUIkNzALnl8PPLYPsaitSQ== X-Received: by 2002:a17:90a:6fc2:b0:1e3:2c21:c29f with SMTP id e60-20020a17090a6fc200b001e32c21c29fmr26608580pjk.191.1654315584979; Fri, 03 Jun 2022 21:06:24 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Subject: [PATCH 17/28] target/arm: Move {arm_s1_, }regime_using_lpae_format to tlb_helper.c Date: Fri, 3 Jun 2022 21:05:56 -0700 Message-Id: <20220604040607.269301-18-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220604040607.269301-1-richard.henderson@linaro.org> References: <20220604040607.269301-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=2607:f8b0:4864:20::102f; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102f.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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1654316867440100001 Content-Type: text/plain; charset="utf-8" These functions are used for both page table walking and for deciding what format in which to deliver exception results. Since ptw.c is only present for system mode, put the functions into tlb_helper.c. Signed-off-by: Richard Henderson --- target/arm/helper.c | 24 ------------------------ target/arm/tlb_helper.c | 26 ++++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/target/arm/helper.c b/target/arm/helper.c index f6931237fe..4ed2093acf 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -10479,30 +10479,6 @@ ARMMMUIdx stage_1_mmu_idx(ARMMMUIdx mmu_idx) } #endif /* !CONFIG_USER_ONLY */ =20 -/* Return true if the translation regime is using LPAE format page tables = */ -bool regime_using_lpae_format(CPUARMState *env, ARMMMUIdx mmu_idx) -{ - int el =3D regime_el(env, mmu_idx); - if (el =3D=3D 2 || arm_el_is_aa64(env, el)) { - return true; - } - if (arm_feature(env, ARM_FEATURE_LPAE) - && (regime_tcr(env, mmu_idx)->raw_tcr & TTBCR_EAE)) { - return true; - } - return false; -} - -/* Returns true if the stage 1 translation regime is using LPAE format page - * tables. Used when raising alignment exceptions, whose FSR changes depen= ding - * on whether the long or short descriptor format is in use. */ -bool arm_s1_regime_using_lpae_format(CPUARMState *env, ARMMMUIdx mmu_idx) -{ - mmu_idx =3D stage_1_mmu_idx(mmu_idx); - - return regime_using_lpae_format(env, mmu_idx); -} - #ifndef CONFIG_USER_ONLY bool regime_is_user(CPUARMState *env, ARMMMUIdx mmu_idx) { diff --git a/target/arm/tlb_helper.c b/target/arm/tlb_helper.c index 6421e16202..7d8a86b3c4 100644 --- a/target/arm/tlb_helper.c +++ b/target/arm/tlb_helper.c @@ -11,6 +11,32 @@ #include "exec/exec-all.h" #include "exec/helper-proto.h" =20 + +/* Return true if the translation regime is using LPAE format page tables = */ +bool regime_using_lpae_format(CPUARMState *env, ARMMMUIdx mmu_idx) +{ + int el =3D regime_el(env, mmu_idx); + if (el =3D=3D 2 || arm_el_is_aa64(env, el)) { + return true; + } + if (arm_feature(env, ARM_FEATURE_LPAE) + && (regime_tcr(env, mmu_idx)->raw_tcr & TTBCR_EAE)) { + return true; + } + return false; +} + +/* + * Returns true if the stage 1 translation regime is using LPAE format page + * tables. Used when raising alignment exceptions, whose FSR changes depen= ding + * on whether the long or short descriptor format is in use. + */ +bool arm_s1_regime_using_lpae_format(CPUARMState *env, ARMMMUIdx mmu_idx) +{ + mmu_idx =3D stage_1_mmu_idx(mmu_idx); + return regime_using_lpae_format(env, mmu_idx); +} + static inline uint32_t merge_syn_data_abort(uint32_t template_syn, unsigned int target_el, bool same_el, bool ea, --=20 2.34.1 From nobody Fri May 17 05:50:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1654317072; cv=none; d=zohomail.com; s=zohoarc; b=ZW9gO5IeXGAiSL4daNktFIHtwlbM9TZoqHrhJixkEQWm/xqADyVcXxjse7pZhAZexcn14YR5HWnVSSiFeG/Xhjw8Ni15Rkn00q4pkKzZoOZXTVGZRfXD/yjISb5ZZFwUJUt9P5DVLU0ARKuS/bsdugwHZJvr2n11vha9w+tUDGM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1654317072; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=qkd0B4g6jM3nkL28VlmdmN6+46UTMQek41TjlfeZ+tg=; b=jzyPJoL7dBUgXJEO2MsBszfMNp5lNv3ttYakkSuFrKWIcMjZmhLdTWBQxp0bC6kpbO0wSiufTDX4okr2qgCmb0s49bhTGdgt6DyM93hkxNaisTXNTLj13qrYTmDFSpOZzDK9kyQdyZqtUYFzNa0V55QGNzjw+dMykoSqIE/w/N0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1654317072781229.57958710215394; Fri, 3 Jun 2022 21:31:12 -0700 (PDT) Received: from localhost ([::1]:34766 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nxLRP-0007lN-Iq for importer@patchew.org; Sat, 04 Jun 2022 00:31:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36996) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nxL3V-0008BF-0u for qemu-devel@nongnu.org; Sat, 04 Jun 2022 00:06:29 -0400 Received: from mail-pj1-x1036.google.com ([2607:f8b0:4864:20::1036]:50691) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nxL3S-0008V4-Hc for qemu-devel@nongnu.org; Sat, 04 Jun 2022 00:06:28 -0400 Received: by mail-pj1-x1036.google.com with SMTP id e24so8741524pjt.0 for ; Fri, 03 Jun 2022 21:06:26 -0700 (PDT) Received: from stoup.. ([2602:ae:1547:e101:3286:cc26:3d5e:3f94]) by smtp.gmail.com with ESMTPSA id a37-20020a631a65000000b003c14af50626sm6093779pgm.62.2022.06.03.21.06.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jun 2022 21:06:25 -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=qkd0B4g6jM3nkL28VlmdmN6+46UTMQek41TjlfeZ+tg=; b=QKfnAh48w/6pL2qxSb4QBEVbra2oS9p4L4Ckt3nlLJ9YZC+50zh/86TlIow5GGanHY ORV87jwPPI/XavX/yPqLgto6PIbHKp4T0yTPqReRyBhRqYAaO3q1ojmRb5YMKSFUIuBf jgT01XeGP8FOaJFIWXaY178Qmxgk8AAn/Xs6VsAMxKH+nKqdoHIscYvq1HLIp4CQL4q2 R8J8NF1ijCno+XeK4QQDWzDEIFTeOmFTlaLCmcQo15k1F/IwaQKL19XoNMklWK5/XlcB qpGaN0dZ638ZdD9rR7WV3tivf/CDNVLVo8CgOC2kJqS0M6qo0vu15dhbZieLzQTKkpg1 dPCw== 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=qkd0B4g6jM3nkL28VlmdmN6+46UTMQek41TjlfeZ+tg=; b=AByWfONLYwWnkHN6otY33b80uxX0O5u51CQVU5C9+fgF3FDIUOh0gIOj6COx4A3A6e eCMJpE61NAMptrP6sNyl0AvlHW1ZtdiCsb3yDaAxuC79mM6KrUhbAroQkT76jc99L6Ul QyC2YYu8rkm/JMq/veD4L+o/phqLC5iCHYFhnEvZVhLPiafr5yE5Qd82oV/YASSPaDgf G1pPlLD3x9PWUIEE/QF29whcOoH/SaJZsmDmrEpwXo7DCjChGTiEMMCJpelXt63lKQl+ lV4ounpK54HHUZvS38ePFQnHysCKZodtfdgb2T66AoW3Nvc/6hm4Y5p/W6ca+iDePcvb lPPw== X-Gm-Message-State: AOAM533cRCD3F90OXWM/eZB5YC+1Jy8QjE/cXDoXfmLtUoTy6dbeux87 L4hG0RNKTzfByBqa24LNscLtvJnyoglR5A== X-Google-Smtp-Source: ABdhPJxuxxoCIAhKZhPjCWxqcTRWPBoJ4Wo9qqhjJQuBM2ExqE1YgUVrQuRdZ0VKb8wHHVX/MgNnTg== X-Received: by 2002:a17:902:a507:b0:162:2a77:7363 with SMTP id s7-20020a170902a50700b001622a777363mr13336670plq.115.1654315585767; Fri, 03 Jun 2022 21:06:25 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Subject: [PATCH 18/28] target/arm: Move arm_pamax, pamax_map into ptw.c Date: Fri, 3 Jun 2022 21:05:57 -0700 Message-Id: <20220604040607.269301-19-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220604040607.269301-1-richard.henderson@linaro.org> References: <20220604040607.269301-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=2607:f8b0:4864:20::1036; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1036.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=ham 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1654317074278100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Richard Henderson --- target/arm/ptw.h | 2 -- target/arm/helper.c | 25 ------------------------- target/arm/ptw.c | 25 +++++++++++++++++++++++++ 3 files changed, 25 insertions(+), 27 deletions(-) diff --git a/target/arm/ptw.h b/target/arm/ptw.h index 28b8cb9fb8..fba650d01c 100644 --- a/target/arm/ptw.h +++ b/target/arm/ptw.h @@ -11,8 +11,6 @@ =20 #ifndef CONFIG_USER_ONLY =20 -extern const uint8_t pamax_map[7]; - bool regime_is_user(CPUARMState *env, ARMMMUIdx mmu_idx); bool regime_translation_disabled(CPUARMState *env, ARMMMUIdx mmu_idx); uint64_t regime_ttbr(CPUARMState *env, ARMMMUIdx mmu_idx, int ttbrn); diff --git a/target/arm/helper.c b/target/arm/helper.c index 4ed2093acf..001d632cd1 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -10778,31 +10778,6 @@ bool check_s2_mmu_setup(ARMCPU *cpu, bool is_aa64,= int level, } #endif /* !CONFIG_USER_ONLY */ =20 -/* This mapping is common between ID_AA64MMFR0.PARANGE and TCR_ELx.{I}PS. = */ -const uint8_t pamax_map[] =3D { - [0] =3D 32, - [1] =3D 36, - [2] =3D 40, - [3] =3D 42, - [4] =3D 44, - [5] =3D 48, - [6] =3D 52, -}; - -/* The cpu-specific constant value of PAMax; also used by hw/arm/virt. */ -unsigned int arm_pamax(ARMCPU *cpu) -{ - unsigned int parange =3D - FIELD_EX64(cpu->isar.id_aa64mmfr0, ID_AA64MMFR0, PARANGE); - - /* - * id_aa64mmfr0 is a read-only register so values outside of the - * supported mappings can be considered an implementation error. - */ - assert(parange < ARRAY_SIZE(pamax_map)); - return pamax_map[parange]; -} - int aa64_va_parameter_tbi(uint64_t tcr, ARMMMUIdx mmu_idx) { if (regime_has_2_ranges(mmu_idx)) { diff --git a/target/arm/ptw.c b/target/arm/ptw.c index e4b860d2ae..d754273fa1 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -23,6 +23,31 @@ static bool get_phys_addr_lpae(CPUARMState *env, uint64_= t address, ARMMMUFaultInfo *fi, ARMCacheAttrs *cacheat= trs) __attribute__((nonnull)); =20 +/* This mapping is common between ID_AA64MMFR0.PARANGE and TCR_ELx.{I}PS. = */ +static const uint8_t pamax_map[] =3D { + [0] =3D 32, + [1] =3D 36, + [2] =3D 40, + [3] =3D 42, + [4] =3D 44, + [5] =3D 48, + [6] =3D 52, +}; + +/* The cpu-specific constant value of PAMax; also used by hw/arm/virt. */ +unsigned int arm_pamax(ARMCPU *cpu) +{ + unsigned int parange =3D + FIELD_EX64(cpu->isar.id_aa64mmfr0, ID_AA64MMFR0, PARANGE); + + /* + * id_aa64mmfr0 is a read-only register so values outside of the + * supported mappings can be considered an implementation error. + */ + assert(parange < ARRAY_SIZE(pamax_map)); + return pamax_map[parange]; +} + static bool regime_translation_big_endian(CPUARMState *env, ARMMMUIdx mmu_= idx) { return (regime_sctlr(env, mmu_idx) & SCTLR_EE) !=3D 0; --=20 2.34.1 From nobody Fri May 17 05:50:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1654317444; cv=none; d=zohomail.com; s=zohoarc; b=SemsLzuuLtVpvWL1/GcZyH3r6fe4dUrHRF+/KvV1Z0AVGyXDqSSJBO0jSmwMEsFN+FjGqXN6GfFKVHkPZmZ4Hh/W7PjbOHHJBwCtNosrsXeLFeNbUgkUqZ03fSgrvrc2nnVcT3IJUMh7j3SZK5SvvenMjw2ajmDuck1sPaJRVsY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1654317444; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=wtKVh+cEc+jGez4qiMWVy6WVEeDNoJJFBFME/IY/n24=; b=mnHt2o40womn/L9pX7zpFzgaNyrhg/VY0WDTpBdgn2Sa/23+2dvXQ8DD/Uajfpi/vJqqCWOkrHyl70AnBxzk9Paa+4X/tgv55YH2G2li/OX5CDtuPZgxRey6MvB2U90ezare1CcD7F9oQuVu872Qw0DtD27orwJf39ytgEZTAw4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1654317444503547.7789341311411; Fri, 3 Jun 2022 21:37:24 -0700 (PDT) Received: from localhost ([::1]:42430 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nxLXP-0004mz-0i for importer@patchew.org; Sat, 04 Jun 2022 00:37:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37062) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nxL3W-0008Hs-GQ for qemu-devel@nongnu.org; Sat, 04 Jun 2022 00:06:30 -0400 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]:54154) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nxL3T-00009X-Rb for qemu-devel@nongnu.org; Sat, 04 Jun 2022 00:06:30 -0400 Received: by mail-pj1-x102c.google.com with SMTP id a10so8694956pju.3 for ; Fri, 03 Jun 2022 21:06:27 -0700 (PDT) Received: from stoup.. ([2602:ae:1547:e101:3286:cc26:3d5e:3f94]) by smtp.gmail.com with ESMTPSA id a37-20020a631a65000000b003c14af50626sm6093779pgm.62.2022.06.03.21.06.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jun 2022 21:06:26 -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=wtKVh+cEc+jGez4qiMWVy6WVEeDNoJJFBFME/IY/n24=; b=vXHXbEtbbcFjNjtLusPGZ+lJ53Ls5ucgvBDL9LCYemaqD6CAIRofxIl9rnmZt2FwEq Ifxp/1WVy4bZBALf0gbwM+7P5GU2/iCvdBz0IH0zT2s056VTrhw2VG5LgHWMn09C0SCz GimxSx+9iurXEw3rfS0+ea26BZolCVTh4azAyEO7hRiKnCji2NhPMK4sfqY8Jo5aNmdw KYLxMgLyBeIRTx5rYRPp3mAKVSYtpaGPcomMmzHOWv+5m5lQWOp/8FyMbrZ8Gd0q7hqy Wqy9Y786FBKValYITF2rRKl0FxOkjWf+NPeMMtSctj6C0C38VZOeZGltZy03rKpGla0k CIMA== 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=wtKVh+cEc+jGez4qiMWVy6WVEeDNoJJFBFME/IY/n24=; b=p5Fv0WZEf5vbkfA3SVj8JXUTFzwgTwtR3iacK3ie7lTvAO0+bJMKxf78vdVVpuos7y ZHMHo88ZnRoEgxAhXde5Erq3tbjadUhY/59qagpYzzV3LNmAmwZA3Xm5TuEic5RsoJaj 1AM2al692AxO6GEZxki/zaIFfvnn5Gu0B1YHBzRnX2gOC6TN1cunimAWPyXxLdNp4uSX 16IKgxyCLIqm39QqII4hyYkpGyBs46IEXL7UJF+1WZQvesjWBIzZZWMNdfvi/YqfTOKP KVYWIP4njG78oMasTqQ0cMoHhTY+8VpXnWI3Fk/RtLyGXXZ7ykTylKMPtFMPFmSQnlZI igvg== X-Gm-Message-State: AOAM531eSrRzGTHndw2bjPeaEhNWEYdM1FzIydMi+X4wbbDW1yUxIvYF LJ6OWiZjT9c3+s6zOCPw7yEHPt6vmJw4Dw== X-Google-Smtp-Source: ABdhPJy82ObSwVifuRhu1GYSA1e405DJshovxy4QzM6zN7y3JFWmN31CXm/veayRZnNe8GYFNPXRTg== X-Received: by 2002:a17:90b:4a4c:b0:1e4:dcfc:e688 with SMTP id lb12-20020a17090b4a4c00b001e4dcfce688mr18753413pjb.38.1654315586483; Fri, 03 Jun 2022 21:06:26 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Subject: [PATCH 19/28] target/arm: Move get_S1prot, get_S2prot to ptw.c Date: Fri, 3 Jun 2022 21:05:58 -0700 Message-Id: <20220604040607.269301-20-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220604040607.269301-1-richard.henderson@linaro.org> References: <20220604040607.269301-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=2607:f8b0:4864:20::102c; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102c.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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1654317446058100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Richard Henderson --- target/arm/ptw.h | 3 -- target/arm/helper.c | 128 -------------------------------------------- target/arm/ptw.c | 128 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 128 insertions(+), 131 deletions(-) diff --git a/target/arm/ptw.h b/target/arm/ptw.h index fba650d01c..93147e0b06 100644 --- a/target/arm/ptw.h +++ b/target/arm/ptw.h @@ -29,9 +29,6 @@ ARMVAParameters aa32_va_parameters(CPUARMState *env, uint= 32_t va, ARMMMUIdx mmu_idx); bool check_s2_mmu_setup(ARMCPU *cpu, bool is_aa64, int level, int inputsize, int stride, int outputsize); -int get_S2prot(CPUARMState *env, int s2ap, int xn, bool s1_is_el0); -int get_S1prot(CPUARMState *env, ARMMMUIdx mmu_idx, bool is_aa64, - int ap, int ns, int xn, int pxn); =20 #endif /* !CONFIG_USER_ONLY */ #endif /* TARGET_ARM_PTW_H */ diff --git a/target/arm/helper.c b/target/arm/helper.c index 001d632cd1..7aadc6eeb9 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -10579,134 +10579,6 @@ int simple_ap_to_rw_prot_is_user(int ap, bool is_= user) } } =20 -/* Translate S2 section/page access permissions to protection flags - * - * @env: CPUARMState - * @s2ap: The 2-bit stage2 access permissions (S2AP) - * @xn: XN (execute-never) bits - * @s1_is_el0: true if this is S2 of an S1+2 walk for EL0 - */ -int get_S2prot(CPUARMState *env, int s2ap, int xn, bool s1_is_el0) -{ - int prot =3D 0; - - if (s2ap & 1) { - prot |=3D PAGE_READ; - } - if (s2ap & 2) { - prot |=3D PAGE_WRITE; - } - - if (cpu_isar_feature(any_tts2uxn, env_archcpu(env))) { - switch (xn) { - case 0: - prot |=3D PAGE_EXEC; - break; - case 1: - if (s1_is_el0) { - prot |=3D PAGE_EXEC; - } - break; - case 2: - break; - case 3: - if (!s1_is_el0) { - prot |=3D PAGE_EXEC; - } - break; - default: - g_assert_not_reached(); - } - } else { - if (!extract32(xn, 1, 1)) { - if (arm_el_is_aa64(env, 2) || prot & PAGE_READ) { - prot |=3D PAGE_EXEC; - } - } - } - return prot; -} - -/* Translate section/page access permissions to protection flags - * - * @env: CPUARMState - * @mmu_idx: MMU index indicating required translation regime - * @is_aa64: TRUE if AArch64 - * @ap: The 2-bit simple AP (AP[2:1]) - * @ns: NS (non-secure) bit - * @xn: XN (execute-never) bit - * @pxn: PXN (privileged execute-never) bit - */ -int get_S1prot(CPUARMState *env, ARMMMUIdx mmu_idx, bool is_aa64, - int ap, int ns, int xn, int pxn) -{ - bool is_user =3D regime_is_user(env, mmu_idx); - int prot_rw, user_rw; - bool have_wxn; - int wxn =3D 0; - - assert(mmu_idx !=3D ARMMMUIdx_Stage2); - assert(mmu_idx !=3D ARMMMUIdx_Stage2_S); - - user_rw =3D simple_ap_to_rw_prot_is_user(ap, true); - if (is_user) { - prot_rw =3D user_rw; - } else { - if (user_rw && regime_is_pan(env, mmu_idx)) { - /* PAN forbids data accesses but doesn't affect insn fetch */ - prot_rw =3D 0; - } else { - prot_rw =3D simple_ap_to_rw_prot_is_user(ap, false); - } - } - - if (ns && arm_is_secure(env) && (env->cp15.scr_el3 & SCR_SIF)) { - return prot_rw; - } - - /* TODO have_wxn should be replaced with - * ARM_FEATURE_V8 || (ARM_FEATURE_V7 && ARM_FEATURE_EL2) - * when ARM_FEATURE_EL2 starts getting set. For now we assume all LPAE - * compatible processors have EL2, which is required for [U]WXN. - */ - have_wxn =3D arm_feature(env, ARM_FEATURE_LPAE); - - if (have_wxn) { - wxn =3D regime_sctlr(env, mmu_idx) & SCTLR_WXN; - } - - if (is_aa64) { - if (regime_has_2_ranges(mmu_idx) && !is_user) { - xn =3D pxn || (user_rw & PAGE_WRITE); - } - } else if (arm_feature(env, ARM_FEATURE_V7)) { - switch (regime_el(env, mmu_idx)) { - case 1: - case 3: - if (is_user) { - xn =3D xn || !(user_rw & PAGE_READ); - } else { - int uwxn =3D 0; - if (have_wxn) { - uwxn =3D regime_sctlr(env, mmu_idx) & SCTLR_UWXN; - } - xn =3D xn || !(prot_rw & PAGE_READ) || pxn || - (uwxn && (user_rw & PAGE_WRITE)); - } - break; - case 2: - break; - } - } else { - xn =3D wxn =3D 0; - } - - if (xn || (wxn && (prot_rw & PAGE_WRITE))) { - return prot_rw; - } - return prot_rw | PAGE_EXEC; -} - /* * check_s2_mmu_setup * @cpu: ARMCPU diff --git a/target/arm/ptw.c b/target/arm/ptw.c index d754273fa1..af9ad42028 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -487,6 +487,134 @@ do_fault: return true; } =20 +/* + * Translate S2 section/page access permissions to protection flags + * @env: CPUARMState + * @s2ap: The 2-bit stage2 access permissions (S2AP) + * @xn: XN (execute-never) bits + * @s1_is_el0: true if this is S2 of an S1+2 walk for EL0 + */ +static int get_S2prot(CPUARMState *env, int s2ap, int xn, bool s1_is_el0) +{ + int prot =3D 0; + + if (s2ap & 1) { + prot |=3D PAGE_READ; + } + if (s2ap & 2) { + prot |=3D PAGE_WRITE; + } + + if (cpu_isar_feature(any_tts2uxn, env_archcpu(env))) { + switch (xn) { + case 0: + prot |=3D PAGE_EXEC; + break; + case 1: + if (s1_is_el0) { + prot |=3D PAGE_EXEC; + } + break; + case 2: + break; + case 3: + if (!s1_is_el0) { + prot |=3D PAGE_EXEC; + } + break; + default: + g_assert_not_reached(); + } + } else { + if (!extract32(xn, 1, 1)) { + if (arm_el_is_aa64(env, 2) || prot & PAGE_READ) { + prot |=3D PAGE_EXEC; + } + } + } + return prot; +} + +/* + * Translate section/page access permissions to protection flags + * @env: CPUARMState + * @mmu_idx: MMU index indicating required translation regime + * @is_aa64: TRUE if AArch64 + * @ap: The 2-bit simple AP (AP[2:1]) + * @ns: NS (non-secure) bit + * @xn: XN (execute-never) bit + * @pxn: PXN (privileged execute-never) bit + */ +static int get_S1prot(CPUARMState *env, ARMMMUIdx mmu_idx, bool is_aa64, + int ap, int ns, int xn, int pxn) +{ + bool is_user =3D regime_is_user(env, mmu_idx); + int prot_rw, user_rw; + bool have_wxn; + int wxn =3D 0; + + assert(mmu_idx !=3D ARMMMUIdx_Stage2); + assert(mmu_idx !=3D ARMMMUIdx_Stage2_S); + + user_rw =3D simple_ap_to_rw_prot_is_user(ap, true); + if (is_user) { + prot_rw =3D user_rw; + } else { + if (user_rw && regime_is_pan(env, mmu_idx)) { + /* PAN forbids data accesses but doesn't affect insn fetch */ + prot_rw =3D 0; + } else { + prot_rw =3D simple_ap_to_rw_prot_is_user(ap, false); + } + } + + if (ns && arm_is_secure(env) && (env->cp15.scr_el3 & SCR_SIF)) { + return prot_rw; + } + + /* TODO have_wxn should be replaced with + * ARM_FEATURE_V8 || (ARM_FEATURE_V7 && ARM_FEATURE_EL2) + * when ARM_FEATURE_EL2 starts getting set. For now we assume all LPAE + * compatible processors have EL2, which is required for [U]WXN. + */ + have_wxn =3D arm_feature(env, ARM_FEATURE_LPAE); + + if (have_wxn) { + wxn =3D regime_sctlr(env, mmu_idx) & SCTLR_WXN; + } + + if (is_aa64) { + if (regime_has_2_ranges(mmu_idx) && !is_user) { + xn =3D pxn || (user_rw & PAGE_WRITE); + } + } else if (arm_feature(env, ARM_FEATURE_V7)) { + switch (regime_el(env, mmu_idx)) { + case 1: + case 3: + if (is_user) { + xn =3D xn || !(user_rw & PAGE_READ); + } else { + int uwxn =3D 0; + if (have_wxn) { + uwxn =3D regime_sctlr(env, mmu_idx) & SCTLR_UWXN; + } + xn =3D xn || !(prot_rw & PAGE_READ) || pxn || + (uwxn && (user_rw & PAGE_WRITE)); + } + break; + case 2: + break; + } + } else { + xn =3D wxn =3D 0; + } + + if (xn || (wxn && (prot_rw & PAGE_WRITE))) { + return prot_rw; + } + return prot_rw | PAGE_EXEC; +} + /** * get_phys_addr_lpae: perform one stage of page table walk, LPAE format * --=20 2.34.1 From nobody Fri May 17 05:50:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1654317731; cv=none; d=zohomail.com; s=zohoarc; b=mA5h3gp1bCPYgz6Gn9RJOmdtSFDDqKmJ73yX7Nlwt2MElSiwoig2nLS9rm6kRREgZ3YVXv3BgAYO7X8votLiOp8M1MdShBd0UajfE6msIH4dVEPYPNU/yBX9AWqGv+p3N47VqeLvJ0vtpww+ijBQrtqph/Iyk8r/Kfz0R0VyZ0o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1654317731; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=wKwxgmTTnQp5W/CZg2mnGE7auUJpNoW6/0mxrOpi9ls=; b=YyUyE6PbYp7hM8HemasAsCiLQ/UpMvsYtUPeUaP6GWxOKSwpOP2iZ5xevLSJWd8FvwUtFtoKIV+x7TxUMWF70RKOC7o1Y7Z2xzkn6hLN15Y+uJXJ4WoEYHCD7Q3Okpu9kmnQnvUnfxvM7t0ZPd9iaQGZwGWeun8Xigtgzw2x4uI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1654317730925654.0918848980351; Fri, 3 Jun 2022 21:42:10 -0700 (PDT) Received: from localhost ([::1]:49092 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nxLc1-0000w7-PO for importer@patchew.org; Sat, 04 Jun 2022 00:42:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37066) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nxL3W-0008I9-LC for qemu-devel@nongnu.org; Sat, 04 Jun 2022 00:06:30 -0400 Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]:36412) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nxL3U-00005b-6z for qemu-devel@nongnu.org; Sat, 04 Jun 2022 00:06:30 -0400 Received: by mail-pj1-x1035.google.com with SMTP id u12-20020a17090a1d4c00b001df78c7c209so13537362pju.1 for ; Fri, 03 Jun 2022 21:06:27 -0700 (PDT) Received: from stoup.. ([2602:ae:1547:e101:3286:cc26:3d5e:3f94]) by smtp.gmail.com with ESMTPSA id a37-20020a631a65000000b003c14af50626sm6093779pgm.62.2022.06.03.21.06.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jun 2022 21:06:26 -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=wKwxgmTTnQp5W/CZg2mnGE7auUJpNoW6/0mxrOpi9ls=; b=jltRyuAND+N1NSRUviNYNAQ12GjK7A+EjLxjC+donEQ//VD9E+Rr+ularAWcS3PUDg q4FPtpVSn7hxtIEgumtVaO4+WSQfoP63IG1KKGWinvufSGqLpVGMFt8Fm/jQmDGSA43m MSdTXCHVWMwJspAZK5Q/0fREYU97e9WlsBUknEwjX8nzweL5SP1nV/npWRZJN0mRK1E2 xV9wY0YRjDPn/EEgEjCg3xF2Qo3xxz4DE753hjoosR75+9CZQP3NhG4s1Rq54/oWRigV /lK9rNjMs5zVjT3/47vaEFThyPjbaSnCUpEVTNJEV521O6cfGV7jxw5M8hbe9lgHNMAK PdXg== 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=wKwxgmTTnQp5W/CZg2mnGE7auUJpNoW6/0mxrOpi9ls=; b=VnOHTFEWwpn0DYrfcvwioFibQ8N1nXVAONL9Wsh7hA4PNdiD21CmNXOido02Z3lmJJ 6LUXvhXhTvscmfSRhvuCsTsddUzxm5ucbMvBQ2HfYxBikyq2Ki+lBI5uA2KetDTCXGiU c2BYC6vyWIivk5jU37az+x+fqQrGOpwdlDeFOI2N5kzaYAJuX3a8I/OOf9hLTzdulCDi LLVE63Ja28iNEcEsF7pX9qEAgoA8UvF9k2noueXdwCiKOicEoZVcKCPx40rIxo/sEmZt iFZec1Qis8hi4bwfb73XsC0U0+VZOSBr7lHNH+WHNJRtcnBgqY8ymjVI2v4Tf+Oqygm5 elsw== X-Gm-Message-State: AOAM533c/CgtLdzSARLpCTma9NnJoWPuaVVwlwJSDG4Y21RHB6Q3omag YNcFikSk5Goi+Bn/PvJFpZQtBlcnNsvFRQ== X-Google-Smtp-Source: ABdhPJx0vdZdhJx9g2H1TCvl1kkfv0RcyqiLwDspKR4XNaItQcExvPUcz+yWKYHGdAmaeXJ4kk1P6g== X-Received: by 2002:a17:902:cec5:b0:166:3418:5260 with SMTP id d5-20020a170902cec500b0016634185260mr13053523plg.129.1654315587334; Fri, 03 Jun 2022 21:06:27 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Subject: [PATCH 20/28] target/arm: Move check_s2_mmu_setup to ptw.c Date: Fri, 3 Jun 2022 21:05:59 -0700 Message-Id: <20220604040607.269301-21-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220604040607.269301-1-richard.henderson@linaro.org> References: <20220604040607.269301-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=2607:f8b0:4864:20::1035; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1035.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=ham 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1654317731586100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Richard Henderson --- target/arm/ptw.h | 2 -- target/arm/helper.c | 70 --------------------------------------------- target/arm/ptw.c | 70 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 72 deletions(-) diff --git a/target/arm/ptw.h b/target/arm/ptw.h index 93147e0b06..a71161b01b 100644 --- a/target/arm/ptw.h +++ b/target/arm/ptw.h @@ -27,8 +27,6 @@ simple_ap_to_rw_prot(CPUARMState *env, ARMMMUIdx mmu_idx,= int ap) =20 ARMVAParameters aa32_va_parameters(CPUARMState *env, uint32_t va, ARMMMUIdx mmu_idx); -bool check_s2_mmu_setup(ARMCPU *cpu, bool is_aa64, int level, - int inputsize, int stride, int outputsize); =20 #endif /* !CONFIG_USER_ONLY */ #endif /* TARGET_ARM_PTW_H */ diff --git a/target/arm/helper.c b/target/arm/helper.c index 7aadc6eeb9..5dfe1f9cc0 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -10578,76 +10578,6 @@ int simple_ap_to_rw_prot_is_user(int ap, bool is_u= ser) g_assert_not_reached(); } } - -/* - * check_s2_mmu_setup - * @cpu: ARMCPU - * @is_aa64: True if the translation regime is in AArch64 state - * @startlevel: Suggested starting level - * @inputsize: Bitsize of IPAs - * @stride: Page-table stride (See the ARM ARM) - * - * Returns true if the suggested S2 translation parameters are OK and - * false otherwise. - */ -bool check_s2_mmu_setup(ARMCPU *cpu, bool is_aa64, int level, - int inputsize, int stride, int outputsize) -{ - const int grainsize =3D stride + 3; - int startsizecheck; - - /* - * Negative levels are usually not allowed... - * Except for FEAT_LPA2, 4k page table, 52-bit address space, which - * begins with level -1. Note that previous feature tests will have - * eliminated this combination if it is not enabled. - */ - if (level < (inputsize =3D=3D 52 && stride =3D=3D 9 ? -1 : 0)) { - return false; - } - - startsizecheck =3D inputsize - ((3 - level) * stride + grainsize); - if (startsizecheck < 1 || startsizecheck > stride + 4) { - return false; - } - - if (is_aa64) { - switch (stride) { - case 13: /* 64KB Pages. */ - if (level =3D=3D 0 || (level =3D=3D 1 && outputsize <=3D 42)) { - return false; - } - break; - case 11: /* 16KB Pages. */ - if (level =3D=3D 0 || (level =3D=3D 1 && outputsize <=3D 40)) { - return false; - } - break; - case 9: /* 4KB Pages. */ - if (level =3D=3D 0 && outputsize <=3D 42) { - return false; - } - break; - default: - g_assert_not_reached(); - } - - /* Inputsize checks. */ - if (inputsize > outputsize && - (arm_el_is_aa64(&cpu->env, 1) || inputsize > 40)) { - /* This is CONSTRAINED UNPREDICTABLE and we choose to fault. = */ - return false; - } - } else { - /* AArch32 only supports 4KB pages. Assert on that. */ - assert(stride =3D=3D 9); - - if (level =3D=3D 0) { - return false; - } - } - return true; -} #endif /* !CONFIG_USER_ONLY */ =20 int aa64_va_parameter_tbi(uint64_t tcr, ARMMMUIdx mmu_idx) diff --git a/target/arm/ptw.c b/target/arm/ptw.c index af9ad42028..525272e99a 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -615,6 +615,76 @@ static int get_S1prot(CPUARMState *env, ARMMMUIdx mmu_= idx, bool is_aa64, return prot_rw | PAGE_EXEC; } =20 +/* + * check_s2_mmu_setup + * @cpu: ARMCPU + * @is_aa64: True if the translation regime is in AArch64 state + * @startlevel: Suggested starting level + * @inputsize: Bitsize of IPAs + * @stride: Page-table stride (See the ARM ARM) + * + * Returns true if the suggested S2 translation parameters are OK and + * false otherwise. + */ +static bool check_s2_mmu_setup(ARMCPU *cpu, bool is_aa64, int level, + int inputsize, int stride, int outputsize) +{ + const int grainsize =3D stride + 3; + int startsizecheck; + + /* + * Negative levels are usually not allowed... + * Except for FEAT_LPA2, 4k page table, 52-bit address space, which + * begins with level -1. Note that previous feature tests will have + * eliminated this combination if it is not enabled. + */ + if (level < (inputsize =3D=3D 52 && stride =3D=3D 9 ? -1 : 0)) { + return false; + } + + startsizecheck =3D inputsize - ((3 - level) * stride + grainsize); + if (startsizecheck < 1 || startsizecheck > stride + 4) { + return false; + } + + if (is_aa64) { + switch (stride) { + case 13: /* 64KB Pages. */ + if (level =3D=3D 0 || (level =3D=3D 1 && outputsize <=3D 42)) { + return false; + } + break; + case 11: /* 16KB Pages. */ + if (level =3D=3D 0 || (level =3D=3D 1 && outputsize <=3D 40)) { + return false; + } + break; + case 9: /* 4KB Pages. */ + if (level =3D=3D 0 && outputsize <=3D 42) { + return false; + } + break; + default: + g_assert_not_reached(); + } + + /* Inputsize checks. */ + if (inputsize > outputsize && + (arm_el_is_aa64(&cpu->env, 1) || inputsize > 40)) { + /* This is CONSTRAINED UNPREDICTABLE and we choose to fault. = */ + return false; + } + } else { + /* AArch32 only supports 4KB pages. Assert on that. */ + assert(stride =3D=3D 9); + + if (level =3D=3D 0) { + return false; + } + } + return true; +} + /** * get_phys_addr_lpae: perform one stage of page table walk, LPAE format * --=20 2.34.1 From nobody Fri May 17 05:50:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1654318126; cv=none; d=zohomail.com; s=zohoarc; b=jOYI1gqCAjDj6gXyM+AhVh/UKb3X7B01VkNQcYVaIRtLfctaF326HAGnpIIc8i2AHPyROlyXmwT/jZn/fcve7kznGwR4B0bw0BSGtFlp9xDvtI0hmyAYtWHyMfmelrvZs/NA/7VyKq3nt7QX4zACLZwrn9Gf3HaGUbmJGuf6GiY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1654318126; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=6KKo07UAnM87DaMoH4z3hFQneciCBNYbYQZeTrJ63eA=; b=dDQ9BxZwFzZ4Y6BfSqQO3K5GnLTlC2Tg7PsvcgpRFVOV/UHA6EcAl0ZS3Qhq9xfM6Q+TC+3DrlbQleJx6Rh1TGNSczmd3Q691/kCAztHmXYIoOOtdyJA4hEApMMU/u5yyZvrjD0dNvx0InNlRduETq3DIfA1s8C26X7CmUF8yWs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1654318126273294.5121864751027; Fri, 3 Jun 2022 21:48:46 -0700 (PDT) Received: from localhost ([::1]:55552 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nxLiP-0005TG-09 for importer@patchew.org; Sat, 04 Jun 2022 00:48:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37078) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nxL3W-0008JL-U2 for qemu-devel@nongnu.org; Sat, 04 Jun 2022 00:06:30 -0400 Received: from mail-pj1-x1030.google.com ([2607:f8b0:4864:20::1030]:38783) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nxL3V-0008VM-3y for qemu-devel@nongnu.org; Sat, 04 Jun 2022 00:06:30 -0400 Received: by mail-pj1-x1030.google.com with SMTP id v11-20020a17090a4ecb00b001e2c5b837ccso13505793pjl.3 for ; Fri, 03 Jun 2022 21:06:28 -0700 (PDT) Received: from stoup.. ([2602:ae:1547:e101:3286:cc26:3d5e:3f94]) by smtp.gmail.com with ESMTPSA id a37-20020a631a65000000b003c14af50626sm6093779pgm.62.2022.06.03.21.06.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jun 2022 21:06:27 -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=6KKo07UAnM87DaMoH4z3hFQneciCBNYbYQZeTrJ63eA=; b=JvM1wUMfOld2jZAq7MIwZrb9A/eGZ68mHqo14HneYJdq5h7IkUSwDhfNflFiFUUyC/ DxkQtuBldVsPz868s73MEHZvpZT8qGlBER8kVbobzRCq6A/ijrOsPxhe+m6Qf7yPwVLO aUjDCeuUn6bciWaQtwJ8xEbOR4xWgkEHqPBCdXXDfdMoJlFz9uuDg2Qw5quvx9Uylhjf QMxzLQUZWGybT38EILAV6aIo3lWcGLVeGQ8V/YzGEG6UPFzCY3bT5iQb/oG/zu84bP6E 6CaORFgp1on+PJ/7DlFQD9kxeWLWUKH2Ltb4CiIKIEyN9cPcUU4YenvOvK5tNuxAkpQx TIfQ== 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=6KKo07UAnM87DaMoH4z3hFQneciCBNYbYQZeTrJ63eA=; b=QQ0zKsX5opfwQqHTh3MDy4g3r2zACnbA3FvBbENWdNJyGs4NiAUyABF3g3clf1x7Gh SIyn6H3yFq3nRpUXg6uFVv7WwIr2cHrmUcDOVV1SaRrBYjeH5Hm2VA0Xj6PeCTkdFPNv KUP4w89M1qwAUPTSIAq4dy0NjhPcmh8U5CDt9vW3HsSrDW4iNCQIUwlmTiNkW68U2Lt9 4oF7WLODzcwB4avxdNzIQtvMhyB4mdDz8US1dCekSgmT29m50YmUeGodt73cRAVjqEqu m2VgkxpWusD9t2T8Wa1+uTi0MEu9LEQNRSzdeg+KrJMvGJtdHidEcS9+MIU87sKxoV/2 U3RA== X-Gm-Message-State: AOAM5326Wb2nvQuKI5c/1Dqzq/WnzyePZknYHUdUEyE1Ul5fkVtO2lE1 EGm3tM4oQf2xFm5blzO4rBcbOItMeaPaNA== X-Google-Smtp-Source: ABdhPJwiG7we0tFckdCvMY5uqeh50yEOX/9qpuCSZp/hLvBCY7DBlOeQ7j+oNbDxa1vF+VLkPLjkWg== X-Received: by 2002:a17:90a:ba15:b0:1e2:e76c:f725 with SMTP id s21-20020a17090aba1500b001e2e76cf725mr14161949pjr.7.1654315588232; Fri, 03 Jun 2022 21:06:28 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Subject: [PATCH 21/28] target/arm: Move aa32_va_parameters to ptw.c Date: Fri, 3 Jun 2022 21:06:00 -0700 Message-Id: <20220604040607.269301-22-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220604040607.269301-1-richard.henderson@linaro.org> References: <20220604040607.269301-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=2607:f8b0:4864:20::1030; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1030.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=ham 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1654318128234100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Richard Henderson --- target/arm/ptw.h | 3 --- target/arm/helper.c | 64 --------------------------------------------- target/arm/ptw.c | 64 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 67 deletions(-) diff --git a/target/arm/ptw.h b/target/arm/ptw.h index a71161b01b..9314fb4d23 100644 --- a/target/arm/ptw.h +++ b/target/arm/ptw.h @@ -25,8 +25,5 @@ simple_ap_to_rw_prot(CPUARMState *env, ARMMMUIdx mmu_idx,= int ap) return simple_ap_to_rw_prot_is_user(ap, regime_is_user(env, mmu_idx)); } =20 -ARMVAParameters aa32_va_parameters(CPUARMState *env, uint32_t va, - ARMMMUIdx mmu_idx); - #endif /* !CONFIG_USER_ONLY */ #endif /* TARGET_ARM_PTW_H */ diff --git a/target/arm/helper.c b/target/arm/helper.c index 5dfe1f9cc0..02e65c9e98 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -10735,70 +10735,6 @@ ARMVAParameters aa64_va_parameters(CPUARMState *en= v, uint64_t va, } =20 #ifndef CONFIG_USER_ONLY -ARMVAParameters aa32_va_parameters(CPUARMState *env, uint32_t va, - ARMMMUIdx mmu_idx) -{ - uint64_t tcr =3D regime_tcr(env, mmu_idx)->raw_tcr; - uint32_t el =3D regime_el(env, mmu_idx); - int select, tsz; - bool epd, hpd; - - assert(mmu_idx !=3D ARMMMUIdx_Stage2_S); - - if (mmu_idx =3D=3D ARMMMUIdx_Stage2) { - /* VTCR */ - bool sext =3D extract32(tcr, 4, 1); - bool sign =3D extract32(tcr, 3, 1); - - /* - * If the sign-extend bit is not the same as t0sz[3], the result - * is unpredictable. Flag this as a guest error. - */ - if (sign !=3D sext) { - qemu_log_mask(LOG_GUEST_ERROR, - "AArch32: VTCR.S / VTCR.T0SZ[3] mismatch\n"); - } - tsz =3D sextract32(tcr, 0, 4) + 8; - select =3D 0; - hpd =3D false; - epd =3D false; - } else if (el =3D=3D 2) { - /* HTCR */ - tsz =3D extract32(tcr, 0, 3); - select =3D 0; - hpd =3D extract64(tcr, 24, 1); - epd =3D false; - } else { - int t0sz =3D extract32(tcr, 0, 3); - int t1sz =3D extract32(tcr, 16, 3); - - if (t1sz =3D=3D 0) { - select =3D va > (0xffffffffu >> t0sz); - } else { - /* Note that we will detect errors later. */ - select =3D va >=3D ~(0xffffffffu >> t1sz); - } - if (!select) { - tsz =3D t0sz; - epd =3D extract32(tcr, 7, 1); - hpd =3D extract64(tcr, 41, 1); - } else { - tsz =3D t1sz; - epd =3D extract32(tcr, 23, 1); - hpd =3D extract64(tcr, 42, 1); - } - /* For aarch32, hpd0 is not enabled without t2e as well. */ - hpd &=3D extract32(tcr, 6, 1); - } - - return (ARMVAParameters) { - .tsz =3D tsz, - .select =3D select, - .epd =3D epd, - .hpd =3D hpd, - }; -} - hwaddr arm_cpu_get_phys_page_attrs_debug(CPUState *cs, vaddr addr, MemTxAttrs *attrs) { diff --git a/target/arm/ptw.c b/target/arm/ptw.c index 525272e99a..427813ea56 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -615,6 +615,70 @@ static int get_S1prot(CPUARMState *env, ARMMMUIdx mmu_= idx, bool is_aa64, return prot_rw | PAGE_EXEC; } =20 +static ARMVAParameters aa32_va_parameters(CPUARMState *env, uint32_t va, + ARMMMUIdx mmu_idx) +{ + uint64_t tcr =3D regime_tcr(env, mmu_idx)->raw_tcr; + uint32_t el =3D regime_el(env, mmu_idx); + int select, tsz; + bool epd, hpd; + + assert(mmu_idx !=3D ARMMMUIdx_Stage2_S); + + if (mmu_idx =3D=3D ARMMMUIdx_Stage2) { + /* VTCR */ + bool sext =3D extract32(tcr, 4, 1); + bool sign =3D extract32(tcr, 3, 1); + + /* + * If the sign-extend bit is not the same as t0sz[3], the result + * is unpredictable. Flag this as a guest error. + */ + if (sign !=3D sext) { + qemu_log_mask(LOG_GUEST_ERROR, + "AArch32: VTCR.S / VTCR.T0SZ[3] mismatch\n"); + } + tsz =3D sextract32(tcr, 0, 4) + 8; + select =3D 0; + hpd =3D false; + epd =3D false; + } else if (el =3D=3D 2) { + /* HTCR */ + tsz =3D extract32(tcr, 0, 3); + select =3D 0; + hpd =3D extract64(tcr, 24, 1); + epd =3D false; + } else { + int t0sz =3D extract32(tcr, 0, 3); + int t1sz =3D extract32(tcr, 16, 3); + + if (t1sz =3D=3D 0) { + select =3D va > (0xffffffffu >> t0sz); + } else { + /* Note that we will detect errors later. */ + select =3D va >=3D ~(0xffffffffu >> t1sz); + } + if (!select) { + tsz =3D t0sz; + epd =3D extract32(tcr, 7, 1); + hpd =3D extract64(tcr, 41, 1); + } else { + tsz =3D t1sz; + epd =3D extract32(tcr, 23, 1); + hpd =3D extract64(tcr, 42, 1); + } + /* For aarch32, hpd0 is not enabled without t2e as well. */ + hpd &=3D extract32(tcr, 6, 1); + } + + return (ARMVAParameters) { + .tsz =3D tsz, + .select =3D select, + .epd =3D epd, + .hpd =3D hpd, + }; +} + /* * check_s2_mmu_setup * @cpu: ARMCPU --=20 2.34.1 From nobody Fri May 17 05:50:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1654316303; cv=none; d=zohomail.com; s=zohoarc; b=St1YreVVL/9yZAK+RRJAFHmiUnp5yh0dn23ZJqMgvSvuFT552MXdR98Ov3VAflCmx9MuZm+GWunhJ6ByVzmJtE/BKpFJGhVdrEHOBvsIQzpk4Ma+oPOGvcMskDZz8P8O0+0VHzpmnL61ol1kLtt5giSoOvdRG4MMCGcxyDemneg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1654316303; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=WU5z3Bzu3rwceAokLvQLv9D+G/DS17uNqZgTXkFyI+0=; b=T6LH3nZxp0WXnwk3apJwsRpoh4UsVooL3k3VqelilMltA1f9u9m+lIxCuVv3hS5/jMKaSx9x0FwyJy8PGL/fCAYwgptsY2CJhx53mj5qa822TBY3IgMMgfN6cGzsr0PZ1BEQzn7RMSxih8dijBcNTb2nomIzuK2dqudF9wgeR1k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1654316303625181.79457098630678; Fri, 3 Jun 2022 21:18:23 -0700 (PDT) Received: from localhost ([::1]:41688 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nxLEy-0001Ej-AZ for importer@patchew.org; Sat, 04 Jun 2022 00:18:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37126) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nxL3Y-0008Of-4j for qemu-devel@nongnu.org; Sat, 04 Jun 2022 00:06:32 -0400 Received: from mail-pg1-x52c.google.com ([2607:f8b0:4864:20::52c]:36831) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nxL3W-00007Y-3K for qemu-devel@nongnu.org; Sat, 04 Jun 2022 00:06:31 -0400 Received: by mail-pg1-x52c.google.com with SMTP id y187so8665024pgd.3 for ; Fri, 03 Jun 2022 21:06:29 -0700 (PDT) Received: from stoup.. ([2602:ae:1547:e101:3286:cc26:3d5e:3f94]) by smtp.gmail.com with ESMTPSA id a37-20020a631a65000000b003c14af50626sm6093779pgm.62.2022.06.03.21.06.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jun 2022 21:06: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=WU5z3Bzu3rwceAokLvQLv9D+G/DS17uNqZgTXkFyI+0=; b=KmLbh34IZ1M3NvbeZtmVafdeC4d+uPFC9VVEsXJY/aUZOEQ8OtviIOz8NWVL5Pg4sB BEzdd3KZ7zCFAOgLZrjmJECRuHrRVv4WrGyWzJMZ9MRE9ufPpzO9V9bKMiHeKfYTx9nR 1Ge1O2ZjmOvOgi18at/yLDM2c20870RfkMc3uci7CMhUaGyHMRI0+OxcuPCcKFzMkdWc yApTDtv12ErW7AWbrFW6uiPLXg7QocYNvktZpkiFRDSmPiXK+KxdGv3hIMDSZl4KeILD aKXZE5TEKOXaDhJiYRYtFNkNYuxR38U4NkDSwapwf01aMg3kR14/nGxBjqOyw2C5/ACj 6mJA== 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=WU5z3Bzu3rwceAokLvQLv9D+G/DS17uNqZgTXkFyI+0=; b=LgWcvCFckrufStnvtRAR+hhTgLGxF54mrKYk7smul9Dm9nELYRWDqDIvs8COPTYSHh 2cnc/0A8FgSN3OZzNATiYXrcbpToC7gg+LMU7SQPFLvEZN7Su2eybkZ6syOQha7LXdij wggUT9/j4a3wW3UR/1cHFEMIrgEKNdP+AwPSeP/4roYyQAqMXgt6/2EUmNDyVIjfAmVG 3gkz+zgzTBjJrFZxgzP81nGlNM8T2ntZBFxm0TooP3zSjLy5LTPD7s1I1aMORCT5IzxN EGWhuV/QE7pE8QZ+N5LvHQOO2RD8CwbzGdIGzk1UjNNqkOvsZbV1WX5Wp/PofEQ5jvl8 OeCw== X-Gm-Message-State: AOAM533smp++vXFtK/PUkaG2VlL7Fjd7Wcqw3RBLU2lh3ii0i80DR4oh XS186HCdCtyxhpzEYPi0OeqvM3u79gmAQQ== X-Google-Smtp-Source: ABdhPJx9oeXfO9f088hhuzbCQepIFOg9Rf8XJwKw+aRJJQTAzIl0JOX/LnBgnlgsvuvNI4maSwyMwg== X-Received: by 2002:a65:668b:0:b0:3f6:4026:97cd with SMTP id b11-20020a65668b000000b003f6402697cdmr11453154pgw.420.1654315589269; Fri, 03 Jun 2022 21:06:29 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Subject: [PATCH 22/28] target/arm: Move ap_to_tw_prot etc to ptw.c Date: Fri, 3 Jun 2022 21:06:01 -0700 Message-Id: <20220604040607.269301-23-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220604040607.269301-1-richard.henderson@linaro.org> References: <20220604040607.269301-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=2607:f8b0:4864:20::52c; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52c.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=ham 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1654316305550100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Richard Henderson --- target/arm/ptw.h | 10 ------ target/arm/helper.c | 77 ------------------------------------------ target/arm/ptw.c | 81 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+), 87 deletions(-) diff --git a/target/arm/ptw.h b/target/arm/ptw.h index 9314fb4d23..85ad576794 100644 --- a/target/arm/ptw.h +++ b/target/arm/ptw.h @@ -15,15 +15,5 @@ bool regime_is_user(CPUARMState *env, ARMMMUIdx mmu_idx); bool regime_translation_disabled(CPUARMState *env, ARMMMUIdx mmu_idx); uint64_t regime_ttbr(CPUARMState *env, ARMMMUIdx mmu_idx, int ttbrn); =20 -int ap_to_rw_prot(CPUARMState *env, ARMMMUIdx mmu_idx, - int ap, int domain_prot); -int simple_ap_to_rw_prot_is_user(int ap, bool is_user); - -static inline int -simple_ap_to_rw_prot(CPUARMState *env, ARMMMUIdx mmu_idx, int ap) -{ - return simple_ap_to_rw_prot_is_user(ap, regime_is_user(env, mmu_idx)); -} - #endif /* !CONFIG_USER_ONLY */ #endif /* TARGET_ARM_PTW_H */ diff --git a/target/arm/helper.c b/target/arm/helper.c index 02e65c9e98..3a39a10e43 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -10501,83 +10501,6 @@ bool regime_is_user(CPUARMState *env, ARMMMUIdx mm= u_idx) g_assert_not_reached(); } } - -/* Translate section/page access permissions to page - * R/W protection flags - * - * @env: CPUARMState - * @mmu_idx: MMU index indicating required translation regime - * @ap: The 3-bit access permissions (AP[2:0]) - * @domain_prot: The 2-bit domain access permissions - */ -int ap_to_rw_prot(CPUARMState *env, ARMMMUIdx mmu_idx, int ap, int domain_= prot) -{ - bool is_user =3D regime_is_user(env, mmu_idx); - - if (domain_prot =3D=3D 3) { - return PAGE_READ | PAGE_WRITE; - } - - switch (ap) { - case 0: - if (arm_feature(env, ARM_FEATURE_V7)) { - return 0; - } - switch (regime_sctlr(env, mmu_idx) & (SCTLR_S | SCTLR_R)) { - case SCTLR_S: - return is_user ? 0 : PAGE_READ; - case SCTLR_R: - return PAGE_READ; - default: - return 0; - } - case 1: - return is_user ? 0 : PAGE_READ | PAGE_WRITE; - case 2: - if (is_user) { - return PAGE_READ; - } else { - return PAGE_READ | PAGE_WRITE; - } - case 3: - return PAGE_READ | PAGE_WRITE; - case 4: /* Reserved. */ - return 0; - case 5: - return is_user ? 0 : PAGE_READ; - case 6: - return PAGE_READ; - case 7: - if (!arm_feature(env, ARM_FEATURE_V6K)) { - return 0; - } - return PAGE_READ; - default: - g_assert_not_reached(); - } -} - -/* Translate section/page access permissions to page - * R/W protection flags. - * - * @ap: The 2-bit simple AP (AP[2:1]) - * @is_user: TRUE if accessing from PL0 - */ -int simple_ap_to_rw_prot_is_user(int ap, bool is_user) -{ - switch (ap) { - case 0: - return is_user ? 0 : PAGE_READ | PAGE_WRITE; - case 1: - return PAGE_READ | PAGE_WRITE; - case 2: - return is_user ? 0 : PAGE_READ; - case 3: - return PAGE_READ; - default: - g_assert_not_reached(); - } -} #endif /* !CONFIG_USER_ONLY */ =20 int aa64_va_parameter_tbi(uint64_t tcr, ARMMMUIdx mmu_idx) diff --git a/target/arm/ptw.c b/target/arm/ptw.c index 427813ea56..9ab77c3998 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -211,6 +211,87 @@ static bool get_level1_table_address(CPUARMState *env,= ARMMMUIdx mmu_idx, return true; } =20 +/* + * Translate section/page access permissions to page R/W protection flags + * @env: CPUARMState + * @mmu_idx: MMU index indicating required translation regime + * @ap: The 3-bit access permissions (AP[2:0]) + * @domain_prot: The 2-bit domain access permissions + */ +static int ap_to_rw_prot(CPUARMState *env, ARMMMUIdx mmu_idx, + int ap, int domain_prot) +{ + bool is_user =3D regime_is_user(env, mmu_idx); + + if (domain_prot =3D=3D 3) { + return PAGE_READ | PAGE_WRITE; + } + + switch (ap) { + case 0: + if (arm_feature(env, ARM_FEATURE_V7)) { + return 0; + } + switch (regime_sctlr(env, mmu_idx) & (SCTLR_S | SCTLR_R)) { + case SCTLR_S: + return is_user ? 0 : PAGE_READ; + case SCTLR_R: + return PAGE_READ; + default: + return 0; + } + case 1: + return is_user ? 0 : PAGE_READ | PAGE_WRITE; + case 2: + if (is_user) { + return PAGE_READ; + } else { + return PAGE_READ | PAGE_WRITE; + } + case 3: + return PAGE_READ | PAGE_WRITE; + case 4: /* Reserved. */ + return 0; + case 5: + return is_user ? 0 : PAGE_READ; + case 6: + return PAGE_READ; + case 7: + if (!arm_feature(env, ARM_FEATURE_V6K)) { + return 0; + } + return PAGE_READ; + default: + g_assert_not_reached(); + } +} + +/* + * Translate section/page access permissions to page R/W protection flags. + * @ap: The 2-bit simple AP (AP[2:1]) + * @is_user: TRUE if accessing from PL0 + */ +static int simple_ap_to_rw_prot_is_user(int ap, bool is_user) +{ + switch (ap) { + case 0: + return is_user ? 0 : PAGE_READ | PAGE_WRITE; + case 1: + return PAGE_READ | PAGE_WRITE; + case 2: + return is_user ? 0 : PAGE_READ; + case 3: + return PAGE_READ; + default: + g_assert_not_reached(); + } +} + +static int simple_ap_to_rw_prot(CPUARMState *env, ARMMMUIdx mmu_idx, int a= p) +{ + return simple_ap_to_rw_prot_is_user(ap, regime_is_user(env, mmu_idx)); +} + static bool get_phys_addr_v5(CPUARMState *env, uint32_t address, MMUAccessType access_type, ARMMMUIdx mmu_idx, hwaddr *phys_ptr, int *prot, --=20 2.34.1 From nobody Fri May 17 05:50:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1654318259; cv=none; d=zohomail.com; s=zohoarc; b=iDkjy/I1I0IflWsjGnXxcGgNeDdokQ7dUzne++1xoRxJY4ltQhm2o75BmEk7wGKhwS+6JZqomwW7gscT3W26UUHhr/iMph8KqSu6L0wU4+TIol4Qvq2zYtFCbrZPrPUETZMdF/GODPSW+/G/GLSKQkbONbZFzj/ap4o2ym0la4g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1654318259; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=JZyYsyMR5C2jCP429J1iL+9VPu9Dr37P/n1C5u4W6jI=; b=my+fVx/bztAqjTdfQxeF0/C8awc7KmJ9paZrTZoYYwAhdVULmyylozKmY9u1f9bUYq+/ydSADnG/Eqc3QBo/QwmJazJJuFeHiCZtmlf/DYa0raVrXlEkXMnjXGjgzj4QDY+UnYFl7v5Tp4EHEDE3qKY3Cm+Dv+H53s3SApwq/+g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1654318259282333.84458165882756; Fri, 3 Jun 2022 21:50:59 -0700 (PDT) Received: from localhost ([::1]:58864 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nxLkX-0007ik-Pt for importer@patchew.org; Sat, 04 Jun 2022 00:50:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37140) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nxL3Y-0008Qf-ME for qemu-devel@nongnu.org; Sat, 04 Jun 2022 00:06:32 -0400 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]:35385) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nxL3X-0008WU-2V for qemu-devel@nongnu.org; Sat, 04 Jun 2022 00:06:32 -0400 Received: by mail-pj1-x102d.google.com with SMTP id o6-20020a17090a0a0600b001e2c6566046so13546760pjo.0 for ; Fri, 03 Jun 2022 21:06:30 -0700 (PDT) Received: from stoup.. ([2602:ae:1547:e101:3286:cc26:3d5e:3f94]) by smtp.gmail.com with ESMTPSA id a37-20020a631a65000000b003c14af50626sm6093779pgm.62.2022.06.03.21.06.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jun 2022 21:06:29 -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=JZyYsyMR5C2jCP429J1iL+9VPu9Dr37P/n1C5u4W6jI=; b=TJhGlFVLXCmu0ZFOVZ3IWzZG9CuRbm0AlNX5MfZ4bvA1h8KC6ymBz0PQgdZV1hqdKB cAqGLMwMecLhJQiuVUtC3s1T8l2u5BECGSFcmZiO4xYAx4nHVoc7AhlmjiAkI8lzNcsC 73U4xqvsa287+CviR4qnOPBK/bJjR3eS3F3n5dUwyDVmGcfqQT156M/fj3NjY6rje0V2 phO6F8YwkGwD1mG27WXL+gHug47xGBQLKiNWa+IumowFaByjoYXs8hZ6xWXpKh7bFCU3 10hEMe6cp1RQLtz+aaKH5O8h+Rnlj8rn8nJOeL6hEqZU0XmkXsRbJuhgWKwefBIv1BZu fuJA== 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=JZyYsyMR5C2jCP429J1iL+9VPu9Dr37P/n1C5u4W6jI=; b=NpMNT9EqWJSPVpxuRSKlV6dHIIeq8FzLxqYqz8U7qLYSb7Ee2LifwYgT+2PEXTePRS Aa1K0Vp6uf1GxFJC68M5De3Tt2vf0oCAVTft2RWCnI8U5M9CE0hE0CjEIriM9kjQpbzL cXgtB9DyCL+ZseWAWM652wweVGd3kgQpoIKC1WhyaNzHoETSXD11b/7SoWuSKzLaaKbe /XHd131fNQYUq8Ael7k85oRWqXydaNH7yhgJtZOc6+RYd2SvJrtIL4YoxDdkbK7FBAHs Garh9sP5jBQFyBG4prPBXQpbS57UGrB+gRpExYoUbozHxRjIc2ONimva4qaM9SH+xqKI YXlg== X-Gm-Message-State: AOAM5326H95qj8nNV+X9O5cqXYYE7XoHn53JhKtLbnhZdV1LiuZ3g8tH G4wYKnjZxagvCyy2LE4YWRDcEOikajSaKw== X-Google-Smtp-Source: ABdhPJzWMrtd1P50lrmyGO+AqF4kAHB6f63nxYJIz4B7EvSPjKZiXuOqhgV9405JTlKozgtpDR/kvQ== X-Received: by 2002:a17:902:d506:b0:167:5021:d644 with SMTP id b6-20020a170902d50600b001675021d644mr4834092plg.159.1654315590325; Fri, 03 Jun 2022 21:06:30 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Subject: [PATCH 23/28] target/arm: Move regime_is_user to ptw.c Date: Fri, 3 Jun 2022 21:06:02 -0700 Message-Id: <20220604040607.269301-24-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220604040607.269301-1-richard.henderson@linaro.org> References: <20220604040607.269301-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=2607:f8b0:4864:20::102d; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102d.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=ham 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1654318260847100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Richard Henderson --- target/arm/ptw.h | 1 - target/arm/helper.c | 24 ------------------------ target/arm/ptw.c | 22 ++++++++++++++++++++++ 3 files changed, 22 insertions(+), 25 deletions(-) diff --git a/target/arm/ptw.h b/target/arm/ptw.h index 85ad576794..3d3061a435 100644 --- a/target/arm/ptw.h +++ b/target/arm/ptw.h @@ -11,7 +11,6 @@ =20 #ifndef CONFIG_USER_ONLY =20 -bool regime_is_user(CPUARMState *env, ARMMMUIdx mmu_idx); bool regime_translation_disabled(CPUARMState *env, ARMMMUIdx mmu_idx); uint64_t regime_ttbr(CPUARMState *env, ARMMMUIdx mmu_idx, int ttbrn); =20 diff --git a/target/arm/helper.c b/target/arm/helper.c index 3a39a10e43..568e02c5dc 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -10479,30 +10479,6 @@ ARMMMUIdx stage_1_mmu_idx(ARMMMUIdx mmu_idx) } #endif /* !CONFIG_USER_ONLY */ =20 -#ifndef CONFIG_USER_ONLY -bool regime_is_user(CPUARMState *env, ARMMMUIdx mmu_idx) -{ - switch (mmu_idx) { - case ARMMMUIdx_SE10_0: - case ARMMMUIdx_E20_0: - case ARMMMUIdx_SE20_0: - case ARMMMUIdx_Stage1_E0: - case ARMMMUIdx_Stage1_SE0: - case ARMMMUIdx_MUser: - case ARMMMUIdx_MSUser: - case ARMMMUIdx_MUserNegPri: - case ARMMMUIdx_MSUserNegPri: - return true; - default: - return false; - case ARMMMUIdx_E10_0: - case ARMMMUIdx_E10_1: - case ARMMMUIdx_E10_1_PAN: - g_assert_not_reached(); - } -} -#endif /* !CONFIG_USER_ONLY */ - int aa64_va_parameter_tbi(uint64_t tcr, ARMMMUIdx mmu_idx) { if (regime_has_2_ranges(mmu_idx)) { diff --git a/target/arm/ptw.c b/target/arm/ptw.c index 9ab77c3998..8db4b5edf1 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -53,6 +53,28 @@ static bool regime_translation_big_endian(CPUARMState *e= nv, ARMMMUIdx mmu_idx) return (regime_sctlr(env, mmu_idx) & SCTLR_EE) !=3D 0; } =20 +static bool regime_is_user(CPUARMState *env, ARMMMUIdx mmu_idx) +{ + switch (mmu_idx) { + case ARMMMUIdx_SE10_0: + case ARMMMUIdx_E20_0: + case ARMMMUIdx_SE20_0: + case ARMMMUIdx_Stage1_E0: + case ARMMMUIdx_Stage1_SE0: + case ARMMMUIdx_MUser: + case ARMMMUIdx_MSUser: + case ARMMMUIdx_MUserNegPri: + case ARMMMUIdx_MSUserNegPri: + return true; + default: + return false; + case ARMMMUIdx_E10_0: + case ARMMMUIdx_E10_1: + case ARMMMUIdx_E10_1_PAN: + g_assert_not_reached(); + } +} + static bool ptw_attrs_are_device(CPUARMState *env, ARMCacheAttrs cacheattr= s) { /* --=20 2.34.1 From nobody Fri May 17 05:50:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1654318382; cv=none; d=zohomail.com; s=zohoarc; b=SDlxIaqS5FIBb/CHiMYYfk+bbIR5bE1ncxNoeLemnr4KSA4lZ24WdzdzBlhgyYvmPpE79CTCecCHrPoKDVDay6WcuR34LkdessUr+58wR08Cda6O4L2wFvmiRH5YWVaEnG4JxCNKEXNR3Q78nLtV8pjZeljdoMlN5SDxn3V04bc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1654318382; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=m8FrJXaj9IkZtQ3fkmfO7j242cR+2ACwn4iIRM1nBdE=; b=CqevQxEeojcmVYriURSiNBlsg12Sx3vFjMgQN1VVJT8w/RQx3WiLPru15pDCARrJwLBi+P91OiTeVjrWEUPQtRm8+3ns2tWPMA9GEgrCFPBuhGDk9+3FNUIcZxcC3MpHSRaNLHGndInO7xNVyylfDLbYmNL0hUZEZsW0KTjapOc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1654318382289178.49537532672264; Fri, 3 Jun 2022 21:53:02 -0700 (PDT) Received: from localhost ([::1]:33130 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nxLmX-00015o-52 for importer@patchew.org; Sat, 04 Jun 2022 00:53:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37232) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nxL3c-00007v-FF for qemu-devel@nongnu.org; Sat, 04 Jun 2022 00:06:36 -0400 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]:41559) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nxL3Y-0000CN-LM for qemu-devel@nongnu.org; Sat, 04 Jun 2022 00:06:35 -0400 Received: by mail-pj1-x102c.google.com with SMTP id l20-20020a17090a409400b001dd2a9d555bso8506084pjg.0 for ; Fri, 03 Jun 2022 21:06:32 -0700 (PDT) Received: from stoup.. ([2602:ae:1547:e101:3286:cc26:3d5e:3f94]) by smtp.gmail.com with ESMTPSA id a37-20020a631a65000000b003c14af50626sm6093779pgm.62.2022.06.03.21.06.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jun 2022 21:06:30 -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=m8FrJXaj9IkZtQ3fkmfO7j242cR+2ACwn4iIRM1nBdE=; b=xvjVy75q9PU5G+jZOXybpnCGXgr8n8KCgaCqpnnAN0zKCuSBtUy7OaWLqGW8zlOQBa ew6AQPbq9ndXlBUyziw5k7qVfx2jFVpTc1EbcDLDpF48Ftwb2Pf/0yuZk71COmtM5n0M V55eZtBKSHUlKXB9s1vqc8RhhkuM3JH7AfSrK5SnqrsSpmcavxEWYrSGp6MmvWmOzIXy f6xiyrD1Fs/DckW7z3r3hTDfyGSKQ9vBna+5cDR8Itf1EmVIvbpWBySIu4epTwSi5rT6 5tebjaEmmNuIgk6/zAgVTjdxehSDVTRPzYEMv6SIkI0nmPpGgQ87OEUHsvZFjllXHFdi XYyw== 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=m8FrJXaj9IkZtQ3fkmfO7j242cR+2ACwn4iIRM1nBdE=; b=Y7V0uk6ltXjzwMG64P3D3Eysw990Tm2WoXec0k7ge8c+YQzH1GmvpOnosdoR7Y967x wFoS8U37wvfKLNYjRtzKOl/s3sCpyxlGshHW6HNOqmkH6cAH+176tTea3fn+ZRZUtbC6 NSNPfPfSnP53qjth7B+EjwfovU9oVQvP0aPS5Ki9toJsBWozGZbJwQQtS/uPdD2jBm2v ZR5L2QJw1y5/TECmxt51BuyC58k7OQTCy5oEA1O7TcdtAN4wgViRMg+K2ssa1aoTZYyl L+lJJd2TuWen6KIDtqWv0xZkJciIPLmfzkoyAUoUmODC584j+/Vtr+lyjqXZ7dojBmyH cuLA== X-Gm-Message-State: AOAM533K/0phcfSOJ1RiEZNvZeTjxv2/MuniGCyNhtXG7XKs8pyr5/DA 0fyT9UVSwcMzkl94CRgxcQ4H47HZFHJKNA== X-Google-Smtp-Source: ABdhPJxoRb864T2mkbXjcP3PS+/NtoPuzyDvC4oJ57htrTwBMkaDKclFvaNikmfWjHT8wMCubbsebA== X-Received: by 2002:a17:903:2d1:b0:156:7ceb:b56f with SMTP id s17-20020a17090302d100b001567cebb56fmr13016010plk.11.1654315591426; Fri, 03 Jun 2022 21:06:31 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Subject: [PATCH 24/28] target/arm: Move regime_ttbr to ptw.c Date: Fri, 3 Jun 2022 21:06:03 -0700 Message-Id: <20220604040607.269301-25-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220604040607.269301-1-richard.henderson@linaro.org> References: <20220604040607.269301-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=2607:f8b0:4864:20::102c; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102c.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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1654318382705100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Richard Henderson --- target/arm/ptw.h | 1 - target/arm/helper.c | 16 ---------------- target/arm/ptw.c | 16 ++++++++++++++++ 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/target/arm/ptw.h b/target/arm/ptw.h index 3d3061a435..ed152ddaf4 100644 --- a/target/arm/ptw.h +++ b/target/arm/ptw.h @@ -12,7 +12,6 @@ #ifndef CONFIG_USER_ONLY =20 bool regime_translation_disabled(CPUARMState *env, ARMMMUIdx mmu_idx); -uint64_t regime_ttbr(CPUARMState *env, ARMMMUIdx mmu_idx, int ttbrn); =20 #endif /* !CONFIG_USER_ONLY */ #endif /* TARGET_ARM_PTW_H */ diff --git a/target/arm/helper.c b/target/arm/helper.c index 568e02c5dc..07b4f7bcc5 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -10439,22 +10439,6 @@ bool regime_translation_disabled(CPUARMState *env,= ARMMMUIdx mmu_idx) return (regime_sctlr(env, mmu_idx) & SCTLR_M) =3D=3D 0; } =20 -/* Return the TTBR associated with this translation regime */ -uint64_t regime_ttbr(CPUARMState *env, ARMMMUIdx mmu_idx, int ttbrn) -{ - if (mmu_idx =3D=3D ARMMMUIdx_Stage2) { - return env->cp15.vttbr_el2; - } - if (mmu_idx =3D=3D ARMMMUIdx_Stage2_S) { - return env->cp15.vsttbr_el2; - } - if (ttbrn =3D=3D 0) { - return env->cp15.ttbr0_el[regime_el(env, mmu_idx)]; - } else { - return env->cp15.ttbr1_el[regime_el(env, mmu_idx)]; - } -} - /* Convert a possible stage1+2 MMU index into the appropriate * stage 1 MMU index */ diff --git a/target/arm/ptw.c b/target/arm/ptw.c index 8db4b5edf1..dc559e6bdf 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -75,6 +75,22 @@ static bool regime_is_user(CPUARMState *env, ARMMMUIdx m= mu_idx) } } =20 +/* Return the TTBR associated with this translation regime */ +static uint64_t regime_ttbr(CPUARMState *env, ARMMMUIdx mmu_idx, int ttbrn) +{ + if (mmu_idx =3D=3D ARMMMUIdx_Stage2) { + return env->cp15.vttbr_el2; + } + if (mmu_idx =3D=3D ARMMMUIdx_Stage2_S) { + return env->cp15.vsttbr_el2; + } + if (ttbrn =3D=3D 0) { + return env->cp15.ttbr0_el[regime_el(env, mmu_idx)]; + } else { + return env->cp15.ttbr1_el[regime_el(env, mmu_idx)]; + } +} + static bool ptw_attrs_are_device(CPUARMState *env, ARMCacheAttrs cacheattr= s) { /* --=20 2.34.1 From nobody Fri May 17 05:50:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1654317560; cv=none; d=zohomail.com; s=zohoarc; b=gouFwPDeY86pC3xGf10dudwswOVktRAHyiSYeJ8pnIIIfhSeGxNAlRlmQPYWWEvaXU/bg0cIi9YU0DR+UTTZvMylcVMwSWEuIDYU6KampecPQaViWsrqs1BNly4V2hUiE3LanAB3WLysvwe4t2NI+MDwwMsS1pE4Cx4coz1+MOc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1654317560; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=kWtcVx4mUIA7p+snzfjlyFCseNpogg1BsFjQCw5lpL0=; b=WuZdy8RIE5Ej4CpPoR6vNNOaf6OEa+x63msvpe32CjDMylIqaDCZEqJ6924uwenLpUg2Ofl2iTdQrOEhCG0PIdQP9jd/sw8A14Z/9n/Ha+Mc3UzHRvHYN9oEfDPHGVdgudKMWPPaUpo+lxWV7Oth/dPR+mejl7LqF6YdV8rkcf0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 165431756090027.826923335493575; Fri, 3 Jun 2022 21:39:20 -0700 (PDT) Received: from localhost ([::1]:45786 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nxLZH-00072U-TM for importer@patchew.org; Sat, 04 Jun 2022 00:39:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37228) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nxL3b-00007j-FG for qemu-devel@nongnu.org; Sat, 04 Jun 2022 00:06:35 -0400 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]:43666) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nxL3Z-0000DM-Kj for qemu-devel@nongnu.org; Sat, 04 Jun 2022 00:06:35 -0400 Received: by mail-pl1-x633.google.com with SMTP id b5so8098431plx.10 for ; Fri, 03 Jun 2022 21:06:33 -0700 (PDT) Received: from stoup.. ([2602:ae:1547:e101:3286:cc26:3d5e:3f94]) by smtp.gmail.com with ESMTPSA id a37-20020a631a65000000b003c14af50626sm6093779pgm.62.2022.06.03.21.06.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jun 2022 21:06:31 -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=kWtcVx4mUIA7p+snzfjlyFCseNpogg1BsFjQCw5lpL0=; b=Zc7Eocd0JHmn2bDVNaKcrB0O5HybR0NYoFyM1NVksyB2MYSAS1swoYy1J7+fwnnIzf aOi4OmEgx68LzNf+9aP4UIcJ3hConJs3Xihu9QO12XNpUBDdd/p06jniNRwueUaIW8zT InXP6VOQjHaPke+jr7a+0caGIRT43rF/kqe8jNQ8vQxhgmcvLDD5nITGk/ecRwbmOz8K qWJBbcPgVJa152UXjDQrnSx2eETrwmP2F53NaoGoDlN/4Ar23QgUizWpjrUvRlPfetUQ VBmDHN6AJV3HRzo+AbgXZMDxGxbblbG+kKVUXC1HYymUkUiLIZSWY+un6ejADuIyIh88 tOGQ== 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=kWtcVx4mUIA7p+snzfjlyFCseNpogg1BsFjQCw5lpL0=; b=Y/R/B8bcCUD5gXtymIn9L/RxJhKYK4do3W7i3NC4duf0g1MCkr3N1WISZZHE5R20wq byx7Wv8CVVgnmlMg9G3A51YV4wCFxnjN0OjiZLtYvt+jLsb1UO4JfhEqbWoroSvuScem O0FpLeIEl3SoSPrpqSxHMB0/J2fOr1HveOKMQVWtAPpoSoww1LY5uOqSTYvHU0BPpKdu +3iSs9uGlEYkncif1Td25gzrRN9WUyQv2+/WVLk5vDjvNsp404YWHjWNEkhCnTIZWP/W pmh8ekLFZ2fQLk1gobZoVBR0kMG0fRTPOwLl7l6gZiXlpClPZyPJA4ySKD0g5u6eLEfj l5TA== X-Gm-Message-State: AOAM532raM+zMd05+5eA23Yb81i8VvDwRUNKnEnY+LZqgTdxCQHPvC7q mLucXe6Z5yNmbYNB+RD6qjESiTDCA1H25g== X-Google-Smtp-Source: ABdhPJw1rTsdTp56Idg7NTR9Illo7s7d//bL/Z2G1FB/oi9Nb9YSGpSZGRt4CdhL5vEltOKPKFIQmg== X-Received: by 2002:a17:902:ebd1:b0:162:224f:abbb with SMTP id p17-20020a170902ebd100b00162224fabbbmr12984772plg.160.1654315592307; Fri, 03 Jun 2022 21:06:32 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Subject: [PATCH 25/28] target/arm: Move regime_translation_disabled to ptw.c Date: Fri, 3 Jun 2022 21:06:04 -0700 Message-Id: <20220604040607.269301-26-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220604040607.269301-1-richard.henderson@linaro.org> References: <20220604040607.269301-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=2607:f8b0:4864:20::633; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x633.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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1654317562675100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Richard Henderson --- target/arm/ptw.h | 17 ---------------- target/arm/helper.c | 47 --------------------------------------------- target/arm/ptw.c | 47 ++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 46 insertions(+), 65 deletions(-) delete mode 100644 target/arm/ptw.h diff --git a/target/arm/ptw.h b/target/arm/ptw.h deleted file mode 100644 index ed152ddaf4..0000000000 --- a/target/arm/ptw.h +++ /dev/null @@ -1,17 +0,0 @@ -/* - * ARM page table walking. - * - * This code is licensed under the GNU GPL v2 or later. - * - * SPDX-License-Identifier: GPL-2.0-or-later - */ - -#ifndef TARGET_ARM_PTW_H -#define TARGET_ARM_PTW_H - -#ifndef CONFIG_USER_ONLY - -bool regime_translation_disabled(CPUARMState *env, ARMMMUIdx mmu_idx); - -#endif /* !CONFIG_USER_ONLY */ -#endif /* TARGET_ARM_PTW_H */ diff --git a/target/arm/helper.c b/target/arm/helper.c index 07b4f7bcc5..7390798463 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -36,7 +36,6 @@ #include "semihosting/common-semi.h" #endif #include "cpregs.h" -#include "ptw.h" =20 #define ARM_CPU_FREQ 1000000000 /* FIXME: 1 GHz, should be configurable */ =20 @@ -10393,52 +10392,6 @@ uint64_t arm_sctlr(CPUARMState *env, int el) } =20 #ifndef CONFIG_USER_ONLY - -/* Return true if the specified stage of address translation is disabled */ -bool regime_translation_disabled(CPUARMState *env, ARMMMUIdx mmu_idx) -{ - uint64_t hcr_el2; - - if (arm_feature(env, ARM_FEATURE_M)) { - switch (env->v7m.mpu_ctrl[regime_is_secure(env, mmu_idx)] & - (R_V7M_MPU_CTRL_ENABLE_MASK | R_V7M_MPU_CTRL_HFNMIENA_MASK= )) { - case R_V7M_MPU_CTRL_ENABLE_MASK: - /* Enabled, but not for HardFault and NMI */ - return mmu_idx & ARM_MMU_IDX_M_NEGPRI; - case R_V7M_MPU_CTRL_ENABLE_MASK | R_V7M_MPU_CTRL_HFNMIENA_MASK: - /* Enabled for all cases */ - return false; - case 0: - default: - /* HFNMIENA set and ENABLE clear is UNPREDICTABLE, but - * we warned about that in armv7m_nvic.c when the guest set it. - */ - return true; - } - } - - hcr_el2 =3D arm_hcr_el2_eff(env); - - if (mmu_idx =3D=3D ARMMMUIdx_Stage2 || mmu_idx =3D=3D ARMMMUIdx_Stage2= _S) { - /* HCR.DC means HCR.VM behaves as 1 */ - return (hcr_el2 & (HCR_DC | HCR_VM)) =3D=3D 0; - } - - if (hcr_el2 & HCR_TGE) { - /* TGE means that NS EL0/1 act as if SCTLR_EL1.M is zero */ - if (!regime_is_secure(env, mmu_idx) && regime_el(env, mmu_idx) =3D= =3D 1) { - return true; - } - } - - if ((hcr_el2 & HCR_DC) && arm_mmu_idx_is_stage1_of_2(mmu_idx)) { - /* HCR.DC means SCTLR_EL1.M behaves as 0 */ - return true; - } - - return (regime_sctlr(env, mmu_idx) & SCTLR_M) =3D=3D 0; -} - /* Convert a possible stage1+2 MMU index into the appropriate * stage 1 MMU index */ diff --git a/target/arm/ptw.c b/target/arm/ptw.c index dc559e6bdf..ec60afd9bf 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -12,7 +12,6 @@ #include "cpu.h" #include "internals.h" #include "idau.h" -#include "ptw.h" =20 =20 static bool get_phys_addr_lpae(CPUARMState *env, uint64_t address, @@ -91,6 +90,52 @@ static uint64_t regime_ttbr(CPUARMState *env, ARMMMUIdx = mmu_idx, int ttbrn) } } =20 +/* Return true if the specified stage of address translation is disabled */ +static bool regime_translation_disabled(CPUARMState *env, ARMMMUIdx mmu_id= x) +{ + uint64_t hcr_el2; + + if (arm_feature(env, ARM_FEATURE_M)) { + switch (env->v7m.mpu_ctrl[regime_is_secure(env, mmu_idx)] & + (R_V7M_MPU_CTRL_ENABLE_MASK | R_V7M_MPU_CTRL_HFNMIENA_MASK= )) { + case R_V7M_MPU_CTRL_ENABLE_MASK: + /* Enabled, but not for HardFault and NMI */ + return mmu_idx & ARM_MMU_IDX_M_NEGPRI; + case R_V7M_MPU_CTRL_ENABLE_MASK | R_V7M_MPU_CTRL_HFNMIENA_MASK: + /* Enabled for all cases */ + return false; + case 0: + default: + /* + * HFNMIENA set and ENABLE clear is UNPREDICTABLE, but + * we warned about that in armv7m_nvic.c when the guest set it. + */ + return true; + } + } + + hcr_el2 =3D arm_hcr_el2_eff(env); + + if (mmu_idx =3D=3D ARMMMUIdx_Stage2 || mmu_idx =3D=3D ARMMMUIdx_Stage2= _S) { + /* HCR.DC means HCR.VM behaves as 1 */ + return (hcr_el2 & (HCR_DC | HCR_VM)) =3D=3D 0; + } + + if (hcr_el2 & HCR_TGE) { + /* TGE means that NS EL0/1 act as if SCTLR_EL1.M is zero */ + if (!regime_is_secure(env, mmu_idx) && regime_el(env, mmu_idx) =3D= =3D 1) { + return true; + } + } + + if ((hcr_el2 & HCR_DC) && arm_mmu_idx_is_stage1_of_2(mmu_idx)) { + /* HCR.DC means SCTLR_EL1.M behaves as 0 */ + return true; + } + + return (regime_sctlr(env, mmu_idx) & SCTLR_M) =3D=3D 0; +} + static bool ptw_attrs_are_device(CPUARMState *env, ARMCacheAttrs cacheattr= s) { /* --=20 2.34.1 From nobody Fri May 17 05:50:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1654317157; cv=none; d=zohomail.com; s=zohoarc; b=hcOORD1gjhKISnHPPx9bzcKRpvVZKDbTYDSqVwGMBeZXgZjpD2jiWLtF7MSao5eLdwk6qYWEQ7Pmdv/qcR84MjL+J0u+Km1ZedQqE6xA2StSOSEEdUJsiIeyX1qJbi8O7PXT7eZp0g+QXlOTd5qo3hfhBe7CLfZ4jSEDfVU5Y/w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1654317157; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=0V/cRerK3utKUgc+h6XMR5lrbyMMtBcUkcTnLi1nxw0=; b=mtg5MWRc9VYke530tOacNx+Cdsu9sFyWIDwYHh7ZUXMF1rZVuZRGSJGk8F3OiEMhW89WDe9m7HQPuYdEwAbliNTDYTIAL4wqRQZuUP++D2ZWrrw6DL8M4AV6ZbizqKDYieExKGsfTU1rsuaKFxPYiWOIOFdFMFeXdaAzLtZndn8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1654317156994271.22904095401134; Fri, 3 Jun 2022 21:32:36 -0700 (PDT) Received: from localhost ([::1]:36060 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nxLSl-0000FK-F0 for importer@patchew.org; Sat, 04 Jun 2022 00:32:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37236) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nxL3b-00008B-Gz for qemu-devel@nongnu.org; Sat, 04 Jun 2022 00:06:35 -0400 Received: from mail-pj1-x1030.google.com ([2607:f8b0:4864:20::1030]:37868) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nxL3Z-00006u-W1 for qemu-devel@nongnu.org; Sat, 04 Jun 2022 00:06:35 -0400 Received: by mail-pj1-x1030.google.com with SMTP id 3-20020a17090a174300b001e426a02ac5so10351951pjm.2 for ; Fri, 03 Jun 2022 21:06:33 -0700 (PDT) Received: from stoup.. ([2602:ae:1547:e101:3286:cc26:3d5e:3f94]) by smtp.gmail.com with ESMTPSA id a37-20020a631a65000000b003c14af50626sm6093779pgm.62.2022.06.03.21.06.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jun 2022 21:06:32 -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=0V/cRerK3utKUgc+h6XMR5lrbyMMtBcUkcTnLi1nxw0=; b=A/VR0+df9og6A9wZN4lCp5JHS2Q5KLYaYEE2/vraJblBWb+KIUD1cfyZxRod7OX59o na+zGWaS8vW/ESgKS1c+nVu/bcq5OkGMJuVGhg90m1vOIJsRGIWRIZ6moe6D0Mk7bmGF tGr1z+zNfTr2q27QdyXDRugeswfs0GxlKPpG7/u8TXMVPAHvyFe6/UVb6MEbHZ5uGjyY u8fhTPmPtwlqSqcG1jXe9NeB7M3pIwdNl8CHMvqzWt32vPxKSfkD4r9Se5t28vLhGTK6 c0fiEvQExMj9PbW8vJmb9eNyLXUlFk1pGzI6H2QGlAzDTv6NaybMA0AuRLeZ3tk4OGNT mu2A== 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=0V/cRerK3utKUgc+h6XMR5lrbyMMtBcUkcTnLi1nxw0=; b=auAcm9xCyjyZvhzWyhDz3WHmzNqnK3gpSRkrWLOQqYt2Jq7AJXhqfgI42SkFK7f7C/ ns1aQ3A730tMSEu3tvfpKe3/3LR8ShBpU3HmcCLAhtnkHKzTMNsi1tp4usOw9O3HSe/J fqiW+TRqJ3HDX8nOAb+1HDrdGlG2bayAiYw/VdPknjuLahbZm3d0T62gxgM6qCUO/8t5 ZQnPBzRsWcMJUEmPhdzKZx4hO1CNtKG/22V5Zod9COu9EBnZVTDlneOYxdN449oIuSWh WLVCbhV60wlJUuD542zq+IhjgFj1gJUDB/zDRHflRNcTOnre6riDqxyeZM9RZf0FQVr4 2Ndg== X-Gm-Message-State: AOAM530eQMfMgbW9FF2dAF/h05PRgEjqSPeBnBUCqB62jQnlNzYNWznP SKa14vRAJwA4RmdbfUyZnjCuFyQJhUGLww== X-Google-Smtp-Source: ABdhPJwDgSigDHM+mdA0/hHza1tJUcU+bQV0Y52tZKglm4n/GG8tNl1cpKhu4SffkAtU4gV2ihzNqQ== X-Received: by 2002:a17:902:e888:b0:163:f3e5:b379 with SMTP id w8-20020a170902e88800b00163f3e5b379mr13235944plg.62.1654315593138; Fri, 03 Jun 2022 21:06:33 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Subject: [PATCH 26/28] target/arm: Move arm_cpu_get_phys_page_attrs_debug to ptw.c Date: Fri, 3 Jun 2022 21:06:05 -0700 Message-Id: <20220604040607.269301-27-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220604040607.269301-1-richard.henderson@linaro.org> References: <20220604040607.269301-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=2607:f8b0:4864:20::1030; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1030.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=ham 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1654317158550100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Richard Henderson --- target/arm/helper.c | 26 -------------------------- target/arm/ptw.c | 24 ++++++++++++++++++++++++ 2 files changed, 24 insertions(+), 26 deletions(-) diff --git a/target/arm/helper.c b/target/arm/helper.c index 7390798463..1c75962a3b 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -10570,32 +10570,6 @@ ARMVAParameters aa64_va_parameters(CPUARMState *en= v, uint64_t va, }; } =20 -#ifndef CONFIG_USER_ONLY -hwaddr arm_cpu_get_phys_page_attrs_debug(CPUState *cs, vaddr addr, - MemTxAttrs *attrs) -{ - ARMCPU *cpu =3D ARM_CPU(cs); - CPUARMState *env =3D &cpu->env; - hwaddr phys_addr; - target_ulong page_size; - int prot; - bool ret; - ARMMMUFaultInfo fi =3D {}; - ARMMMUIdx mmu_idx =3D arm_mmu_idx(env); - ARMCacheAttrs cacheattrs =3D {}; - - *attrs =3D (MemTxAttrs) {}; - - ret =3D get_phys_addr(env, addr, MMU_DATA_LOAD, mmu_idx, &phys_addr, - attrs, &prot, &page_size, &fi, &cacheattrs); - - if (ret) { - return -1; - } - return phys_addr; -} -#endif - /* Note that signed overflow is undefined in C. The following routines are careful to use unsigned types where modulo arithmetic is required. Failure to do so _will_ break on newer gcc. */ diff --git a/target/arm/ptw.c b/target/arm/ptw.c index ec60afd9bf..e9f6870d0a 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -2491,3 +2491,27 @@ bool get_phys_addr(CPUARMState *env, target_ulong ad= dress, phys_ptr, prot, page_size, fi); } } + +hwaddr arm_cpu_get_phys_page_attrs_debug(CPUState *cs, vaddr addr, + MemTxAttrs *attrs) +{ + ARMCPU *cpu =3D ARM_CPU(cs); + CPUARMState *env =3D &cpu->env; + hwaddr phys_addr; + target_ulong page_size; + int prot; + bool ret; + ARMMMUFaultInfo fi =3D {}; + ARMMMUIdx mmu_idx =3D arm_mmu_idx(env); + ARMCacheAttrs cacheattrs =3D {}; + + *attrs =3D (MemTxAttrs) {}; + + ret =3D get_phys_addr(env, addr, MMU_DATA_LOAD, mmu_idx, &phys_addr, + attrs, &prot, &page_size, &fi, &cacheattrs); + + if (ret) { + return -1; + } + return phys_addr; +} --=20 2.34.1 From nobody Fri May 17 05:50:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1654317493; cv=none; d=zohomail.com; s=zohoarc; b=Yv29FJkKummGrGkG9s2tldMk5YS8t+TBSI2y++fSv/aoF5VvjACO9Q/lJyKsF3VY2ShIVzNHR8wGcNhHKWy+S1bArYoJRWUBMCN6HYcyRVcC3TMK9Z9EHVAD5no8b+4bah/8P3ulIzZK0v/UySQbt153L0xUvsuA99lkTHApK/Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1654317493; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=5sl9gLz55OAPAQErBGvbxfcLL/+qUiy1+18KidfepAw=; b=GzwtgtuvagI4Fs/IDU5vMICVrr4XL7KM5cOIfeynx+YwZ8+NO+DtoWDHT6iB6lnrSEKAPCKrq64yuaV1WwYeIrII3iJ3Pe4+mO52oSkd5OGKu8Ow6Qy2V6rN9VhRHqYrxYOVRGRP3843NIwsHyYCAJAQjwSf0W44cIAWgqyxMBI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1654317493778395.405369576171; Fri, 3 Jun 2022 21:38:13 -0700 (PDT) Received: from localhost ([::1]:43620 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nxLYC-0005Z2-A0 for importer@patchew.org; Sat, 04 Jun 2022 00:38:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37284) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nxL3c-0000DB-SU for qemu-devel@nongnu.org; Sat, 04 Jun 2022 00:06:36 -0400 Received: from mail-pf1-x430.google.com ([2607:f8b0:4864:20::430]:40704) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nxL3b-0000E3-9Z for qemu-devel@nongnu.org; Sat, 04 Jun 2022 00:06:36 -0400 Received: by mail-pf1-x430.google.com with SMTP id z17so8536601pff.7 for ; Fri, 03 Jun 2022 21:06:34 -0700 (PDT) Received: from stoup.. ([2602:ae:1547:e101:3286:cc26:3d5e:3f94]) by smtp.gmail.com with ESMTPSA id a37-20020a631a65000000b003c14af50626sm6093779pgm.62.2022.06.03.21.06.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jun 2022 21:06:33 -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=5sl9gLz55OAPAQErBGvbxfcLL/+qUiy1+18KidfepAw=; b=Ohr6uolozazipRZkgiFIlqcuoqIDCbB+Ip7jhAALyY5xZlHUMmK8WsZvfcT9kQCabD b8FQ0+BW4ZDFnat7GcuhuyLx+iEY6pKeS2LPJOvhHtXQNu6NqgbRniAvwi4t09yVu6be /2PtnwFP4gRBuTD9f6w+Q2KMIHOs42U3aC2x0/KiCXrUpHa3ZTZ5UpDoF7PLOJmMAe1g bgf0BmxwnUB6J980DjXYvBGfgJkBKauZ+fJK1FUUmfSVvBU1yysVAYYEHgqabLMM/pfU DSrN21C56GpKYQa5S2SyjSjKER8msAVZReIZeYdyytZlu4z4pWN/BUHXl6l/flUEQ3rZ yYfg== 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=5sl9gLz55OAPAQErBGvbxfcLL/+qUiy1+18KidfepAw=; b=mMed2ImcDYbZBJqTKgyRYXSwMddohE8Bm5FC/d7QPKSKw873ckodvcMI4vHZ9QLK8A xfSncNFxrVI+hd2rrFU08PHAlHPpUYNUX9EueMsYElos6uDDsEPRVyhkfGT77CS2Hyts u5Ilc4lWX48R1XcP2vsIlW0LFIB9QfSh7deilnMYgB/9gueIxkigBT6avJkWiHx/5u3R 8f46nRZbzuxYMigsgC1lKQKiLiN0PQbvHUEc+GiGft2FXQN9Vlj5Hezic2QTEfJNml20 XHwzIrFjgtofFZ6h7/YuN5ydylKkIyVdb1EWMOgvjlVUD6AIVjUsnEfsMd0BNvAdTUmC m+lQ== X-Gm-Message-State: AOAM533YAQ0vId2mxqI9i450W2tYYDHWSIG3ATco71mHzRsXedliwJtf osZIX5qVCREHrlZJTf53LuUXwjmkf8rCPQ== X-Google-Smtp-Source: ABdhPJyObY6GDeeH4On3nLBo4728OIOe0U/+85dXk+tGzfWOifqxCPafO+VDMWMy0oMSimOMuYhSug== X-Received: by 2002:a62:db81:0:b0:51b:ed38:c409 with SMTP id f123-20020a62db81000000b0051bed38c409mr3585873pfg.37.1654315593937; Fri, 03 Jun 2022 21:06:33 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Subject: [PATCH 27/28] target/arm: Move stage_1_mmu_idx, arm_stage1_mmu_idx to ptw.c Date: Fri, 3 Jun 2022 21:06:06 -0700 Message-Id: <20220604040607.269301-28-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220604040607.269301-1-richard.henderson@linaro.org> References: <20220604040607.269301-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=2607:f8b0:4864:20::430; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x430.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=ham 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1654317494308100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Richard Henderson --- target/arm/helper.c | 32 -------------------------------- target/arm/ptw.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 32 deletions(-) diff --git a/target/arm/helper.c b/target/arm/helper.c index 1c75962a3b..1018cd24eb 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -10391,31 +10391,6 @@ uint64_t arm_sctlr(CPUARMState *env, int el) return env->cp15.sctlr_el[el]; } =20 -#ifndef CONFIG_USER_ONLY -/* Convert a possible stage1+2 MMU index into the appropriate - * stage 1 MMU index - */ -ARMMMUIdx stage_1_mmu_idx(ARMMMUIdx mmu_idx) -{ - switch (mmu_idx) { - case ARMMMUIdx_SE10_0: - return ARMMMUIdx_Stage1_SE0; - case ARMMMUIdx_SE10_1: - return ARMMMUIdx_Stage1_SE1; - case ARMMMUIdx_SE10_1_PAN: - return ARMMMUIdx_Stage1_SE1_PAN; - case ARMMMUIdx_E10_0: - return ARMMMUIdx_Stage1_E0; - case ARMMMUIdx_E10_1: - return ARMMMUIdx_Stage1_E1; - case ARMMMUIdx_E10_1_PAN: - return ARMMMUIdx_Stage1_E1_PAN; - default: - return mmu_idx; - } -} -#endif /* !CONFIG_USER_ONLY */ - int aa64_va_parameter_tbi(uint64_t tcr, ARMMMUIdx mmu_idx) { if (regime_has_2_ranges(mmu_idx)) { @@ -11045,13 +11020,6 @@ ARMMMUIdx arm_mmu_idx(CPUARMState *env) return arm_mmu_idx_el(env, arm_current_el(env)); } =20 -#ifndef CONFIG_USER_ONLY -ARMMMUIdx arm_stage1_mmu_idx(CPUARMState *env) -{ - return stage_1_mmu_idx(arm_mmu_idx(env)); -} -#endif - static CPUARMTBFlags rebuild_hflags_common(CPUARMState *env, int fp_el, ARMMMUIdx mmu_idx, CPUARMTBFlags flags) diff --git a/target/arm/ptw.c b/target/arm/ptw.c index e9f6870d0a..49e9a1d108 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -47,6 +47,34 @@ unsigned int arm_pamax(ARMCPU *cpu) return pamax_map[parange]; } =20 +/* + * Convert a possible stage1+2 MMU index into the appropriate stage 1 MMU = index + */ +ARMMMUIdx stage_1_mmu_idx(ARMMMUIdx mmu_idx) +{ + switch (mmu_idx) { + case ARMMMUIdx_SE10_0: + return ARMMMUIdx_Stage1_SE0; + case ARMMMUIdx_SE10_1: + return ARMMMUIdx_Stage1_SE1; + case ARMMMUIdx_SE10_1_PAN: + return ARMMMUIdx_Stage1_SE1_PAN; + case ARMMMUIdx_E10_0: + return ARMMMUIdx_Stage1_E0; + case ARMMMUIdx_E10_1: + return ARMMMUIdx_Stage1_E1; + case ARMMMUIdx_E10_1_PAN: + return ARMMMUIdx_Stage1_E1_PAN; + default: + return mmu_idx; + } +} + +ARMMMUIdx arm_stage1_mmu_idx(CPUARMState *env) +{ + return stage_1_mmu_idx(arm_mmu_idx(env)); +} + static bool regime_translation_big_endian(CPUARMState *env, ARMMMUIdx mmu_= idx) { return (regime_sctlr(env, mmu_idx) & SCTLR_EE) !=3D 0; --=20 2.34.1 From nobody Fri May 17 05:50:23 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1654317808; cv=none; d=zohomail.com; s=zohoarc; b=CcRmloL6a4DORar5XJchI/i6n69j7I8cgb7EhTrKMH+Yv8i/mZ/EHowlnCN43Gxzlubom7TF2awN7TaUmInhGVW1xinccvS5Y8dAW6ghabgVkeG29qWnFj95eGZcac+S76XfuVYL8efAaWoAatEkKlmFX+3SX9sBqYw1Xja0xrI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1654317808; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=3nHmctdTM0Wz3l6IJSRdIRxCF9GcdCYO2x/ZBvhVz9w=; b=SzaUa4oJr4oyC0i+CgV31gzyBRChDcv6Plmin34i2X2fpc742RegW+bQnq4TlWspDpDJ/6fOV3swK2mafVgFrFIUaLX5IUGwpm6V2ODYhtwcarYJifmFbbbiJ6OZq9Kg4NIpHZshyWdetb9VUz1HUidzZu2pqdE+qJExTmBln/c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1654317807902344.01173409849605; Fri, 3 Jun 2022 21:43:27 -0700 (PDT) Received: from localhost ([::1]:50018 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nxLdG-0001ZY-Dx for importer@patchew.org; Sat, 04 Jun 2022 00:43:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37302) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nxL3e-0000HL-Ml for qemu-devel@nongnu.org; Sat, 04 Jun 2022 00:06:38 -0400 Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]:55160) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nxL3b-0008Uy-Hc for qemu-devel@nongnu.org; Sat, 04 Jun 2022 00:06:38 -0400 Received: by mail-pj1-x1035.google.com with SMTP id j7so8692071pjn.4 for ; Fri, 03 Jun 2022 21:06:35 -0700 (PDT) Received: from stoup.. ([2602:ae:1547:e101:3286:cc26:3d5e:3f94]) by smtp.gmail.com with ESMTPSA id a37-20020a631a65000000b003c14af50626sm6093779pgm.62.2022.06.03.21.06.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jun 2022 21:06:34 -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=3nHmctdTM0Wz3l6IJSRdIRxCF9GcdCYO2x/ZBvhVz9w=; b=aXzhVQg2ZbWi5Wa/x78NPnlODX6YRmwAY0o+sYCdKbe0jSoQes2+Vzb7EMEjL2ZbXV pUJnPG38N/s5nV2M8UFlx/TumEoRW6FoEunpnxg2StLCSHG7WRDFT1jytYngT1KeWe8o 9QgZJIITsHWWDPoz0StwRtRRWT5Imw5/TkykHDY/nuqNHjnNsqDOBhE7Pb95+bgtVNj3 Gf97v0k61Uwxs3RSgTgolKRtA/L/36dwcI/qXh2U3tcDqASAQTANMW2G3CSZUqPDIQ9D asuo/ipREjsh5V3OAzzb6avGicvukJHx5H+XcKtSJbY92EUEw8ZEbsXw5FTpT25EhQIM q8zQ== 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=3nHmctdTM0Wz3l6IJSRdIRxCF9GcdCYO2x/ZBvhVz9w=; b=zKigIExxZoNr6EARxtFGJHt+Qn9+boYvuDUuWCmGtTqpI58O3lp07klPvGImdycdnR BibTEgknb0inWaIJlMRGjsp5lQyEVYHckZJdopaQELGNspiqMWTI3RVqzwCMxkTP/Jnl wIN4+/L/EBS0WZa66pqrquNui13wVllxDFRTUS38hnWny9uZbK/E8cVooMuAWOYWF+Ie 8e0hpq5WP4LMlcvTG+vXJX06apZwa52X+VrK+wzY3OMcb1uO07VKdcpF70HmZwqMJ2ac pjdrBAYyNhGaK5HioKJJb/EHe1W7Q3+zlLXjJyWmyV4bvU9pcb6Y/C4JgMJDqgXrY9yg B/QA== X-Gm-Message-State: AOAM533G5iuLWY7wA09rmSQKz4KY35V3kKlzQIcahBQQ5Vb7YhGlV0el cOTCludU3LXSYZEWpsKTZKlZmkiU3NVqXQ== X-Google-Smtp-Source: ABdhPJwh0RRLcpPQ7dRRSA9eeuBF+KYu/a9l0FdOqjdAeepbnfNdvRzApuSTs22GrmDeAFQnPETqSg== X-Received: by 2002:a17:902:7149:b0:166:4e68:5c41 with SMTP id u9-20020a170902714900b001664e685c41mr8837281plm.25.1654315594672; Fri, 03 Jun 2022 21:06:34 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Subject: [PATCH 28/28] target/arm: Pass CPUARMState to arm_ld[lq]_ptw Date: Fri, 3 Jun 2022 21:06:07 -0700 Message-Id: <20220604040607.269301-29-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220604040607.269301-1-richard.henderson@linaro.org> References: <20220604040607.269301-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=2607:f8b0:4864:20::1035; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1035.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=ham 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1654317810125100001 Content-Type: text/plain; charset="utf-8" The use of ARM_CPU to recover env from cs calls object_class_dynamic_cast, which shows up on the profile. This is pointless, because all callers already have env, and the reverse operation, env_cpu, is only pointer arithmetic. Signed-off-by: Richard Henderson --- target/arm/ptw.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/target/arm/ptw.c b/target/arm/ptw.c index 49e9a1d108..4d97a24808 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -241,11 +241,10 @@ static hwaddr S1_ptw_translate(CPUARMState *env, ARMM= MUIdx mmu_idx, } =20 /* All loads done in the course of a page table walk go through here. */ -static uint32_t arm_ldl_ptw(CPUState *cs, hwaddr addr, bool is_secure, +static uint32_t arm_ldl_ptw(CPUARMState *env, hwaddr addr, bool is_secure, ARMMMUIdx mmu_idx, ARMMMUFaultInfo *fi) { - ARMCPU *cpu =3D ARM_CPU(cs); - CPUARMState *env =3D &cpu->env; + CPUState *cs =3D env_cpu(env); MemTxAttrs attrs =3D {}; MemTxResult result =3D MEMTX_OK; AddressSpace *as; @@ -270,11 +269,10 @@ static uint32_t arm_ldl_ptw(CPUState *cs, hwaddr addr= , bool is_secure, return 0; } =20 -static uint64_t arm_ldq_ptw(CPUState *cs, hwaddr addr, bool is_secure, +static uint64_t arm_ldq_ptw(CPUARMState *env, hwaddr addr, bool is_secure, ARMMMUIdx mmu_idx, ARMMMUFaultInfo *fi) { - ARMCPU *cpu =3D ARM_CPU(cs); - CPUARMState *env =3D &cpu->env; + CPUState *cs =3D env_cpu(env); MemTxAttrs attrs =3D {}; MemTxResult result =3D MEMTX_OK; AddressSpace *as; @@ -409,7 +407,6 @@ static bool get_phys_addr_v5(CPUARMState *env, uint32_t= address, target_ulong *page_size, ARMMMUFaultInfo *fi) { - CPUState *cs =3D env_cpu(env); int level =3D 1; uint32_t table; uint32_t desc; @@ -427,7 +424,7 @@ static bool get_phys_addr_v5(CPUARMState *env, uint32_t= address, fi->type =3D ARMFault_Translation; goto do_fault; } - desc =3D arm_ldl_ptw(cs, table, regime_is_secure(env, mmu_idx), + desc =3D arm_ldl_ptw(env, table, regime_is_secure(env, mmu_idx), mmu_idx, fi); if (fi->type !=3D ARMFault_None) { goto do_fault; @@ -466,7 +463,7 @@ static bool get_phys_addr_v5(CPUARMState *env, uint32_t= address, /* Fine pagetable. */ table =3D (desc & 0xfffff000) | ((address >> 8) & 0xffc); } - desc =3D arm_ldl_ptw(cs, table, regime_is_secure(env, mmu_idx), + desc =3D arm_ldl_ptw(env, table, regime_is_secure(env, mmu_idx), mmu_idx, fi); if (fi->type !=3D ARMFault_None) { goto do_fault; @@ -531,7 +528,6 @@ static bool get_phys_addr_v6(CPUARMState *env, uint32_t= address, hwaddr *phys_ptr, MemTxAttrs *attrs, int *pro= t, target_ulong *page_size, ARMMMUFaultInfo *fi) { - CPUState *cs =3D env_cpu(env); ARMCPU *cpu =3D env_archcpu(env); int level =3D 1; uint32_t table; @@ -553,7 +549,7 @@ static bool get_phys_addr_v6(CPUARMState *env, uint32_t= address, fi->type =3D ARMFault_Translation; goto do_fault; } - desc =3D arm_ldl_ptw(cs, table, regime_is_secure(env, mmu_idx), + desc =3D arm_ldl_ptw(env, table, regime_is_secure(env, mmu_idx), mmu_idx, fi); if (fi->type !=3D ARMFault_None) { goto do_fault; @@ -607,7 +603,7 @@ static bool get_phys_addr_v6(CPUARMState *env, uint32_t= address, ns =3D extract32(desc, 3, 1); /* Lookup l2 entry. */ table =3D (desc & 0xfffffc00) | ((address >> 10) & 0x3fc); - desc =3D arm_ldl_ptw(cs, table, regime_is_secure(env, mmu_idx), + desc =3D arm_ldl_ptw(env, table, regime_is_secure(env, mmu_idx), mmu_idx, fi); if (fi->type !=3D ARMFault_None) { goto do_fault; @@ -973,7 +969,6 @@ static bool get_phys_addr_lpae(CPUARMState *env, uint64= _t address, ARMMMUFaultInfo *fi, ARMCacheAttrs *cacheat= trs) { ARMCPU *cpu =3D env_archcpu(env); - CPUState *cs =3D CPU(cpu); /* Read an LPAE long-descriptor translation table. */ ARMFaultType fault_type =3D ARMFault_Translation; uint32_t level; @@ -1196,7 +1191,7 @@ static bool get_phys_addr_lpae(CPUARMState *env, uint= 64_t address, descaddr |=3D (address >> (stride * (4 - level))) & indexmask; descaddr &=3D ~7ULL; nstable =3D extract32(tableattrs, 4, 1); - descriptor =3D arm_ldq_ptw(cs, descaddr, !nstable, mmu_idx, fi); + descriptor =3D arm_ldq_ptw(env, descaddr, !nstable, mmu_idx, fi); if (fi->type !=3D ARMFault_None) { goto do_fault; } --=20 2.34.1