From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4F36FC4332F for ; Tue, 27 Dec 2022 14:37:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:Message-Id:MIME-Version:Subject: Date:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=diy2HxnaZl3AteP4j+DWEeIL525qQM7MnyOwssazH6E=; b=KxfKifSYM3aqIq lQliBdlzYNLvlyHAv67P3yRURP9M+xfSuSdJC0/N3fX85E+VwiRz9lFztZ9HPNAp0iIyflCurgJid o/W1iflG0KxxVHwIinPTNIstHNXk3JzDaIPVLpXZFYzmpxgpDj2BkmpjV80Jyca+Bl9aToBx1Ew7E fENRdJ3sQFhMsnB2qxQpTTWFFeojxvHQ4FbfPVJvu2fPv3dhcMq0XozsaLV+Qe3joOPrC6Y/bue5m 89gjspJOvGlofsYoACof/zvU/weruklIPNonjYsyKM42GURNdqrzzl90Ruk9kohOU2SFMsnjCSS+S 1x2Jh6Cbg87NskUjGdPA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pAB4U-00Diir-CP; Tue, 27 Dec 2022 14:36:50 +0000 Received: from ams.source.kernel.org ([145.40.68.75]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pAB4R-00Digg-61 for linux-arm-kernel@lists.infradead.org; Tue, 27 Dec 2022 14:36:49 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id C74A3B81077; Tue, 27 Dec 2022 14:36:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7553BC433F0; Tue, 27 Dec 2022 14:36:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672151804; bh=2wGkgyxcWBmupp2V3Kr1yM7oSkmUUvMbGfA3AUoZn8E=; h=From:Date:Subject:To:Cc:From; b=fwqv0f+Qzrn5JNWk+QRQIMvWsc6rLZ36bNR6VBppAg2HqEvMVT4KSm0wD5faCRAFX l3gpISIe0ZxJBg9l7EtV5BoXV4ISE8KwbKQ4xNnijFqTxn4AVkw+4gMLiMaSvh5fJN 45zsXHw8cmCSd/h4Utacu5mBXRNewFXY1EsQM8P+nWKUIh3uhbQuzgMdKvgHMG1rdF BgjF0MgQf9h0Y+2njJsO8UU3Bihfwm8MiFJOw8oEt7NyiIh8iPwa779cqCHFhwW0nm LKU5mtdF+ATtCuLaUlmg8u0nv19QSNuHuumzoheTx7u01qYidxLhWd9e9Tk+fTK3En nCPEWePuxYDEg== From: Mark Brown Date: Tue, 27 Dec 2022 14:34:58 +0000 Subject: [PATCH v3] arm64/fpsimd: Add interface for kernel use of SVE and SME MIME-Version: 1.0 Message-Id: <20221208-arm64-kernel-sve-sme-v3-1-1036dfbef29c@kernel.org> X-B4-Tracking: v=1; b=H4sIAJMCq2MC/0WNQQ6CMBBFr0K6drAtUBtX3sO4aHGAibY1U0JMC He36MLly8/7bxUZmTCLc7UKxoUypVigOVSin1wcEeheWGiptdLSguNgWnggR3xCXhByQLDeNl2P p84qL4rqXUbw7GI/7XJiGikeg8sz8r6/GAd6f7PXW+GBU4B5YnT/mJKNslrJrjZtq4wBVR5TioS XX71OPIpt+wBFc97jwwAAAA== To: Catalin Marinas , Will Deacon Cc: Ard Biesheuvel , linux-arm-kernel@lists.infradead.org, Mark Brown X-Mailer: b4 0.12-dev-7ab1d X-Developer-Signature: v=1; a=openpgp-sha256; l=4413; i=broonie@kernel.org; h=from:subject:message-id; bh=2wGkgyxcWBmupp2V3Kr1yM7oSkmUUvMbGfA3AUoZn8E=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBjqwL6LMWY6Ku64ZH2EE3jwnXYfvd744SuyNGPAhZG hBfr0deJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCY6sC+gAKCRAk1otyXVSH0LKWB/ 9sm/SUvpDmf+C9lzBBsecAqwDKafYYzvmS/KojA+3dPuMMRWVd0HfsahccIxZYDFVx90ZD3azd5rK/ O4OmycvgYbB7nx9F2d2fY/UCNeHZVNdRWpyqaSowfzRipPI/f//n3XvQxuuXao8whelFA5PRlf6pEI zJVd3hvbi0okCky3UUYMDww0LYtiRLDznELM1vEIEwXslAlgWsA09Z4ANMxEXVqkLr5xDj4UqqiIAx ThIBtRNKQSwknhplxoG+fXmOCfgRZrkGCTtIhoTh9JflBeWYrBL38Y7r4HARHf/UDlzwJnLYCE+zh7 Pq/E21VrDJIlwNH9jH9ZBCk6qH0Rl/ X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221227_063647_602922_2E54B8B9 X-CRM114-Status: GOOD ( 23.03 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org We currently support in kernel use of FPSIMD via the kernel_neon_begin() and kernel_neon_end() interface but there is no corresponding interface for SVE or SME. Given that SVE hardware is now becoming widely available there is interest in using these more modern floating point instruction sets for in kernel applications let's add an interface which allows them to be selected in addition to FPSIMD. The sharing of registers and code means that using kernel_neon_begin() is actually doing most of the setup required, the only problem is that we are not configuring the vector length so any SVE or SME code would just use whatever vector length is configured in the hardware potentially leading to uneven performance on systems which support multiple vector lengths. Add a new kernel_fp_begin()/end() interface which allows the caller to flag if it will use SVE or SME and initialises the vector length if requested. We allow simultaneous specification of multiple extensions since it is possible that a user may wish to mix them in a single algorithm, there is no cost to allowing this. Signed-off-by: Mark Brown --- This patch is mainly published so that people working on implmenenting in kernel SVE or SME have something to reference, I'm not expecting it to be merged until we have an algorithm we want to merge. For now the main thing is avoiding having to explain the considerations for vector length configuration repeatedly. v3: - Rebase onto v6.2-rc1. - Fix build with SVE and !SME on clang. - Make symbol _GPL. v2: - Check for system_supports_sme() for setting the SME VL. --- arch/arm64/include/asm/fpsimd.h | 7 ++++++ arch/arm64/kernel/fpsimd.c | 47 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/arch/arm64/include/asm/fpsimd.h b/arch/arm64/include/asm/fpsimd.h index e6fa1e2982c8..6ac5eb8e5ed0 100644 --- a/arch/arm64/include/asm/fpsimd.h +++ b/arch/arm64/include/asm/fpsimd.h @@ -44,6 +44,13 @@ */ #define SME_VQ_MAX 16 +#define KERNEL_FP_FPSIMD 1 +#define KERNEL_FP_SVE 2 +#define KERNEL_FP_SME 4 + +void kernel_fp_begin(unsigned int flags); +void kernel_fp_end(void); + struct task_struct; extern void fpsimd_save_state(struct user_fpsimd_state *state); diff --git a/arch/arm64/kernel/fpsimd.c b/arch/arm64/kernel/fpsimd.c index dcc81e7200d4..903c00f8317d 100644 --- a/arch/arm64/kernel/fpsimd.c +++ b/arch/arm64/kernel/fpsimd.c @@ -1923,6 +1923,53 @@ void kernel_neon_end(void) } EXPORT_SYMBOL_GPL(kernel_neon_end); +/** + * kernel_fp_begin(): obtain the CPU floating point registers for use + * by the calling context + * + * @flags: KERNEL_FP_ flags specifying which FP features will be used. + * + * The caller is responsible for ensuring that the requested floating + * point features are available on the current system. Task context + * in the registers is saved back to memory as necessary. If SVE or + * SME support is enabled then the maximum available vector length + * will be selected. + * + * A matching call to kernel_fp_end() must be made before returning from the + * calling context. + * + * The caller may freely use the floating point registers until + * kernel_fp_end() is called. + */ +void kernel_fp_begin(unsigned int flags) +{ + kernel_neon_begin(); + + if (system_supports_sve() && (flags & KERNEL_FP_SVE)) + sve_set_vq(sve_vq_from_vl(sve_max_vl()) - 1); + +#ifdef CONFIG_ARM64_SME + if (system_supports_sme() && (flags & KERNEL_FP_SME)) + sme_set_vq(sve_vq_from_vl(sme_max_vl()) - 1); +#endif +} +EXPORT_SYMBOL_GPL(kernel_fp_begin); + +/** + * kernel_fp_end(): end kernel usage of the floating point registers + * + * Must be called from a context in which kernel_fp_begin() was previously + * called, with no call to kernel_fp_end() in the meantime. + * + * The caller must not use the FPSIMD registers after this function is called, + * unless kernel_fp_begin() is called again in the meantime. + */ +void kernel_fp_end(void) +{ + kernel_neon_end(); +} +EXPORT_SYMBOL_GPL(kernel_fp_end); + #ifdef CONFIG_EFI static DEFINE_PER_CPU(struct user_fpsimd_state, efi_fpsimd_state); --- base-commit: 1b929c02afd37871d5afb9d498426f83432e71c2 change-id: 20221208-arm64-kernel-sve-sme-8b835ce7581b Best regards, -- Mark Brown _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel