From patchwork Fri Jul 14 15:46:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 702734 Delivered-To: patch@linaro.org Received: by 2002:adf:db4e:0:b0:314:25da:8dc4 with SMTP id f14csp1161487wrj; Fri, 14 Jul 2023 08:48:29 -0700 (PDT) X-Google-Smtp-Source: APBJJlEaHDB01AZcBEjFJh9iwcvKXv9GrAe7kZ8J2KYF/xRcJVhrQa2s0zXBkiliFGVpY2zHb3Rm X-Received: by 2002:a05:622a:1a82:b0:403:b3a2:820f with SMTP id s2-20020a05622a1a8200b00403b3a2820fmr3510113qtc.31.1689349708912; Fri, 14 Jul 2023 08:48:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689349708; cv=none; d=google.com; s=arc-20160816; b=Iozr/nAsu52GdRaqeXKafiViOpcZ61WYX3NUGm7yNo1gUmoJmo95SGdEQ+DtlF+vSb 2wX77L/DW10WoNFuBM39X4Kf1jQ2jcansBFjXU0yrSIdiXvDy1QmqOwIAhWeSomCJYe4 I5F/rqFnzzEjyeFGJ4iO/igTzzzRl65mJcLxU5fRyLLfFvZUuBrsHB0tCUvQBJa2IPqf fxtBh7Y3l4OVhvsD0cm0ePBp5968DLX8Ur2Md3QrOxEHcReIYfOxrmaJZzyVU1zkOA7u sHRU50OsJTp7DxpQyRfXJEABv5wIRML6MHEykfxF7LhFkJsDXC+bdE6YzuaZgTA3vU2o m4JA== 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=wjXax+BQ/9wUzLTNVvfXm39pxSfddxOCMcJwUt+OkWM=; fh=jvpdohKmRoZMO537s6xMKXXtj7EZws1LOMQI/oP4vXs=; b=TM09Ntex0MXEmdem0Um7shX7kr3hUoNkL84u8GuaYWlXpBX3fbRuaxAg/KBJP4FLy1 7CF1iWs+KNiObwAp9oggU0y+dUZZEL1PmpIm1COKRlGKGj8oBnaqXYrF0VVfbZLeETn0 tgAx1K8/aBmMBZ1nASfqPTYEXbZ/gnuEyKL/31lgW8rmhLA3Lq2UVxOvrD7NvD9EmYCy wTcn/6vsx/lE1o6USrUwY5oG15r4iIZzqLxOVbzLAPMXEqlQLR8PlzKe+qz7D5hrBTjg Hn0O0010wyHF5XN/NNRraEWh5eHRYU9jJJU72mzlG8gGxTxpXFeHRv/PGbyHkNM7P3LK +bEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CoNTr4QX; 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 j22-20020ac85c56000000b00403b55ed491si4759870qtj.524.2023.07.14.08.48.28 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 14 Jul 2023 08:48:28 -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=CoNTr4QX; 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] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qKL0T-0007By-UO; Fri, 14 Jul 2023 11:46:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qKL0S-0007Ad-Ch for qemu-devel@nongnu.org; Fri, 14 Jul 2023 11:46:56 -0400 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qKL0P-000759-HF for qemu-devel@nongnu.org; Fri, 14 Jul 2023 11:46:56 -0400 Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-3159da54e95so2075032f8f.3 for ; Fri, 14 Jul 2023 08:46:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1689349612; x=1691941612; 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=wjXax+BQ/9wUzLTNVvfXm39pxSfddxOCMcJwUt+OkWM=; b=CoNTr4QXfJDkliJsojuyX7mGwBLRb6m7rL9z9VdrE5+ETsWyvIKDPpkd6cChiGl/wq Fc9X2CjDE+XVmHkflLOtX99UvqYiVj0AquR/3kSLVsxtcgr7BxXODqLVGmBa/JYAXT3+ I3a3wgY/5M+3v7ep33y88hfsRn+5LtUeUAB3mJtPLW0RVffAFb4UIimE8Mj3SZpFQsWd b+KS1ODviNZx+pvXb9eE4KdcWMReHTl5BLgRcq3J0vD8DBO4TqbdsRINdcv9iNQFVbjU 8SYjGnc6bK0g/45nvThrINkQbloDiaxiUYG0WUBFvHrTee3JQLyBYOz6BU5qxtj5CTVu 4emQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689349612; x=1691941612; 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=wjXax+BQ/9wUzLTNVvfXm39pxSfddxOCMcJwUt+OkWM=; b=iVUV7+6CgFn/S6NKdX8zTvppwrXSk49DZ0+ntGit8nHmkKHwHJ8rYRrx6+ZoRjuFHD Bqzmep+1Zk4HAObBndIF82agV4+NvtokyjaImozAD2V0KBuWcsAU6UOx8kAobN/e6dzL MduLpKQRN3helCWmWN/qhfYhjEfPiRpAu1b/bjVk0SekJsJim22c5ojOTVkj0Lv7woBu JSh0UIInGqmTUFBr0J8IszldZVrosrdP0nIWIuQ/XpFEuskQX6w5snR456bn3pydK5w2 eImj8TOHnRLoUghTdHfsGJorop0Sq8SV2PUKGDsZkuK1/KzF4DdBA4mDWue8j2GN0Ugu +k7Q== X-Gm-Message-State: ABy/qLaIKY2fIWCUdOQmPpMRPVPMi6xWn1WZrg/416xf8fuCUErUTGfA 5GRtzeL7PuTQkG9ZVRuRtfN0+A== X-Received: by 2002:a5d:4b44:0:b0:313:edaa:2505 with SMTP id w4-20020a5d4b44000000b00313edaa2505mr4842435wrs.20.1689349612285; Fri, 14 Jul 2023 08:46:52 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id t16-20020a5d49d0000000b003143bb5ecd5sm11214025wrs.69.2023.07.14.08.46.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jul 2023 08:46:52 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH 03/14] target/arm/ptw: Set s1ns bit in fault info more consistently Date: Fri, 14 Jul 2023 16:46:37 +0100 Message-Id: <20230714154648.327466-4-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230714154648.327466-1-peter.maydell@linaro.org> References: <20230714154648.327466-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::431; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x431.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-bounces+patch=linaro.org@nongnu.org The s1ns bit in ARMMMUFaultInfo is documented as "true if we faulted on a non-secure IPA while in secure state". Both the places which look at this bit only do so after having confirmed that this is a stage 2 fault and we're dealing with Secure EL2, which leaves the ptw.c code free to set the bit to any random value in the other cases. Instead of taking advantage of that freedom, consistently make the bit be set to false for the "not a stage 2 fault for Secure EL2" cases. This removes some cases where we were using an 'is_secure' boolean and leaving the reader guessing about whether that was the right thing for Realm and Root cases. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson --- target/arm/ptw.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/target/arm/ptw.c b/target/arm/ptw.c index eb57ebd897b..67078ae3509 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -514,6 +514,17 @@ static ARMSecuritySpace S2_security_space(ARMSecuritySpace s1_space, } } +static bool fault_s1ns(ARMSecuritySpace space, ARMMMUIdx s2_mmu_idx) +{ + /* + * For stage 2 faults in Secure EL22, S1NS indicates + * whether the faulting IPA is in the Secure or NonSecure + * IPA space. For all other kinds of fault, it is false. + */ + return space == ARMSS_Secure && regime_is_stage2(s2_mmu_idx) + && s2_mmu_idx == ARMMMUIdx_Stage2_S; +} + /* Translate a S1 pagetable walk through S2 if needed. */ static bool S1_ptw_translate(CPUARMState *env, S1Translate *ptw, hwaddr addr, ARMMMUFaultInfo *fi) @@ -586,7 +597,7 @@ static bool S1_ptw_translate(CPUARMState *env, S1Translate *ptw, fi->s2addr = addr; fi->stage2 = true; fi->s1ptw = true; - fi->s1ns = !is_secure; + fi->s1ns = fault_s1ns(ptw->in_space, s2_mmu_idx); return false; } } @@ -602,7 +613,7 @@ static bool S1_ptw_translate(CPUARMState *env, S1Translate *ptw, fi->s2addr = addr; fi->stage2 = regime_is_stage2(s2_mmu_idx); fi->s1ptw = fi->stage2; - fi->s1ns = !is_secure; + fi->s1ns = fault_s1ns(ptw->in_space, s2_mmu_idx); return false; } @@ -729,7 +740,7 @@ static uint64_t arm_casq_ptw(CPUARMState *env, uint64_t old_val, fi->s2addr = ptw->out_virt; fi->stage2 = true; fi->s1ptw = true; - fi->s1ns = !ptw->in_secure; + fi->s1ns = fault_s1ns(ptw->in_space, ptw->in_ptw_idx); return 0; } @@ -2030,7 +2041,7 @@ static bool get_phys_addr_lpae(CPUARMState *env, S1Translate *ptw, fi->level = level; /* Tag the error as S2 for failed S1 PTW at S2 or ordinary S2. */ fi->stage2 = fi->s1ptw || regime_is_stage2(mmu_idx); - fi->s1ns = mmu_idx == ARMMMUIdx_Stage2; + fi->s1ns = fault_s1ns(ptw->in_space, mmu_idx); return true; }