Lines Matching refs:ic
104 #define journal_entry_tag(ic, je) ((__u8 *)&(je)->last_bytes[(ic)->sectors_per_block]) argument
297 struct dm_integrity_c *ic; member
315 struct dm_integrity_c *ic; member
327 struct dm_integrity_c *ic; member
385 static void dm_integrity_io_error(struct dm_integrity_c *ic, const char *msg, int err) in dm_integrity_io_error() argument
388 atomic64_inc(&ic->number_of_mismatches); in dm_integrity_io_error()
389 if (!cmpxchg(&ic->failed, 0, err)) in dm_integrity_io_error()
393 static int dm_integrity_failed(struct dm_integrity_c *ic) in dm_integrity_failed() argument
395 return READ_ONCE(ic->failed); in dm_integrity_failed()
398 static bool dm_integrity_disable_recalculate(struct dm_integrity_c *ic) in dm_integrity_disable_recalculate() argument
400 if (ic->legacy_recalculate) in dm_integrity_disable_recalculate()
402 if (!(ic->sb->flags & cpu_to_le32(SB_FLAG_FIXED_HMAC)) ? in dm_integrity_disable_recalculate()
403 ic->internal_hash_alg.key || ic->journal_mac_alg.key : in dm_integrity_disable_recalculate()
404 ic->internal_hash_alg.key && !ic->journal_mac_alg.key) in dm_integrity_disable_recalculate()
409 static commit_id_t dm_integrity_commit_id(struct dm_integrity_c *ic, unsigned i, in dm_integrity_commit_id() argument
416 return ic->commit_ids[seq] ^ cpu_to_le64(((__u64)i << 32) ^ j); in dm_integrity_commit_id()
419 static void get_area_and_offset(struct dm_integrity_c *ic, sector_t data_sector, in get_area_and_offset() argument
422 if (!ic->meta_dev) { in get_area_and_offset()
423 __u8 log2_interleave_sectors = ic->sb->log2_interleave_sectors; in get_area_and_offset()
432 #define sector_to_block(ic, n) \ argument
434 BUG_ON((n) & (unsigned)((ic)->sectors_per_block - 1)); \
435 (n) >>= (ic)->sb->log2_sectors_per_block; \
438 static __u64 get_metadata_sector_and_offset(struct dm_integrity_c *ic, sector_t area, in get_metadata_sector_and_offset() argument
444 ms = area << ic->sb->log2_interleave_sectors; in get_metadata_sector_and_offset()
445 if (likely(ic->log2_metadata_run >= 0)) in get_metadata_sector_and_offset()
446 ms += area << ic->log2_metadata_run; in get_metadata_sector_and_offset()
448 ms += area * ic->metadata_run; in get_metadata_sector_and_offset()
449 ms >>= ic->log2_buffer_sectors; in get_metadata_sector_and_offset()
451 sector_to_block(ic, offset); in get_metadata_sector_and_offset()
453 if (likely(ic->log2_tag_size >= 0)) { in get_metadata_sector_and_offset()
454 ms += offset >> (SECTOR_SHIFT + ic->log2_buffer_sectors - ic->log2_tag_size); in get_metadata_sector_and_offset()
455 mo = (offset << ic->log2_tag_size) & ((1U << SECTOR_SHIFT << ic->log2_buffer_sectors) - 1); in get_metadata_sector_and_offset()
457 ms += (__u64)offset * ic->tag_size >> (SECTOR_SHIFT + ic->log2_buffer_sectors); in get_metadata_sector_and_offset()
458 mo = (offset * ic->tag_size) & ((1U << SECTOR_SHIFT << ic->log2_buffer_sectors) - 1); in get_metadata_sector_and_offset()
464 static sector_t get_data_sector(struct dm_integrity_c *ic, sector_t area, sector_t offset) in get_data_sector() argument
468 if (ic->meta_dev) in get_data_sector()
471 result = area << ic->sb->log2_interleave_sectors; in get_data_sector()
472 if (likely(ic->log2_metadata_run >= 0)) in get_data_sector()
473 result += (area + 1) << ic->log2_metadata_run; in get_data_sector()
475 result += (area + 1) * ic->metadata_run; in get_data_sector()
477 result += (sector_t)ic->initial_sectors + offset; in get_data_sector()
478 result += ic->start; in get_data_sector()
483 static void wraparound_section(struct dm_integrity_c *ic, unsigned *sec_ptr) in wraparound_section() argument
485 if (unlikely(*sec_ptr >= ic->journal_sections)) in wraparound_section()
486 *sec_ptr -= ic->journal_sections; in wraparound_section()
489 static void sb_set_version(struct dm_integrity_c *ic) in sb_set_version() argument
491 if (ic->sb->flags & cpu_to_le32(SB_FLAG_FIXED_HMAC)) in sb_set_version()
492 ic->sb->version = SB_VERSION_5; in sb_set_version()
493 else if (ic->sb->flags & cpu_to_le32(SB_FLAG_FIXED_PADDING)) in sb_set_version()
494 ic->sb->version = SB_VERSION_4; in sb_set_version()
495 else if (ic->mode == 'B' || ic->sb->flags & cpu_to_le32(SB_FLAG_DIRTY_BITMAP)) in sb_set_version()
496 ic->sb->version = SB_VERSION_3; in sb_set_version()
497 else if (ic->meta_dev || ic->sb->flags & cpu_to_le32(SB_FLAG_RECALCULATING)) in sb_set_version()
498 ic->sb->version = SB_VERSION_2; in sb_set_version()
500 ic->sb->version = SB_VERSION_1; in sb_set_version()
503 static int sb_mac(struct dm_integrity_c *ic, bool wr) in sb_mac() argument
505 SHASH_DESC_ON_STACK(desc, ic->journal_mac); in sb_mac()
507 unsigned size = crypto_shash_digestsize(ic->journal_mac); in sb_mac()
510 dm_integrity_io_error(ic, "digest is too long", -EINVAL); in sb_mac()
514 desc->tfm = ic->journal_mac; in sb_mac()
518 dm_integrity_io_error(ic, "crypto_shash_init", r); in sb_mac()
522 r = crypto_shash_update(desc, (__u8 *)ic->sb, (1 << SECTOR_SHIFT) - size); in sb_mac()
524 dm_integrity_io_error(ic, "crypto_shash_update", r); in sb_mac()
529 r = crypto_shash_final(desc, (__u8 *)ic->sb + (1 << SECTOR_SHIFT) - size); in sb_mac()
531 dm_integrity_io_error(ic, "crypto_shash_final", r); in sb_mac()
538 dm_integrity_io_error(ic, "crypto_shash_final", r); in sb_mac()
541 if (memcmp((__u8 *)ic->sb + (1 << SECTOR_SHIFT) - size, result, size)) { in sb_mac()
542 dm_integrity_io_error(ic, "superblock mac", -EILSEQ); in sb_mac()
550 static int sync_rw_sb(struct dm_integrity_c *ic, int op, int op_flags) in sync_rw_sb() argument
559 io_req.mem.ptr.addr = ic->sb; in sync_rw_sb()
561 io_req.client = ic->io; in sync_rw_sb()
562 io_loc.bdev = ic->meta_dev ? ic->meta_dev->bdev : ic->dev->bdev; in sync_rw_sb()
563 io_loc.sector = ic->start; in sync_rw_sb()
567 sb_set_version(ic); in sync_rw_sb()
568 if (ic->journal_mac && ic->sb->flags & cpu_to_le32(SB_FLAG_FIXED_HMAC)) { in sync_rw_sb()
569 r = sb_mac(ic, true); in sync_rw_sb()
580 if (ic->mode != 'R' && ic->journal_mac && ic->sb->flags & cpu_to_le32(SB_FLAG_FIXED_HMAC)) { in sync_rw_sb()
581 r = sb_mac(ic, false); in sync_rw_sb()
595 static bool block_bitmap_op(struct dm_integrity_c *ic, struct page_list *bitmap, in block_bitmap_op() argument
601 if (unlikely(((sector | n_sectors) & ((1 << ic->sb->log2_sectors_per_block) - 1)) != 0)) { in block_bitmap_op()
605 ic->sb->log2_sectors_per_block, in block_bitmap_op()
606 ic->log2_blocks_per_bitmap_bit, in block_bitmap_op()
614 bit = sector >> (ic->sb->log2_sectors_per_block + ic->log2_blocks_per_bitmap_bit); in block_bitmap_op()
616 (ic->sb->log2_sectors_per_block + ic->log2_blocks_per_bitmap_bit); in block_bitmap_op()
700 static void block_bitmap_copy(struct dm_integrity_c *ic, struct page_list *dst, struct page_list *s… in block_bitmap_copy() argument
702 unsigned n_bitmap_pages = DIV_ROUND_UP(ic->n_bitmap_blocks, PAGE_SIZE / BITMAP_BLOCK_SIZE); in block_bitmap_copy()
712 static struct bitmap_block_status *sector_to_bitmap_block(struct dm_integrity_c *ic, sector_t secto… in sector_to_bitmap_block() argument
714 unsigned bit = sector >> (ic->sb->log2_sectors_per_block + ic->log2_blocks_per_bitmap_bit); in sector_to_bitmap_block()
717 BUG_ON(bitmap_block >= ic->n_bitmap_blocks); in sector_to_bitmap_block()
718 return &ic->bbs[bitmap_block]; in sector_to_bitmap_block()
721 static void access_journal_check(struct dm_integrity_c *ic, unsigned section, unsigned offset, in access_journal_check() argument
725 unsigned limit = e ? ic->journal_section_entries : ic->journal_section_sectors; in access_journal_check()
727 if (unlikely(section >= ic->journal_sections) || in access_journal_check()
730 function, section, offset, ic->journal_sections, limit); in access_journal_check()
736 static void page_list_location(struct dm_integrity_c *ic, unsigned section, unsigned offset, in page_list_location() argument
741 access_journal_check(ic, section, offset, false, "page_list_location"); in page_list_location()
743 sector = section * ic->journal_section_sectors + offset; in page_list_location()
749 static struct journal_sector *access_page_list(struct dm_integrity_c *ic, struct page_list *pl, in access_page_list() argument
755 page_list_location(ic, section, offset, &pl_index, &pl_offset); in access_page_list()
765 static struct journal_sector *access_journal(struct dm_integrity_c *ic, unsigned section, unsigned … in access_journal() argument
767 return access_page_list(ic, ic->journal, section, offset, NULL); in access_journal()
770 static struct journal_entry *access_journal_entry(struct dm_integrity_c *ic, unsigned section, unsi… in access_journal_entry() argument
775 access_journal_check(ic, section, n, true, "access_journal_entry"); in access_journal_entry()
780 js = access_journal(ic, section, rel_sector); in access_journal_entry()
781 return (struct journal_entry *)((char *)js + offset * ic->journal_entry_size); in access_journal_entry()
784 static struct journal_sector *access_journal_data(struct dm_integrity_c *ic, unsigned section, unsi… in access_journal_data() argument
786 n <<= ic->sb->log2_sectors_per_block; in access_journal_data()
790 access_journal_check(ic, section, n, false, "access_journal_data"); in access_journal_data()
792 return access_journal(ic, section, n); in access_journal_data()
795 static void section_mac(struct dm_integrity_c *ic, unsigned section, __u8 result[JOURNAL_MAC_SIZE]) in section_mac() argument
797 SHASH_DESC_ON_STACK(desc, ic->journal_mac); in section_mac()
801 desc->tfm = ic->journal_mac; in section_mac()
805 dm_integrity_io_error(ic, "crypto_shash_init", r); in section_mac()
809 if (ic->sb->flags & cpu_to_le32(SB_FLAG_FIXED_HMAC)) { in section_mac()
812 r = crypto_shash_update(desc, (__u8 *)&ic->sb->salt, SALT_SIZE); in section_mac()
814 dm_integrity_io_error(ic, "crypto_shash_update", r); in section_mac()
821 dm_integrity_io_error(ic, "crypto_shash_update", r); in section_mac()
826 for (j = 0; j < ic->journal_section_entries; j++) { in section_mac()
827 struct journal_entry *je = access_journal_entry(ic, section, j); in section_mac()
830 dm_integrity_io_error(ic, "crypto_shash_update", r); in section_mac()
835 size = crypto_shash_digestsize(ic->journal_mac); in section_mac()
840 dm_integrity_io_error(ic, "crypto_shash_final", r); in section_mac()
848 dm_integrity_io_error(ic, "digest_size", -EINVAL); in section_mac()
853 dm_integrity_io_error(ic, "crypto_shash_final", r); in section_mac()
864 static void rw_section_mac(struct dm_integrity_c *ic, unsigned section, bool wr) in rw_section_mac() argument
869 if (!ic->journal_mac) in rw_section_mac()
872 section_mac(ic, section, result); in rw_section_mac()
875 struct journal_sector *js = access_journal(ic, section, j); in rw_section_mac()
881 dm_integrity_io_error(ic, "journal mac", -EILSEQ); in rw_section_mac()
894 static void xor_journal(struct dm_integrity_c *ic, bool encrypt, unsigned section, in xor_journal() argument
898 size_t n_bytes = (size_t)(n_sections * ic->journal_section_sectors) << SECTOR_SHIFT; in xor_journal()
903 source_pl = ic->journal; in xor_journal()
904 target_pl = ic->journal_io; in xor_journal()
906 source_pl = ic->journal_io; in xor_journal()
907 target_pl = ic->journal; in xor_journal()
910 page_list_location(ic, section, 0, &pl_index, &pl_offset); in xor_journal()
926 rw_section_mac(ic, section, true); in xor_journal()
931 page_list_location(ic, section, 0, §ion_index, &dummy); in xor_journal()
937 src_pages[1] = ic->journal_xor[pl_index].page; in xor_journal()
956 complete(&comp->ic->crypto_backoff); in complete_journal_encrypt()
959 dm_integrity_io_error(comp->ic, "asynchronous encrypt", err); in complete_journal_encrypt()
978 wait_for_completion(&comp->ic->crypto_backoff); in do_crypt()
979 reinit_completion(&comp->ic->crypto_backoff); in do_crypt()
982 dm_integrity_io_error(comp->ic, "encrypt", r); in do_crypt()
986 static void crypt_journal(struct dm_integrity_c *ic, bool encrypt, unsigned section, in crypt_journal() argument
995 source_sg = ic->journal_scatterlist; in crypt_journal()
996 target_sg = ic->journal_io_scatterlist; in crypt_journal()
998 source_sg = ic->journal_io_scatterlist; in crypt_journal()
999 target_sg = ic->journal_scatterlist; in crypt_journal()
1008 rw_section_mac(ic, section, true); in crypt_journal()
1010 req = ic->sk_requests[section]; in crypt_journal()
1011 ivsize = crypto_skcipher_ivsize(ic->journal_crypt); in crypt_journal()
1030 static void encrypt_journal(struct dm_integrity_c *ic, bool encrypt, unsigned section, in encrypt_journal() argument
1033 if (ic->journal_xor) in encrypt_journal()
1034 return xor_journal(ic, encrypt, section, n_sections, comp); in encrypt_journal()
1036 return crypt_journal(ic, encrypt, section, n_sections, comp); in encrypt_journal()
1043 dm_integrity_io_error(comp->ic, "writing journal", -EIO); in complete_journal_io()
1047 static void rw_journal_sectors(struct dm_integrity_c *ic, int op, int op_flags, in rw_journal_sectors() argument
1055 if (unlikely(dm_integrity_failed(ic))) { in rw_journal_sectors()
1067 if (ic->journal_io) in rw_journal_sectors()
1068 io_req.mem.ptr.pl = &ic->journal_io[pl_index]; in rw_journal_sectors()
1070 io_req.mem.ptr.pl = &ic->journal[pl_index]; in rw_journal_sectors()
1078 io_req.client = ic->io; in rw_journal_sectors()
1079 io_loc.bdev = ic->meta_dev ? ic->meta_dev->bdev : ic->dev->bdev; in rw_journal_sectors()
1080 io_loc.sector = ic->start + SB_SECTORS + sector; in rw_journal_sectors()
1085 dm_integrity_io_error(ic, op == REQ_OP_READ ? "reading journal" : "writing journal", r); in rw_journal_sectors()
1093 static void rw_journal(struct dm_integrity_c *ic, int op, int op_flags, unsigned section, in rw_journal() argument
1098 sector = section * ic->journal_section_sectors; in rw_journal()
1099 n_sectors = n_sections * ic->journal_section_sectors; in rw_journal()
1101 rw_journal_sectors(ic, op, op_flags, sector, n_sectors, comp); in rw_journal()
1104 static void write_journal(struct dm_integrity_c *ic, unsigned commit_start, unsigned commit_section… in write_journal() argument
1111 io_comp.ic = ic; in write_journal()
1114 if (commit_start + commit_sections <= ic->journal_sections) { in write_journal()
1116 if (ic->journal_io) { in write_journal()
1117 crypt_comp_1.ic = ic; in write_journal()
1120 encrypt_journal(ic, true, commit_start, commit_sections, &crypt_comp_1); in write_journal()
1124 rw_section_mac(ic, commit_start + i, true); in write_journal()
1126 rw_journal(ic, REQ_OP_WRITE, REQ_FUA | REQ_SYNC, commit_start, in write_journal()
1131 to_end = ic->journal_sections - commit_start; in write_journal()
1132 if (ic->journal_io) { in write_journal()
1133 crypt_comp_1.ic = ic; in write_journal()
1136 encrypt_journal(ic, true, commit_start, to_end, &crypt_comp_1); in write_journal()
1138 rw_journal(ic, REQ_OP_WRITE, REQ_FUA, commit_start, to_end, &io_comp); in write_journal()
1141 encrypt_journal(ic, true, 0, commit_sections - to_end, &crypt_comp_1); in write_journal()
1144 crypt_comp_2.ic = ic; in write_journal()
1147 encrypt_journal(ic, true, 0, commit_sections - to_end, &crypt_comp_2); in write_journal()
1149 rw_journal(ic, REQ_OP_WRITE, REQ_FUA, commit_start, to_end, &io_comp); in write_journal()
1154 rw_section_mac(ic, commit_start + i, true); in write_journal()
1155 rw_journal(ic, REQ_OP_WRITE, REQ_FUA, commit_start, to_end, &io_comp); in write_journal()
1157 rw_section_mac(ic, i, true); in write_journal()
1159 rw_journal(ic, REQ_OP_WRITE, REQ_FUA, 0, commit_sections - to_end, &io_comp); in write_journal()
1165 static void copy_from_journal(struct dm_integrity_c *ic, unsigned section, unsigned offset, in copy_from_journal() argument
1173 BUG_ON((target | n_sectors | offset) & (unsigned)(ic->sectors_per_block - 1)); in copy_from_journal()
1175 if (unlikely(dm_integrity_failed(ic))) { in copy_from_journal()
1180 sector = section * ic->journal_section_sectors + JOURNAL_BLOCK_SECTORS + offset; in copy_from_journal()
1188 io_req.mem.ptr.pl = &ic->journal[pl_index]; in copy_from_journal()
1192 io_req.client = ic->io; in copy_from_journal()
1193 io_loc.bdev = ic->dev->bdev; in copy_from_journal()
1210 static bool add_new_range(struct dm_integrity_c *ic, struct dm_integrity_range *new_range, bool che… in add_new_range() argument
1212 struct rb_node **n = &ic->in_progress.rb_node; in add_new_range()
1215 BUG_ON((new_range->logical_sector | new_range->n_sectors) & (unsigned)(ic->sectors_per_block - 1)); in add_new_range()
1219 list_for_each_entry(range, &ic->wait_list, wait_entry) { in add_new_range()
1241 rb_insert_color(&new_range->node, &ic->in_progress); in add_new_range()
1246 static void remove_range_unlocked(struct dm_integrity_c *ic, struct dm_integrity_range *range) in remove_range_unlocked() argument
1248 rb_erase(&range->node, &ic->in_progress); in remove_range_unlocked()
1249 while (unlikely(!list_empty(&ic->wait_list))) { in remove_range_unlocked()
1251 list_first_entry(&ic->wait_list, struct dm_integrity_range, wait_entry); in remove_range_unlocked()
1255 if (!add_new_range(ic, last_range, false)) { in remove_range_unlocked()
1257 list_add(&last_range->wait_entry, &ic->wait_list); in remove_range_unlocked()
1265 static void remove_range(struct dm_integrity_c *ic, struct dm_integrity_range *range) in remove_range() argument
1269 spin_lock_irqsave(&ic->endio_wait.lock, flags); in remove_range()
1270 remove_range_unlocked(ic, range); in remove_range()
1271 spin_unlock_irqrestore(&ic->endio_wait.lock, flags); in remove_range()
1274 static void wait_and_add_new_range(struct dm_integrity_c *ic, struct dm_integrity_range *new_range) in wait_and_add_new_range() argument
1277 list_add_tail(&new_range->wait_entry, &ic->wait_list); in wait_and_add_new_range()
1281 spin_unlock_irq(&ic->endio_wait.lock); in wait_and_add_new_range()
1283 spin_lock_irq(&ic->endio_wait.lock); in wait_and_add_new_range()
1287 static void add_new_range_and_wait(struct dm_integrity_c *ic, struct dm_integrity_range *new_range) in add_new_range_and_wait() argument
1289 if (unlikely(!add_new_range(ic, new_range, true))) in add_new_range_and_wait()
1290 wait_and_add_new_range(ic, new_range); in add_new_range_and_wait()
1299 static void add_journal_node(struct dm_integrity_c *ic, struct journal_node *node, sector_t sector) in add_journal_node() argument
1307 link = &ic->journal_tree_root.rb_node; in add_journal_node()
1321 rb_insert_color(&node->node, &ic->journal_tree_root); in add_journal_node()
1324 static void remove_journal_node(struct dm_integrity_c *ic, struct journal_node *node) in remove_journal_node() argument
1327 rb_erase(&node->node, &ic->journal_tree_root); in remove_journal_node()
1333 static unsigned find_journal_node(struct dm_integrity_c *ic, sector_t sector, sector_t *next_sector) in find_journal_node() argument
1335 struct rb_node *n = ic->journal_tree_root.rb_node; in find_journal_node()
1341 found = j - ic->journal_tree; in find_journal_node()
1354 static bool test_journal_node(struct dm_integrity_c *ic, unsigned pos, sector_t sector) in test_journal_node() argument
1359 if (unlikely(pos >= ic->journal_entries)) in test_journal_node()
1361 node = &ic->journal_tree[pos]; in test_journal_node()
1375 static bool find_newer_committed_node(struct dm_integrity_c *ic, struct journal_node *node) in find_newer_committed_node() argument
1392 next_section = (unsigned)(next_node - ic->journal_tree) / ic->journal_section_entries; in find_newer_committed_node()
1393 if (next_section >= ic->committed_section && in find_newer_committed_node()
1394 next_section < ic->committed_section + ic->n_committed_sections) in find_newer_committed_node()
1396 if (next_section + ic->journal_sections < ic->committed_section + ic->n_committed_sections) in find_newer_committed_node()
1406 static int dm_integrity_rw_tag(struct dm_integrity_c *ic, unsigned char *tag, sector_t *metadata_bl… in dm_integrity_rw_tag() argument
1412 unsigned may_be = MAY_BE_HASH | (ic->discard ? MAY_BE_FILLER : 0); in dm_integrity_rw_tag()
1420 r = dm_integrity_failed(ic); in dm_integrity_rw_tag()
1424 data = dm_bufio_read(ic->bufio, *metadata_block, &b); in dm_integrity_rw_tag()
1428 to_copy = min((1U << SECTOR_SHIFT << ic->log2_buffer_sectors) - *metadata_offset, total_size); in dm_integrity_rw_tag()
1440 if (likely(is_power_of_2(ic->tag_size))) { in dm_integrity_rw_tag()
1442 if (unlikely(!ic->discard) || in dm_integrity_rw_tag()
1457 if (unlikely(hash_offset == ic->tag_size)) { in dm_integrity_rw_tag()
1463 may_be = MAY_BE_HASH | (ic->discard ? MAY_BE_FILLER : 0); in dm_integrity_rw_tag()
1472 if (unlikely(*metadata_offset == 1U << SECTOR_SHIFT << ic->log2_buffer_sectors)) { in dm_integrity_rw_tag()
1477 if (unlikely(!is_power_of_2(ic->tag_size))) { in dm_integrity_rw_tag()
1478 hash_offset = (hash_offset + to_copy) % ic->tag_size; in dm_integrity_rw_tag()
1492 struct dm_integrity_c *ic; member
1500 dm_integrity_io_error(fr->ic, "flushing disk cache", -EIO); in flush_notify()
1504 static void dm_integrity_flush_buffers(struct dm_integrity_c *ic, bool flush_data) in dm_integrity_flush_buffers() argument
1510 if (!ic->meta_dev) in dm_integrity_flush_buffers()
1519 fr.io_req.client = dm_bufio_get_dm_io_client(ic->bufio), in dm_integrity_flush_buffers()
1520 fr.io_reg.bdev = ic->dev->bdev, in dm_integrity_flush_buffers()
1523 fr.ic = ic; in dm_integrity_flush_buffers()
1529 r = dm_bufio_write_dirty_buffers(ic->bufio); in dm_integrity_flush_buffers()
1531 dm_integrity_io_error(ic, "writing tags", r); in dm_integrity_flush_buffers()
1537 static void sleep_on_endio_wait(struct dm_integrity_c *ic) in sleep_on_endio_wait() argument
1540 __add_wait_queue(&ic->endio_wait, &wait); in sleep_on_endio_wait()
1542 spin_unlock_irq(&ic->endio_wait.lock); in sleep_on_endio_wait()
1544 spin_lock_irq(&ic->endio_wait.lock); in sleep_on_endio_wait()
1545 __remove_wait_queue(&ic->endio_wait, &wait); in sleep_on_endio_wait()
1550 struct dm_integrity_c *ic = from_timer(ic, t, autocommit_timer); in autocommit_fn() local
1552 if (likely(!dm_integrity_failed(ic))) in autocommit_fn()
1553 queue_work(ic->commit_wq, &ic->commit_work); in autocommit_fn()
1556 static void schedule_autocommit(struct dm_integrity_c *ic) in schedule_autocommit() argument
1558 if (!timer_pending(&ic->autocommit_timer)) in schedule_autocommit()
1559 mod_timer(&ic->autocommit_timer, jiffies + ic->autocommit_jiffies); in schedule_autocommit()
1562 static void submit_flush_bio(struct dm_integrity_c *ic, struct dm_integrity_io *dio) in submit_flush_bio() argument
1567 spin_lock_irqsave(&ic->endio_wait.lock, flags); in submit_flush_bio()
1569 bio_list_add(&ic->flush_bio_list, bio); in submit_flush_bio()
1570 spin_unlock_irqrestore(&ic->endio_wait.lock, flags); in submit_flush_bio()
1572 queue_work(ic->commit_wq, &ic->commit_work); in submit_flush_bio()
1575 static void do_endio(struct dm_integrity_c *ic, struct bio *bio) in do_endio() argument
1577 int r = dm_integrity_failed(ic); in do_endio()
1580 if (unlikely(ic->synchronous_mode) && bio_op(bio) == REQ_OP_WRITE) { in do_endio()
1582 spin_lock_irqsave(&ic->endio_wait.lock, flags); in do_endio()
1583 bio_list_add(&ic->synchronous_bios, bio); in do_endio()
1584 queue_delayed_work(ic->commit_wq, &ic->bitmap_flush_work, 0); in do_endio()
1585 spin_unlock_irqrestore(&ic->endio_wait.lock, flags); in do_endio()
1591 static void do_endio_flush(struct dm_integrity_c *ic, struct dm_integrity_io *dio) in do_endio_flush() argument
1595 if (unlikely(dio->fua) && likely(!bio->bi_status) && likely(!dm_integrity_failed(ic))) in do_endio_flush()
1596 submit_flush_bio(ic, dio); in do_endio_flush()
1598 do_endio(ic, bio); in do_endio_flush()
1604 struct dm_integrity_c *ic = dio->ic; in dec_in_flight() local
1607 remove_range(ic, &dio->range); in dec_in_flight()
1610 schedule_autocommit(ic); in dec_in_flight()
1620 queue_work(ic->offload_wq, &dio->work); in dec_in_flight()
1623 do_endio_flush(ic, dio); in dec_in_flight()
1641 static void integrity_sector_checksum(struct dm_integrity_c *ic, sector_t sector, in integrity_sector_checksum() argument
1645 SHASH_DESC_ON_STACK(req, ic->internal_hash); in integrity_sector_checksum()
1649 req->tfm = ic->internal_hash; in integrity_sector_checksum()
1653 dm_integrity_io_error(ic, "crypto_shash_init", r); in integrity_sector_checksum()
1657 if (ic->sb->flags & cpu_to_le32(SB_FLAG_FIXED_HMAC)) { in integrity_sector_checksum()
1658 r = crypto_shash_update(req, (__u8 *)&ic->sb->salt, SALT_SIZE); in integrity_sector_checksum()
1660 dm_integrity_io_error(ic, "crypto_shash_update", r); in integrity_sector_checksum()
1667 dm_integrity_io_error(ic, "crypto_shash_update", r); in integrity_sector_checksum()
1671 r = crypto_shash_update(req, data, ic->sectors_per_block << SECTOR_SHIFT); in integrity_sector_checksum()
1673 dm_integrity_io_error(ic, "crypto_shash_update", r); in integrity_sector_checksum()
1679 dm_integrity_io_error(ic, "crypto_shash_final", r); in integrity_sector_checksum()
1683 digest_size = crypto_shash_digestsize(ic->internal_hash); in integrity_sector_checksum()
1684 if (unlikely(digest_size < ic->tag_size)) in integrity_sector_checksum()
1685 memset(result + digest_size, 0, ic->tag_size - digest_size); in integrity_sector_checksum()
1691 get_random_bytes(result, ic->tag_size); in integrity_sector_checksum()
1697 struct dm_integrity_c *ic = dio->ic; in integrity_metadata() local
1701 if (ic->internal_hash) { in integrity_metadata()
1704 unsigned digest_size = crypto_shash_digestsize(ic->internal_hash); in integrity_metadata()
1707 unsigned extra_space = unlikely(digest_size > ic->tag_size) ? digest_size - ic->tag_size : 0; in integrity_metadata()
1712 if (unlikely(ic->mode == 'R')) in integrity_metadata()
1716 …checksums = kmalloc((PAGE_SIZE >> SECTOR_SHIFT >> ic->sb->log2_sectors_per_block) * ic->tag_size +… in integrity_metadata()
1733 unsigned max_blocks = max_size / ic->tag_size; in integrity_metadata()
1737 unsigned this_step_blocks = bi_size >> (SECTOR_SHIFT + ic->sb->log2_sectors_per_block); in integrity_metadata()
1739 r = dm_integrity_rw_tag(ic, checksums, &dio->metadata_block, &dio->metadata_offset, in integrity_metadata()
1740 this_step_blocks * ic->tag_size, TAG_WRITE); in integrity_metadata()
1752 bi_size -= this_step_blocks << (SECTOR_SHIFT + ic->sb->log2_sectors_per_block); in integrity_metadata()
1753 bi_sector += this_step_blocks << ic->sb->log2_sectors_per_block; in integrity_metadata()
1774 integrity_sector_checksum(ic, sector, mem + pos, checksums_ptr); in integrity_metadata()
1775 checksums_ptr += ic->tag_size; in integrity_metadata()
1776 sectors_to_process -= ic->sectors_per_block; in integrity_metadata()
1777 pos += ic->sectors_per_block << SECTOR_SHIFT; in integrity_metadata()
1778 sector += ic->sectors_per_block; in integrity_metadata()
1782 r = dm_integrity_rw_tag(ic, checksums, &dio->metadata_block, &dio->metadata_offset, in integrity_metadata()
1788 (sector - ((r + ic->tag_size - 1) / ic->tag_size))); in integrity_metadata()
1790 atomic64_inc(&ic->number_of_mismatches); in integrity_metadata()
1816 sector_to_block(ic, data_to_process); in integrity_metadata()
1817 data_to_process *= ic->tag_size; in integrity_metadata()
1826 r = dm_integrity_rw_tag(ic, tag, &dio->metadata_block, &dio->metadata_offset, in integrity_metadata()
1846 struct dm_integrity_c *ic = ti->private; in dm_integrity_map() local
1852 dio->ic = ic; in dm_integrity_map()
1870 submit_flush_bio(ic, dio); in dm_integrity_map()
1883 if (unlikely(dio->range.logical_sector + bio_sectors(bio) > ic->provided_data_sectors)) { in dm_integrity_map()
1886 ic->provided_data_sectors); in dm_integrity_map()
1889 …if (unlikely((dio->range.logical_sector | bio_sectors(bio)) & (unsigned)(ic->sectors_per_block - 1… in dm_integrity_map()
1891 ic->sectors_per_block, in dm_integrity_map()
1896 if (ic->sectors_per_block > 1 && likely(dio->op != REQ_OP_DISCARD)) { in dm_integrity_map()
1900 if (unlikely(bv.bv_len & ((ic->sectors_per_block << SECTOR_SHIFT) - 1))) { in dm_integrity_map()
1902 bv.bv_offset, bv.bv_len, ic->sectors_per_block); in dm_integrity_map()
1909 if (!ic->internal_hash) { in dm_integrity_map()
1911 unsigned wanted_tag_size = bio_sectors(bio) >> ic->sb->log2_sectors_per_block; in dm_integrity_map()
1912 if (ic->log2_tag_size >= 0) in dm_integrity_map()
1913 wanted_tag_size <<= ic->log2_tag_size; in dm_integrity_map()
1915 wanted_tag_size *= ic->tag_size; in dm_integrity_map()
1929 if (unlikely(ic->mode == 'R') && unlikely(dio->op != REQ_OP_READ)) in dm_integrity_map()
1932 get_area_and_offset(ic, dio->range.logical_sector, &area, &offset); in dm_integrity_map()
1933 dio->metadata_block = get_metadata_sector_and_offset(ic, area, offset, &dio->metadata_offset); in dm_integrity_map()
1934 bio->bi_iter.bi_sector = get_data_sector(ic, area, offset); in dm_integrity_map()
1943 struct dm_integrity_c *ic = dio->ic; in __journal_read_write() local
1963 struct journal_entry *je = access_journal_entry(ic, journal_section, journal_entry); in __journal_read_write()
1974 __io_wait_event(ic->copy_to_journal_wait, !journal_entry_is_inprogress(je)); in __journal_read_write()
1979 js = access_journal_data(ic, journal_section, journal_entry); in __journal_read_write()
1987 } while (++s < ic->sectors_per_block); in __journal_read_write()
1989 if (ic->internal_hash) { in __journal_read_write()
1992 integrity_sector_checksum(ic, logical_sector, mem + bv.bv_offset, checksums_onstack); in __journal_read_write()
1993 if (unlikely(memcmp(checksums_onstack, journal_entry_tag(ic, je), ic->tag_size))) { in __journal_read_write()
2001 if (!ic->internal_hash) { in __journal_read_write()
2003 unsigned tag_todo = ic->tag_size; in __journal_read_write()
2004 char *tag_ptr = journal_entry_tag(ic, je); in __journal_read_write()
2029 js = access_journal_data(ic, journal_section, journal_entry); in __journal_read_write()
2030 memcpy(js, mem + bv.bv_offset, ic->sectors_per_block << SECTOR_SHIFT); in __journal_read_write()
2035 } while (++s < ic->sectors_per_block); in __journal_read_write()
2037 if (ic->internal_hash) { in __journal_read_write()
2038 unsigned digest_size = crypto_shash_digestsize(ic->internal_hash); in __journal_read_write()
2039 if (unlikely(digest_size > ic->tag_size)) { in __journal_read_write()
2041 integrity_sector_checksum(ic, logical_sector, (char *)js, checksums_onstack); in __journal_read_write()
2042 memcpy(journal_entry_tag(ic, je), checksums_onstack, ic->tag_size); in __journal_read_write()
2044 integrity_sector_checksum(ic, logical_sector, (char *)js, journal_entry_tag(ic, je)); in __journal_read_write()
2049 logical_sector += ic->sectors_per_block; in __journal_read_write()
2052 if (unlikely(journal_entry == ic->journal_section_entries)) { in __journal_read_write()
2055 wraparound_section(ic, &journal_section); in __journal_read_write()
2058 bv.bv_offset += ic->sectors_per_block << SECTOR_SHIFT; in __journal_read_write()
2059 } while (bv.bv_len -= ic->sectors_per_block << SECTOR_SHIFT); in __journal_read_write()
2068 if (unlikely(waitqueue_active(&ic->copy_to_journal_wait))) in __journal_read_write()
2069 wake_up(&ic->copy_to_journal_wait); in __journal_read_write()
2070 if (READ_ONCE(ic->free_sectors) <= ic->free_sectors_threshold) { in __journal_read_write()
2071 queue_work(ic->commit_wq, &ic->commit_work); in __journal_read_write()
2073 schedule_autocommit(ic); in __journal_read_write()
2076 remove_range(ic, &dio->range); in __journal_read_write()
2083 get_area_and_offset(ic, dio->range.logical_sector, &area, &offset); in __journal_read_write()
2084 dio->metadata_block = get_metadata_sector_and_offset(ic, area, offset, &dio->metadata_offset); in __journal_read_write()
2093 struct dm_integrity_c *ic = dio->ic; in dm_integrity_map_continue() local
2099 bool need_sync_io = ic->internal_hash && dio->op == REQ_OP_READ; in dm_integrity_map_continue()
2100 if (unlikely(dio->op == REQ_OP_DISCARD) && ic->mode != 'D') in dm_integrity_map_continue()
2105 queue_work(ic->offload_wq, &dio->work); in dm_integrity_map_continue()
2110 spin_lock_irq(&ic->endio_wait.lock); in dm_integrity_map_continue()
2112 if (unlikely(dm_integrity_failed(ic))) { in dm_integrity_map_continue()
2113 spin_unlock_irq(&ic->endio_wait.lock); in dm_integrity_map_continue()
2114 do_endio(ic, bio); in dm_integrity_map_continue()
2119 if (ic->mode == 'J' && likely(dio->op != REQ_OP_DISCARD)) { in dm_integrity_map_continue()
2125 (sector_t)ic->free_sectors << ic->sb->log2_sectors_per_block); in dm_integrity_map_continue()
2129 sleep_on_endio_wait(ic); in dm_integrity_map_continue()
2132 range_sectors = dio->range.n_sectors >> ic->sb->log2_sectors_per_block; in dm_integrity_map_continue()
2133 ic->free_sectors -= range_sectors; in dm_integrity_map_continue()
2134 journal_section = ic->free_section; in dm_integrity_map_continue()
2135 journal_entry = ic->free_section_entry; in dm_integrity_map_continue()
2137 next_entry = ic->free_section_entry + range_sectors; in dm_integrity_map_continue()
2138 ic->free_section_entry = next_entry % ic->journal_section_entries; in dm_integrity_map_continue()
2139 ic->free_section += next_entry / ic->journal_section_entries; in dm_integrity_map_continue()
2140 ic->n_uncommitted_sections += next_entry / ic->journal_section_entries; in dm_integrity_map_continue()
2141 wraparound_section(ic, &ic->free_section); in dm_integrity_map_continue()
2143 pos = journal_section * ic->journal_section_entries + journal_entry; in dm_integrity_map_continue()
2150 add_journal_node(ic, &ic->journal_tree[pos], dio->range.logical_sector + i); in dm_integrity_map_continue()
2152 if (unlikely(pos >= ic->journal_entries)) in dm_integrity_map_continue()
2155 je = access_journal_entry(ic, ws, we); in dm_integrity_map_continue()
2159 if (unlikely(we == ic->journal_section_entries)) { in dm_integrity_map_continue()
2162 wraparound_section(ic, &ws); in dm_integrity_map_continue()
2164 } while ((i += ic->sectors_per_block) < dio->range.n_sectors); in dm_integrity_map_continue()
2166 spin_unlock_irq(&ic->endio_wait.lock); in dm_integrity_map_continue()
2170 journal_read_pos = find_journal_node(ic, dio->range.logical_sector, &next_sector); in dm_integrity_map_continue()
2177 for (i = ic->sectors_per_block; i < dio->range.n_sectors; i += ic->sectors_per_block, jp++) { in dm_integrity_map_continue()
2178 if (!test_journal_node(ic, jp, dio->range.logical_sector + i)) in dm_integrity_map_continue()
2185 if (unlikely(!add_new_range(ic, &dio->range, true))) { in dm_integrity_map_continue()
2193 spin_unlock_irq(&ic->endio_wait.lock); in dm_integrity_map_continue()
2195 queue_work(ic->wait_wq, &dio->work); in dm_integrity_map_continue()
2199 dio->range.n_sectors = ic->sectors_per_block; in dm_integrity_map_continue()
2200 wait_and_add_new_range(ic, &dio->range); in dm_integrity_map_continue()
2208 unsigned new_pos = find_journal_node(ic, dio->range.logical_sector, &next_sector); in dm_integrity_map_continue()
2210 remove_range_unlocked(ic, &dio->range); in dm_integrity_map_continue()
2215 if (ic->mode == 'J' && likely(dio->op == REQ_OP_DISCARD) && !discard_retried) { in dm_integrity_map_continue()
2217 unsigned new_pos = find_journal_node(ic, dio->range.logical_sector, &next_sector); in dm_integrity_map_continue()
2220 remove_range_unlocked(ic, &dio->range); in dm_integrity_map_continue()
2221 spin_unlock_irq(&ic->endio_wait.lock); in dm_integrity_map_continue()
2222 queue_work(ic->commit_wq, &ic->commit_work); in dm_integrity_map_continue()
2223 flush_workqueue(ic->commit_wq); in dm_integrity_map_continue()
2224 queue_work(ic->writer_wq, &ic->writer_work); in dm_integrity_map_continue()
2225 flush_workqueue(ic->writer_wq); in dm_integrity_map_continue()
2230 spin_unlock_irq(&ic->endio_wait.lock); in dm_integrity_map_continue()
2233 journal_section = journal_read_pos / ic->journal_section_entries; in dm_integrity_map_continue()
2234 journal_entry = journal_read_pos % ic->journal_section_entries; in dm_integrity_map_continue()
2238 if (ic->mode == 'B' && (dio->op == REQ_OP_WRITE || unlikely(dio->op == REQ_OP_DISCARD))) { in dm_integrity_map_continue()
2239 if (!block_bitmap_op(ic, ic->may_write_bitmap, dio->range.logical_sector, in dm_integrity_map_continue()
2243 bbs = sector_to_bitmap_block(ic, dio->range.logical_sector); in dm_integrity_map_continue()
2247 queue_work(ic->writer_wq, &bbs->work); in dm_integrity_map_continue()
2261 bio_set_dev(bio, ic->dev->bdev); in dm_integrity_map_continue()
2267 if (unlikely(dio->op == REQ_OP_DISCARD) && likely(ic->mode != 'D')) { in dm_integrity_map_continue()
2269 dm_integrity_flush_buffers(ic, false); in dm_integrity_map_continue()
2283 if (ic->sb->flags & cpu_to_le32(SB_FLAG_RECALCULATING) && in dm_integrity_map_continue()
2284 dio->range.logical_sector + dio->range.n_sectors > le64_to_cpu(ic->sb->recalc_sector)) in dm_integrity_map_continue()
2286 if (ic->mode == 'B') { in dm_integrity_map_continue()
2287 if (!block_bitmap_op(ic, ic->recalc_bitmap, dio->range.logical_sector, in dm_integrity_map_continue()
2300 queue_work(ic->metadata_wq, &dio->work); in dm_integrity_map_continue()
2309 do_endio_flush(ic, dio); in dm_integrity_map_continue()
2320 static void pad_uncommitted(struct dm_integrity_c *ic) in pad_uncommitted() argument
2322 if (ic->free_section_entry) { in pad_uncommitted()
2323 ic->free_sectors -= ic->journal_section_entries - ic->free_section_entry; in pad_uncommitted()
2324 ic->free_section_entry = 0; in pad_uncommitted()
2325 ic->free_section++; in pad_uncommitted()
2326 wraparound_section(ic, &ic->free_section); in pad_uncommitted()
2327 ic->n_uncommitted_sections++; in pad_uncommitted()
2329 if (WARN_ON(ic->journal_sections * ic->journal_section_entries != in pad_uncommitted()
2330 (ic->n_uncommitted_sections + ic->n_committed_sections) * in pad_uncommitted()
2331 ic->journal_section_entries + ic->free_sectors)) { in pad_uncommitted()
2335 ic->journal_sections, ic->journal_section_entries, in pad_uncommitted()
2336 ic->n_uncommitted_sections, ic->n_committed_sections, in pad_uncommitted()
2337 ic->journal_section_entries, ic->free_sectors); in pad_uncommitted()
2343 struct dm_integrity_c *ic = container_of(w, struct dm_integrity_c, commit_work); in integrity_commit() local
2348 del_timer(&ic->autocommit_timer); in integrity_commit()
2350 spin_lock_irq(&ic->endio_wait.lock); in integrity_commit()
2351 flushes = bio_list_get(&ic->flush_bio_list); in integrity_commit()
2352 if (unlikely(ic->mode != 'J')) { in integrity_commit()
2353 spin_unlock_irq(&ic->endio_wait.lock); in integrity_commit()
2354 dm_integrity_flush_buffers(ic, true); in integrity_commit()
2358 pad_uncommitted(ic); in integrity_commit()
2359 commit_start = ic->uncommitted_section; in integrity_commit()
2360 commit_sections = ic->n_uncommitted_sections; in integrity_commit()
2361 spin_unlock_irq(&ic->endio_wait.lock); in integrity_commit()
2366 ic->wrote_to_journal = true; in integrity_commit()
2370 for (j = 0; j < ic->journal_section_entries; j++) { in integrity_commit()
2372 je = access_journal_entry(ic, i, j); in integrity_commit()
2373 io_wait_event(ic->copy_to_journal_wait, !journal_entry_is_inprogress(je)); in integrity_commit()
2375 for (j = 0; j < ic->journal_section_sectors; j++) { in integrity_commit()
2377 js = access_journal(ic, i, j); in integrity_commit()
2378 js->commit_id = dm_integrity_commit_id(ic, i, j, ic->commit_seq); in integrity_commit()
2381 if (unlikely(i >= ic->journal_sections)) in integrity_commit()
2382 ic->commit_seq = next_commit_seq(ic->commit_seq); in integrity_commit()
2383 wraparound_section(ic, &i); in integrity_commit()
2387 write_journal(ic, commit_start, commit_sections); in integrity_commit()
2389 spin_lock_irq(&ic->endio_wait.lock); in integrity_commit()
2390 ic->uncommitted_section += commit_sections; in integrity_commit()
2391 wraparound_section(ic, &ic->uncommitted_section); in integrity_commit()
2392 ic->n_uncommitted_sections -= commit_sections; in integrity_commit()
2393 ic->n_committed_sections += commit_sections; in integrity_commit()
2394 spin_unlock_irq(&ic->endio_wait.lock); in integrity_commit()
2396 if (READ_ONCE(ic->free_sectors) <= ic->free_sectors_threshold) in integrity_commit()
2397 queue_work(ic->writer_wq, &ic->writer_work); in integrity_commit()
2403 do_endio(ic, flushes); in integrity_commit()
2412 struct dm_integrity_c *ic = comp->ic; in complete_copy_from_journal() local
2413 remove_range(ic, &io->range); in complete_copy_from_journal()
2414 mempool_free(io, &ic->journal_io_mempool); in complete_copy_from_journal()
2416 dm_integrity_io_error(ic, "copying from journal", -EIO); in complete_copy_from_journal()
2420 static void restore_last_bytes(struct dm_integrity_c *ic, struct journal_sector *js, in restore_last_bytes() argument
2427 } while (++s < ic->sectors_per_block); in restore_last_bytes()
2430 static void do_journal_write(struct dm_integrity_c *ic, unsigned write_start, in do_journal_write() argument
2439 comp.ic = ic; in do_journal_write()
2444 for (n = 0; n < write_sections; n++, i++, wraparound_section(ic, &i)) { in do_journal_write()
2448 rw_section_mac(ic, i, false); in do_journal_write()
2449 for (j = 0; j < ic->journal_section_entries; j++) { in do_journal_write()
2450 struct journal_entry *je = access_journal_entry(ic, i, j); in do_journal_write()
2462 if (unlikely(sec & (unsigned)(ic->sectors_per_block - 1))) { in do_journal_write()
2463 dm_integrity_io_error(ic, "invalid sector in journal", -EIO); in do_journal_write()
2464 sec &= ~(sector_t)(ic->sectors_per_block - 1); in do_journal_write()
2466 if (unlikely(sec >= ic->provided_data_sectors)) { in do_journal_write()
2471 get_area_and_offset(ic, sec, &area, &offset); in do_journal_write()
2472 restore_last_bytes(ic, access_journal_data(ic, i, j), je); in do_journal_write()
2473 for (k = j + 1; k < ic->journal_section_entries; k++) { in do_journal_write()
2474 struct journal_entry *je2 = access_journal_entry(ic, i, k); in do_journal_write()
2480 if (unlikely(sec2 >= ic->provided_data_sectors)) in do_journal_write()
2482 get_area_and_offset(ic, sec2, &area2, &offset2); in do_journal_write()
2483 if (area2 != area || offset2 != offset + ((k - j) << ic->sb->log2_sectors_per_block)) in do_journal_write()
2485 restore_last_bytes(ic, access_journal_data(ic, i, k), je2); in do_journal_write()
2489 io = mempool_alloc(&ic->journal_io_mempool, GFP_NOIO); in do_journal_write()
2492 io->range.n_sectors = (k - j) << ic->sb->log2_sectors_per_block; in do_journal_write()
2494 spin_lock_irq(&ic->endio_wait.lock); in do_journal_write()
2495 add_new_range_and_wait(ic, &io->range); in do_journal_write()
2498 struct journal_node *section_node = &ic->journal_tree[i * ic->journal_section_entries]; in do_journal_write()
2501 while (j < k && find_newer_committed_node(ic, §ion_node[j])) { in do_journal_write()
2502 struct journal_entry *je2 = access_journal_entry(ic, i, j); in do_journal_write()
2505 remove_journal_node(ic, §ion_node[j]); in do_journal_write()
2507 sec += ic->sectors_per_block; in do_journal_write()
2508 offset += ic->sectors_per_block; in do_journal_write()
2510 while (j < k && find_newer_committed_node(ic, §ion_node[k - 1])) { in do_journal_write()
2511 struct journal_entry *je2 = access_journal_entry(ic, i, k - 1); in do_journal_write()
2514 remove_journal_node(ic, §ion_node[k - 1]); in do_journal_write()
2518 remove_range_unlocked(ic, &io->range); in do_journal_write()
2519 spin_unlock_irq(&ic->endio_wait.lock); in do_journal_write()
2520 mempool_free(io, &ic->journal_io_mempool); in do_journal_write()
2524 remove_journal_node(ic, §ion_node[l]); in do_journal_write()
2527 spin_unlock_irq(&ic->endio_wait.lock); in do_journal_write()
2529 metadata_block = get_metadata_sector_and_offset(ic, area, offset, &metadata_offset); in do_journal_write()
2532 struct journal_entry *je2 = access_journal_entry(ic, i, l); in do_journal_write()
2538 ic->internal_hash) { in do_journal_write()
2541 integrity_sector_checksum(ic, sec + ((l - j) << ic->sb->log2_sectors_per_block), in do_journal_write()
2542 (char *)access_journal_data(ic, i, l), test_tag); in do_journal_write()
2543 if (unlikely(memcmp(test_tag, journal_entry_tag(ic, je2), ic->tag_size))) in do_journal_write()
2544 dm_integrity_io_error(ic, "tag mismatch when replaying journal", -EILSEQ); in do_journal_write()
2548 r = dm_integrity_rw_tag(ic, journal_entry_tag(ic, je2), &metadata_block, &metadata_offset, in do_journal_write()
2549 ic->tag_size, TAG_WRITE); in do_journal_write()
2551 dm_integrity_io_error(ic, "reading tags", r); in do_journal_write()
2556 copy_from_journal(ic, i, j << ic->sb->log2_sectors_per_block, in do_journal_write()
2557 (k - j) << ic->sb->log2_sectors_per_block, in do_journal_write()
2558 get_data_sector(ic, area, offset), in do_journal_write()
2565 dm_bufio_write_dirty_buffers_async(ic->bufio); in do_journal_write()
2572 dm_integrity_flush_buffers(ic, true); in do_journal_write()
2577 struct dm_integrity_c *ic = container_of(w, struct dm_integrity_c, writer_work); in integrity_writer() local
2582 spin_lock_irq(&ic->endio_wait.lock); in integrity_writer()
2583 write_start = ic->committed_section; in integrity_writer()
2584 write_sections = ic->n_committed_sections; in integrity_writer()
2585 spin_unlock_irq(&ic->endio_wait.lock); in integrity_writer()
2590 do_journal_write(ic, write_start, write_sections, false); in integrity_writer()
2592 spin_lock_irq(&ic->endio_wait.lock); in integrity_writer()
2594 ic->committed_section += write_sections; in integrity_writer()
2595 wraparound_section(ic, &ic->committed_section); in integrity_writer()
2596 ic->n_committed_sections -= write_sections; in integrity_writer()
2598 prev_free_sectors = ic->free_sectors; in integrity_writer()
2599 ic->free_sectors += write_sections * ic->journal_section_entries; in integrity_writer()
2601 wake_up_locked(&ic->endio_wait); in integrity_writer()
2603 spin_unlock_irq(&ic->endio_wait.lock); in integrity_writer()
2606 static void recalc_write_super(struct dm_integrity_c *ic) in recalc_write_super() argument
2610 dm_integrity_flush_buffers(ic, false); in recalc_write_super()
2611 if (dm_integrity_failed(ic)) in recalc_write_super()
2614 r = sync_rw_sb(ic, REQ_OP_WRITE, 0); in recalc_write_super()
2616 dm_integrity_io_error(ic, "writing superblock", r); in recalc_write_super()
2621 struct dm_integrity_c *ic = container_of(w, struct dm_integrity_c, recalc_work); in integrity_recalc() local
2634 DEBUG_print("start recalculation... (position %llx)\n", le64_to_cpu(ic->sb->recalc_sector)); in integrity_recalc()
2636 spin_lock_irq(&ic->endio_wait.lock); in integrity_recalc()
2640 if (unlikely(dm_post_suspending(ic->ti))) in integrity_recalc()
2643 range.logical_sector = le64_to_cpu(ic->sb->recalc_sector); in integrity_recalc()
2644 if (unlikely(range.logical_sector >= ic->provided_data_sectors)) { in integrity_recalc()
2645 if (ic->mode == 'B') { in integrity_recalc()
2646 block_bitmap_op(ic, ic->recalc_bitmap, 0, ic->provided_data_sectors, BITMAP_OP_CLEAR); in integrity_recalc()
2648 queue_delayed_work(ic->commit_wq, &ic->bitmap_flush_work, 0); in integrity_recalc()
2653 get_area_and_offset(ic, range.logical_sector, &area, &offset); in integrity_recalc()
2654 range.n_sectors = min((sector_t)RECALC_SECTORS, ic->provided_data_sectors - range.logical_sector); in integrity_recalc()
2655 if (!ic->meta_dev) in integrity_recalc()
2656 …range.n_sectors = min(range.n_sectors, ((sector_t)1U << ic->sb->log2_interleave_sectors) - (unsign… in integrity_recalc()
2658 add_new_range_and_wait(ic, &range); in integrity_recalc()
2659 spin_unlock_irq(&ic->endio_wait.lock); in integrity_recalc()
2663 if (ic->mode == 'B') { in integrity_recalc()
2664 if (block_bitmap_op(ic, ic->recalc_bitmap, logical_sector, n_sectors, BITMAP_OP_TEST_ALL_CLEAR)) { in integrity_recalc()
2667 while (block_bitmap_op(ic, ic->recalc_bitmap, logical_sector, in integrity_recalc()
2668 ic->sectors_per_block, BITMAP_OP_TEST_ALL_CLEAR)) { in integrity_recalc()
2669 logical_sector += ic->sectors_per_block; in integrity_recalc()
2670 n_sectors -= ic->sectors_per_block; in integrity_recalc()
2673 while (block_bitmap_op(ic, ic->recalc_bitmap, logical_sector + n_sectors - ic->sectors_per_block, in integrity_recalc()
2674 ic->sectors_per_block, BITMAP_OP_TEST_ALL_CLEAR)) { in integrity_recalc()
2675 n_sectors -= ic->sectors_per_block; in integrity_recalc()
2678 get_area_and_offset(ic, logical_sector, &area, &offset); in integrity_recalc()
2684 recalc_write_super(ic); in integrity_recalc()
2685 if (ic->mode == 'B') { in integrity_recalc()
2686 queue_delayed_work(ic->commit_wq, &ic->bitmap_flush_work, ic->bitmap_flush_interval); in integrity_recalc()
2691 if (unlikely(dm_integrity_failed(ic))) in integrity_recalc()
2697 io_req.mem.ptr.addr = ic->recalc_buffer; in integrity_recalc()
2699 io_req.client = ic->io; in integrity_recalc()
2700 io_loc.bdev = ic->dev->bdev; in integrity_recalc()
2701 io_loc.sector = get_data_sector(ic, area, offset); in integrity_recalc()
2706 dm_integrity_io_error(ic, "reading data", r); in integrity_recalc()
2710 t = ic->recalc_tags; in integrity_recalc()
2711 for (i = 0; i < n_sectors; i += ic->sectors_per_block) { in integrity_recalc()
2712 integrity_sector_checksum(ic, logical_sector + i, ic->recalc_buffer + (i << SECTOR_SHIFT), t); in integrity_recalc()
2713 t += ic->tag_size; in integrity_recalc()
2716 metadata_block = get_metadata_sector_and_offset(ic, area, offset, &metadata_offset); in integrity_recalc()
2718 …r = dm_integrity_rw_tag(ic, ic->recalc_tags, &metadata_block, &metadata_offset, t - ic->recalc_tag… in integrity_recalc()
2720 dm_integrity_io_error(ic, "writing tags", r); in integrity_recalc()
2724 if (ic->mode == 'B') { in integrity_recalc()
2727 (ic->sb->log2_sectors_per_block + ic->log2_blocks_per_bitmap_bit)) << in integrity_recalc()
2728 (ic->sb->log2_sectors_per_block + ic->log2_blocks_per_bitmap_bit); in integrity_recalc()
2730 (ic->sb->log2_sectors_per_block + ic->log2_blocks_per_bitmap_bit)) << in integrity_recalc()
2731 (ic->sb->log2_sectors_per_block + ic->log2_blocks_per_bitmap_bit); in integrity_recalc()
2732 block_bitmap_op(ic, ic->recalc_bitmap, start, end - start, BITMAP_OP_CLEAR); in integrity_recalc()
2738 spin_lock_irq(&ic->endio_wait.lock); in integrity_recalc()
2739 remove_range_unlocked(ic, &range); in integrity_recalc()
2740 ic->sb->recalc_sector = cpu_to_le64(range.logical_sector + range.n_sectors); in integrity_recalc()
2744 remove_range(ic, &range); in integrity_recalc()
2748 spin_unlock_irq(&ic->endio_wait.lock); in integrity_recalc()
2750 recalc_write_super(ic); in integrity_recalc()
2756 struct dm_integrity_c *ic = bbs->ic; in bitmap_block_work() local
2773 if (block_bitmap_op(ic, ic->may_write_bitmap, dio->range.logical_sector, in bitmap_block_work()
2775 remove_range(ic, &dio->range); in bitmap_block_work()
2777 queue_work(ic->offload_wq, &dio->work); in bitmap_block_work()
2779 block_bitmap_op(ic, ic->journal, dio->range.logical_sector, in bitmap_block_work()
2788 rw_journal_sectors(ic, REQ_OP_WRITE, REQ_FUA | REQ_SYNC, in bitmap_block_work()
2795 block_bitmap_op(ic, ic->may_write_bitmap, dio->range.logical_sector, in bitmap_block_work()
2798 remove_range(ic, &dio->range); in bitmap_block_work()
2800 queue_work(ic->offload_wq, &dio->work); in bitmap_block_work()
2803 queue_delayed_work(ic->commit_wq, &ic->bitmap_flush_work, ic->bitmap_flush_interval); in bitmap_block_work()
2808 struct dm_integrity_c *ic = container_of(work, struct dm_integrity_c, bitmap_flush_work.work); in bitmap_flush_work() local
2813 dm_integrity_flush_buffers(ic, false); in bitmap_flush_work()
2816 range.n_sectors = ic->provided_data_sectors; in bitmap_flush_work()
2818 spin_lock_irq(&ic->endio_wait.lock); in bitmap_flush_work()
2819 add_new_range_and_wait(ic, &range); in bitmap_flush_work()
2820 spin_unlock_irq(&ic->endio_wait.lock); in bitmap_flush_work()
2822 dm_integrity_flush_buffers(ic, true); in bitmap_flush_work()
2824 limit = ic->provided_data_sectors; in bitmap_flush_work()
2825 if (ic->sb->flags & cpu_to_le32(SB_FLAG_RECALCULATING)) { in bitmap_flush_work()
2826 limit = le64_to_cpu(ic->sb->recalc_sector) in bitmap_flush_work()
2827 >> (ic->sb->log2_sectors_per_block + ic->log2_blocks_per_bitmap_bit) in bitmap_flush_work()
2828 << (ic->sb->log2_sectors_per_block + ic->log2_blocks_per_bitmap_bit); in bitmap_flush_work()
2831 block_bitmap_op(ic, ic->journal, 0, limit, BITMAP_OP_CLEAR); in bitmap_flush_work()
2832 block_bitmap_op(ic, ic->may_write_bitmap, 0, limit, BITMAP_OP_CLEAR); in bitmap_flush_work()
2834 rw_journal_sectors(ic, REQ_OP_WRITE, REQ_FUA | REQ_SYNC, 0, in bitmap_flush_work()
2835 ic->n_bitmap_blocks * (BITMAP_BLOCK_SIZE >> SECTOR_SHIFT), NULL); in bitmap_flush_work()
2837 spin_lock_irq(&ic->endio_wait.lock); in bitmap_flush_work()
2838 remove_range_unlocked(ic, &range); in bitmap_flush_work()
2839 while (unlikely((bio = bio_list_pop(&ic->synchronous_bios)) != NULL)) { in bitmap_flush_work()
2841 spin_unlock_irq(&ic->endio_wait.lock); in bitmap_flush_work()
2842 spin_lock_irq(&ic->endio_wait.lock); in bitmap_flush_work()
2844 spin_unlock_irq(&ic->endio_wait.lock); in bitmap_flush_work()
2848 static void init_journal(struct dm_integrity_c *ic, unsigned start_section, in init_journal() argument
2858 wraparound_section(ic, &i); in init_journal()
2859 for (j = 0; j < ic->journal_section_sectors; j++) { in init_journal()
2860 struct journal_sector *js = access_journal(ic, i, j); in init_journal()
2862 js->commit_id = dm_integrity_commit_id(ic, i, j, commit_seq); in init_journal()
2864 for (j = 0; j < ic->journal_section_entries; j++) { in init_journal()
2865 struct journal_entry *je = access_journal_entry(ic, i, j); in init_journal()
2870 write_journal(ic, start_section, n_sections); in init_journal()
2873 static int find_commit_seq(struct dm_integrity_c *ic, unsigned i, unsigned j, commit_id_t id) in find_commit_seq() argument
2877 if (dm_integrity_commit_id(ic, i, j, k) == id) in find_commit_seq()
2880 dm_integrity_io_error(ic, "journal commit id", -EIO); in find_commit_seq()
2884 static void replay_journal(struct dm_integrity_c *ic) in replay_journal() argument
2894 if (ic->mode == 'R') in replay_journal()
2897 if (ic->journal_uptodate) in replay_journal()
2903 if (!ic->just_formatted) { in replay_journal()
2905 rw_journal(ic, REQ_OP_READ, 0, 0, ic->journal_sections, NULL); in replay_journal()
2906 if (ic->journal_io) in replay_journal()
2907 DEBUG_bytes(lowmem_page_address(ic->journal_io[0].page), 64, "read journal"); in replay_journal()
2908 if (ic->journal_io) { in replay_journal()
2910 crypt_comp.ic = ic; in replay_journal()
2913 encrypt_journal(ic, false, 0, ic->journal_sections, &crypt_comp); in replay_journal()
2916 DEBUG_bytes(lowmem_page_address(ic->journal[0].page), 64, "decrypted journal"); in replay_journal()
2919 if (dm_integrity_failed(ic)) in replay_journal()
2925 for (i = 0; i < ic->journal_sections; i++) { in replay_journal()
2926 for (j = 0; j < ic->journal_section_sectors; j++) { in replay_journal()
2928 struct journal_sector *js = access_journal(ic, i, j); in replay_journal()
2929 k = find_commit_seq(ic, i, j, js->commit_id); in replay_journal()
2936 for (j = 0; j < ic->journal_section_entries; j++) { in replay_journal()
2937 struct journal_entry *je = access_journal_entry(ic, i, j); in replay_journal()
2955 dm_integrity_io_error(ic, "journal commit ids", -EIO); in replay_journal()
2970 if (unlikely(write_start >= ic->journal_sections)) in replay_journal()
2972 wraparound_section(ic, &write_start); in replay_journal()
2975 for (write_sections = 0; write_sections < ic->journal_sections; write_sections++) { in replay_journal()
2976 for (j = 0; j < ic->journal_section_sectors; j++) { in replay_journal()
2977 struct journal_sector *js = access_journal(ic, i, j); in replay_journal()
2979 if (js->commit_id != dm_integrity_commit_id(ic, i, j, want_commit_seq)) { in replay_journal()
2986 i, j, find_commit_seq(ic, i, j, js->commit_id), want_commit_seq); in replay_journal()
2991 if (unlikely(i >= ic->journal_sections)) in replay_journal()
2993 wraparound_section(ic, &i); in replay_journal()
3000 do_journal_write(ic, write_start, write_sections, true); in replay_journal()
3003 if (write_sections == ic->journal_sections && (ic->mode == 'J' || journal_empty)) { in replay_journal()
3005 ic->commit_seq = want_commit_seq; in replay_journal()
3006 DEBUG_print("continuing from section %u, commit seq %d\n", write_start, ic->commit_seq); in replay_journal()
3015 init_journal(ic, s, 1, erase_seq); in replay_journal()
3017 wraparound_section(ic, &s); in replay_journal()
3018 if (ic->journal_sections >= 2) { in replay_journal()
3019 init_journal(ic, s, ic->journal_sections - 2, erase_seq); in replay_journal()
3020 s += ic->journal_sections - 2; in replay_journal()
3021 wraparound_section(ic, &s); in replay_journal()
3022 init_journal(ic, s, 1, erase_seq); in replay_journal()
3026 ic->commit_seq = next_commit_seq(erase_seq); in replay_journal()
3029 ic->committed_section = continue_section; in replay_journal()
3030 ic->n_committed_sections = 0; in replay_journal()
3032 ic->uncommitted_section = continue_section; in replay_journal()
3033 ic->n_uncommitted_sections = 0; in replay_journal()
3035 ic->free_section = continue_section; in replay_journal()
3036 ic->free_section_entry = 0; in replay_journal()
3037 ic->free_sectors = ic->journal_entries; in replay_journal()
3039 ic->journal_tree_root = RB_ROOT; in replay_journal()
3040 for (i = 0; i < ic->journal_entries; i++) in replay_journal()
3041 init_journal_node(&ic->journal_tree[i]); in replay_journal()
3044 static void dm_integrity_enter_synchronous_mode(struct dm_integrity_c *ic) in dm_integrity_enter_synchronous_mode() argument
3048 if (ic->mode == 'B') { in dm_integrity_enter_synchronous_mode()
3049 ic->bitmap_flush_interval = msecs_to_jiffies(10) + 1; in dm_integrity_enter_synchronous_mode()
3050 ic->synchronous_mode = 1; in dm_integrity_enter_synchronous_mode()
3052 cancel_delayed_work_sync(&ic->bitmap_flush_work); in dm_integrity_enter_synchronous_mode()
3053 queue_delayed_work(ic->commit_wq, &ic->bitmap_flush_work, 0); in dm_integrity_enter_synchronous_mode()
3054 flush_workqueue(ic->commit_wq); in dm_integrity_enter_synchronous_mode()
3060 struct dm_integrity_c *ic = container_of(n, struct dm_integrity_c, reboot_notifier); in dm_integrity_reboot() local
3064 dm_integrity_enter_synchronous_mode(ic); in dm_integrity_reboot()
3071 struct dm_integrity_c *ic = (struct dm_integrity_c *)ti->private; in dm_integrity_postsuspend() local
3074 WARN_ON(unregister_reboot_notifier(&ic->reboot_notifier)); in dm_integrity_postsuspend()
3076 del_timer_sync(&ic->autocommit_timer); in dm_integrity_postsuspend()
3078 if (ic->recalc_wq) in dm_integrity_postsuspend()
3079 drain_workqueue(ic->recalc_wq); in dm_integrity_postsuspend()
3081 if (ic->mode == 'B') in dm_integrity_postsuspend()
3082 cancel_delayed_work_sync(&ic->bitmap_flush_work); in dm_integrity_postsuspend()
3084 queue_work(ic->commit_wq, &ic->commit_work); in dm_integrity_postsuspend()
3085 drain_workqueue(ic->commit_wq); in dm_integrity_postsuspend()
3087 if (ic->mode == 'J') { in dm_integrity_postsuspend()
3088 queue_work(ic->writer_wq, &ic->writer_work); in dm_integrity_postsuspend()
3089 drain_workqueue(ic->writer_wq); in dm_integrity_postsuspend()
3090 dm_integrity_flush_buffers(ic, true); in dm_integrity_postsuspend()
3091 if (ic->wrote_to_journal) { in dm_integrity_postsuspend()
3092 init_journal(ic, ic->free_section, in dm_integrity_postsuspend()
3093 ic->journal_sections - ic->free_section, ic->commit_seq); in dm_integrity_postsuspend()
3094 if (ic->free_section) { in dm_integrity_postsuspend()
3095 init_journal(ic, 0, ic->free_section, in dm_integrity_postsuspend()
3096 next_commit_seq(ic->commit_seq)); in dm_integrity_postsuspend()
3101 if (ic->mode == 'B') { in dm_integrity_postsuspend()
3102 dm_integrity_flush_buffers(ic, true); in dm_integrity_postsuspend()
3105 init_journal(ic, 0, ic->journal_sections, 0); in dm_integrity_postsuspend()
3106 ic->sb->flags &= ~cpu_to_le32(SB_FLAG_DIRTY_BITMAP); in dm_integrity_postsuspend()
3107 r = sync_rw_sb(ic, REQ_OP_WRITE, REQ_FUA); in dm_integrity_postsuspend()
3109 dm_integrity_io_error(ic, "writing superblock", r); in dm_integrity_postsuspend()
3113 BUG_ON(!RB_EMPTY_ROOT(&ic->in_progress)); in dm_integrity_postsuspend()
3115 ic->journal_uptodate = true; in dm_integrity_postsuspend()
3120 struct dm_integrity_c *ic = (struct dm_integrity_c *)ti->private; in dm_integrity_resume() local
3121 __u64 old_provided_data_sectors = le64_to_cpu(ic->sb->provided_data_sectors); in dm_integrity_resume()
3126 ic->wrote_to_journal = false; in dm_integrity_resume()
3128 if (ic->provided_data_sectors != old_provided_data_sectors) { in dm_integrity_resume()
3129 if (ic->provided_data_sectors > old_provided_data_sectors && in dm_integrity_resume()
3130 ic->mode == 'B' && in dm_integrity_resume()
3131 ic->sb->log2_blocks_per_bitmap_bit == ic->log2_blocks_per_bitmap_bit) { in dm_integrity_resume()
3132 rw_journal_sectors(ic, REQ_OP_READ, 0, 0, in dm_integrity_resume()
3133 ic->n_bitmap_blocks * (BITMAP_BLOCK_SIZE >> SECTOR_SHIFT), NULL); in dm_integrity_resume()
3134 block_bitmap_op(ic, ic->journal, old_provided_data_sectors, in dm_integrity_resume()
3135 ic->provided_data_sectors - old_provided_data_sectors, BITMAP_OP_SET); in dm_integrity_resume()
3136 rw_journal_sectors(ic, REQ_OP_WRITE, REQ_FUA | REQ_SYNC, 0, in dm_integrity_resume()
3137 ic->n_bitmap_blocks * (BITMAP_BLOCK_SIZE >> SECTOR_SHIFT), NULL); in dm_integrity_resume()
3140 ic->sb->provided_data_sectors = cpu_to_le64(ic->provided_data_sectors); in dm_integrity_resume()
3141 r = sync_rw_sb(ic, REQ_OP_WRITE, REQ_FUA); in dm_integrity_resume()
3143 dm_integrity_io_error(ic, "writing superblock", r); in dm_integrity_resume()
3146 if (ic->sb->flags & cpu_to_le32(SB_FLAG_DIRTY_BITMAP)) { in dm_integrity_resume()
3148 rw_journal_sectors(ic, REQ_OP_READ, 0, 0, in dm_integrity_resume()
3149 ic->n_bitmap_blocks * (BITMAP_BLOCK_SIZE >> SECTOR_SHIFT), NULL); in dm_integrity_resume()
3150 if (ic->mode == 'B') { in dm_integrity_resume()
3151 if (ic->sb->log2_blocks_per_bitmap_bit == ic->log2_blocks_per_bitmap_bit && in dm_integrity_resume()
3152 !ic->reset_recalculate_flag) { in dm_integrity_resume()
3153 block_bitmap_copy(ic, ic->recalc_bitmap, ic->journal); in dm_integrity_resume()
3154 block_bitmap_copy(ic, ic->may_write_bitmap, ic->journal); in dm_integrity_resume()
3155 if (!block_bitmap_op(ic, ic->journal, 0, ic->provided_data_sectors, in dm_integrity_resume()
3157 ic->sb->flags |= cpu_to_le32(SB_FLAG_RECALCULATING); in dm_integrity_resume()
3158 ic->sb->recalc_sector = cpu_to_le64(0); in dm_integrity_resume()
3162 ic->sb->log2_blocks_per_bitmap_bit, ic->log2_blocks_per_bitmap_bit); in dm_integrity_resume()
3163 ic->sb->log2_blocks_per_bitmap_bit = ic->log2_blocks_per_bitmap_bit; in dm_integrity_resume()
3164 block_bitmap_op(ic, ic->recalc_bitmap, 0, ic->provided_data_sectors, BITMAP_OP_SET); in dm_integrity_resume()
3165 block_bitmap_op(ic, ic->may_write_bitmap, 0, ic->provided_data_sectors, BITMAP_OP_SET); in dm_integrity_resume()
3166 block_bitmap_op(ic, ic->journal, 0, ic->provided_data_sectors, BITMAP_OP_SET); in dm_integrity_resume()
3167 rw_journal_sectors(ic, REQ_OP_WRITE, REQ_FUA | REQ_SYNC, 0, in dm_integrity_resume()
3168 ic->n_bitmap_blocks * (BITMAP_BLOCK_SIZE >> SECTOR_SHIFT), NULL); in dm_integrity_resume()
3169 ic->sb->flags |= cpu_to_le32(SB_FLAG_RECALCULATING); in dm_integrity_resume()
3170 ic->sb->recalc_sector = cpu_to_le64(0); in dm_integrity_resume()
3173 if (!(ic->sb->log2_blocks_per_bitmap_bit == ic->log2_blocks_per_bitmap_bit && in dm_integrity_resume()
3174 … block_bitmap_op(ic, ic->journal, 0, ic->provided_data_sectors, BITMAP_OP_TEST_ALL_CLEAR)) || in dm_integrity_resume()
3175 ic->reset_recalculate_flag) { in dm_integrity_resume()
3176 ic->sb->flags |= cpu_to_le32(SB_FLAG_RECALCULATING); in dm_integrity_resume()
3177 ic->sb->recalc_sector = cpu_to_le64(0); in dm_integrity_resume()
3179 init_journal(ic, 0, ic->journal_sections, 0); in dm_integrity_resume()
3180 replay_journal(ic); in dm_integrity_resume()
3181 ic->sb->flags &= ~cpu_to_le32(SB_FLAG_DIRTY_BITMAP); in dm_integrity_resume()
3183 r = sync_rw_sb(ic, REQ_OP_WRITE, REQ_FUA); in dm_integrity_resume()
3185 dm_integrity_io_error(ic, "writing superblock", r); in dm_integrity_resume()
3187 replay_journal(ic); in dm_integrity_resume()
3188 if (ic->reset_recalculate_flag) { in dm_integrity_resume()
3189 ic->sb->flags |= cpu_to_le32(SB_FLAG_RECALCULATING); in dm_integrity_resume()
3190 ic->sb->recalc_sector = cpu_to_le64(0); in dm_integrity_resume()
3192 if (ic->mode == 'B') { in dm_integrity_resume()
3193 ic->sb->flags |= cpu_to_le32(SB_FLAG_DIRTY_BITMAP); in dm_integrity_resume()
3194 ic->sb->log2_blocks_per_bitmap_bit = ic->log2_blocks_per_bitmap_bit; in dm_integrity_resume()
3195 r = sync_rw_sb(ic, REQ_OP_WRITE, REQ_FUA); in dm_integrity_resume()
3197 dm_integrity_io_error(ic, "writing superblock", r); in dm_integrity_resume()
3199 block_bitmap_op(ic, ic->journal, 0, ic->provided_data_sectors, BITMAP_OP_CLEAR); in dm_integrity_resume()
3200 block_bitmap_op(ic, ic->recalc_bitmap, 0, ic->provided_data_sectors, BITMAP_OP_CLEAR); in dm_integrity_resume()
3201 block_bitmap_op(ic, ic->may_write_bitmap, 0, ic->provided_data_sectors, BITMAP_OP_CLEAR); in dm_integrity_resume()
3202 if (ic->sb->flags & cpu_to_le32(SB_FLAG_RECALCULATING) && in dm_integrity_resume()
3203 le64_to_cpu(ic->sb->recalc_sector) < ic->provided_data_sectors) { in dm_integrity_resume()
3204 block_bitmap_op(ic, ic->journal, le64_to_cpu(ic->sb->recalc_sector), in dm_integrity_resume()
3205 ic->provided_data_sectors - le64_to_cpu(ic->sb->recalc_sector), BITMAP_OP_SET); in dm_integrity_resume()
3206 block_bitmap_op(ic, ic->recalc_bitmap, le64_to_cpu(ic->sb->recalc_sector), in dm_integrity_resume()
3207 ic->provided_data_sectors - le64_to_cpu(ic->sb->recalc_sector), BITMAP_OP_SET); in dm_integrity_resume()
3208 block_bitmap_op(ic, ic->may_write_bitmap, le64_to_cpu(ic->sb->recalc_sector), in dm_integrity_resume()
3209 ic->provided_data_sectors - le64_to_cpu(ic->sb->recalc_sector), BITMAP_OP_SET); in dm_integrity_resume()
3211 rw_journal_sectors(ic, REQ_OP_WRITE, REQ_FUA | REQ_SYNC, 0, in dm_integrity_resume()
3212 ic->n_bitmap_blocks * (BITMAP_BLOCK_SIZE >> SECTOR_SHIFT), NULL); in dm_integrity_resume()
3216 DEBUG_print("testing recalc: %x\n", ic->sb->flags); in dm_integrity_resume()
3217 if (ic->sb->flags & cpu_to_le32(SB_FLAG_RECALCULATING)) { in dm_integrity_resume()
3218 __u64 recalc_pos = le64_to_cpu(ic->sb->recalc_sector); in dm_integrity_resume()
3219 DEBUG_print("recalc pos: %llx / %llx\n", recalc_pos, ic->provided_data_sectors); in dm_integrity_resume()
3220 if (recalc_pos < ic->provided_data_sectors) { in dm_integrity_resume()
3221 queue_work(ic->recalc_wq, &ic->recalc_work); in dm_integrity_resume()
3222 } else if (recalc_pos > ic->provided_data_sectors) { in dm_integrity_resume()
3223 ic->sb->recalc_sector = cpu_to_le64(ic->provided_data_sectors); in dm_integrity_resume()
3224 recalc_write_super(ic); in dm_integrity_resume()
3228 ic->reboot_notifier.notifier_call = dm_integrity_reboot; in dm_integrity_resume()
3229 ic->reboot_notifier.next = NULL; in dm_integrity_resume()
3230 ic->reboot_notifier.priority = INT_MAX - 1; /* be notified after md and before hardware drivers */ in dm_integrity_resume()
3231 WARN_ON(register_reboot_notifier(&ic->reboot_notifier)); in dm_integrity_resume()
3235 dm_integrity_enter_synchronous_mode(ic); in dm_integrity_resume()
3242 struct dm_integrity_c *ic = (struct dm_integrity_c *)ti->private; in dm_integrity_status() local
3249 (unsigned long long)atomic64_read(&ic->number_of_mismatches), in dm_integrity_status()
3250 ic->provided_data_sectors); in dm_integrity_status()
3251 if (ic->sb->flags & cpu_to_le32(SB_FLAG_RECALCULATING)) in dm_integrity_status()
3252 DMEMIT(" %llu", le64_to_cpu(ic->sb->recalc_sector)); in dm_integrity_status()
3258 __u64 watermark_percentage = (__u64)(ic->journal_entries - ic->free_sectors_threshold) * 100; in dm_integrity_status()
3259 watermark_percentage += ic->journal_entries / 2; in dm_integrity_status()
3260 do_div(watermark_percentage, ic->journal_entries); in dm_integrity_status()
3262 arg_count += !!ic->meta_dev; in dm_integrity_status()
3263 arg_count += ic->sectors_per_block != 1; in dm_integrity_status()
3264 arg_count += !!(ic->sb->flags & cpu_to_le32(SB_FLAG_RECALCULATING)); in dm_integrity_status()
3265 arg_count += ic->reset_recalculate_flag; in dm_integrity_status()
3266 arg_count += ic->discard; in dm_integrity_status()
3267 arg_count += ic->mode == 'J'; in dm_integrity_status()
3268 arg_count += ic->mode == 'J'; in dm_integrity_status()
3269 arg_count += ic->mode == 'B'; in dm_integrity_status()
3270 arg_count += ic->mode == 'B'; in dm_integrity_status()
3271 arg_count += !!ic->internal_hash_alg.alg_string; in dm_integrity_status()
3272 arg_count += !!ic->journal_crypt_alg.alg_string; in dm_integrity_status()
3273 arg_count += !!ic->journal_mac_alg.alg_string; in dm_integrity_status()
3274 arg_count += (ic->sb->flags & cpu_to_le32(SB_FLAG_FIXED_PADDING)) != 0; in dm_integrity_status()
3275 arg_count += (ic->sb->flags & cpu_to_le32(SB_FLAG_FIXED_HMAC)) != 0; in dm_integrity_status()
3276 arg_count += ic->legacy_recalculate; in dm_integrity_status()
3277 DMEMIT("%s %llu %u %c %u", ic->dev->name, ic->start, in dm_integrity_status()
3278 ic->tag_size, ic->mode, arg_count); in dm_integrity_status()
3279 if (ic->meta_dev) in dm_integrity_status()
3280 DMEMIT(" meta_device:%s", ic->meta_dev->name); in dm_integrity_status()
3281 if (ic->sectors_per_block != 1) in dm_integrity_status()
3282 DMEMIT(" block_size:%u", ic->sectors_per_block << SECTOR_SHIFT); in dm_integrity_status()
3283 if (ic->sb->flags & cpu_to_le32(SB_FLAG_RECALCULATING)) in dm_integrity_status()
3285 if (ic->reset_recalculate_flag) in dm_integrity_status()
3287 if (ic->discard) in dm_integrity_status()
3289 DMEMIT(" journal_sectors:%u", ic->initial_sectors - SB_SECTORS); in dm_integrity_status()
3290 DMEMIT(" interleave_sectors:%u", 1U << ic->sb->log2_interleave_sectors); in dm_integrity_status()
3291 DMEMIT(" buffer_sectors:%u", 1U << ic->log2_buffer_sectors); in dm_integrity_status()
3292 if (ic->mode == 'J') { in dm_integrity_status()
3294 DMEMIT(" commit_time:%u", ic->autocommit_msec); in dm_integrity_status()
3296 if (ic->mode == 'B') { in dm_integrity_status()
3297 …DMEMIT(" sectors_per_bit:%llu", (sector_t)ic->sectors_per_block << ic->log2_blocks_per_bitmap_bit); in dm_integrity_status()
3298 DMEMIT(" bitmap_flush_interval:%u", jiffies_to_msecs(ic->bitmap_flush_interval)); in dm_integrity_status()
3300 if ((ic->sb->flags & cpu_to_le32(SB_FLAG_FIXED_PADDING)) != 0) in dm_integrity_status()
3302 if ((ic->sb->flags & cpu_to_le32(SB_FLAG_FIXED_HMAC)) != 0) in dm_integrity_status()
3304 if (ic->legacy_recalculate) in dm_integrity_status()
3309 if (ic->a.alg_string) { \ in dm_integrity_status()
3310 DMEMIT(" %s:%s", n, ic->a.alg_string); \ in dm_integrity_status()
3311 if (ic->a.key_string) \ in dm_integrity_status()
3312 DMEMIT(":%s", ic->a.key_string);\ in dm_integrity_status()
3323 ic->dev->name, ic->start, ic->tag_size, ic->mode); in dm_integrity_status()
3325 if (ic->meta_dev) in dm_integrity_status()
3326 DMEMIT(",meta_device=%s", ic->meta_dev->name); in dm_integrity_status()
3327 if (ic->sectors_per_block != 1) in dm_integrity_status()
3328 DMEMIT(",block_size=%u", ic->sectors_per_block << SECTOR_SHIFT); in dm_integrity_status()
3330 DMEMIT(",recalculate=%c", (ic->sb->flags & cpu_to_le32(SB_FLAG_RECALCULATING)) ? in dm_integrity_status()
3332 DMEMIT(",allow_discards=%c", ic->discard ? 'y' : 'n'); in dm_integrity_status()
3334 ((ic->sb->flags & cpu_to_le32(SB_FLAG_FIXED_PADDING)) != 0) ? 'y' : 'n'); in dm_integrity_status()
3336 ((ic->sb->flags & cpu_to_le32(SB_FLAG_FIXED_HMAC)) != 0) ? 'y' : 'n'); in dm_integrity_status()
3337 DMEMIT(",legacy_recalculate=%c", ic->legacy_recalculate ? 'y' : 'n'); in dm_integrity_status()
3339 DMEMIT(",journal_sectors=%u", ic->initial_sectors - SB_SECTORS); in dm_integrity_status()
3340 DMEMIT(",interleave_sectors=%u", 1U << ic->sb->log2_interleave_sectors); in dm_integrity_status()
3341 DMEMIT(",buffer_sectors=%u", 1U << ic->log2_buffer_sectors); in dm_integrity_status()
3350 struct dm_integrity_c *ic = ti->private; in dm_integrity_iterate_devices() local
3352 if (!ic->meta_dev) in dm_integrity_iterate_devices()
3353 return fn(ti, ic->dev, ic->start + ic->initial_sectors + ic->metadata_run, ti->len, data); in dm_integrity_iterate_devices()
3355 return fn(ti, ic->dev, 0, ti->len, data); in dm_integrity_iterate_devices()
3360 struct dm_integrity_c *ic = ti->private; in dm_integrity_io_hints() local
3362 if (ic->sectors_per_block > 1) { in dm_integrity_io_hints()
3363 limits->logical_block_size = ic->sectors_per_block << SECTOR_SHIFT; in dm_integrity_io_hints()
3364 limits->physical_block_size = ic->sectors_per_block << SECTOR_SHIFT; in dm_integrity_io_hints()
3365 blk_limits_io_min(limits, ic->sectors_per_block << SECTOR_SHIFT); in dm_integrity_io_hints()
3369 static void calculate_journal_section_size(struct dm_integrity_c *ic) in calculate_journal_section_size() argument
3373 ic->journal_sections = le32_to_cpu(ic->sb->journal_sections); in calculate_journal_section_size()
3374 …ic->journal_entry_size = roundup(offsetof(struct journal_entry, last_bytes[ic->sectors_per_block])… in calculate_journal_section_size()
3377 if (ic->sb->flags & cpu_to_le32(SB_FLAG_HAVE_JOURNAL_MAC)) in calculate_journal_section_size()
3379 ic->journal_entries_per_sector = sector_space / ic->journal_entry_size; in calculate_journal_section_size()
3380 ic->journal_section_entries = ic->journal_entries_per_sector * JOURNAL_BLOCK_SECTORS; in calculate_journal_section_size()
3381 …ic->journal_section_sectors = (ic->journal_section_entries << ic->sb->log2_sectors_per_block) + JO… in calculate_journal_section_size()
3382 ic->journal_entries = ic->journal_section_entries * ic->journal_sections; in calculate_journal_section_size()
3385 static int calculate_device_limits(struct dm_integrity_c *ic) in calculate_device_limits() argument
3389 calculate_journal_section_size(ic); in calculate_device_limits()
3390 initial_sectors = SB_SECTORS + (__u64)ic->journal_section_sectors * ic->journal_sections; in calculate_device_limits()
3391 …if (initial_sectors + METADATA_PADDING_SECTORS >= ic->meta_device_sectors || initial_sectors > UIN… in calculate_device_limits()
3393 ic->initial_sectors = initial_sectors; in calculate_device_limits()
3395 if (!ic->meta_dev) { in calculate_device_limits()
3400 ic->sb->flags & cpu_to_le32(SB_FLAG_FIXED_PADDING) ? in calculate_device_limits()
3404 …ic->metadata_run = round_up((__u64)ic->tag_size << (ic->sb->log2_interleave_sectors - ic->sb->log2… in calculate_device_limits()
3406 if (!(ic->metadata_run & (ic->metadata_run - 1))) in calculate_device_limits()
3407 ic->log2_metadata_run = __ffs(ic->metadata_run); in calculate_device_limits()
3409 ic->log2_metadata_run = -1; in calculate_device_limits()
3411 get_area_and_offset(ic, ic->provided_data_sectors - 1, &last_area, &last_offset); in calculate_device_limits()
3412 last_sector = get_data_sector(ic, last_area, last_offset); in calculate_device_limits()
3413 if (last_sector < ic->start || last_sector >= ic->meta_device_sectors) in calculate_device_limits()
3416 __u64 meta_size = (ic->provided_data_sectors >> ic->sb->log2_sectors_per_block) * ic->tag_size; in calculate_device_limits()
3417 meta_size = (meta_size + ((1U << (ic->log2_buffer_sectors + SECTOR_SHIFT)) - 1)) in calculate_device_limits()
3418 >> (ic->log2_buffer_sectors + SECTOR_SHIFT); in calculate_device_limits()
3419 meta_size <<= ic->log2_buffer_sectors; in calculate_device_limits()
3420 if (ic->initial_sectors + meta_size < ic->initial_sectors || in calculate_device_limits()
3421 ic->initial_sectors + meta_size > ic->meta_device_sectors) in calculate_device_limits()
3423 ic->metadata_run = 1; in calculate_device_limits()
3424 ic->log2_metadata_run = 0; in calculate_device_limits()
3430 static void get_provided_data_sectors(struct dm_integrity_c *ic) in get_provided_data_sectors() argument
3432 if (!ic->meta_dev) { in get_provided_data_sectors()
3434 ic->provided_data_sectors = 0; in get_provided_data_sectors()
3435 for (test_bit = fls64(ic->meta_device_sectors) - 1; test_bit >= 3; test_bit--) { in get_provided_data_sectors()
3436 __u64 prev_data_sectors = ic->provided_data_sectors; in get_provided_data_sectors()
3438 ic->provided_data_sectors |= (sector_t)1 << test_bit; in get_provided_data_sectors()
3439 if (calculate_device_limits(ic)) in get_provided_data_sectors()
3440 ic->provided_data_sectors = prev_data_sectors; in get_provided_data_sectors()
3443 ic->provided_data_sectors = ic->data_device_sectors; in get_provided_data_sectors()
3444 ic->provided_data_sectors &= ~(sector_t)(ic->sectors_per_block - 1); in get_provided_data_sectors()
3448 static int initialize_superblock(struct dm_integrity_c *ic, unsigned journal_sectors, unsigned inte… in initialize_superblock() argument
3453 memset(ic->sb, 0, SB_SECTORS << SECTOR_SHIFT); in initialize_superblock()
3454 memcpy(ic->sb->magic, SB_MAGIC, 8); in initialize_superblock()
3455 ic->sb->integrity_tag_size = cpu_to_le16(ic->tag_size); in initialize_superblock()
3456 ic->sb->log2_sectors_per_block = __ffs(ic->sectors_per_block); in initialize_superblock()
3457 if (ic->journal_mac_alg.alg_string) in initialize_superblock()
3458 ic->sb->flags |= cpu_to_le32(SB_FLAG_HAVE_JOURNAL_MAC); in initialize_superblock()
3460 calculate_journal_section_size(ic); in initialize_superblock()
3461 journal_sections = journal_sectors / ic->journal_section_sectors; in initialize_superblock()
3465 if (ic->fix_hmac && (ic->internal_hash_alg.alg_string || ic->journal_mac_alg.alg_string)) { in initialize_superblock()
3466 ic->sb->flags |= cpu_to_le32(SB_FLAG_FIXED_HMAC); in initialize_superblock()
3467 get_random_bytes(ic->sb->salt, SALT_SIZE); in initialize_superblock()
3470 if (!ic->meta_dev) { in initialize_superblock()
3471 if (ic->fix_padding) in initialize_superblock()
3472 ic->sb->flags |= cpu_to_le32(SB_FLAG_FIXED_PADDING); in initialize_superblock()
3473 ic->sb->journal_sections = cpu_to_le32(journal_sections); in initialize_superblock()
3476 ic->sb->log2_interleave_sectors = __fls(interleave_sectors); in initialize_superblock()
3477 …ic->sb->log2_interleave_sectors = max((__u8)MIN_LOG2_INTERLEAVE_SECTORS, ic->sb->log2_interleave_s… in initialize_superblock()
3478 …ic->sb->log2_interleave_sectors = min((__u8)MAX_LOG2_INTERLEAVE_SECTORS, ic->sb->log2_interleave_s… in initialize_superblock()
3480 get_provided_data_sectors(ic); in initialize_superblock()
3481 if (!ic->provided_data_sectors) in initialize_superblock()
3484 ic->sb->log2_interleave_sectors = 0; in initialize_superblock()
3486 get_provided_data_sectors(ic); in initialize_superblock()
3487 if (!ic->provided_data_sectors) in initialize_superblock()
3491 ic->sb->journal_sections = cpu_to_le32(0); in initialize_superblock()
3493 __u32 prev_journal_sections = le32_to_cpu(ic->sb->journal_sections); in initialize_superblock()
3497 ic->sb->journal_sections = cpu_to_le32(test_journal_sections); in initialize_superblock()
3498 if (calculate_device_limits(ic)) in initialize_superblock()
3499 ic->sb->journal_sections = cpu_to_le32(prev_journal_sections); in initialize_superblock()
3502 if (!le32_to_cpu(ic->sb->journal_sections)) { in initialize_superblock()
3503 if (ic->log2_buffer_sectors > 3) { in initialize_superblock()
3504 ic->log2_buffer_sectors--; in initialize_superblock()
3511 ic->sb->provided_data_sectors = cpu_to_le64(ic->provided_data_sectors); in initialize_superblock()
3513 sb_set_version(ic); in initialize_superblock()
3518 static void dm_integrity_set(struct dm_target *ti, struct dm_integrity_c *ic) in dm_integrity_set() argument
3525 bi.tuple_size = ic->tag_size; in dm_integrity_set()
3527 bi.interval_exp = ic->sb->log2_sectors_per_block + SECTOR_SHIFT; in dm_integrity_set()
3568 static void dm_integrity_free_journal_scatterlist(struct dm_integrity_c *ic, struct scatterlist **s… in dm_integrity_free_journal_scatterlist() argument
3571 for (i = 0; i < ic->journal_sections; i++) in dm_integrity_free_journal_scatterlist()
3576 static struct scatterlist **dm_integrity_alloc_journal_scatterlist(struct dm_integrity_c *ic, in dm_integrity_alloc_journal_scatterlist() argument
3582 sl = kvmalloc_array(ic->journal_sections, in dm_integrity_alloc_journal_scatterlist()
3588 for (i = 0; i < ic->journal_sections; i++) { in dm_integrity_alloc_journal_scatterlist()
3595 page_list_location(ic, i, 0, &start_index, &start_offset); in dm_integrity_alloc_journal_scatterlist()
3596 page_list_location(ic, i, ic->journal_section_sectors - 1, in dm_integrity_alloc_journal_scatterlist()
3604 dm_integrity_free_journal_scatterlist(ic, sl); in dm_integrity_alloc_journal_scatterlist()
3695 static int create_journal(struct dm_integrity_c *ic, char **error) in create_journal() argument
3703 ic->commit_ids[0] = cpu_to_le64(0x1111111111111111ULL); in create_journal()
3704 ic->commit_ids[1] = cpu_to_le64(0x2222222222222222ULL); in create_journal()
3705 ic->commit_ids[2] = cpu_to_le64(0x3333333333333333ULL); in create_journal()
3706 ic->commit_ids[3] = cpu_to_le64(0x4444444444444444ULL); in create_journal()
3708 journal_pages = roundup((__u64)ic->journal_sections * ic->journal_section_sectors, in create_journal()
3716 ic->journal_pages = journal_pages; in create_journal()
3718 ic->journal = dm_integrity_alloc_page_list(ic->journal_pages); in create_journal()
3719 if (!ic->journal) { in create_journal()
3724 if (ic->journal_crypt_alg.alg_string) { in create_journal()
3728 comp.ic = ic; in create_journal()
3729 …ic->journal_crypt = crypto_alloc_skcipher(ic->journal_crypt_alg.alg_string, 0, CRYPTO_ALG_ALLOCATE… in create_journal()
3730 if (IS_ERR(ic->journal_crypt)) { in create_journal()
3732 r = PTR_ERR(ic->journal_crypt); in create_journal()
3733 ic->journal_crypt = NULL; in create_journal()
3736 ivsize = crypto_skcipher_ivsize(ic->journal_crypt); in create_journal()
3737 blocksize = crypto_skcipher_blocksize(ic->journal_crypt); in create_journal()
3739 if (ic->journal_crypt_alg.key) { in create_journal()
3740 r = crypto_skcipher_setkey(ic->journal_crypt, ic->journal_crypt_alg.key, in create_journal()
3741 ic->journal_crypt_alg.key_size); in create_journal()
3748 ic->journal_crypt_alg.alg_string, blocksize, ivsize); in create_journal()
3750 ic->journal_io = dm_integrity_alloc_page_list(ic->journal_pages); in create_journal()
3751 if (!ic->journal_io) { in create_journal()
3760 req = skcipher_request_alloc(ic->journal_crypt, GFP_KERNEL); in create_journal()
3774 ic->journal_xor = dm_integrity_alloc_page_list(ic->journal_pages); in create_journal()
3775 if (!ic->journal_xor) { in create_journal()
3781 sg = kvmalloc_array(ic->journal_pages + 1, in create_journal()
3789 sg_init_table(sg, ic->journal_pages + 1); in create_journal()
3790 for (i = 0; i < ic->journal_pages; i++) { in create_journal()
3791 char *va = lowmem_page_address(ic->journal_xor[i].page); in create_journal()
3795 sg_set_buf(&sg[i], &ic->commit_ids, sizeof ic->commit_ids); in create_journal()
3798 PAGE_SIZE * ic->journal_pages + sizeof ic->commit_ids, crypt_iv); in create_journal()
3804 r = dm_integrity_failed(ic); in create_journal()
3809 DEBUG_bytes(lowmem_page_address(ic->journal_xor[0].page), 64, "xor data"); in create_journal()
3811 crypto_free_skcipher(ic->journal_crypt); in create_journal()
3812 ic->journal_crypt = NULL; in create_journal()
3816 req = skcipher_request_alloc(ic->journal_crypt, GFP_KERNEL); in create_journal()
3837 ic->journal_scatterlist = dm_integrity_alloc_journal_scatterlist(ic, ic->journal); in create_journal()
3838 if (!ic->journal_scatterlist) { in create_journal()
3843 ic->journal_io_scatterlist = dm_integrity_alloc_journal_scatterlist(ic, ic->journal_io); in create_journal()
3844 if (!ic->journal_io_scatterlist) { in create_journal()
3849 ic->sk_requests = kvmalloc_array(ic->journal_sections, in create_journal()
3852 if (!ic->sk_requests) { in create_journal()
3857 for (i = 0; i < ic->journal_sections; i++) { in create_journal()
3873 r = dm_integrity_failed(ic); in create_journal()
3879 section_req = skcipher_request_alloc(ic->journal_crypt, GFP_KERNEL); in create_journal()
3894 section_req->cryptlen = (size_t)ic->journal_section_sectors << SECTOR_SHIFT; in create_journal()
3895 ic->sk_requests[i] = section_req; in create_journal()
3905 if (ic->commit_ids[j] == ic->commit_ids[i]) { in create_journal()
3906 ic->commit_ids[i] = cpu_to_le64(le64_to_cpu(ic->commit_ids[i]) + 1); in create_journal()
3910 DEBUG_print("commit id %u: %016llx\n", i, ic->commit_ids[i]); in create_journal()
3913 journal_tree_size = (__u64)ic->journal_entries * sizeof(struct journal_node); in create_journal()
3919 ic->journal_tree = kvmalloc(journal_tree_size, GFP_KERNEL); in create_journal()
3920 if (!ic->journal_tree) { in create_journal()
3958 struct dm_integrity_c *ic; in dm_integrity_ctr() local
3982 ic = kzalloc(sizeof(struct dm_integrity_c), GFP_KERNEL); in dm_integrity_ctr()
3983 if (!ic) { in dm_integrity_ctr()
3987 ti->private = ic; in dm_integrity_ctr()
3989 ic->ti = ti; in dm_integrity_ctr()
3991 ic->in_progress = RB_ROOT; in dm_integrity_ctr()
3992 INIT_LIST_HEAD(&ic->wait_list); in dm_integrity_ctr()
3993 init_waitqueue_head(&ic->endio_wait); in dm_integrity_ctr()
3994 bio_list_init(&ic->flush_bio_list); in dm_integrity_ctr()
3995 init_waitqueue_head(&ic->copy_to_journal_wait); in dm_integrity_ctr()
3996 init_completion(&ic->crypto_backoff); in dm_integrity_ctr()
3997 atomic64_set(&ic->number_of_mismatches, 0); in dm_integrity_ctr()
3998 ic->bitmap_flush_interval = BITMAP_FLUSH_INTERVAL; in dm_integrity_ctr()
4000 r = dm_get_device(ti, argv[0], dm_table_get_mode(ti->table), &ic->dev); in dm_integrity_ctr()
4011 ic->start = start; in dm_integrity_ctr()
4014 if (sscanf(argv[2], "%u%c", &ic->tag_size, &dummy) != 1 || !ic->tag_size) { in dm_integrity_ctr()
4023 ic->mode = argv[3][0]; in dm_integrity_ctr()
4035 ic->sectors_per_block = 1; in dm_integrity_ctr()
4064 if (ic->meta_dev) { in dm_integrity_ctr()
4065 dm_put_device(ti, ic->meta_dev); in dm_integrity_ctr()
4066 ic->meta_dev = NULL; in dm_integrity_ctr()
4069 dm_table_get_mode(ti->table), &ic->meta_dev); in dm_integrity_ctr()
4082 ic->sectors_per_block = val >> SECTOR_SHIFT; in dm_integrity_ctr()
4091 ic->bitmap_flush_interval = msecs_to_jiffies(val); in dm_integrity_ctr()
4093 r = get_alg_and_key(opt_string, &ic->internal_hash_alg, &ti->error, in dm_integrity_ctr()
4098 r = get_alg_and_key(opt_string, &ic->journal_crypt_alg, &ti->error, in dm_integrity_ctr()
4103 r = get_alg_and_key(opt_string, &ic->journal_mac_alg, &ti->error, in dm_integrity_ctr()
4108 ic->recalculate_flag = true; in dm_integrity_ctr()
4110 ic->recalculate_flag = true; in dm_integrity_ctr()
4111 ic->reset_recalculate_flag = true; in dm_integrity_ctr()
4113 ic->discard = true; in dm_integrity_ctr()
4115 ic->fix_padding = true; in dm_integrity_ctr()
4117 ic->fix_hmac = true; in dm_integrity_ctr()
4119 ic->legacy_recalculate = true; in dm_integrity_ctr()
4127 ic->data_device_sectors = i_size_read(ic->dev->bdev->bd_inode) >> SECTOR_SHIFT; in dm_integrity_ctr()
4128 if (!ic->meta_dev) in dm_integrity_ctr()
4129 ic->meta_device_sectors = ic->data_device_sectors; in dm_integrity_ctr()
4131 ic->meta_device_sectors = i_size_read(ic->meta_dev->bdev->bd_inode) >> SECTOR_SHIFT; in dm_integrity_ctr()
4135 ic->data_device_sectors >> DEFAULT_JOURNAL_SIZE_FACTOR); in dm_integrity_ctr()
4140 ic->log2_buffer_sectors = min((int)__fls(buffer_sectors), 31 - SECTOR_SHIFT); in dm_integrity_ctr()
4142 r = get_mac(&ic->internal_hash, &ic->internal_hash_alg, &ti->error, in dm_integrity_ctr()
4147 r = get_mac(&ic->journal_mac, &ic->journal_mac_alg, &ti->error, in dm_integrity_ctr()
4152 if (!ic->tag_size) { in dm_integrity_ctr()
4153 if (!ic->internal_hash) { in dm_integrity_ctr()
4158 ic->tag_size = crypto_shash_digestsize(ic->internal_hash); in dm_integrity_ctr()
4160 if (ic->tag_size > MAX_TAG_SIZE) { in dm_integrity_ctr()
4165 if (!(ic->tag_size & (ic->tag_size - 1))) in dm_integrity_ctr()
4166 ic->log2_tag_size = __ffs(ic->tag_size); in dm_integrity_ctr()
4168 ic->log2_tag_size = -1; in dm_integrity_ctr()
4170 if (ic->mode == 'B' && !ic->internal_hash) { in dm_integrity_ctr()
4176 if (ic->discard && !ic->internal_hash) { in dm_integrity_ctr()
4182 ic->autocommit_jiffies = msecs_to_jiffies(sync_msec); in dm_integrity_ctr()
4183 ic->autocommit_msec = sync_msec; in dm_integrity_ctr()
4184 timer_setup(&ic->autocommit_timer, autocommit_fn, 0); in dm_integrity_ctr()
4186 ic->io = dm_io_client_create(); in dm_integrity_ctr()
4187 if (IS_ERR(ic->io)) { in dm_integrity_ctr()
4188 r = PTR_ERR(ic->io); in dm_integrity_ctr()
4189 ic->io = NULL; in dm_integrity_ctr()
4194 r = mempool_init_slab_pool(&ic->journal_io_mempool, JOURNAL_IO_MEMPOOL, journal_io_cache); in dm_integrity_ctr()
4200 ic->metadata_wq = alloc_workqueue("dm-integrity-metadata", in dm_integrity_ctr()
4202 if (!ic->metadata_wq) { in dm_integrity_ctr()
4212 ic->wait_wq = alloc_workqueue("dm-integrity-wait", WQ_MEM_RECLAIM | WQ_UNBOUND, 1); in dm_integrity_ctr()
4213 if (!ic->wait_wq) { in dm_integrity_ctr()
4219 ic->offload_wq = alloc_workqueue("dm-integrity-offload", WQ_MEM_RECLAIM, in dm_integrity_ctr()
4221 if (!ic->offload_wq) { in dm_integrity_ctr()
4227 ic->commit_wq = alloc_workqueue("dm-integrity-commit", WQ_MEM_RECLAIM, 1); in dm_integrity_ctr()
4228 if (!ic->commit_wq) { in dm_integrity_ctr()
4233 INIT_WORK(&ic->commit_work, integrity_commit); in dm_integrity_ctr()
4235 if (ic->mode == 'J' || ic->mode == 'B') { in dm_integrity_ctr()
4236 ic->writer_wq = alloc_workqueue("dm-integrity-writer", WQ_MEM_RECLAIM, 1); in dm_integrity_ctr()
4237 if (!ic->writer_wq) { in dm_integrity_ctr()
4242 INIT_WORK(&ic->writer_work, integrity_writer); in dm_integrity_ctr()
4245 ic->sb = alloc_pages_exact(SB_SECTORS << SECTOR_SHIFT, GFP_KERNEL); in dm_integrity_ctr()
4246 if (!ic->sb) { in dm_integrity_ctr()
4252 r = sync_rw_sb(ic, REQ_OP_READ, 0); in dm_integrity_ctr()
4258 if (memcmp(ic->sb->magic, SB_MAGIC, 8)) { in dm_integrity_ctr()
4259 if (ic->mode != 'R') { in dm_integrity_ctr()
4260 if (memchr_inv(ic->sb, 0, SB_SECTORS << SECTOR_SHIFT)) { in dm_integrity_ctr()
4267 r = initialize_superblock(ic, journal_sectors, interleave_sectors); in dm_integrity_ctr()
4272 if (ic->mode != 'R') in dm_integrity_ctr()
4276 if (!ic->sb->version || ic->sb->version > SB_VERSION_5) { in dm_integrity_ctr()
4281 if (le16_to_cpu(ic->sb->integrity_tag_size) != ic->tag_size) { in dm_integrity_ctr()
4286 if (ic->sb->log2_sectors_per_block != __ffs(ic->sectors_per_block)) { in dm_integrity_ctr()
4291 if (!le32_to_cpu(ic->sb->journal_sections)) { in dm_integrity_ctr()
4297 if (!ic->meta_dev) { in dm_integrity_ctr()
4298 if (ic->sb->log2_interleave_sectors < MIN_LOG2_INTERLEAVE_SECTORS || in dm_integrity_ctr()
4299 ic->sb->log2_interleave_sectors > MAX_LOG2_INTERLEAVE_SECTORS) { in dm_integrity_ctr()
4305 if (ic->sb->log2_interleave_sectors) { in dm_integrity_ctr()
4311 …if (!!(ic->sb->flags & cpu_to_le32(SB_FLAG_HAVE_JOURNAL_MAC)) != !!ic->journal_mac_alg.alg_string)… in dm_integrity_ctr()
4317 get_provided_data_sectors(ic); in dm_integrity_ctr()
4318 if (!ic->provided_data_sectors) { in dm_integrity_ctr()
4325 r = calculate_device_limits(ic); in dm_integrity_ctr()
4327 if (ic->meta_dev) { in dm_integrity_ctr()
4328 if (ic->log2_buffer_sectors > 3) { in dm_integrity_ctr()
4329 ic->log2_buffer_sectors--; in dm_integrity_ctr()
4339 if (log2_sectors_per_bitmap_bit < ic->sb->log2_sectors_per_block) in dm_integrity_ctr()
4340 log2_sectors_per_bitmap_bit = ic->sb->log2_sectors_per_block; in dm_integrity_ctr()
4342 …bits_in_journal = ((__u64)ic->journal_section_sectors * ic->journal_sections) << (SECTOR_SHIFT + 3… in dm_integrity_ctr()
4345 …while (bits_in_journal < (ic->provided_data_sectors + ((sector_t)1 << log2_sectors_per_bitmap_bit)… in dm_integrity_ctr()
4348 log2_blocks_per_bitmap_bit = log2_sectors_per_bitmap_bit - ic->sb->log2_sectors_per_block; in dm_integrity_ctr()
4349 ic->log2_blocks_per_bitmap_bit = log2_blocks_per_bitmap_bit; in dm_integrity_ctr()
4351 ic->sb->log2_blocks_per_bitmap_bit = log2_blocks_per_bitmap_bit; in dm_integrity_ctr()
4353 n_bitmap_bits = ((ic->provided_data_sectors >> ic->sb->log2_sectors_per_block) in dm_integrity_ctr()
4355 ic->n_bitmap_blocks = DIV_ROUND_UP(n_bitmap_bits, BITMAP_BLOCK_SIZE * 8); in dm_integrity_ctr()
4357 if (!ic->meta_dev) in dm_integrity_ctr()
4358 ic->log2_buffer_sectors = min(ic->log2_buffer_sectors, (__u8)__ffs(ic->metadata_run)); in dm_integrity_ctr()
4360 if (ti->len > ic->provided_data_sectors) { in dm_integrity_ctr()
4367 threshold = (__u64)ic->journal_entries * (100 - journal_watermark); in dm_integrity_ctr()
4370 ic->free_sectors_threshold = threshold; in dm_integrity_ctr()
4373 DEBUG_print(" integrity_tag_size %u\n", le16_to_cpu(ic->sb->integrity_tag_size)); in dm_integrity_ctr()
4374 DEBUG_print(" journal_entry_size %u\n", ic->journal_entry_size); in dm_integrity_ctr()
4375 DEBUG_print(" journal_entries_per_sector %u\n", ic->journal_entries_per_sector); in dm_integrity_ctr()
4376 DEBUG_print(" journal_section_entries %u\n", ic->journal_section_entries); in dm_integrity_ctr()
4377 DEBUG_print(" journal_section_sectors %u\n", ic->journal_section_sectors); in dm_integrity_ctr()
4378 DEBUG_print(" journal_sections %u\n", (unsigned)le32_to_cpu(ic->sb->journal_sections)); in dm_integrity_ctr()
4379 DEBUG_print(" journal_entries %u\n", ic->journal_entries); in dm_integrity_ctr()
4380 DEBUG_print(" log2_interleave_sectors %d\n", ic->sb->log2_interleave_sectors); in dm_integrity_ctr()
4381 DEBUG_print(" data_device_sectors 0x%llx\n", i_size_read(ic->dev->bdev->bd_inode) >> SECTOR_SHIFT); in dm_integrity_ctr()
4382 DEBUG_print(" initial_sectors 0x%x\n", ic->initial_sectors); in dm_integrity_ctr()
4383 DEBUG_print(" metadata_run 0x%x\n", ic->metadata_run); in dm_integrity_ctr()
4384 DEBUG_print(" log2_metadata_run %d\n", ic->log2_metadata_run); in dm_integrity_ctr()
4385 …DEBUG_print(" provided_data_sectors 0x%llx (%llu)\n", ic->provided_data_sectors, ic->provided_data… in dm_integrity_ctr()
4386 DEBUG_print(" log2_buffer_sectors %u\n", ic->log2_buffer_sectors); in dm_integrity_ctr()
4389 if (ic->recalculate_flag && !(ic->sb->flags & cpu_to_le32(SB_FLAG_RECALCULATING))) { in dm_integrity_ctr()
4390 ic->sb->flags |= cpu_to_le32(SB_FLAG_RECALCULATING); in dm_integrity_ctr()
4391 ic->sb->recalc_sector = cpu_to_le64(0); in dm_integrity_ctr()
4394 if (ic->internal_hash) { in dm_integrity_ctr()
4396 ic->recalc_wq = alloc_workqueue("dm-integrity-recalc", WQ_MEM_RECLAIM, 1); in dm_integrity_ctr()
4397 if (!ic->recalc_wq ) { in dm_integrity_ctr()
4402 INIT_WORK(&ic->recalc_work, integrity_recalc); in dm_integrity_ctr()
4403 ic->recalc_buffer = vmalloc(RECALC_SECTORS << SECTOR_SHIFT); in dm_integrity_ctr()
4404 if (!ic->recalc_buffer) { in dm_integrity_ctr()
4409 recalc_tags_size = (RECALC_SECTORS >> ic->sb->log2_sectors_per_block) * ic->tag_size; in dm_integrity_ctr()
4410 if (crypto_shash_digestsize(ic->internal_hash) > ic->tag_size) in dm_integrity_ctr()
4411 recalc_tags_size += crypto_shash_digestsize(ic->internal_hash) - ic->tag_size; in dm_integrity_ctr()
4412 ic->recalc_tags = kvmalloc(recalc_tags_size, GFP_KERNEL); in dm_integrity_ctr()
4413 if (!ic->recalc_tags) { in dm_integrity_ctr()
4419 if (ic->sb->flags & cpu_to_le32(SB_FLAG_RECALCULATING)) { in dm_integrity_ctr()
4426 if (ic->sb->flags & cpu_to_le32(SB_FLAG_RECALCULATING) && in dm_integrity_ctr()
4427 le64_to_cpu(ic->sb->recalc_sector) < ic->provided_data_sectors && in dm_integrity_ctr()
4428 dm_integrity_disable_recalculate(ic)) { in dm_integrity_ctr()
4434 ic->bufio = dm_bufio_client_create(ic->meta_dev ? ic->meta_dev->bdev : ic->dev->bdev, in dm_integrity_ctr()
4435 1U << (SECTOR_SHIFT + ic->log2_buffer_sectors), 1, 0, NULL, NULL); in dm_integrity_ctr()
4436 if (IS_ERR(ic->bufio)) { in dm_integrity_ctr()
4437 r = PTR_ERR(ic->bufio); in dm_integrity_ctr()
4439 ic->bufio = NULL; in dm_integrity_ctr()
4442 dm_bufio_set_sector_offset(ic->bufio, ic->start + ic->initial_sectors); in dm_integrity_ctr()
4444 if (ic->mode != 'R') { in dm_integrity_ctr()
4445 r = create_journal(ic, &ti->error); in dm_integrity_ctr()
4451 if (ic->mode == 'B') { in dm_integrity_ctr()
4453 unsigned n_bitmap_pages = DIV_ROUND_UP(ic->n_bitmap_blocks, PAGE_SIZE / BITMAP_BLOCK_SIZE); in dm_integrity_ctr()
4455 ic->recalc_bitmap = dm_integrity_alloc_page_list(n_bitmap_pages); in dm_integrity_ctr()
4456 if (!ic->recalc_bitmap) { in dm_integrity_ctr()
4460 ic->may_write_bitmap = dm_integrity_alloc_page_list(n_bitmap_pages); in dm_integrity_ctr()
4461 if (!ic->may_write_bitmap) { in dm_integrity_ctr()
4465 ic->bbs = kvmalloc_array(ic->n_bitmap_blocks, sizeof(struct bitmap_block_status), GFP_KERNEL); in dm_integrity_ctr()
4466 if (!ic->bbs) { in dm_integrity_ctr()
4470 INIT_DELAYED_WORK(&ic->bitmap_flush_work, bitmap_flush_work); in dm_integrity_ctr()
4471 for (i = 0; i < ic->n_bitmap_blocks; i++) { in dm_integrity_ctr()
4472 struct bitmap_block_status *bbs = &ic->bbs[i]; in dm_integrity_ctr()
4476 bbs->ic = ic; in dm_integrity_ctr()
4485 bbs->bitmap = lowmem_page_address(ic->journal[pl_index].page) + pl_offset; in dm_integrity_ctr()
4490 init_journal(ic, 0, ic->journal_sections, 0); in dm_integrity_ctr()
4491 r = dm_integrity_failed(ic); in dm_integrity_ctr()
4496 r = sync_rw_sb(ic, REQ_OP_WRITE, REQ_FUA); in dm_integrity_ctr()
4501 ic->just_formatted = true; in dm_integrity_ctr()
4504 if (!ic->meta_dev) { in dm_integrity_ctr()
4505 r = dm_set_target_max_io_len(ti, 1U << ic->sb->log2_interleave_sectors); in dm_integrity_ctr()
4509 if (ic->mode == 'B') { in dm_integrity_ctr()
4510 …unsigned max_io_len = ((sector_t)ic->sectors_per_block << ic->log2_blocks_per_bitmap_bit) * (BITMA… in dm_integrity_ctr()
4521 if (!ic->internal_hash) in dm_integrity_ctr()
4522 dm_integrity_set(ti, ic); in dm_integrity_ctr()
4526 if (ic->discard) in dm_integrity_ctr()
4538 struct dm_integrity_c *ic = ti->private; in dm_integrity_dtr() local
4540 BUG_ON(!RB_EMPTY_ROOT(&ic->in_progress)); in dm_integrity_dtr()
4541 BUG_ON(!list_empty(&ic->wait_list)); in dm_integrity_dtr()
4543 if (ic->mode == 'B') in dm_integrity_dtr()
4544 cancel_delayed_work_sync(&ic->bitmap_flush_work); in dm_integrity_dtr()
4545 if (ic->metadata_wq) in dm_integrity_dtr()
4546 destroy_workqueue(ic->metadata_wq); in dm_integrity_dtr()
4547 if (ic->wait_wq) in dm_integrity_dtr()
4548 destroy_workqueue(ic->wait_wq); in dm_integrity_dtr()
4549 if (ic->offload_wq) in dm_integrity_dtr()
4550 destroy_workqueue(ic->offload_wq); in dm_integrity_dtr()
4551 if (ic->commit_wq) in dm_integrity_dtr()
4552 destroy_workqueue(ic->commit_wq); in dm_integrity_dtr()
4553 if (ic->writer_wq) in dm_integrity_dtr()
4554 destroy_workqueue(ic->writer_wq); in dm_integrity_dtr()
4555 if (ic->recalc_wq) in dm_integrity_dtr()
4556 destroy_workqueue(ic->recalc_wq); in dm_integrity_dtr()
4557 vfree(ic->recalc_buffer); in dm_integrity_dtr()
4558 kvfree(ic->recalc_tags); in dm_integrity_dtr()
4559 kvfree(ic->bbs); in dm_integrity_dtr()
4560 if (ic->bufio) in dm_integrity_dtr()
4561 dm_bufio_client_destroy(ic->bufio); in dm_integrity_dtr()
4562 mempool_exit(&ic->journal_io_mempool); in dm_integrity_dtr()
4563 if (ic->io) in dm_integrity_dtr()
4564 dm_io_client_destroy(ic->io); in dm_integrity_dtr()
4565 if (ic->dev) in dm_integrity_dtr()
4566 dm_put_device(ti, ic->dev); in dm_integrity_dtr()
4567 if (ic->meta_dev) in dm_integrity_dtr()
4568 dm_put_device(ti, ic->meta_dev); in dm_integrity_dtr()
4569 dm_integrity_free_page_list(ic->journal); in dm_integrity_dtr()
4570 dm_integrity_free_page_list(ic->journal_io); in dm_integrity_dtr()
4571 dm_integrity_free_page_list(ic->journal_xor); in dm_integrity_dtr()
4572 dm_integrity_free_page_list(ic->recalc_bitmap); in dm_integrity_dtr()
4573 dm_integrity_free_page_list(ic->may_write_bitmap); in dm_integrity_dtr()
4574 if (ic->journal_scatterlist) in dm_integrity_dtr()
4575 dm_integrity_free_journal_scatterlist(ic, ic->journal_scatterlist); in dm_integrity_dtr()
4576 if (ic->journal_io_scatterlist) in dm_integrity_dtr()
4577 dm_integrity_free_journal_scatterlist(ic, ic->journal_io_scatterlist); in dm_integrity_dtr()
4578 if (ic->sk_requests) { in dm_integrity_dtr()
4581 for (i = 0; i < ic->journal_sections; i++) { in dm_integrity_dtr()
4582 struct skcipher_request *req = ic->sk_requests[i]; in dm_integrity_dtr()
4588 kvfree(ic->sk_requests); in dm_integrity_dtr()
4590 kvfree(ic->journal_tree); in dm_integrity_dtr()
4591 if (ic->sb) in dm_integrity_dtr()
4592 free_pages_exact(ic->sb, SB_SECTORS << SECTOR_SHIFT); in dm_integrity_dtr()
4594 if (ic->internal_hash) in dm_integrity_dtr()
4595 crypto_free_shash(ic->internal_hash); in dm_integrity_dtr()
4596 free_alg(&ic->internal_hash_alg); in dm_integrity_dtr()
4598 if (ic->journal_crypt) in dm_integrity_dtr()
4599 crypto_free_skcipher(ic->journal_crypt); in dm_integrity_dtr()
4600 free_alg(&ic->journal_crypt_alg); in dm_integrity_dtr()
4602 if (ic->journal_mac) in dm_integrity_dtr()
4603 crypto_free_shash(ic->journal_mac); in dm_integrity_dtr()
4604 free_alg(&ic->journal_mac_alg); in dm_integrity_dtr()
4606 kfree(ic); in dm_integrity_dtr()