From patchwork Sat Oct 1 16:22:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 611379 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp272759pvb; Sat, 1 Oct 2022 09:25:09 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5wny/JSYPehBjhoChuEklnBohEVh6JQZ8CU2+FjRCZwxv8229hPYUWxMoPfeNM9LOwC73+ X-Received: by 2002:a05:6214:2587:b0:4af:a06f:f5b7 with SMTP id fq7-20020a056214258700b004afa06ff5b7mr11544908qvb.73.1664641509439; Sat, 01 Oct 2022 09:25:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664641509; cv=none; d=google.com; s=arc-20160816; b=bs6BTa7ygcE6STc93RoFDvSUxGAfjr9EBLxnygJdybUG/ViqAGeY+eYTqzvNOgVCLa 7z5iI8+DFomHOtsGAXQJacuKM/ytied0+pTHOexIaWjElBq3lymdnNLBh+04c+8iO0mm 1Yv7pXKdsoX6xnf8zFOtE9gDvjC8mkvPh2wP9V0ue6B55tzbLRy7QdMgVsIlyap+kRKI /U7jjhTaOpUzujPObALrGhXaDcgYZrGjJVErf1JNlkcBekH66OwzgiaKk1N4SVCK3Q5V Xy/9PBbmO225cnMIiWrlD77Dgi1a+wZUxpKHeVSIxcmA/+JXc2+wxMucN+ChmQI/UaPd BgWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=sUrjBJ7dwQzpr5dWkCg6Vpf21komKkvxoPfjuiTQD48=; b=tygEMGcbHIQcwXEfEsa6dQMQQ55xZzQxMhDuJnwPAHOnYuNI9+jntzhX8b5O9xzb4p 1y1KbHARm7Z7iapI+na9uZxeAt5SQCEUdmKQW1YOK6RDps4+tsYJwAdAZUDP40TM6r66 eIaJrMchQU0PSkw6jYaOtdXwBUdpKNd8Y+WCzBDjmorqYuxhVPZP18m9SZ2AtBePhg+K NypuNt5BBMj3Tha7GWMWmk8T3wjkUxRZ7u8e28tv4xMLotZSmms0gPcXKU5BYBOSNTNm Enlrp5mfD94pFyoEncphVyvs17/txf1EY9sgy1zDz5JQ/nxNAtCXKJOaFxqKY0PEbM5b dSCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YqMh1wM8; 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 bj3-20020a05620a190300b006cbbda1a0fbsi2607642qkb.225.2022.10.01.09.25.09 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 01 Oct 2022 09:25:09 -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=YqMh1wM8; 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]:35376 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oefIa-00079a-TQ for patch@linaro.org; Sat, 01 Oct 2022 12:25:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38962) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oefGy-0006GI-KC for qemu-devel@nongnu.org; Sat, 01 Oct 2022 12:23:28 -0400 Received: from mail-qt1-x82e.google.com ([2607:f8b0:4864:20::82e]:42726) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oefGw-0006DO-Ul for qemu-devel@nongnu.org; Sat, 01 Oct 2022 12:23:28 -0400 Received: by mail-qt1-x82e.google.com with SMTP id w2so4334795qtv.9 for ; Sat, 01 Oct 2022 09:23:26 -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:cc:to:from:from:to:cc:subject:date; bh=sUrjBJ7dwQzpr5dWkCg6Vpf21komKkvxoPfjuiTQD48=; b=YqMh1wM8B6us+FgC9F+Y0msBRmrQt9992KTMWlqh0DIfeCSsH2RaKRHxX4GHO1B2KP YBSzOpDuIl9chCQiyY0l2tysMreZRfuxE+LKR6BtRopSCN2uNgyzD65/XpYC2w2xLfq0 FIloio4N2J7DtHgBw45C5cRWWr15dXoSCufl549CTqLNttieMHNapW609i9jCVSDJGwl 7zS2z4NJc6RCDgkLTwqbv2ykps/8HROGUf3EIyvDXXDSqwWcT7VCZ2JzIbhpqcK9cJpG 5f4k59riCZxkg/fMCyzMpTkHknHTm9TvUPPINpef1CUyb4g971sldbKKSHbIVT+AUPsC Mbkw== 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:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=sUrjBJ7dwQzpr5dWkCg6Vpf21komKkvxoPfjuiTQD48=; b=zoP+e+6IrndmO2TcWoiHs158biLFY5gEhajQ8tBwQl+h+svfzJDcRm8rwEAs3YMk4g EQ1hAr+ItT0aBxq697CV4+/bnEDOvVTY7wu0X2mu4ww4cr3Ugc2kVML5Cm51OgWZ355N 69UCG4URdFUSlwc/sGZGVcoMgqmjR15G6LHfibnXvyNv2vTBP9xMbw1+r6ICreIjdkwC Gd3VULsD/3+Gwd0vjre/4xas/fNwwWpr+EI5JFnMI+mP8AWXzVwSKLyfVm2yRf+lcJmr ESbmPYhAEFAAapnJ+MJ3Pbs/+kQilDnBowZRUYyVIidujbce37JmYjIaV7ZNoAYCnFWA 9bWg== X-Gm-Message-State: ACrzQf0eYj7oSEXkp5ODtaTsuNXequDe7isE9zMnBTuaCfscT7eFo2pk vgIBZjniHd8LWajzP4y11sVQ0TsZf8mA7w== X-Received: by 2002:a05:622a:2c8:b0:35d:4b4d:57b0 with SMTP id a8-20020a05622a02c800b0035d4b4d57b0mr11032021qtx.307.1664641405917; Sat, 01 Oct 2022 09:23:25 -0700 (PDT) Received: from stoup.. ([2605:ef80:8084:91a4:f7cb:db31:c505:b931]) by smtp.gmail.com with ESMTPSA id t4-20020a37ea04000000b006d1d8fdea8asm4387445qkj.85.2022.10.01.09.23.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Oct 2022 09:23:25 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Subject: [PATCH v3 01/42] target/arm: Split s2walk_secure from ipa_secure in get_phys_addr Date: Sat, 1 Oct 2022 09:22:37 -0700 Message-Id: <20221001162318.153420-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221001162318.153420-1-richard.henderson@linaro.org> References: <20221001162318.153420-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::82e; envelope-from=richard.henderson@linaro.org; helo=mail-qt1-x82e.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" The starting security state comes with the translation regime, not the current state of arm_is_secure_below_el3(). Create a new local variable, s2walk_secure, which does not need to be written back to result->attrs.secure -- we compute that value later, after the S2 walk is complete. Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- v3: Do not modify ipa_secure, per review. --- target/arm/ptw.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/target/arm/ptw.c b/target/arm/ptw.c index 2ddfc028ab..b8c494ad9f 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -2298,7 +2298,7 @@ bool get_phys_addr(CPUARMState *env, target_ulong address, hwaddr ipa; int s1_prot; int ret; - bool ipa_secure; + bool ipa_secure, s2walk_secure; ARMCacheAttrs cacheattrs1; ARMMMUIdx s2_mmu_idx; bool is_el0; @@ -2313,17 +2313,17 @@ bool get_phys_addr(CPUARMState *env, target_ulong address, ipa = result->phys; ipa_secure = result->attrs.secure; - if (arm_is_secure_below_el3(env)) { - if (ipa_secure) { - result->attrs.secure = !(env->cp15.vstcr_el2 & VSTCR_SW); - } else { - result->attrs.secure = !(env->cp15.vtcr_el2 & VTCR_NSW); - } + 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; } - s2_mmu_idx = (result->attrs.secure + s2_mmu_idx = (s2walk_secure ? ARMMMUIdx_Stage2_S : ARMMMUIdx_Stage2); is_el0 = mmu_idx == ARMMMUIdx_E10_0 || mmu_idx == ARMMMUIdx_SE10_0; @@ -2366,7 +2366,7 @@ bool get_phys_addr(CPUARMState *env, target_ulong address, result->cacheattrs); /* Check if IPA translates to secure or non-secure PA space. */ - if (arm_is_secure_below_el3(env)) { + if (is_secure) { if (ipa_secure) { result->attrs.secure = !(env->cp15.vstcr_el2 & (VSTCR_SA | VSTCR_SW));