]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
lib/crc-t10dif: add support for arch overrides
authorEric Biggers <ebiggers@google.com>
Mon, 2 Dec 2024 01:20:46 +0000 (17:20 -0800)
committerEric Biggers <ebiggers@google.com>
Mon, 2 Dec 2024 01:23:13 +0000 (17:23 -0800)
Following what was done for CRC32, add support for architecture-specific
override of the CRC-T10DIF library.  This will allow the CRC-T10DIF
library functions to access architecture-optimized code directly.

Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
Link: https://lore.kernel.org/r/20241202012056.209768-3-ebiggers@kernel.org
Signed-off-by: Eric Biggers <ebiggers@google.com>
include/linux/crc-t10dif.h
lib/Kconfig

index 206ba2305483e8e4faaf56ec1aa506d8a1353cc0..16787c1cee21c65588dad2e7508065a400ee1b76 100644 (file)
@@ -7,10 +7,13 @@
 #define CRC_T10DIF_DIGEST_SIZE 2
 #define CRC_T10DIF_BLOCK_SIZE 1
 
+u16 crc_t10dif_arch(u16 crc, const u8 *p, size_t len);
 u16 crc_t10dif_generic(u16 crc, const u8 *p, size_t len);
 
 static inline u16 crc_t10dif_update(u16 crc, const u8 *p, size_t len)
 {
+       if (IS_ENABLED(CONFIG_CRC_T10DIF_ARCH))
+               return crc_t10dif_arch(crc, p, len);
        return crc_t10dif_generic(crc, p, len);
 }
 
@@ -19,4 +22,13 @@ static inline u16 crc_t10dif(const u8 *p, size_t len)
        return crc_t10dif_update(0, p, len);
 }
 
+#if IS_ENABLED(CONFIG_CRC_T10DIF_ARCH)
+bool crc_t10dif_is_optimized(void);
+#else
+static inline bool crc_t10dif_is_optimized(void)
+{
+       return false;
+}
+#endif
+
 #endif
index be59f7cdf44898613aac6051e04816c77dfae3be..e52a38d8d783f58ef7f440ce767054353921f339 100644 (file)
@@ -161,6 +161,38 @@ config CRC_T10DIF
          kernel tree needs to calculate CRC checks for use with the
          SCSI data integrity subsystem.
 
+config ARCH_HAS_CRC_T10DIF
+       bool
+
+choice
+       prompt "CRC-T10DIF implementation"
+       depends on CRC_T10DIF
+       default CRC_T10DIF_IMPL_ARCH if ARCH_HAS_CRC_T10DIF
+       default CRC_T10DIF_IMPL_GENERIC if !ARCH_HAS_CRC_T10DIF
+       help
+         This option allows you to override the default choice of CRC-T10DIF
+         implementation.
+
+config CRC_T10DIF_IMPL_ARCH
+       bool "Architecture-optimized" if ARCH_HAS_CRC_T10DIF
+       help
+         Use the optimized implementation of CRC-T10DIF for the selected
+         architecture.  It is recommended to keep this enabled, as it can
+         greatly improve CRC-T10DIF performance.
+
+config CRC_T10DIF_IMPL_GENERIC
+       bool "Generic implementation"
+       help
+         Use the generic table-based implementation of CRC-T10DIF.  Selecting
+         this will reduce code size slightly but can greatly reduce CRC-T10DIF
+         performance.
+
+endchoice
+
+config CRC_T10DIF_ARCH
+       tristate
+       default CRC_T10DIF if CRC_T10DIF_IMPL_ARCH
+
 config CRC64_ROCKSOFT
        tristate "CRC calculation for the Rocksoft model CRC64"
        select CRC64