From patchwork Mon Feb 27 23:01:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 657154 Delivered-To: patch@linaro.org Received: by 2002:adf:a3c6:0:0:0:0:0 with SMTP id m6csp2617191wrb; Mon, 27 Feb 2023 15:04:45 -0800 (PST) X-Google-Smtp-Source: AK7set9Xn7l54Gc7EHPDJ9wfak4ZxoyDMfLPC7GDCMu3VeLkVB/HACvCd+yn73TiB6/4iPDXhZ6g X-Received: by 2002:a05:622a:1482:b0:3a7:ef31:a07b with SMTP id t2-20020a05622a148200b003a7ef31a07bmr1524629qtx.11.1677539085817; Mon, 27 Feb 2023 15:04:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677539085; cv=none; d=google.com; s=arc-20160816; b=b55fjU5mWTASlK+8rW0O9mNICdc/iYb0IHSZWtCr7DlbmPbd86Z2HX+xdLrcD5YBKs nexPrPdhQw8ywjvpJwaKzBG+Llypv4upyaG7cJ9uWuvVdEpD3B5YD7A6oxTg5iaLXdGl Jz24nCyjk+HauYi5wqJ8KO+DY9BrpM5C5tF32k3IGnpMuLXzrvaQwXxOnrNA40YGlI6r +Y/ixJ39Ort8KjT7dnit81EOEXD1haZWY3Iuy6gEpTUlryOA+hY7U6gLXs3aiq+CwW2X 0lbhUIJ861G150lWQpi4GlbOJzRqc8crj+2NN7KE8NgY8+iVdOmx0v8zYAoF1H7SmaXL H5lw== 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=PP4E13jT/Sv96Ax+VfQqfeV0Z6Vd+p408nT+Z3wCuJQ=; b=hq3yyVkm8h3v3t7PYIB4Mr2N/P0GtO8Fs4PSdGoIbsTKKtsIxKGET0qKiCy9FKHSpD QCHFKWsqapgMwAeBLpyQAhDQWKTbtYVa0N+xg+4tT8j2u9Q8YRW7APGMR3xV8Z3Va6WT IEVcvnycD9CRTRWiWfTe7URA9BwcMHxJbEMeGiW1Fjd+lBrV40HdXmiNLmfwIwT0j5Jz oMAddpLzS9IPaXIUd/M1OoxVsMuVe4aM99l0X1RHkyW9ce7EDfJ0IYJkA1odM9dKqGwp MN9zI3WNmto8IKn482J+ucIVlGN2KLuk98aenSuKI1n+TqHIvaRWDO1EYUGsDD0+NWcY /DKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uInLixzR; 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 w12-20020a05620a444c00b006ff045dc7e6si8242567qkp.29.2023.02.27.15.04.45 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 27 Feb 2023 15:04:45 -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=uInLixzR; 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 1pWmVT-00009n-M7; Mon, 27 Feb 2023 18:02:07 -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 1pWmV9-0007tr-Q2 for qemu-devel@nongnu.org; Mon, 27 Feb 2023 18:01:55 -0500 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pWmV6-00013D-Oo for qemu-devel@nongnu.org; Mon, 27 Feb 2023 18:01:47 -0500 Received: by mail-pl1-x631.google.com with SMTP id c1so8515417plg.4 for ; Mon, 27 Feb 2023 15:01:44 -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=PP4E13jT/Sv96Ax+VfQqfeV0Z6Vd+p408nT+Z3wCuJQ=; b=uInLixzRQQtO0QsfPkZ79882CFSX6TYtQIKw/HkxQ3NVEtuHbRxS++K5clg+7Eg0pG akqGN4ujRdtHP8v0HnIMy/HZuFKIxatqNry0JrHbJipjh8BQjQsSQf8tqczJgyxUDtKi tNdkLzmzYPi5AXdFWNJO9Y3YLOjG8VaFFWBSvthN+hSU+0fo9gPGFm/MU9OVOyOl+YWC 5NDPyO4IbdietvTGxrDSrX2rux8xJSoTHmQ11vkknk0zC9dB1CkANXB7hFsxmmxTc+hV KtUIVgX6JO7WzWgq+EJGJ18zavF2TasbdxAvsuL7DefTttAATHrPH9MEOHH2Qc7Eaxmt zSkg== 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=PP4E13jT/Sv96Ax+VfQqfeV0Z6Vd+p408nT+Z3wCuJQ=; b=JCoMsXdx/+R3iHUGI86Dqa0hE1KISPhtbQ6VWCCWhoTFRUjpVXEWjSqcNSzXcsEUJo bsQx7EkNNVHi2tLYR56Qb6Ezzyzs9uu+BrqanaY/Do0MQBNySLkYcyVfSK7N9MtFQUwY Y9UeNj3926DjitqSfiYW860tYMG3fQQRgkIznT/yiT/8QX16Exl1+aQT+W+XivVV9rJG OgVdxsgyOY0oGMn7EixwURGpWWHueTV6yYSjYggk30kbLjz/lmoxiJYQSixWCc+9IzJ+ LZgs7Ljm8hzPqBv1dYxAr/JGkP+2RDkRjl7xyNFUuCDPPvV3r8P1bOHRJqcLRwSn3k6b Swpw== X-Gm-Message-State: AO0yUKWmjk7wgSbIKbY1Wweal4x0xF81l/pGcq0ySjiDfe6UQGD9gT+n YcBPZW48dJRESGrIrKHH4J08XWVEdkBaU2l3wrk= X-Received: by 2002:a05:6a20:6915:b0:cb:cb17:eac6 with SMTP id q21-20020a056a20691500b000cbcb17eac6mr999586pzj.32.1677538903324; Mon, 27 Feb 2023 15:01:43 -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 u2-20020a637902000000b0050301745a5dsm4406130pgc.50.2023.02.27.15.01.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Feb 2023 15:01:42 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Peter Maydell Subject: [PATCH for-8.0 v4 11/21] target/arm: NSTable is RES0 for the RME EL3 regime Date: Mon, 27 Feb 2023 13:01:12 -1000 Message-Id: <20230227230122.816702-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230227230122.816702-1-richard.henderson@linaro.org> References: <20230227230122.816702-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::631; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x631.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. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- 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 75f276b520..0c07e5e24f 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -1242,7 +1242,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; @@ -1258,7 +1257,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) { @@ -1419,20 +1417,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. @@ -1441,7 +1438,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; } @@ -1544,7 +1545,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 */ /*