From patchwork Mon Oct 9 12:08:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13413516 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id DC903E95A96 for ; Mon, 9 Oct 2023 12:12:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 588946B0116; Mon, 9 Oct 2023 08:12:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5396C6B0117; Mon, 9 Oct 2023 08:12:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 401296B0118; Mon, 9 Oct 2023 08:12:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 2C6996B0116 for ; Mon, 9 Oct 2023 08:12:29 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 06121B48BB for ; Mon, 9 Oct 2023 12:12:29 +0000 (UTC) X-FDA: 81325810818.20.B3BAA84 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf11.hostedemail.com (Postfix) with ESMTP id 07E7140006 for ; Mon, 9 Oct 2023 12:12:26 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=j9U89MV1; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf11.hostedemail.com: domain of broonie@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=broonie@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1696853547; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=9L/qLqBtAh0CT0/a9d9JFTAwYj23uTsA4POYtvvApb8=; b=j+OdufB0qNjp3rs5Uaj3gaseCET8CVvSiZJrG5kOCX1KZof17C410P0y2/P4RV8nQ8k/R4 HAAxzOfuvW8u6oxESWM8UR8p8m2W8XfqGFwFZYtTBGfyzD3GmOZ+iYVSIA0HeLwGMly+xn VWfmwy94Z89dfjmGPwkqdasBztA0gik= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=j9U89MV1; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf11.hostedemail.com: domain of broonie@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=broonie@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1696853547; a=rsa-sha256; cv=none; b=te5+DN+Yg/KKztuNpIpgjV01OcvuEisrxuVkaI/Z2G1Vdo2OGm8yicruQBaFFMdQipBsOw OjV5T9giYNmk+53H6EdH76g9aBgwfmwFAalIXBNBlAP4KscfIV6YqBP0+rrDkDGdTD4AUc QEBjzhCxGXjZODoAV9EXzy3bbeafdho= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by ams.source.kernel.org (Postfix) with ESMTP id A9016B81145; Mon, 9 Oct 2023 12:12:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BD389C433CC; Mon, 9 Oct 2023 12:12:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1696853544; bh=HYoopujMYYx9DIwWQ/56zZgOFvuBdtqWANEIYJVZJO8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=j9U89MV1GBU5jOVOLZpCSQry22wWl///VTwFucF5T+ppLeyNlY+ijNsKStJjX34zz TKtMy0coDvVyA+8ko0HqNYCUMkgHFACaF6LEWpLS1QxmhzeE9XnEjzyQ0M8mEULhOy LoDl1uMcTq+Z0BPqDawgEjWUIaaGtEiTfAuKnfR4txzV/sle6cv7axr7grDcYKQzB0 cMUl8mqk7ccL5ojvydYfH77A8erbD64hcfT3XJ4LIwDDSLm8GsFaXNsL/c0VGUO7LX elVXN6hoTFeVaqLLe/WXRoRAuUJPbwwSWMPqVxC1UU5DdJApxPBpYygj5t2E7gAAB0 PKRs52LSefP9A== From: Mark Brown Date: Mon, 09 Oct 2023 13:08:49 +0100 Subject: [PATCH v6 15/38] arm64/gcs: Allow GCS usage at EL0 and EL1 MIME-Version: 1.0 Message-Id: <20231009-arm64-gcs-v6-15-78e55deaa4dd@kernel.org> References: <20231009-arm64-gcs-v6-0-78e55deaa4dd@kernel.org> In-Reply-To: <20231009-arm64-gcs-v6-0-78e55deaa4dd@kernel.org> To: Catalin Marinas , Will Deacon , Jonathan Corbet , Andrew Morton , Marc Zyngier , Oliver Upton , James Morse , Suzuki K Poulose , Arnd Bergmann , Oleg Nesterov , Eric Biederman , Kees Cook , Shuah Khan , "Rick P. Edgecombe" , Deepak Gupta , Ard Biesheuvel , Szabolcs Nagy Cc: "H.J. Lu" , Paul Walmsley , Palmer Dabbelt , Albert Ou , Florian Weimer , Christian Brauner , linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, kvmarm@lists.linux.dev, linux-fsdevel@vger.kernel.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, Mark Brown X-Mailer: b4 0.13-dev-0438c X-Developer-Signature: v=1; a=openpgp-sha256; l=2250; i=broonie@kernel.org; h=from:subject:message-id; bh=HYoopujMYYx9DIwWQ/56zZgOFvuBdtqWANEIYJVZJO8=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBlI+2dfP1gHPRa8C0+dKhkGMXquypekN26lEUP9onB zh3nmgqJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZSPtnQAKCRAk1otyXVSH0GamB/ 4zkdD6yWJZ6LzOyEnr8Hw3FnF1NVfnuu8/QcW8ibj5rkATYPiavxMq3LPm07WlulO7ZtCP7Gdeg0GH kDP3wzqx62horUPdFah+l76lfzloOsBbU39pySCg9LZVRsnjG1FyFqDV/K7qE5GDRondjc529mjnmW /Zq7/3B279Cu8mPCyA322DF81o2QzFuyQqwCwR1f/nvr1kKFH/CAFqJR1R1zfkYTz948CaxtKKewpc 7k2FwkiXhUAo2OyVo5APZZQ4cGYkttf6x44lxUYW5FpwU9Okq5Y1aiKcdQ3ADCFCe2kgupisipbU4v oMCEU+UrDbK8wEiZ/6nPcObFK6gRMN X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Rspamd-Queue-Id: 07E7140006 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: 7bey88e9cmut1qchdiougtexruzdjbeg X-HE-Tag: 1696853546-872136 X-HE-Meta: U2FsdGVkX18TWl0TdwAKuMWtozTbF8qDZZWvdqehUIHtXrkIYNQ4aFl+f5xY/qKFwa0s5nT+YI8cmexw6jaXsbtZfl9eLFjBL3rZvHSiGxPbKTRZjdULWhP3Y//cVc4F7vBZU27coxe4RDuu5dtPHIqAn/WKskVxkuznPRmsu/vHmY/F844vvTRi+h3LM9fDGhKaspgANrP71qCXd8khXKAcMgbqXnwHrOZKUry/hwygXLoGT4WBnbe8mjxmBA4SDh4yUC10G0N8mjWxNw4bNMqoRwZBrMyxnQteGnPLJzJMNs3048yUl/nQHk0mp2jeBEHoKR/znS4SCdYxYs+fx/KvKr+HV4JqJgOEF+ex1E1bGbEsbPYvI9AqO0rVvzgXadombg68q/oI6MSUpTdmovX+ICq552LnDWwnd1MvGjmo8lsM7CzWs4R6/kpeuUkxg9PIaFtdwyGYQ3l+SWG7swLiGUcSir13bzHoZkDT06/qk6xU54YBBaxRDkroO/NFWBAW3xSmpXPHsKwsDH56DFhzYXaCFBSiOrywkLuw2SexhL752mvL/OwOC/WSyGJvHPqWeIStLEklwJRZG78AL9pVoio5Cnn7d2rtqt6sQghpUZ2+IKkwbBWKdB1uqstbXg2IqaO0n1W9B8u1IKqljTN0SlcJXyJEZEOnJgOL4M+OqI/5LoBXT2lLdDP6vp797RQo2vv6tHSvRwDxl0JNjgZHF3teS3TbTzFVOGAXd91vqPEudhy75ybI2Fw8c84HwLIdN5eMukUAlY+S20rTY256jioMgSA7WtOlI1M4bxwhoHya6/279AsaHfoSokgfy+pLd1Zhzvs4OhsPKtMkLOy0HA7E3Iwo7erJ8rL4vQiS0/0/w96G5yP2jbq8Px7kXXEgLS6VIxLj1+rwH40iPHslLd7UWM/fXVo6etb1pq/OLO56C9OfJEdmeVrT8k2fyU6YyBCYf1hYWPhVeyL xkA/sv7y N+UP68iivpXPJDn+f0cF2WNs0KwPt4jF9IsQ0mt6aTiBo/KBtGPTpvHJYIzyP6vSY77ENrbcFN1eJAm1NJn0bm7HjSPgLJSeH3HqoY5/onAQD3M6KOpDe13hKf5wyigk7z4mrE/yrSb/Cbfrp5qRuKt9TL+ZD59Qr5Bn4tasCVncou9tOmzNzTO/h1EcO1VQ96fqXaUqCMyCoXnkm8n/8rw20IGG4svwyMueDD6xtzE7xyXeyc0hBmgFdApcbk9tUAxjzTIbKMogwcA75J7qL4uU1bhGLXyDoRdLqQ/S+SYpgds27xvwKas0AaJe9D+U+NJlNfzQbGbKTXnI= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: There is a control HCRX_EL2.GCSEn which must be set to allow GCS features to take effect at lower ELs and also fine grained traps for GCS usage at EL0 and EL1. Configure all these to allow GCS usage by EL0 and EL1. Signed-off-by: Mark Brown --- arch/arm64/include/asm/el2_setup.h | 17 +++++++++++++++++ arch/arm64/include/asm/kvm_arm.h | 4 ++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/arch/arm64/include/asm/el2_setup.h b/arch/arm64/include/asm/el2_setup.h index b7afaa026842..17672563e333 100644 --- a/arch/arm64/include/asm/el2_setup.h +++ b/arch/arm64/include/asm/el2_setup.h @@ -27,6 +27,14 @@ ubfx x0, x0, #ID_AA64MMFR1_EL1_HCX_SHIFT, #4 cbz x0, .Lskip_hcrx_\@ mov_q x0, HCRX_HOST_FLAGS + + /* Enable GCS if supported */ + mrs_s x1, SYS_ID_AA64PFR1_EL1 + ubfx x1, x1, #ID_AA64PFR1_EL1_GCS_SHIFT, #4 + cbz x1, .Lset_hcrx_\@ + orr x0, x0, #HCRX_EL2_GCSEn + +.Lset_hcrx_\@: msr_s SYS_HCRX_EL2, x0 .Lskip_hcrx_\@: .endm @@ -190,6 +198,15 @@ orr x0, x0, #HFGxTR_EL2_nPIR_EL1 orr x0, x0, #HFGxTR_EL2_nPIRE0_EL1 + /* GCS depends on PIE so we don't check it if PIE is absent */ + mrs_s x1, SYS_ID_AA64PFR1_EL1 + ubfx x1, x1, #ID_AA64PFR1_EL1_GCS_SHIFT, #4 + cbz x1, .Lset_fgt_\@ + + /* Disable traps of access to GCS registers at EL0 and EL1 */ + orr x0, x0, #HFGxTR_EL2_nGCS_EL1_MASK + orr x0, x0, #HFGxTR_EL2_nGCS_EL0_MASK + .Lset_fgt_\@: msr_s SYS_HFGRTR_EL2, x0 msr_s SYS_HFGWTR_EL2, x0 diff --git a/arch/arm64/include/asm/kvm_arm.h b/arch/arm64/include/asm/kvm_arm.h index 5882b2415596..d74b626b829a 100644 --- a/arch/arm64/include/asm/kvm_arm.h +++ b/arch/arm64/include/asm/kvm_arm.h @@ -102,8 +102,8 @@ #define HCR_HOST_NVHE_PROTECTED_FLAGS (HCR_HOST_NVHE_FLAGS | HCR_TSC) #define HCR_HOST_VHE_FLAGS (HCR_RW | HCR_TGE | HCR_E2H) -#define HCRX_GUEST_FLAGS (HCRX_EL2_SMPME | HCRX_EL2_TCR2En) -#define HCRX_HOST_FLAGS (HCRX_EL2_MSCEn | HCRX_EL2_TCR2En) +#define HCRX_GUEST_FLAGS (HCRX_EL2_SMPME | HCRX_EL2_TCR2En | HCRX_EL2_GCSEn) +#define HCRX_HOST_FLAGS (HCRX_EL2_MSCEn | HCRX_EL2_TCR2En | HCRX_EL2_GCSEn) /* TCR_EL2 Registers bits */ #define TCR_EL2_RES1 ((1U << 31) | (1 << 23))