@@ -59,6 +59,7 @@ struct convert_context {
5959 struct bio * bio_out ;
6060 struct bvec_iter iter_out ;
6161 atomic_t cc_pending ;
62+ unsigned int tag_offset ;
6263 u64 cc_sector ;
6364 union {
6465 struct skcipher_request * req ;
@@ -1187,7 +1188,7 @@ static int dm_crypt_integrity_io_alloc(struct dm_crypt_io *io, struct bio *bio)
11871188
11881189 tag_len = io -> cc -> tuple_size * (bio_sectors (bio ) >> io -> cc -> sector_shift );
11891190
1190- bip -> bip_iter .bi_sector = io -> cc -> start + io -> sector ;
1191+ bip -> bip_iter .bi_sector = bio -> bi_iter . bi_sector ;
11911192
11921193 ret = bio_integrity_add_page (bio , virt_to_page (io -> integrity_metadata ),
11931194 tag_len , offset_in_page (io -> integrity_metadata ));
@@ -1256,6 +1257,7 @@ static void crypt_convert_init(struct crypt_config *cc,
12561257 if (bio_out )
12571258 ctx -> iter_out = bio_out -> bi_iter ;
12581259 ctx -> cc_sector = sector + cc -> iv_offset ;
1260+ ctx -> tag_offset = 0 ;
12591261 init_completion (& ctx -> restart );
12601262}
12611263
@@ -1588,7 +1590,6 @@ static void crypt_free_req(struct crypt_config *cc, void *req, struct bio *base_
15881590static blk_status_t crypt_convert (struct crypt_config * cc ,
15891591 struct convert_context * ctx , bool atomic , bool reset_pending )
15901592{
1591- unsigned int tag_offset = 0 ;
15921593 unsigned int sector_step = cc -> sector_size >> SECTOR_SHIFT ;
15931594 int r ;
15941595
@@ -1611,9 +1612,9 @@ static blk_status_t crypt_convert(struct crypt_config *cc,
16111612 atomic_inc (& ctx -> cc_pending );
16121613
16131614 if (crypt_integrity_aead (cc ))
1614- r = crypt_convert_block_aead (cc , ctx , ctx -> r .req_aead , tag_offset );
1615+ r = crypt_convert_block_aead (cc , ctx , ctx -> r .req_aead , ctx -> tag_offset );
16151616 else
1616- r = crypt_convert_block_skcipher (cc , ctx , ctx -> r .req , tag_offset );
1617+ r = crypt_convert_block_skcipher (cc , ctx , ctx -> r .req , ctx -> tag_offset );
16171618
16181619 switch (r ) {
16191620 /*
@@ -1633,8 +1634,8 @@ static blk_status_t crypt_convert(struct crypt_config *cc,
16331634 * exit and continue processing in a workqueue
16341635 */
16351636 ctx -> r .req = NULL ;
1637+ ctx -> tag_offset ++ ;
16361638 ctx -> cc_sector += sector_step ;
1637- tag_offset ++ ;
16381639 return BLK_STS_DEV_RESOURCE ;
16391640 }
16401641 } else {
@@ -1648,16 +1649,16 @@ static blk_status_t crypt_convert(struct crypt_config *cc,
16481649 */
16491650 case - EINPROGRESS :
16501651 ctx -> r .req = NULL ;
1652+ ctx -> tag_offset ++ ;
16511653 ctx -> cc_sector += sector_step ;
1652- tag_offset ++ ;
16531654 continue ;
16541655 /*
16551656 * The request was already processed (synchronously).
16561657 */
16571658 case 0 :
16581659 atomic_dec (& ctx -> cc_pending );
16591660 ctx -> cc_sector += sector_step ;
1660- tag_offset ++ ;
1661+ ctx -> tag_offset ++ ;
16611662 if (!atomic )
16621663 cond_resched ();
16631664 continue ;
@@ -1719,6 +1720,7 @@ static struct bio *crypt_alloc_buffer(struct dm_crypt_io *io, unsigned int size)
17191720 clone -> bi_private = io ;
17201721 clone -> bi_end_io = crypt_endio ;
17211722 clone -> bi_ioprio = io -> base_bio -> bi_ioprio ;
1723+ clone -> bi_iter .bi_sector = cc -> start + io -> sector ;
17221724
17231725 remaining_size = size ;
17241726
@@ -1909,7 +1911,6 @@ static int kcryptd_io_read(struct dm_crypt_io *io, gfp_t gfp)
19091911 crypt_dec_pending (io );
19101912 return 1 ;
19111913 }
1912- clone -> bi_iter .bi_sector = cc -> start + io -> sector ;
19131914 crypt_convert_init (cc , & io -> ctx , clone , clone , io -> sector );
19141915 io -> saved_bi_iter = clone -> bi_iter ;
19151916 dm_submit_bio_remap (io -> base_bio , clone );
@@ -1925,13 +1926,13 @@ static int kcryptd_io_read(struct dm_crypt_io *io, gfp_t gfp)
19251926 clone = bio_alloc_clone (cc -> dev -> bdev , io -> base_bio , gfp , & cc -> bs );
19261927 if (!clone )
19271928 return 1 ;
1929+
1930+ clone -> bi_iter .bi_sector = cc -> start + io -> sector ;
19281931 clone -> bi_private = io ;
19291932 clone -> bi_end_io = crypt_endio ;
19301933
19311934 crypt_inc_pending (io );
19321935
1933- clone -> bi_iter .bi_sector = cc -> start + io -> sector ;
1934-
19351936 if (dm_crypt_integrity_io_alloc (io , clone )) {
19361937 crypt_dec_pending (io );
19371938 bio_put (clone );
@@ -2039,8 +2040,6 @@ static void kcryptd_crypt_write_io_submit(struct dm_crypt_io *io, int async)
20392040 /* crypt_convert should have filled the clone bio */
20402041 BUG_ON (io -> ctx .iter_out .bi_size );
20412042
2042- clone -> bi_iter .bi_sector = cc -> start + io -> sector ;
2043-
20442043 if ((likely (!async ) && test_bit (DM_CRYPT_NO_OFFLOAD , & cc -> flags )) ||
20452044 test_bit (DM_CRYPT_NO_WRITE_WORKQUEUE , & cc -> flags )) {
20462045 dm_submit_bio_remap (io -> base_bio , clone );
@@ -2092,13 +2091,12 @@ static void kcryptd_crypt_write_continue(struct work_struct *work)
20922091 struct crypt_config * cc = io -> cc ;
20932092 struct convert_context * ctx = & io -> ctx ;
20942093 int crypt_finished ;
2095- sector_t sector = io -> sector ;
20962094 blk_status_t r ;
20972095
20982096 wait_for_completion (& ctx -> restart );
20992097 reinit_completion (& ctx -> restart );
21002098
2101- r = crypt_convert (cc , & io -> ctx , true , false);
2099+ r = crypt_convert (cc , & io -> ctx , false , false);
21022100 if (r )
21032101 io -> error = r ;
21042102 crypt_finished = atomic_dec_and_test (& ctx -> cc_pending );
@@ -2109,10 +2107,8 @@ static void kcryptd_crypt_write_continue(struct work_struct *work)
21092107 }
21102108
21112109 /* Encryption was already finished, submit io now */
2112- if (crypt_finished ) {
2110+ if (crypt_finished )
21132111 kcryptd_crypt_write_io_submit (io , 0 );
2114- io -> sector = sector ;
2115- }
21162112
21172113 crypt_dec_pending (io );
21182114}
@@ -2123,14 +2119,13 @@ static void kcryptd_crypt_write_convert(struct dm_crypt_io *io)
21232119 struct convert_context * ctx = & io -> ctx ;
21242120 struct bio * clone ;
21252121 int crypt_finished ;
2126- sector_t sector = io -> sector ;
21272122 blk_status_t r ;
21282123
21292124 /*
21302125 * Prevent io from disappearing until this function completes.
21312126 */
21322127 crypt_inc_pending (io );
2133- crypt_convert_init (cc , ctx , NULL , io -> base_bio , sector );
2128+ crypt_convert_init (cc , ctx , NULL , io -> base_bio , io -> sector );
21342129
21352130 clone = crypt_alloc_buffer (io , io -> base_bio -> bi_iter .bi_size );
21362131 if (unlikely (!clone )) {
@@ -2147,8 +2142,6 @@ static void kcryptd_crypt_write_convert(struct dm_crypt_io *io)
21472142 io -> ctx .iter_in = clone -> bi_iter ;
21482143 }
21492144
2150- sector += bio_sectors (clone );
2151-
21522145 crypt_inc_pending (io );
21532146 r = crypt_convert (cc , ctx ,
21542147 test_bit (DM_CRYPT_NO_WRITE_WORKQUEUE , & cc -> flags ), true);
@@ -2172,10 +2165,8 @@ static void kcryptd_crypt_write_convert(struct dm_crypt_io *io)
21722165 }
21732166
21742167 /* Encryption was already finished, submit io now */
2175- if (crypt_finished ) {
2168+ if (crypt_finished )
21762169 kcryptd_crypt_write_io_submit (io , 0 );
2177- io -> sector = sector ;
2178- }
21792170
21802171dec :
21812172 crypt_dec_pending (io );
@@ -2203,7 +2194,7 @@ static void kcryptd_crypt_read_continue(struct work_struct *work)
22032194 wait_for_completion (& io -> ctx .restart );
22042195 reinit_completion (& io -> ctx .restart );
22052196
2206- r = crypt_convert (cc , & io -> ctx , true , false);
2197+ r = crypt_convert (cc , & io -> ctx , false , false);
22072198 if (r )
22082199 io -> error = r ;
22092200
@@ -2221,7 +2212,6 @@ static void kcryptd_crypt_read_convert(struct dm_crypt_io *io)
22212212 crypt_inc_pending (io );
22222213
22232214 if (io -> ctx .aead_recheck ) {
2224- io -> ctx .cc_sector = io -> sector + cc -> iv_offset ;
22252215 r = crypt_convert (cc , & io -> ctx ,
22262216 test_bit (DM_CRYPT_NO_READ_WORKQUEUE , & cc -> flags ), true);
22272217 } else {
0 commit comments