From patchwork Mon Feb 20 23:26:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 655130 Delivered-To: patch@linaro.org Received: by 2002:adf:9bcd:0:0:0:0:0 with SMTP id e13csp1661211wrc; Mon, 20 Feb 2023 15:27:13 -0800 (PST) X-Google-Smtp-Source: AK7set9xaVXpvEzX98s4hpZgyDpqTvdnT8hJapvb8dSqGQMfzkJE8DuHEA70TxEvVcxLNqDVkmMe X-Received: by 2002:ad4:5fcd:0:b0:56f:4d1:cfbc with SMTP id jq13-20020ad45fcd000000b0056f04d1cfbcmr4221411qvb.33.1676935633539; Mon, 20 Feb 2023 15:27:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676935633; cv=none; d=google.com; s=arc-20160816; b=RHuS+7Z772o1cBrdjv4eAl4WsXiFcKgApm5zTFKodMMGNyBWW90iDGk+sh8mJnvAo5 pTTEOqjs4zy6+gjoUUyByCW48coDCQlL7yxEnaTpiVXZhNogDJICkKdIMsjMVPmO/fVv wa7NELI0uBEj7AKuM+51Vx/LzEnBQp8ZhUbhWKXs5i0LpK+7VjrTPHCK0EEEmHOkcYYJ ijf/Wd2sbS6KV9fnJsFE/vL8TxxCfxMzmYrmdxaDUj8z8xsLjx/Lc/dyr49MvFWCLUGZ VHsT9gWMiHjyhA6Ps7W3EbAQgm0VeLiWdNf9FYDz2kRPuuYmWTWEPa7jOeLQuUoncKB6 qNMg== 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=9O4rQ+1tSrDA/VIHaikB47RvthTap5eXu1DpMH/jhqs=; b=SZMUl1OEPR6jnVB4N0lQ+8nlFacbt8OBXCzuXQk7CaB/lsl0eE5A0xuhMJWbrjYZMB YPZKzJ8RJbesEYcF4mS7EArpHt5GKrolPBa1gqQnApVtW9VF/ZXYXG6w3bflf6IjZrJ0 Zf1O2U09pWIY/vtUUK8Y6emUnE0cVG9k71EMJCEJZzbT6dHcSwEiYOKK7GYbmyIJCxfo s41urxnIP5m7BEkz4o/9jBZwApmE0eDtqprUtB4sXLi3/haYYlKxCRxKtPvdu+iZNxXQ QheR3UqYAIxfyRZ+AoBdINdIEujWz7wvMG18viT4RNyxzwwh2E1uplvIgk6KEjZ52n56 hr9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="A7/KCoOv"; 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 fi14-20020a0562141a4e00b005376fc51789si2222614qvb.43.2023.02.20.15.27.13 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 20 Feb 2023 15:27:13 -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="A7/KCoOv"; 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 1pUFYc-00048M-5m; Mon, 20 Feb 2023 18:26:54 -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 1pUFYZ-00043a-Os for qemu-devel@nongnu.org; Mon, 20 Feb 2023 18:26:51 -0500 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pUFYX-0000Or-NT for qemu-devel@nongnu.org; Mon, 20 Feb 2023 18:26:51 -0500 Received: by mail-pl1-x636.google.com with SMTP id e5so4173347plg.8 for ; Mon, 20 Feb 2023 15:26:49 -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=9O4rQ+1tSrDA/VIHaikB47RvthTap5eXu1DpMH/jhqs=; b=A7/KCoOvzdkchqGOJQIfJM9hQTufU2tNpCTEO9VwXDuY3E49vaflRpzqnfGj3L7wj8 PzSsZGiEDQm36f5zCTtlpyrTCSmCzotgP4daU2b1/s+YLmcOTRxBlP/Yoadhl3UcOWta qa4OL9tAHQzVeHvDwQfMnDlC9U3MxtnrHlYF5diehNDjmrABFwEqt6iqEeCwhkJ09cSa lFX1gqWKE+s8LUNTySJATjVjRx7yxUphN8com+DzFHF0HjZ9yr/EzDPN7SUUxj33aafn uDAW+L9IWYfL1jp0xFib/LAb8HJjP2LFBnY7zq55ZfgaL3lwYzUQKBjelkqGVfsdPfYK cHIQ== 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=9O4rQ+1tSrDA/VIHaikB47RvthTap5eXu1DpMH/jhqs=; b=tcSRIjR/3NmbcNfgjdyhjH9srE9bfUfXl5s4svtTogr1qeO3CdtryNoXwQmfhr8oMZ dsFEj7dRGiodpCH+EwQBH0tOHmqFMZ0WbtvW9Q38tozHmrve40Y7XUqetnpBG0QMQXZa zJXNvuU3o6zbugJPPPtCBIgYJrvqx7EHOJxjHqqmWsER91D9V5tgpBXLz7x3/ZY8rPrf xE0OMO0ScyoCgO7ism/TmcIk6AchxcifVjA0lRQxLPszsqT3CLuvwAkyTI+Vb+LSi9QD H7XIgSG/ZG5mddObMjKnhNmB4Z9dP8nBX2W5wtrbyWIENHp4zi1/3Cp2AqN8QKr3kLzR 1dhw== X-Gm-Message-State: AO0yUKUEXHudxzTG/ngajw7rMzBxBJEcqsu9WjFiQ8SJ4X8SagsDS8Mr K2/TydJZyNOCz+Qm6Pd35QGS9AkLRFQGU5/z3mw= X-Received: by 2002:a17:903:2305:b0:19a:a4fc:7f80 with SMTP id d5-20020a170903230500b0019aa4fc7f80mr6249197plh.26.1676935608092; Mon, 20 Feb 2023 15:26:48 -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 j10-20020a170902690a00b001992e74d058sm2665348plk.7.2023.02.20.15.26.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Feb 2023 15:26:47 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Subject: [PATCH v2 11/21] target/arm: NSTable is RES0 for the RME EL3 regime Date: Mon, 20 Feb 2023 13:26:16 -1000 Message-Id: <20230220232626.429947-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230220232626.429947-1-richard.henderson@linaro.org> References: <20230220232626.429947-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::636; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x636.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 --- 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 7745287a46..d612e5f38a 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -1240,7 +1240,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; @@ -1256,7 +1255,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) { @@ -1417,20 +1415,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. @@ -1439,7 +1436,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; } @@ -1542,7 +1543,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 */ /*