From patchwork Sun Jul 3 08:23:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 586804 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp2915872mab; Sun, 3 Jul 2022 01:38:23 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vVhFEF7m+8rdKfe38oQLdrvoF297eIEIkO/MCQmpfeVUAN62+hAFWHf5ayUnn7shdVDcD7 X-Received: by 2002:a81:14d6:0:b0:31c:4c40:c75b with SMTP id 205-20020a8114d6000000b0031c4c40c75bmr18041620ywu.129.1656837503015; Sun, 03 Jul 2022 01:38:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656837503; cv=none; d=google.com; s=arc-20160816; b=op3Gj/bdiG0OMTCjqSWytZOquM1cczpMOtSx18upEXoe9qeMqxxt/8Ww3qfFenuHOK JCprrbe9UeVXnubEs5Q+xMcKy1O1JnpA4ozlCd4+GxbM9E/KmWYubGrGcT+lIDMQnZDT cIoDgBlpp2osPRczwlni3b+SEjYuMKoG9Dn1f+zJ5vCBxe8vCnoGqEuoqZpDOxLNPKbx oxFDegWZSjLHdLZcXTLMWjLywsDXkKXGDx1rdHh7UtetcBA4E1wF1LX9zDHos0OSUn8b LTZH9Q9shlmwnd0xpMwXkdzmCq9X1ly3x9gk7YSCag4PoEmvlU6uD2AEkyPWGAAqLcZQ r7NA== 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=PdgMMDPY/PA7ZASda7ITPHb+8tgdBcmBCdmhnbT+eGk=; b=y+8XRBFmaqjazXirmHancHJGCVm6M1bN0wpUgM2zeENTuvvqACoHBO/Vi07V4YPBQ3 9/8rv8yFxYVtrHCl9MAra1WhQHwksDnw8LxEylriDHBaRoownfnkZ43QX88H9Wgq8fyi DtJ6xhTajNcdw6/sdHBiwAn+tw1z/w43wawunvLlgkPenOtlQqYGeYSUfob67jQasKv7 UNJuCTXjvRu00Uhu1PE9RUTjcgdmHfqG5oGarDc32mVcU0AhpinoIaCoTTnJqNsHBStW Y+6bc+0D+Q6R8oBh/Ek1nMklWkm0uK/U8uZCqyP2SHzlSg5mekoivg9wXmjgRKrZTUMl mtlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VFf5P75p; 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 141-20020a810a93000000b0031c7e922197si5177295ywk.360.2022.07.03.01.38.22 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 03 Jul 2022 01:38:23 -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=VFf5P75p; 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]:60980 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o7v7W-0002pl-HJ for patch@linaro.org; Sun, 03 Jul 2022 04:38:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52730) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o7uuW-0006lO-Pa for qemu-devel@nongnu.org; Sun, 03 Jul 2022 04:24:57 -0400 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]:36493) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o7uuU-0005ro-D9 for qemu-devel@nongnu.org; Sun, 03 Jul 2022 04:24:56 -0400 Received: by mail-pf1-x42c.google.com with SMTP id f85so2519787pfa.3 for ; Sun, 03 Jul 2022 01:24:53 -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=PdgMMDPY/PA7ZASda7ITPHb+8tgdBcmBCdmhnbT+eGk=; b=VFf5P75pROgYjJ6zLa7zRk5IyQXBkg4lWB7eeDPU0ChEseqAs4xyUFg3hbA9EPYW00 iJ0Vvpx3w/7B7EAQolZuI31I7lzCNohV0EIHFBnNQN4UzxKAsAuHJXu3UpC1I+8+1mmC mCIsm+/vPOvkky92zXAhEwT3dpV7UsCDYWQYhLVcv5yZEIqpyMJ0ezDtyQETo8ffEfFy /sCpGHtIyqOyH17XsmL7raB8Pr4fCjaVHgQNtq6nnSlk/DOGunqhBpy0upBE/Lw5ggcX ah+3WLyKCZ0yAAd2vHKA3ufPkpnT0W/9VGvMCtqBfCL4cZysJ4dQInczMv89/6UH18iS 6aNg== 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=PdgMMDPY/PA7ZASda7ITPHb+8tgdBcmBCdmhnbT+eGk=; b=pEa1J9nEc0ZDNUwUycXxLhTLsGNrweRrhc3AvOOsTgC7kV919i69xkNUFrcQ8cB4yQ IxKqK5lUILboHpEHdGi8pOulzEAeijv6WPnt8u3lnpfHaAP090y/UFX41P1wOiS7VoDh VOxQHhGxTnUpHdUn1FLhyBtcv934LMMPSEIp2vYJtuQ2pQufIrKlgW4sHpjuymAEomRY rpZvhl4hkGTyGVij9GevfV5kL6PxKHWrXGs9AYLuRPQifuxcC8IQ7CFVsv3yGaZXwvaU kCc4lCddabR9d+E/qSrprOYcAl8iVkhFNjXJCt0EgtwekAaJ4nScG57VBWizYDijpY1h dcTg== X-Gm-Message-State: AJIora8h84xOeD5qSqKcxJwT2wEBmbEsmecdRPeX/VrGjj7HziYdCZIE 5eWQjO59GxvSwxojj0i1a7nlb7L6BjHT907G X-Received: by 2002:a63:1e59:0:b0:412:b99:2ad6 with SMTP id p25-20020a631e59000000b004120b992ad6mr4929664pgm.241.1656836692727; Sun, 03 Jul 2022 01:24:52 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id im22-20020a170902bb1600b0016a3f9e528asm13569112plb.57.2022.07.03.01.24.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Jul 2022 01:24:51 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Subject: [PATCH 09/62] target/arm: Fix ipa_secure in get_phys_addr Date: Sun, 3 Jul 2022 13:53:26 +0530 Message-Id: <20220703082419.770989-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220703082419.770989-1-richard.henderson@linaro.org> References: <20220703082419.770989-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42c; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42c.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+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(). More use of the local variable, ipa_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 --- target/arm/ptw.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/target/arm/ptw.c b/target/arm/ptw.c index 1a946f3757..b78658161f 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -2304,6 +2304,7 @@ bool get_phys_addr(CPUARMState *env, target_ulong address, GetPhysAddrResult *result, ARMMMUFaultInfo *fi) { ARMMMUIdx s1_mmu_idx = stage_1_mmu_idx(mmu_idx); + bool is_secure = regime_is_secure(env, mmu_idx); if (mmu_idx != s1_mmu_idx) { /* @@ -2328,18 +2329,16 @@ bool get_phys_addr(CPUARMState *env, target_ulong address, } ipa = result->phys; - ipa_secure = result->attrs.secure; - if (arm_is_secure_below_el3(env)) { - result->attrs.secure = - (ipa_secure - ? !(env->cp15.vstcr_el2.raw_tcr & VSTCR_SW) - : !(env->cp15.vtcr_el2.raw_tcr & VTCR_NSW)); + if (is_secure) { + /* Select TCR based on the NS bit from the S1 walk. */ + ipa_secure = !(result->attrs.secure + ? env->cp15.vstcr_el2.raw_tcr & VSTCR_SW + : env->cp15.vtcr_el2.raw_tcr & VTCR_NSW); } else { - assert(!ipa_secure); + ipa_secure = false; } - s2_mmu_idx = (result->attrs.secure - ? ARMMMUIdx_Stage2_S : ARMMMUIdx_Stage2); + s2_mmu_idx = (ipa_secure ? ARMMMUIdx_Stage2_S : ARMMMUIdx_Stage2); is_el0 = mmu_idx == ARMMMUIdx_E10_0 || mmu_idx == ARMMMUIdx_SE10_0; /* @@ -2383,7 +2382,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.raw_tcr & (VSTCR_SA | VSTCR_SW)); @@ -2407,7 +2406,7 @@ bool get_phys_addr(CPUARMState *env, target_ulong address, * cannot upgrade an non-secure translation regime's attributes * to secure. */ - result->attrs.secure = regime_is_secure(env, mmu_idx); + result->attrs.secure = is_secure; result->attrs.user = regime_is_user(env, mmu_idx); /*