]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
f2fs: switch to using the crc32 library
authorEric Biggers <ebiggers@google.com>
Mon, 2 Dec 2024 01:08:43 +0000 (17:08 -0800)
committerEric Biggers <ebiggers@google.com>
Mon, 2 Dec 2024 01:23:02 +0000 (17:23 -0800)
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 <ardb@kernel.org>
Acked-by: Chao Yu <chao@kernel.org>
Link: https://lore.kernel.org/r/20241202010844.144356-19-ebiggers@kernel.org
Signed-off-by: Eric Biggers <ebiggers@google.com>
fs/f2fs/Kconfig
fs/f2fs/f2fs.h
fs/f2fs/super.c

index 68a1e23e1557c74bbc7b47e7b8c99ea6bf603474..5916a02fb46dd78dbccb1b23857c3b87bebf6809 100644 (file)
@@ -4,8 +4,7 @@ config F2FS_FS
        depends on BLOCK
        select BUFFER_HEAD
        select NLS
-       select CRYPTO
-       select CRYPTO_CRC32
+       select CRC32
        select F2FS_FS_XATTR if FS_ENCRYPTION
        select FS_ENCRYPTION_ALGS if FS_ENCRYPTION
        select FS_IOMAP
index 6f2cbf4c57402bd40497ad5c1cefd8ecff35d678..fd7e9cb6f89394b67da7013f63b7411f0fb0d9ae 100644 (file)
@@ -24,7 +24,6 @@
 #include <linux/quotaops.h>
 #include <linux/part_stat.h>
 #include <linux/rw_hint.h>
-#include <crypto/hash.h>
 
 #include <linux/fscrypt.h>
 #include <linux/fsverity.h>
@@ -1768,9 +1767,6 @@ struct f2fs_sb_info {
        u64 sectors_written_start;
        u64 kbytes_written;
 
-       /* Reference to checksum algorithm driver via cryptoapi */
-       struct crypto_shash *s_chksum_driver;
-
        /* Precomputed FS UUID checksum for seeding other checksums */
        __u32 s_chksum_seed;
 
@@ -1948,21 +1944,7 @@ static inline unsigned int f2fs_time_to_wait(struct f2fs_sb_info *sbi,
 static inline u32 __f2fs_crc32(struct f2fs_sb_info *sbi, u32 crc,
                              const void *address, unsigned int length)
 {
-       struct {
-               struct shash_desc shash;
-               char ctx[4];
-       } desc;
-       int err;
-
-       BUG_ON(crypto_shash_descsize(sbi->s_chksum_driver) != sizeof(desc.ctx));
-
-       desc.shash.tfm = sbi->s_chksum_driver;
-       *(u32 *)desc.ctx = crc;
-
-       err = crypto_shash_update(&desc.shash, address, length);
-       BUG_ON(err);
-
-       return *(u32 *)desc.ctx;
+       return crc32(crc, address, length);
 }
 
 static inline u32 f2fs_crc32(struct f2fs_sb_info *sbi, const void *address,
index fc7d463dee158ac6aeb7d101492b56e0045636cc..19b67828ae325031c645d67a9b78b3c01039d15f 100644 (file)
@@ -1694,8 +1694,6 @@ static void f2fs_put_super(struct super_block *sb)
 
        kvfree(sbi->ckpt);
 
-       if (sbi->s_chksum_driver)
-               crypto_free_shash(sbi->s_chksum_driver);
        kfree(sbi->raw_super);
 
        f2fs_destroy_page_array_cache(sbi);
@@ -4466,15 +4464,6 @@ try_onemore:
        }
        mutex_init(&sbi->flush_lock);
 
-       /* Load the checksum driver */
-       sbi->s_chksum_driver = crypto_alloc_shash("crc32", 0, 0);
-       if (IS_ERR(sbi->s_chksum_driver)) {
-               f2fs_err(sbi, "Cannot load crc32 driver.");
-               err = PTR_ERR(sbi->s_chksum_driver);
-               sbi->s_chksum_driver = NULL;
-               goto free_sbi;
-       }
-
        /* set a block size */
        if (unlikely(!sb_set_blocksize(sb, F2FS_BLKSIZE))) {
                f2fs_err(sbi, "unable to set blocksize");
@@ -4919,8 +4908,6 @@ free_options:
 free_sb_buf:
        kfree(raw_super);
 free_sbi:
-       if (sbi->s_chksum_driver)
-               crypto_free_shash(sbi->s_chksum_driver);
        kfree(sbi);
        sb->s_fs_info = NULL;
 
@@ -5127,5 +5114,3 @@ module_exit(exit_f2fs_fs)
 MODULE_AUTHOR("Samsung Electronics's Praesto Team");
 MODULE_DESCRIPTION("Flash Friendly File System");
 MODULE_LICENSE("GPL");
-MODULE_SOFTDEP("pre: crc32");
-