Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp3557723rwb; Mon, 7 Aug 2023 16:02:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEwmx07wdaDB6RWePLi1ADp1W+8mIAQlO7k1wd6yI8LS89l+GMENYFZaQRoQ3oEXQFr0KfV X-Received: by 2002:a05:6a20:2451:b0:140:3554:3f41 with SMTP id t17-20020a056a20245100b0014035543f41mr11560720pzc.54.1691449334199; Mon, 07 Aug 2023 16:02:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691449334; cv=none; d=google.com; s=arc-20160816; b=P1ZxFit8vS0VPh8eUuLMujosDbZirUApJRWH/1nkv8aAl52yxzu/pqzc+VAsbBzEpe 1XUZPqfwr04Yv3v6JD7DoNhvQH2GUw6ddAia6qSNLMBOQhwXpLmxh3sRvSXQdFtQp9+J cgaMm5xD1wTo5uoVeiLFEVnnWbedgchKFT2aAYQbJnDASG8KhXLJ5pSGTokHx20CKwfi ME1ahU/fs70iijS56gFGfTRuYUxEw3y1wrNdb0QzB+dPQ7Yj+QM008OkjHeWrD+0Gk1u a5Q5rdSkij4CjMKkrJLvc+ilNlnq4VhjacxwLKXC/V8yq4XPYNd8vSo1yii2NzTce40y nMEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=UsQ4evMiiAYwQjdayZkqlkQ8Zju2zsq0zDtbSV9Oikk=; fh=EdAFSmIgUzZTC6WCy4Jg1wBZ0/m6m2d/OjiRUJ3BsTI=; b=k8OIGzV5uqn/44ogag2rOTmJW8VTHYxmktt7e8GehkV4QsbjgH9AUup2WvyA4klhwD 3dGXwcme0bNwT2DhsdbFvDtuR6A0SZSi2OM56OlJjR+lTqghL6Rw0Glw1o4uuXfbbbkF OL2x2ypNxdGa8s0ZgAlY8OUUECnUsyKzICMxQufNZyaTnNK1fy/SVHw5BG0TxLaBmSOo zg+T0TLQYokzdZrFCKNaHSuj/1KVnW98GCpAiWzJNhSAUAc4OzXmzwkVsa1AhOtTJ6SG DUitf4k3f1o161/P5/wkD+ZrmZBnqj9M7yyaZz9ay3NsP9y4XohwH6mdg1JNqqtucWcY c3DA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LVzzDEWk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q10-20020a056a00084a00b0068740bcd8d7si4063993pfk.362.2023.08.07.16.02.02; Mon, 07 Aug 2023 16:02:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LVzzDEWk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230450AbjHGWD0 (ORCPT + 99 others); Mon, 7 Aug 2023 18:03:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42380 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230267AbjHGWCp (ORCPT ); Mon, 7 Aug 2023 18:02:45 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C6DA114; Mon, 7 Aug 2023 15:02:22 -0700 (PDT) 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 80EBC622B3; 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 -- 2.30.2