Skip to content

Conversation

@pwnall
Copy link
Member

@pwnall pwnall commented Sep 11, 2017

The hardware-accelerated CRC32C implementation that takes advantage of ARM64 instructions is currently runtime-gated on hwcap() returning a value that has the HWCAP_CRC32 flag set. This covers the __crc32c{b,h,w,d} intrinsics, but does not cover the vmull_p64 call. The later should be gated on the presence of the HWCAP_PMULL flag.

This is a speculative fix for Chrome crashes observed at the first vmull_64 callsite on MSM8916-based boards.

@pwnall
Copy link
Member Author

pwnall commented Sep 11, 2017

I tested that the accelerated version is still used on my Pixel C, which does have the pmull capability. I haven't tested that the version is not used on a board without pmull.

inline bool CanUseArm64Linux() {
#if defined(HAVE_STRONG_GETAUXVAL) || defined(HAVE_WEAK_GETAUXVAL)
// From 'arch/arm64/include/uapi/asm/hwcap.h' in Linux kernel source code.
constexpr unsigned long kHwCapPmull = 1 << 4;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very minor nit, but I think the standard (maybe just Android) constant names are HWCAP_PMULL and HWCAP_CRC32. What about adopting a constant naming convention similar to those? Maybe kHWCAP_PMULL and kHWCAP_CRC32?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Thank you! This was bothering me, but I didn't know a good way out. I really like your suggestion!

The hardware-accelerated CRC32C implementation that takes advantage of
ARM64 instructions is currently runtime-gated on hwcap() returning a
value that has the HWCAP_CRC32 flag set. This covers the
__crc32c{b,h,w,d} intrinsics, but does not cover the vmull_p64 call. The
later should be gated on the presence of the HWCAP_PMULL flag.

This is a speculative fix for Chrome crashes observed at the first
vmull_64 callsite on MSM8916-based boards.
@zorrorffm
Copy link

@pwnall Yes, your fix is correct. Crypto instructions including pmull are optional for armv8 core, we should detect cpu capabilities before using crypto instructions. For this crc32c implementation, crc32 and pmull capabilities should be detected by AT_HWCAP flag set. Also I will modify corresponding patch in leveldb, thank you for your findings

@cmumford cmumford merged commit 9bc7a0c into master Sep 12, 2017
@pwnall pwnall deleted the pmull branch September 12, 2017 19:40
sitsofe added a commit to sitsofe/fio that referenced this pull request Dec 6, 2021
Issue axboe#1239 shows a crash on a FUJITSU/A64FX ARM platform at the
following line:

crc/crc32c-arm64.c:
 64                 t1 = (uint64_t)vmull_p64(crc1, k2);

On armv8 PMULL crypto instructions like vmull_p64 are defined as
optional (see
google/crc32c#6 (comment) and
dotnet/runtime#35143 (comment) ).

Avoid the crash by gating use of the hardware accelerated ARM crc32c
path behind runtime detection of PMULL.

Fixes: axboe#1239

Signed-off-by: Sitsofe Wheeler <[email protected]>
Tested-by: Yi Zhang <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants