Skip to content

Commit

Permalink
Fix blake3 on macOS/arm64
Browse files Browse the repository at this point in the history
    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 <[email protected]>
  • Loading branch information
lundman committed Oct 20, 2023
1 parent 802749c commit abcf9d3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion module/icp/algs/blake3/blake3_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ blake3_param(ZFS_MODULE_PARAM_ARGS)
int err;

generic_impl_init();
if ((void *)req->newptr == NULL) {
if ((const void *)req->newptr == NULL) {
const uint32_t impl = IMPL_READ(generic_impl_chosen);
const int init_buflen = 64;
const char *fmt;
Expand Down
5 changes: 3 additions & 2 deletions module/zfs/blake3_zfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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));
Expand Down

0 comments on commit abcf9d3

Please sign in to comment.