Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

lib/crc32: expose whether the lib is really optimized at runtime

Make the CRC32 library export a function crc32_optimizations() which
returns flags that indicate which CRC32 functions are actually executing
optimized code at runtime.

This will be used to determine whether the crc32[c]-$arch shash
algorithms should be registered in the crypto API. btrfs could also
start using these flags instead of the hack that it currently uses where
it parses the crypto_shash_driver_name.

Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
Link: https://lore.kernel.org/r/20241202010844.144356-4-ebiggers@kernel.org
Signed-off-by: Eric Biggers <ebiggers@google.com>

+35
+10
arch/arm64/lib/crc32-glue.c
··· 85 85 } 86 86 EXPORT_SYMBOL(crc32_be_arch); 87 87 88 + u32 crc32_optimizations(void) 89 + { 90 + if (alternative_has_cap_likely(ARM64_HAS_CRC32)) 91 + return CRC32_LE_OPTIMIZATION | 92 + CRC32_BE_OPTIMIZATION | 93 + CRC32C_OPTIMIZATION; 94 + return 0; 95 + } 96 + EXPORT_SYMBOL(crc32_optimizations); 97 + 88 98 MODULE_LICENSE("GPL"); 89 99 MODULE_DESCRIPTION("arm64-optimized CRC32 functions");
+10
arch/riscv/lib/crc32-riscv.c
··· 297 297 } 298 298 EXPORT_SYMBOL(crc32_be_arch); 299 299 300 + u32 crc32_optimizations(void) 301 + { 302 + if (riscv_has_extension_likely(RISCV_ISA_EXT_ZBC)) 303 + return CRC32_LE_OPTIMIZATION | 304 + CRC32_BE_OPTIMIZATION | 305 + CRC32C_OPTIMIZATION; 306 + return 0; 307 + } 308 + EXPORT_SYMBOL(crc32_optimizations); 309 + 300 310 MODULE_LICENSE("GPL"); 301 311 MODULE_DESCRIPTION("Accelerated CRC32 implementation with Zbc extension");
+15
include/linux/crc32.h
··· 37 37 return crc32c_le_base(crc, p, len); 38 38 } 39 39 40 + /* 41 + * crc32_optimizations() returns flags that indicate which CRC32 library 42 + * functions are using architecture-specific optimizations. Unlike 43 + * IS_ENABLED(CONFIG_CRC32_ARCH) it takes into account the different CRC32 44 + * variants and also whether any needed CPU features are available at runtime. 45 + */ 46 + #define CRC32_LE_OPTIMIZATION BIT(0) /* crc32_le() is optimized */ 47 + #define CRC32_BE_OPTIMIZATION BIT(1) /* crc32_be() is optimized */ 48 + #define CRC32C_OPTIMIZATION BIT(2) /* __crc32c_le() is optimized */ 49 + #if IS_ENABLED(CONFIG_CRC32_ARCH) 50 + u32 crc32_optimizations(void); 51 + #else 52 + static inline u32 crc32_optimizations(void) { return 0; } 53 + #endif 54 + 40 55 /** 41 56 * crc32_le_combine - Combine two crc32 check values into one. For two 42 57 * sequences of bytes, seq1 and seq2 with lengths len1