Linux 5.16 compat: don't use XSTATE_XSAVE to save FPU state

Linux 5.16 moved XSTATE_XSAVE and XSTATE_XRESTORE out of our reach,
so add our own XSAVE{,OPT,S} code and use it for Linux 5.16.

Please note that this differs from previous behavior in that it
won't handle exceptions created by XSAVE an XRSTOR. This is sensible
for three reasons.

 - Exceptions during XSAVE and XRSTOR can only occur if the feature
   is not supported or enabled or the memory operand isn't aligned
   on a 64 byte boundary. If this happens something else went
   terribly wrong, and it may be better to stop execution.

 - Previously we just printed a warning and didn't handle the fault,
   this is arguable for the above reason.

 - All other *SAVE instruction also don't handle exceptions, so this
   at least aligns behavior.

Finally add a test to catch such a regression in the future.

Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Attila Fülöp <attila@fueloep.org>
Closes #13042
Closes #13059
This commit is contained in:
Attila Fülöp
2022-02-09 21:50:10 +01:00
committed by GitHub
parent e2909fae8f
commit 8e94ac0e36
9 changed files with 300 additions and 6 deletions
@@ -89,5 +89,6 @@ SUBDIRS = \
if BUILD_LINUX
SUBDIRS += \
simd \
tmpfile
endif
@@ -0,0 +1,2 @@
pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/simd
dist_pkgdata_SCRIPTS = simd_supported.ksh
+58
View File
@@ -0,0 +1,58 @@
#!/bin/ksh -p
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright (c) 2022 by Attila Fülöp <attila@fueloep.org>
#
. $STF_SUITE/include/libtest.shlib
#
# DESCRIPTION:
# Make sure we have SIMD support, so it will not go away without notice
#
# STRATEGY:
# 1. Test if we are running on a Linux x86 system with SSE support
# 2. If so, check if the zfs_fletcher_4_impl module parameter contains
# a sse implementation
# 3. If not fail the test, otherwise pass it
log_note "Testing if we support SIMD instructions (Linux x86 only)"
if !is_linux; then
log_unsupported "Not a Linux System"
fi
case "$(uname -m)" in
i386|i686|x86_64)
typeset -R modparam="/sys/module/zcommon/parameters/zfs_fletcher_4_impl"
if cat /proc/cpuinfo | awk '/^flags/ {print; exit;}' | grep -q sse; then
log_must grep -q sse "$modparam"
log_pass "SIMD instructions supported"
else
log_unsupported "No FPU present"
fi
;;
*)
log_unsupported "Not a x86 CPU"
;;
esac