From patchwork Tue Aug 22 13:56:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13360864 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 BD57AEE49A4 for ; Tue, 22 Aug 2023 14:04:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4515128001D; Tue, 22 Aug 2023 10:04:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 401A628001C; Tue, 22 Aug 2023 10:04:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2C98528001D; Tue, 22 Aug 2023 10:04:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 1ADDE28001C for ; Tue, 22 Aug 2023 10:04:38 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id E757EA02EA for ; Tue, 22 Aug 2023 14:04:37 +0000 (UTC) X-FDA: 81151910994.22.5C8B671 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf27.hostedemail.com (Postfix) with ESMTP id DF8AB40024 for ; Tue, 22 Aug 2023 14:04:30 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=sZSW4rjL; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf27.hostedemail.com: domain of broonie@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=broonie@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692713071; a=rsa-sha256; cv=none; b=v/4jCNKf1d77O7U3S0HBdOlzyEmx31OpSqoaujGpF6WAikRfGDV9zbhoYzQwlKvPqEUCAz HqOvvPp2HmJNvhXVKvEu56gW3g6D5E0yvmRDgzQ3RwWP9KsX0K/JdOipKp2gkPZ4F4HBV9 rTe949PQChTTYtpKzAA92Fq7ERKU5Ho= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=sZSW4rjL; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf27.hostedemail.com: domain of broonie@kernel.org designates 139.178.84.217 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=1692713071; 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=JSP77B+Y3YCkRF/5Q7wWTE+uCUtdfLprljgasao2aNM=; b=mkceapua1kQtejrHNjYR+l+a3BxHvS8Tzvgn02gcCS68v+Gwi4/+34rdVa2ptYOeV4RE8/ NtYCsPhVxS1eNM1hZDfdX2Hs3/PrkFI496xgeT8+40xi90ommZrPhMlhsSLjPKVuUi5HAB x4joRTuDmF4+1idJTHrAffhSYbyib9o= Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2874E65772; Tue, 22 Aug 2023 14:04:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 306B5C433D9; Tue, 22 Aug 2023 14:04:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1692713070; bh=pwwrxxHNbxebLhKstTJRuW9z+xYEVATpqSssYbiri7Q=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=sZSW4rjLwA2JoLMroRes84FP1Uggqm+n2XFnpLQH8Lx537J0vlc618fxkrax1fkz7 AWsM1yQto+us5qp2bAedK58gaLODH2fu3tWb7DiuWxapBx7yunNfarCkaWa1Y25fFp +WHGtMZJTBpVb3ennN7P+jTEODW1i+t91zsYyUHuiJ7VIOvlLnw2tPh/QqcQdt06Fz hPFotVr1cWeqHca05NZ7FL5Is3r5pK0k4qdAfcj7uvyciiYJCB/xZf3ip18Xgtw+II 2fjEbSXQZ94YHjN7TytzzUkY0OtFr0JnJCC8KmwSE80JqzE8AtIUtrS73ecDNdUabI s0PgwuPYPTIgA== From: Mark Brown Date: Tue, 22 Aug 2023 14:56:47 +0100 Subject: [PATCH v5 14/37] arm64/gcs: Allow GCS usage at EL0 and EL1 MIME-Version: 1.0 Message-Id: <20230822-arm64-gcs-v5-14-9ef181dd6324@kernel.org> References: <20230822-arm64-gcs-v5-0-9ef181dd6324@kernel.org> In-Reply-To: <20230822-arm64-gcs-v5-0-9ef181dd6324@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 , 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-034f2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2248; i=broonie@kernel.org; h=from:subject:message-id; bh=pwwrxxHNbxebLhKstTJRuW9z+xYEVATpqSssYbiri7Q=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBk5L/6XoElEHPflOWlW0T2wIqNYHftOygW9afb6Crt iX4GfuSJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZOS/+gAKCRAk1otyXVSH0PMIB/ 41ZVjw0mVWxPVAnn8MNtk1Y7a35QupccsA49y/cDOD8wVMKyE+K3HwonGB6/IbPZB3CcdyJ252zu0c XmQWPKdy4ndP8gyFD2sHwRpNy55Y/JIUywl9PSARR4cT+hLmJD0dROQ31kAx5hcVwk3uuy64dAOxC6 BFEzL9grYY3AsuLucp0RYjNE4CFDrnCw4GvERGfn8vLVzuour6PIKxivLiUyB6NtQ5jcG0boPr03g9 b+GN9sCzo16q1iwl8V5x7LfZ/N2IE+aRTWQhxGcUC5y7OEtu31baibbvCLkGa0HOMHy1piWAzYsUSt 1pC12LY/XtP9XuCikXRimPTPnTd/RH X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: DF8AB40024 X-Stat-Signature: axxhe1w8dtreunif167jg3o37kxs319d X-HE-Tag: 1692713070-359976 X-HE-Meta: U2FsdGVkX1/nsgFBHuNr1fhCHspUHwkSNG1wE5SOMsa3iEGC3obyIAkJ3ZxXq94aQt/g6rkCsgQYKKJXnktpr3riLJbKop4bZGSNTfbD2ScpsMDcMEDaTA4wuY6yxxdHUtw/LZ6BpjIPPcvFrhp9T5P2fJ1qO3O12J+Rfu4ir4jwrfyishcbfXaixvLj2uwaTFT2JbDvMc7IidE6EWWQM0CK8sBuhYR1e+nvjcPxzePezbyuW2iZeQvAbq8n6u/64JqGCNgphmO31QHYjKIJyoFLhFy6MBNPm0B1rGhKJf6/bjqk3zAyLghxZXp5Sfr9baCzXxyouWckABtriNLrmnhixiYWeqZJstnPCv35MCz5lq2zktJQjjPnC+zcgVOE1cQXk87wfjUHX0WgeeQC542E9YneUhl7+KCbbnliQfNqKFSsZRUe6e4garajVt8eeaZqIbjMqZjdnfzFKj9FG6KBtfia6WZclaRVxs/KWDfn5dioljreAe3j0oy5f8+Z/ijkyHp2Vx1woQrdjU023J5o6ZIvcEbdch4r/fmtnxXPkBTvUyIZtVOjhST2EKG0FbrKpZ1B3Xk3jF1GLo6jkXAnT+Xs9qGxSEY81LB21GKRpLLKPi81ZfQ7vx1b32AQLeqyF7KgtzRymll+DOMBYinltWCYq0nqidL9XKOpl61PQqnXeUb+NJVfROQ2EdolFwg1QwKd8BhI0StSGytSZV8+q6KpOWpyf5OIfW9U5g5xWdMZnM1bPJMNj3rHouBCX63L2id103plgkQt0ps8xlrQQ9Ngzbza4QMC+CEFFiuto+MOZhvI77ajhwgJhOTHSRvgezwzC6zxE5UJ+BMiJukAm358Cm/oYoO308Iuml5uopjsRA3sOLw4/JBptv9C4Hz7BUXJij+YwCQcpfGa5EVI5xcioniMEuaGhvKFWTA0rvjJ+hZr15go1vuyIaqtU1Sxh+qgROD/gykiUrP B9wxUBuo rstuCOnt9f7E+/J1kTg1boCxd5srxJG232innri0iTiN+GRnU3uw6wsY7v7K2WEsakC2EaG0e8w4o7JXosKw+oTzObrJXw4Qz4wolvk5MPZS1rOaisOGPAposz8IZi1OHkw1L359bxZhTdHCiZ4iu/6ZofYy/BeZd7IkP6sIx/wA4HRGezgV4w2NDMbffnfOaxG8ExIAEEhrdYoxBkR+I5370iMN4rKRrRf2zK5pinJaoNuC2bsN6MrncfiwzhoWozUigSUNEQotpXGir9Ri3VtAeu6ZXFsIYZb52DwXOi7Z7UKcarHXGf1aMfzLKtjiBBVdlHCXzVLt1Is6YLUQPo2C9a7nO8yFXdibq0i3o48O4JzirbNylKcRJIym9WQyup7lGqEL21eGWu99EzdR2UHJj3LvmaNshbXHEC6AFf3HqPvI= 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 58e5eb27da68..9c84e200217b 100644 --- a/arch/arm64/include/asm/kvm_arm.h +++ b/arch/arm64/include/asm/kvm_arm.h @@ -94,8 +94,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))