Skip to content

Commit 3ca4bec

Browse files
committed
f2fs: switch to using the crc32 library
Now that the crc32() library function takes advantage of architecture-specific optimizations, it is unnecessary to go through the crypto API. Just use crc32(). This is much simpler, and it improves performance due to eliminating the crypto API overhead. Reviewed-by: Ard Biesheuvel <[email protected]> Acked-by: Chao Yu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Eric Biggers <[email protected]>
1 parent dd348f0 commit 3ca4bec

File tree

3 files changed

+2
-36
lines changed

3 files changed

+2
-36
lines changed

fs/f2fs/Kconfig

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ config F2FS_FS
44
depends on BLOCK
55
select BUFFER_HEAD
66
select NLS
7-
select CRYPTO
8-
select CRYPTO_CRC32
7+
select CRC32
98
select F2FS_FS_XATTR if FS_ENCRYPTION
109
select FS_ENCRYPTION_ALGS if FS_ENCRYPTION
1110
select FS_IOMAP

fs/f2fs/f2fs.h

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include <linux/quotaops.h>
2525
#include <linux/part_stat.h>
2626
#include <linux/rw_hint.h>
27-
#include <crypto/hash.h>
2827

2928
#include <linux/fscrypt.h>
3029
#include <linux/fsverity.h>
@@ -1768,9 +1767,6 @@ struct f2fs_sb_info {
17681767
u64 sectors_written_start;
17691768
u64 kbytes_written;
17701769

1771-
/* Reference to checksum algorithm driver via cryptoapi */
1772-
struct crypto_shash *s_chksum_driver;
1773-
17741770
/* Precomputed FS UUID checksum for seeding other checksums */
17751771
__u32 s_chksum_seed;
17761772

@@ -1948,21 +1944,7 @@ static inline unsigned int f2fs_time_to_wait(struct f2fs_sb_info *sbi,
19481944
static inline u32 __f2fs_crc32(struct f2fs_sb_info *sbi, u32 crc,
19491945
const void *address, unsigned int length)
19501946
{
1951-
struct {
1952-
struct shash_desc shash;
1953-
char ctx[4];
1954-
} desc;
1955-
int err;
1956-
1957-
BUG_ON(crypto_shash_descsize(sbi->s_chksum_driver) != sizeof(desc.ctx));
1958-
1959-
desc.shash.tfm = sbi->s_chksum_driver;
1960-
*(u32 *)desc.ctx = crc;
1961-
1962-
err = crypto_shash_update(&desc.shash, address, length);
1963-
BUG_ON(err);
1964-
1965-
return *(u32 *)desc.ctx;
1947+
return crc32(crc, address, length);
19661948
}
19671949

19681950
static inline u32 f2fs_crc32(struct f2fs_sb_info *sbi, const void *address,

fs/f2fs/super.c

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1694,8 +1694,6 @@ static void f2fs_put_super(struct super_block *sb)
16941694

16951695
kvfree(sbi->ckpt);
16961696

1697-
if (sbi->s_chksum_driver)
1698-
crypto_free_shash(sbi->s_chksum_driver);
16991697
kfree(sbi->raw_super);
17001698

17011699
f2fs_destroy_page_array_cache(sbi);
@@ -4466,15 +4464,6 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
44664464
}
44674465
mutex_init(&sbi->flush_lock);
44684466

4469-
/* Load the checksum driver */
4470-
sbi->s_chksum_driver = crypto_alloc_shash("crc32", 0, 0);
4471-
if (IS_ERR(sbi->s_chksum_driver)) {
4472-
f2fs_err(sbi, "Cannot load crc32 driver.");
4473-
err = PTR_ERR(sbi->s_chksum_driver);
4474-
sbi->s_chksum_driver = NULL;
4475-
goto free_sbi;
4476-
}
4477-
44784467
/* set a block size */
44794468
if (unlikely(!sb_set_blocksize(sb, F2FS_BLKSIZE))) {
44804469
f2fs_err(sbi, "unable to set blocksize");
@@ -4919,8 +4908,6 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
49194908
free_sb_buf:
49204909
kfree(raw_super);
49214910
free_sbi:
4922-
if (sbi->s_chksum_driver)
4923-
crypto_free_shash(sbi->s_chksum_driver);
49244911
kfree(sbi);
49254912
sb->s_fs_info = NULL;
49264913

@@ -5127,5 +5114,3 @@ module_exit(exit_f2fs_fs)
51275114
MODULE_AUTHOR("Samsung Electronics's Praesto Team");
51285115
MODULE_DESCRIPTION("Flash Friendly File System");
51295116
MODULE_LICENSE("GPL");
5130-
MODULE_SOFTDEP("pre: crc32");
5131-

0 commit comments

Comments
 (0)