From patchwork Sat Feb 3 12:25:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13544134 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 CEB67C4828F for ; Sat, 3 Feb 2024 12:30:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 34C986B008A; Sat, 3 Feb 2024 07:30:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2D6256B008C; Sat, 3 Feb 2024 07:30:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 176DC6B0092; Sat, 3 Feb 2024 07:30:34 -0500 (EST) 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 021496B008A for ; Sat, 3 Feb 2024 07:30:34 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 90458A0916 for ; Sat, 3 Feb 2024 12:30:33 +0000 (UTC) X-FDA: 81750425946.10.1215B99 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf06.hostedemail.com (Postfix) with ESMTP id B927A180021 for ; Sat, 3 Feb 2024 12:30:31 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Jf0yWUkh; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf06.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=1706963431; 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=3RPtjoVUURCD2FEDdjcqddw/q4iV+gF/xoRfO7VfOV4=; b=QkHm0Hilvg4hCVbBG7tUfofNi2Tk0yH7CPO/AECSmnbWByVT+k4J1k04WRzeOKbhTjxGYt B/Y7Q8Uiii/qV0qpffxOXEabnmW4lAWVjTOHTzbxTS8jDxvjxfPJ2coy+PB3D+fAIqI8sL 6gaLcVLYd94aCxmmO0tcm/8kQAis0Dw= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Jf0yWUkh; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf06.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=1706963431; a=rsa-sha256; cv=none; b=iulPoHhJtX9rQAG78DHAtYkL2BAsljQHDWerAWNA5Sr7WBXfKwakelQkY/u4qdaxu1ufox QjQclxqaOvtv0bRx0gAVq2CVz3tm01zfJLtNTA0a0o/qzS+d52mcQzRnnBUN7j71pGyvqg 215OtvVeiD4CS+FgjDHfMF818XT0mPc= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 0D8116069B; Sat, 3 Feb 2024 12:30:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 02E5AC43399; Sat, 3 Feb 2024 12:30:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706963430; bh=3WES2VkMACm1ygqHaT5urKF+J7gA2tcL8ARwsPvb13c=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Jf0yWUkhVM+JPbg1AC9kf4U5ONRAwYdHevZSinRnbGZ0+KN++7exp6ecg4cwGt7kx nh44Z0xzRzf+fZQGsC0TGJ5mk4I4iECUK+bu6JkEDp3mPmAyeMdzfongItAXfWwLmO 72ZB5ax5EmAuMn9vjkhjXLkdBJNEKJm5nvmsL5UOOozEj3iDNkziBBugg85Yd0OR7c 9WNrIf+8gbGKFg3x5EwZnGxzHwSV8MV2RnahJN3xt8zblAc7qTmQCkFXb04E08vrJ3 uliIc8MtMK9akxMTcHmzdSG/UPpFJvpUUci9cs/GPvmqSWDoRbsoOTVjo4jEZvLkFO JJBUPfhe4OHaQ== From: Mark Brown Date: Sat, 03 Feb 2024 12:25:35 +0000 Subject: [PATCH v8 09/38] arm64/cpufeature: Runtime detection of Guarded Control Stack (GCS) MIME-Version: 1.0 Message-Id: <20240203-arm64-gcs-v8-9-c9fec77673ef@kernel.org> References: <20240203-arm64-gcs-v8-0-c9fec77673ef@kernel.org> In-Reply-To: <20240203-arm64-gcs-v8-0-c9fec77673ef@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-a684c X-Developer-Signature: v=1; a=openpgp-sha256; l=2884; i=broonie@kernel.org; h=from:subject:message-id; bh=3WES2VkMACm1ygqHaT5urKF+J7gA2tcL8ARwsPvb13c=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBlvjDYgOeEFvKfL/KhibKOKVGUlvLRngYcrrqWdJ/C KPdQLjGJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZb4w2AAKCRAk1otyXVSH0DMjB/ 9Gjxj9HcxjjqdUkEH0zrL2GPEPBRWZ79lIIib6G577yXxcDoZZFwnRJKLTRLp15kUQpHY8s2Wyybkj OW3ZubuGxbYsa+d4rmUbWybg2GcBrDI7n2EA9/5WxwsF785F60BqdK5qVZIBCFK8z/ae3X6XbtCwfq LqI9vNIRF7hvoOhW5B7MCmez2Jg3vstbUwhkG/GvUujyFOb8qQUpMEOckUUq5lzlIlskAf70EgwusG zDcvFRvf/mQk7hvDk3m1E3hChIBJz7tjuBNeAS7DHAi4llL0fRzGwDwt4LzzGvn10dShS80qncZaGH LZLZWCZMaz4WDsHv2xgmJ7X12Km121 X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Rspamd-Queue-Id: B927A180021 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: dhm1mxcpwuwfc31yj9ht86azf1p9jysk X-HE-Tag: 1706963431-270683 X-HE-Meta: U2FsdGVkX19+wBplkNytxTzH+FGeCy0HQizTclc6E1sUCTCYTTzFq+Cxj5UNKQrHePtIWOw8lLmg2Mgo48XJ4g+cG327ZE4J9q95R+JujxjP6v1jtrUKCLsjQ1MwqUpFSEtI6aivSk3VBE2XLJhZUvDjSsnimO3OjA+9WMyCkgk5FhT0flI7tbyQ5s1BY7L18C3KzG6TQq/6/O6PDcatwDv4MI7xOR8ybxry6TaIOhtOo2XqQaaR8iLo2WiC7MkBeLhpbyDepF1NmDQNAU33vIeTucjDWL5UESUpkFk8XpIhfSeuuY2v3DcYBaCu7oKE0WIX+0mjsG31fMZWej+dz8SqQZvAuhMpz8HHSD2E1NCq0lMTqOeeWHR7bkwQ5CkVy/YM/I9itsNeF1rP786o9KFRiSH8YxoVgmik/xRY7wRRs7gwbpVZ1PE3x0Pmhm1IvkGfaonpMMpYRVyNMq2g1+uOONBHZ3WkWqsuJ2ld1xamG9TlwUwCnDX5yK4ze73nx2jWjV2JNYk64fHd7WfNgNaTfi0W9Jg8ZSme24N177yGKKc2btvE85Yxo29yeEu8q7NLYWDEVwlZaLxamU7xWO/hXEbPuosQmRTqQhgX3SsFHmfk8w/TciTZQxXVvjaPWSr9JGKFHMpfNn1gVr20RWqYnh645rG+oBQEdZ4mhayjr8fHN3PtvfpeFbYd32QDrsh+ClygyAZ5tl1uUL1NHx8jI2rpEsgmOlv/K3iNTgfonRh6ULnhjjYFbYfRKDLo2d5+rjYEeTA9uGtTJkcnuDKPL6lqHMocxRTpKK/McOOIqMMOQXzdFhOyCv9GW4fa+2nCnMSnf4g7Z66uBO+Hme/0beNWtTjTGh+Xq1GpkjhmYIxZXJHwfIdP6Qv5XunfU6r0S4pjtmVpTSd8LMHUHKNJxLEoZDppXL/UDtHkwh7vl1iDgq0rEGWHA1T/qRGP2jLHTn/O2F4z7b/9pNZ 9IbSLu7U a8Qx2MDuS+NDJ5QbRVy9JvEVM+Oh/Ag2kW95vb3NXwFBUHN380KeDugiXKGRKtkjfPi+MWa5S1HutERZYRDWrsGVM+LmJ4AYunTdUoDZAQoczN07xix9JU3xmbHHXtmM90zd28j/kjsZSH3RZTV6tgetddbHpx7x/6+eDPpnAQzoRBPNKYSLe15BNxE61BkDhKpBD5XZuJtCb/5O7wn/scbr0wbuqOP/85dwsrcNtGEj6odrHaobs/8yjQZNifyL2W/LSSfWko5+kWU84FtcUDYgHVJZN12NHuxMuUOnDFWDuOPeYYzeF0AAVUL/9bjIJkIk4 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: Add a cpufeature for GCS, allowing other code to conditionally support it at runtime. Signed-off-by: Mark Brown --- arch/arm64/include/asm/cpufeature.h | 6 ++++++ arch/arm64/kernel/cpufeature.c | 16 ++++++++++++++++ arch/arm64/tools/cpucaps | 1 + 3 files changed, 23 insertions(+) diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h index 21c824edf8ce..3f3a685fa6e2 100644 --- a/arch/arm64/include/asm/cpufeature.h +++ b/arch/arm64/include/asm/cpufeature.h @@ -825,6 +825,12 @@ static inline bool system_supports_lpa2(void) return cpus_have_final_cap(ARM64_HAS_LPA2); } +static inline bool system_supports_gcs(void) +{ + return IS_ENABLED(CONFIG_ARM64_GCS) && + alternative_has_cap_unlikely(ARM64_HAS_GCS); +} + int do_emulate_mrs(struct pt_regs *regs, u32 sys_reg, u32 rt); bool try_emulate_mrs(struct pt_regs *regs, u32 isn); diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c index 8d1a634a403e..b606842ab8c1 100644 --- a/arch/arm64/kernel/cpufeature.c +++ b/arch/arm64/kernel/cpufeature.c @@ -255,6 +255,8 @@ static const struct arm64_ftr_bits ftr_id_aa64pfr0[] = { }; static const struct arm64_ftr_bits ftr_id_aa64pfr1[] = { + ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_GCS), + FTR_STRICT, FTR_LOWER_SAFE, ID_AA64PFR1_EL1_GCS_SHIFT, 4, 0), ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_SME), FTR_STRICT, FTR_LOWER_SAFE, ID_AA64PFR1_EL1_SME_SHIFT, 4, 0), ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64PFR1_EL1_MPAM_frac_SHIFT, 4, 0), @@ -2250,6 +2252,12 @@ static void cpu_enable_mops(const struct arm64_cpu_capabilities *__unused) sysreg_clear_set(sctlr_el1, 0, SCTLR_EL1_MSCEn); } +static void cpu_enable_gcs(const struct arm64_cpu_capabilities *__unused) +{ + /* GCS is not currently used at EL1 */ + write_sysreg_s(0, SYS_GCSCR_EL1); +} + /* Internal helper functions to match cpu capability type */ static bool cpucap_late_cpu_optional(const struct arm64_cpu_capabilities *cap) @@ -2739,6 +2747,14 @@ static const struct arm64_cpu_capabilities arm64_features[] = { .type = ARM64_CPUCAP_SYSTEM_FEATURE, .matches = has_lpa2, }, + { + .desc = "Guarded Control Stack (GCS)", + .capability = ARM64_HAS_GCS, + .type = ARM64_CPUCAP_SYSTEM_FEATURE, + .cpu_enable = cpu_enable_gcs, + .matches = has_cpuid_feature, + ARM64_CPUID_FIELDS(ID_AA64PFR1_EL1, GCS, IMP) + }, {}, }; diff --git a/arch/arm64/tools/cpucaps b/arch/arm64/tools/cpucaps index b912b1409fc0..148734504295 100644 --- a/arch/arm64/tools/cpucaps +++ b/arch/arm64/tools/cpucaps @@ -28,6 +28,7 @@ HAS_EPAN HAS_EVT HAS_FGT HAS_FPSIMD +HAS_GCS HAS_GENERIC_AUTH HAS_GENERIC_AUTH_ARCH_QARMA3 HAS_GENERIC_AUTH_ARCH_QARMA5