From patchwork Thu Aug 1 12:06:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13750388 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 CF55EC3DA64 for ; Thu, 1 Aug 2024 12:58:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 60CC16B00A5; Thu, 1 Aug 2024 08:58:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 596726B00A6; Thu, 1 Aug 2024 08:58:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 40FD06B00A7; Thu, 1 Aug 2024 08:58:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 1FB3B6B00A5 for ; Thu, 1 Aug 2024 08:58:28 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id CAA7D160D45 for ; Thu, 1 Aug 2024 12:58:27 +0000 (UTC) X-FDA: 82403680254.25.1CB6BF7 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf29.hostedemail.com (Postfix) with ESMTP id 69C6012002F for ; Thu, 1 Aug 2024 12:58:25 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=pTC4lgO7; spf=pass (imf29.hostedemail.com: domain of broonie@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=broonie@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722517050; 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=UPBStWM6YeANFGDZl+K7sYZhcCxUJS/7XncZR9RI7Zc=; b=n8xO8TMgiaMA9p/RA+RIQwIwhd0TzUSEvQMfIAV7nJZPY8xOb6Pji9+IYyHZZEPk6VE0ZV 2Xlwdz0yiAth/2q/XLR+vO0e694Ce1ifK0lFGUdt7GzAZy5zhH/ks/Doe9azroqD8GGyvV cGF5vW5XIOf/6Z6kI1Uvi6IiQoqwu1Q= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722517050; a=rsa-sha256; cv=none; b=d6sUdBdFos5JIspX1dajud3TwqM5yR4KhJP1Wz9s0klHDuyFsZUPWPoMqF6cxr54KxBEn+ rJuRqLEmphKIb8jT1lB1peothLBsRP36NixmW+Oj4PmAVn0iOzMgB31hqxqpT2j59rWfUT 2UXUARiPcotx6fv1y1udLPVgKt6ijPE= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=pTC4lgO7; spf=pass (imf29.hostedemail.com: domain of broonie@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=broonie@kernel.org; dmarc=pass (policy=none) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 6A245CE19B5; Thu, 1 Aug 2024 12:58:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1DD58C4AF09; Thu, 1 Aug 2024 12:58:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722517101; bh=n96ljJnJVMpYM9CVsfMUORPIasrMIuo5nt8SCuY5I/I=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=pTC4lgO7SQKGHaiX2nkMESdUjPENIlCeXI7cbdMEO1veZv+NnE7Q0HtzHnypIRSwX EFFbCP9R/odkVfMcUNhw2BYaIXYd3+HHHyjwGShekpbDTq/8639R57lZi260FRwS9W BXwQfAdQaytr8C0yGa+c68hCauRvpcE5dlS4czXMOBk4eaOepEeEMdHSJS4YgQtuZk I467IPjnvVLTzCPUkz/2CCGzWf602uS+MbKUA33Seoqav/yPBIg4Pmjhg1gOrHSJdQ mzerRki9mRWRzWC7SiWU82YMhlX5m5cdrQzDukG/jpa0w3ctN8oQ6BmSr2GFLvtm/r 68Ybg8kKNBgRg== From: Mark Brown Date: Thu, 01 Aug 2024 13:06:36 +0100 Subject: [PATCH v10 09/40] arm64/gcs: Provide basic EL2 setup to allow GCS usage at EL0 and EL1 MIME-Version: 1.0 Message-Id: <20240801-arm64-gcs-v10-9-699e2bd2190b@kernel.org> References: <20240801-arm64-gcs-v10-0-699e2bd2190b@kernel.org> In-Reply-To: <20240801-arm64-gcs-v10-0-699e2bd2190b@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 , Shuah Khan , "Rick P. Edgecombe" , Deepak Gupta , Ard Biesheuvel , Szabolcs Nagy , Kees Cook Cc: "H.J. Lu" , Paul Walmsley , Palmer Dabbelt , Albert Ou , Florian Weimer , Christian Brauner , Thiago Jung Bauermann , Ross Burton , 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.15-dev-37811 X-Developer-Signature: v=1; a=openpgp-sha256; l=2228; i=broonie@kernel.org; h=from:subject:message-id; bh=n96ljJnJVMpYM9CVsfMUORPIasrMIuo5nt8SCuY5I/I=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBmq4YMcSNTIJcJ2iVFyb/E14kVTlvrio58Ua+gwj4/ lAQflIiJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZquGDAAKCRAk1otyXVSH0DvuB/ oDx/VdoNOsQl5QDmrDks6jRvVft2wlWPJjs7YotfALeKJpT6PRTjX/fHk0yQ3nT1TbsgavUVMh5ugk azWaDppWDeoeJyRUeR8AwqHPaLkF75qzW8tRm1tYmbjlUvU9Cs9kNG23dqrPxY48VY9JN/FknkR15Z vIT8K7Tidey9v247fvxyj4rfKz1arkjoyGZLJVMyWb6u9BHi66D9qeos14lTWlCqrtqjX8EJYBKS7r 3I0t3sTBFUAUPotD1oVJPOQb4oPqtBVJy9PMQP1Yq1fWgtYabT5l5VrcJQzcK+M8dNstOCEIZLt/rL V6ygoYoUMW539BYpF1RQrxycLsV1z0 X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Rspamd-Queue-Id: 69C6012002F X-Stat-Signature: 7k584ax61iho7ekqfgsp5w6ktaguqua8 X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1722517105-86123 X-HE-Meta: U2FsdGVkX19J1tj3gmOLpmSibzjhHgqSLM/vB59qJFFfKZGjLTN1jHJrIBCPmCzEm9LVCUIugwVYVxrmI1knjUiEYgPEqRTh6d/kIoy3FY0MNF/7SAQU3XsuxMd4lQ0t9EOCN6soikTmXkLEtiJX03tPAFaEQG4J0V2sZjJXfgi5eCoFSsAs10W4bqrCiLDwDTTtTzaOgoRS+XzvnWha1BAfY1mIVqZUaqmF1owpbbOB+vWRPg6b1MDWNGDj0kYZaeJ4od+Zr28zYtSt1hQPkdA4w3D8iXohMDYBl2yDD7tvRur/wFzQcWeox6gw2aoyEc1SJPTuP4xybvXcKUxCDbAGfBCylYSzCnL0Y82qQ7L8MscbKhpqIpCzZIKKvxcfazFIKuHTb61e46HMrqvdpt8rZUHjRk3GcbDjDo+PWM2IAeHsYgmjkAxj6VwMbe4FMz8jrdx+jnFsj7vchO4xw5mxtJUBwRZyAk5G9nSae4CS5Er/ZsQ+84ExVjszqAtYqdNtsRgSKHpc4gLNypdK7GP0K6Ou/pR9mVDDeD8ovnpKYgTWGkJ5JX8RhPuhJtxpKSXEzfKhF+xY/CkNClqbcrKBLSLJgtrbBiy4K2E6+p9TRiWPVgPX3Z3xBE0Na9H6OoE5m9oDIxXYGzmIaehUlMsbt7OTCXrjXmqtr/ERf+0LmeW0yqav/C8OZair65I/dJt6fH8e0tKtnnlynE3Okk5tjAnsP52Y0UGO903fhbC+8hHHaLPBqn1LeLQx9vzXPYXshoOP46lxHUB+vmKhW4qDOyLB6Nc/81MwYD8j2cvIFsy790b5WKiwlhy6cCVG3AD7H9CukSgdr1XIyNRnHVMTbI3FmxJM9SauA3A7Ad6KHgWGE9Lx2sn0jFRyPT1ubyL7tNeOMZIiTY6k9/QwusMgg6/EGJqBTbcPWYKQi94aQPYsQ83P6VsjZdG2gEQaxmOnrb7+s+VwAwIWquL 2EQEr0j4 QnNBOBs06ODiLuzUaZtteE16CHLD9YgQQh7LAedjDL/w48H08g66lgJr6+hftBobGfmDydeVNQSfdaioe5V0tvzzt33Z+MxKPi1Q8lAg4xs6x+urXqBh/bMwRDcD6TrtRqgTD+g9I7xvoV0AvjCEOhiC6EJfWP7QeW3RGWKyT7CLKHThpN5ufoUsMfGhqFXpPxsNvc+E1BHhD4w16/C7OXGX2MVdLvdlaM6MUYa2Zwmoy2kQkhnII6/UtkztghzNl5WMblKgWieoeceN6FRn0r8XQfv0WdNUe7IB4BnxWSVJowmCyNeVvTbUf0c97Vw3227Ev 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: List-Subscribe: List-Unsubscribe: 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. We also initialise GCSCR_EL1 and GCSCRE0_EL1 to ensure that we can execute function call instructions without faulting regardless of the state when the kernel is started. Signed-off-by: Mark Brown Reviewed-by: Catalin Marinas --- arch/arm64/include/asm/el2_setup.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/arch/arm64/include/asm/el2_setup.h b/arch/arm64/include/asm/el2_setup.h index fd87c4b8f984..09211aebcf03 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 @@ -191,6 +199,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 @@ -204,6 +221,17 @@ .Lskip_fgt_\@: .endm +.macro __init_el2_gcs + mrs_s x1, SYS_ID_AA64PFR1_EL1 + ubfx x1, x1, #ID_AA64PFR1_EL1_GCS_SHIFT, #4 + cbz x1, .Lskip_gcs_\@ + + /* Ensure GCS is not enabled when we start trying to do BLs */ + msr_s SYS_GCSCR_EL1, xzr + msr_s SYS_GCSCRE0_EL1, xzr +.Lskip_gcs_\@: +.endm + .macro __init_el2_nvhe_prepare_eret mov x0, #INIT_PSTATE_EL1 msr spsr_el2, x0 @@ -229,6 +257,7 @@ __init_el2_nvhe_idregs __init_el2_cptr __init_el2_fgt + __init_el2_gcs .endm #ifndef __KVM_NVHE_HYPERVISOR__