From patchwork Wed Dec 8 23:11:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 522231 Delivered-To: patch@linaro.org Received: by 2002:a05:6e04:2287:0:0:0:0 with SMTP id bl7csp155871imb; Wed, 8 Dec 2021 15:15:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJxvdCtfNOpVyw6lBIWUHAdbhB/DZ0/p4Cd7h1b5iRPTZrn9zyzojT0fzrclH5xePyjwtRan X-Received: by 2002:a05:6902:1005:: with SMTP id w5mr1912577ybt.135.1639005358056; Wed, 08 Dec 2021 15:15:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1639005358; cv=none; d=google.com; s=arc-20160816; b=Z3zKmJqfNFCaQb9XKgtohUiluj982qH/9lbJ8GUkQ3m8kjHPyD7akJZdXB4iAVJv0F 0Vg+bHtnK6h41uL9ljpEBeWgLqT7ocmyCGfMVueAAnKzs9QwSY+W8tLcGUYeJLiVGG4U L4R6I6xiHmBMdeIFuCngzRebsM8GGyTR4PacYry3BIlImV9Q9+mRVdVp5N93HgQW8IBC nmL/iyEc79MFZR2Jpsp83EMtbQekJSkAxNffyY/XePMu1nSCSxa8NvhKHeuS7MM+v7PN O+/gKDPe6snKHNQG9wJO9yVZewx8VNUo1LHUEnz9tDliLKb7mJKeTuuQ/EfZfhJH9Knt BkYw== 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=8Odri40+f/dUoIsb/bgSIF+/bcyc0os3qiW/fNyIHw0=; b=xyWBVl+HCtvAcRymcZQg7DsaSWgNg/8f8UsA8pgvb6UdtKdwBhGCrvWkC2v6U7fJp5 rJfik327lwSdNiwKhcLavPsQJwM7K0i+Zn+eDENc6frS9art49w8B30YtGleCgOWVHVk ZwAoZNfUwmzGfigX7AqLn9nfEbeLP7tgEwSxGxKLlov5GVYmzGlHh5RFoDAiL3vi7WvY 0DLM35ODaiVr5wZ4qwQgEpwnSgUIk0bmvHcps1p57qk1wOkKcOfzQ9qH/ffFrhpZ89dz CqTyHRylcPsUuJleeEjawbXkqiTC1T+Lt/0OJt/FiFFc4O5pOqBK5rfudYECjW9XgxLj DOwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="aGP/X3W0"; 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 u7si6373630ybb.508.2021.12.08.15.15.58 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 08 Dec 2021 15:15:58 -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="aGP/X3W0"; 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]:39972 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mv6AH-0001ea-It for patch@linaro.org; Wed, 08 Dec 2021 18:15:57 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34162) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mv66S-00058A-EM for qemu-devel@nongnu.org; Wed, 08 Dec 2021 18:12:00 -0500 Received: from [2607:f8b0:4864:20::42d] (port=42665 helo=mail-pf1-x42d.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mv66Q-0004mt-5n for qemu-devel@nongnu.org; Wed, 08 Dec 2021 18:12:00 -0500 Received: by mail-pf1-x42d.google.com with SMTP id u80so3745688pfc.9 for ; Wed, 08 Dec 2021 15:11:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=8Odri40+f/dUoIsb/bgSIF+/bcyc0os3qiW/fNyIHw0=; b=aGP/X3W0C6PCiBh8YmcA7oZxwYFBL7hHkZKp+cfNv0qAi7nP4jbDHPXInWXSdUl3Sv wbmwJSwk78QrrU9Nn4HHVXOgYGymMI4BxvRkA98qGqh26L7F4ruRVrHNf9Thfy4IlPwm RNv8nDAOHwV4G6bWBbaHENyXWqHMnjT2Cft0s4qC6hQQ/b9HbGjwISvKRtwD2QtnS4v+ e72rKA1JciX5MMYQpjol+k/ju1PDFIpQQOud7zQWOfhZw0ssex88cW3nX9Nd2LoZiFWK 1/ZefKrRLWN6RZt2RYwhSy8yHlkiFFJuNb+zdqgnO7lHJGeX0dGLByWBESWiU7vMdnDd 0KfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8Odri40+f/dUoIsb/bgSIF+/bcyc0os3qiW/fNyIHw0=; b=rz/4p9k/2HAUMhSiMJtBWV+ktQMnVmh171+9iXVI+4eA2APIYsiaAe4598SgzkQpZW k9fLCjWQrQ48ZDojFbXawkAi2stnLvG72UcTAqwnxYB5Dpa8byT/LYPmbEtBHCUy13Ud oroT715r/CFdUoKoTwuSLVhxg3z2aUUJiO4/2tE1uiku7XoW5icYs7gDVZymEuyr/KM2 u4ZuHpQmkDnWWlytp7NVUq/w2Udeeb3+dPvDYlY5WUbQ13RqkZljIlIPo81vB8pvqUCa 2ccwWDnOOuBusKW1Y3ukowKt1Tcwea+Wi0OG1DNuKrr6faVv37Cj2c91nLCQEiR7H7V0 A/rA== X-Gm-Message-State: AOAM5316dpq5vDvlVl5QDHjqrIfoopW3krXx1BxhNh1j3I5CfJNi3ZSJ nU//EcFyjvpeiFcqu8BzD2+HdFGJo9C5NA== X-Received: by 2002:a63:6882:: with SMTP id d124mr31976744pgc.234.1639005116664; Wed, 08 Dec 2021 15:11:56 -0800 (PST) Received: from localhost.localdomain (45-19-222-18.lightspeed.sntcca.sbcglobal.net. [45.19.222.18]) by smtp.gmail.com with ESMTPSA id k15sm3301062pgn.91.2021.12.08.15.11.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Dec 2021 15:11:56 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 1/6] target/arm: Fault on invalid TCR_ELx.TxSZ Date: Wed, 8 Dec 2021 15:11:49 -0800 Message-Id: <20211208231154.392029-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211208231154.392029-1-richard.henderson@linaro.org> References: <20211208231154.392029-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::42d (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::42d; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42d.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 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, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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" Without FEAT_LVA, the behaviour of programming an invalid value is IMPLEMENTATION DEFINED. With FEAT_LVA, programming an invalid minimum value requires a Translation fault. It is most self-consistent to choose to generate the fault always. Signed-off-by: Richard Henderson Reviewed-by: Alex Bennée --- target/arm/helper.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/target/arm/helper.c b/target/arm/helper.c index 9b317899a6..575723d62c 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -11129,7 +11129,7 @@ ARMVAParameters aa64_va_parameters(CPUARMState *env, uint64_t va, { uint64_t tcr = regime_tcr(env, mmu_idx)->raw_tcr; bool epd, hpd, using16k, using64k; - int select, tsz, tbi, max_tsz; + int select, tsz, tbi; if (!regime_has_2_ranges(mmu_idx)) { select = 0; @@ -11165,15 +11165,6 @@ ARMVAParameters aa64_va_parameters(CPUARMState *env, uint64_t va, } } - if (cpu_isar_feature(aa64_st, env_archcpu(env))) { - max_tsz = 48 - using64k; - } else { - max_tsz = 39; - } - - tsz = MIN(tsz, max_tsz); - tsz = MAX(tsz, 16); /* TODO: ARMv8.2-LVA */ - /* Present TBI as a composite with TBID. */ tbi = aa64_va_parameter_tbi(tcr, mmu_idx); if (!data) { @@ -11309,9 +11300,30 @@ static bool get_phys_addr_lpae(CPUARMState *env, uint64_t address, /* TODO: This code does not support shareability levels. */ if (aarch64) { + int min_tsz = 16, max_tsz = 39; /* TODO: ARMv8.2-LVA */ + param = aa64_va_parameters(env, address, mmu_idx, access_type != MMU_INST_FETCH); level = 0; + + if (cpu_isar_feature(aa64_st, env_archcpu(env))) { + max_tsz = 48 - param.using64k; + } + + /* + * If TxSZ is programmed to a value larger than the maximum, + * or smaller than the effective minimum, it is IMPLEMENTATION + * DEFINED whether we behave as if the field were programmed + * within bounds, or if a level 0 Translation fault is generated. + * + * With FEAT_LVA, fault on less than minimum becomes required, + * so our choice is to always raise the fault. + */ + if (param.tsz < min_tsz || param.tsz > max_tsz) { + fault_type = ARMFault_Translation; + goto do_fault; + } + addrsize = 64 - 8 * param.tbi; inputsize = 64 - param.tsz; } else { From patchwork Wed Dec 8 23:11:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 522228 Delivered-To: patch@linaro.org Received: by 2002:a05:6e04:2287:0:0:0:0 with SMTP id bl7csp152455imb; Wed, 8 Dec 2021 15:13:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJxvTho0hWJQiiLpsNYpqMIBk+Qe+H9xy93RsgpQ8QUicWlW0wWBofKfdZYi12rmzWMYa9mV X-Received: by 2002:ab0:7784:: with SMTP id x4mr12778555uar.143.1639005180874; Wed, 08 Dec 2021 15:13:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1639005180; cv=none; d=google.com; s=arc-20160816; b=sLZNUg116vR69AvXZEDQ00gq+fA8gvVKuGG2qTsUNZgq22Tq4zNT3CUmpsYmRgwK9z 0j1Wvx7bkMywwoPD+l+BgItOYar7fMo1hOtLvTUphd80CIJp13wzZUGc2iAM3i0/8BqB pAnOK/q7WTrrsIQzpDGXm57QBdJgJ/H++4eJbIX4EkgANXmP5tC0WiS6CFYMlXNlO6sm ehbCFLWSdrYie1pwZC9GMPbmLFcNyJ+ZwCtyyEbJAUlJ5OEHhQue2QjeLWTszaJHFGTR 1IHovp0ouR++OeOqj8pPMINUaObbvPBkqNqIJa5Y/gm2GYVK8GIKifVfwEbDRu3mY6X3 doTQ== 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=Bg5qVk1ZQ88PRRWOggs3a3wuRuKCDpNLFKTwJvEK+Vk=; b=YPCDZUTKSqW3nFGFAHaqX6MGozsjK+QdnQCWlVhMRmJgGfuIr1booy04SjQaeMttTi swRfbnWbsWRI0+LcJKJTPNFmqcS/y9rMIGwEQEegQtDD9rvafTkRLc2wvhwiy4HeDGmv R5TC551skBplRljGyAqVhVaN+1+ZnQl+7OShc4qhZJsU6mHfWksph1eG1y/vskoWQj6J mmkmFxmVrrkFBgl2sEk6FlxQYjOzUWUUEV9wAX2zG0Wf2hxRB4pQECmYPQbYPLrExiSg HGODbXSdma/tlq2AYYnUk/MH6Z1D/IYElQxhFHtahxYhNeAeqonsWrjCRAiNDkBf9wBc kFqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TUCxmnVt; 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 x22si5919835vsk.99.2021.12.08.15.13.00 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 08 Dec 2021 15:13:00 -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=TUCxmnVt; 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]:60928 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mv67P-0005Ak-BL for patch@linaro.org; Wed, 08 Dec 2021 18:12:59 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34176) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mv66S-00058s-RH for qemu-devel@nongnu.org; Wed, 08 Dec 2021 18:12:00 -0500 Received: from [2607:f8b0:4864:20::62e] (port=42602 helo=mail-pl1-x62e.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mv66Q-0004nC-RJ for qemu-devel@nongnu.org; Wed, 08 Dec 2021 18:12:00 -0500 Received: by mail-pl1-x62e.google.com with SMTP id u17so2557307plg.9 for ; Wed, 08 Dec 2021 15:11:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=Bg5qVk1ZQ88PRRWOggs3a3wuRuKCDpNLFKTwJvEK+Vk=; b=TUCxmnVtTnJf++YlY/xAH9sToCVtf1EsMUZAx2FXAQXsTbzeew2Re6MjIGulNLS0w+ ky6UH23X/hOgPaJuPTj936B4YdOKgA34ohuE4A0lCv2xyZjTNgsE+hjYMTKPv/aNO1vh 5EmFEBtlx6Q/C66v8ydLIMOeYgn9ZhsIA8asGRb4xMwiyZ/yANjDHupqIpKsSCfyJAUp XQylnB+UWSCmSOm4Qiu8DvS/OCUnb9Zb03AVXPgaPGRGzGtisZTVzM5kRWl+tc1Ji5sy td5cjiAWJjLmvp0kL+IUeI2b6glhYkhEJn9NiiiFF7yhiieFm+23yXhRlN1SgcoSp4R2 Tq2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Bg5qVk1ZQ88PRRWOggs3a3wuRuKCDpNLFKTwJvEK+Vk=; b=RjbZlN27rGe4V0JKvym3F8KwHqintfP+mt7GAFqaqq1fPeNf/wplm5niumaNYQYLr0 YNUW7FT3ARhtEs7TRkjWWsOEzhgEs9i+PVMPIKIwWQC9ZzKPGbgfWnQ52szgEBa2KKYe ycNsqLWMcdIoOpOba3SL5bzHCX3ws01DlVefLLVdcE5qQ0nwKnZuUeA1+guE6Ev5jgop 1U6Yq3NLXJQLCk0vXmUionobMvEJDNlUwY9IFX7s8tkLY/uOCP78u8UL791FrtYbGjtO XY1Bw29KY0pZs/s8/ryYrA7c27cms1oIH1+KmcWIC4oKjxsE4YuL96SDcAzpCQnE9mMS u/+g== X-Gm-Message-State: AOAM533i3W3ABZNliam0d3Dx7XxBn0cBjO7uTEC/N7uy9kTzLfTXdiLE b0LcUOkKhgPnN6DGMMwsjq8E2Y+ZY1M/ww== X-Received: by 2002:a17:902:ba84:b0:142:5514:8dd7 with SMTP id k4-20020a170902ba8400b0014255148dd7mr63438969pls.87.1639005117597; Wed, 08 Dec 2021 15:11:57 -0800 (PST) Received: from localhost.localdomain (45-19-222-18.lightspeed.sntcca.sbcglobal.net. [45.19.222.18]) by smtp.gmail.com with ESMTPSA id k15sm3301062pgn.91.2021.12.08.15.11.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Dec 2021 15:11:57 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 2/6] target/arm: Move arm_pamax out of line Date: Wed, 8 Dec 2021 15:11:50 -0800 Message-Id: <20211208231154.392029-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211208231154.392029-1-richard.henderson@linaro.org> References: <20211208231154.392029-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::62e (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::62e; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62e.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 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, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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" Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Alex Bennée --- target/arm/internals.h | 19 +------------------ target/arm/helper.c | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/target/arm/internals.h b/target/arm/internals.h index 89f7610ebc..27d2fcd26c 100644 --- a/target/arm/internals.h +++ b/target/arm/internals.h @@ -243,24 +243,7 @@ static inline void update_spsel(CPUARMState *env, uint32_t imm) * Returns the implementation defined bit-width of physical addresses. * The ARMv8 reference manuals refer to this as PAMax(). */ -static inline unsigned int arm_pamax(ARMCPU *cpu) -{ - static const unsigned int pamax_map[] = { - [0] = 32, - [1] = 36, - [2] = 40, - [3] = 42, - [4] = 44, - [5] = 48, - }; - unsigned int parange = - FIELD_EX64(cpu->isar.id_aa64mmfr0, ID_AA64MMFR0, PARANGE); - - /* id_aa64mmfr0 is a read-only register so values outside of the - * supported mappings can be considered an implementation error. */ - assert(parange < ARRAY_SIZE(pamax_map)); - return pamax_map[parange]; -} +unsigned int arm_pamax(ARMCPU *cpu); /* Return true if extended addresses are enabled. * This is always the case if our translation regime is 64 bit, diff --git a/target/arm/helper.c b/target/arm/helper.c index 575723d62c..fab9ee70d8 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -11090,6 +11090,28 @@ static uint8_t convert_stage2_attrs(CPUARMState *env, uint8_t s2attrs) } #endif /* !CONFIG_USER_ONLY */ +/* The cpu-specific constant value of PAMax; also used by hw/arm/virt. */ +unsigned int arm_pamax(ARMCPU *cpu) +{ + static const unsigned int pamax_map[] = { + [0] = 32, + [1] = 36, + [2] = 40, + [3] = 42, + [4] = 44, + [5] = 48, + }; + unsigned int parange = + FIELD_EX64(cpu->isar.id_aa64mmfr0, ID_AA64MMFR0, PARANGE); + + /* + * id_aa64mmfr0 is a read-only register so values outside of the + * supported mappings can be considered an implementation error. + */ + assert(parange < ARRAY_SIZE(pamax_map)); + return pamax_map[parange]; +} + static int aa64_va_parameter_tbi(uint64_t tcr, ARMMMUIdx mmu_idx) { if (regime_has_2_ranges(mmu_idx)) { From patchwork Wed Dec 8 23:11:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 522232 Delivered-To: patch@linaro.org Received: by 2002:a05:6e04:2287:0:0:0:0 with SMTP id bl7csp158154imb; Wed, 8 Dec 2021 15:17:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJxDI/SrUPsOmUHp4B8BDfE+FcIOQlPJPIWQWUBnJbZdtCJSSBSRkxBhxVcf65ErUCi97PRf X-Received: by 2002:a1f:3f4f:: with SMTP id m76mr2574855vka.1.1639005472894; Wed, 08 Dec 2021 15:17:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1639005472; cv=none; d=google.com; s=arc-20160816; b=NPAoHoLl2QJ9QhYvWn2UmDlsvKR9CH8UD863VDIFUYChdD/36SxnSy375DAcSGnggq 5D7DHsvI0YEwShO2ve5qv6FOX3j1czDBy9POqQ9CAtZlw+MoyqYvmX0a55F6eCyGMGKN O64eDQvZrliuIV7sXEFjohZElaB3NptfEX0Qzuv4WFVCkHUw9nOb7fZvZO4pzU4kpcxm xrDUqiCeZuUuO5vyHeU4hfBzS8gPFtUvk1NwwQNvijBgXkxhUPHBiMS2vMOxCdqq8S1K DTLpfrKCa9vpVldofpuoLuj6mqHhpIsjyTLD0uM63oRm8X+PLGYov/iM5NUdpz/te9Vt 4Kkw== 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=J/dJZhp4tYu7wqYDqWQx/znhFVjWKRlJoKxN5tcfeHc=; b=mVHVQzYEFFGYNnsLPEaMyD1GLliHeOm/npjpTDMBr7ezPBMwF8wpw5SGo45oTJ1EZ5 dgPFXZuOkqw2ii4GAedTCC7kH68ChaSZU67Gg/yOgKYjEJucsQaYWb+TiPZoFsWlCKVY N5jYufvpPStqYL64edjnZ20HBL6cRovrw7RHSs0U2kvkO3I+6xs2/b+0E21plbO9+huV eV9YgXEsROwYyLhideD9aYWnMJeIbBgt5NxsEBX4UwtTg2xtywLtfZVscU8Rp+y6rxpS A+P0Jo3RoSLZkw9eHv5zWesIlBIa0Moe+mkofYHR6u6LIJEZwOiDeiIAbsTkDrn1SuLu pUtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IOvWIYSh; 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 g79si5944748vke.223.2021.12.08.15.17.52 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 08 Dec 2021 15:17:52 -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=IOvWIYSh; 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]:46278 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mv6C8-0005zu-8M for patch@linaro.org; Wed, 08 Dec 2021 18:17:52 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34230) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mv66V-0005DA-2R for qemu-devel@nongnu.org; Wed, 08 Dec 2021 18:12:03 -0500 Received: from [2607:f8b0:4864:20::1031] (port=34571 helo=mail-pj1-x1031.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mv66R-0004nN-OG for qemu-devel@nongnu.org; Wed, 08 Dec 2021 18:12:02 -0500 Received: by mail-pj1-x1031.google.com with SMTP id j5-20020a17090a318500b001a6c749e697so4911151pjb.1 for ; Wed, 08 Dec 2021 15:11:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=J/dJZhp4tYu7wqYDqWQx/znhFVjWKRlJoKxN5tcfeHc=; b=IOvWIYShmAI+HNwmS31OEjEzRP4johVjr5XNAPLSWxkItnc0tf4Bz+hUtmpa0pDZa2 Jw3MohuNKuHbKc1BuP7ZlHpVnnzkMuseAZErtke3XNlVOlqWvAP6n577gIc4EUKWGTxJ g1T4dsZeFzl839nXzgcOWXlNh7u76RO4zWHvu5hN3MtVZbW64MjrKl2TrQ+6Es/wAEI4 SzSPCnzS8QWepCHYu3n02EHHxHlP2/UmqQXQ7iUZBH2iz0+2I2S6RQqOimcH60IF9PJZ pNiDTULuK7mtLKiwasHnI2XrQ0Og2KyZdecj+v4JRly1MVfHYSJAZgsMHCclXbXu0Cb5 Goew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=J/dJZhp4tYu7wqYDqWQx/znhFVjWKRlJoKxN5tcfeHc=; b=LrkI0JZteG2Miu2tKheVNxAqTYbaVoYwU56D0FJjIlK0SmYKCBu9sxn7lv3kOnZVx/ bAtYuckAVHiujwNbIiFgtsEP518IXGvyHnirZTcqxyE0O0lpZ3lolI5m6HK+VxFCjruM YRTAoVDeqApnOPFT8+IiikJ5DxB9M+jx/VFIy9W7jiNfXcXMIaYoLibynmkl5bPGf5kJ l0kdW3jXNWDf852S40KJ9nXtOWpcaow+GOFu5QP1EbjdA6xTwZshetOmlqpi24zowerl RlYvlKmK3syxBiFj7eOAhTWlq9ghURNToVHb1sxp5sY2UAoW9za/KmH5TWYHHPjDOwqV 7LnQ== X-Gm-Message-State: AOAM5323G6MMGEeFANWbIL+Gp3PmjnbO5Yr/nWesGejYM5WPGlWFyeju sEMC9W2J7j4ulXdse2cJLDWRBVzbUsMDLg== X-Received: by 2002:a17:902:b7c8:b0:141:9ddb:33e7 with SMTP id v8-20020a170902b7c800b001419ddb33e7mr63387132plz.60.1639005118430; Wed, 08 Dec 2021 15:11:58 -0800 (PST) Received: from localhost.localdomain (45-19-222-18.lightspeed.sntcca.sbcglobal.net. [45.19.222.18]) by smtp.gmail.com with ESMTPSA id k15sm3301062pgn.91.2021.12.08.15.11.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Dec 2021 15:11:58 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 3/6] target/arm: Honor TCR_ELx.{I}PS Date: Wed, 8 Dec 2021 15:11:51 -0800 Message-Id: <20211208231154.392029-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211208231154.392029-1-richard.henderson@linaro.org> References: <20211208231154.392029-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::1031 (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::1031; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1031.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 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, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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" This field controls the output (intermediate) physical address size of the translation process. V8 requires to raise an AddressSize fault if the page tables are programmed incorrectly, such that any intermediate descriptor address, or the final translated address, is out of range. Add an outputsize field to ARMVAParameters, and fill it in during aa64_va_parameters. Pass the value to check_s2_mmu_setup to use instead of the raw PAMax value. Test the descaddr as extracted from TTBR and from page table entries. Restrict descaddrmask so that we won't raise the fault for v7. Signed-off-by: Richard Henderson Reviewed-by: Alex Bennée --- target/arm/internals.h | 1 + target/arm/helper.c | 92 +++++++++++++++++++++++++++++------------- 2 files changed, 65 insertions(+), 28 deletions(-) diff --git a/target/arm/internals.h b/target/arm/internals.h index 27d2fcd26c..3e801833b4 100644 --- a/target/arm/internals.h +++ b/target/arm/internals.h @@ -1032,6 +1032,7 @@ static inline uint32_t aarch64_pstate_valid_mask(const ARMISARegisters *id) */ typedef struct ARMVAParameters { unsigned tsz : 8; + unsigned ps : 3; unsigned select : 1; bool tbi : 1; bool epd : 1; diff --git a/target/arm/helper.c b/target/arm/helper.c index fab9ee70d8..568914bd42 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -11003,7 +11003,7 @@ do_fault: * false otherwise. */ static bool check_s2_mmu_setup(ARMCPU *cpu, bool is_aa64, int level, - int inputsize, int stride) + int inputsize, int stride, int outputsize) { const int grainsize = stride + 3; int startsizecheck; @@ -11019,22 +11019,19 @@ static bool check_s2_mmu_setup(ARMCPU *cpu, bool is_aa64, int level, } if (is_aa64) { - CPUARMState *env = &cpu->env; - unsigned int pamax = arm_pamax(cpu); - switch (stride) { case 13: /* 64KB Pages. */ - if (level == 0 || (level == 1 && pamax <= 42)) { + if (level == 0 || (level == 1 && outputsize <= 42)) { return false; } break; case 11: /* 16KB Pages. */ - if (level == 0 || (level == 1 && pamax <= 40)) { + if (level == 0 || (level == 1 && outputsize <= 40)) { return false; } break; case 9: /* 4KB Pages. */ - if (level == 0 && pamax <= 42) { + if (level == 0 && outputsize <= 42) { return false; } break; @@ -11043,8 +11040,8 @@ static bool check_s2_mmu_setup(ARMCPU *cpu, bool is_aa64, int level, } /* Inputsize checks. */ - if (inputsize > pamax && - (arm_el_is_aa64(env, 1) || inputsize > 40)) { + if (inputsize > outputsize && + (arm_el_is_aa64(&cpu->env, 1) || inputsize > 40)) { /* This is CONSTRAINED UNPREDICTABLE and we choose to fault. */ return false; } @@ -11090,17 +11087,19 @@ static uint8_t convert_stage2_attrs(CPUARMState *env, uint8_t s2attrs) } #endif /* !CONFIG_USER_ONLY */ +/* This mapping is common between ID_AA64MMFR0.PARANGE and TCR_ELx.{I}PS. */ +static const uint8_t pamax_map[] = { + [0] = 32, + [1] = 36, + [2] = 40, + [3] = 42, + [4] = 44, + [5] = 48, +}; + /* The cpu-specific constant value of PAMax; also used by hw/arm/virt. */ unsigned int arm_pamax(ARMCPU *cpu) { - static const unsigned int pamax_map[] = { - [0] = 32, - [1] = 36, - [2] = 40, - [3] = 42, - [4] = 44, - [5] = 48, - }; unsigned int parange = FIELD_EX64(cpu->isar.id_aa64mmfr0, ID_AA64MMFR0, PARANGE); @@ -11151,7 +11150,7 @@ ARMVAParameters aa64_va_parameters(CPUARMState *env, uint64_t va, { uint64_t tcr = regime_tcr(env, mmu_idx)->raw_tcr; bool epd, hpd, using16k, using64k; - int select, tsz, tbi; + int select, tsz, tbi, ps; if (!regime_has_2_ranges(mmu_idx)) { select = 0; @@ -11165,6 +11164,7 @@ ARMVAParameters aa64_va_parameters(CPUARMState *env, uint64_t va, hpd = extract32(tcr, 24, 1); } epd = false; + ps = extract64(tcr, 16, 3); } else { /* * Bit 55 is always between the two regions, and is canonical for @@ -11185,6 +11185,7 @@ ARMVAParameters aa64_va_parameters(CPUARMState *env, uint64_t va, epd = extract32(tcr, 23, 1); hpd = extract64(tcr, 42, 1); } + ps = extract64(tcr, 32, 3); } /* Present TBI as a composite with TBID. */ @@ -11196,6 +11197,7 @@ ARMVAParameters aa64_va_parameters(CPUARMState *env, uint64_t va, return (ARMVAParameters) { .tsz = tsz, + .ps = ps, .select = select, .tbi = tbi, .epd = epd, @@ -11312,7 +11314,7 @@ static bool get_phys_addr_lpae(CPUARMState *env, uint64_t address, target_ulong page_size; uint32_t attrs; int32_t stride; - int addrsize, inputsize; + int addrsize, inputsize, outputsize; TCR *tcr = regime_tcr(env, mmu_idx); int ap, ns, xn, pxn; uint32_t el = regime_el(env, mmu_idx); @@ -11323,6 +11325,7 @@ static bool get_phys_addr_lpae(CPUARMState *env, uint64_t address, /* TODO: This code does not support shareability levels. */ if (aarch64) { int min_tsz = 16, max_tsz = 39; /* TODO: ARMv8.2-LVA */ + int parange; param = aa64_va_parameters(env, address, mmu_idx, access_type != MMU_INST_FETCH); @@ -11348,11 +11351,22 @@ static bool get_phys_addr_lpae(CPUARMState *env, uint64_t address, addrsize = 64 - 8 * param.tbi; inputsize = 64 - param.tsz; + + /* + * Bound PS by PARANGE to find the effective output address size. + * ID_AA64MMFR0 is a read-only register so values outside of the + * supported mappings can be considered an implementation error. + */ + parange = FIELD_EX64(cpu->isar.id_aa64mmfr0, ID_AA64MMFR0, PARANGE); + parange = MIN(parange, param.ps); + assert(parange < ARRAY_SIZE(pamax_map)); + outputsize = pamax_map[parange]; } else { param = aa32_va_parameters(env, address, mmu_idx); level = 1; addrsize = (mmu_idx == ARMMMUIdx_Stage2 ? 40 : 32); inputsize = addrsize - param.tsz; + outputsize = 40; } /* @@ -11437,7 +11451,7 @@ static bool get_phys_addr_lpae(CPUARMState *env, uint64_t address, /* Check that the starting level is valid. */ ok = check_s2_mmu_setup(cpu, aarch64, startlevel, - inputsize, stride); + inputsize, stride, outputsize); if (!ok) { fault_type = ARMFault_Translation; goto do_fault; @@ -11445,24 +11459,41 @@ static bool get_phys_addr_lpae(CPUARMState *env, uint64_t address, level = startlevel; } - indexmask_grainsize = (1ULL << (stride + 3)) - 1; - indexmask = (1ULL << (inputsize - (stride * (4 - level)))) - 1; + indexmask_grainsize = MAKE_64BIT_MASK(0, stride + 3); + indexmask = MAKE_64BIT_MASK(0, inputsize - (stride * (4 - level))); /* Now we can extract the actual base address from the TTBR */ descaddr = extract64(ttbr, 0, 48); + + /* + * If the base address is out of range, raise AddressSizeFault. + * In the pseudocode, this is !IsZero(baseregister<47:outputsize>), + * but we've just cleared the bits above 47, so simplify the test. + */ + if (descaddr >> outputsize) { + level = 0; + fault_type = ARMFault_AddressSize; + goto do_fault; + } + /* * We rely on this masking to clear the RES0 bits at the bottom of the TTBR * and also to mask out CnP (bit 0) which could validly be non-zero. */ descaddr &= ~indexmask; - /* The address field in the descriptor goes up to bit 39 for ARMv7 - * but up to bit 47 for ARMv8, but we use the descaddrmask - * up to bit 39 for AArch32, because we don't need other bits in that case - * to construct next descriptor address (anyway they should be all zeroes). + /* + * The address field in the descriptor goes up to bit 39 for ARMv7 + * but up to bit 47 for ARMv8. In ARMv7, those middle bits are SBZP, + * but in ARMv8 they are checked for zero and an AddressSize fault + * is raised if they are not. */ - descaddrmask = ((1ull << (aarch64 ? 48 : 40)) - 1) & - ~indexmask_grainsize; + if (aarch64 || arm_feature(env, ARM_FEATURE_V8)) { + descaddrmask = MAKE_64BIT_MASK(0, 48); + } else { + 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 @@ -11487,7 +11518,12 @@ static bool get_phys_addr_lpae(CPUARMState *env, uint64_t address, /* Invalid, or the Reserved level 3 encoding */ goto do_fault; } + descaddr = descriptor & descaddrmask; + if (descaddr >> outputsize) { + fault_type = ARMFault_AddressSize; + goto do_fault; + } if ((descriptor & 2) && (level < 3)) { /* Table entry. The top five bits are attributes which may From patchwork Wed Dec 8 23:11:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 522230 Delivered-To: patch@linaro.org Received: by 2002:a05:6e04:2287:0:0:0:0 with SMTP id bl7csp155858imb; Wed, 8 Dec 2021 15:15:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJx1WyNdGjUoPO4GlPuQS//4P048QilDR7zvgbqUi8slDAv+Aq/+YBKdpAYNL2/wITX81ZKT X-Received: by 2002:a25:26ce:: with SMTP id m197mr2082568ybm.209.1639005357128; Wed, 08 Dec 2021 15:15:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1639005357; cv=none; d=google.com; s=arc-20160816; b=0aTQYOnQXjug5RwM0OxjGcXJ5HeeVzvP7KY1J2NPqjEdTpRtEbIYO/2Px/mNTDcvA4 1GRFrVV4NOzDCSeFJe3s8QzIifL7yBELfJWjBwVpIQFDXVWpFc3rlrnHw7hfJ4FaR86i xAj2vh6RZx3nueSapsUpd2SzJ3XMHHExd/PY1VvAgyDHRD7Ld++xCjzLxJ9/vp3ipSsF BM6DgatKbQVwPgrkzi2y6g1/VzlYASahUxgG61zlKmWRh5eo/mDzE7M86F8TS8Rf/vof ZndGoB8GVwIJYEAxod6mQFjE5m0rzPEvPUpMMbgEU4KPUOMfcInWwwwSw4n2xphYsBM6 vq5g== 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=nEPvlsXoO0/jwpDg/CNkKw+cUVDhy5CThal9Lsb0r4k=; b=PHvLDCAWNHVOS2VGMD2GkBZK78l+C1DEmu1sWUA1fhFCmctDLYvHbOhUpHuGxpK7wS upMmCx9wM/b4Q1qXF2BzEHAPNnCFrRKkyp8LR11jfdK8/i/kf/9+jekusdSCTUfcAFiW U2a6DbKy8m65O3kDBmb4DhiB511PYiXcC6DEPH0BMisc1Jxlkit+BiJRFDw78UtZYNh2 Wgrb4d0BHWSuqmn1+aZ1/6p00oUHTz6Yy1NowzqBHHVJ+I2Jn7mhzo871qmPutDUNlEW EvlnUa+Cwmb+OI1QoZzyqVYe0zZXgDAXPc/JKpIkuu33Y/w+r3RknnQZclxYCAeITeql wRPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iptOSutf; 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 o16si6266119yba.562.2021.12.08.15.15.57 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 08 Dec 2021 15:15:57 -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=iptOSutf; 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]:39994 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mv6AG-0001fI-Jv for patch@linaro.org; Wed, 08 Dec 2021 18:15:56 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34214) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mv66U-0005Bb-D1 for qemu-devel@nongnu.org; Wed, 08 Dec 2021 18:12:02 -0500 Received: from [2607:f8b0:4864:20::1031] (port=35808 helo=mail-pj1-x1031.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mv66S-0004nY-IE for qemu-devel@nongnu.org; Wed, 08 Dec 2021 18:12:02 -0500 Received: by mail-pj1-x1031.google.com with SMTP id j6-20020a17090a588600b001a78a5ce46aso5537243pji.0 for ; Wed, 08 Dec 2021 15:12:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=nEPvlsXoO0/jwpDg/CNkKw+cUVDhy5CThal9Lsb0r4k=; b=iptOSutfk+n404WPvENJMtfjI8rRKktJrMyiL5xGVm02IgDbP/wSv+hDnPNUdB7qEk XOe9YGxQV+Ji5zzyQclZEjRvdfKyP5Ej7jDM4/OWp4WS8He7rTNV3d2h/es1zdE1VAaV VTkCOmxZkaES1oRMPm0SVKf9A8AZEBX+uif0ke/LCdiw6egiUKuZlKrk+K0okLd8yq// eaymqfMM7EPkYbaqTwZoIy70bNTGOoVZiLhhb2hIK8wvkxC3yZT13WvtTIT4AmZUE0Ux QWray3NnBjm1lkkCRPVhzYBtObanN5awpMwzdpyJMepelk2aoiZ692GOWcNugtRuVNKQ qBTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nEPvlsXoO0/jwpDg/CNkKw+cUVDhy5CThal9Lsb0r4k=; b=A/af67xkbF1rpxl+6Dcqtojd1SXUapbMswiEylcKqEMCrQZpv4z5MZ7ktlq0H35JAr DM4d+2WUL3tS3X8mZICLgoTyct53GHAr7vVElHv5+AlUFWeCybHRjTAlODnYbTTpi66O HmB/ntB2p1GjxfSsLd5H/FnxhcXSqTYNEb7eeMwUjfBfSJlkvvrNPm6NIM4yp0dC3PxO OlpO9apLUBki+SdqDStapjpY0q9+fAS/3KfEyiexyOVj/lyfhBhEq6shqEUzHOZnNlON tH9OTJAL2vJCKdgHyApwUx+9SUoBxtJYgwR07VpcCE/Yd72O/jBZbcGZRnDcFbYJB284 kmkg== X-Gm-Message-State: AOAM531wMa1GD5fDenvU90/T1L0B8Hjeu62YOKszC+bqUSCD+3xjiQsn MGTeWVNxKxVlrQHrvPjT/sP+bER+X0iAig== X-Received: by 2002:a17:903:283:b0:142:1243:d879 with SMTP id j3-20020a170903028300b001421243d879mr63922603plr.61.1639005119325; Wed, 08 Dec 2021 15:11:59 -0800 (PST) Received: from localhost.localdomain (45-19-222-18.lightspeed.sntcca.sbcglobal.net. [45.19.222.18]) by smtp.gmail.com with ESMTPSA id k15sm3301062pgn.91.2021.12.08.15.11.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Dec 2021 15:11:58 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 4/6] target/arm: Implement FEAT_LVA Date: Wed, 8 Dec 2021 15:11:52 -0800 Message-Id: <20211208231154.392029-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211208231154.392029-1-richard.henderson@linaro.org> References: <20211208231154.392029-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::1031 (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::1031; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1031.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 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, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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" This feature is relatively small, as it applies only to 64k pages and thus requires no additional changes to the table descriptor walking algorithm, only a change to the minimum TSZ (which is the inverse of the maximum virtual address space size). Signed-off-by: Richard Henderson Reviewed-by: Alex Bennée --- target/arm/cpu-param.h | 2 +- target/arm/cpu.h | 5 +++++ target/arm/cpu64.c | 1 + target/arm/helper.c | 8 +++++++- 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/target/arm/cpu-param.h b/target/arm/cpu-param.h index 7f38d33b8e..5f9c288b1a 100644 --- a/target/arm/cpu-param.h +++ b/target/arm/cpu-param.h @@ -11,7 +11,7 @@ #ifdef TARGET_AARCH64 # define TARGET_LONG_BITS 64 # define TARGET_PHYS_ADDR_SPACE_BITS 48 -# define TARGET_VIRT_ADDR_SPACE_BITS 48 +# define TARGET_VIRT_ADDR_SPACE_BITS 52 #else # define TARGET_LONG_BITS 32 # define TARGET_PHYS_ADDR_SPACE_BITS 40 diff --git a/target/arm/cpu.h b/target/arm/cpu.h index e33f37b70a..3149000004 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -4288,6 +4288,11 @@ static inline bool isar_feature_aa64_ccidx(const ARMISARegisters *id) return FIELD_EX64(id->id_aa64mmfr2, ID_AA64MMFR2, CCIDX) != 0; } +static inline bool isar_feature_aa64_lva(const ARMISARegisters *id) +{ + return FIELD_EX64(id->id_aa64mmfr2, ID_AA64MMFR2, VARANGE) != 0; +} + static inline bool isar_feature_aa64_tts2uxn(const ARMISARegisters *id) { return FIELD_EX64(id->id_aa64mmfr1, ID_AA64MMFR1, XNX) != 0; diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c index 15245a60a8..f44ee643ef 100644 --- a/target/arm/cpu64.c +++ b/target/arm/cpu64.c @@ -755,6 +755,7 @@ static void aarch64_max_initfn(Object *obj) t = FIELD_DP64(t, ID_AA64MMFR2, UAO, 1); t = FIELD_DP64(t, ID_AA64MMFR2, CNP, 1); /* TTCNP */ t = FIELD_DP64(t, ID_AA64MMFR2, ST, 1); /* TTST */ + t = FIELD_DP64(t, ID_AA64MMFR2, VARANGE, 1); /* FEAT_LPA */ cpu->isar.id_aa64mmfr2 = t; t = cpu->isar.id_aa64zfr0; diff --git a/target/arm/helper.c b/target/arm/helper.c index 568914bd42..6a59975028 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -11324,7 +11324,7 @@ static bool get_phys_addr_lpae(CPUARMState *env, uint64_t address, /* TODO: This code does not support shareability levels. */ if (aarch64) { - int min_tsz = 16, max_tsz = 39; /* TODO: ARMv8.2-LVA */ + int min_tsz = 16, max_tsz = 39; int parange; param = aa64_va_parameters(env, address, mmu_idx, @@ -11334,6 +11334,12 @@ static bool get_phys_addr_lpae(CPUARMState *env, uint64_t address, if (cpu_isar_feature(aa64_st, env_archcpu(env))) { max_tsz = 48 - param.using64k; } + if (param.using64k) { + if (cpu_isar_feature(aa64_lva, env_archcpu(env))) { + min_tsz = 12; + } + } + /* TODO: FEAT_LPA2 */ /* * If TxSZ is programmed to a value larger than the maximum, From patchwork Wed Dec 8 23:11:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 522229 Delivered-To: patch@linaro.org Received: by 2002:a05:6e04:2287:0:0:0:0 with SMTP id bl7csp153444imb; Wed, 8 Dec 2021 15:13:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJwuXng9iH4UeyvPsgLFEu7RsgmJLEEmmfRvzPfIRBIXCISeXwOK8LYgwZl5WxeNtVSVaujd X-Received: by 2002:a67:2f05:: with SMTP id v5mr2166770vsv.25.1639005229672; Wed, 08 Dec 2021 15:13:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1639005229; cv=none; d=google.com; s=arc-20160816; b=RymIhNSMdL08XCBeiQuxb9mmbDxJAWkZRQdqABUip05e9VNuw4qZrtysIPcTQWz9tG sfYW0T2QN27e7YBKtqnl2bWDuFC6HqmzMc1S2IPKRd2S6EXWQ2MhReQEaeBEwTRYu3z8 KD/Quyl6BKgEkSBVW076dxmgv4R+DGWvFLI/s68WChEquWP49hUjCTqLR4iu2ew7CZMh WpkD7pDsAnjUlIIV7WcUWH6OeMuuxL/2T3CPNA+F+Q+RtTKw6tdQ4nvfdeDbXLGMO0tL l1+oLbG5XqDYZFNSIVBZs8tatoQ1ffh+B7jLn4X7ybMXMf1EesXI9LnnzLk7NwEB3JXB flZA== 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=eXPzA23R6/mCA8LiCwN5fF4QHA07i/kRSJFbv5jfL1Q=; b=uSPLawsQ2q9J23KkuzwO7mMKwb3FVphH4tZUVrq0kEX+0/N1QutWk1XFJs7y4TVMxk 4YIS9B2cu1yw6vBk8uoq/ban1CiCkMIFqPwpKplbau1cyR76h8YcNA6D6AtLf6Xo375a bZkiKx7ZDPA/5xXfuZXgFbC8mKRXVlkw9INjXScLLrmmVFdk6sUCwwVeMY5Qh/QlMX9G XukgkwCS6uxzDVMNR2vdeKcdkU7qREgod15aWBUdj96ErUi6dYVP89NWrEim7mS9+s0B x8sPCapWwvCVEK2urL7pndULOdxHQvpf4P13PPXbJINxkrM2kU3FtEXTt1Hc9xOpUF0M Vb4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="F/8o/wLQ"; 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 w132si5954362vkd.181.2021.12.08.15.13.49 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 08 Dec 2021 15:13:49 -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="F/8o/wLQ"; 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]:34254 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mv68D-0006DK-1r for patch@linaro.org; Wed, 08 Dec 2021 18:13:49 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34232) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mv66V-0005DE-2L for qemu-devel@nongnu.org; Wed, 08 Dec 2021 18:12:03 -0500 Received: from [2607:f8b0:4864:20::1032] (port=42789 helo=mail-pj1-x1032.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mv66T-0004nu-Ky for qemu-devel@nongnu.org; Wed, 08 Dec 2021 18:12:02 -0500 Received: by mail-pj1-x1032.google.com with SMTP id fv9-20020a17090b0e8900b001a6a5ab1392so3373654pjb.1 for ; Wed, 08 Dec 2021 15:12:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=eXPzA23R6/mCA8LiCwN5fF4QHA07i/kRSJFbv5jfL1Q=; b=F/8o/wLQeaecWx8RfLD+pdlx9Dw3/VgqLDr/EJB3WMo0NPjvBXhJbkDG1F/9TaYB7i +61+UhRoOrm4yaLttntd2lki51EqzD594hJPy4zmZVdTjTpbb/ZHptMjEhAlcD0PdRId XfHPkA5EnGsO/Rylx6Z4ap7x4Kgv5zLCO8J0onoei8fu/51E3vjhTU7yEnhGJg6Xi09i veyvE9XEkUNFn61yavn1kbZ2Da8pMaRNEv1hmZeErbZc/egSMNQWtgHwwvf96/cUTKhR 24ktlK9u3IBBQsealB1uMiWQeYsYJsB6cIuHJKuH9r6MjpSEt9eAlXMdHsmTQYizBBF+ umHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=eXPzA23R6/mCA8LiCwN5fF4QHA07i/kRSJFbv5jfL1Q=; b=HwbCVwxA190bG3jbRColvhE0OAWPcIQlxGF00o5d7jI2BG479IjMgzp3zXfvPGEgVW M423rlCI8x9vhcRnB6117YiIosz3JkpUC3p9tjX1+FS2x+AoG1c1TjxDP++DG6wtjghZ zKM789WMrQSqE1r0NN5JHI/bkYm1HohqrgbOXhsRMXcSdp+GPXrubg6KHOCObkg+SpSD MAEJ7UThfiCfggJw2qTuqbJOd72g4/6sP3/7FZcn8h3XCYZKTZErm2g0ySqwoK3Ky6O9 S39QRlF5umPElwkcQVWGl8ezZ0SsqoOVygAQWIUPtL3UTKvGDh8nIj92OTuYFpfcSu47 rX/Q== X-Gm-Message-State: AOAM533pckDkcm7mUb1VHOT5Tj96+4ies9hU5/HQgEtqxPvjQmO+QxRS XCNe+e40s1Rip4yw0i36De+pv7h/l1IQ4w== X-Received: by 2002:a17:902:a605:b0:143:d289:f3fb with SMTP id u5-20020a170902a60500b00143d289f3fbmr63139108plq.41.1639005120089; Wed, 08 Dec 2021 15:12:00 -0800 (PST) Received: from localhost.localdomain (45-19-222-18.lightspeed.sntcca.sbcglobal.net. [45.19.222.18]) by smtp.gmail.com with ESMTPSA id k15sm3301062pgn.91.2021.12.08.15.11.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Dec 2021 15:11:59 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 5/6] target/arm: Implement FEAT_LPA Date: Wed, 8 Dec 2021 15:11:53 -0800 Message-Id: <20211208231154.392029-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211208231154.392029-1-richard.henderson@linaro.org> References: <20211208231154.392029-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::1032 (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::1032; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1032.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 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, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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" Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- target/arm/cpu-param.h | 2 +- target/arm/cpu64.c | 2 +- target/arm/helper.c | 19 ++++++++++++++++--- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/target/arm/cpu-param.h b/target/arm/cpu-param.h index 5f9c288b1a..b59d505761 100644 --- a/target/arm/cpu-param.h +++ b/target/arm/cpu-param.h @@ -10,7 +10,7 @@ #ifdef TARGET_AARCH64 # define TARGET_LONG_BITS 64 -# define TARGET_PHYS_ADDR_SPACE_BITS 48 +# define TARGET_PHYS_ADDR_SPACE_BITS 52 # define TARGET_VIRT_ADDR_SPACE_BITS 52 #else # define TARGET_LONG_BITS 32 diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c index f44ee643ef..3bb79ca744 100644 --- a/target/arm/cpu64.c +++ b/target/arm/cpu64.c @@ -739,7 +739,7 @@ static void aarch64_max_initfn(Object *obj) cpu->isar.id_aa64pfr1 = t; t = cpu->isar.id_aa64mmfr0; - t = FIELD_DP64(t, ID_AA64MMFR0, PARANGE, 5); /* PARange: 48 bits */ + t = FIELD_DP64(t, ID_AA64MMFR0, PARANGE, 6); /* FEAT_LPA: 52 bits */ cpu->isar.id_aa64mmfr0 = t; t = cpu->isar.id_aa64mmfr1; diff --git a/target/arm/helper.c b/target/arm/helper.c index 6a59975028..e39c1f5b3a 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -11095,6 +11095,7 @@ static const uint8_t pamax_map[] = { [3] = 42, [4] = 44, [5] = 48, + [6] = 52, }; /* The cpu-specific constant value of PAMax; also used by hw/arm/virt. */ @@ -11472,11 +11473,15 @@ static bool get_phys_addr_lpae(CPUARMState *env, uint64_t address, descaddr = extract64(ttbr, 0, 48); /* - * If the base address is out of range, raise AddressSizeFault. + * For FEAT_LPA and PS=6, bits [51:48] of descaddr are in [5:2] of TTBR. + * + * Otherwise, if the base address is out of range, raise AddressSizeFault. * In the pseudocode, this is !IsZero(baseregister<47:outputsize>), * but we've just cleared the bits above 47, so simplify the test. */ - if (descaddr >> outputsize) { + if (outputsize > 48) { + descaddr |= extract64(ttbr, 2, 4) << 48; + } else if (descaddr >> outputsize) { level = 0; fault_type = ARMFault_AddressSize; goto do_fault; @@ -11526,7 +11531,15 @@ static bool get_phys_addr_lpae(CPUARMState *env, uint64_t address, } descaddr = descriptor & descaddrmask; - if (descaddr >> outputsize) { + + /* + * For FEAT_LPA and PS=6, bits [51:48] of descaddr are in [15:12] + * of descriptor. Otherwise, if descaddr is out of range, raise + * AddressSizeFault. + */ + if (outputsize > 48) { + descaddr |= extract64(descriptor, 12, 4) << 48; + } else if (descaddr >> outputsize) { fault_type = ARMFault_AddressSize; goto do_fault; } From patchwork Wed Dec 8 23:11:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 522233 Delivered-To: patch@linaro.org Received: by 2002:a05:6e04:2287:0:0:0:0 with SMTP id bl7csp160863imb; Wed, 8 Dec 2021 15:20:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJy4Q1vfxcmxY1/22laG4EkHmrItHhXC0bvlXaNwYKfpuh8wwoZ69oiVRtCprbzodmuAfQ2K X-Received: by 2002:a05:6102:5086:: with SMTP id bl6mr2228372vsb.64.1639005612871; Wed, 08 Dec 2021 15:20:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1639005612; cv=none; d=google.com; s=arc-20160816; b=uWUogjPLIOG/IyO6KfFgOpPhmIv8qsTtcwbOAGWEfb4O6wASEKnAh9TrAbgKpAHlix +TEUWe6XW+LfgjOfCjRh/vu1PV6o5rRiaMTPl9Jfty77rATgzaWv6alinsN5h3LcNX3f Lrcg6IK+7UEIWCsSCza5exwR0UwqxkDdrlzuSq4egMlmjCRoYV6SMVPYrDV8PYdnUCIZ g9374M4Oc9PGQnyVNHlYQhMvkcy27zds0jFTiB69QstX3f/1VG3q9vR1J3ZZzo/Qo736 8OFuyO3DU21GHc74ZpAd3wR/pmifCUr5LQd0LNiUluCC8mQWAbTPwQoOGvt5yz400ztX frtA== 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=uAAN1kaoQfn9Rr4weQnVVbWtBx1U1Cj2+/RVGbi/Znc=; b=vqW+wYaEQF/Vo/BdtwyBz6+qMbT0U8fNR0Qa4VePupctXDb/u3VI8P4tS1Z3VR/gnS iSrFHDQj3fbZZZZJR6Q7vcR4hlB9KploFMUCO0NfdB9r7ekmx43ex9C3HbbBOh3xoXGF 82r1CEL8WfQyQIgwDAlhz0ht053j2Uty1g60ASKpBtc2yatsyQvDEYYOqXYPWzkwOlUD wok4L9TZD1SXN71CkILsYMPGA82YQd5FX8/nmv99ONOdEUudSpVp2GlV78TTF04L9n2e wQLt7CPNdOO71D0/wfd+NatkdxGZo2Q3Ql3o+tYEkyq6P25zNdFQLQodsLuQcTzPLccn stAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZGWN0Qm8; 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 g2si5750433uaw.135.2021.12.08.15.20.12 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 08 Dec 2021 15:20:12 -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=ZGWN0Qm8; 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]:49848 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mv6EO-0008Os-9Z for patch@linaro.org; Wed, 08 Dec 2021 18:20:12 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34252) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mv66W-0005GU-2E for qemu-devel@nongnu.org; Wed, 08 Dec 2021 18:12:04 -0500 Received: from [2607:f8b0:4864:20::62f] (port=46867 helo=mail-pl1-x62f.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mv66U-0004oJ-6m for qemu-devel@nongnu.org; Wed, 08 Dec 2021 18:12:03 -0500 Received: by mail-pl1-x62f.google.com with SMTP id p18so2542709plf.13 for ; Wed, 08 Dec 2021 15:12:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=uAAN1kaoQfn9Rr4weQnVVbWtBx1U1Cj2+/RVGbi/Znc=; b=ZGWN0Qm8ZcnMBjqS+4QWdb8rEBhm1xVtj3vrz5bkaTjZPPQlhBVgtp41c3/K8jq4KI oKzGuLNfqpOTszNnOArZnNBCG050ycuJyO3MYn6Kd8YXo4sh0SvNRsZrjIxsvx9aAWiP yYbeolZsqHmOc0MK3im1YkpKl4ZMBhTuhTfuZ0UlLEclp0yviMUWGxCxlr5UG19HBzY3 ZM7dGJU+7yPKLcci55w5J2yExBwhAqK86G+9WnDdl2UPIm7pWYUewTOgJy6GcktyhJ+m 9spHRMgoc5PsqRGswjAtT9TaddOmPWkPpqqjlO7V/9KAlzXib14f6WMjIqqdl/jorntS joTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uAAN1kaoQfn9Rr4weQnVVbWtBx1U1Cj2+/RVGbi/Znc=; b=0JDv2BTuveL3+6HL2QXr2wLgBNvtyUUwEEmSrKntFY2/rsG9nohU9BT0XGWQpPTCtt P2uOeHYudNgof57wjvM82G4SvdMcG2oICkoicrR1H3ScpYXekeOgWpetll3Dwfq/Uk6m WWl7PLhS5fHvNnGXDe5lU7sGhqCJx4DPSH29kt9MG3C78jkN1Aiq6SeM/OdXoiuKV8Ld 5XTTsrIufu55wx8ojUsbdJq85Qitam7o13nmsVubf8jEmIYYIE8InuOcO4F3tWg8ScV9 xPdzZuNBDwErTNZqhndFWvpXR4j8fYOOaO1RkxrhdDXKiIaTdoyZ9p0grNvszGt9gYBB GIeQ== X-Gm-Message-State: AOAM532apu2vdWSuxmQTot1ZqWk5V5Zkscu4GmmV0Th33Oy8b4dRYLAx rKEB67SJqBEwfdl0soNB3ogmsLS0Q2y/WQ== X-Received: by 2002:a17:903:1c5:b0:141:fbe2:56c1 with SMTP id e5-20020a17090301c500b00141fbe256c1mr62743920plh.52.1639005120803; Wed, 08 Dec 2021 15:12:00 -0800 (PST) Received: from localhost.localdomain (45-19-222-18.lightspeed.sntcca.sbcglobal.net. [45.19.222.18]) by smtp.gmail.com with ESMTPSA id k15sm3301062pgn.91.2021.12.08.15.12.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Dec 2021 15:12:00 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 6/6] target/arm: Implement FEAT_LPA2 Date: Wed, 8 Dec 2021 15:11:54 -0800 Message-Id: <20211208231154.392029-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211208231154.392029-1-richard.henderson@linaro.org> References: <20211208231154.392029-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::62f (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::62f; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62f.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 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, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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" Signed-off-by: Richard Henderson Reviewed-by: Alex Bennée --- target/arm/cpu.h | 12 +++++++ target/arm/internals.h | 2 ++ target/arm/cpu64.c | 2 ++ target/arm/helper.c | 80 +++++++++++++++++++++++++++++++++++------- 4 files changed, 83 insertions(+), 13 deletions(-) diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 3149000004..379585352b 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -4283,6 +4283,18 @@ static inline bool isar_feature_aa64_i8mm(const ARMISARegisters *id) return FIELD_EX64(id->id_aa64isar1, ID_AA64ISAR1, I8MM) != 0; } +static inline bool isar_feature_aa64_tgran4_lpa2(const ARMISARegisters *id) +{ + return sextract64(id->id_aa64mmfr0, + R_ID_AA64MMFR0_TGRAN4_SHIFT, + R_ID_AA64MMFR0_TGRAN4_LENGTH) >= 1; +} + +static inline bool isar_feature_aa64_tgran16_lpa2(const ARMISARegisters *id) +{ + return FIELD_EX64(id->id_aa64mmfr0, ID_AA64MMFR0, TGRAN16) >= 2; +} + static inline bool isar_feature_aa64_ccidx(const ARMISARegisters *id) { return FIELD_EX64(id->id_aa64mmfr2, ID_AA64MMFR2, CCIDX) != 0; diff --git a/target/arm/internals.h b/target/arm/internals.h index 3e801833b4..868cae2a55 100644 --- a/target/arm/internals.h +++ b/target/arm/internals.h @@ -1033,12 +1033,14 @@ static inline uint32_t aarch64_pstate_valid_mask(const ARMISARegisters *id) typedef struct ARMVAParameters { unsigned tsz : 8; unsigned ps : 3; + unsigned sh : 2; unsigned select : 1; bool tbi : 1; bool epd : 1; bool hpd : 1; bool using16k : 1; bool using64k : 1; + bool ds : 1; } ARMVAParameters; ARMVAParameters aa64_va_parameters(CPUARMState *env, uint64_t va, diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c index 3bb79ca744..5a1940aa94 100644 --- a/target/arm/cpu64.c +++ b/target/arm/cpu64.c @@ -740,6 +740,8 @@ static void aarch64_max_initfn(Object *obj) t = cpu->isar.id_aa64mmfr0; t = FIELD_DP64(t, ID_AA64MMFR0, PARANGE, 6); /* FEAT_LPA: 52 bits */ + t = FIELD_DP64(t, ID_AA64MMFR0, TGRAN16, 2); /* FEAT_LPA2: 52 bits */ + t = FIELD_DP64(t, ID_AA64MMFR0, TGRAN4, 1); /* FEAT_LPA2: 52 bits */ cpu->isar.id_aa64mmfr0 = t; t = cpu->isar.id_aa64mmfr1; diff --git a/target/arm/helper.c b/target/arm/helper.c index e39c1f5b3a..f4a8b37f98 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -11008,8 +11008,13 @@ static bool check_s2_mmu_setup(ARMCPU *cpu, bool is_aa64, int level, const int grainsize = stride + 3; int startsizecheck; - /* Negative levels are never allowed. */ - if (level < 0) { + /* + * Negative levels are usually not allowed... + * Except for FEAT_LPA2, 4k page table, 52-bit address space, which + * begins with level -1. Note that previous feature tests will have + * eliminated this combination if it is not enabled. + */ + if (level < (inputsize == 52 && stride == 9 ? -1 : 0)) { return false; } @@ -11150,8 +11155,8 @@ ARMVAParameters aa64_va_parameters(CPUARMState *env, uint64_t va, ARMMMUIdx mmu_idx, bool data) { uint64_t tcr = regime_tcr(env, mmu_idx)->raw_tcr; - bool epd, hpd, using16k, using64k; - int select, tsz, tbi, ps; + bool epd, hpd, using16k, using64k, ds; + int select, tsz, tbi, ps, sh; if (!regime_has_2_ranges(mmu_idx)) { select = 0; @@ -11165,7 +11170,9 @@ ARMVAParameters aa64_va_parameters(CPUARMState *env, uint64_t va, hpd = extract32(tcr, 24, 1); } epd = false; + sh = extract64(tcr, 12, 2); ps = extract64(tcr, 16, 3); + ds = extract64(tcr, 32, 1); } else { /* * Bit 55 is always between the two regions, and is canonical for @@ -11175,6 +11182,7 @@ ARMVAParameters aa64_va_parameters(CPUARMState *env, uint64_t va, if (!select) { tsz = extract32(tcr, 0, 6); epd = extract32(tcr, 7, 1); + sh = extract32(tcr, 12, 2); using64k = extract32(tcr, 14, 1); using16k = extract32(tcr, 15, 1); hpd = extract64(tcr, 41, 1); @@ -11184,9 +11192,11 @@ ARMVAParameters aa64_va_parameters(CPUARMState *env, uint64_t va, using64k = tg == 3; tsz = extract32(tcr, 16, 6); epd = extract32(tcr, 23, 1); + sh = extract32(tcr, 28, 2); hpd = extract64(tcr, 42, 1); } ps = extract64(tcr, 32, 3); + ds = extract64(tcr, 59, 1); } /* Present TBI as a composite with TBID. */ @@ -11199,12 +11209,14 @@ ARMVAParameters aa64_va_parameters(CPUARMState *env, uint64_t va, return (ARMVAParameters) { .tsz = tsz, .ps = ps, + .sh = sh, .select = select, .tbi = tbi, .epd = epd, .hpd = hpd, .using16k = using16k, .using64k = using64k, + .ds = ds, }; } @@ -11332,15 +11344,31 @@ static bool get_phys_addr_lpae(CPUARMState *env, uint64_t address, access_type != MMU_INST_FETCH); level = 0; - if (cpu_isar_feature(aa64_st, env_archcpu(env))) { + /* Find the minimum allowed input address size. */ + if (cpu_isar_feature(aa64_st, cpu)) { max_tsz = 48 - param.using64k; } + + /* + * Find the maximum allowed input address size. + * DS is RES0 unless FEAT_LPA2 is supported for the given page size; + * adjust param.ds to the effective value of DS, as documented. + */ if (param.using64k) { - if (cpu_isar_feature(aa64_lva, env_archcpu(env))) { + if (cpu_isar_feature(aa64_lva, cpu)) { min_tsz = 12; } + param.ds = false; + } else if (param.ds) { + /* ??? Assume tgran{4,16}_2 == 0, i.e. match tgran{4,16}. */ + if (param.using16k + ? cpu_isar_feature(aa64_tgran16_lpa2, cpu) + : cpu_isar_feature(aa64_tgran4_lpa2, cpu)) { + min_tsz = 12; + } else { + param.ds = false; + } } - /* TODO: FEAT_LPA2 */ /* * If TxSZ is programmed to a value larger than the maximum, @@ -11441,10 +11469,19 @@ static bool get_phys_addr_lpae(CPUARMState *env, uint64_t address, * VTCR_EL2.SL0 field (whose interpretation depends on the page size) */ uint32_t sl0 = extract32(tcr->raw_tcr, 6, 2); + uint32_t sl2 = extract64(tcr->raw_tcr, 33, 1); uint32_t startlevel; bool ok; - if (!aarch64 || stride == 9) { + /* SL2 is RES0 unless DS=1 & 4kb granule. */ + if (param.ds && stride == 9 && sl2) { + if (sl0 != 0) { + level = 0; + fault_type = ARMFault_Translation; + goto do_fault; + } + startlevel = -1; + } else if (!aarch64 || stride == 9) { /* AArch32 or 4KB pages */ startlevel = 2 - sl0; @@ -11499,7 +11536,9 @@ static bool get_phys_addr_lpae(CPUARMState *env, uint64_t address, * but in ARMv8 they are checked for zero and an AddressSize fault * is raised if they are not. */ - if (aarch64 || arm_feature(env, ARM_FEATURE_V8)) { + if (param.ds) { + descaddrmask = MAKE_64BIT_MASK(0, 50); + } else if (aarch64 || arm_feature(env, ARM_FEATURE_V8)) { descaddrmask = MAKE_64BIT_MASK(0, 48); } else { descaddrmask = MAKE_64BIT_MASK(0, 40); @@ -11534,11 +11573,16 @@ static bool get_phys_addr_lpae(CPUARMState *env, uint64_t address, /* * For FEAT_LPA and PS=6, bits [51:48] of descaddr are in [15:12] - * of descriptor. Otherwise, if descaddr is out of range, raise - * AddressSizeFault. + * of descriptor. For FEAT_LPA2 and effective DS, bits [51:50] of + * descaddr are in [9:8]. Otherwise, if descaddr is out of range, + * raise AddressSizeFault. */ if (outputsize > 48) { - descaddr |= extract64(descriptor, 12, 4) << 48; + if (param.ds) { + descaddr |= extract64(descriptor, 8, 2) << 50; + } else { + descaddr |= extract64(descriptor, 12, 4) << 48; + } } else if (descaddr >> outputsize) { fault_type = ARMFault_AddressSize; goto do_fault; @@ -11632,7 +11676,17 @@ static bool get_phys_addr_lpae(CPUARMState *env, uint64_t address, assert(attrindx <= 7); cacheattrs->attrs = extract64(mair, attrindx * 8, 8); } - cacheattrs->shareability = extract32(attrs, 6, 2); + + /* + * For FEAT_LPA2 and effective DS, the SH field in the attributes + * was re-purposed for output address bits. The SH attribute in + * that case comes from TCR_ELx, which we extracted earlier. + */ + if (param.ds) { + cacheattrs->shareability = param.sh; + } else { + cacheattrs->shareability = extract32(attrs, 6, 2); + } *phys_ptr = descaddr; *page_size_ptr = page_size;