From patchwork Thu Oct 20 12:21:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 616778 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp315605pvb; Thu, 20 Oct 2022 07:51:57 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7msl519/ZkdrSsF5w0s4BzPVMEXmF65GDUF4X0OnXMOGWG/7hgk4dV5iqHrUjYkbYalath X-Received: by 2002:a05:620a:45a4:b0:6ee:d0a5:16f8 with SMTP id bp36-20020a05620a45a400b006eed0a516f8mr9610165qkb.270.1666277517788; Thu, 20 Oct 2022 07:51:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666277517; cv=none; d=google.com; s=arc-20160816; b=x9Cvw7gUHOo+dwnyNWiMpO+T1Kb2pP+ZouB7s0jzF8RsWHEawVVMaS0zul+QsTYa6s fYYJgf9tQUITURXj/8bkIkUGaKwLGaJi9CSZpwswiV+E760wSlUXmuuKIVE8SsafT0Qw 6R78FSAy9VaP0PS/c+r9+QAadbT9bfQmMa3SePwNOQyX7WRd0Vqv0dH353zrPl4SyR3z i5vXJCdmJFK+o8DKJDDEI0FbrSHT3SQdd/Glk8sKqITYUj4lFcdt9WFzEA8CRegOw2ce q5d0SDDYkVWiJNm8QZsb9yvbA13Olo1yJMISb3tdrKt6PGQqKjTmkzyF+EiYf4y8qj9t HVpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=3O+4MnJv0rRyn/a/QFn0L+UaRzjg4a2Dnz6YCScVZBo=; b=yVxsw6EphYzw+yPsv4iGu1oMlgfbITgmiB9weW4/7d3N9P0yfJqdVoP/NTU57pbwbO MNtTpbLlGpct375zINsKMwgbdAwaMTNK3g3Rvrfrvr05AJ+KgPsoPH3iytCkjrzgDNYO c41THGlIyii7+4R1KpYfXPgJqGXTKDPY5CMM5JtirfpiYlth0KYuVp5J88W4L42ChISq ZclFoMYZyUkpHY0hKuQR3J8Aj0MvRPW1lVf1D9UFFPQRuH4YzNSYf7l1Udf0005VVtlp VUH/bsAw9lw/M0Mso27hiyvtk6X3OmvStXmHw6bgQajoiClK1LcM1UXfn7cUWphKVgzR B2eQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mn38bEqU; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id c6-20020ac81e86000000b0039c004a481fsi12076977qtm.332.2022.10.20.07.51.57 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 20 Oct 2022 07:51:57 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mn38bEqU; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:33856 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1olWto-0007yo-Rj for patch@linaro.org; Thu, 20 Oct 2022 10:51:56 -0400 Received: from [::1] (helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1olWgJ-0007e0-VS for patch@linaro.org; Thu, 20 Oct 2022 10:38:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58176) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1olUZJ-0001aq-NG for qemu-devel@nongnu.org; Thu, 20 Oct 2022 08:23:00 -0400 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]:53054) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1olUYy-000130-9G for qemu-devel@nongnu.org; Thu, 20 Oct 2022 08:22:30 -0400 Received: by mail-wm1-x32f.google.com with SMTP id l32so14785502wms.2 for ; Thu, 20 Oct 2022 05:22:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=3O+4MnJv0rRyn/a/QFn0L+UaRzjg4a2Dnz6YCScVZBo=; b=mn38bEqUWbCwVTttS5hf5CZC4xnK+l7eRK5MCjNkrjP8ZjgJqK3ydsJCW4Ld0sPp73 kWoEspf52t3oMwqJdHdWT3VaKRmjUvs0cX5wt+svRj5nBY1ILYNHoQMmfcAnQ0t+VSCM uCQf7d9jFWG6KwWT71igXNye4TlR/a6CFr2DP5Cxxn78b1ZryEu4kHelWYVAHimHtKp7 H47TJswBttuJ2sbUIwX3KBr+VG3SQo07yozHsT/+jD1yFzsTCHmYr3KjkpAcGDX6iRvX f5/B3vfObnq5ru+mWV7qQK/QweGD/wHhLw6DIkbQfqMLAKQqJ54xSOwY4d69AnYsihG3 1ouA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3O+4MnJv0rRyn/a/QFn0L+UaRzjg4a2Dnz6YCScVZBo=; b=1/69qnMBlPHE2ERYQMIpYzzyxQDxDB4bcOflcsl6IphzB/8cHL2CgQ3mW1HZ37guM/ GU9XepLymtlieC0zvKkl7XuG4S/anXpOhXdXrrcMwmQUel1fcc7xvbZhmtJjvIqVsrSy WF8U+NWCodNW6MmnVuFhaUfmhH+QZzBqKhzODM+hmDRCIzD03RVEqsTgSoqgJ675q5J5 Lc0VZxxd8V3qAD9PnAlZ3ZPzmbuohCK2LcBzfYbyMwptWIKQMUAs/LgAKgDrZEucFc8+ 7VSLNGtKkjbI4YzXoBkxjjoa8+HF9uAVl06AzRp0nsksws728M/WAG8SY1uPFLn54nH0 WCRw== X-Gm-Message-State: ACrzQf3Tbh9WTKOAfgPbSCqlvYb0wkywyfnE5gBvOQw9csfqQwLhF7Lr SmQaCM0st9hHVwaH1FwG1WHimSxXbd+cRg== X-Received: by 2002:a05:600c:6890:b0:3c6:c323:878d with SMTP id fn16-20020a05600c689000b003c6c323878dmr29609333wmb.87.1666268525770; Thu, 20 Oct 2022 05:22:05 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id t15-20020a5d49cf000000b00230c9d427f9sm16520192wrs.53.2022.10.20.05.22.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Oct 2022 05:22:05 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 13/24] target/arm: Split out get_phys_addr_twostage Date: Thu, 20 Oct 2022 13:21:35 +0100 Message-Id: <20221020122146.3177980-14-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221020122146.3177980-1-peter.maydell@linaro.org> References: <20221020122146.3177980-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32f; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x32f.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 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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson Message-id: 20221011031911.2408754-12-richard.henderson@linaro.org Signed-off-by: Peter Maydell --- target/arm/ptw.c | 191 +++++++++++++++++++++++++---------------------- 1 file changed, 100 insertions(+), 91 deletions(-) diff --git a/target/arm/ptw.c b/target/arm/ptw.c index 8f41d285b7d..dd6556560af 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -31,6 +31,13 @@ static bool get_phys_addr_lpae(CPUARMState *env, S1Translate *ptw, GetPhysAddrResult *result, ARMMMUFaultInfo *fi) __attribute__((nonnull)); +static bool get_phys_addr_with_struct(CPUARMState *env, S1Translate *ptw, + target_ulong address, + MMUAccessType access_type, + GetPhysAddrResult *result, + ARMMMUFaultInfo *fi) + __attribute__((nonnull)); + /* This mapping is common between ID_AA64MMFR0.PARANGE and TCR_ELx.{I}PS. */ static const uint8_t pamax_map[] = { [0] = 32, @@ -2428,6 +2435,94 @@ static bool get_phys_addr_disabled(CPUARMState *env, target_ulong address, return 0; } +static bool get_phys_addr_twostage(CPUARMState *env, S1Translate *ptw, + target_ulong address, + MMUAccessType access_type, + GetPhysAddrResult *result, + ARMMMUFaultInfo *fi) +{ + hwaddr ipa; + int s1_prot; + int ret; + bool is_secure = ptw->in_secure; + bool ipa_secure, s2walk_secure; + ARMCacheAttrs cacheattrs1; + bool is_el0; + uint64_t hcr; + + ret = get_phys_addr_with_struct(env, ptw, address, access_type, result, fi); + + /* If S1 fails or S2 is disabled, return early. */ + if (ret || regime_translation_disabled(env, ARMMMUIdx_Stage2, is_secure)) { + return ret; + } + + ipa = result->f.phys_addr; + ipa_secure = result->f.attrs.secure; + if (is_secure) { + /* Select TCR based on the NS bit from the S1 walk. */ + s2walk_secure = !(ipa_secure + ? env->cp15.vstcr_el2 & VSTCR_SW + : env->cp15.vtcr_el2 & VTCR_NSW); + } else { + assert(!ipa_secure); + s2walk_secure = false; + } + + is_el0 = ptw->in_mmu_idx == ARMMMUIdx_Stage1_E0; + ptw->in_mmu_idx = s2walk_secure ? ARMMMUIdx_Stage2_S : ARMMMUIdx_Stage2; + ptw->in_secure = s2walk_secure; + + /* + * S1 is done, now do S2 translation. + * Save the stage1 results so that we may merge prot and cacheattrs later. + */ + s1_prot = result->f.prot; + cacheattrs1 = result->cacheattrs; + memset(result, 0, sizeof(*result)); + + ret = get_phys_addr_lpae(env, ptw, ipa, access_type, is_el0, result, fi); + fi->s2addr = ipa; + + /* Combine the S1 and S2 perms. */ + result->f.prot &= s1_prot; + + /* If S2 fails, return early. */ + if (ret) { + return ret; + } + + /* Combine the S1 and S2 cache attributes. */ + hcr = arm_hcr_el2_eff_secstate(env, is_secure); + if (hcr & 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 (cacheattrs1.attrs != 0xf0) { + cacheattrs1.attrs = 0xff; + } + cacheattrs1.shareability = 0; + } + result->cacheattrs = combine_cacheattrs(hcr, cacheattrs1, + result->cacheattrs); + + /* + * Check if IPA translates to secure or non-secure PA space. + * Note that VSTCR overrides VTCR and {N}SW overrides {N}SA. + */ + result->f.attrs.secure = + (is_secure + && !(env->cp15.vstcr_el2 & (VSTCR_SA | VSTCR_SW)) + && (ipa_secure + || !(env->cp15.vtcr_el2 & (VTCR_NSA | VTCR_NSW)))); + + return 0; +} + static bool get_phys_addr_with_struct(CPUARMState *env, S1Translate *ptw, target_ulong address, MMUAccessType access_type, @@ -2441,99 +2536,13 @@ static bool get_phys_addr_with_struct(CPUARMState *env, S1Translate *ptw, if (mmu_idx != s1_mmu_idx) { /* * Call ourselves recursively to do the stage 1 and then stage 2 - * translations if mmu_idx is a two-stage regime. + * translations if mmu_idx is a two-stage regime, and EL2 present. + * Otherwise, a stage1+stage2 translation is just stage 1. */ + ptw->in_mmu_idx = mmu_idx = s1_mmu_idx; if (arm_feature(env, ARM_FEATURE_EL2)) { - hwaddr ipa; - int s1_prot; - int ret; - bool ipa_secure, s2walk_secure; - ARMCacheAttrs cacheattrs1; - bool is_el0; - uint64_t hcr; - - ptw->in_mmu_idx = s1_mmu_idx; - ret = get_phys_addr_with_struct(env, ptw, address, access_type, - result, fi); - - /* If S1 fails or S2 is disabled, return early. */ - if (ret || regime_translation_disabled(env, ARMMMUIdx_Stage2, - is_secure)) { - return ret; - } - - ipa = result->f.phys_addr; - ipa_secure = result->f.attrs.secure; - if (is_secure) { - /* Select TCR based on the NS bit from the S1 walk. */ - s2walk_secure = !(ipa_secure - ? env->cp15.vstcr_el2 & VSTCR_SW - : env->cp15.vtcr_el2 & VTCR_NSW); - } else { - assert(!ipa_secure); - s2walk_secure = false; - } - - ptw->in_mmu_idx = - s2walk_secure ? ARMMMUIdx_Stage2_S : ARMMMUIdx_Stage2; - ptw->in_secure = s2walk_secure; - is_el0 = mmu_idx == ARMMMUIdx_E10_0; - - /* - * S1 is done, now do S2 translation. - * Save the stage1 results so that we may merge - * prot and cacheattrs later. - */ - s1_prot = result->f.prot; - cacheattrs1 = result->cacheattrs; - memset(result, 0, sizeof(*result)); - - ret = get_phys_addr_lpae(env, ptw, ipa, access_type, - is_el0, result, fi); - fi->s2addr = ipa; - - /* Combine the S1 and S2 perms. */ - result->f.prot &= s1_prot; - - /* If S2 fails, return early. */ - if (ret) { - return ret; - } - - /* Combine the S1 and S2 cache attributes. */ - hcr = arm_hcr_el2_eff_secstate(env, is_secure); - if (hcr & 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 (cacheattrs1.attrs != 0xf0) { - cacheattrs1.attrs = 0xff; - } - cacheattrs1.shareability = 0; - } - result->cacheattrs = combine_cacheattrs(hcr, cacheattrs1, - result->cacheattrs); - - /* - * Check if IPA translates to secure or non-secure PA space. - * Note that VSTCR overrides VTCR and {N}SW overrides {N}SA. - */ - result->f.attrs.secure = - (is_secure - && !(env->cp15.vstcr_el2 & (VSTCR_SA | VSTCR_SW)) - && (ipa_secure - || !(env->cp15.vtcr_el2 & (VTCR_NSA | VTCR_NSW)))); - - return 0; - } else { - /* - * For non-EL2 CPUs a stage1+stage2 translation is just stage 1. - */ - mmu_idx = stage_1_mmu_idx(mmu_idx); + return get_phys_addr_twostage(env, ptw, address, access_type, + result, fi); } }