From patchwork Tue Aug 22 13:56:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13360859 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 E79D0EE49A3 for ; Tue, 22 Aug 2023 14:04:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7FAC2280018; Tue, 22 Aug 2023 10:04:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7AAA3900011; Tue, 22 Aug 2023 10:04:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 624A0280018; Tue, 22 Aug 2023 10:04:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 5408B900011 for ; Tue, 22 Aug 2023 10:04:02 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 30FDB1C9118 for ; Tue, 22 Aug 2023 14:04:02 +0000 (UTC) X-FDA: 81151909524.27.F3E723A Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf13.hostedemail.com (Postfix) with ESMTP id 50AD620036 for ; Tue, 22 Aug 2023 14:04:00 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Gm44lb1O; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf13.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=1692713040; 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=UsQ4evMiiAYwQjdayZkqlkQ8Zju2zsq0zDtbSV9Oikk=; b=r9sadc+OIj6XtFt/uEE1Kog6P3ARhk7L+PbV/CjmNQeoyW9Rl3hUmdBU2s8KnsQMroyi67 l5CPHN4/Eb93YZfY7V9hVelvQwa1dVUACbA30pQKHOf2gBfxah6RgIwfOLepoTUiPR9iXF mnh5R2Of9AA5/E6VKqxJam6BhOXssLU= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Gm44lb1O; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf13.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=1692713040; a=rsa-sha256; cv=none; b=2kp44zAbmOab3zf/OoaDdSCcJiFz6pKrK5o46ferrX6yz6evQiu7d5i+lSkE8APV35gAnA r54pU3Mv1NEq9iSnS8uyyyb7CXgYFwhVNXDXxB2EEIa4PGxZCDpjxF+qDMGdrLqq3uNgpp IXZ+RjgTKdSbwgml8OpvYHO9PrE0tBM= 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 88CC36576D; Tue, 22 Aug 2023 14:03:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0C4C8C433B9; Tue, 22 Aug 2023 14:03:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1692713038; bh=teb0sKS9busqSVOZxV9N3xrEhZqf3CdoVbQJObdkbLU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Gm44lb1OIiur2ErWSm0bJWXftj+KzNuOgrIjuWkrniWEX/6m+60GL7eqSnE4XGJAo JqXsH61UMv7SajkmLtSB4Y+x9tRilyC4aTYriNQgj8I0NQIVKs9fscnbvIpdfA18t/ EC+zcW2SBzjW+tSjJJW9XPTh0cMThUWSFZDlHUinNMxA2AJn588xBIOgYZ8elIHmvN P1ltTRWjqjOh1pL3u68268I/khyQFbO4R7/S0GuVxD7XC2gypvVr3gEivsJwyV0TFU P/yNAmL6eQPf5WBEkpM3hWs/aiKdBgwKmrqeczrV6NpPCzVeUSDnoJcCi5TIc+9QS4 2CdYlI8QSh2/A== From: Mark Brown Date: Tue, 22 Aug 2023 14:56:42 +0100 Subject: [PATCH v5 09/37] arm64/cpufeature: Runtime detection of Guarded Control Stack (GCS) MIME-Version: 1.0 Message-Id: <20230822-arm64-gcs-v5-9-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=2901; i=broonie@kernel.org; h=from:subject:message-id; bh=teb0sKS9busqSVOZxV9N3xrEhZqf3CdoVbQJObdkbLU=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBk5L/2LCMqbwDztxrqMpNwVXemFsoZYDDfoYP8KPfw j1oK57uJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZOS/9gAKCRAk1otyXVSH0GWvB/ 97UAxRcmCfkVB6b8kBDSVXzdSs7X1Ik3oWgpf9EGshuT+8TCkb6EiKl9hjiuf+W+fXtYkA2OYrsRPT ZWC09bkTGoij/X2pZLkd8ksm+WApc4UT+SAR95XeHJws+fJe2HwPRYejAsy3vRFFwIUEDjM9MzElW2 LrrXxzE1/go+aHg+hwt2/S3GbeQngIRE5XOL7vHphrwmI0BQd1lsFb4HvQdgC253beL3z4qhyOZA9i 3IeHu9HfcfPjoRxh1cLH2pwH6Aw6fas30sooXE5IGZAcilEzyCprLMsxO0SD5pkjruLDlaBOljHFA8 CqeP5G7FFD0cP7A4fuIryfjdyNouTv X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Rspamd-Queue-Id: 50AD620036 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 3etoc57dyarnbu3q4gdrxwzs5o885cyo X-HE-Tag: 1692713040-253072 X-HE-Meta: U2FsdGVkX19QJDgHyAlgyK/jbamXT+YcYVmsuxGhCaIZWe1YvgpaHzXSTmNNNHLmrMec7QANnAz+Ku3yj5Cl08BoLAaLugjXqjhj2o41gjKOiWl8KysaG9hpPWeoOKWWnCfg3L06aGmjJnVTjuMC98rfPuMpBZY4A3P8VrCkUl13/J/+535RUWxpFe27Pweh56F83K3EHm2ouT+Jw0fcL2svoF2V2UREXLovEBSz2ZQcjPbirk287ONndpVJWIUNmqEsMaQHGa06DBbF0/NgSY60eJsvDEziSCxNrfPeI3f6E+UztGHaOOodht1W//sfzMVB3WH690OzisDZGqzvivyAlmzr/ceiE2NAad6jYXxvox9+hp0EcY1VYxqlYNd+CSWC3nXnCzLsFrs0x3VClJoNL2WqDMIznD+GsOHaFy+iBMvlmRtq2BGnkdHs0UHaLAX7ujcojUND5run4WjsZnbsk24Xok4hkRJUKrtEIUAjsMg7Tcpsf+w5AyASlVkwG1mWqQh4IlzyPW7Q4K8c/v843XLutSCclYPCDq24lJbVPQyqfK+78cIGR81tRgOvmI0N+VaEfKNy1azdKRzhIWk+/2W16ew77cK/woAgN9M9dP1lfUVZ1aM2vr/Ave9Q1xHl97wFGckUD0qlKWAkW6gmpiv810Kfr1QgwXCPz3j2PFhEZg8Rl0/7TJ7v28OZt5ytvNzNYh/968tassBmc2fE3FzR7JaQsY73isyoKVCVM9O+GFgS3esft7gNhT3tnNTzDga+EuS08UELcsHzLYsYVO0E4GmRg8rzMOP6PTImMGd5Ik+KYmeD0xjgLCh/rYKypPlQOgmlwcOrZS+ebW/NaeA6HLH/jIP+H/pVuyhFM9RGF2w3j7ZWNBjS53FgQOcVAnC4BZnTSifddzyOMwysEwxfQItxbEOGeq8E/CPfWgR7OgkvB9Sv3qThEq5E3KXBlMsZRW8qu34VlnH +eiJuk+B leiW4YFRXWB3o4RGeXbcLqaQ50djrkfPHxQN1ouCeh26xHcGOSenAz96y0CFY4+vBaPvyam/TsKVGZ+xn+s0dPyVhLsw53bdWIf+19+CRq0vWRJJmDjAI9u4dwG8YkjnyC6GAXjUjMqktdWrbAHDuAOh+kCfjnF4H2sTO8dhr70xPca0f+m3NlM95LvkXbUoZBfThhdqdhICVXCb0QrRjiSob3+8bMtQ4mDWQWqc7fH41JOKqznBxprlCv2evOKxhF1VQv+dO+tH5jTkACdGFrmhOTm8QSTJr87ibYZZeT+QMnmDsRd8dphKetHjhFpARI5sqpYQx9nsBM86kuLf9Re6TyyUvmrxCwZZmd727i+VomQwjUrN32mUPTeeCVit+pfE94g6Ij8A86XOgISdixn2IKJdABybKt3IHdyylnjPsw0g= 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: 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 96e50227f940..189783142a96 100644 --- a/arch/arm64/include/asm/cpufeature.h +++ b/arch/arm64/include/asm/cpufeature.h @@ -831,6 +831,12 @@ static inline bool system_supports_tlb_range(void) cpus_have_const_cap(ARM64_HAS_TLB_RANGE); } +static inline bool system_supports_gcs(void) +{ + return IS_ENABLED(CONFIG_ARM64_GCS) && + cpus_have_const_cap(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 f9d456fe132d..91a14a6ccb04 100644 --- a/arch/arm64/kernel/cpufeature.c +++ b/arch/arm64/kernel/cpufeature.c @@ -254,6 +254,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), @@ -2219,6 +2221,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) @@ -2715,6 +2723,14 @@ static const struct arm64_cpu_capabilities arm64_features[] = { .min_field_value = ID_AA64MMFR2_EL1_EVT_IMP, .matches = has_cpuid_feature, }, + { + .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 c80ed4f3cbce..ab582f592131 100644 --- a/arch/arm64/tools/cpucaps +++ b/arch/arm64/tools/cpucaps @@ -26,6 +26,7 @@ HAS_ECV HAS_ECV_CNTPOFF HAS_EPAN HAS_EVT +HAS_GCS HAS_GENERIC_AUTH HAS_GENERIC_AUTH_ARCH_QARMA3 HAS_GENERIC_AUTH_ARCH_QARMA5