From patchwork Thu Oct 21 18:07:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 12576073 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EF6E1C433F5 for ; Thu, 21 Oct 2021 18:09:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D600361B1F for ; Thu, 21 Oct 2021 18:09:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232422AbhJUSLb (ORCPT ); Thu, 21 Oct 2021 14:11:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:56838 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232381AbhJUSLb (ORCPT ); Thu, 21 Oct 2021 14:11:31 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6F09F61B02; Thu, 21 Oct 2021 18:09:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1634839755; bh=9qDWgiu5vJ3aJ/SkyuYiO231kDNUJDdP3sBILOMUncg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eL8/+el/unUzhurn9PyCJI4hRuiOgcLy5EsvUgpcLu1bZb9tgP2Mr0KYY+dcmLu3a 6lYP4TkLvJlYpxfox6NRvq0JJfY4DSZBZSNo35eYwljv/Evn1eTPHep0HoFTE19vzw tAa+vFplKjuMKrDVO2clrzd4eHx8g9f9bH7EhUnqUTx3BcGf9s7yLUnFYo1WQI34mH npRSQ3bTeS/q7V7d3DbbM7PDsZerjkMCFXrps6glDz+DWwpCIyizlfNxurKx5xdgrf dCI2gGxHH7Y/NfLL/Ah49WYK9jHQViEuQhRm2GRJITRbd/ahNEL3ja1UfJb9ByCwhd 5Y+TwVmV5re+g== From: Mark Brown To: Catalin Marinas , Will Deacon , Shuah Khan , Shuah Khan Cc: Alan Hayward , Luis Machado , Salil Akerkar , Basant Kumar Dwivedi , Szabolcs Nagy , linux-arm-kernel@lists.infradead.org, linux-kselftest@vger.kernel.org, Mark Brown Subject: [PATCH v4 24/33] arm64/sme: Save and restore streaming mode over EFI runtime calls Date: Thu, 21 Oct 2021 19:07:13 +0100 Message-Id: <20211021180722.3699248-25-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211021180722.3699248-1-broonie@kernel.org> References: <20211021180722.3699248-1-broonie@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3623; h=from:subject; bh=9qDWgiu5vJ3aJ/SkyuYiO231kDNUJDdP3sBILOMUncg=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBhcaxR6X08PDr9+9Kwl7X6H191zd1p/UaU+SrmnSQ5 hWnHV6mJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCYXGsUQAKCRAk1otyXVSH0GydB/ 9ZZYMV6/74FyhHoOz9UQUKS2TEFCaoOWAVHDS45mUwMs//ctc7/l2cvgON2aczhTRfijlezEN+zUy7 JDwtYFm8klfjc0WbZLpVHI3Swh7tRJuLhDQtdqCqTp271MET2FSxI6FFJg58bRKCzChO2QaAlk76wi yjxpwtvLonoghlP2dq4ARiqhi+33CzzIXpkux4B5uIeyz6+/Ym92l8K01adknQfxPLtUdNXYg/hn8N 92/ge7/OXCvfBj3ubHX6fcNMD0J+EGaTTXk26UKaKvttz+zwxhTfCV6ad4zqeSBM8/k0yl69M20zVN I/zkY2wa6FeCh+UcTovYRNAeRVhNem X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org When saving and restoring the floating point state over an EFI runtime call ensure that we handle streaming mode, only handling FFR if we are not in streaming mode and ensuring that we are in normal mode over the call into runtime services. We currently assume that ZA will not be modified by runtime services, the specification is not yet finalised so this may need updating if that changes. Signed-off-by: Mark Brown --- arch/arm64/kernel/fpsimd.c | 47 +++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/arch/arm64/kernel/fpsimd.c b/arch/arm64/kernel/fpsimd.c index cdbc1fd8fde2..242afb78b000 100644 --- a/arch/arm64/kernel/fpsimd.c +++ b/arch/arm64/kernel/fpsimd.c @@ -1046,21 +1046,25 @@ int vec_verify_vq_map(enum vec_type type) static void __init sve_efi_setup(void) { - struct vl_info *info = &vl_info[ARM64_VEC_SVE]; + int max_vl = 0; + int i; if (!IS_ENABLED(CONFIG_EFI)) return; + for (i = 0; i < ARRAY_SIZE(vl_info); i++) + max_vl = max(vl_info[i].max_vl, max_vl); + /* * alloc_percpu() warns and prints a backtrace if this goes wrong. * This is evidence of a crippled system and we are returning void, * so no attempt is made to handle this situation here. */ - if (!sve_vl_valid(info->max_vl)) + if (!sve_vl_valid(max_vl)) goto fail; efi_sve_state = __alloc_percpu( - SVE_SIG_REGS_SIZE(sve_vq_from_vl(info->max_vl)), SVE_VQ_BYTES); + SVE_SIG_REGS_SIZE(sve_vq_from_vl(max_vl)), SVE_VQ_BYTES); if (!efi_sve_state) goto fail; @@ -1830,6 +1834,7 @@ EXPORT_SYMBOL(kernel_neon_end); static DEFINE_PER_CPU(struct user_fpsimd_state, efi_fpsimd_state); static DEFINE_PER_CPU(bool, efi_fpsimd_state_used); static DEFINE_PER_CPU(bool, efi_sve_state_used); +static DEFINE_PER_CPU(bool, efi_sm_state); /* * EFI runtime services support functions @@ -1864,12 +1869,28 @@ void __efi_fpsimd_begin(void) */ if (system_supports_sve() && likely(efi_sve_state)) { char *sve_state = this_cpu_ptr(efi_sve_state); + bool ffr = true; + u64 svcr; __this_cpu_write(efi_sve_state_used, true); + /* If we are in streaming mode don't touch FFR */ + if (system_supports_sme()) { + svcr = read_sysreg_s(SYS_SVCR_EL0); + + ffr = svcr & SYS_SVCR_EL0_SM_MASK; + + __this_cpu_write(efi_sm_state, ffr); + } + sve_save_state(sve_state + sve_ffr_offset(sve_max_vl()), &this_cpu_ptr(&efi_fpsimd_state)->fpsr, - true); + ffr); + + if (system_supports_sme()) + sysreg_clear_set_s(SYS_SVCR_EL0, + SYS_SVCR_EL0_SM_MASK, 0); + } else { fpsimd_save_state(this_cpu_ptr(&efi_fpsimd_state)); } @@ -1892,11 +1913,25 @@ void __efi_fpsimd_end(void) if (system_supports_sve() && likely(__this_cpu_read(efi_sve_state_used))) { char const *sve_state = this_cpu_ptr(efi_sve_state); + bool ffr = true; + + /* + * Restore streaming mode; EFI calls are + * normal function calls so should not return in + * streaming mode. + */ + if (system_supports_sme()) { + if (__this_cpu_read(efi_sm_state)) { + sysreg_clear_set_s(SYS_SVCR_EL0, + 0, + SYS_SVCR_EL0_SM_MASK); + ffr = false; + } + } - sve_set_vq(sve_vq_from_vl(sve_get_vl()) - 1); sve_load_state(sve_state + sve_ffr_offset(sve_max_vl()), &this_cpu_ptr(&efi_fpsimd_state)->fpsr, - true); + ffr); __this_cpu_write(efi_sve_state_used, false); } else {