From: Eric Biggers via Linux-f2fs-devel <linux-f2fs-devel@lists.sourceforge.net>
To: linux-kernel@vger.kernel.org
Cc: linux-arch@vger.kernel.org, linux-s390@vger.kernel.org,
Theodore Ts'o <tytso@mit.edu>,
linux-scsi@vger.kernel.org, "Darrick J. Wong" <djwong@kernel.org>,
x86@kernel.org, linux-mips@vger.kernel.org,
linux-f2fs-devel@lists.sourceforge.net,
linux-crypto@vger.kernel.org, loongarch@lists.linux.dev,
sparclinux@vger.kernel.org, linux-riscv@lists.infradead.org,
linux-ext4@vger.kernel.org, linuxppc-dev@lists.ozlabs.org,
Ard Biesheuvel <ardb@kernel.org>,
linux-arm-kernel@lists.infradead.org
Subject: [f2fs-dev] [PATCH v4 17/19] jbd2: switch to using the crc32c library
Date: Sun, 1 Dec 2024 17:08:42 -0800 [thread overview]
Message-ID: <20241202010844.144356-18-ebiggers@kernel.org> (raw)
In-Reply-To: <20241202010844.144356-1-ebiggers@kernel.org>
From: Eric Biggers <ebiggers@google.com>
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>
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
fs/jbd2/Kconfig | 2 --
fs/jbd2/journal.c | 30 +++---------------------------
include/linux/jbd2.h | 33 +++------------------------------
3 files changed, 6 insertions(+), 59 deletions(-)
diff --git a/fs/jbd2/Kconfig b/fs/jbd2/Kconfig
index 4ad2c67f93f1..9c19e1512101 100644
--- a/fs/jbd2/Kconfig
+++ b/fs/jbd2/Kconfig
@@ -1,11 +1,9 @@
# SPDX-License-Identifier: GPL-2.0-only
config JBD2
tristate
select CRC32
- select CRYPTO
- select CRYPTO_CRC32C
help
This is a generic journaling layer for block devices that support
both 32-bit and 64-bit block numbers. It is currently used by
the ext4 and OCFS2 filesystems, but it could also be used to add
journal support to other file systems or block devices such
diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
index 7e49d912b091..d8084b31b361 100644
--- a/fs/jbd2/journal.c
+++ b/fs/jbd2/journal.c
@@ -1367,24 +1367,16 @@ static int journal_check_superblock(journal_t *journal)
printk(KERN_ERR "JBD2: Can't enable checksumming v1 and v2/3 "
"at the same time!\n");
return err;
}
- /* Load the checksum driver */
if (jbd2_journal_has_csum_v2or3_feature(journal)) {
if (sb->s_checksum_type != JBD2_CRC32C_CHKSUM) {
printk(KERN_ERR "JBD2: Unknown checksum type\n");
return err;
}
- journal->j_chksum_driver = crypto_alloc_shash("crc32c", 0, 0);
- if (IS_ERR(journal->j_chksum_driver)) {
- printk(KERN_ERR "JBD2: Cannot load crc32c driver.\n");
- err = PTR_ERR(journal->j_chksum_driver);
- journal->j_chksum_driver = NULL;
- return err;
- }
/* Check superblock checksum */
if (sb->s_checksum != jbd2_superblock_csum(journal, sb)) {
printk(KERN_ERR "JBD2: journal checksum error\n");
err = -EFSBADCRC;
return err;
@@ -1606,12 +1598,10 @@ static journal_t *journal_init_common(struct block_device *bdev,
return journal;
err_cleanup:
percpu_counter_destroy(&journal->j_checkpoint_jh_count);
- if (journal->j_chksum_driver)
- crypto_free_shash(journal->j_chksum_driver);
kfree(journal->j_wbuf);
jbd2_journal_destroy_revoke(journal);
journal_fail_superblock(journal);
kfree(journal);
return ERR_PTR(err);
@@ -2189,12 +2179,10 @@ int jbd2_journal_destroy(journal_t *journal)
if (journal->j_proc_entry)
jbd2_stats_proc_exit(journal);
iput(journal->j_inode);
if (journal->j_revoke)
jbd2_journal_destroy_revoke(journal);
- if (journal->j_chksum_driver)
- crypto_free_shash(journal->j_chksum_driver);
kfree(journal->j_fc_wbuf);
kfree(journal->j_wbuf);
kfree(journal);
return err;
@@ -2335,31 +2323,19 @@ int jbd2_journal_set_features(journal_t *journal, unsigned long compat,
pr_err("JBD2: Cannot enable fast commits.\n");
return 0;
}
}
- /* Load the checksum driver if necessary */
- if ((journal->j_chksum_driver == NULL) &&
- INCOMPAT_FEATURE_ON(JBD2_FEATURE_INCOMPAT_CSUM_V3)) {
- journal->j_chksum_driver = crypto_alloc_shash("crc32c", 0, 0);
- if (IS_ERR(journal->j_chksum_driver)) {
- printk(KERN_ERR "JBD2: Cannot load crc32c driver.\n");
- journal->j_chksum_driver = NULL;
- return 0;
- }
- /* Precompute checksum seed for all metadata */
- journal->j_csum_seed = jbd2_chksum(journal, ~0, sb->s_uuid,
- sizeof(sb->s_uuid));
- }
-
lock_buffer(journal->j_sb_buffer);
- /* If enabling v3 checksums, update superblock */
+ /* If enabling v3 checksums, update superblock and precompute seed */
if (INCOMPAT_FEATURE_ON(JBD2_FEATURE_INCOMPAT_CSUM_V3)) {
sb->s_checksum_type = JBD2_CRC32C_CHKSUM;
sb->s_feature_compat &=
~cpu_to_be32(JBD2_FEATURE_COMPAT_CHECKSUM);
+ journal->j_csum_seed = jbd2_chksum(journal, ~0, sb->s_uuid,
+ sizeof(sb->s_uuid));
}
/* If enabling v1 checksums, downgrade superblock */
if (COMPAT_FEATURE_ON(JBD2_FEATURE_COMPAT_CHECKSUM))
sb->s_feature_incompat &=
diff --git a/include/linux/jbd2.h b/include/linux/jbd2.h
index 50f7ea8714bf..561025b4f3d9 100644
--- a/include/linux/jbd2.h
+++ b/include/linux/jbd2.h
@@ -26,11 +26,11 @@
#include <linux/mutex.h>
#include <linux/timer.h>
#include <linux/slab.h>
#include <linux/bit_spinlock.h>
#include <linux/blkdev.h>
-#include <crypto/hash.h>
+#include <linux/crc32c.h>
#endif
#define journal_oom_retry 1
/*
@@ -1239,17 +1239,10 @@ struct journal_s
* An opaque pointer to fs-private information. ext3 puts its
* superblock pointer here.
*/
void *j_private;
- /**
- * @j_chksum_driver:
- *
- * Reference to checksum algorithm driver via cryptoapi.
- */
- struct crypto_shash *j_chksum_driver;
-
/**
* @j_csum_seed:
*
* Precomputed journal UUID checksum for seeding other checksums.
*/
@@ -1748,14 +1741,11 @@ static inline bool jbd2_journal_has_csum_v2or3_feature(journal_t *j)
return jbd2_has_feature_csum2(j) || jbd2_has_feature_csum3(j);
}
static inline int jbd2_journal_has_csum_v2or3(journal_t *journal)
{
- WARN_ON_ONCE(jbd2_journal_has_csum_v2or3_feature(journal) &&
- journal->j_chksum_driver == NULL);
-
- return journal->j_chksum_driver != NULL;
+ return jbd2_journal_has_csum_v2or3_feature(journal);
}
static inline int jbd2_journal_get_num_fc_blks(journal_superblock_t *jsb)
{
int num_fc_blocks = be32_to_cpu(jsb->s_num_fc_blks);
@@ -1788,31 +1778,14 @@ static inline unsigned long jbd2_log_space_left(journal_t *journal)
#define BJ_Forget 2 /* Buffer superseded by this transaction */
#define BJ_Shadow 3 /* Buffer contents being shadowed to the log */
#define BJ_Reserved 4 /* Buffer is reserved for access by journal */
#define BJ_Types 5
-/* JBD uses a CRC32 checksum */
-#define JBD_MAX_CHECKSUM_SIZE 4
-
static inline u32 jbd2_chksum(journal_t *journal, u32 crc,
const void *address, unsigned int length)
{
- DEFINE_RAW_FLEX(struct shash_desc, desc, __ctx,
- DIV_ROUND_UP(JBD_MAX_CHECKSUM_SIZE,
- sizeof(*((struct shash_desc *)0)->__ctx)));
- int err;
-
- BUG_ON(crypto_shash_descsize(journal->j_chksum_driver) >
- JBD_MAX_CHECKSUM_SIZE);
-
- desc->tfm = journal->j_chksum_driver;
- *(u32 *)desc->__ctx = crc;
-
- err = crypto_shash_update(desc, address, length);
- BUG_ON(err);
-
- return *(u32 *)desc->__ctx;
+ return crc32c(crc, address, length);
}
/* Return most recent uncommitted transaction */
static inline tid_t jbd2_get_latest_transaction(journal_t *journal)
{
--
2.47.1
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
next prev parent reply other threads:[~2024-12-02 1:10 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-02 1:08 [f2fs-dev] [PATCH v4 00/19] Wire up CRC32 library functions to arch-optimized code Eric Biggers via Linux-f2fs-devel
2024-12-02 1:08 ` [f2fs-dev] [PATCH v4 01/19] lib/crc32: drop leading underscores from __crc32c_le_base Eric Biggers via Linux-f2fs-devel
2024-12-02 1:08 ` [f2fs-dev] [PATCH v4 02/19] lib/crc32: improve support for arch-specific overrides Eric Biggers via Linux-f2fs-devel
2024-12-02 1:08 ` [f2fs-dev] [PATCH v4 03/19] lib/crc32: expose whether the lib is really optimized at runtime Eric Biggers via Linux-f2fs-devel
2024-12-02 1:08 ` [f2fs-dev] [PATCH v4 04/19] crypto: crc32 - don't unnecessarily register arch algorithms Eric Biggers via Linux-f2fs-devel
2024-12-02 1:08 ` [f2fs-dev] [PATCH v4 05/19] arm/crc32: expose CRC32 functions through lib Eric Biggers via Linux-f2fs-devel
2024-12-02 1:08 ` [f2fs-dev] [PATCH v4 06/19] loongarch/crc32: " Eric Biggers via Linux-f2fs-devel
2024-12-02 1:08 ` [f2fs-dev] [PATCH v4 07/19] mips/crc32: " Eric Biggers via Linux-f2fs-devel
2024-12-02 1:08 ` [f2fs-dev] [PATCH v4 08/19] powerpc/crc32: " Eric Biggers via Linux-f2fs-devel
2024-12-02 1:08 ` [f2fs-dev] [PATCH v4 09/19] s390/crc32: " Eric Biggers via Linux-f2fs-devel
2024-12-02 1:08 ` [f2fs-dev] [PATCH v4 10/19] sparc/crc32: " Eric Biggers via Linux-f2fs-devel
2024-12-02 1:08 ` [f2fs-dev] [PATCH v4 11/19] x86/crc32: update prototype for crc_pcl() Eric Biggers via Linux-f2fs-devel
2024-12-02 1:08 ` [f2fs-dev] [PATCH v4 12/19] x86/crc32: update prototype for crc32_pclmul_le_16() Eric Biggers via Linux-f2fs-devel
2024-12-02 1:08 ` [f2fs-dev] [PATCH v4 13/19] x86/crc32: expose CRC32 functions through lib Eric Biggers via Linux-f2fs-devel
2024-12-02 1:08 ` [f2fs-dev] [PATCH v4 14/19] bcachefs: Explicitly select CRYPTO from BCACHEFS_FS Eric Biggers via Linux-f2fs-devel
2024-12-02 1:08 ` [f2fs-dev] [PATCH v4 15/19] lib/crc32: make crc32c() go directly to lib Eric Biggers via Linux-f2fs-devel
2025-10-19 6:08 ` Askar Safin
2025-10-19 8:10 ` Askar Safin
2025-10-19 16:23 ` Eric Biggers via Linux-f2fs-devel
2024-12-02 1:08 ` [f2fs-dev] [PATCH v4 16/19] ext4: switch to using the crc32c library Eric Biggers via Linux-f2fs-devel
2024-12-02 1:08 ` Eric Biggers via Linux-f2fs-devel [this message]
2024-12-02 1:08 ` [f2fs-dev] [PATCH v4 18/19] f2fs: switch to using the crc32 library Eric Biggers via Linux-f2fs-devel
2024-12-02 1:08 ` [f2fs-dev] [PATCH v4 19/19] scsi: target: iscsi: switch to using the crc32c library Eric Biggers via Linux-f2fs-devel
2024-12-12 21:37 ` [f2fs-dev] [PATCH v4 00/19] Wire up CRC32 library functions to arch-optimized code Eric Biggers via Linux-f2fs-devel
2025-01-29 0:56 ` patchwork-bot+f2fs--- via Linux-f2fs-devel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241202010844.144356-18-ebiggers@kernel.org \
--to=linux-f2fs-devel@lists.sourceforge.net \
--cc=ardb@kernel.org \
--cc=djwong@kernel.org \
--cc=ebiggers@kernel.org \
--cc=linux-arch@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mips@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=linux-s390@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=loongarch@lists.linux.dev \
--cc=sparclinux@vger.kernel.org \
--cc=tytso@mit.edu \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).