Fix memory allocation issue for BLAKE3 context

The kmem_alloc(sizeof (*ctx), KM_NOSLEEP) call on FreeBSD can't be
used in this code segment. Work around this by pre-allocating a percpu
context array for later use.

Reviewed-by: Ryan Moeller <ryan@iXsystems.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Tino Reichardt <milky-zfs@mcmilk.de>
Closes #13568
This commit is contained in:
Tino Reichardt
2022-06-21 23:32:09 +02:00
committed by GitHub
parent b17663f571
commit deb1213098
4 changed files with 48 additions and 4 deletions
+8 -4
View File
@@ -47,18 +47,22 @@ void
abd_checksum_blake3_native(abd_t *abd, uint64_t size, const void *ctx_template,
zio_cksum_t *zcp)
{
BLAKE3_CTX *ctx;
ctx = kmem_alloc(sizeof (*ctx), KM_NOSLEEP);
ASSERT(ctx != 0);
ASSERT(ctx_template != 0);
#if defined(_KERNEL)
BLAKE3_CTX *ctx = blake3_per_cpu_ctx[CPU_SEQID_UNSTABLE];
#else
BLAKE3_CTX *ctx = kmem_alloc(sizeof (*ctx), KM_SLEEP);
#endif
memcpy(ctx, ctx_template, sizeof (*ctx));
(void) abd_iterate_func(abd, 0, size, blake3_incremental, ctx);
Blake3_Final(ctx, (uint8_t *)zcp);
#if !defined(_KERNEL)
memset(ctx, 0, sizeof (*ctx));
kmem_free(ctx, sizeof (*ctx));
#endif
}
/*
+7
View File
@@ -277,6 +277,9 @@ chksum_benchmark(void)
void
chksum_init(void)
{
#ifdef _KERNEL
blake3_per_cpu_ctx_init();
#endif
/* Benchmark supported implementations */
chksum_benchmark();
@@ -313,4 +316,8 @@ chksum_fini(void)
chksum_stat_cnt = 0;
chksum_stat_data = 0;
}
#ifdef _KERNEL
blake3_per_cpu_ctx_fini();
#endif
}