Skip to content

Commit dd348f0

Browse files
committed
jbd2: 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 f2b4fa1 commit dd348f0

File tree

3 files changed

+6
-59
lines changed

3 files changed

+6
-59
lines changed

fs/jbd2/Kconfig

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
config JBD2
33
tristate
44
select CRC32
5-
select CRYPTO
6-
select CRYPTO_CRC32C
75
help
86
This is a generic journaling layer for block devices that support
97
both 32-bit and 64-bit block numbers. It is currently used by

fs/jbd2/journal.c

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,20 +1369,12 @@ static int journal_check_superblock(journal_t *journal)
13691369
return err;
13701370
}
13711371

1372-
/* Load the checksum driver */
13731372
if (jbd2_journal_has_csum_v2or3_feature(journal)) {
13741373
if (sb->s_checksum_type != JBD2_CRC32C_CHKSUM) {
13751374
printk(KERN_ERR "JBD2: Unknown checksum type\n");
13761375
return err;
13771376
}
13781377

1379-
journal->j_chksum_driver = crypto_alloc_shash("crc32c", 0, 0);
1380-
if (IS_ERR(journal->j_chksum_driver)) {
1381-
printk(KERN_ERR "JBD2: Cannot load crc32c driver.\n");
1382-
err = PTR_ERR(journal->j_chksum_driver);
1383-
journal->j_chksum_driver = NULL;
1384-
return err;
1385-
}
13861378
/* Check superblock checksum */
13871379
if (sb->s_checksum != jbd2_superblock_csum(journal, sb)) {
13881380
printk(KERN_ERR "JBD2: journal checksum error\n");
@@ -1608,8 +1600,6 @@ static journal_t *journal_init_common(struct block_device *bdev,
16081600

16091601
err_cleanup:
16101602
percpu_counter_destroy(&journal->j_checkpoint_jh_count);
1611-
if (journal->j_chksum_driver)
1612-
crypto_free_shash(journal->j_chksum_driver);
16131603
kfree(journal->j_wbuf);
16141604
jbd2_journal_destroy_revoke(journal);
16151605
journal_fail_superblock(journal);
@@ -2191,8 +2181,6 @@ int jbd2_journal_destroy(journal_t *journal)
21912181
iput(journal->j_inode);
21922182
if (journal->j_revoke)
21932183
jbd2_journal_destroy_revoke(journal);
2194-
if (journal->j_chksum_driver)
2195-
crypto_free_shash(journal->j_chksum_driver);
21962184
kfree(journal->j_fc_wbuf);
21972185
kfree(journal->j_wbuf);
21982186
kfree(journal);
@@ -2337,27 +2325,15 @@ int jbd2_journal_set_features(journal_t *journal, unsigned long compat,
23372325
}
23382326
}
23392327

2340-
/* Load the checksum driver if necessary */
2341-
if ((journal->j_chksum_driver == NULL) &&
2342-
INCOMPAT_FEATURE_ON(JBD2_FEATURE_INCOMPAT_CSUM_V3)) {
2343-
journal->j_chksum_driver = crypto_alloc_shash("crc32c", 0, 0);
2344-
if (IS_ERR(journal->j_chksum_driver)) {
2345-
printk(KERN_ERR "JBD2: Cannot load crc32c driver.\n");
2346-
journal->j_chksum_driver = NULL;
2347-
return 0;
2348-
}
2349-
/* Precompute checksum seed for all metadata */
2350-
journal->j_csum_seed = jbd2_chksum(journal, ~0, sb->s_uuid,
2351-
sizeof(sb->s_uuid));
2352-
}
2353-
23542328
lock_buffer(journal->j_sb_buffer);
23552329

2356-
/* If enabling v3 checksums, update superblock */
2330+
/* If enabling v3 checksums, update superblock and precompute seed */
23572331
if (INCOMPAT_FEATURE_ON(JBD2_FEATURE_INCOMPAT_CSUM_V3)) {
23582332
sb->s_checksum_type = JBD2_CRC32C_CHKSUM;
23592333
sb->s_feature_compat &=
23602334
~cpu_to_be32(JBD2_FEATURE_COMPAT_CHECKSUM);
2335+
journal->j_csum_seed = jbd2_chksum(journal, ~0, sb->s_uuid,
2336+
sizeof(sb->s_uuid));
23612337
}
23622338

23632339
/* If enabling v1 checksums, downgrade superblock */

include/linux/jbd2.h

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#include <linux/slab.h>
2929
#include <linux/bit_spinlock.h>
3030
#include <linux/blkdev.h>
31-
#include <crypto/hash.h>
31+
#include <linux/crc32c.h>
3232
#endif
3333

3434
#define journal_oom_retry 1
@@ -1241,13 +1241,6 @@ struct journal_s
12411241
*/
12421242
void *j_private;
12431243

1244-
/**
1245-
* @j_chksum_driver:
1246-
*
1247-
* Reference to checksum algorithm driver via cryptoapi.
1248-
*/
1249-
struct crypto_shash *j_chksum_driver;
1250-
12511244
/**
12521245
* @j_csum_seed:
12531246
*
@@ -1750,10 +1743,7 @@ static inline bool jbd2_journal_has_csum_v2or3_feature(journal_t *j)
17501743

17511744
static inline int jbd2_journal_has_csum_v2or3(journal_t *journal)
17521745
{
1753-
WARN_ON_ONCE(jbd2_journal_has_csum_v2or3_feature(journal) &&
1754-
journal->j_chksum_driver == NULL);
1755-
1756-
return journal->j_chksum_driver != NULL;
1746+
return jbd2_journal_has_csum_v2or3_feature(journal);
17571747
}
17581748

17591749
static inline int jbd2_journal_get_num_fc_blks(journal_superblock_t *jsb)
@@ -1790,27 +1780,10 @@ static inline unsigned long jbd2_log_space_left(journal_t *journal)
17901780
#define BJ_Reserved 4 /* Buffer is reserved for access by journal */
17911781
#define BJ_Types 5
17921782

1793-
/* JBD uses a CRC32 checksum */
1794-
#define JBD_MAX_CHECKSUM_SIZE 4
1795-
17961783
static inline u32 jbd2_chksum(journal_t *journal, u32 crc,
17971784
const void *address, unsigned int length)
17981785
{
1799-
DEFINE_RAW_FLEX(struct shash_desc, desc, __ctx,
1800-
DIV_ROUND_UP(JBD_MAX_CHECKSUM_SIZE,
1801-
sizeof(*((struct shash_desc *)0)->__ctx)));
1802-
int err;
1803-
1804-
BUG_ON(crypto_shash_descsize(journal->j_chksum_driver) >
1805-
JBD_MAX_CHECKSUM_SIZE);
1806-
1807-
desc->tfm = journal->j_chksum_driver;
1808-
*(u32 *)desc->__ctx = crc;
1809-
1810-
err = crypto_shash_update(desc, address, length);
1811-
BUG_ON(err);
1812-
1813-
return *(u32 *)desc->__ctx;
1786+
return crc32c(crc, address, length);
18141787
}
18151788

18161789
/* Return most recent uncommitted transaction */

0 commit comments

Comments
 (0)