From patchwork Wed Nov 22 09:42:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13464404 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 E3B65C61D9D for ; Wed, 22 Nov 2023 09:44:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 887B56B059E; Wed, 22 Nov 2023 04:44:11 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 835B76B059F; Wed, 22 Nov 2023 04:44:11 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6D7896B05A0; Wed, 22 Nov 2023 04:44:11 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 59B8D6B059E for ; Wed, 22 Nov 2023 04:44:11 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 26AF2140567 for ; Wed, 22 Nov 2023 09:44:11 +0000 (UTC) X-FDA: 81485104302.15.B5C56DB Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf09.hostedemail.com (Postfix) with ESMTP id 5C576140013 for ; Wed, 22 Nov 2023 09:44:09 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=OvKVQHJl; spf=pass (imf09.hostedemail.com: domain of broonie@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=broonie@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1700646249; 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=cEnjzLtEtU2/qgYRbmQ8ScupbG36KHsvEqwwkTuL5DM=; b=hJd27Vro5RhPfqsm2CFlVuCc9905ovecQ9So7a0yIjCLn7rMdT4ERH1OWGh6wB+KsTLqgn SjDDWGL5MXUBW/eDHCfUaisXzRf0q5A+mVsHPxdslK5sK/J37V38KmyUmvD2DmOjeihhBQ 6kDK5D+10gDmIxBCz8ubwoSu2zASBpA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700646249; a=rsa-sha256; cv=none; b=Pl/Ou01BBeMIgU2R4Tya/LbXCpf/yfB0cD1fiG+P4FbZN/Z/tRyaQiXq2PMXIe4uU2JSa6 8mEV03aSGqoDtQdv+jxdIzYjf8NXcLV9Zlqe8o3tn7434j27mePPG1B4Yh29HSyPZFNZNK y9VpUN7ycRhVDnkRd1bklCoer7ioN+w= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=OvKVQHJl; spf=pass (imf09.hostedemail.com: domain of broonie@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=broonie@kernel.org; dmarc=pass (policy=none) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 6160A619E9; Wed, 22 Nov 2023 09:44:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 22E86C4339A; Wed, 22 Nov 2023 09:44:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700646248; bh=i9QyE7h/VNfEY/fQWg1KcUCsnEaqWFpKvbtjF57JZIU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=OvKVQHJlaRBJIrr/EqVvB1Vhp4g6DB+5CWEBUGNM3o4IyXrYXjYMV9aL349rfMduV iC1sUc8GEMqhX9H+WRYy595ExaJkKlI4MNhh8kzV2HwPjOacNIQul8xtmQvxy/xNWy bJyZ92pIRTGziqyBTlQVmhpRcHecvfbBV8wVxA1Jl3BIzkpyZ6s/ZovvVa/P4DuGKH mxVnXURPLXu73B5K45nsYhJhGwSGJGkfi7MoHRbDJvnCRGQ5ZNTznbOFNqjlxfBHPi GJ1mJL/sYWm4X7XtGJckFaZSRb6p2wAJFNIMhy8vDr+jKDW1Wp5g6OdIf+KPnIfmWR oSzOQyZR1Z4qQ== From: Mark Brown Date: Wed, 22 Nov 2023 09:42:20 +0000 Subject: [PATCH v7 10/39] arm64/cpufeature: Runtime detection of Guarded Control Stack (GCS) MIME-Version: 1.0 Message-Id: <20231122-arm64-gcs-v7-10-201c483bd775@kernel.org> References: <20231122-arm64-gcs-v7-0-201c483bd775@kernel.org> In-Reply-To: <20231122-arm64-gcs-v7-0-201c483bd775@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-0438c X-Developer-Signature: v=1; a=openpgp-sha256; l=2922; i=broonie@kernel.org; h=from:subject:message-id; bh=i9QyE7h/VNfEY/fQWg1KcUCsnEaqWFpKvbtjF57JZIU=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBlXcz+s2txHvZTDwLAf6SOVjsd+5BN63pi8i51Z FULlftCXzOJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZV3M/gAKCRAk1otyXVSH 0LSmCACGoUb2lLCDHWabC23R3Nx8VwtQ0tQQHq3bVsr9lWag6ifOZORAusKIlhzB1Oof9Iv9cBG 7FBO3D5ZhNs6EMIXSMOy38ifF/x/csaQnxTcH0SQxUa0yxqQabljmKvoALa4i6z2Sae8FCyOu5E bYUX0M3PHsUF5jPmg/O+j9TkHroXSXFGeQgLHN7x67h3d/QTmpeg1SC6AwlkZYnH/dUUQusDF4r mj6E+PFeikOSBCVgHbO/jkc02tozpz97gUJGsZ9H4glsVXGtiH+3gPm2IGliCtYTvx2Jwl0/Mu+ 7ZPEOpq55NzT3FgzhsBiZfL6DeYDKnu1Tu30JsJ4LpYGSAQ+ X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Rspamd-Queue-Id: 5C576140013 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: pfx3hqfb43amh46tbzge8f5g5tjbmpct X-HE-Tag: 1700646249-472828 X-HE-Meta: U2FsdGVkX19J+38x6y4Yct5q/kJFhygbGJjUE0vw3iQIOd95x+aZGLQ8GwCRolAc7V0Axd8Dg9ngt0DPm5s7kqaFZc5STiyL2NB9pWCTWzjlrvYAnLDIMSPQTRY+PN3GkTflbNXWOKI8/XgrAOV0DWAAoiJ3OsdZRSDZ3uXntfdmkFqQ2IFWKkQ7OB6xTXc4LB24C1C7SJNcoU5fA5MjOizas/osn+irljrUAQIQEfi+JciLNgc8twGS47ZRwrdvPw80R6DPdZ13u8CtbfKvodZOBTG/VDjERiuAoytMnZvURNSiTFXawl7X7TWJD/xp2fgS8Lkm1CYrbTtTCPaia04A3NGEB2wTtztZyUhiQnFkTiqfmqSEqOUHLqgKlHHZq6bF7jsdWzvEOpKL3dZBuzFnh2fz2QdsnQruRzQy0WjKnrzQSZ8Ccp9PecpZJfHzzxbXbLggioFcfSarX9cnGSJMnhJyQoLaagLGim5zwjTVkxG6Qo6ofsG56QYXmH5sxHcnH9C3Z0TZvsCNfRelAy0BjXh2POAxpf//ONJ+9WaGNzYtfauhzwkJuI5uDRAgi9IS4USUXvb9OyzzwSzfLsahvQBZBOCsJjspE2QsmIJ5LkqEZkzCfVxjbXg9funKH+n/oq2OSqCG9cFYokH3jLYVGAGHoegBYX+7wtQQyZ7bgVZgUlEJZBhOOzWFjRkeffN57J+r1w4FI5+10E8w5yN8/sfKkEqFPNKS2PO2pV9dbvcr2lPSn5hz80iQnhjht57jdZxFz/mVBs2l2GBrV7ejwXPMtIny6RmBIvss+p6qkFHXJ4uZ+KH2J0c/07QUMgk5QwR3HV6K6tfC5pO+hKddh7uLY3wlse67rWtj1sR4SQxeQUDjN4r31dDzfU58BYM22OQT9BsSSwsyw1vCLlt8aQICV+xAQo/TaZHmsILWsx1RlydfwVeKRJHzBiIzqofW/xWmV42QBX22Z0L wOTxu0Pf wzEqDg6Ue32yBuqVgd4SWYqoYNOYHU2UsSE5iCS7cpYE5LATOctU2emdqqYKfZ5j79x9OKNSikqswwgLaEGhpL8leG2KxuRRjMFC4ituQeQ84oy4glGUY6YKC71tkZFRgSRSje43PSCDfvsn8BrueflbHPDPMQ8Zw2P5fseKI5emj0H5Otsj7CGCPmzVJd4dS0QSyNbf8iVYgCpcE1/CTB+zU73e/fJpXFU6t/ukmnXdR0cD0Mx6YSJ9LJ00RY8yF2mwnoWOMfDXZqOIqcXKWb0Jl+2Lj2a4e+wuNQlcCLKfKthJpRRHca5Kf2hkiYxGrGLxD 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 f6d416fe49b0..5696a55cc1f8 100644 --- a/arch/arm64/include/asm/cpufeature.h +++ b/arch/arm64/include/asm/cpufeature.h @@ -819,6 +819,12 @@ static inline bool system_supports_tlb_range(void) return alternative_has_cap_unlikely(ARM64_HAS_TLB_RANGE); } +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 646591c67e7a..5477451cefa1 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), @@ -2242,6 +2244,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) @@ -2731,6 +2739,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 b98c38288a9d..30d27f6301fd 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