Re: git: 2a58b312b62f - main - zfs: merge openzfs/zfs@431083f75

From: Kyle Evans <kevans_at_freebsd.org>
Date: Tue, 04 Apr 2023 06:25:39 UTC
On Mon, Apr 3, 2023 at 10:13 AM Martin Matuska <mm@freebsd.org> wrote:
>
> The branch main has been updated by mm:
>
> URL: https://cgit.FreeBSD.org/src/commit/?id=2a58b312b62f908ec92311d1bd8536dbaeb8e55b
>
> commit 2a58b312b62f908ec92311d1bd8536dbaeb8e55b
> Merge: b98fbf3781df 431083f75bdd
> Author:     Martin Matuska <mm@FreeBSD.org>
> AuthorDate: 2023-04-03 14:49:30 +0000
> Commit:     Martin Matuska <mm@FreeBSD.org>
> CommitDate: 2023-04-03 14:49:30 +0000
>
>     zfs: merge openzfs/zfs@431083f75
>
>     Notable upstream pull request merges:
> [... snip ...]
>       #13741 SHA2 reworking and API for iterating over multiple implementations
> [... snip ...]

This one broke ZFS on aarch64, because kfpu_* are basically stubbed
out but should be using fpu_kern(9). I tried the below patch
(https://people.freebsd.org/~kevans/zfs-vfp.diff), but it doesn't
work. It seems to take a data abort while trying to fetch curthread in
kfpu_end() specifically in blake2. It looks like the blake2
implementation is probably clobbering x18, so pcpup is completely
bogus and it goes downhill from there. It's late and I don't know
off-hand how to cope with that, maybe Andy will have a better idea.

Thanks,

Kyle Evans

--- a/sys/contrib/openzfs/include/os/freebsd/spl/sys/simd_aarch64.h
+++ b/sys/contrib/openzfs/include/os/freebsd/spl/sys/simd_aarch64.h
@@ -44,13 +44,23 @@
 #define _FREEBSD_SIMD_AARCH64_H

 #include <sys/types.h>
+#include <sys/ucontext.h>
 #include <machine/elf.h>
+#include <machine/fpu.h>
 #include <machine/md_var.h>
+#include <machine/pcb.h>

 #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)