From patchwork Wed Feb 22 02:33:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 655670 Delivered-To: patch@linaro.org Received: by 2002:adf:a3c6:0:0:0:0:0 with SMTP id m6csp456618wrb; Tue, 21 Feb 2023 18:37:04 -0800 (PST) X-Google-Smtp-Source: AK7set+oEqRiaPCX9Juw/L+HhlRiySgvXh6Tsv+3Io6yasR0b4aspD/bCAQEUEuaqTRz3I/y9034 X-Received: by 2002:a05:6214:2508:b0:56f:8a99:1a7a with SMTP id gf8-20020a056214250800b0056f8a991a7amr11380045qvb.23.1677033423924; Tue, 21 Feb 2023 18:37:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677033423; cv=none; d=google.com; s=arc-20160816; b=L3ld2WeR0/R34pZ8wUHzibKgnsEQuUcdrjfRsmaV9BjJqGo5JfrjJz+MsXeVImGhUc HAUQbOgC/jgWIugC9T7gDImYXuTfGPOJm5/9sdy2gyGQYcr5//dhgaPJNLLqRPKR1VSD fmrHN2ak2dUp7U5Bb2eu0F4KMWubFtfIg+JNrexAIUaHVpfs403VPgb3OcASXH5X3Pnd nez3LWhNnaGYqpMVB0yVcUZinH+/rb3+F3opqfvtNt8VCC5wHAXMCHW8j56rolMYl6S+ yUqKx4n9KrcsmTGDk8lIXR/mUZFWLki3nyvabNjF9dq/ZGkHVOJGiOFicrpKiSybBVBf xucw== 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=vZ42O5SQoIJotc7B0HupvbG77824SBhRrElE1X3jpLY=; b=Jwoz/k+xMtcadtv06dt4PsYuPIjm+Sn3CqQ64u5rdA2u5z2XcT/rU+3/G11EHK8Ml0 LaJouD0voWp0FRdfJk3ZDbx0sU9PC2qOhSpit3XfdXdMzUs2smzLGRT6wgaBo775cQxp J0Wnmf2JlNyi9ivTt8gUySJ9V6HJj70ga8e6B4i80owiOheSzpan3HKCMB3M4ySda4el z9opi2itMakizdfm0lxxnnElrKQZxdDz9XHCZ5MwSihTtuzGoFjHQeQW8sFNCVLBfooW qlcRfD3D7fmWz726jxN9rPH3WES0vcda7KQjPacj1m1PTXjQ3Ef2xPopZFCbPJBSah45 K51Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="pce8Ec/S"; 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 g9-20020a05620a40c900b0070633740535si14012329qko.387.2023.02.21.18.37.03 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 21 Feb 2023 18:37:03 -0800 (PST) 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="pce8Ec/S"; 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 1pUexR-0007cA-0M; Tue, 21 Feb 2023 21:34:13 -0500 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 1pUexL-0007Oj-Cy for qemu-devel@nongnu.org; Tue, 21 Feb 2023 21:34:07 -0500 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pUexG-0001go-1G for qemu-devel@nongnu.org; Tue, 21 Feb 2023 21:34:04 -0500 Received: by mail-pl1-x62d.google.com with SMTP id s5so7147270plg.0 for ; Tue, 21 Feb 2023 18:34:01 -0800 (PST) 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 :message-id:reply-to; bh=vZ42O5SQoIJotc7B0HupvbG77824SBhRrElE1X3jpLY=; b=pce8Ec/SaTsZ2O46hf0UgbCiRNOnqhvwbiZVSuSjFzOQlyzH73UYBlQ+VnArCsoGcg KrisqGapxxhprtrnm5hAbC+sR1N2B9vlz6mSYs1Y7TdfHdqzlFx7swA3MrJqHU4lc4/7 KTCGwhOw5Mxur67/2Qfow5S15a1nmUZE+hMP8Pf1CG4deM2cDhccNQSDr6AvyYFpPfTF wELHHHvEtST2ra196AcQFYfSO7xMSbs7ECBpZLTfukI61dCbQGLJZw400zMJj/sjwE8d AZPfgFSX7lwxaA02Pa1qYCsbJQcR+1/MxB2vt8S5YW13uuDAbdIl5SZsDrm25xvqE0XQ JO9w== 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:message-id:reply-to; bh=vZ42O5SQoIJotc7B0HupvbG77824SBhRrElE1X3jpLY=; b=ENcEVXAVjDlKKce+H8bxGeY/OSf3z9stY3DjfVh77jIPbg1xNGz1XXSUpJeespbB+i NfdFbm33qFClcXOJH5PHMM8OERSPwWtzeCmGxRDJyotAw8yFAUdgpXMieEBt56LBr0T3 iL6wQbgFogV1j0gV5d7gz+c97L2J8CJIJ/HA8aRZWSwb27/XqDr4R6L8VU/aPkV0oj/K OCrh0Mvx0S+jirwmwzknwH4a0HHJrQW23S3Zlv67HS9KMiaKJrIXSLi0MdGjV4ctu6F1 9KgtwsHZDD11nsL/b74NlydOVqrNjCn9rTGC+IWVhZgSM7f70Su3k9StFfyZQBv4OAue BkcQ== X-Gm-Message-State: AO0yUKW9hTUwI6eRgoWE/uv4bC9pcfqOMa99Hah/zzu18WcO9Fqq1Nkt 7UmV/bPE1mNzUm996qMe3TGPEkHg4wg+4lvQz1U= X-Received: by 2002:a17:902:facd:b0:19a:9b87:e73f with SMTP id ld13-20020a170902facd00b0019a9b87e73fmr7466085plb.1.1677033240587; Tue, 21 Feb 2023 18:34:00 -0800 (PST) Received: from stoup.. (rrcs-173-198-77-218.west.biz.rr.com. [173.198.77.218]) by smtp.gmail.com with ESMTPSA id k3-20020a170902e90300b00198fde9178csm10520112pld.197.2023.02.21.18.33.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 18:34:00 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Subject: [PATCH v3 15/25] target/arm: NSTable is RES0 for the RME EL3 regime Date: Tue, 21 Feb 2023 16:33:26 -1000 Message-Id: <20230222023336.915045-16-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230222023336.915045-1-richard.henderson@linaro.org> References: <20230222023336.915045-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62d; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62d.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=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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Test in_space instead of in_secure so that we don't switch out of Root space. Handle the output space change immediately, rather than try and combine the NSTable and NS bits later. Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- target/arm/ptw.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/target/arm/ptw.c b/target/arm/ptw.c index a77db3dd43..8b3deb0884 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -1238,7 +1238,6 @@ static bool get_phys_addr_lpae(CPUARMState *env, S1Translate *ptw, { ARMCPU *cpu = env_archcpu(env); ARMMMUIdx mmu_idx = ptw->in_mmu_idx; - bool is_secure = ptw->in_secure; int32_t level; ARMVAParameters param; uint64_t ttbr; @@ -1254,7 +1253,6 @@ static bool get_phys_addr_lpae(CPUARMState *env, S1Translate *ptw, uint64_t descaddrmask; bool aarch64 = arm_el_is_aa64(env, el); uint64_t descriptor, new_descriptor; - bool nstable; /* TODO: This code does not support shareability levels. */ if (aarch64) { @@ -1415,20 +1413,19 @@ static bool get_phys_addr_lpae(CPUARMState *env, S1Translate *ptw, descaddrmask = MAKE_64BIT_MASK(0, 40); } descaddrmask &= ~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 = is_secure ? 0 : (1 << 4); + tableattrs = 0; next_level: descaddr |= (address >> (stride * (4 - level))) & indexmask; descaddr &= ~7ULL; - nstable = extract32(tableattrs, 4, 1); - if (nstable && ptw->in_secure) { + + /* + * Process the NSTable bit from the previous level. This changes + * the table address space and the output space from Secure to + * NonSecure. With RME, the EL3 translation regime does not change + * from Root to NonSecure. + */ + if (extract32(tableattrs, 4, 1) && ptw->in_space == ARMSS_Secure) { /* * Stage2_S -> Stage2 or Phys_S -> Phys_NS * Assert the relative order of the secure/non-secure indexes. @@ -1437,7 +1434,11 @@ static bool get_phys_addr_lpae(CPUARMState *env, S1Translate *ptw, QEMU_BUILD_BUG_ON(ARMMMUIdx_Stage2_S + 1 != ARMMMUIdx_Stage2); ptw->in_ptw_idx += 1; ptw->in_secure = false; + ptw->in_space = ARMSS_NonSecure; + result->f.attrs.secure = false; + result->f.attrs.space = ARMSS_NonSecure; } + if (!S1_ptw_translate(env, ptw, descaddr, fi)) { goto do_fault; } @@ -1540,7 +1541,7 @@ static bool get_phys_addr_lpae(CPUARMState *env, S1Translate *ptw, */ attrs = new_descriptor & (MAKE_64BIT_MASK(2, 10) | MAKE_64BIT_MASK(50, 14)); if (!regime_is_stage2(mmu_idx)) { - attrs |= nstable << 5; /* NS */ + attrs |= !ptw->in_secure << 5; /* NS */ if (!param.hpd) { attrs |= extract64(tableattrs, 0, 2) << 53; /* XN, PXN */ /*