Skip to content

Commit f2b4fa1

Browse files
committed
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 <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Acked-by: Theodore Ts'o <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Eric Biggers <[email protected]>
1 parent 38a9a51 commit f2b4fa1

File tree

3 files changed

+4
-39
lines changed

3 files changed

+4
-39
lines changed

fs/ext4/Kconfig

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ config EXT4_FS
3131
select BUFFER_HEAD
3232
select JBD2
3333
select CRC16
34-
select CRYPTO
35-
select CRYPTO_CRC32C
34+
select CRC32
3635
select FS_IOMAP
3736
select FS_ENCRYPTION_ALGS if FS_ENCRYPTION
3837
help

fs/ext4/ext4.h

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#include <linux/blockgroup_lock.h>
3434
#include <linux/percpu_counter.h>
3535
#include <linux/ratelimit.h>
36-
#include <crypto/hash.h>
36+
#include <linux/crc32c.h>
3737
#include <linux/falloc.h>
3838
#include <linux/percpu-rwsem.h>
3939
#include <linux/fiemap.h>
@@ -1662,9 +1662,6 @@ struct ext4_sb_info {
16621662
/* record the last minlen when FITRIM is called. */
16631663
unsigned long s_last_trim_minblks;
16641664

1665-
/* Reference to checksum algorithm driver via cryptoapi */
1666-
struct crypto_shash *s_chksum_driver;
1667-
16681665
/* Precomputed FS UUID checksum for seeding other checksums */
16691666
__u32 s_csum_seed;
16701667

@@ -2463,19 +2460,7 @@ static inline __le16 ext4_rec_len_to_disk(unsigned len, unsigned blocksize)
24632460
static inline u32 ext4_chksum(struct ext4_sb_info *sbi, u32 crc,
24642461
const void *address, unsigned int length)
24652462
{
2466-
struct {
2467-
struct shash_desc shash;
2468-
char ctx[4];
2469-
} desc;
2470-
2471-
BUG_ON(crypto_shash_descsize(sbi->s_chksum_driver)!=sizeof(desc.ctx));
2472-
2473-
desc.shash.tfm = sbi->s_chksum_driver;
2474-
*(u32 *)desc.ctx = crc;
2475-
2476-
BUG_ON(crypto_shash_update(&desc.shash, address, length));
2477-
2478-
return *(u32 *)desc.ctx;
2463+
return crc32c(crc, address, length);
24792464
}
24802465

24812466
#ifdef __KERNEL__
@@ -3276,11 +3261,7 @@ extern int ext4_register_li_request(struct super_block *sb,
32763261

32773262
static inline int ext4_has_metadata_csum(struct super_block *sb)
32783263
{
3279-
WARN_ON_ONCE(ext4_has_feature_metadata_csum(sb) &&
3280-
!EXT4_SB(sb)->s_chksum_driver);
3281-
3282-
return ext4_has_feature_metadata_csum(sb) &&
3283-
(EXT4_SB(sb)->s_chksum_driver != NULL);
3264+
return ext4_has_feature_metadata_csum(sb);
32843265
}
32853266

32863267
static inline int ext4_has_group_desc_csum(struct super_block *sb)

fs/ext4/super.c

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,8 +1380,6 @@ static void ext4_put_super(struct super_block *sb)
13801380
*/
13811381
kobject_put(&sbi->s_kobj);
13821382
wait_for_completion(&sbi->s_kobj_unregister);
1383-
if (sbi->s_chksum_driver)
1384-
crypto_free_shash(sbi->s_chksum_driver);
13851383
kfree(sbi->s_blockgroup_lock);
13861384
fs_put_dax(sbi->s_daxdev, NULL);
13871385
fscrypt_free_dummy_policy(&sbi->s_dummy_enc_policy);
@@ -4634,15 +4632,6 @@ static int ext4_init_metadata_csum(struct super_block *sb, struct ext4_super_blo
46344632
ext4_setup_csum_trigger(sb, EXT4_JTR_ORPHAN_FILE,
46354633
ext4_orphan_file_block_trigger);
46364634

4637-
/* Load the checksum driver */
4638-
sbi->s_chksum_driver = crypto_alloc_shash("crc32c", 0, 0);
4639-
if (IS_ERR(sbi->s_chksum_driver)) {
4640-
int ret = PTR_ERR(sbi->s_chksum_driver);
4641-
ext4_msg(sb, KERN_ERR, "Cannot load crc32c driver.");
4642-
sbi->s_chksum_driver = NULL;
4643-
return ret;
4644-
}
4645-
46464635
/* Check superblock checksum */
46474636
if (!ext4_superblock_csum_verify(sb, es)) {
46484637
ext4_msg(sb, KERN_ERR, "VFS: Found ext4 filesystem with "
@@ -5687,9 +5676,6 @@ failed_mount8: __maybe_unused
56875676
del_timer_sync(&sbi->s_err_report);
56885677
ext4_group_desc_free(sbi);
56895678
failed_mount:
5690-
if (sbi->s_chksum_driver)
5691-
crypto_free_shash(sbi->s_chksum_driver);
5692-
56935679
#if IS_ENABLED(CONFIG_UNICODE)
56945680
utf8_unload(sb->s_encoding);
56955681
#endif
@@ -7494,6 +7480,5 @@ static void __exit ext4_exit_fs(void)
74947480
MODULE_AUTHOR("Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others");
74957481
MODULE_DESCRIPTION("Fourth Extended Filesystem");
74967482
MODULE_LICENSE("GPL");
7497-
MODULE_SOFTDEP("pre: crc32c");
74987483
module_init(ext4_init_fs)
74997484
module_exit(ext4_exit_fs)

0 commit comments

Comments
 (0)