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 5FD5FC433FE for ; Thu, 3 Nov 2022 18:08:23 +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:MIME-Version:Message-Id:Date:Subject:Cc :To: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=uiUrdarity+Pe1gxXwK/HbIV5HP7XSarSJ/tFDShMA8=; b=afF7bvRTiaedlE +HhMZupIypK4mPAQBfZXY1axUrEes2vt93csq/S94pJ6v3qngItB67jD7Z4nT5pBFJnMveuOPCrev wNDPq4FF2hMkPDBigg/HtoimYdO8NmLel2hJE6aRncwaQ0TO15odcuR/CPyg6dF0M9BlC5Rye2Mxj wpeMcbGIsXJ4dJkKXlDMqFRe9ydL9qW9umrlVyQAgMckjgJDnvhBPv9BSKMbOuH0UVwJvgSTHaJrx /2TAoAsGa0UmXWKbQQBBwpe5ZhhC8ho1wyOjeaGxzCAyohlG/sgdWOogzcotgdSrjKRIucvrMK6NU OQoft+2LP2zj67wdDxPg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oqecX-001BO0-P3; Thu, 03 Nov 2022 18:07:17 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oqecU-001BNM-5x for linux-arm-kernel@lists.infradead.org; Thu, 03 Nov 2022 18:07:15 +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 dfw.source.kernel.org (Postfix) with ESMTPS id 7220761FAB; Thu, 3 Nov 2022 18:07:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 88006C433D6; Thu, 3 Nov 2022 18:07:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667498832; bh=nbQjot/OsqyXMz8kR7chSO2Xh6UE0wXbLeIHJk1dcvM=; h=From:To:Cc:Subject:Date:From; b=luiW9Flx/p20mlRT51YqxAty26gZNm1sbJQSnEf0P8a/Un7XqvACBGe6gRYUXmmtN xxgjXbuAnass/ttSgTuSFKHIDWWT+9ZFquTnVDuwfG97UPbGYW1pRNLyoLa7JaAsAi +DkctO1dWdtKWWvVxx90Q+IAyjjCADdKyK6M58P7rFbS1cqe049oDCmSow5i3Oiz66 tYbVf+Gzw28zZdwep0RvBNgJThwk6MVpGw2YuX1YdR/VY9HumsG+1vheg+L0kYpudh +fI221F+26cGNVawS8wgZMU17ZFtTLknh5Hzf1uFL0SVWAeZrSMcXYTpKf8GjXjz3f fta5nNXRA35Sg== From: Mark Brown To: Catalin Marinas , Will Deacon Cc: Ard Biesheuvel , linux-arm-kernel@lists.infradead.org, Mark Brown Subject: [PATCH] arm64/fpsimd: Add interface for kernel use of SVE and SME Date: Thu, 3 Nov 2022 18:07:04 +0000 Message-Id: <20221103180704.638457-1-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4001; i=broonie@kernel.org; h=from:subject; bh=nbQjot/OsqyXMz8kR7chSO2Xh6UE0wXbLeIHJk1dcvM=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBjZANHnE5SGGcYDVzn67rjgtaUHS/aEcG3tvCl+2+/ swELxT2JATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCY2QDRwAKCRAk1otyXVSH0ATbB/ 9MDOar69shYC+vYUNkmD8nw8FtPWKGgBYu+XCXpcLh/smTuf26NiAFLD/5vIWXWdzWf8h1nPEz3ZDI RP5B1UjDQbrTKCwxfR9X24eh8KvmHijgYxS6ksY2WTZ5xMPBTS3lcPPd53QlCcWutbW7WiNUnOcyzy XB4gx/gmA4nyDGo+Xa7uR0755heULal2/34JRknMlZ7xoZ64JRGKX+nUZF/ImqjJUZVhIeF/yU6t/1 Xd37LSKqeHB2IzawbJyfM2oc6fgHkwq/5HOpDnNCAgGt3uqKYVzfVbUImGXMYDEwJ10alrylZjlbnu Rs1uRDHsnEtNszONW9ECvAe2Ru2bgZ 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-20221103_110714_316703_98D7BEA1 X-CRM114-Status: GOOD ( 23.53 ) 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 --- We currently don't have any users for this that are currently candidates for merging but there's people actively looking at SVE and they're all just using kernel_neon_begin() so it seems useful to at least get a patch on the list they can be pointed at even if it doesn't get merged. arch/arm64/include/asm/fpsimd.h | 7 +++++ arch/arm64/kernel/fpsimd.c | 45 +++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/arch/arm64/include/asm/fpsimd.h b/arch/arm64/include/asm/fpsimd.h index 6f86b7ab6c28..d4045fb73483 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 23834d96d1e7..73e4ab835423 100644 --- a/arch/arm64/kernel/fpsimd.c +++ b/arch/arm64/kernel/fpsimd.c @@ -1858,6 +1858,51 @@ void kernel_neon_end(void) } EXPORT_SYMBOL(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); + + if (system_supports_sve() && (flags & KERNEL_FP_SME)) + sme_set_vq(sve_vq_from_vl(sme_max_vl()) - 1); +} +EXPORT_SYMBOL(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(kernel_fp_end); + #ifdef CONFIG_EFI static DEFINE_PER_CPU(struct user_fpsimd_state, efi_fpsimd_state); -- 2.30.2 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel