From patchwork Tue Jun 25 14:57: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: 13711437 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 591E3C30658 for ; Tue, 25 Jun 2024 15:02:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D97486B00A3; Tue, 25 Jun 2024 11:02:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D206C6B00A4; Tue, 25 Jun 2024 11:02:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B996C6B00A5; Tue, 25 Jun 2024 11:02:23 -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 96CB16B00A3 for ; Tue, 25 Jun 2024 11:02:23 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 1BBE7801FC for ; Tue, 25 Jun 2024 15:02:23 +0000 (UTC) X-FDA: 82269726966.02.A136188 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf10.hostedemail.com (Postfix) with ESMTP id 9E09BC00CE for ; Tue, 25 Jun 2024 15:01:46 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=guFLMlnM; spf=pass (imf10.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=1719327698; 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=yuW8U8d6RaSDulCVk8KUFCc3flk69UeERzuK80b34IU=; b=kIvBBRrzwV80kBkQiRK8Z4uQRbw2e8qXg3kimJheJfGF03ixPyYoglzLGRKOGrlN1eSvg8 Qa2IiAG8fg/5oEOSI/j8Fkq4lmffgJW/k9ZK1fJw7xaP8i1Y30Yj5xcsnMQtYmg7GPSS/n +mACxXU1l42u5uMlRL+HYZofSJEFmyI= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=guFLMlnM; spf=pass (imf10.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719327698; a=rsa-sha256; cv=none; b=SfADaa0hbwfEvZK0IsA5r1Ox9UkwHAO/ekf927n1HwS2J+azizKxs7Xb+qRweA4s97f6JM VNA9RSKlaGwa99X/fafWq0ixwc3KYPSX7X2aUVgj+TrhnVf+zf7EyqbN3XYv8zfjT0V2LL W5hF2hQ3EEmgIDjZYWeCMQK2dHbecyc= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 3AD6E61461; Tue, 25 Jun 2024 15:01:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 71FBFC32782; Tue, 25 Jun 2024 15:01:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719327704; bh=HBYukUfWWcYFaZwVBzBm0FRifOIeZ7AM+OQsOqT0FkM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=guFLMlnM1QO43GlmvCb+/U/FOOQAUKPCWEgOqJfY5M5MDV6SRmAQOa8q7C9lTPBvJ bCTwBCFm1G71kP5NwfiymCRgWuFdfK88BlX2BsEf4OZvoHlBG33AubZ3oA/ri9TwuR x3h6i4zE6icz8GEnRzzvzKVrK4BJFmIoHUDgx/cYgO94TdAqy3duoeOcMTWTqqkl83 XJYk7MlKz+mCHz9ly6aD2LU/yOz2Xsh7xy2ZOaj10LsQ7cSw/hkg7Hoa8xWvYO8fgZ 5F+4lZS184nGsTwjJsweeg8rH9zsi87ornpjkfw9+/ddJndjUetLK/mVuxfPCyrGG0 cmGd+vmSRllcQ== From: Mark Brown Date: Tue, 25 Jun 2024 15:57:37 +0100 Subject: [PATCH v9 09/39] arm64/cpufeature: Runtime detection of Guarded Control Stack (GCS) MIME-Version: 1.0 Message-Id: <20240625-arm64-gcs-v9-9-0f634469b8f0@kernel.org> References: <20240625-arm64-gcs-v9-0-0f634469b8f0@kernel.org> In-Reply-To: <20240625-arm64-gcs-v9-0-0f634469b8f0@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.14-dev-d4707 X-Developer-Signature: v=1; a=openpgp-sha256; l=2967; i=broonie@kernel.org; h=from:subject:message-id; bh=HBYukUfWWcYFaZwVBzBm0FRifOIeZ7AM+OQsOqT0FkM=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBmett5TPImNiJ8QKbVQxAR+IKRHbeiwzvOwBa7FcIp VCtDJlSJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZnrbeQAKCRAk1otyXVSH0C0wB/ 9NlpCrbN55O/ocWyGWdcitxqcYlV5HNiRlaj/HXg3uyfnTgowjv1GnR10+pBR8qw6i05h/sCLgJkcW 89w0l/rOivkbV/LHTpoMWradc1lhtcePGc8r2oqea9dHPtD1nKD632CWNTiByENihEmHnufFbWzCdD n/kuevX+t5HPce0qds2YCgqByhWei+20Tq3fTtGrBTDK+9DFEpFfKxnT2fuZx1e/20QT/gQaFeXkCQ yrzSLi6gdBWy9fG6Xpuh2j2YiYF7yaiS6DhtFjSLzwS/lGdnk3onXV/WMYzqbgrefN54gTj2hKQG03 WFocfLobkJrHHUhGnQ39ToAgXyrPXO X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 9E09BC00CE X-Stat-Signature: 3atank5bsubcb7s14bstn41hfc39hnqu X-Rspam-User: X-HE-Tag: 1719327706-136253 X-HE-Meta: U2FsdGVkX1/Iw7T83wQ8w9/5B1gZ7JUghcuKItHUXZ32NTitTAu0ORHSL1UibvC/VN7eM/9jAZHUeTOMIantV0QMzF0FcNe/MzE5ksgGjDvFOZ08p5nKb/WQiJjDDu5IZ3B2Usg2KI3i8+pZsGW800POvJ5vqBgFfTdfYePh8E6p4mSguyw+eSZqL8IhFew2C8ZZSLWJnWDNCpnFzXyiOeMvAaE0AlqzjkvYF8QUa0RXqTq2Yx1YAtUT0kjW5i4DoVROly7aoXpw/t5UwjucrrOQcYPHjZje4clIzW32HNhM6pxA9hcxq045OfhuJjoBHddzRmLF0pXInWsh0opXqFRlLR/h3ihXR1WG6BN9UeiqVAt25mzQyEE3VEsEoPWeR1c775IsoJNAAOOW9phtC4B1dxpyJNUJ61nOnZ50mTQ3GGAFYtGtwgmemfgSD0X+7Dx56TE0L8AR538PQGpuMXZWssyEkhz19R877vG2V39XIKxs7n9A8A0tpkzgho3Fm8e9AIVKs1wH+SYPCm8YNmiExFormoDJGjc1ElV+QCvNR0J31Pg2iGpEbea56+u5yg/3WAQANS0TgSgnUyibfFByDtGbF93cx8m/bVIUkqku4+WG2ayvNKV4zUYb1RF7FNgu9y3/6HNQk6vf674QRcWzAGRPB6dPQQChPBqZeMONldytTH5kmNbuKwUYGUzARnkRprPI6vLmRpdslVqJr7VVHfdLnfEVl0YlGiAEkeeMduAjZQc1s196fM6o7+PIDQYa6X++zyCp88iyR0YmGK8hZZvHEofnhjbWZP4eMMONfQYT4Nnm9WJKvkPZ5QQEN9eDQnNBluOt3oLEzay42EBY0otv/PWmttHVl9MhJD9TVvYH+mZtSVxgumLCnc2seoUbxGd4Y3L5rz03LRerfXM5DnBTC42h06HvBfidC91iDqPS+WYr4ZIq25+2QbUbqTX42WUHpw7pOmrBTDH 61QrO9ep gtnwsGzL0VJLisoQeoZXN5GshfNFweHGDbyMI8nmY77nMDH55LSfYVFF4nus5Yf7TDyyQu3KoluNxTlDIN+HulWAvttWnNj6u/d0Wz4QTRcB+5nRYxgr7KEFryXSXeXani6t6u9kO23wJhk0Yj2YdPcdDMSPSrOW2jVZfYCahnnZhyeyyYlKTQXnEAFhgJokAkWDd9fclWAXKZ05kv6z/7BLzLzTXP1P3wNXk2PUcbjsHPRau9pt+7FO/QyOd8bDz+TovhpO6wOll61/ANbZlJioglE8VtFc65xYXPXrOKnXdUwyq0MfbtQtTp8E8nGhIWTnVV9XmomI4OHjmWNkWWn6KSSZ6/2RRM8EbtF+rMYmj3Z9OwV96GEDCWMp3esKGUVVR+vcIFG4JTCyhZMm8FoGgnuXfRTUeuxwdO1Pt5Pa+QCI= 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 --- 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 8b904a757bd3..0ebed5dfe55f 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 48e7029f1054..056d394920f9 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), @@ -2347,6 +2349,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) @@ -2869,6 +2877,14 @@ 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, + .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 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