@@ -223,6 +223,7 @@ struct dm_integrity_c {
223223 int failed ;
224224
225225 struct crypto_shash * internal_hash ;
226+ unsigned int internal_hash_digestsize ;
226227
227228 struct dm_target * ti ;
228229
@@ -1676,7 +1677,7 @@ static void integrity_sector_checksum(struct dm_integrity_c *ic, sector_t sector
16761677 goto failed ;
16771678 }
16781679
1679- digest_size = crypto_shash_digestsize ( ic -> internal_hash ) ;
1680+ digest_size = ic -> internal_hash_digestsize ;
16801681 if (unlikely (digest_size < ic -> tag_size ))
16811682 memset (result + digest_size , 0 , ic -> tag_size - digest_size );
16821683
@@ -1776,7 +1777,7 @@ static void integrity_metadata(struct work_struct *w)
17761777 if (ic -> internal_hash ) {
17771778 struct bvec_iter iter ;
17781779 struct bio_vec bv ;
1779- unsigned int digest_size = crypto_shash_digestsize ( ic -> internal_hash ) ;
1780+ unsigned int digest_size = ic -> internal_hash_digestsize ;
17801781 struct bio * bio = dm_bio_from_per_bio_data (dio , sizeof (struct dm_integrity_io ));
17811782 char * checksums ;
17821783 unsigned int extra_space = unlikely (digest_size > ic -> tag_size ) ? digest_size - ic -> tag_size : 0 ;
@@ -2124,7 +2125,7 @@ static bool __journal_read_write(struct dm_integrity_io *dio, struct bio *bio,
21242125 } while (++ s < ic -> sectors_per_block );
21252126
21262127 if (ic -> internal_hash ) {
2127- unsigned int digest_size = crypto_shash_digestsize ( ic -> internal_hash ) ;
2128+ unsigned int digest_size = ic -> internal_hash_digestsize ;
21282129
21292130 if (unlikely (digest_size > ic -> tag_size )) {
21302131 char checksums_onstack [HASH_MAX_DIGESTSIZE ];
@@ -2428,7 +2429,7 @@ static int dm_integrity_map_inline(struct dm_integrity_io *dio, bool from_map)
24282429 if (!dio -> integrity_payload ) {
24292430 unsigned digest_size , extra_size ;
24302431 dio -> payload_len = ic -> tuple_size * (bio_sectors (bio ) >> ic -> sb -> log2_sectors_per_block );
2431- digest_size = crypto_shash_digestsize ( ic -> internal_hash ) ;
2432+ digest_size = ic -> internal_hash_digestsize ;
24322433 extra_size = unlikely (digest_size > ic -> tag_size ) ? digest_size - ic -> tag_size : 0 ;
24332434 dio -> payload_len += extra_size ;
24342435 dio -> integrity_payload = kmalloc (dio -> payload_len , GFP_NOIO | __GFP_NORETRY | __GFP_NOMEMALLOC | __GFP_NOWARN );
@@ -2589,7 +2590,7 @@ static void dm_integrity_inline_recheck(struct work_struct *w)
25892590 bio_put (outgoing_bio );
25902591
25912592 integrity_sector_checksum (ic , dio -> bio_details .bi_iter .bi_sector , outgoing_data , digest );
2592- if (unlikely (crypto_memneq (digest , dio -> integrity_payload , min (crypto_shash_digestsize ( ic -> internal_hash ) , ic -> tag_size )))) {
2593+ if (unlikely (crypto_memneq (digest , dio -> integrity_payload , min (ic -> internal_hash_digestsize , ic -> tag_size )))) {
25932594 DMERR_LIMIT ("%pg: Checksum failed at sector 0x%llx" ,
25942595 ic -> dev -> bdev , dio -> bio_details .bi_iter .bi_sector );
25952596 atomic64_inc (& ic -> number_of_mismatches );
@@ -2629,7 +2630,7 @@ static int dm_integrity_end_io(struct dm_target *ti, struct bio *bio, blk_status
26292630 //memset(mem, 0xff, ic->sectors_per_block << SECTOR_SHIFT);
26302631 integrity_sector_checksum (ic , dio -> bio_details .bi_iter .bi_sector , mem , digest );
26312632 if (unlikely (crypto_memneq (digest , dio -> integrity_payload + pos ,
2632- min (crypto_shash_digestsize ( ic -> internal_hash ) , ic -> tag_size )))) {
2633+ min (ic -> internal_hash_digestsize , ic -> tag_size )))) {
26332634 kunmap_local (mem );
26342635 dm_integrity_free_payload (dio );
26352636 INIT_WORK (& dio -> work , dm_integrity_inline_recheck );
@@ -3011,8 +3012,8 @@ static void integrity_recalc(struct work_struct *w)
30113012 goto free_ret ;
30123013 }
30133014 recalc_tags_size = (recalc_sectors >> ic -> sb -> log2_sectors_per_block ) * ic -> tag_size ;
3014- if (crypto_shash_digestsize ( ic -> internal_hash ) > ic -> tag_size )
3015- recalc_tags_size += crypto_shash_digestsize ( ic -> internal_hash ) - ic -> tag_size ;
3015+ if (ic -> internal_hash_digestsize > ic -> tag_size )
3016+ recalc_tags_size += ic -> internal_hash_digestsize - ic -> tag_size ;
30163017 recalc_tags = kvmalloc (recalc_tags_size , GFP_NOIO );
30173018 if (!recalc_tags ) {
30183019 vfree (recalc_buffer );
@@ -3171,8 +3172,8 @@ static void integrity_recalc_inline(struct work_struct *w)
31713172 }
31723173
31733174 recalc_tags_size = (recalc_sectors >> ic -> sb -> log2_sectors_per_block ) * ic -> tuple_size ;
3174- if (crypto_shash_digestsize ( ic -> internal_hash ) > ic -> tuple_size )
3175- recalc_tags_size += crypto_shash_digestsize ( ic -> internal_hash ) - ic -> tuple_size ;
3175+ if (ic -> internal_hash_digestsize > ic -> tuple_size )
3176+ recalc_tags_size += ic -> internal_hash_digestsize - ic -> tuple_size ;
31763177 recalc_tags = kmalloc (recalc_tags_size , GFP_NOIO | __GFP_NOWARN );
31773178 if (!recalc_tags ) {
31783179 kfree (recalc_buffer );
@@ -4694,6 +4695,8 @@ static int dm_integrity_ctr(struct dm_target *ti, unsigned int argc, char **argv
46944695 "Invalid internal hash" , "Error setting internal hash key" );
46954696 if (r )
46964697 goto bad ;
4698+ if (ic -> internal_hash )
4699+ ic -> internal_hash_digestsize = crypto_shash_digestsize (ic -> internal_hash );
46974700
46984701 r = get_mac (& ic -> journal_mac , & ic -> journal_mac_alg , & ti -> error ,
46994702 "Invalid journal mac" , "Error setting journal mac key" );
@@ -4706,7 +4709,7 @@ static int dm_integrity_ctr(struct dm_target *ti, unsigned int argc, char **argv
47064709 r = - EINVAL ;
47074710 goto bad ;
47084711 }
4709- ic -> tag_size = crypto_shash_digestsize ( ic -> internal_hash ) ;
4712+ ic -> tag_size = ic -> internal_hash_digestsize ;
47104713 }
47114714 if (ic -> tag_size > MAX_TAG_SIZE ) {
47124715 ti -> error = "Too big tag size" ;
0 commit comments