diff --git a/config/toolchain-simd.m4 b/config/toolchain-simd.m4 index 061576fd94..4ccccc2e3e 100644 --- a/config/toolchain-simd.m4 +++ b/config/toolchain-simd.m4 @@ -27,6 +27,7 @@ AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_TOOLCHAIN_SIMD], [ ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_XSAVE ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_XSAVEOPT ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_XSAVES + ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_XSAVEC ;; esac ]) @@ -488,3 +489,24 @@ AC_DEFUN([ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_XSAVES], [ AC_MSG_RESULT([no]) ]) ]) + +dnl # +dnl # ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_XSAVEC +dnl # +AC_DEFUN([ZFS_AC_CONFIG_TOOLCHAIN_CAN_BUILD_XSAVEC], [ + AC_MSG_CHECKING([whether host toolchain supports XSAVEC]) + + AC_LINK_IFELSE([AC_LANG_SOURCE([ + [ + void main() + { + char b[4096] __attribute__ ((aligned (64))); + __asm__ __volatile__("xsavec %[b]\n" : : [b] "m" (*b) : "memory"); + } + ]])], [ + AC_MSG_RESULT([yes]) + AC_DEFINE([HAVE_XSAVEC], 1, [Define if host toolchain supports XSAVEC]) + ], [ + AC_MSG_RESULT([no]) + ]) +]) diff --git a/include/os/linux/kernel/linux/simd_x86.h b/include/os/linux/kernel/linux/simd_x86.h index 699b8a5718..633046b0c1 100644 --- a/include/os/linux/kernel/linux/simd_x86.h +++ b/include/os/linux/kernel/linux/simd_x86.h @@ -322,6 +322,12 @@ kfpu_begin(void) * FPU state to be correctly preserved and restored. */ uint8_t *state = zfs_kfpu_fpregs[smp_processor_id()]; +#if defined(HAVE_XSAVEC) + if (static_cpu_has(X86_FEATURE_XSAVEC)) { + kfpu_do_xsave("xsavec", state, ~0); + return; + } +#endif #if defined(HAVE_XSAVES) if (static_cpu_has(X86_FEATURE_XSAVES)) { kfpu_do_xsave("xsaves", state, ~XFEATURE_MASK_XTILE); @@ -383,6 +389,13 @@ static inline void kfpu_end(void) { uint8_t *state = zfs_kfpu_fpregs[smp_processor_id()]; + +#if defined(HAVE_XSAVEC) + if (static_cpu_has(X86_FEATURE_XSAVEC)) { + kfpu_do_xrstor("xrstor", state, ~0); + goto out; + } +#endif #if defined(HAVE_XSAVES) if (static_cpu_has(X86_FEATURE_XSAVES)) { kfpu_do_xrstor("xrstors", state, ~XFEATURE_MASK_XTILE);