From patchwork Mon Oct 9 12:08:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13413511 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 BBDC4E95A97 for ; Mon, 9 Oct 2023 12:11:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5D7266B0106; Mon, 9 Oct 2023 08:11:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 587026B010A; Mon, 9 Oct 2023 08:11:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 44ED56B010B; Mon, 9 Oct 2023 08:11:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 35C746B0106 for ; Mon, 9 Oct 2023 08:11:52 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id F17F41CA703 for ; Mon, 9 Oct 2023 12:11:51 +0000 (UTC) X-FDA: 81325809222.27.2DAFE3E Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf27.hostedemail.com (Postfix) with ESMTP id 821234002B for ; Mon, 9 Oct 2023 12:11:49 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="rP9e/pVE"; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf27.hostedemail.com: domain of broonie@kernel.org designates 145.40.73.55 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=1696853510; 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=/Zs1p4gXcfRJjLPLe6OvvtG5B7qTRT6IlsWnjCwxGRY=; b=TKL96iHxzAAaeUd7SxK9w7vU97TTttSKkAbi02jSVpoicRWLwIX+BTqhRlx78EWvM3CLZE 938+eRxO+YAV3QzNkmqQST8DNMSjXeXnxvl37ePERyRSCTT65OtqItacat3zXGSHASGvRt i4z1zPbEwPwfbERQX676hzuYWFhGv/4= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="rP9e/pVE"; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf27.hostedemail.com: domain of broonie@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=broonie@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1696853510; a=rsa-sha256; cv=none; b=BMJMmWjzBOSdfANpCUe0zCh7kk80yXh3cQVkjGReGnMDpnm48Flg2PFgeln9m+Gdh49SOs YQ+cU3NUt9oA8gvyq1FtJdHm9L1mlTScAADhHqut+OBciIs397ZDQj5AcmmJ4ecxQIX6+M oc5CZQzWm6Vz7BQm5WXX28mtj04ELNY= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id BB587CE138A; Mon, 9 Oct 2023 12:11:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9380BC433C8; Mon, 9 Oct 2023 12:11:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1696853505; bh=XR/JPTU4enAJ4pcvH8p8vc1g83S1au3eNbsnIb4ywnQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=rP9e/pVEU1XRIjj2Q9uCE+vVJQiSYLoJDDmvoN3Y+fxV4PDyb0Vs8fWv5dE22EdGz B0vb94hqvciW/TEsRbokha5ZqcprcqYd4Usrcmcr+y93H4dv3DKJAP5z76Exn3fa8W QPI2YjyCvmt6N7kiuo4tZXT3emLIL5NPZKALokimQSPX+EFbD6N5Q642tmTnWEAJKJ 7VgVCJPy4ZM09WcaxWoJv7Zi7JTkaps2cE7IhSdwgsbyuLYN5uaWHbaRut0htOs6RP au6TpCRBbjfRQmVcgQG5R8QCGK7+4xIbwmdWHVFFsdzFe+q++lxMpBhENWv+eDo/c+ wD58DJP+NWIbg== From: Mark Brown Date: Mon, 09 Oct 2023 13:08:44 +0100 Subject: [PATCH v6 10/38] arm64/cpufeature: Runtime detection of Guarded Control Stack (GCS) MIME-Version: 1.0 Message-Id: <20231009-arm64-gcs-v6-10-78e55deaa4dd@kernel.org> References: <20231009-arm64-gcs-v6-0-78e55deaa4dd@kernel.org> In-Reply-To: <20231009-arm64-gcs-v6-0-78e55deaa4dd@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 , 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=2903; i=broonie@kernel.org; h=from:subject:message-id; bh=XR/JPTU4enAJ4pcvH8p8vc1g83S1au3eNbsnIb4ywnQ=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBlI+2ZAGHqvxhmUj+PJXN+2VsAYfmovxTrEoIYjBrX 2bzDiHWJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZSPtmQAKCRAk1otyXVSH0LouB/ 4jMbLZC7D6Zl9Jb2+lm+LeAvBZcAupYd70rbx+3xkuxxpcymaCTO3zxHXISjX1SuQqDXdZ2Qr7PfGU AD2rdudrC2wAVWtVlIuvD1s8iyD5b5nIqoiQrsYKu1s6UByhZnLIrwDq8BXPLFUNVBkwd0pMBv4DVJ OSnLTLI6pOfw2BRvIdml05y4Axyxu65IveS3S9NiO7r8GE9M/+Yjsv2UB9TfMCca2oJdKaITbH+0ht xPC1Vr58uRUI6DwnycYpnuE4Hl+w2AI0CrMHY3eiChkjo0rYQHBWfhw4qqpUKruKnfZ739/1FkLGqb XWMGY3i9fPM/PuQFxByz8YwPzG371T X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 821234002B X-Stat-Signature: b6ixp4syoy3soghxqzd7pbdkpigs3jzg X-Rspam-User: X-HE-Tag: 1696853509-450081 X-HE-Meta: U2FsdGVkX181YnZuPWxl4gF5fwNFxR3kIXsg5/o3ca9kp07LUwJTaEDP86TNpIGlI2IV8FsP8Bi29tSJlkvqayeKtAivKDaK9pPCBjPqaVUY8rlGWhvorcU2zctc0Jecx5JBAOFxaMGRrPbFr77SAjze4qzzlk37XJZFe5GMgJKG76QS5pPAvndC9RTDTwjL0devrvCxKQbYVVNuOWRUlUv+v70LAnQsSUacw2W9p35oifTah/mJyemt/MpQCfbijkiGt/z2HxNeVRTyUlgu7EYU11sIi6PhAFgzXdd6rSGkRC0E627YqT/ZEhG9DRGDhbJhc2CTi5GdOewRrtdhdT7BFhTOymsov/+F2DJdxTEmmsBsxI+TdpjY6tZEiqPdPfsaS+n0RpXvn7Ib+l/cDdGrVfpx9X/38dmQn1dWy/5UwPc+Gxa0iw2IHpMJMFofj+qVxyQUhMXTAvxX8hEV/8Lx4Nb3Vhot3DQT6dnf30km2RlxKjDw5GMi3FoOa8BUFlXtVjup3A/MGQJh8/0e1U8tGp4CZADzg/aq0KmhHM6stc9cKaRgH5PP69diSHsfk3tiylfebgFA2+g4NNsXwDncf7nIsJb8vWXzpfiqy7naF98WbdQaezBBKJQ11VMJUqy220vuYIZJQZmF6KEep31TnTKd3FAuZJs7dY6j84viPmktm/LRaxX1OetXRjVnzgCewoRj/AITCrbf/PuQsRBxxTuVqWjKNI8/JxL5zCF9feRXQ/sk1tqC6WMOkQoRm+ay8CTrtxEaIp8c2PCtZFMVnOy3H6NtADSX0vs7K+mJpqaULosvsjjB+xU+JU8Y0dKgg4DL1M8ocKvQ+lDw8ykg3AZFBbgE8qUmJGo21qmEuL54I23aBg+vd6srk6mWBIk7jolUb48bLD22N1XjZFweGD9jCIs0r8sSqvi8ifI4CJuzPTiTstU6Hg/QsnrH03/y4LSQyPdl09OJpmE 9m9u4aMH euYtWCIyN0lqkvlROj1b10rtN7Fg2KMu7hPQtcChBV1860AsJcNDFDpUId9mYZlVtVmk6myAUQt5z2ZWFFW1I0XxNBlwjGjHAHY6BygMKmn8Mo3KhDyu1/DS5tI2Yd0MmZArtPfkVFLV7wcqJ+2B8HlXGrO3dDD6cLP/Dh/yVXv3tvxNngKRobtu7r9GYx52YWbQK6R+yucu3D+mEw2gcueH24yTUdMDgh32dloJWBf99/iHDogUK3sBmmRcyH3kdAdx2YTXvFAM+VWjnUXlRRx7j3Fl1BujJt2dnpnhxzFh2E/dOJUjo5X800ZZSrWbVr8G2UfMJYX3rUBw= 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 5bba39376055..4a5eea41f8ed 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 444a73c2e638..e247dce1759c 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), @@ -2220,6 +2222,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) @@ -2719,6 +2727,14 @@ static const struct arm64_cpu_capabilities arm64_features[] = { .matches = has_cpuid_feature, ARM64_CPUID_FIELDS(ID_AA64MMFR2_EL1, EVT, IMP) }, + { + .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 c3f06fdef609..9b470b311f29 100644 --- a/arch/arm64/tools/cpucaps +++ b/arch/arm64/tools/cpucaps @@ -27,6 +27,7 @@ HAS_ECV_CNTPOFF HAS_EPAN HAS_EVT HAS_FGT +HAS_GCS HAS_GENERIC_AUTH HAS_GENERIC_AUTH_ARCH_QARMA3 HAS_GENERIC_AUTH_ARCH_QARMA5