From patchwork Thu Aug 1 12:06:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13750389 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 2AC77C3DA4A for ; Thu, 1 Aug 2024 12:58:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B647B6B00A7; Thu, 1 Aug 2024 08:58:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AEDBD6B00A8; Thu, 1 Aug 2024 08:58:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9409B6B00A9; Thu, 1 Aug 2024 08:58:35 -0400 (EDT) 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 70AF16B00A7 for ; Thu, 1 Aug 2024 08:58:35 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 20E3340D7B for ; Thu, 1 Aug 2024 12:58:35 +0000 (UTC) X-FDA: 82403680590.18.6302228 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf28.hostedemail.com (Postfix) with ESMTP id A7775C0008 for ; Thu, 1 Aug 2024 12:58:32 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=qScMxBIs; spf=pass (imf28.hostedemail.com: domain of broonie@kernel.org designates 145.40.73.55 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=1722517037; 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=GycIpknep37rYdVQ5s1q83aQmaLU2J/Dkh6k2oXEc/k=; b=XNIJ6w4uX81E5CH/829n+urdL/3hfUmD3pXK6NKb9hLl4SU7GRvXC/14oe5m4wRS77e8T7 VqlOBpEK54y4j/siOQMHxpFIhIo1eZnNwqnWejENV0zgiIC4VtQf8utx5l2ageUYhha6J6 kxx/Wk3Z/JGtZG87VgPBcYv6CeVENys= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=qScMxBIs; spf=pass (imf28.hostedemail.com: domain of broonie@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=broonie@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722517037; a=rsa-sha256; cv=none; b=mxemxFQRbm82rVp2Wyws6Qm+JHkRvhh66B+B3YawpbOUFIkNkwrwXWFgxoapmbdYgLxrqd FdqZwRqR/T+fRy/0laxcJqYtQJY+X6CRxrzZrrMiNIoqz8SXgzENu1actMaSCSBJQTmYO2 j+4RGXuFIvzXMsNTCLiuCD/jXPQDdhY= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 2AE1FCE1979; Thu, 1 Aug 2024 12:58:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ED585C32786; Thu, 1 Aug 2024 12:58:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722517108; bh=7s/gHN1rW9TWM0RWrG/NmXj1X2oouK/u/2cODr8xaC4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=qScMxBIszKrXZE6l4jPoTZd0nsXO1uelO8k1eOLYUYobg5sCv+WFBa/d9YsyPSjjE Z3j6LkQGPdSakAiJyW3ywm/GCPzVnFwElgiqof7vhrJX2QXsPqq5y0pLAMme20kovg 4N9nUNe+fShGNxKq9paQfEnIMMwvAbMfweChUFzIn+lCsfai4eJp1X0wVoD4A0UPqJ 7hGh+xa1HXikFeCOdh+57VLYWktfB1I6vBg3MPem/FMEiyccc3PegQIP8kXmxbXGij CL3VqAezLGfpJprR1gOrh3ZMaWOOl9hB2i8Khf5JXTuVWsbO7Xp5uOI1LAGDQrRteJ 74cl5kQDYkVzA== From: Mark Brown Date: Thu, 01 Aug 2024 13:06:37 +0100 Subject: [PATCH v10 10/40] arm64/cpufeature: Runtime detection of Guarded Control Stack (GCS) MIME-Version: 1.0 Message-Id: <20240801-arm64-gcs-v10-10-699e2bd2190b@kernel.org> References: <20240801-arm64-gcs-v10-0-699e2bd2190b@kernel.org> In-Reply-To: <20240801-arm64-gcs-v10-0-699e2bd2190b@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 , Shuah Khan , "Rick P. Edgecombe" , Deepak Gupta , Ard Biesheuvel , Szabolcs Nagy , Kees Cook Cc: "H.J. Lu" , Paul Walmsley , Palmer Dabbelt , Albert Ou , Florian Weimer , Christian Brauner , Thiago Jung Bauermann , Ross Burton , 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.15-dev-37811 X-Developer-Signature: v=1; a=openpgp-sha256; l=2453; i=broonie@kernel.org; h=from:subject:message-id; bh=7s/gHN1rW9TWM0RWrG/NmXj1X2oouK/u/2cODr8xaC4=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBmq4YNgfqa/ixM61jewvMBym4ukRMnWI/ViFp4+3Jz URec3AeJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZquGDQAKCRAk1otyXVSH0An1B/ 42nmOBfn/4sSlWSLsHjdMFjPjyaLDIR7Dx9tGlYicIgU0lkdGVZEZk/Tk/sufifPGYX8G79vGolOK/ MczkShezUksVzrd1+DAMNjoHsukcOl8U3cqwFjCKW700My8kSSTR43ucvlPf9jlRzxlkRw+hU5upW8 PAr3+wx1mTca/ZynY3/XuSz3Udebj7h4fkiNPBzVU/kEnE/LJDLvcvsDSg7p1TziVpg7w6sr1noMu8 05mLN/s+AzWeWhuoJ/M774sJ6AvcfWn6lvHpKGctfqdo8u/MQ5oHFV7hUt3QR+nhcgJ8JvdKEeDRif TWMj6huJOHT/eJ7M+sNF3opx5AEHQG X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: A7775C0008 X-Stat-Signature: nn68bereb5jdghb8n3d7r71fkapy6yfc X-Rspam-User: X-HE-Tag: 1722517112-106821 X-HE-Meta: U2FsdGVkX18/EDXzI9edpm/lJTzhELLvcxxVtvBXo9RmEHXOAPCiP1cU+EOTJGPj/QDfwo2TybrDrnB1w6DesDkaFZFZnPMuoz8w72LN5C4j8EGHtG8usjvi5iGX/wAw5Jlf//t6GCshA8VWywHp/hWE73n5n7Mo5ntPVvbWiyU/CMPllnQEHAsc1ECDXdgmO7NtlQ4Bv9SuSe+0TpFq/npR2cHqf4DX+XdvGAroFbU5Onv7BiuK/3OqPvsiVfQ+AGPoTlNdCodx+sMzwCvZ+wlJ4o+ssIlUJhXnVoDGA8xYcgjJep+Ui04utaZYYJMzvp0Fq7l/dV0U58LPlFIWOpsnNDKcWQBWQ6+aUAwO8R1F5Z6PZyaNZmxDTEQZosYPeQUzzD6kUpPLe3PjgozxlnzxwGohqe2rdR8MQUvO3T91H9xrvvD83RZgcu9Lr3rDtZs0/7yzr8zJ+/vVa7p+9VPgdrefgnzmHN0Qn4dCrxFTtBrxlFdKX4ZkgShz5oXKXnU/HJ9UD11kWt7eIMFBVyucLJt9bYjw/CN85Y3G7SP7eSwqolOlyrkumMQT71E+jQxAGhlWlE5+XhWaZKS7LFlgon3PSg7diFY1Dk/+f8Pb4LThpgFDdpTEXjL52lAvLtd2GypJpDpsilGqjWLl7L9ShYoJcke7Ku5TNeUb2C8n5t/dBB2SZ12ZdLnGBYOs/63PcJr/g7Fe00or+byR22r1wnIIUN5SU1rcdduB1Xyp81mlYWujBsyKQkc8W1pHFRepnGgrf8bfVPEyfuv6qd6WmWdbSuWf1k4zfuBFv6YQuEtOmARami7FYaK0NOOn/Mh5WMcDbghPWbZDEnqszysFjYFprDmCqEhzrNQHtW2hmwOzoLDtYnOVDJ6WHNTw3/IB1JcEGWkXCpB2jh9k32mfbBv62wwJHyvkd/G1SIem+Yqs69SxBJz60zpahG/Ol5bpfbR3BYsPyA+1qM3 OXCKV5GS 3R3wYfEfJMoPlP8cRln/afdIFPgWHKvC2zGroQQ4uGR4q9GZLpwsTYfPe5V5PD2e1Zp5bcR/ohlfdPFcuQcwiwGiXJc3F4qnrVZnNnlMWkTMzuQ0TM43wi0dBYIO/5hjVyNj5kQoEuX21umoGi/s7PxNStUYzurkUS5coyMxfYl+VfcASc2XJ1CyAdPGA2bO9FtXZoytDsyC1dKm2PFncSFZE/tsvcUy/OrfdW3VtQLHKdyOL9sX2Yqb+UpfZoabr96vbeFiZk+F5wwqWu727hR1JTLjG53ig3fhhOZpjZbmyV77z4joiSp3NS+Tl2BjnQcFcSKxTQN1BuqPPWDTTrXDZ8gVMetEP9OGYkwYpfhkxc5hAkKfjf82HxfNqnebBYrX6 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. Reviewed-by: Thiago Jung Bauermann Signed-off-by: Mark Brown Reviewed-by: Catalin Marinas --- arch/arm64/include/asm/cpufeature.h | 6 ++++++ arch/arm64/kernel/cpufeature.c | 9 +++++++++ arch/arm64/tools/cpucaps | 1 + 3 files changed, 16 insertions(+) diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h index 558434267271..e0f0e4c24544 100644 --- a/arch/arm64/include/asm/cpufeature.h +++ b/arch/arm64/include/asm/cpufeature.h @@ -832,6 +832,12 @@ static inline bool system_supports_lpa2(void) return cpus_have_final_cap(ARM64_HAS_LPA2); } +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 646ecd3069fd..315bd7be1106 100644 --- a/arch/arm64/kernel/cpufeature.c +++ b/arch/arm64/kernel/cpufeature.c @@ -291,6 +291,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), @@ -2870,6 +2872,13 @@ static const struct arm64_cpu_capabilities arm64_features[] = { .matches = has_nv1, ARM64_CPUID_FIELDS_NEG(ID_AA64MMFR4_EL1, E2H0, NI_NV1) }, + { + .desc = "Guarded Control Stack (GCS)", + .capability = ARM64_HAS_GCS, + .type = ARM64_CPUCAP_SYSTEM_FEATURE, + .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 ac3429d892b9..66eff95c0824 100644 --- a/arch/arm64/tools/cpucaps +++ b/arch/arm64/tools/cpucaps @@ -29,6 +29,7 @@ HAS_EVT HAS_FPMR HAS_FGT HAS_FPSIMD +HAS_GCS HAS_GENERIC_AUTH HAS_GENERIC_AUTH_ARCH_QARMA3 HAS_GENERIC_AUTH_ARCH_QARMA5