From a96cfb7228d6ac67de45d626c8bbd03434201fb8 Mon Sep 17 00:00:00 2001 From: Joergen Lundman Date: Tue, 11 Apr 2023 14:34:52 +0900 Subject: [PATCH] Fix blake3 on macOS/arm64 BLAKE3_CTX *ctx = blake3_per_cpu_ctx[CPU_SEQID_UNSTABLE]; We have macOS arm64 to call kmem_alloc() as the cpu_number() changes quite frequently, and would reuse an already active ctx. If in future we want to avoid kmem_alloc, we can use the blake3_per_cpu_ctx[CPU_SEQID_UNSTABLE] but check if it is busy, and move to the next free slot. Easily implemented with CAS. Signed-off-by: Jorgen Lundman --- module/zfs/blake3_zfs.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/module/zfs/blake3_zfs.c b/module/zfs/blake3_zfs.c index 7783282b671a..50924534695b 100644 --- a/module/zfs/blake3_zfs.c +++ b/module/zfs/blake3_zfs.c @@ -49,7 +49,7 @@ abd_checksum_blake3_native(abd_t *abd, uint64_t size, const void *ctx_template, { ASSERT(ctx_template != NULL); -#if defined(_KERNEL) +#if defined(_KERNEL) && !(defined(__APPLE__) && defined(__aarch64__)) kpreempt_disable(); BLAKE3_CTX *ctx = blake3_per_cpu_ctx[CPU_SEQID]; #else @@ -60,7 +60,8 @@ abd_checksum_blake3_native(abd_t *abd, uint64_t size, const void *ctx_template, (void) abd_iterate_func(abd, 0, size, blake3_incremental, ctx); Blake3_Final(ctx, (uint8_t *)zcp); -#if defined(_KERNEL) +#if defined(_KERNEL) && !(defined(__APPLE__) && defined(__aarch64__)) + /* To keep conditionals the same */ kpreempt_enable(); #else memset(ctx, 0, sizeof (*ctx));