From patchwork Mon Aug 7 22:00:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13345130 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 8C609C001DE for ; Mon, 7 Aug 2023 22:02:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 23DD26B007D; Mon, 7 Aug 2023 18:02:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1A3258D0003; Mon, 7 Aug 2023 18:02:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F34E78D0001; Mon, 7 Aug 2023 18:02:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id D3DAF6B007D for ; Mon, 7 Aug 2023 18:02:24 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id A3CA740C14 for ; Mon, 7 Aug 2023 22:02:24 +0000 (UTC) X-FDA: 81098683008.19.26610D9 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf23.hostedemail.com (Postfix) with ESMTP id 7226A140012 for ; Mon, 7 Aug 2023 22:02:22 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=LVzzDEWk; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf23.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=1691445742; 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=e+CI8Ir/J0Iv46TMxYtHK+0DKcfbBkTwQzJt2l+qOzETp0MiLWH5WDRyFQPZIVpq19PhNS JJd0g1UivC+N3E0WH+wafEnGp1y9MaVdWAmEtcFMNyowqjzBzoMn+I6UlBM+LVpUo1+9Ea IZBiaizL5LEoa/0WVVcrLfch0S9vwPg= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=LVzzDEWk; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf23.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=1691445742; a=rsa-sha256; cv=none; b=bMeGhomXGQEH11xlFAZWe6l7/u9TFl3j7R1oRJeunL+TvhoLTHlLdmFxAKtLqWL+gtrnhG +uUQfOtDzDStanMVWsEgmCJdSptS7mnfUb52eZdcrn8CALzZ7Mlf5XmgUqFhRJ/YSng/fB bC9XM5msS+Q3fQoK8bn2kdxsG/7F3fU= 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 80514622B2; Mon, 7 Aug 2023 22:02:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 35F60C433D9; Mon, 7 Aug 2023 22:02:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1691445740; bh=teb0sKS9busqSVOZxV9N3xrEhZqf3CdoVbQJObdkbLU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=LVzzDEWk5irsxJYUs1w1FquJWSX+JT78LSGknjsJsaejE+UoRpw58HiGbpXy/uKKX lr2CjK8ST7ioqGIwCg6NUpvsRwMWJuH2jruwL5NNRnDLOY9+V+boB6F1bY4uU1vYNw n1A1JxLL9hnmg1WqURqvV4j4PxB+iJ+Kqvnu7ZA6ethH1XCdP6sCjs8u+zn3uANIg1 rK3jnoINCNkFwtm0pDuOtUQF23D5cmJ2BpIw7LC09GyxR4dB1H+RW4jbyFYJUJC4nP J+w+XeKpEqYT5FjUPLMNrR4utFZUox+SR6RIbQLU46H1GGLdpiRM1D2ZP6m5mZcPZH jGc0OD1BIhhcw== From: Mark Brown Date: Mon, 07 Aug 2023 23:00:13 +0100 Subject: [PATCH v4 08/36] arm64/cpufeature: Runtime detection of Guarded Control Stack (GCS) MIME-Version: 1.0 Message-Id: <20230807-arm64-gcs-v4-8-68cfa37f9069@kernel.org> References: <20230807-arm64-gcs-v4-0-68cfa37f9069@kernel.org> In-Reply-To: <20230807-arm64-gcs-v4-0-68cfa37f9069@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/pANAwAKASTWi3JdVIfQAcsmYgBk0WmeNgerRxHk3+vE3fBS5wdL2AtUi7SFsWNQ653Z m4fHZ06JATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZNFpngAKCRAk1otyXVSH0P2pB/ wKlrLvyaCHwWtLXYP9hvB1q4+QtHKBda328eUhF+7qyfOjcVaOhbuom1bNnFuI++/guvbu5LG1kM9X 27l5PwyGxbXv6q7MnO8hgn6Nn9Hu/HiKDapUzAzcEOZEv8kWzIZvMB36boWq18dQ57i1v3mq0xZsUQ WTyKXGmNDPaju7j3528qf6l0AjKyZs/sCPQBz7/zf1ZWTFLPBlaqkZfiYH4smiqxCAcZgQxITYLiAk 9pbqLvnVI7TT7Zlv5Wx1rAClUq7gWOvkmff8qbKDfYvAyNV0YtBGCobyAi79UT4ZoBPAIHBtiR1elr ElgMhlMSnbddJ6zrDyW0TjYkp/NLau X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Rspamd-Queue-Id: 7226A140012 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: tpuag7x4e13fiuiwqtac5q1epqokk6xe X-HE-Tag: 1691445742-759917 X-HE-Meta: U2FsdGVkX19En7Tky4V2BZir2uM3Nyq9ephVqMnYO+rKw98N6UOgmC9Bm13P2BBKWNj9LcvsO4KXSaWCLqD3Wf5MFRmMZ5KmHPzwk8tSwazYATviEc0BlBPglaMiDMHNvuHhF3mY7zSTl2ln5w9xoxLIYbYEHH1Rz67ss9jSzk3YQa5/wFeUlOc9p1e44A/PKXXN0a7ocHQEMlLmDL7Deud99a7kimkRsHrd66xZeIhirLfG8trwgKd5QImyaleedqUCh2N0mV35k64PLc+tW3C6vQfs/FHjPFvHlMAa3UGk+hHzy1LCeSFGVckNR/ULWbAKxId+KPu2XdF+GaCAwq6tC/+Snlni8s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icity=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