Skip to content

Commit c69520c

Browse files
mysqlonarmdr-m
authored andcommitted
MDEV-23030: ARM crash on Raspberry Pi 4
MariaDB adopted a hardware optimized crc32c approach on ARM64 starting 10.5. Said implementation of crc32c needs support from target hardware for crc32 and pmull instructions. Existing logic is checking only for crc32 support from target hardware through a runtime check and so if target hardware doesn't support pmull it would cause things to fail/crash. Expanded runtime check to ensure pmull support is also checked on the target hardware along with existing crc32. Thanks to Marko and Daniel for review.
1 parent f99de89 commit c69520c

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

include/my_sys.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -911,6 +911,9 @@ extern MYSQL_PLUGIN_IMPORT my_crc32_t my_checksum;
911911

912912
#if defined(__GNUC__) && defined(HAVE_ARMV8_CRC)
913913
int crc32_aarch64_available(void);
914+
#if defined(HAVE_ARMV8_CRYPTO)
915+
int crc32c_aarch64_available(void);
916+
#endif
914917
#endif
915918

916919
#ifdef DBUG_ASSERT_EXISTS

mysys/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ ELSEIF(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|AARCH64")
9090
__asm__(\"pmull v2.1q, v2.1d, v1.1d\");
9191
return ret;
9292
}
93-
int main() { foo(0); }" HAVE_ARMV8_CRYPTO)
93+
#include <sys/auxv.h>
94+
int main() { foo(0); getauxval(AT_HWCAP); }" HAVE_ARMV8_CRYPTO)
9495

9596
CHECK_C_COMPILER_FLAG(-march=armv8-a+crc+crypto HAVE_ARMV8_CRC_CRYPTO_INTRINSICS)
9697
IF(HAVE_ARMV8_CRC_CRYPTO_INTRINSICS)

mysys/crc32/crc32_arm64.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,21 @@ int crc32_aarch64_available(void)
1818
unsigned long auxv= getauxval(AT_HWCAP);
1919
return (auxv & HWCAP_CRC32) != 0;
2020
}
21+
22+
#if defined(HAVE_ARMV8_CRYPTO)
23+
24+
#ifndef HWCAP_PMULL
25+
#define HWCAP_PMULL (1 << 4)
2126
#endif
2227

28+
/* Check if target ARM machine support crc32 + pmull for computing crc32c */
29+
int crc32c_aarch64_available(void)
30+
{
31+
return !(~getauxval(AT_HWCAP) & (HWCAP_CRC32 | HWCAP_PMULL));
32+
}
33+
#endif /* HAVE_ARMV8_CRYPTO */
34+
#endif /* HAVE_ARMV8_CRC */
35+
2336
#ifndef HAVE_ARMV8_CRC_CRYPTO_INTRINSICS
2437

2538
/* Request crc extension capabilities from the assembler */

storage/innobase/ut/ut0crc32.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,11 +342,11 @@ allocations, would not hurt if called twice, but would be pointless. */
342342
void ut_crc32_init()
343343
{
344344
#ifndef HAVE_CRC32_VPMSUM
345-
# if defined(__GNUC__) && defined(HAVE_ARMV8_CRC)
346-
if (crc32_aarch64_available())
345+
# if defined(__GNUC__) && defined(HAVE_ARMV8_CRC) && defined(HAVE_ARMV8_CRYPTO)
346+
if (crc32c_aarch64_available())
347347
{
348348
ut_crc32_low= crc32c_aarch64;
349-
ut_crc32_implementation= "Using ARMv8 crc32 instructions";
349+
ut_crc32_implementation= "Using ARMv8 crc32 + pmull instructions";
350350
return;
351351
}
352352
# elif defined(TRY_SSE4_2)

0 commit comments

Comments
 (0)