From patchwork Wed Nov 22 09:42:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13464409 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 D52E7C61D9B for ; Wed, 22 Nov 2023 09:44:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6DAEB6B05A8; Wed, 22 Nov 2023 04:44:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 688F76B05A9; Wed, 22 Nov 2023 04:44:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 503246B05AA; Wed, 22 Nov 2023 04:44:50 -0500 (EST) 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 417336B05A8 for ; Wed, 22 Nov 2023 04:44:50 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 2194F8014D for ; Wed, 22 Nov 2023 09:44:50 +0000 (UTC) X-FDA: 81485105940.18.AFA9F35 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf03.hostedemail.com (Postfix) with ESMTP id 2465C2001C for ; Wed, 22 Nov 2023 09:44:47 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=SyPO5tjn; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf03.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=1700646288; 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=u9Kh223n1sw2bA4JKVyqpsNW0iXZWBnYpCmPJVjaA/w=; b=mehDeRdZ1vO05jrs2VzZu932SPGptUJPqotdZfTg3I6XRjb045/xoIdh9i8k85U2oTmTu7 BvZMVgdi1q6wKOdwTxsNKVrCqASgpIC19RmPfJK0pn0LUbzlIo765LW5NLrXfJkgnfqt6u lIEhUg9MDQV0hGccdTU18XwY/l5ihes= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=SyPO5tjn; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf03.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=1700646288; a=rsa-sha256; cv=none; b=XEYXSsFkIucAIIzx6ghsoTJj14liBgfJLEEgvDkH/wGVhXtVz/c1o2x/E0N3EKhLXqNywe vzeDLnfpJF5KSXCw+n2p6B0hvzH94/RUPU1ObEAUspZB+caeIskaurs+kq5qkbxj7yoWGW xBSj3mXP8/HvKPGpTuHor1C9X2/ghDY= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by ams.source.kernel.org (Postfix) with ESMTP id DED0CB81183; Wed, 22 Nov 2023 09:44:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 70B4AC433C7; Wed, 22 Nov 2023 09:44:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700646285; bh=eAZyVctWUIW822C6a4XspzvFhF8YmdJ2KmfW+KTTZkg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=SyPO5tjneJ1lWQ6vMvro8FogjGi2iuc2b+pcmTXuO8VKhRqYlvw00yJlvvbHsdh84 TjGzB+y7+/Y3Q920f0JAUO7oIDuDC/YZstqwF38A6ixh909kP+lzJHULCdJGX+fIzu q2JxSOEaKpH+uJ3EXxGW9/9dWeXbeAXUDeWofNO1W6RlsAf2V1MwnpzjgSB/ogU4X+ iQxSL+7QlIiwyGcC1yZ1M5CuYrxppxx40R+51v4wstppfqJqFFJl8enKcPtvvp49Ck 5eg7e8+cZV57vDaFzG3Pv8smXqbDeUH6q2VouWbCf5uw9sS0ZDl4rykCqfkbJEE4hX ADwfS0/JxHqSg== From: Mark Brown Date: Wed, 22 Nov 2023 09:42:25 +0000 Subject: [PATCH v7 15/39] arm64/gcs: Allow GCS usage at EL0 and EL1 MIME-Version: 1.0 Message-Id: <20231122-arm64-gcs-v7-15-201c483bd775@kernel.org> References: <20231122-arm64-gcs-v7-0-201c483bd775@kernel.org> In-Reply-To: <20231122-arm64-gcs-v7-0-201c483bd775@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 , Thiago Jung Bauermann , 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=2246; i=broonie@kernel.org; h=from:subject:message-id; bh=eAZyVctWUIW822C6a4XspzvFhF8YmdJ2KmfW+KTTZkg=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBlXc0CgBXsZyH7UmX+GJUnolHom10FZwrrBFtz2 fm0irI1LESJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZV3NAgAKCRAk1otyXVSH 0DSKB/0YQg4ct+cd7LzPnbzosVtkcpo9NOAazn/sUsJ2DtI354warKGrRY6PxciWlxzrMDgiIus HiJme7H4zGCw0IDbOmwwTfwCBkzLrvskL6mtcVElBOwwj0p22FxA2z06bnEyl+hOGCVOvm6HJGr S2L6/PMBzs/qmDYtEl04cqXyrEjy7B073aCQ39bj4OWb8e9pd1x45oG1v1BG9nEsklqU/iYgKZl +W/7rPeizJfM/yQ1ZEYuaJ73f8isMI/FMN+vA1i0JVuceYiVSaL7GypOFOYgDGwoP/Xmt6S2aUk PoVEJ298MhJe8H7+mrvEZOIqa4+3U3qcVTURWXFcrBZzuVbh X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 2465C2001C X-Stat-Signature: gsw9eb3beoraa15i3fny8s6g1twgfiao X-HE-Tag: 1700646287-608891 X-HE-Meta: U2FsdGVkX18DHc1igdN17+ERylzs1Fv6Wwz3f6uvZESR+QSeAqVPUHtqyHMC++CSazPhDKebwY9603uUOzezvXcQINoCj6rxDb8gQVQ1OTJeA+k711exrl1NElhfOxIqhuiJDEf5R9HIubGGEqDUdo91ucFgohfPFDALHOKE+xIGPq/fPzcSpJsPoe8eg87N0rAK0wPf1UezS34gVIhU7WjSpmr68VlYvpC8S+Z+JZ0HZNofWpdgqfJiRp/Bo6Y7wul6sEHbRbcGkoYdn8X5WozBG2dptz/gpe4+OKI7pMcU7SsCk/wsNgyw8QHudipoJ+3dh3yF5Tgz84xYrlEt49Y7S8NutyQfKsHsg8VXXO44iwtCR8Q0ZP2kmlPWWtOYLaBDvtfj+RmEMi/xMnCV0Gqcha4aJ4DE/IjyOGg9j7Aa18b3j9zE73NdU4F5FrtwlyRt6QKIidBp8IcncpIaxeZhSEV54EsljxJCQJOTQeLkqQpgFawOuAgYMZa2tMiiyYPbi9OOC1jlDZze0ucDbRY6wgwrHbS0rZirOQY62E9oQ8rwbxSk49e1ScKmhItjVzZp1uZnOg3mMd6vRFOdmlRE94YGk4bsVAp51ICJlqFexKf/zHaUQt4i35jIqfjMnFK1FpzUjUChxUDQnvQvnqE7UHvcU+/i7N4b9BRTFctOLnGJ1eqRJBqWQ0o1SrpotqcBQ3w7OiOTgUYn/2xBkRG82kQ++YW9dsOTrGTu9k505Adpxopj0Ous+8Ms5I8fnI0gXUQTyHxdTC4torIKvQrMXeaBleVDRHRvqAz+TD0DYjKrek9ovn18k+ac19YvTCmg0ZtnhDwFqUy9/FKm/GIfIzXwiVOv1Q++JJ1JSxA64jIUlLz7EU5MTCJe3otQMAJziRxQJBkCdBqDHF6zIUO41Zzfdi4YC66eq9VPgGAUxsEBEMtz2j/TNrxrk+LChUGFHnu5Pat6Dcy40NV L/JszYSC i7V8hpzRGnAx5PkWf0tbfdSTCCQg/dNJska505Eq2B1BW4kyx5ta51Zgo1CQG4oNjN32CTEj2mZpNsd4TKoWyZySROl3vFL2v7xVypekoGFu6TRCXVYd/aHIhEnrC0hyVPj+7GsN6ETml9kIKXAIEXSJs34jtmx9wZR5yipWo3/yGu9nv4dvchnFERUKHv5uqgDDxVD2yiSxAFMVICEAOrHysdE9cvIN31WgIUddR09vZEvohz5zIdGLLOhi1E5ouriA+XOyCqACC5bn4d1i5cLkAAGrs6MQ36QMKrmbVzoLmocPNU4MYvKS4WNmXhVk2BJV+ 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. 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 b85f46a73e21..e4b6a29879b7 100644 --- a/arch/arm64/include/asm/kvm_arm.h +++ b/arch/arm64/include/asm/kvm_arm.h @@ -103,9 +103,9 @@ #define HCR_HOST_VHE_FLAGS (HCR_RW | HCR_TGE | HCR_E2H) #define HCRX_GUEST_FLAGS \ - (HCRX_EL2_SMPME | HCRX_EL2_TCR2En | \ + (HCRX_EL2_SMPME | HCRX_EL2_TCR2En | HCRX_EL2_GCSEn |\ (cpus_have_final_cap(ARM64_HAS_MOPS) ? (HCRX_EL2_MSCEn | HCRX_EL2_MCE2) : 0)) -#define HCRX_HOST_FLAGS (HCRX_EL2_MSCEn | HCRX_EL2_TCR2En) +#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))