From d0cbd9feaf5b82130f2e679256c71e0c7413aae9 Mon Sep 17 00:00:00 2001 From: Kyle Evans Date: Fri, 7 Apr 2023 00:40:34 +0000 Subject: [PATCH] module: freebsd: fix aarch64 fpu handling Just like x86, aarch64 needs to use the fpu_kern(9) API around FPU usage, otherwise we panic promptly at boot as soon as ZFS attempts to do checksum benchmarking. Reviewed-by: Richard Yao Reviewed-by: Brian Behlendorf Reviewed-by: Tino Reichardt Signed-off-by: Kyle Evans Closes #14715 --- include/os/freebsd/spl/sys/simd_aarch64.h | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/include/os/freebsd/spl/sys/simd_aarch64.h b/include/os/freebsd/spl/sys/simd_aarch64.h index df33bdaecc..234f401db7 100644 --- a/include/os/freebsd/spl/sys/simd_aarch64.h +++ b/include/os/freebsd/spl/sys/simd_aarch64.h @@ -44,13 +44,23 @@ #define _FREEBSD_SIMD_AARCH64_H #include +#include #include +#include #include +#include #define kfpu_allowed() 1 #define kfpu_initialize(tsk) do {} while (0) -#define kfpu_begin() do {} while (0) -#define kfpu_end() do {} while (0) +#define kfpu_begin() do { \ + if (__predict_false(!is_fpu_kern_thread(0))) \ + fpu_kern_enter(curthread, NULL, FPU_KERN_NOCTX); \ +} while (0) + +#define kfpu_end() do { \ + if (__predict_false(curthread->td_pcb->pcb_fpflags & PCB_FP_NOSAVE)) \ + fpu_kern_leave(curthread, NULL); \ +} while (0) #define kfpu_init() (0) #define kfpu_fini() do {} while (0)