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

ext4: switch to using the crc32c library

Now that the crc32c() library function directly takes advantage of
architecture-specific optimizations, it is unnecessary to go through the
crypto API. Just use crc32c(). This is much simpler, and it improves
performance due to eliminating the crypto API overhead.

Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Acked-by: Theodore Ts'o <tytso@mit.edu>
Link: https://lore.kernel.org/r/20241202010844.144356-17-ebiggers@kernel.org
Signed-off-by: Eric Biggers <ebiggers@google.com>

+4 -39
+1 -2
fs/ext4/Kconfig
··· 31 31 select BUFFER_HEAD 32 32 select JBD2 33 33 select CRC16 34 - select CRYPTO 35 - select CRYPTO_CRC32C 34 + select CRC32 36 35 select FS_IOMAP 37 36 select FS_ENCRYPTION_ALGS if FS_ENCRYPTION 38 37 help
+3 -22
fs/ext4/ext4.h
··· 33 33 #include <linux/blockgroup_lock.h> 34 34 #include <linux/percpu_counter.h> 35 35 #include <linux/ratelimit.h> 36 - #include <crypto/hash.h> 36 + #include <linux/crc32c.h> 37 37 #include <linux/falloc.h> 38 38 #include <linux/percpu-rwsem.h> 39 39 #include <linux/fiemap.h> ··· 1662 1662 /* record the last minlen when FITRIM is called. */ 1663 1663 unsigned long s_last_trim_minblks; 1664 1664 1665 - /* Reference to checksum algorithm driver via cryptoapi */ 1666 - struct crypto_shash *s_chksum_driver; 1667 - 1668 1665 /* Precomputed FS UUID checksum for seeding other checksums */ 1669 1666 __u32 s_csum_seed; 1670 1667 ··· 2460 2463 static inline u32 ext4_chksum(struct ext4_sb_info *sbi, u32 crc, 2461 2464 const void *address, unsigned int length) 2462 2465 { 2463 - struct { 2464 - struct shash_desc shash; 2465 - char ctx[4]; 2466 - } desc; 2467 - 2468 - BUG_ON(crypto_shash_descsize(sbi->s_chksum_driver)!=sizeof(desc.ctx)); 2469 - 2470 - desc.shash.tfm = sbi->s_chksum_driver; 2471 - *(u32 *)desc.ctx = crc; 2472 - 2473 - BUG_ON(crypto_shash_update(&desc.shash, address, length)); 2474 - 2475 - return *(u32 *)desc.ctx; 2466 + return crc32c(crc, address, length); 2476 2467 } 2477 2468 2478 2469 #ifdef __KERNEL__ ··· 3261 3276 3262 3277 static inline int ext4_has_metadata_csum(struct super_block *sb) 3263 3278 { 3264 - WARN_ON_ONCE(ext4_has_feature_metadata_csum(sb) && 3265 - !EXT4_SB(sb)->s_chksum_driver); 3266 - 3267 - return ext4_has_feature_metadata_csum(sb) && 3268 - (EXT4_SB(sb)->s_chksum_driver != NULL); 3279 + return ext4_has_feature_metadata_csum(sb); 3269 3280 } 3270 3281 3271 3282 static inline int ext4_has_group_desc_csum(struct super_block *sb)
-15
fs/ext4/super.c
··· 1380 1380 */ 1381 1381 kobject_put(&sbi->s_kobj); 1382 1382 wait_for_completion(&sbi->s_kobj_unregister); 1383 - if (sbi->s_chksum_driver) 1384 - crypto_free_shash(sbi->s_chksum_driver); 1385 1383 kfree(sbi->s_blockgroup_lock); 1386 1384 fs_put_dax(sbi->s_daxdev, NULL); 1387 1385 fscrypt_free_dummy_policy(&sbi->s_dummy_enc_policy); ··· 4632 4634 ext4_setup_csum_trigger(sb, EXT4_JTR_ORPHAN_FILE, 4633 4635 ext4_orphan_file_block_trigger); 4634 4636 4635 - /* Load the checksum driver */ 4636 - sbi->s_chksum_driver = crypto_alloc_shash("crc32c", 0, 0); 4637 - if (IS_ERR(sbi->s_chksum_driver)) { 4638 - int ret = PTR_ERR(sbi->s_chksum_driver); 4639 - ext4_msg(sb, KERN_ERR, "Cannot load crc32c driver."); 4640 - sbi->s_chksum_driver = NULL; 4641 - return ret; 4642 - } 4643 - 4644 4637 /* Check superblock checksum */ 4645 4638 if (!ext4_superblock_csum_verify(sb, es)) { 4646 4639 ext4_msg(sb, KERN_ERR, "VFS: Found ext4 filesystem with " ··· 5676 5687 del_timer_sync(&sbi->s_err_report); 5677 5688 ext4_group_desc_free(sbi); 5678 5689 failed_mount: 5679 - if (sbi->s_chksum_driver) 5680 - crypto_free_shash(sbi->s_chksum_driver); 5681 - 5682 5690 #if IS_ENABLED(CONFIG_UNICODE) 5683 5691 utf8_unload(sb->s_encoding); 5684 5692 #endif ··· 7480 7494 MODULE_AUTHOR("Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others"); 7481 7495 MODULE_DESCRIPTION("Fourth Extended Filesystem"); 7482 7496 MODULE_LICENSE("GPL"); 7483 - MODULE_SOFTDEP("pre: crc32c"); 7484 7497 module_init(ext4_init_fs) 7485 7498 module_exit(ext4_exit_fs)