Skip to content

Commit 222ef5b

Browse files
committed
Vectorized fletcher_4 must be 64-bit aligned
The fletcher_4_native() and fletcher_4_byteswap() functions may only safely use the vectorized implementations when the buffer is 64-bit aligned. Otherwise fallback to the scalar implementation. Signed-off-by: Brian Behlendorf <[email protected]> Issue #4330
1 parent d1d19c7 commit 222ef5b

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

module/zcommon/zfs_fletcher.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,12 @@ fletcher_4_impl_get(void)
334334
void
335335
fletcher_4_native(const void *buf, uint64_t size, zio_cksum_t *zcp)
336336
{
337-
const fletcher_4_ops_t *ops = fletcher_4_impl_get();
337+
const fletcher_4_ops_t *ops;
338+
339+
if (IS_P2ALIGNED(size, sizeof (uint64_t)))
340+
ops = fletcher_4_impl_get();
341+
else
342+
ops = &fletcher_4_scalar_ops;
338343

339344
ops->init(zcp);
340345
ops->compute(buf, size, zcp);
@@ -345,7 +350,12 @@ fletcher_4_native(const void *buf, uint64_t size, zio_cksum_t *zcp)
345350
void
346351
fletcher_4_byteswap(const void *buf, uint64_t size, zio_cksum_t *zcp)
347352
{
348-
const fletcher_4_ops_t *ops = fletcher_4_impl_get();
353+
const fletcher_4_ops_t *ops;
354+
355+
if (IS_P2ALIGNED(size, sizeof (uint64_t)))
356+
ops = fletcher_4_impl_get();
357+
else
358+
ops = &fletcher_4_scalar_ops;
349359

350360
ops->init(zcp);
351361
ops->compute_byteswap(buf, size, zcp);

0 commit comments

Comments
 (0)