Lines Matching full:ic
106 #define journal_entry_tag(ic, je) ((__u8 *)&(je)->last_bytes[(ic)->sectors_per_block]) argument
301 struct dm_integrity_c *ic; member
319 struct dm_integrity_c *ic; member
331 struct dm_integrity_c *ic; member
389 static void dm_integrity_io_error(struct dm_integrity_c *ic, const char *msg, int err) in dm_integrity_io_error() argument
392 atomic64_inc(&ic->number_of_mismatches); in dm_integrity_io_error()
393 if (!cmpxchg(&ic->failed, 0, err)) in dm_integrity_io_error()
397 static int dm_integrity_failed(struct dm_integrity_c *ic) in dm_integrity_failed() argument
399 return READ_ONCE(ic->failed); in dm_integrity_failed()
402 static bool dm_integrity_disable_recalculate(struct dm_integrity_c *ic) in dm_integrity_disable_recalculate() argument
404 if (ic->legacy_recalculate) in dm_integrity_disable_recalculate()
406 if (!(ic->sb->flags & cpu_to_le32(SB_FLAG_FIXED_HMAC)) ? in dm_integrity_disable_recalculate()
407 ic->internal_hash_alg.key || ic->journal_mac_alg.key : in dm_integrity_disable_recalculate()
408 ic->internal_hash_alg.key && !ic->journal_mac_alg.key) in dm_integrity_disable_recalculate()
413 static commit_id_t dm_integrity_commit_id(struct dm_integrity_c *ic, unsigned i, in dm_integrity_commit_id() argument
420 return ic->commit_ids[seq] ^ cpu_to_le64(((__u64)i << 32) ^ j); in dm_integrity_commit_id()
423 static void get_area_and_offset(struct dm_integrity_c *ic, sector_t data_sector, in get_area_and_offset() argument
426 if (!ic->meta_dev) { in get_area_and_offset()
427 __u8 log2_interleave_sectors = ic->sb->log2_interleave_sectors; in get_area_and_offset()
436 #define sector_to_block(ic, n) \ argument
438 BUG_ON((n) & (unsigned)((ic)->sectors_per_block - 1)); \
439 (n) >>= (ic)->sb->log2_sectors_per_block; \
442 static __u64 get_metadata_sector_and_offset(struct dm_integrity_c *ic, sector_t area, in get_metadata_sector_and_offset() argument
448 ms = area << ic->sb->log2_interleave_sectors; in get_metadata_sector_and_offset()
449 if (likely(ic->log2_metadata_run >= 0)) in get_metadata_sector_and_offset()
450 ms += area << ic->log2_metadata_run; in get_metadata_sector_and_offset()
452 ms += area * ic->metadata_run; in get_metadata_sector_and_offset()
453 ms >>= ic->log2_buffer_sectors; in get_metadata_sector_and_offset()
455 sector_to_block(ic, offset); in get_metadata_sector_and_offset()
457 if (likely(ic->log2_tag_size >= 0)) { in get_metadata_sector_and_offset()
458 ms += offset >> (SECTOR_SHIFT + ic->log2_buffer_sectors - ic->log2_tag_size); in get_metadata_sector_and_offset()
459 mo = (offset << ic->log2_tag_size) & ((1U << SECTOR_SHIFT << ic->log2_buffer_sectors) - 1); in get_metadata_sector_and_offset()
461 ms += (__u64)offset * ic->tag_size >> (SECTOR_SHIFT + ic->log2_buffer_sectors); in get_metadata_sector_and_offset()
462 mo = (offset * ic->tag_size) & ((1U << SECTOR_SHIFT << ic->log2_buffer_sectors) - 1); in get_metadata_sector_and_offset()
468 static sector_t get_data_sector(struct dm_integrity_c *ic, sector_t area, sector_t offset) in get_data_sector() argument
472 if (ic->meta_dev) in get_data_sector()
475 result = area << ic->sb->log2_interleave_sectors; in get_data_sector()
476 if (likely(ic->log2_metadata_run >= 0)) in get_data_sector()
477 result += (area + 1) << ic->log2_metadata_run; in get_data_sector()
479 result += (area + 1) * ic->metadata_run; in get_data_sector()
481 result += (sector_t)ic->initial_sectors + offset; in get_data_sector()
482 result += ic->start; in get_data_sector()
487 static void wraparound_section(struct dm_integrity_c *ic, unsigned *sec_ptr) in wraparound_section() argument
489 if (unlikely(*sec_ptr >= ic->journal_sections)) in wraparound_section()
490 *sec_ptr -= ic->journal_sections; in wraparound_section()
493 static void sb_set_version(struct dm_integrity_c *ic) in sb_set_version() argument
495 if (ic->sb->flags & cpu_to_le32(SB_FLAG_FIXED_HMAC)) in sb_set_version()
496 ic->sb->version = SB_VERSION_5; in sb_set_version()
497 else if (ic->sb->flags & cpu_to_le32(SB_FLAG_FIXED_PADDING)) in sb_set_version()
498 ic->sb->version = SB_VERSION_4; in sb_set_version()
499 else if (ic->mode == 'B' || ic->sb->flags & cpu_to_le32(SB_FLAG_DIRTY_BITMAP)) in sb_set_version()
500 ic->sb->version = SB_VERSION_3; in sb_set_version()
501 else if (ic->meta_dev || ic->sb->flags & cpu_to_le32(SB_FLAG_RECALCULATING)) in sb_set_version()
502 ic->sb->version = SB_VERSION_2; in sb_set_version()
504 ic->sb->version = SB_VERSION_1; in sb_set_version()
507 static int sb_mac(struct dm_integrity_c *ic, bool wr) in sb_mac() argument
509 SHASH_DESC_ON_STACK(desc, ic->journal_mac); in sb_mac()
511 unsigned size = crypto_shash_digestsize(ic->journal_mac); in sb_mac()
514 dm_integrity_io_error(ic, "digest is too long", -EINVAL); in sb_mac()
518 desc->tfm = ic->journal_mac; in sb_mac()
522 dm_integrity_io_error(ic, "crypto_shash_init", r); in sb_mac()
526 r = crypto_shash_update(desc, (__u8 *)ic->sb, (1 << SECTOR_SHIFT) - size); in sb_mac()
528 dm_integrity_io_error(ic, "crypto_shash_update", r); in sb_mac()
533 r = crypto_shash_final(desc, (__u8 *)ic->sb + (1 << SECTOR_SHIFT) - size); in sb_mac()
535 dm_integrity_io_error(ic, "crypto_shash_final", r); in sb_mac()
542 dm_integrity_io_error(ic, "crypto_shash_final", r); in sb_mac()
545 if (memcmp((__u8 *)ic->sb + (1 << SECTOR_SHIFT) - size, result, size)) { in sb_mac()
546 dm_integrity_io_error(ic, "superblock mac", -EILSEQ); in sb_mac()
547 dm_audit_log_target(DM_MSG_PREFIX, "mac-superblock", ic->ti, 0); in sb_mac()
555 static int sync_rw_sb(struct dm_integrity_c *ic, blk_opf_t opf) in sync_rw_sb() argument
564 io_req.mem.ptr.addr = ic->sb; in sync_rw_sb()
566 io_req.client = ic->io; in sync_rw_sb()
567 io_loc.bdev = ic->meta_dev ? ic->meta_dev->bdev : ic->dev->bdev; in sync_rw_sb()
568 io_loc.sector = ic->start; in sync_rw_sb()
572 sb_set_version(ic); in sync_rw_sb()
573 if (ic->journal_mac && ic->sb->flags & cpu_to_le32(SB_FLAG_FIXED_HMAC)) { in sync_rw_sb()
574 r = sb_mac(ic, true); in sync_rw_sb()
585 if (ic->mode != 'R' && ic->journal_mac && ic->sb->flags & cpu_to_le32(SB_FLAG_FIXED_HMAC)) { in sync_rw_sb()
586 r = sb_mac(ic, false); in sync_rw_sb()
600 static bool block_bitmap_op(struct dm_integrity_c *ic, struct page_list *bitmap, in block_bitmap_op() argument
606 if (unlikely(((sector | n_sectors) & ((1 << ic->sb->log2_sectors_per_block) - 1)) != 0)) { in block_bitmap_op()
610 ic->sb->log2_sectors_per_block, in block_bitmap_op()
611 ic->log2_blocks_per_bitmap_bit, in block_bitmap_op()
619 bit = sector >> (ic->sb->log2_sectors_per_block + ic->log2_blocks_per_bitmap_bit); in block_bitmap_op()
621 (ic->sb->log2_sectors_per_block + ic->log2_blocks_per_bitmap_bit); in block_bitmap_op()
705 static void block_bitmap_copy(struct dm_integrity_c *ic, struct page_list *dst, struct page_list *s… in block_bitmap_copy() argument
707 unsigned n_bitmap_pages = DIV_ROUND_UP(ic->n_bitmap_blocks, PAGE_SIZE / BITMAP_BLOCK_SIZE); in block_bitmap_copy()
717 static struct bitmap_block_status *sector_to_bitmap_block(struct dm_integrity_c *ic, sector_t secto… in sector_to_bitmap_block() argument
719 unsigned bit = sector >> (ic->sb->log2_sectors_per_block + ic->log2_blocks_per_bitmap_bit); in sector_to_bitmap_block()
722 BUG_ON(bitmap_block >= ic->n_bitmap_blocks); in sector_to_bitmap_block()
723 return &ic->bbs[bitmap_block]; in sector_to_bitmap_block()
726 static void access_journal_check(struct dm_integrity_c *ic, unsigned section, unsigned offset, in access_journal_check() argument
730 unsigned limit = e ? ic->journal_section_entries : ic->journal_section_sectors; in access_journal_check()
732 if (unlikely(section >= ic->journal_sections) || in access_journal_check()
735 function, section, offset, ic->journal_sections, limit); in access_journal_check()
741 static void page_list_location(struct dm_integrity_c *ic, unsigned section, unsigned offset, in page_list_location() argument
746 access_journal_check(ic, section, offset, false, "page_list_location"); in page_list_location()
748 sector = section * ic->journal_section_sectors + offset; in page_list_location()
754 static struct journal_sector *access_page_list(struct dm_integrity_c *ic, struct page_list *pl, in access_page_list() argument
760 page_list_location(ic, section, offset, &pl_index, &pl_offset); in access_page_list()
770 static struct journal_sector *access_journal(struct dm_integrity_c *ic, unsigned section, unsigned … in access_journal() argument
772 return access_page_list(ic, ic->journal, section, offset, NULL); in access_journal()
775 static struct journal_entry *access_journal_entry(struct dm_integrity_c *ic, unsigned section, unsi… in access_journal_entry() argument
780 access_journal_check(ic, section, n, true, "access_journal_entry"); in access_journal_entry()
785 js = access_journal(ic, section, rel_sector); in access_journal_entry()
786 return (struct journal_entry *)((char *)js + offset * ic->journal_entry_size); in access_journal_entry()
789 static struct journal_sector *access_journal_data(struct dm_integrity_c *ic, unsigned section, unsi… in access_journal_data() argument
791 n <<= ic->sb->log2_sectors_per_block; in access_journal_data()
795 access_journal_check(ic, section, n, false, "access_journal_data"); in access_journal_data()
797 return access_journal(ic, section, n); in access_journal_data()
800 static void section_mac(struct dm_integrity_c *ic, unsigned section, __u8 result[JOURNAL_MAC_SIZE]) in section_mac() argument
802 SHASH_DESC_ON_STACK(desc, ic->journal_mac); in section_mac()
806 desc->tfm = ic->journal_mac; in section_mac()
810 dm_integrity_io_error(ic, "crypto_shash_init", r); in section_mac()
814 if (ic->sb->flags & cpu_to_le32(SB_FLAG_FIXED_HMAC)) { in section_mac()
817 r = crypto_shash_update(desc, (__u8 *)&ic->sb->salt, SALT_SIZE); in section_mac()
819 dm_integrity_io_error(ic, "crypto_shash_update", r); in section_mac()
826 dm_integrity_io_error(ic, "crypto_shash_update", r); in section_mac()
831 for (j = 0; j < ic->journal_section_entries; j++) { in section_mac()
832 struct journal_entry *je = access_journal_entry(ic, section, j); in section_mac()
835 dm_integrity_io_error(ic, "crypto_shash_update", r); in section_mac()
840 size = crypto_shash_digestsize(ic->journal_mac); in section_mac()
845 dm_integrity_io_error(ic, "crypto_shash_final", r); in section_mac()
853 dm_integrity_io_error(ic, "digest_size", -EINVAL); in section_mac()
858 dm_integrity_io_error(ic, "crypto_shash_final", r); in section_mac()
869 static void rw_section_mac(struct dm_integrity_c *ic, unsigned section, bool wr) in rw_section_mac() argument
874 if (!ic->journal_mac) in rw_section_mac()
877 section_mac(ic, section, result); in rw_section_mac()
880 struct journal_sector *js = access_journal(ic, section, j); in rw_section_mac()
886 dm_integrity_io_error(ic, "journal mac", -EILSEQ); in rw_section_mac()
887 dm_audit_log_target(DM_MSG_PREFIX, "mac-journal", ic->ti, 0); in rw_section_mac()
901 static void xor_journal(struct dm_integrity_c *ic, bool encrypt, unsigned section, in xor_journal() argument
905 size_t n_bytes = (size_t)(n_sections * ic->journal_section_sectors) << SECTOR_SHIFT; in xor_journal()
910 source_pl = ic->journal; in xor_journal()
911 target_pl = ic->journal_io; in xor_journal()
913 source_pl = ic->journal_io; in xor_journal()
914 target_pl = ic->journal; in xor_journal()
917 page_list_location(ic, section, 0, &pl_index, &pl_offset); in xor_journal()
933 rw_section_mac(ic, section, true); in xor_journal()
938 page_list_location(ic, section, 0, §ion_index, &dummy); in xor_journal()
944 src_pages[1] = ic->journal_xor[pl_index].page; in xor_journal()
963 complete(&comp->ic->crypto_backoff); in complete_journal_encrypt()
966 dm_integrity_io_error(comp->ic, "asynchronous encrypt", err); in complete_journal_encrypt()
985 wait_for_completion(&comp->ic->crypto_backoff); in do_crypt()
986 reinit_completion(&comp->ic->crypto_backoff); in do_crypt()
989 dm_integrity_io_error(comp->ic, "encrypt", r); in do_crypt()
993 static void crypt_journal(struct dm_integrity_c *ic, bool encrypt, unsigned section, in crypt_journal() argument
1002 source_sg = ic->journal_scatterlist; in crypt_journal()
1003 target_sg = ic->journal_io_scatterlist; in crypt_journal()
1005 source_sg = ic->journal_io_scatterlist; in crypt_journal()
1006 target_sg = ic->journal_scatterlist; in crypt_journal()
1015 rw_section_mac(ic, section, true); in crypt_journal()
1017 req = ic->sk_requests[section]; in crypt_journal()
1018 ivsize = crypto_skcipher_ivsize(ic->journal_crypt); in crypt_journal()
1037 static void encrypt_journal(struct dm_integrity_c *ic, bool encrypt, unsigned section, in encrypt_journal() argument
1040 if (ic->journal_xor) in encrypt_journal()
1041 return xor_journal(ic, encrypt, section, n_sections, comp); in encrypt_journal()
1043 return crypt_journal(ic, encrypt, section, n_sections, comp); in encrypt_journal()
1050 dm_integrity_io_error(comp->ic, "writing journal", -EIO); in complete_journal_io()
1054 static void rw_journal_sectors(struct dm_integrity_c *ic, blk_opf_t opf, in rw_journal_sectors() argument
1063 if (unlikely(dm_integrity_failed(ic))) { in rw_journal_sectors()
1074 if (ic->journal_io) in rw_journal_sectors()
1075 io_req.mem.ptr.pl = &ic->journal_io[pl_index]; in rw_journal_sectors()
1077 io_req.mem.ptr.pl = &ic->journal[pl_index]; in rw_journal_sectors()
1085 io_req.client = ic->io; in rw_journal_sectors()
1086 io_loc.bdev = ic->meta_dev ? ic->meta_dev->bdev : ic->dev->bdev; in rw_journal_sectors()
1087 io_loc.sector = ic->start + SB_SECTORS + sector; in rw_journal_sectors()
1092 dm_integrity_io_error(ic, (opf & REQ_OP_MASK) == REQ_OP_READ ? in rw_journal_sectors()
1101 static void rw_journal(struct dm_integrity_c *ic, blk_opf_t opf, in rw_journal() argument
1107 sector = section * ic->journal_section_sectors; in rw_journal()
1108 n_sectors = n_sections * ic->journal_section_sectors; in rw_journal()
1110 rw_journal_sectors(ic, opf, sector, n_sectors, comp); in rw_journal()
1113 static void write_journal(struct dm_integrity_c *ic, unsigned commit_start, unsigned commit_section… in write_journal() argument
1120 io_comp.ic = ic; in write_journal()
1123 if (commit_start + commit_sections <= ic->journal_sections) { in write_journal()
1125 if (ic->journal_io) { in write_journal()
1126 crypt_comp_1.ic = ic; in write_journal()
1129 encrypt_journal(ic, true, commit_start, commit_sections, &crypt_comp_1); in write_journal()
1133 rw_section_mac(ic, commit_start + i, true); in write_journal()
1135 rw_journal(ic, REQ_OP_WRITE | REQ_FUA | REQ_SYNC, commit_start, in write_journal()
1140 to_end = ic->journal_sections - commit_start; in write_journal()
1141 if (ic->journal_io) { in write_journal()
1142 crypt_comp_1.ic = ic; in write_journal()
1145 encrypt_journal(ic, true, commit_start, to_end, &crypt_comp_1); in write_journal()
1147 rw_journal(ic, REQ_OP_WRITE | REQ_FUA, in write_journal()
1151 encrypt_journal(ic, true, 0, commit_sections - to_end, &crypt_comp_1); in write_journal()
1154 crypt_comp_2.ic = ic; in write_journal()
1157 encrypt_journal(ic, true, 0, commit_sections - to_end, &crypt_comp_2); in write_journal()
1159 rw_journal(ic, REQ_OP_WRITE | REQ_FUA, commit_start, to_end, &io_comp); in write_journal()
1164 rw_section_mac(ic, commit_start + i, true); in write_journal()
1165 rw_journal(ic, REQ_OP_WRITE | REQ_FUA, commit_start, to_end, &io_comp); in write_journal()
1167 rw_section_mac(ic, i, true); in write_journal()
1169 rw_journal(ic, REQ_OP_WRITE | REQ_FUA, 0, commit_sections - to_end, &io_comp); in write_journal()
1175 static void copy_from_journal(struct dm_integrity_c *ic, unsigned section, unsigned offset, in copy_from_journal() argument
1183 BUG_ON((target | n_sectors | offset) & (unsigned)(ic->sectors_per_block - 1)); in copy_from_journal()
1185 if (unlikely(dm_integrity_failed(ic))) { in copy_from_journal()
1190 sector = section * ic->journal_section_sectors + JOURNAL_BLOCK_SECTORS + offset; in copy_from_journal()
1197 io_req.mem.ptr.pl = &ic->journal[pl_index]; in copy_from_journal()
1201 io_req.client = ic->io; in copy_from_journal()
1202 io_loc.bdev = ic->dev->bdev; in copy_from_journal()
1219 static bool add_new_range(struct dm_integrity_c *ic, struct dm_integrity_range *new_range, bool che… in add_new_range() argument
1221 struct rb_node **n = &ic->in_progress.rb_node; in add_new_range()
1224 BUG_ON((new_range->logical_sector | new_range->n_sectors) & (unsigned)(ic->sectors_per_block - 1)); in add_new_range()
1228 list_for_each_entry(range, &ic->wait_list, wait_entry) { in add_new_range()
1250 rb_insert_color(&new_range->node, &ic->in_progress); in add_new_range()
1255 static void remove_range_unlocked(struct dm_integrity_c *ic, struct dm_integrity_range *range) in remove_range_unlocked() argument
1257 rb_erase(&range->node, &ic->in_progress); in remove_range_unlocked()
1258 while (unlikely(!list_empty(&ic->wait_list))) { in remove_range_unlocked()
1260 list_first_entry(&ic->wait_list, struct dm_integrity_range, wait_entry); in remove_range_unlocked()
1264 if (!add_new_range(ic, last_range, false)) { in remove_range_unlocked()
1266 list_add(&last_range->wait_entry, &ic->wait_list); in remove_range_unlocked()
1274 static void remove_range(struct dm_integrity_c *ic, struct dm_integrity_range *range) in remove_range() argument
1278 spin_lock_irqsave(&ic->endio_wait.lock, flags); in remove_range()
1279 remove_range_unlocked(ic, range); in remove_range()
1280 spin_unlock_irqrestore(&ic->endio_wait.lock, flags); in remove_range()
1283 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
1286 list_add_tail(&new_range->wait_entry, &ic->wait_list); in wait_and_add_new_range()
1290 spin_unlock_irq(&ic->endio_wait.lock); in wait_and_add_new_range()
1292 spin_lock_irq(&ic->endio_wait.lock); in wait_and_add_new_range()
1296 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
1298 if (unlikely(!add_new_range(ic, new_range, true))) in add_new_range_and_wait()
1299 wait_and_add_new_range(ic, new_range); in add_new_range_and_wait()
1308 static void add_journal_node(struct dm_integrity_c *ic, struct journal_node *node, sector_t sector) in add_journal_node() argument
1316 link = &ic->journal_tree_root.rb_node; in add_journal_node()
1330 rb_insert_color(&node->node, &ic->journal_tree_root); in add_journal_node()
1333 static void remove_journal_node(struct dm_integrity_c *ic, struct journal_node *node) in remove_journal_node() argument
1336 rb_erase(&node->node, &ic->journal_tree_root); in remove_journal_node()
1342 static unsigned find_journal_node(struct dm_integrity_c *ic, sector_t sector, sector_t *next_sector) in find_journal_node() argument
1344 struct rb_node *n = ic->journal_tree_root.rb_node; in find_journal_node()
1350 found = j - ic->journal_tree; in find_journal_node()
1363 static bool test_journal_node(struct dm_integrity_c *ic, unsigned pos, sector_t sector) in test_journal_node() argument
1368 if (unlikely(pos >= ic->journal_entries)) in test_journal_node()
1370 node = &ic->journal_tree[pos]; in test_journal_node()
1384 static bool find_newer_committed_node(struct dm_integrity_c *ic, struct journal_node *node) in find_newer_committed_node() argument
1401 next_section = (unsigned)(next_node - ic->journal_tree) / ic->journal_section_entries; in find_newer_committed_node()
1402 if (next_section >= ic->committed_section && in find_newer_committed_node()
1403 next_section < ic->committed_section + ic->n_committed_sections) in find_newer_committed_node()
1405 if (next_section + ic->journal_sections < ic->committed_section + ic->n_committed_sections) in find_newer_committed_node()
1415 static int dm_integrity_rw_tag(struct dm_integrity_c *ic, unsigned char *tag, sector_t *metadata_bl… in dm_integrity_rw_tag() argument
1421 unsigned may_be = MAY_BE_HASH | (ic->discard ? MAY_BE_FILLER : 0); in dm_integrity_rw_tag()
1429 r = dm_integrity_failed(ic); in dm_integrity_rw_tag()
1433 data = dm_bufio_read(ic->bufio, *metadata_block, &b); in dm_integrity_rw_tag()
1437 to_copy = min((1U << SECTOR_SHIFT << ic->log2_buffer_sectors) - *metadata_offset, total_size); in dm_integrity_rw_tag()
1449 if (likely(is_power_of_2(ic->tag_size))) { in dm_integrity_rw_tag()
1451 if (unlikely(!ic->discard) || in dm_integrity_rw_tag()
1466 if (unlikely(hash_offset == ic->tag_size)) { in dm_integrity_rw_tag()
1472 may_be = MAY_BE_HASH | (ic->discard ? MAY_BE_FILLER : 0); in dm_integrity_rw_tag()
1481 if (unlikely(*metadata_offset == 1U << SECTOR_SHIFT << ic->log2_buffer_sectors)) { in dm_integrity_rw_tag()
1486 if (unlikely(!is_power_of_2(ic->tag_size))) { in dm_integrity_rw_tag()
1487 hash_offset = (hash_offset + to_copy) % ic->tag_size; in dm_integrity_rw_tag()
1501 struct dm_integrity_c *ic; member
1509 dm_integrity_io_error(fr->ic, "flushing disk cache", -EIO); in flush_notify()
1513 static void dm_integrity_flush_buffers(struct dm_integrity_c *ic, bool flush_data) in dm_integrity_flush_buffers() argument
1519 if (!ic->meta_dev) in dm_integrity_flush_buffers()
1527 fr.io_req.client = dm_bufio_get_dm_io_client(ic->bufio), in dm_integrity_flush_buffers()
1528 fr.io_reg.bdev = ic->dev->bdev, in dm_integrity_flush_buffers()
1531 fr.ic = ic; in dm_integrity_flush_buffers()
1537 r = dm_bufio_write_dirty_buffers(ic->bufio); in dm_integrity_flush_buffers()
1539 dm_integrity_io_error(ic, "writing tags", r); in dm_integrity_flush_buffers()
1545 static void sleep_on_endio_wait(struct dm_integrity_c *ic) in sleep_on_endio_wait() argument
1548 __add_wait_queue(&ic->endio_wait, &wait); in sleep_on_endio_wait()
1550 spin_unlock_irq(&ic->endio_wait.lock); in sleep_on_endio_wait()
1552 spin_lock_irq(&ic->endio_wait.lock); in sleep_on_endio_wait()
1553 __remove_wait_queue(&ic->endio_wait, &wait); in sleep_on_endio_wait()
1558 struct dm_integrity_c *ic = from_timer(ic, t, autocommit_timer); in autocommit_fn() local
1560 if (likely(!dm_integrity_failed(ic))) in autocommit_fn()
1561 queue_work(ic->commit_wq, &ic->commit_work); in autocommit_fn()
1564 static void schedule_autocommit(struct dm_integrity_c *ic) in schedule_autocommit() argument
1566 if (!timer_pending(&ic->autocommit_timer)) in schedule_autocommit()
1567 mod_timer(&ic->autocommit_timer, jiffies + ic->autocommit_jiffies); in schedule_autocommit()
1570 static void submit_flush_bio(struct dm_integrity_c *ic, struct dm_integrity_io *dio) in submit_flush_bio() argument
1575 spin_lock_irqsave(&ic->endio_wait.lock, flags); in submit_flush_bio()
1577 bio_list_add(&ic->flush_bio_list, bio); in submit_flush_bio()
1578 spin_unlock_irqrestore(&ic->endio_wait.lock, flags); in submit_flush_bio()
1580 queue_work(ic->commit_wq, &ic->commit_work); in submit_flush_bio()
1583 static void do_endio(struct dm_integrity_c *ic, struct bio *bio) in do_endio() argument
1585 int r = dm_integrity_failed(ic); in do_endio()
1588 if (unlikely(ic->synchronous_mode) && bio_op(bio) == REQ_OP_WRITE) { in do_endio()
1590 spin_lock_irqsave(&ic->endio_wait.lock, flags); in do_endio()
1591 bio_list_add(&ic->synchronous_bios, bio); in do_endio()
1592 queue_delayed_work(ic->commit_wq, &ic->bitmap_flush_work, 0); in do_endio()
1593 spin_unlock_irqrestore(&ic->endio_wait.lock, flags); in do_endio()
1599 static void do_endio_flush(struct dm_integrity_c *ic, struct dm_integrity_io *dio) in do_endio_flush() argument
1603 if (unlikely(dio->fua) && likely(!bio->bi_status) && likely(!dm_integrity_failed(ic))) in do_endio_flush()
1604 submit_flush_bio(ic, dio); in do_endio_flush()
1606 do_endio(ic, bio); in do_endio_flush()
1612 struct dm_integrity_c *ic = dio->ic; in dec_in_flight() local
1615 remove_range(ic, &dio->range); in dec_in_flight()
1618 schedule_autocommit(ic); in dec_in_flight()
1628 queue_work(ic->offload_wq, &dio->work); in dec_in_flight()
1631 do_endio_flush(ic, dio); in dec_in_flight()
1649 static void integrity_sector_checksum(struct dm_integrity_c *ic, sector_t sector, in integrity_sector_checksum() argument
1653 SHASH_DESC_ON_STACK(req, ic->internal_hash); in integrity_sector_checksum()
1657 req->tfm = ic->internal_hash; in integrity_sector_checksum()
1661 dm_integrity_io_error(ic, "crypto_shash_init", r); in integrity_sector_checksum()
1665 if (ic->sb->flags & cpu_to_le32(SB_FLAG_FIXED_HMAC)) { in integrity_sector_checksum()
1666 r = crypto_shash_update(req, (__u8 *)&ic->sb->salt, SALT_SIZE); in integrity_sector_checksum()
1668 dm_integrity_io_error(ic, "crypto_shash_update", r); in integrity_sector_checksum()
1675 dm_integrity_io_error(ic, "crypto_shash_update", r); in integrity_sector_checksum()
1679 r = crypto_shash_update(req, data, ic->sectors_per_block << SECTOR_SHIFT); in integrity_sector_checksum()
1681 dm_integrity_io_error(ic, "crypto_shash_update", r); in integrity_sector_checksum()
1687 dm_integrity_io_error(ic, "crypto_shash_final", r); in integrity_sector_checksum()
1691 digest_size = crypto_shash_digestsize(ic->internal_hash); in integrity_sector_checksum()
1692 if (unlikely(digest_size < ic->tag_size)) in integrity_sector_checksum()
1693 memset(result + digest_size, 0, ic->tag_size - digest_size); in integrity_sector_checksum()
1699 get_random_bytes(result, ic->tag_size); in integrity_sector_checksum()
1705 struct dm_integrity_c *ic = dio->ic; in integrity_metadata() local
1709 if (ic->internal_hash) { in integrity_metadata()
1712 unsigned digest_size = crypto_shash_digestsize(ic->internal_hash); in integrity_metadata()
1715 unsigned extra_space = unlikely(digest_size > ic->tag_size) ? digest_size - ic->tag_size : 0; in integrity_metadata()
1720 if (unlikely(ic->mode == 'R')) in integrity_metadata()
1724 …checksums = kmalloc((PAGE_SIZE >> SECTOR_SHIFT >> ic->sb->log2_sectors_per_block) * ic->tag_size +… in integrity_metadata()
1741 unsigned max_blocks = max_size / ic->tag_size; in integrity_metadata()
1745 unsigned this_step_blocks = bi_size >> (SECTOR_SHIFT + ic->sb->log2_sectors_per_block); in integrity_metadata()
1747 r = dm_integrity_rw_tag(ic, checksums, &dio->metadata_block, &dio->metadata_offset, in integrity_metadata()
1748 this_step_blocks * ic->tag_size, TAG_WRITE); in integrity_metadata()
1755 /*if (bi_size < this_step_blocks << (SECTOR_SHIFT + ic->sb->log2_sectors_per_block)) { in integrity_metadata()
1760 bi_size -= this_step_blocks << (SECTOR_SHIFT + ic->sb->log2_sectors_per_block); in integrity_metadata()
1761 bi_sector += this_step_blocks << ic->sb->log2_sectors_per_block; in integrity_metadata()
1781 integrity_sector_checksum(ic, sector, mem + pos, checksums_ptr); in integrity_metadata()
1782 checksums_ptr += ic->tag_size; in integrity_metadata()
1783 sectors_to_process -= ic->sectors_per_block; in integrity_metadata()
1784 pos += ic->sectors_per_block << SECTOR_SHIFT; in integrity_metadata()
1785 sector += ic->sectors_per_block; in integrity_metadata()
1789 r = dm_integrity_rw_tag(ic, checksums, &dio->metadata_block, &dio->metadata_offset, in integrity_metadata()
1795 s = sector - ((r + ic->tag_size - 1) / ic->tag_size); in integrity_metadata()
1799 atomic64_inc(&ic->number_of_mismatches); in integrity_metadata()
1827 sector_to_block(ic, data_to_process); in integrity_metadata()
1828 data_to_process *= ic->tag_size; in integrity_metadata()
1837 r = dm_integrity_rw_tag(ic, tag, &dio->metadata_block, &dio->metadata_offset, in integrity_metadata()
1857 struct dm_integrity_c *ic = ti->private; in dm_integrity_map() local
1863 dio->ic = ic; in dm_integrity_map()
1881 submit_flush_bio(ic, dio); in dm_integrity_map()
1894 if (unlikely(dio->range.logical_sector + bio_sectors(bio) > ic->provided_data_sectors)) { in dm_integrity_map()
1897 ic->provided_data_sectors); in dm_integrity_map()
1900 …if (unlikely((dio->range.logical_sector | bio_sectors(bio)) & (unsigned)(ic->sectors_per_block - 1… in dm_integrity_map()
1902 ic->sectors_per_block, in dm_integrity_map()
1907 if (ic->sectors_per_block > 1 && likely(dio->op != REQ_OP_DISCARD)) { in dm_integrity_map()
1911 if (unlikely(bv.bv_len & ((ic->sectors_per_block << SECTOR_SHIFT) - 1))) { in dm_integrity_map()
1913 bv.bv_offset, bv.bv_len, ic->sectors_per_block); in dm_integrity_map()
1920 if (!ic->internal_hash) { in dm_integrity_map()
1922 unsigned wanted_tag_size = bio_sectors(bio) >> ic->sb->log2_sectors_per_block; in dm_integrity_map()
1923 if (ic->log2_tag_size >= 0) in dm_integrity_map()
1924 wanted_tag_size <<= ic->log2_tag_size; in dm_integrity_map()
1926 wanted_tag_size *= ic->tag_size; in dm_integrity_map()
1940 if (unlikely(ic->mode == 'R') && unlikely(dio->op != REQ_OP_READ)) in dm_integrity_map()
1943 get_area_and_offset(ic, dio->range.logical_sector, &area, &offset); in dm_integrity_map()
1944 dio->metadata_block = get_metadata_sector_and_offset(ic, area, offset, &dio->metadata_offset); in dm_integrity_map()
1945 bio->bi_iter.bi_sector = get_data_sector(ic, area, offset); in dm_integrity_map()
1954 struct dm_integrity_c *ic = dio->ic; in __journal_read_write() local
1974 struct journal_entry *je = access_journal_entry(ic, journal_section, journal_entry); in __journal_read_write()
1985 __io_wait_event(ic->copy_to_journal_wait, !journal_entry_is_inprogress(je)); in __journal_read_write()
1990 js = access_journal_data(ic, journal_section, journal_entry); in __journal_read_write()
1998 } while (++s < ic->sectors_per_block); in __journal_read_write()
2000 if (ic->internal_hash) { in __journal_read_write()
2003 integrity_sector_checksum(ic, logical_sector, mem + bv.bv_offset, checksums_onstack); in __journal_read_write()
2004 if (unlikely(memcmp(checksums_onstack, journal_entry_tag(ic, je), ic->tag_size))) { in __journal_read_write()
2014 if (!ic->internal_hash) { in __journal_read_write()
2016 unsigned tag_todo = ic->tag_size; in __journal_read_write()
2017 char *tag_ptr = journal_entry_tag(ic, je); in __journal_read_write()
2042 js = access_journal_data(ic, journal_section, journal_entry); in __journal_read_write()
2043 memcpy(js, mem + bv.bv_offset, ic->sectors_per_block << SECTOR_SHIFT); in __journal_read_write()
2048 } while (++s < ic->sectors_per_block); in __journal_read_write()
2050 if (ic->internal_hash) { in __journal_read_write()
2051 unsigned digest_size = crypto_shash_digestsize(ic->internal_hash); in __journal_read_write()
2052 if (unlikely(digest_size > ic->tag_size)) { in __journal_read_write()
2054 integrity_sector_checksum(ic, logical_sector, (char *)js, checksums_onstack); in __journal_read_write()
2055 memcpy(journal_entry_tag(ic, je), checksums_onstack, ic->tag_size); in __journal_read_write()
2057 integrity_sector_checksum(ic, logical_sector, (char *)js, journal_entry_tag(ic, je)); in __journal_read_write()
2062 logical_sector += ic->sectors_per_block; in __journal_read_write()
2065 if (unlikely(journal_entry == ic->journal_section_entries)) { in __journal_read_write()
2068 wraparound_section(ic, &journal_section); in __journal_read_write()
2071 bv.bv_offset += ic->sectors_per_block << SECTOR_SHIFT; in __journal_read_write()
2072 } while (bv.bv_len -= ic->sectors_per_block << SECTOR_SHIFT); in __journal_read_write()
2081 if (unlikely(waitqueue_active(&ic->copy_to_journal_wait))) in __journal_read_write()
2082 wake_up(&ic->copy_to_journal_wait); in __journal_read_write()
2083 if (READ_ONCE(ic->free_sectors) <= ic->free_sectors_threshold) { in __journal_read_write()
2084 queue_work(ic->commit_wq, &ic->commit_work); in __journal_read_write()
2086 schedule_autocommit(ic); in __journal_read_write()
2089 remove_range(ic, &dio->range); in __journal_read_write()
2096 get_area_and_offset(ic, dio->range.logical_sector, &area, &offset); in __journal_read_write()
2097 dio->metadata_block = get_metadata_sector_and_offset(ic, area, offset, &dio->metadata_offset); in __journal_read_write()
2106 struct dm_integrity_c *ic = dio->ic; in dm_integrity_map_continue() local
2112 bool need_sync_io = ic->internal_hash && dio->op == REQ_OP_READ; in dm_integrity_map_continue()
2113 if (unlikely(dio->op == REQ_OP_DISCARD) && ic->mode != 'D') in dm_integrity_map_continue()
2118 queue_work(ic->offload_wq, &dio->work); in dm_integrity_map_continue()
2123 spin_lock_irq(&ic->endio_wait.lock); in dm_integrity_map_continue()
2125 if (unlikely(dm_integrity_failed(ic))) { in dm_integrity_map_continue()
2126 spin_unlock_irq(&ic->endio_wait.lock); in dm_integrity_map_continue()
2127 do_endio(ic, bio); in dm_integrity_map_continue()
2132 if (ic->mode == 'J' && likely(dio->op != REQ_OP_DISCARD)) { in dm_integrity_map_continue()
2138 (sector_t)ic->free_sectors << ic->sb->log2_sectors_per_block); in dm_integrity_map_continue()
2142 sleep_on_endio_wait(ic); in dm_integrity_map_continue()
2145 range_sectors = dio->range.n_sectors >> ic->sb->log2_sectors_per_block; in dm_integrity_map_continue()
2146 ic->free_sectors -= range_sectors; in dm_integrity_map_continue()
2147 journal_section = ic->free_section; in dm_integrity_map_continue()
2148 journal_entry = ic->free_section_entry; in dm_integrity_map_continue()
2150 next_entry = ic->free_section_entry + range_sectors; in dm_integrity_map_continue()
2151 ic->free_section_entry = next_entry % ic->journal_section_entries; in dm_integrity_map_continue()
2152 ic->free_section += next_entry / ic->journal_section_entries; in dm_integrity_map_continue()
2153 ic->n_uncommitted_sections += next_entry / ic->journal_section_entries; in dm_integrity_map_continue()
2154 wraparound_section(ic, &ic->free_section); in dm_integrity_map_continue()
2156 pos = journal_section * ic->journal_section_entries + journal_entry; in dm_integrity_map_continue()
2163 add_journal_node(ic, &ic->journal_tree[pos], dio->range.logical_sector + i); in dm_integrity_map_continue()
2165 if (unlikely(pos >= ic->journal_entries)) in dm_integrity_map_continue()
2168 je = access_journal_entry(ic, ws, we); in dm_integrity_map_continue()
2172 if (unlikely(we == ic->journal_section_entries)) { in dm_integrity_map_continue()
2175 wraparound_section(ic, &ws); in dm_integrity_map_continue()
2177 } while ((i += ic->sectors_per_block) < dio->range.n_sectors); in dm_integrity_map_continue()
2179 spin_unlock_irq(&ic->endio_wait.lock); in dm_integrity_map_continue()
2183 journal_read_pos = find_journal_node(ic, dio->range.logical_sector, &next_sector); in dm_integrity_map_continue()
2190 for (i = ic->sectors_per_block; i < dio->range.n_sectors; i += ic->sectors_per_block, jp++) { in dm_integrity_map_continue()
2191 if (!test_journal_node(ic, jp, dio->range.logical_sector + i)) in dm_integrity_map_continue()
2198 if (unlikely(!add_new_range(ic, &dio->range, true))) { in dm_integrity_map_continue()
2206 spin_unlock_irq(&ic->endio_wait.lock); in dm_integrity_map_continue()
2208 queue_work(ic->wait_wq, &dio->work); in dm_integrity_map_continue()
2212 dio->range.n_sectors = ic->sectors_per_block; in dm_integrity_map_continue()
2213 wait_and_add_new_range(ic, &dio->range); in dm_integrity_map_continue()
2221 unsigned new_pos = find_journal_node(ic, dio->range.logical_sector, &next_sector); in dm_integrity_map_continue()
2223 remove_range_unlocked(ic, &dio->range); in dm_integrity_map_continue()
2228 if (ic->mode == 'J' && likely(dio->op == REQ_OP_DISCARD) && !discard_retried) { in dm_integrity_map_continue()
2230 unsigned new_pos = find_journal_node(ic, dio->range.logical_sector, &next_sector); in dm_integrity_map_continue()
2233 remove_range_unlocked(ic, &dio->range); in dm_integrity_map_continue()
2234 spin_unlock_irq(&ic->endio_wait.lock); in dm_integrity_map_continue()
2235 queue_work(ic->commit_wq, &ic->commit_work); in dm_integrity_map_continue()
2236 flush_workqueue(ic->commit_wq); in dm_integrity_map_continue()
2237 queue_work(ic->writer_wq, &ic->writer_work); in dm_integrity_map_continue()
2238 flush_workqueue(ic->writer_wq); in dm_integrity_map_continue()
2243 spin_unlock_irq(&ic->endio_wait.lock); in dm_integrity_map_continue()
2246 journal_section = journal_read_pos / ic->journal_section_entries; in dm_integrity_map_continue()
2247 journal_entry = journal_read_pos % ic->journal_section_entries; in dm_integrity_map_continue()
2251 if (ic->mode == 'B' && (dio->op == REQ_OP_WRITE || unlikely(dio->op == REQ_OP_DISCARD))) { in dm_integrity_map_continue()
2252 if (!block_bitmap_op(ic, ic->may_write_bitmap, dio->range.logical_sector, in dm_integrity_map_continue()
2256 bbs = sector_to_bitmap_block(ic, dio->range.logical_sector); in dm_integrity_map_continue()
2260 queue_work(ic->writer_wq, &bbs->work); in dm_integrity_map_continue()
2274 bio_set_dev(bio, ic->dev->bdev); in dm_integrity_map_continue()
2280 if (unlikely(dio->op == REQ_OP_DISCARD) && likely(ic->mode != 'D')) { in dm_integrity_map_continue()
2282 dm_integrity_flush_buffers(ic, false); in dm_integrity_map_continue()
2296 if (ic->sb->flags & cpu_to_le32(SB_FLAG_RECALCULATING) && in dm_integrity_map_continue()
2297 dio->range.logical_sector + dio->range.n_sectors > le64_to_cpu(ic->sb->recalc_sector)) in dm_integrity_map_continue()
2299 if (ic->mode == 'B') { in dm_integrity_map_continue()
2300 if (!block_bitmap_op(ic, ic->recalc_bitmap, dio->range.logical_sector, in dm_integrity_map_continue()
2313 queue_work(ic->metadata_wq, &dio->work); in dm_integrity_map_continue()
2322 do_endio_flush(ic, dio); in dm_integrity_map_continue()
2333 static void pad_uncommitted(struct dm_integrity_c *ic) in pad_uncommitted() argument
2335 if (ic->free_section_entry) { in pad_uncommitted()
2336 ic->free_sectors -= ic->journal_section_entries - ic->free_section_entry; in pad_uncommitted()
2337 ic->free_section_entry = 0; in pad_uncommitted()
2338 ic->free_section++; in pad_uncommitted()
2339 wraparound_section(ic, &ic->free_section); in pad_uncommitted()
2340 ic->n_uncommitted_sections++; in pad_uncommitted()
2342 if (WARN_ON(ic->journal_sections * ic->journal_section_entries != in pad_uncommitted()
2343 (ic->n_uncommitted_sections + ic->n_committed_sections) * in pad_uncommitted()
2344 ic->journal_section_entries + ic->free_sectors)) { in pad_uncommitted()
2348 ic->journal_sections, ic->journal_section_entries, in pad_uncommitted()
2349 ic->n_uncommitted_sections, ic->n_committed_sections, in pad_uncommitted()
2350 ic->journal_section_entries, ic->free_sectors); in pad_uncommitted()
2356 struct dm_integrity_c *ic = container_of(w, struct dm_integrity_c, commit_work); in integrity_commit() local
2361 del_timer(&ic->autocommit_timer); in integrity_commit()
2363 spin_lock_irq(&ic->endio_wait.lock); in integrity_commit()
2364 flushes = bio_list_get(&ic->flush_bio_list); in integrity_commit()
2365 if (unlikely(ic->mode != 'J')) { in integrity_commit()
2366 spin_unlock_irq(&ic->endio_wait.lock); in integrity_commit()
2367 dm_integrity_flush_buffers(ic, true); in integrity_commit()
2371 pad_uncommitted(ic); in integrity_commit()
2372 commit_start = ic->uncommitted_section; in integrity_commit()
2373 commit_sections = ic->n_uncommitted_sections; in integrity_commit()
2374 spin_unlock_irq(&ic->endio_wait.lock); in integrity_commit()
2379 ic->wrote_to_journal = true; in integrity_commit()
2383 for (j = 0; j < ic->journal_section_entries; j++) { in integrity_commit()
2385 je = access_journal_entry(ic, i, j); in integrity_commit()
2386 io_wait_event(ic->copy_to_journal_wait, !journal_entry_is_inprogress(je)); in integrity_commit()
2388 for (j = 0; j < ic->journal_section_sectors; j++) { in integrity_commit()
2390 js = access_journal(ic, i, j); in integrity_commit()
2391 js->commit_id = dm_integrity_commit_id(ic, i, j, ic->commit_seq); in integrity_commit()
2394 if (unlikely(i >= ic->journal_sections)) in integrity_commit()
2395 ic->commit_seq = next_commit_seq(ic->commit_seq); in integrity_commit()
2396 wraparound_section(ic, &i); in integrity_commit()
2400 write_journal(ic, commit_start, commit_sections); in integrity_commit()
2402 spin_lock_irq(&ic->endio_wait.lock); in integrity_commit()
2403 ic->uncommitted_section += commit_sections; in integrity_commit()
2404 wraparound_section(ic, &ic->uncommitted_section); in integrity_commit()
2405 ic->n_uncommitted_sections -= commit_sections; in integrity_commit()
2406 ic->n_committed_sections += commit_sections; in integrity_commit()
2407 spin_unlock_irq(&ic->endio_wait.lock); in integrity_commit()
2409 if (READ_ONCE(ic->free_sectors) <= ic->free_sectors_threshold) in integrity_commit()
2410 queue_work(ic->writer_wq, &ic->writer_work); in integrity_commit()
2416 do_endio(ic, flushes); in integrity_commit()
2425 struct dm_integrity_c *ic = comp->ic; in complete_copy_from_journal() local
2426 remove_range(ic, &io->range); in complete_copy_from_journal()
2427 mempool_free(io, &ic->journal_io_mempool); in complete_copy_from_journal()
2429 dm_integrity_io_error(ic, "copying from journal", -EIO); in complete_copy_from_journal()
2433 static void restore_last_bytes(struct dm_integrity_c *ic, struct journal_sector *js, in restore_last_bytes() argument
2440 } while (++s < ic->sectors_per_block); in restore_last_bytes()
2443 static void do_journal_write(struct dm_integrity_c *ic, unsigned write_start, in do_journal_write() argument
2452 comp.ic = ic; in do_journal_write()
2457 for (n = 0; n < write_sections; n++, i++, wraparound_section(ic, &i)) { in do_journal_write()
2461 rw_section_mac(ic, i, false); in do_journal_write()
2462 for (j = 0; j < ic->journal_section_entries; j++) { in do_journal_write()
2463 struct journal_entry *je = access_journal_entry(ic, i, j); in do_journal_write()
2475 if (unlikely(sec & (unsigned)(ic->sectors_per_block - 1))) { in do_journal_write()
2476 dm_integrity_io_error(ic, "invalid sector in journal", -EIO); in do_journal_write()
2477 sec &= ~(sector_t)(ic->sectors_per_block - 1); in do_journal_write()
2479 if (unlikely(sec >= ic->provided_data_sectors)) { in do_journal_write()
2484 get_area_and_offset(ic, sec, &area, &offset); in do_journal_write()
2485 restore_last_bytes(ic, access_journal_data(ic, i, j), je); in do_journal_write()
2486 for (k = j + 1; k < ic->journal_section_entries; k++) { in do_journal_write()
2487 struct journal_entry *je2 = access_journal_entry(ic, i, k); in do_journal_write()
2493 if (unlikely(sec2 >= ic->provided_data_sectors)) in do_journal_write()
2495 get_area_and_offset(ic, sec2, &area2, &offset2); in do_journal_write()
2496 if (area2 != area || offset2 != offset + ((k - j) << ic->sb->log2_sectors_per_block)) in do_journal_write()
2498 restore_last_bytes(ic, access_journal_data(ic, i, k), je2); in do_journal_write()
2502 io = mempool_alloc(&ic->journal_io_mempool, GFP_NOIO); in do_journal_write()
2505 io->range.n_sectors = (k - j) << ic->sb->log2_sectors_per_block; in do_journal_write()
2507 spin_lock_irq(&ic->endio_wait.lock); in do_journal_write()
2508 add_new_range_and_wait(ic, &io->range); in do_journal_write()
2511 struct journal_node *section_node = &ic->journal_tree[i * ic->journal_section_entries]; in do_journal_write()
2514 while (j < k && find_newer_committed_node(ic, §ion_node[j])) { in do_journal_write()
2515 struct journal_entry *je2 = access_journal_entry(ic, i, j); in do_journal_write()
2518 remove_journal_node(ic, §ion_node[j]); in do_journal_write()
2520 sec += ic->sectors_per_block; in do_journal_write()
2521 offset += ic->sectors_per_block; in do_journal_write()
2523 while (j < k && find_newer_committed_node(ic, §ion_node[k - 1])) { in do_journal_write()
2524 struct journal_entry *je2 = access_journal_entry(ic, i, k - 1); in do_journal_write()
2527 remove_journal_node(ic, §ion_node[k - 1]); in do_journal_write()
2531 remove_range_unlocked(ic, &io->range); in do_journal_write()
2532 spin_unlock_irq(&ic->endio_wait.lock); in do_journal_write()
2533 mempool_free(io, &ic->journal_io_mempool); in do_journal_write()
2537 remove_journal_node(ic, §ion_node[l]); in do_journal_write()
2540 spin_unlock_irq(&ic->endio_wait.lock); in do_journal_write()
2542 metadata_block = get_metadata_sector_and_offset(ic, area, offset, &metadata_offset); in do_journal_write()
2545 struct journal_entry *je2 = access_journal_entry(ic, i, l); in do_journal_write()
2551 ic->internal_hash) { in do_journal_write()
2554 integrity_sector_checksum(ic, sec + ((l - j) << ic->sb->log2_sectors_per_block), in do_journal_write()
2555 (char *)access_journal_data(ic, i, l), test_tag); in do_journal_write()
2556 if (unlikely(memcmp(test_tag, journal_entry_tag(ic, je2), ic->tag_size))) { in do_journal_write()
2557 dm_integrity_io_error(ic, "tag mismatch when replaying journal", -EILSEQ); in do_journal_write()
2558 dm_audit_log_target(DM_MSG_PREFIX, "integrity-replay-journal", ic->ti, 0); in do_journal_write()
2563 r = dm_integrity_rw_tag(ic, journal_entry_tag(ic, je2), &metadata_block, &metadata_offset, in do_journal_write()
2564 ic->tag_size, TAG_WRITE); in do_journal_write()
2566 dm_integrity_io_error(ic, "reading tags", r); in do_journal_write()
2571 copy_from_journal(ic, i, j << ic->sb->log2_sectors_per_block, in do_journal_write()
2572 (k - j) << ic->sb->log2_sectors_per_block, in do_journal_write()
2573 get_data_sector(ic, area, offset), in do_journal_write()
2580 dm_bufio_write_dirty_buffers_async(ic->bufio); in do_journal_write()
2587 dm_integrity_flush_buffers(ic, true); in do_journal_write()
2592 struct dm_integrity_c *ic = container_of(w, struct dm_integrity_c, writer_work); in integrity_writer() local
2597 spin_lock_irq(&ic->endio_wait.lock); in integrity_writer()
2598 write_start = ic->committed_section; in integrity_writer()
2599 write_sections = ic->n_committed_sections; in integrity_writer()
2600 spin_unlock_irq(&ic->endio_wait.lock); in integrity_writer()
2605 do_journal_write(ic, write_start, write_sections, false); in integrity_writer()
2607 spin_lock_irq(&ic->endio_wait.lock); in integrity_writer()
2609 ic->committed_section += write_sections; in integrity_writer()
2610 wraparound_section(ic, &ic->committed_section); in integrity_writer()
2611 ic->n_committed_sections -= write_sections; in integrity_writer()
2613 prev_free_sectors = ic->free_sectors; in integrity_writer()
2614 ic->free_sectors += write_sections * ic->journal_section_entries; in integrity_writer()
2616 wake_up_locked(&ic->endio_wait); in integrity_writer()
2618 spin_unlock_irq(&ic->endio_wait.lock); in integrity_writer()
2621 static void recalc_write_super(struct dm_integrity_c *ic) in recalc_write_super() argument
2625 dm_integrity_flush_buffers(ic, false); in recalc_write_super()
2626 if (dm_integrity_failed(ic)) in recalc_write_super()
2629 r = sync_rw_sb(ic, REQ_OP_WRITE); in recalc_write_super()
2631 dm_integrity_io_error(ic, "writing superblock", r); in recalc_write_super()
2636 struct dm_integrity_c *ic = container_of(w, struct dm_integrity_c, recalc_work); in integrity_recalc() local
2649 DEBUG_print("start recalculation... (position %llx)\n", le64_to_cpu(ic->sb->recalc_sector)); in integrity_recalc()
2651 spin_lock_irq(&ic->endio_wait.lock); in integrity_recalc()
2655 if (unlikely(dm_post_suspending(ic->ti))) in integrity_recalc()
2658 range.logical_sector = le64_to_cpu(ic->sb->recalc_sector); in integrity_recalc()
2659 if (unlikely(range.logical_sector >= ic->provided_data_sectors)) { in integrity_recalc()
2660 if (ic->mode == 'B') { in integrity_recalc()
2661 block_bitmap_op(ic, ic->recalc_bitmap, 0, ic->provided_data_sectors, BITMAP_OP_CLEAR); in integrity_recalc()
2663 queue_delayed_work(ic->commit_wq, &ic->bitmap_flush_work, 0); in integrity_recalc()
2668 get_area_and_offset(ic, range.logical_sector, &area, &offset); in integrity_recalc()
2669 range.n_sectors = min((sector_t)RECALC_SECTORS, ic->provided_data_sectors - range.logical_sector); in integrity_recalc()
2670 if (!ic->meta_dev) in integrity_recalc()
2671 …range.n_sectors = min(range.n_sectors, ((sector_t)1U << ic->sb->log2_interleave_sectors) - (unsign… in integrity_recalc()
2673 add_new_range_and_wait(ic, &range); in integrity_recalc()
2674 spin_unlock_irq(&ic->endio_wait.lock); in integrity_recalc()
2678 if (ic->mode == 'B') { in integrity_recalc()
2679 if (block_bitmap_op(ic, ic->recalc_bitmap, logical_sector, n_sectors, BITMAP_OP_TEST_ALL_CLEAR)) { in integrity_recalc()
2682 while (block_bitmap_op(ic, ic->recalc_bitmap, logical_sector, in integrity_recalc()
2683 ic->sectors_per_block, BITMAP_OP_TEST_ALL_CLEAR)) { in integrity_recalc()
2684 logical_sector += ic->sectors_per_block; in integrity_recalc()
2685 n_sectors -= ic->sectors_per_block; in integrity_recalc()
2688 while (block_bitmap_op(ic, ic->recalc_bitmap, logical_sector + n_sectors - ic->sectors_per_block, in integrity_recalc()
2689 ic->sectors_per_block, BITMAP_OP_TEST_ALL_CLEAR)) { in integrity_recalc()
2690 n_sectors -= ic->sectors_per_block; in integrity_recalc()
2693 get_area_and_offset(ic, logical_sector, &area, &offset); in integrity_recalc()
2699 recalc_write_super(ic); in integrity_recalc()
2700 if (ic->mode == 'B') { in integrity_recalc()
2701 queue_delayed_work(ic->commit_wq, &ic->bitmap_flush_work, ic->bitmap_flush_interval); in integrity_recalc()
2706 if (unlikely(dm_integrity_failed(ic))) in integrity_recalc()
2711 io_req.mem.ptr.addr = ic->recalc_buffer; in integrity_recalc()
2713 io_req.client = ic->io; in integrity_recalc()
2714 io_loc.bdev = ic->dev->bdev; in integrity_recalc()
2715 io_loc.sector = get_data_sector(ic, area, offset); in integrity_recalc()
2720 dm_integrity_io_error(ic, "reading data", r); in integrity_recalc()
2724 t = ic->recalc_tags; in integrity_recalc()
2725 for (i = 0; i < n_sectors; i += ic->sectors_per_block) { in integrity_recalc()
2726 integrity_sector_checksum(ic, logical_sector + i, ic->recalc_buffer + (i << SECTOR_SHIFT), t); in integrity_recalc()
2727 t += ic->tag_size; in integrity_recalc()
2730 metadata_block = get_metadata_sector_and_offset(ic, area, offset, &metadata_offset); in integrity_recalc()
2732 …r = dm_integrity_rw_tag(ic, ic->recalc_tags, &metadata_block, &metadata_offset, t - ic->recalc_tag… in integrity_recalc()
2734 dm_integrity_io_error(ic, "writing tags", r); in integrity_recalc()
2738 if (ic->mode == 'B') { in integrity_recalc()
2741 (ic->sb->log2_sectors_per_block + ic->log2_blocks_per_bitmap_bit)) << in integrity_recalc()
2742 (ic->sb->log2_sectors_per_block + ic->log2_blocks_per_bitmap_bit); in integrity_recalc()
2744 (ic->sb->log2_sectors_per_block + ic->log2_blocks_per_bitmap_bit)) << in integrity_recalc()
2745 (ic->sb->log2_sectors_per_block + ic->log2_blocks_per_bitmap_bit); in integrity_recalc()
2746 block_bitmap_op(ic, ic->recalc_bitmap, start, end - start, BITMAP_OP_CLEAR); in integrity_recalc()
2752 spin_lock_irq(&ic->endio_wait.lock); in integrity_recalc()
2753 remove_range_unlocked(ic, &range); in integrity_recalc()
2754 ic->sb->recalc_sector = cpu_to_le64(range.logical_sector + range.n_sectors); in integrity_recalc()
2758 remove_range(ic, &range); in integrity_recalc()
2762 spin_unlock_irq(&ic->endio_wait.lock); in integrity_recalc()
2764 recalc_write_super(ic); in integrity_recalc()
2770 struct dm_integrity_c *ic = bbs->ic; in bitmap_block_work() local
2787 if (block_bitmap_op(ic, ic->may_write_bitmap, dio->range.logical_sector, in bitmap_block_work()
2789 remove_range(ic, &dio->range); in bitmap_block_work()
2791 queue_work(ic->offload_wq, &dio->work); in bitmap_block_work()
2793 block_bitmap_op(ic, ic->journal, dio->range.logical_sector, in bitmap_block_work()
2802 rw_journal_sectors(ic, REQ_OP_WRITE | REQ_FUA | REQ_SYNC, in bitmap_block_work()
2809 block_bitmap_op(ic, ic->may_write_bitmap, dio->range.logical_sector, in bitmap_block_work()
2812 remove_range(ic, &dio->range); in bitmap_block_work()
2814 queue_work(ic->offload_wq, &dio->work); in bitmap_block_work()
2817 queue_delayed_work(ic->commit_wq, &ic->bitmap_flush_work, ic->bitmap_flush_interval); in bitmap_block_work()
2822 struct dm_integrity_c *ic = container_of(work, struct dm_integrity_c, bitmap_flush_work.work); in bitmap_flush_work() local
2827 dm_integrity_flush_buffers(ic, false); in bitmap_flush_work()
2830 range.n_sectors = ic->provided_data_sectors; in bitmap_flush_work()
2832 spin_lock_irq(&ic->endio_wait.lock); in bitmap_flush_work()
2833 add_new_range_and_wait(ic, &range); in bitmap_flush_work()
2834 spin_unlock_irq(&ic->endio_wait.lock); in bitmap_flush_work()
2836 dm_integrity_flush_buffers(ic, true); in bitmap_flush_work()
2838 limit = ic->provided_data_sectors; in bitmap_flush_work()
2839 if (ic->sb->flags & cpu_to_le32(SB_FLAG_RECALCULATING)) { in bitmap_flush_work()
2840 limit = le64_to_cpu(ic->sb->recalc_sector) in bitmap_flush_work()
2841 >> (ic->sb->log2_sectors_per_block + ic->log2_blocks_per_bitmap_bit) in bitmap_flush_work()
2842 << (ic->sb->log2_sectors_per_block + ic->log2_blocks_per_bitmap_bit); in bitmap_flush_work()
2845 block_bitmap_op(ic, ic->journal, 0, limit, BITMAP_OP_CLEAR); in bitmap_flush_work()
2846 block_bitmap_op(ic, ic->may_write_bitmap, 0, limit, BITMAP_OP_CLEAR); in bitmap_flush_work()
2848 rw_journal_sectors(ic, REQ_OP_WRITE | REQ_FUA | REQ_SYNC, 0, in bitmap_flush_work()
2849 ic->n_bitmap_blocks * (BITMAP_BLOCK_SIZE >> SECTOR_SHIFT), NULL); in bitmap_flush_work()
2851 spin_lock_irq(&ic->endio_wait.lock); in bitmap_flush_work()
2852 remove_range_unlocked(ic, &range); in bitmap_flush_work()
2853 while (unlikely((bio = bio_list_pop(&ic->synchronous_bios)) != NULL)) { in bitmap_flush_work()
2855 spin_unlock_irq(&ic->endio_wait.lock); in bitmap_flush_work()
2856 spin_lock_irq(&ic->endio_wait.lock); in bitmap_flush_work()
2858 spin_unlock_irq(&ic->endio_wait.lock); in bitmap_flush_work()
2862 static void init_journal(struct dm_integrity_c *ic, unsigned start_section, in init_journal() argument
2872 wraparound_section(ic, &i); in init_journal()
2873 for (j = 0; j < ic->journal_section_sectors; j++) { in init_journal()
2874 struct journal_sector *js = access_journal(ic, i, j); in init_journal()
2877 js->commit_id = dm_integrity_commit_id(ic, i, j, commit_seq); in init_journal()
2879 for (j = 0; j < ic->journal_section_entries; j++) { in init_journal()
2880 struct journal_entry *je = access_journal_entry(ic, i, j); in init_journal()
2885 write_journal(ic, start_section, n_sections); in init_journal()
2888 static int find_commit_seq(struct dm_integrity_c *ic, unsigned i, unsigned j, commit_id_t id) in find_commit_seq() argument
2892 if (dm_integrity_commit_id(ic, i, j, k) == id) in find_commit_seq()
2895 dm_integrity_io_error(ic, "journal commit id", -EIO); in find_commit_seq()
2899 static void replay_journal(struct dm_integrity_c *ic) in replay_journal() argument
2909 if (ic->mode == 'R') in replay_journal()
2912 if (ic->journal_uptodate) in replay_journal()
2918 if (!ic->just_formatted) { in replay_journal()
2920 rw_journal(ic, REQ_OP_READ, 0, ic->journal_sections, NULL); in replay_journal()
2921 if (ic->journal_io) in replay_journal()
2922 DEBUG_bytes(lowmem_page_address(ic->journal_io[0].page), 64, "read journal"); in replay_journal()
2923 if (ic->journal_io) { in replay_journal()
2925 crypt_comp.ic = ic; in replay_journal()
2928 encrypt_journal(ic, false, 0, ic->journal_sections, &crypt_comp); in replay_journal()
2931 DEBUG_bytes(lowmem_page_address(ic->journal[0].page), 64, "decrypted journal"); in replay_journal()
2934 if (dm_integrity_failed(ic)) in replay_journal()
2940 for (i = 0; i < ic->journal_sections; i++) { in replay_journal()
2941 for (j = 0; j < ic->journal_section_sectors; j++) { in replay_journal()
2943 struct journal_sector *js = access_journal(ic, i, j); in replay_journal()
2944 k = find_commit_seq(ic, i, j, js->commit_id); in replay_journal()
2951 for (j = 0; j < ic->journal_section_entries; j++) { in replay_journal()
2952 struct journal_entry *je = access_journal_entry(ic, i, j); in replay_journal()
2970 dm_integrity_io_error(ic, "journal commit ids", -EIO); in replay_journal()
2985 if (unlikely(write_start >= ic->journal_sections)) in replay_journal()
2987 wraparound_section(ic, &write_start); in replay_journal()
2990 for (write_sections = 0; write_sections < ic->journal_sections; write_sections++) { in replay_journal()
2991 for (j = 0; j < ic->journal_section_sectors; j++) { in replay_journal()
2992 struct journal_sector *js = access_journal(ic, i, j); in replay_journal()
2994 if (js->commit_id != dm_integrity_commit_id(ic, i, j, want_commit_seq)) { in replay_journal()
3001 i, j, find_commit_seq(ic, i, j, js->commit_id), want_commit_seq); in replay_journal()
3006 if (unlikely(i >= ic->journal_sections)) in replay_journal()
3008 wraparound_section(ic, &i); in replay_journal()
3015 do_journal_write(ic, write_start, write_sections, true); in replay_journal()
3018 if (write_sections == ic->journal_sections && (ic->mode == 'J' || journal_empty)) { in replay_journal()
3020 ic->commit_seq = want_commit_seq; in replay_journal()
3021 DEBUG_print("continuing from section %u, commit seq %d\n", write_start, ic->commit_seq); in replay_journal()
3030 init_journal(ic, s, 1, erase_seq); in replay_journal()
3032 wraparound_section(ic, &s); in replay_journal()
3033 if (ic->journal_sections >= 2) { in replay_journal()
3034 init_journal(ic, s, ic->journal_sections - 2, erase_seq); in replay_journal()
3035 s += ic->journal_sections - 2; in replay_journal()
3036 wraparound_section(ic, &s); in replay_journal()
3037 init_journal(ic, s, 1, erase_seq); in replay_journal()
3041 ic->commit_seq = next_commit_seq(erase_seq); in replay_journal()
3044 ic->committed_section = continue_section; in replay_journal()
3045 ic->n_committed_sections = 0; in replay_journal()
3047 ic->uncommitted_section = continue_section; in replay_journal()
3048 ic->n_uncommitted_sections = 0; in replay_journal()
3050 ic->free_section = continue_section; in replay_journal()
3051 ic->free_section_entry = 0; in replay_journal()
3052 ic->free_sectors = ic->journal_entries; in replay_journal()
3054 ic->journal_tree_root = RB_ROOT; in replay_journal()
3055 for (i = 0; i < ic->journal_entries; i++) in replay_journal()
3056 init_journal_node(&ic->journal_tree[i]); in replay_journal()
3059 static void dm_integrity_enter_synchronous_mode(struct dm_integrity_c *ic) in dm_integrity_enter_synchronous_mode() argument
3063 if (ic->mode == 'B') { in dm_integrity_enter_synchronous_mode()
3064 ic->bitmap_flush_interval = msecs_to_jiffies(10) + 1; in dm_integrity_enter_synchronous_mode()
3065 ic->synchronous_mode = 1; in dm_integrity_enter_synchronous_mode()
3067 cancel_delayed_work_sync(&ic->bitmap_flush_work); in dm_integrity_enter_synchronous_mode()
3068 queue_delayed_work(ic->commit_wq, &ic->bitmap_flush_work, 0); in dm_integrity_enter_synchronous_mode()
3069 flush_workqueue(ic->commit_wq); in dm_integrity_enter_synchronous_mode()
3075 struct dm_integrity_c *ic = container_of(n, struct dm_integrity_c, reboot_notifier); in dm_integrity_reboot() local
3079 dm_integrity_enter_synchronous_mode(ic); in dm_integrity_reboot()
3086 struct dm_integrity_c *ic = (struct dm_integrity_c *)ti->private; in dm_integrity_postsuspend() local
3089 WARN_ON(unregister_reboot_notifier(&ic->reboot_notifier)); in dm_integrity_postsuspend()
3091 del_timer_sync(&ic->autocommit_timer); in dm_integrity_postsuspend()
3093 if (ic->recalc_wq) in dm_integrity_postsuspend()
3094 drain_workqueue(ic->recalc_wq); in dm_integrity_postsuspend()
3096 if (ic->mode == 'B') in dm_integrity_postsuspend()
3097 cancel_delayed_work_sync(&ic->bitmap_flush_work); in dm_integrity_postsuspend()
3099 queue_work(ic->commit_wq, &ic->commit_work); in dm_integrity_postsuspend()
3100 drain_workqueue(ic->commit_wq); in dm_integrity_postsuspend()
3102 if (ic->mode == 'J') { in dm_integrity_postsuspend()
3103 queue_work(ic->writer_wq, &ic->writer_work); in dm_integrity_postsuspend()
3104 drain_workqueue(ic->writer_wq); in dm_integrity_postsuspend()
3105 dm_integrity_flush_buffers(ic, true); in dm_integrity_postsuspend()
3106 if (ic->wrote_to_journal) { in dm_integrity_postsuspend()
3107 init_journal(ic, ic->free_section, in dm_integrity_postsuspend()
3108 ic->journal_sections - ic->free_section, ic->commit_seq); in dm_integrity_postsuspend()
3109 if (ic->free_section) { in dm_integrity_postsuspend()
3110 init_journal(ic, 0, ic->free_section, in dm_integrity_postsuspend()
3111 next_commit_seq(ic->commit_seq)); in dm_integrity_postsuspend()
3116 if (ic->mode == 'B') { in dm_integrity_postsuspend()
3117 dm_integrity_flush_buffers(ic, true); in dm_integrity_postsuspend()
3120 init_journal(ic, 0, ic->journal_sections, 0); in dm_integrity_postsuspend()
3121 ic->sb->flags &= ~cpu_to_le32(SB_FLAG_DIRTY_BITMAP); in dm_integrity_postsuspend()
3122 r = sync_rw_sb(ic, REQ_OP_WRITE | REQ_FUA); in dm_integrity_postsuspend()
3124 dm_integrity_io_error(ic, "writing superblock", r); in dm_integrity_postsuspend()
3128 BUG_ON(!RB_EMPTY_ROOT(&ic->in_progress)); in dm_integrity_postsuspend()
3130 ic->journal_uptodate = true; in dm_integrity_postsuspend()
3135 struct dm_integrity_c *ic = (struct dm_integrity_c *)ti->private; in dm_integrity_resume() local
3136 __u64 old_provided_data_sectors = le64_to_cpu(ic->sb->provided_data_sectors); in dm_integrity_resume()
3141 ic->wrote_to_journal = false; in dm_integrity_resume()
3143 if (ic->provided_data_sectors != old_provided_data_sectors) { in dm_integrity_resume()
3144 if (ic->provided_data_sectors > old_provided_data_sectors && in dm_integrity_resume()
3145 ic->mode == 'B' && in dm_integrity_resume()
3146 ic->sb->log2_blocks_per_bitmap_bit == ic->log2_blocks_per_bitmap_bit) { in dm_integrity_resume()
3147 rw_journal_sectors(ic, REQ_OP_READ, 0, in dm_integrity_resume()
3148 ic->n_bitmap_blocks * (BITMAP_BLOCK_SIZE >> SECTOR_SHIFT), NULL); in dm_integrity_resume()
3149 block_bitmap_op(ic, ic->journal, old_provided_data_sectors, in dm_integrity_resume()
3150 ic->provided_data_sectors - old_provided_data_sectors, BITMAP_OP_SET); in dm_integrity_resume()
3151 rw_journal_sectors(ic, REQ_OP_WRITE | REQ_FUA | REQ_SYNC, 0, in dm_integrity_resume()
3152 ic->n_bitmap_blocks * (BITMAP_BLOCK_SIZE >> SECTOR_SHIFT), NULL); in dm_integrity_resume()
3155 ic->sb->provided_data_sectors = cpu_to_le64(ic->provided_data_sectors); in dm_integrity_resume()
3156 r = sync_rw_sb(ic, REQ_OP_WRITE | REQ_FUA); in dm_integrity_resume()
3158 dm_integrity_io_error(ic, "writing superblock", r); in dm_integrity_resume()
3161 if (ic->sb->flags & cpu_to_le32(SB_FLAG_DIRTY_BITMAP)) { in dm_integrity_resume()
3163 rw_journal_sectors(ic, REQ_OP_READ, 0, in dm_integrity_resume()
3164 ic->n_bitmap_blocks * (BITMAP_BLOCK_SIZE >> SECTOR_SHIFT), NULL); in dm_integrity_resume()
3165 if (ic->mode == 'B') { in dm_integrity_resume()
3166 if (ic->sb->log2_blocks_per_bitmap_bit == ic->log2_blocks_per_bitmap_bit && in dm_integrity_resume()
3167 !ic->reset_recalculate_flag) { in dm_integrity_resume()
3168 block_bitmap_copy(ic, ic->recalc_bitmap, ic->journal); in dm_integrity_resume()
3169 block_bitmap_copy(ic, ic->may_write_bitmap, ic->journal); in dm_integrity_resume()
3170 if (!block_bitmap_op(ic, ic->journal, 0, ic->provided_data_sectors, in dm_integrity_resume()
3172 ic->sb->flags |= cpu_to_le32(SB_FLAG_RECALCULATING); in dm_integrity_resume()
3173 ic->sb->recalc_sector = cpu_to_le64(0); in dm_integrity_resume()
3177 ic->sb->log2_blocks_per_bitmap_bit, ic->log2_blocks_per_bitmap_bit); in dm_integrity_resume()
3178 ic->sb->log2_blocks_per_bitmap_bit = ic->log2_blocks_per_bitmap_bit; in dm_integrity_resume()
3179 block_bitmap_op(ic, ic->recalc_bitmap, 0, ic->provided_data_sectors, BITMAP_OP_SET); in dm_integrity_resume()
3180 block_bitmap_op(ic, ic->may_write_bitmap, 0, ic->provided_data_sectors, BITMAP_OP_SET); in dm_integrity_resume()
3181 block_bitmap_op(ic, ic->journal, 0, ic->provided_data_sectors, BITMAP_OP_SET); in dm_integrity_resume()
3182 rw_journal_sectors(ic, REQ_OP_WRITE | REQ_FUA | REQ_SYNC, 0, in dm_integrity_resume()
3183 ic->n_bitmap_blocks * (BITMAP_BLOCK_SIZE >> SECTOR_SHIFT), NULL); in dm_integrity_resume()
3184 ic->sb->flags |= cpu_to_le32(SB_FLAG_RECALCULATING); in dm_integrity_resume()
3185 ic->sb->recalc_sector = cpu_to_le64(0); in dm_integrity_resume()
3188 if (!(ic->sb->log2_blocks_per_bitmap_bit == ic->log2_blocks_per_bitmap_bit && in dm_integrity_resume()
3189 … block_bitmap_op(ic, ic->journal, 0, ic->provided_data_sectors, BITMAP_OP_TEST_ALL_CLEAR)) || in dm_integrity_resume()
3190 ic->reset_recalculate_flag) { in dm_integrity_resume()
3191 ic->sb->flags |= cpu_to_le32(SB_FLAG_RECALCULATING); in dm_integrity_resume()
3192 ic->sb->recalc_sector = cpu_to_le64(0); in dm_integrity_resume()
3194 init_journal(ic, 0, ic->journal_sections, 0); in dm_integrity_resume()
3195 replay_journal(ic); in dm_integrity_resume()
3196 ic->sb->flags &= ~cpu_to_le32(SB_FLAG_DIRTY_BITMAP); in dm_integrity_resume()
3198 r = sync_rw_sb(ic, REQ_OP_WRITE | REQ_FUA); in dm_integrity_resume()
3200 dm_integrity_io_error(ic, "writing superblock", r); in dm_integrity_resume()
3202 replay_journal(ic); in dm_integrity_resume()
3203 if (ic->reset_recalculate_flag) { in dm_integrity_resume()
3204 ic->sb->flags |= cpu_to_le32(SB_FLAG_RECALCULATING); in dm_integrity_resume()
3205 ic->sb->recalc_sector = cpu_to_le64(0); in dm_integrity_resume()
3207 if (ic->mode == 'B') { in dm_integrity_resume()
3208 ic->sb->flags |= cpu_to_le32(SB_FLAG_DIRTY_BITMAP); in dm_integrity_resume()
3209 ic->sb->log2_blocks_per_bitmap_bit = ic->log2_blocks_per_bitmap_bit; in dm_integrity_resume()
3210 r = sync_rw_sb(ic, REQ_OP_WRITE | REQ_FUA); in dm_integrity_resume()
3212 dm_integrity_io_error(ic, "writing superblock", r); in dm_integrity_resume()
3214 block_bitmap_op(ic, ic->journal, 0, ic->provided_data_sectors, BITMAP_OP_CLEAR); in dm_integrity_resume()
3215 block_bitmap_op(ic, ic->recalc_bitmap, 0, ic->provided_data_sectors, BITMAP_OP_CLEAR); in dm_integrity_resume()
3216 block_bitmap_op(ic, ic->may_write_bitmap, 0, ic->provided_data_sectors, BITMAP_OP_CLEAR); in dm_integrity_resume()
3217 if (ic->sb->flags & cpu_to_le32(SB_FLAG_RECALCULATING) && in dm_integrity_resume()
3218 le64_to_cpu(ic->sb->recalc_sector) < ic->provided_data_sectors) { in dm_integrity_resume()
3219 block_bitmap_op(ic, ic->journal, le64_to_cpu(ic->sb->recalc_sector), in dm_integrity_resume()
3220 ic->provided_data_sectors - le64_to_cpu(ic->sb->recalc_sector), BITMAP_OP_SET); in dm_integrity_resume()
3221 block_bitmap_op(ic, ic->recalc_bitmap, le64_to_cpu(ic->sb->recalc_sector), in dm_integrity_resume()
3222 ic->provided_data_sectors - le64_to_cpu(ic->sb->recalc_sector), BITMAP_OP_SET); in dm_integrity_resume()
3223 block_bitmap_op(ic, ic->may_write_bitmap, le64_to_cpu(ic->sb->recalc_sector), in dm_integrity_resume()
3224 ic->provided_data_sectors - le64_to_cpu(ic->sb->recalc_sector), BITMAP_OP_SET); in dm_integrity_resume()
3226 rw_journal_sectors(ic, REQ_OP_WRITE | REQ_FUA | REQ_SYNC, 0, in dm_integrity_resume()
3227 ic->n_bitmap_blocks * (BITMAP_BLOCK_SIZE >> SECTOR_SHIFT), NULL); in dm_integrity_resume()
3231 DEBUG_print("testing recalc: %x\n", ic->sb->flags); in dm_integrity_resume()
3232 if (ic->sb->flags & cpu_to_le32(SB_FLAG_RECALCULATING)) { in dm_integrity_resume()
3233 __u64 recalc_pos = le64_to_cpu(ic->sb->recalc_sector); in dm_integrity_resume()
3234 DEBUG_print("recalc pos: %llx / %llx\n", recalc_pos, ic->provided_data_sectors); in dm_integrity_resume()
3235 if (recalc_pos < ic->provided_data_sectors) { in dm_integrity_resume()
3236 queue_work(ic->recalc_wq, &ic->recalc_work); in dm_integrity_resume()
3237 } else if (recalc_pos > ic->provided_data_sectors) { in dm_integrity_resume()
3238 ic->sb->recalc_sector = cpu_to_le64(ic->provided_data_sectors); in dm_integrity_resume()
3239 recalc_write_super(ic); in dm_integrity_resume()
3243 ic->reboot_notifier.notifier_call = dm_integrity_reboot; in dm_integrity_resume()
3244 ic->reboot_notifier.next = NULL; in dm_integrity_resume()
3245 ic->reboot_notifier.priority = INT_MAX - 1; /* be notified after md and before hardware drivers */ in dm_integrity_resume()
3246 WARN_ON(register_reboot_notifier(&ic->reboot_notifier)); in dm_integrity_resume()
3250 dm_integrity_enter_synchronous_mode(ic); in dm_integrity_resume()
3257 struct dm_integrity_c *ic = (struct dm_integrity_c *)ti->private; in dm_integrity_status() local
3264 (unsigned long long)atomic64_read(&ic->number_of_mismatches), in dm_integrity_status()
3265 ic->provided_data_sectors); in dm_integrity_status()
3266 if (ic->sb->flags & cpu_to_le32(SB_FLAG_RECALCULATING)) in dm_integrity_status()
3267 DMEMIT(" %llu", le64_to_cpu(ic->sb->recalc_sector)); in dm_integrity_status()
3273 __u64 watermark_percentage = (__u64)(ic->journal_entries - ic->free_sectors_threshold) * 100; in dm_integrity_status()
3274 watermark_percentage += ic->journal_entries / 2; in dm_integrity_status()
3275 do_div(watermark_percentage, ic->journal_entries); in dm_integrity_status()
3277 arg_count += !!ic->meta_dev; in dm_integrity_status()
3278 arg_count += ic->sectors_per_block != 1; in dm_integrity_status()
3279 arg_count += !!(ic->sb->flags & cpu_to_le32(SB_FLAG_RECALCULATING)); in dm_integrity_status()
3280 arg_count += ic->reset_recalculate_flag; in dm_integrity_status()
3281 arg_count += ic->discard; in dm_integrity_status()
3282 arg_count += ic->mode == 'J'; in dm_integrity_status()
3283 arg_count += ic->mode == 'J'; in dm_integrity_status()
3284 arg_count += ic->mode == 'B'; in dm_integrity_status()
3285 arg_count += ic->mode == 'B'; in dm_integrity_status()
3286 arg_count += !!ic->internal_hash_alg.alg_string; in dm_integrity_status()
3287 arg_count += !!ic->journal_crypt_alg.alg_string; in dm_integrity_status()
3288 arg_count += !!ic->journal_mac_alg.alg_string; in dm_integrity_status()
3289 arg_count += (ic->sb->flags & cpu_to_le32(SB_FLAG_FIXED_PADDING)) != 0; in dm_integrity_status()
3290 arg_count += (ic->sb->flags & cpu_to_le32(SB_FLAG_FIXED_HMAC)) != 0; in dm_integrity_status()
3291 arg_count += ic->legacy_recalculate; in dm_integrity_status()
3292 DMEMIT("%s %llu %u %c %u", ic->dev->name, ic->start, in dm_integrity_status()
3293 ic->tag_size, ic->mode, arg_count); in dm_integrity_status()
3294 if (ic->meta_dev) in dm_integrity_status()
3295 DMEMIT(" meta_device:%s", ic->meta_dev->name); in dm_integrity_status()
3296 if (ic->sectors_per_block != 1) in dm_integrity_status()
3297 DMEMIT(" block_size:%u", ic->sectors_per_block << SECTOR_SHIFT); in dm_integrity_status()
3298 if (ic->sb->flags & cpu_to_le32(SB_FLAG_RECALCULATING)) in dm_integrity_status()
3300 if (ic->reset_recalculate_flag) in dm_integrity_status()
3302 if (ic->discard) in dm_integrity_status()
3304 DMEMIT(" journal_sectors:%u", ic->initial_sectors - SB_SECTORS); in dm_integrity_status()
3305 DMEMIT(" interleave_sectors:%u", 1U << ic->sb->log2_interleave_sectors); in dm_integrity_status()
3306 DMEMIT(" buffer_sectors:%u", 1U << ic->log2_buffer_sectors); in dm_integrity_status()
3307 if (ic->mode == 'J') { in dm_integrity_status()
3309 DMEMIT(" commit_time:%u", ic->autocommit_msec); in dm_integrity_status()
3311 if (ic->mode == 'B') { in dm_integrity_status()
3312 …DMEMIT(" sectors_per_bit:%llu", (sector_t)ic->sectors_per_block << ic->log2_blocks_per_bitmap_bit); in dm_integrity_status()
3313 DMEMIT(" bitmap_flush_interval:%u", jiffies_to_msecs(ic->bitmap_flush_interval)); in dm_integrity_status()
3315 if ((ic->sb->flags & cpu_to_le32(SB_FLAG_FIXED_PADDING)) != 0) in dm_integrity_status()
3317 if ((ic->sb->flags & cpu_to_le32(SB_FLAG_FIXED_HMAC)) != 0) in dm_integrity_status()
3319 if (ic->legacy_recalculate) in dm_integrity_status()
3324 if (ic->a.alg_string) { \ in dm_integrity_status()
3325 DMEMIT(" %s:%s", n, ic->a.alg_string); \ in dm_integrity_status()
3326 if (ic->a.key_string) \ in dm_integrity_status()
3327 DMEMIT(":%s", ic->a.key_string);\ in dm_integrity_status()
3338 ic->dev->name, ic->start, ic->tag_size, ic->mode); in dm_integrity_status()
3340 if (ic->meta_dev) in dm_integrity_status()
3341 DMEMIT(",meta_device=%s", ic->meta_dev->name); in dm_integrity_status()
3342 if (ic->sectors_per_block != 1) in dm_integrity_status()
3343 DMEMIT(",block_size=%u", ic->sectors_per_block << SECTOR_SHIFT); in dm_integrity_status()
3345 DMEMIT(",recalculate=%c", (ic->sb->flags & cpu_to_le32(SB_FLAG_RECALCULATING)) ? in dm_integrity_status()
3347 DMEMIT(",allow_discards=%c", ic->discard ? 'y' : 'n'); in dm_integrity_status()
3349 ((ic->sb->flags & cpu_to_le32(SB_FLAG_FIXED_PADDING)) != 0) ? 'y' : 'n'); in dm_integrity_status()
3351 ((ic->sb->flags & cpu_to_le32(SB_FLAG_FIXED_HMAC)) != 0) ? 'y' : 'n'); in dm_integrity_status()
3352 DMEMIT(",legacy_recalculate=%c", ic->legacy_recalculate ? 'y' : 'n'); in dm_integrity_status()
3354 DMEMIT(",journal_sectors=%u", ic->initial_sectors - SB_SECTORS); in dm_integrity_status()
3355 DMEMIT(",interleave_sectors=%u", 1U << ic->sb->log2_interleave_sectors); in dm_integrity_status()
3356 DMEMIT(",buffer_sectors=%u", 1U << ic->log2_buffer_sectors); in dm_integrity_status()
3365 struct dm_integrity_c *ic = ti->private; in dm_integrity_iterate_devices() local
3367 if (!ic->meta_dev) in dm_integrity_iterate_devices()
3368 return fn(ti, ic->dev, ic->start + ic->initial_sectors + ic->metadata_run, ti->len, data); in dm_integrity_iterate_devices()
3370 return fn(ti, ic->dev, 0, ti->len, data); in dm_integrity_iterate_devices()
3375 struct dm_integrity_c *ic = ti->private; in dm_integrity_io_hints() local
3377 if (ic->sectors_per_block > 1) { in dm_integrity_io_hints()
3378 limits->logical_block_size = ic->sectors_per_block << SECTOR_SHIFT; in dm_integrity_io_hints()
3379 limits->physical_block_size = ic->sectors_per_block << SECTOR_SHIFT; in dm_integrity_io_hints()
3380 blk_limits_io_min(limits, ic->sectors_per_block << SECTOR_SHIFT); in dm_integrity_io_hints()
3385 static void calculate_journal_section_size(struct dm_integrity_c *ic) in calculate_journal_section_size() argument
3389 ic->journal_sections = le32_to_cpu(ic->sb->journal_sections); in calculate_journal_section_size()
3390 …ic->journal_entry_size = roundup(offsetof(struct journal_entry, last_bytes[ic->sectors_per_block])… in calculate_journal_section_size()
3393 if (ic->sb->flags & cpu_to_le32(SB_FLAG_HAVE_JOURNAL_MAC)) in calculate_journal_section_size()
3395 ic->journal_entries_per_sector = sector_space / ic->journal_entry_size; in calculate_journal_section_size()
3396 ic->journal_section_entries = ic->journal_entries_per_sector * JOURNAL_BLOCK_SECTORS; in calculate_journal_section_size()
3397 …ic->journal_section_sectors = (ic->journal_section_entries << ic->sb->log2_sectors_per_block) + JO… in calculate_journal_section_size()
3398 ic->journal_entries = ic->journal_section_entries * ic->journal_sections; in calculate_journal_section_size()
3401 static int calculate_device_limits(struct dm_integrity_c *ic) in calculate_device_limits() argument
3405 calculate_journal_section_size(ic); in calculate_device_limits()
3406 initial_sectors = SB_SECTORS + (__u64)ic->journal_section_sectors * ic->journal_sections; in calculate_device_limits()
3407 …if (initial_sectors + METADATA_PADDING_SECTORS >= ic->meta_device_sectors || initial_sectors > UIN… in calculate_device_limits()
3409 ic->initial_sectors = initial_sectors; in calculate_device_limits()
3411 if (!ic->meta_dev) { in calculate_device_limits()
3416 ic->sb->flags & cpu_to_le32(SB_FLAG_FIXED_PADDING) ? in calculate_device_limits()
3420 …ic->metadata_run = round_up((__u64)ic->tag_size << (ic->sb->log2_interleave_sectors - ic->sb->log2… in calculate_device_limits()
3422 if (!(ic->metadata_run & (ic->metadata_run - 1))) in calculate_device_limits()
3423 ic->log2_metadata_run = __ffs(ic->metadata_run); in calculate_device_limits()
3425 ic->log2_metadata_run = -1; in calculate_device_limits()
3427 get_area_and_offset(ic, ic->provided_data_sectors - 1, &last_area, &last_offset); in calculate_device_limits()
3428 last_sector = get_data_sector(ic, last_area, last_offset); in calculate_device_limits()
3429 if (last_sector < ic->start || last_sector >= ic->meta_device_sectors) in calculate_device_limits()
3432 __u64 meta_size = (ic->provided_data_sectors >> ic->sb->log2_sectors_per_block) * ic->tag_size; in calculate_device_limits()
3433 meta_size = (meta_size + ((1U << (ic->log2_buffer_sectors + SECTOR_SHIFT)) - 1)) in calculate_device_limits()
3434 >> (ic->log2_buffer_sectors + SECTOR_SHIFT); in calculate_device_limits()
3435 meta_size <<= ic->log2_buffer_sectors; in calculate_device_limits()
3436 if (ic->initial_sectors + meta_size < ic->initial_sectors || in calculate_device_limits()
3437 ic->initial_sectors + meta_size > ic->meta_device_sectors) in calculate_device_limits()
3439 ic->metadata_run = 1; in calculate_device_limits()
3440 ic->log2_metadata_run = 0; in calculate_device_limits()
3446 static void get_provided_data_sectors(struct dm_integrity_c *ic) in get_provided_data_sectors() argument
3448 if (!ic->meta_dev) { in get_provided_data_sectors()
3450 ic->provided_data_sectors = 0; in get_provided_data_sectors()
3451 for (test_bit = fls64(ic->meta_device_sectors) - 1; test_bit >= 3; test_bit--) { in get_provided_data_sectors()
3452 __u64 prev_data_sectors = ic->provided_data_sectors; in get_provided_data_sectors()
3454 ic->provided_data_sectors |= (sector_t)1 << test_bit; in get_provided_data_sectors()
3455 if (calculate_device_limits(ic)) in get_provided_data_sectors()
3456 ic->provided_data_sectors = prev_data_sectors; in get_provided_data_sectors()
3459 ic->provided_data_sectors = ic->data_device_sectors; in get_provided_data_sectors()
3460 ic->provided_data_sectors &= ~(sector_t)(ic->sectors_per_block - 1); in get_provided_data_sectors()
3464 static int initialize_superblock(struct dm_integrity_c *ic, unsigned journal_sectors, unsigned inte… in initialize_superblock() argument
3469 memset(ic->sb, 0, SB_SECTORS << SECTOR_SHIFT); in initialize_superblock()
3470 memcpy(ic->sb->magic, SB_MAGIC, 8); in initialize_superblock()
3471 ic->sb->integrity_tag_size = cpu_to_le16(ic->tag_size); in initialize_superblock()
3472 ic->sb->log2_sectors_per_block = __ffs(ic->sectors_per_block); in initialize_superblock()
3473 if (ic->journal_mac_alg.alg_string) in initialize_superblock()
3474 ic->sb->flags |= cpu_to_le32(SB_FLAG_HAVE_JOURNAL_MAC); in initialize_superblock()
3476 calculate_journal_section_size(ic); in initialize_superblock()
3477 journal_sections = journal_sectors / ic->journal_section_sectors; in initialize_superblock()
3481 if (ic->fix_hmac && (ic->internal_hash_alg.alg_string || ic->journal_mac_alg.alg_string)) { in initialize_superblock()
3482 ic->sb->flags |= cpu_to_le32(SB_FLAG_FIXED_HMAC); in initialize_superblock()
3483 get_random_bytes(ic->sb->salt, SALT_SIZE); in initialize_superblock()
3486 if (!ic->meta_dev) { in initialize_superblock()
3487 if (ic->fix_padding) in initialize_superblock()
3488 ic->sb->flags |= cpu_to_le32(SB_FLAG_FIXED_PADDING); in initialize_superblock()
3489 ic->sb->journal_sections = cpu_to_le32(journal_sections); in initialize_superblock()
3492 ic->sb->log2_interleave_sectors = __fls(interleave_sectors); in initialize_superblock()
3493 …ic->sb->log2_interleave_sectors = max((__u8)MIN_LOG2_INTERLEAVE_SECTORS, ic->sb->log2_interleave_s… in initialize_superblock()
3494 …ic->sb->log2_interleave_sectors = min((__u8)MAX_LOG2_INTERLEAVE_SECTORS, ic->sb->log2_interleave_s… in initialize_superblock()
3496 get_provided_data_sectors(ic); in initialize_superblock()
3497 if (!ic->provided_data_sectors) in initialize_superblock()
3500 ic->sb->log2_interleave_sectors = 0; in initialize_superblock()
3502 get_provided_data_sectors(ic); in initialize_superblock()
3503 if (!ic->provided_data_sectors) in initialize_superblock()
3507 ic->sb->journal_sections = cpu_to_le32(0); in initialize_superblock()
3509 __u32 prev_journal_sections = le32_to_cpu(ic->sb->journal_sections); in initialize_superblock()
3513 ic->sb->journal_sections = cpu_to_le32(test_journal_sections); in initialize_superblock()
3514 if (calculate_device_limits(ic)) in initialize_superblock()
3515 ic->sb->journal_sections = cpu_to_le32(prev_journal_sections); in initialize_superblock()
3518 if (!le32_to_cpu(ic->sb->journal_sections)) { in initialize_superblock()
3519 if (ic->log2_buffer_sectors > 3) { in initialize_superblock()
3520 ic->log2_buffer_sectors--; in initialize_superblock()
3527 ic->sb->provided_data_sectors = cpu_to_le64(ic->provided_data_sectors); in initialize_superblock()
3529 sb_set_version(ic); in initialize_superblock()
3534 static void dm_integrity_set(struct dm_target *ti, struct dm_integrity_c *ic) in dm_integrity_set() argument
3541 bi.tuple_size = ic->tag_size; in dm_integrity_set()
3543 bi.interval_exp = ic->sb->log2_sectors_per_block + SECTOR_SHIFT; in dm_integrity_set()
3584 static void dm_integrity_free_journal_scatterlist(struct dm_integrity_c *ic, struct scatterlist **s… in dm_integrity_free_journal_scatterlist() argument
3587 for (i = 0; i < ic->journal_sections; i++) in dm_integrity_free_journal_scatterlist()
3592 static struct scatterlist **dm_integrity_alloc_journal_scatterlist(struct dm_integrity_c *ic, in dm_integrity_alloc_journal_scatterlist() argument
3598 sl = kvmalloc_array(ic->journal_sections, in dm_integrity_alloc_journal_scatterlist()
3604 for (i = 0; i < ic->journal_sections; i++) { in dm_integrity_alloc_journal_scatterlist()
3611 page_list_location(ic, i, 0, &start_index, &start_offset); in dm_integrity_alloc_journal_scatterlist()
3612 page_list_location(ic, i, ic->journal_section_sectors - 1, in dm_integrity_alloc_journal_scatterlist()
3620 dm_integrity_free_journal_scatterlist(ic, sl); in dm_integrity_alloc_journal_scatterlist()
3711 static int create_journal(struct dm_integrity_c *ic, char **error) in create_journal() argument
3719 ic->commit_ids[0] = cpu_to_le64(0x1111111111111111ULL); in create_journal()
3720 ic->commit_ids[1] = cpu_to_le64(0x2222222222222222ULL); in create_journal()
3721 ic->commit_ids[2] = cpu_to_le64(0x3333333333333333ULL); in create_journal()
3722 ic->commit_ids[3] = cpu_to_le64(0x4444444444444444ULL); in create_journal()
3724 journal_pages = roundup((__u64)ic->journal_sections * ic->journal_section_sectors, in create_journal()
3732 ic->journal_pages = journal_pages; in create_journal()
3734 ic->journal = dm_integrity_alloc_page_list(ic->journal_pages); in create_journal()
3735 if (!ic->journal) { in create_journal()
3740 if (ic->journal_crypt_alg.alg_string) { in create_journal()
3744 comp.ic = ic; in create_journal()
3745 …ic->journal_crypt = crypto_alloc_skcipher(ic->journal_crypt_alg.alg_string, 0, CRYPTO_ALG_ALLOCATE… in create_journal()
3746 if (IS_ERR(ic->journal_crypt)) { in create_journal()
3748 r = PTR_ERR(ic->journal_crypt); in create_journal()
3749 ic->journal_crypt = NULL; in create_journal()
3752 ivsize = crypto_skcipher_ivsize(ic->journal_crypt); in create_journal()
3753 blocksize = crypto_skcipher_blocksize(ic->journal_crypt); in create_journal()
3755 if (ic->journal_crypt_alg.key) { in create_journal()
3756 r = crypto_skcipher_setkey(ic->journal_crypt, ic->journal_crypt_alg.key, in create_journal()
3757 ic->journal_crypt_alg.key_size); in create_journal()
3764 ic->journal_crypt_alg.alg_string, blocksize, ivsize); in create_journal()
3766 ic->journal_io = dm_integrity_alloc_page_list(ic->journal_pages); in create_journal()
3767 if (!ic->journal_io) { in create_journal()
3776 req = skcipher_request_alloc(ic->journal_crypt, GFP_KERNEL); in create_journal()
3790 ic->journal_xor = dm_integrity_alloc_page_list(ic->journal_pages); in create_journal()
3791 if (!ic->journal_xor) { in create_journal()
3797 sg = kvmalloc_array(ic->journal_pages + 1, in create_journal()
3805 sg_init_table(sg, ic->journal_pages + 1); in create_journal()
3806 for (i = 0; i < ic->journal_pages; i++) { in create_journal()
3807 char *va = lowmem_page_address(ic->journal_xor[i].page); in create_journal()
3811 sg_set_buf(&sg[i], &ic->commit_ids, sizeof ic->commit_ids); in create_journal()
3814 PAGE_SIZE * ic->journal_pages + sizeof ic->commit_ids, crypt_iv); in create_journal()
3820 r = dm_integrity_failed(ic); in create_journal()
3825 DEBUG_bytes(lowmem_page_address(ic->journal_xor[0].page), 64, "xor data"); in create_journal()
3827 crypto_free_skcipher(ic->journal_crypt); in create_journal()
3828 ic->journal_crypt = NULL; in create_journal()
3832 req = skcipher_request_alloc(ic->journal_crypt, GFP_KERNEL); in create_journal()
3853 ic->journal_scatterlist = dm_integrity_alloc_journal_scatterlist(ic, ic->journal); in create_journal()
3854 if (!ic->journal_scatterlist) { in create_journal()
3859 ic->journal_io_scatterlist = dm_integrity_alloc_journal_scatterlist(ic, ic->journal_io); in create_journal()
3860 if (!ic->journal_io_scatterlist) { in create_journal()
3865 ic->sk_requests = kvmalloc_array(ic->journal_sections, in create_journal()
3868 if (!ic->sk_requests) { in create_journal()
3873 for (i = 0; i < ic->journal_sections; i++) { in create_journal()
3889 r = dm_integrity_failed(ic); in create_journal()
3895 section_req = skcipher_request_alloc(ic->journal_crypt, GFP_KERNEL); in create_journal()
3910 section_req->cryptlen = (size_t)ic->journal_section_sectors << SECTOR_SHIFT; in create_journal()
3911 ic->sk_requests[i] = section_req; in create_journal()
3921 if (ic->commit_ids[j] == ic->commit_ids[i]) { in create_journal()
3922 ic->commit_ids[i] = cpu_to_le64(le64_to_cpu(ic->commit_ids[i]) + 1); in create_journal()
3926 DEBUG_print("commit id %u: %016llx\n", i, ic->commit_ids[i]); in create_journal()
3929 journal_tree_size = (__u64)ic->journal_entries * sizeof(struct journal_node); in create_journal()
3935 ic->journal_tree = kvmalloc(journal_tree_size, GFP_KERNEL); in create_journal()
3936 if (!ic->journal_tree) { in create_journal()
3974 struct dm_integrity_c *ic; in dm_integrity_ctr() local
3998 ic = kzalloc(sizeof(struct dm_integrity_c), GFP_KERNEL); in dm_integrity_ctr()
3999 if (!ic) { in dm_integrity_ctr()
4003 ti->private = ic; in dm_integrity_ctr()
4005 ic->ti = ti; in dm_integrity_ctr()
4007 ic->in_progress = RB_ROOT; in dm_integrity_ctr()
4008 INIT_LIST_HEAD(&ic->wait_list); in dm_integrity_ctr()
4009 init_waitqueue_head(&ic->endio_wait); in dm_integrity_ctr()
4010 bio_list_init(&ic->flush_bio_list); in dm_integrity_ctr()
4011 init_waitqueue_head(&ic->copy_to_journal_wait); in dm_integrity_ctr()
4012 init_completion(&ic->crypto_backoff); in dm_integrity_ctr()
4013 atomic64_set(&ic->number_of_mismatches, 0); in dm_integrity_ctr()
4014 ic->bitmap_flush_interval = BITMAP_FLUSH_INTERVAL; in dm_integrity_ctr()
4016 r = dm_get_device(ti, argv[0], dm_table_get_mode(ti->table), &ic->dev); in dm_integrity_ctr()
4027 ic->start = start; in dm_integrity_ctr()
4030 if (sscanf(argv[2], "%u%c", &ic->tag_size, &dummy) != 1 || !ic->tag_size) { in dm_integrity_ctr()
4039 ic->mode = argv[3][0]; in dm_integrity_ctr()
4051 ic->sectors_per_block = 1; in dm_integrity_ctr()
4080 if (ic->meta_dev) { in dm_integrity_ctr()
4081 dm_put_device(ti, ic->meta_dev); in dm_integrity_ctr()
4082 ic->meta_dev = NULL; in dm_integrity_ctr()
4085 dm_table_get_mode(ti->table), &ic->meta_dev); in dm_integrity_ctr()
4098 ic->sectors_per_block = val >> SECTOR_SHIFT; in dm_integrity_ctr()
4107 ic->bitmap_flush_interval = msecs_to_jiffies(val); in dm_integrity_ctr()
4109 r = get_alg_and_key(opt_string, &ic->internal_hash_alg, &ti->error, in dm_integrity_ctr()
4114 r = get_alg_and_key(opt_string, &ic->journal_crypt_alg, &ti->error, in dm_integrity_ctr()
4119 r = get_alg_and_key(opt_string, &ic->journal_mac_alg, &ti->error, in dm_integrity_ctr()
4124 ic->recalculate_flag = true; in dm_integrity_ctr()
4126 ic->recalculate_flag = true; in dm_integrity_ctr()
4127 ic->reset_recalculate_flag = true; in dm_integrity_ctr()
4129 ic->discard = true; in dm_integrity_ctr()
4131 ic->fix_padding = true; in dm_integrity_ctr()
4133 ic->fix_hmac = true; in dm_integrity_ctr()
4135 ic->legacy_recalculate = true; in dm_integrity_ctr()
4143 ic->data_device_sectors = bdev_nr_sectors(ic->dev->bdev); in dm_integrity_ctr()
4144 if (!ic->meta_dev) in dm_integrity_ctr()
4145 ic->meta_device_sectors = ic->data_device_sectors; in dm_integrity_ctr()
4147 ic->meta_device_sectors = bdev_nr_sectors(ic->meta_dev->bdev); in dm_integrity_ctr()
4151 ic->data_device_sectors >> DEFAULT_JOURNAL_SIZE_FACTOR); in dm_integrity_ctr()
4156 ic->log2_buffer_sectors = min((int)__fls(buffer_sectors), 31 - SECTOR_SHIFT); in dm_integrity_ctr()
4158 r = get_mac(&ic->internal_hash, &ic->internal_hash_alg, &ti->error, in dm_integrity_ctr()
4163 r = get_mac(&ic->journal_mac, &ic->journal_mac_alg, &ti->error, in dm_integrity_ctr()
4168 if (!ic->tag_size) { in dm_integrity_ctr()
4169 if (!ic->internal_hash) { in dm_integrity_ctr()
4174 ic->tag_size = crypto_shash_digestsize(ic->internal_hash); in dm_integrity_ctr()
4176 if (ic->tag_size > MAX_TAG_SIZE) { in dm_integrity_ctr()
4181 if (!(ic->tag_size & (ic->tag_size - 1))) in dm_integrity_ctr()
4182 ic->log2_tag_size = __ffs(ic->tag_size); in dm_integrity_ctr()
4184 ic->log2_tag_size = -1; in dm_integrity_ctr()
4186 if (ic->mode == 'B' && !ic->internal_hash) { in dm_integrity_ctr()
4192 if (ic->discard && !ic->internal_hash) { in dm_integrity_ctr()
4198 ic->autocommit_jiffies = msecs_to_jiffies(sync_msec); in dm_integrity_ctr()
4199 ic->autocommit_msec = sync_msec; in dm_integrity_ctr()
4200 timer_setup(&ic->autocommit_timer, autocommit_fn, 0); in dm_integrity_ctr()
4202 ic->io = dm_io_client_create(); in dm_integrity_ctr()
4203 if (IS_ERR(ic->io)) { in dm_integrity_ctr()
4204 r = PTR_ERR(ic->io); in dm_integrity_ctr()
4205 ic->io = NULL; in dm_integrity_ctr()
4210 r = mempool_init_slab_pool(&ic->journal_io_mempool, JOURNAL_IO_MEMPOOL, journal_io_cache); in dm_integrity_ctr()
4216 ic->metadata_wq = alloc_workqueue("dm-integrity-metadata", in dm_integrity_ctr()
4218 if (!ic->metadata_wq) { in dm_integrity_ctr()
4228 ic->wait_wq = alloc_workqueue("dm-integrity-wait", WQ_MEM_RECLAIM | WQ_UNBOUND, 1); in dm_integrity_ctr()
4229 if (!ic->wait_wq) { in dm_integrity_ctr()
4235 ic->offload_wq = alloc_workqueue("dm-integrity-offload", WQ_MEM_RECLAIM, in dm_integrity_ctr()
4237 if (!ic->offload_wq) { in dm_integrity_ctr()
4243 ic->commit_wq = alloc_workqueue("dm-integrity-commit", WQ_MEM_RECLAIM, 1); in dm_integrity_ctr()
4244 if (!ic->commit_wq) { in dm_integrity_ctr()
4249 INIT_WORK(&ic->commit_work, integrity_commit); in dm_integrity_ctr()
4251 if (ic->mode == 'J' || ic->mode == 'B') { in dm_integrity_ctr()
4252 ic->writer_wq = alloc_workqueue("dm-integrity-writer", WQ_MEM_RECLAIM, 1); in dm_integrity_ctr()
4253 if (!ic->writer_wq) { in dm_integrity_ctr()
4258 INIT_WORK(&ic->writer_work, integrity_writer); in dm_integrity_ctr()
4261 ic->sb = alloc_pages_exact(SB_SECTORS << SECTOR_SHIFT, GFP_KERNEL); in dm_integrity_ctr()
4262 if (!ic->sb) { in dm_integrity_ctr()
4268 r = sync_rw_sb(ic, REQ_OP_READ); in dm_integrity_ctr()
4274 if (memcmp(ic->sb->magic, SB_MAGIC, 8)) { in dm_integrity_ctr()
4275 if (ic->mode != 'R') { in dm_integrity_ctr()
4276 if (memchr_inv(ic->sb, 0, SB_SECTORS << SECTOR_SHIFT)) { in dm_integrity_ctr()
4283 r = initialize_superblock(ic, journal_sectors, interleave_sectors); in dm_integrity_ctr()
4288 if (ic->mode != 'R') in dm_integrity_ctr()
4292 if (!ic->sb->version || ic->sb->version > SB_VERSION_5) { in dm_integrity_ctr()
4297 if (le16_to_cpu(ic->sb->integrity_tag_size) != ic->tag_size) { in dm_integrity_ctr()
4302 if (ic->sb->log2_sectors_per_block != __ffs(ic->sectors_per_block)) { in dm_integrity_ctr()
4307 if (!le32_to_cpu(ic->sb->journal_sections)) { in dm_integrity_ctr()
4313 if (!ic->meta_dev) { in dm_integrity_ctr()
4314 if (ic->sb->log2_interleave_sectors < MIN_LOG2_INTERLEAVE_SECTORS || in dm_integrity_ctr()
4315 ic->sb->log2_interleave_sectors > MAX_LOG2_INTERLEAVE_SECTORS) { in dm_integrity_ctr()
4321 if (ic->sb->log2_interleave_sectors) { in dm_integrity_ctr()
4327 …if (!!(ic->sb->flags & cpu_to_le32(SB_FLAG_HAVE_JOURNAL_MAC)) != !!ic->journal_mac_alg.alg_string)… in dm_integrity_ctr()
4333 get_provided_data_sectors(ic); in dm_integrity_ctr()
4334 if (!ic->provided_data_sectors) { in dm_integrity_ctr()
4341 r = calculate_device_limits(ic); in dm_integrity_ctr()
4343 if (ic->meta_dev) { in dm_integrity_ctr()
4344 if (ic->log2_buffer_sectors > 3) { in dm_integrity_ctr()
4345 ic->log2_buffer_sectors--; in dm_integrity_ctr()
4355 if (log2_sectors_per_bitmap_bit < ic->sb->log2_sectors_per_block) in dm_integrity_ctr()
4356 log2_sectors_per_bitmap_bit = ic->sb->log2_sectors_per_block; in dm_integrity_ctr()
4358 …bits_in_journal = ((__u64)ic->journal_section_sectors * ic->journal_sections) << (SECTOR_SHIFT + 3… in dm_integrity_ctr()
4361 …while (bits_in_journal < (ic->provided_data_sectors + ((sector_t)1 << log2_sectors_per_bitmap_bit)… in dm_integrity_ctr()
4364 log2_blocks_per_bitmap_bit = log2_sectors_per_bitmap_bit - ic->sb->log2_sectors_per_block; in dm_integrity_ctr()
4365 ic->log2_blocks_per_bitmap_bit = log2_blocks_per_bitmap_bit; in dm_integrity_ctr()
4367 ic->sb->log2_blocks_per_bitmap_bit = log2_blocks_per_bitmap_bit; in dm_integrity_ctr()
4369 n_bitmap_bits = ((ic->provided_data_sectors >> ic->sb->log2_sectors_per_block) in dm_integrity_ctr()
4371 ic->n_bitmap_blocks = DIV_ROUND_UP(n_bitmap_bits, BITMAP_BLOCK_SIZE * 8); in dm_integrity_ctr()
4373 if (!ic->meta_dev) in dm_integrity_ctr()
4374 ic->log2_buffer_sectors = min(ic->log2_buffer_sectors, (__u8)__ffs(ic->metadata_run)); in dm_integrity_ctr()
4376 if (ti->len > ic->provided_data_sectors) { in dm_integrity_ctr()
4383 threshold = (__u64)ic->journal_entries * (100 - journal_watermark); in dm_integrity_ctr()
4386 ic->free_sectors_threshold = threshold; in dm_integrity_ctr()
4389 DEBUG_print(" integrity_tag_size %u\n", le16_to_cpu(ic->sb->integrity_tag_size)); in dm_integrity_ctr()
4390 DEBUG_print(" journal_entry_size %u\n", ic->journal_entry_size); in dm_integrity_ctr()
4391 DEBUG_print(" journal_entries_per_sector %u\n", ic->journal_entries_per_sector); in dm_integrity_ctr()
4392 DEBUG_print(" journal_section_entries %u\n", ic->journal_section_entries); in dm_integrity_ctr()
4393 DEBUG_print(" journal_section_sectors %u\n", ic->journal_section_sectors); in dm_integrity_ctr()
4394 DEBUG_print(" journal_sections %u\n", (unsigned)le32_to_cpu(ic->sb->journal_sections)); in dm_integrity_ctr()
4395 DEBUG_print(" journal_entries %u\n", ic->journal_entries); in dm_integrity_ctr()
4396 DEBUG_print(" log2_interleave_sectors %d\n", ic->sb->log2_interleave_sectors); in dm_integrity_ctr()
4397 DEBUG_print(" data_device_sectors 0x%llx\n", bdev_nr_sectors(ic->dev->bdev)); in dm_integrity_ctr()
4398 DEBUG_print(" initial_sectors 0x%x\n", ic->initial_sectors); in dm_integrity_ctr()
4399 DEBUG_print(" metadata_run 0x%x\n", ic->metadata_run); in dm_integrity_ctr()
4400 DEBUG_print(" log2_metadata_run %d\n", ic->log2_metadata_run); in dm_integrity_ctr()
4401 …DEBUG_print(" provided_data_sectors 0x%llx (%llu)\n", ic->provided_data_sectors, ic->provided_data… in dm_integrity_ctr()
4402 DEBUG_print(" log2_buffer_sectors %u\n", ic->log2_buffer_sectors); in dm_integrity_ctr()
4405 if (ic->recalculate_flag && !(ic->sb->flags & cpu_to_le32(SB_FLAG_RECALCULATING))) { in dm_integrity_ctr()
4406 ic->sb->flags |= cpu_to_le32(SB_FLAG_RECALCULATING); in dm_integrity_ctr()
4407 ic->sb->recalc_sector = cpu_to_le64(0); in dm_integrity_ctr()
4410 if (ic->internal_hash) { in dm_integrity_ctr()
4412 ic->recalc_wq = alloc_workqueue("dm-integrity-recalc", WQ_MEM_RECLAIM, 1); in dm_integrity_ctr()
4413 if (!ic->recalc_wq ) { in dm_integrity_ctr()
4418 INIT_WORK(&ic->recalc_work, integrity_recalc); in dm_integrity_ctr()
4419 ic->recalc_buffer = vmalloc(RECALC_SECTORS << SECTOR_SHIFT); in dm_integrity_ctr()
4420 if (!ic->recalc_buffer) { in dm_integrity_ctr()
4425 recalc_tags_size = (RECALC_SECTORS >> ic->sb->log2_sectors_per_block) * ic->tag_size; in dm_integrity_ctr()
4426 if (crypto_shash_digestsize(ic->internal_hash) > ic->tag_size) in dm_integrity_ctr()
4427 recalc_tags_size += crypto_shash_digestsize(ic->internal_hash) - ic->tag_size; in dm_integrity_ctr()
4428 ic->recalc_tags = kvmalloc(recalc_tags_size, GFP_KERNEL); in dm_integrity_ctr()
4429 if (!ic->recalc_tags) { in dm_integrity_ctr()
4435 if (ic->sb->flags & cpu_to_le32(SB_FLAG_RECALCULATING)) { in dm_integrity_ctr()
4442 if (ic->sb->flags & cpu_to_le32(SB_FLAG_RECALCULATING) && in dm_integrity_ctr()
4443 le64_to_cpu(ic->sb->recalc_sector) < ic->provided_data_sectors && in dm_integrity_ctr()
4444 dm_integrity_disable_recalculate(ic)) { in dm_integrity_ctr()
4450 ic->bufio = dm_bufio_client_create(ic->meta_dev ? ic->meta_dev->bdev : ic->dev->bdev, in dm_integrity_ctr()
4451 1U << (SECTOR_SHIFT + ic->log2_buffer_sectors), 1, 0, NULL, NULL, 0); in dm_integrity_ctr()
4452 if (IS_ERR(ic->bufio)) { in dm_integrity_ctr()
4453 r = PTR_ERR(ic->bufio); in dm_integrity_ctr()
4455 ic->bufio = NULL; in dm_integrity_ctr()
4458 dm_bufio_set_sector_offset(ic->bufio, ic->start + ic->initial_sectors); in dm_integrity_ctr()
4460 if (ic->mode != 'R') { in dm_integrity_ctr()
4461 r = create_journal(ic, &ti->error); in dm_integrity_ctr()
4467 if (ic->mode == 'B') { in dm_integrity_ctr()
4469 unsigned n_bitmap_pages = DIV_ROUND_UP(ic->n_bitmap_blocks, PAGE_SIZE / BITMAP_BLOCK_SIZE); in dm_integrity_ctr()
4471 ic->recalc_bitmap = dm_integrity_alloc_page_list(n_bitmap_pages); in dm_integrity_ctr()
4472 if (!ic->recalc_bitmap) { in dm_integrity_ctr()
4476 ic->may_write_bitmap = dm_integrity_alloc_page_list(n_bitmap_pages); in dm_integrity_ctr()
4477 if (!ic->may_write_bitmap) { in dm_integrity_ctr()
4481 ic->bbs = kvmalloc_array(ic->n_bitmap_blocks, sizeof(struct bitmap_block_status), GFP_KERNEL); in dm_integrity_ctr()
4482 if (!ic->bbs) { in dm_integrity_ctr()
4486 INIT_DELAYED_WORK(&ic->bitmap_flush_work, bitmap_flush_work); in dm_integrity_ctr()
4487 for (i = 0; i < ic->n_bitmap_blocks; i++) { in dm_integrity_ctr()
4488 struct bitmap_block_status *bbs = &ic->bbs[i]; in dm_integrity_ctr()
4492 bbs->ic = ic; in dm_integrity_ctr()
4501 bbs->bitmap = lowmem_page_address(ic->journal[pl_index].page) + pl_offset; in dm_integrity_ctr()
4506 init_journal(ic, 0, ic->journal_sections, 0); in dm_integrity_ctr()
4507 r = dm_integrity_failed(ic); in dm_integrity_ctr()
4512 r = sync_rw_sb(ic, REQ_OP_WRITE | REQ_FUA); in dm_integrity_ctr()
4517 ic->just_formatted = true; in dm_integrity_ctr()
4520 if (!ic->meta_dev) { in dm_integrity_ctr()
4521 r = dm_set_target_max_io_len(ti, 1U << ic->sb->log2_interleave_sectors); in dm_integrity_ctr()
4525 if (ic->mode == 'B') { in dm_integrity_ctr()
4526 …unsigned max_io_len = ((sector_t)ic->sectors_per_block << ic->log2_blocks_per_bitmap_bit) * (BITMA… in dm_integrity_ctr()
4537 if (!ic->internal_hash) in dm_integrity_ctr()
4538 dm_integrity_set(ti, ic); in dm_integrity_ctr()
4542 if (ic->discard) in dm_integrity_ctr()
4556 struct dm_integrity_c *ic = ti->private; in dm_integrity_dtr() local
4558 BUG_ON(!RB_EMPTY_ROOT(&ic->in_progress)); in dm_integrity_dtr()
4559 BUG_ON(!list_empty(&ic->wait_list)); in dm_integrity_dtr()
4561 if (ic->metadata_wq) in dm_integrity_dtr()
4562 destroy_workqueue(ic->metadata_wq); in dm_integrity_dtr()
4563 if (ic->wait_wq) in dm_integrity_dtr()
4564 destroy_workqueue(ic->wait_wq); in dm_integrity_dtr()
4565 if (ic->offload_wq) in dm_integrity_dtr()
4566 destroy_workqueue(ic->offload_wq); in dm_integrity_dtr()
4567 if (ic->commit_wq) in dm_integrity_dtr()
4568 destroy_workqueue(ic->commit_wq); in dm_integrity_dtr()
4569 if (ic->writer_wq) in dm_integrity_dtr()
4570 destroy_workqueue(ic->writer_wq); in dm_integrity_dtr()
4571 if (ic->recalc_wq) in dm_integrity_dtr()
4572 destroy_workqueue(ic->recalc_wq); in dm_integrity_dtr()
4573 vfree(ic->recalc_buffer); in dm_integrity_dtr()
4574 kvfree(ic->recalc_tags); in dm_integrity_dtr()
4575 kvfree(ic->bbs); in dm_integrity_dtr()
4576 if (ic->bufio) in dm_integrity_dtr()
4577 dm_bufio_client_destroy(ic->bufio); in dm_integrity_dtr()
4578 mempool_exit(&ic->journal_io_mempool); in dm_integrity_dtr()
4579 if (ic->io) in dm_integrity_dtr()
4580 dm_io_client_destroy(ic->io); in dm_integrity_dtr()
4581 if (ic->dev) in dm_integrity_dtr()
4582 dm_put_device(ti, ic->dev); in dm_integrity_dtr()
4583 if (ic->meta_dev) in dm_integrity_dtr()
4584 dm_put_device(ti, ic->meta_dev); in dm_integrity_dtr()
4585 dm_integrity_free_page_list(ic->journal); in dm_integrity_dtr()
4586 dm_integrity_free_page_list(ic->journal_io); in dm_integrity_dtr()
4587 dm_integrity_free_page_list(ic->journal_xor); in dm_integrity_dtr()
4588 dm_integrity_free_page_list(ic->recalc_bitmap); in dm_integrity_dtr()
4589 dm_integrity_free_page_list(ic->may_write_bitmap); in dm_integrity_dtr()
4590 if (ic->journal_scatterlist) in dm_integrity_dtr()
4591 dm_integrity_free_journal_scatterlist(ic, ic->journal_scatterlist); in dm_integrity_dtr()
4592 if (ic->journal_io_scatterlist) in dm_integrity_dtr()
4593 dm_integrity_free_journal_scatterlist(ic, ic->journal_io_scatterlist); in dm_integrity_dtr()
4594 if (ic->sk_requests) { in dm_integrity_dtr()
4597 for (i = 0; i < ic->journal_sections; i++) { in dm_integrity_dtr()
4598 struct skcipher_request *req = ic->sk_requests[i]; in dm_integrity_dtr()
4604 kvfree(ic->sk_requests); in dm_integrity_dtr()
4606 kvfree(ic->journal_tree); in dm_integrity_dtr()
4607 if (ic->sb) in dm_integrity_dtr()
4608 free_pages_exact(ic->sb, SB_SECTORS << SECTOR_SHIFT); in dm_integrity_dtr()
4610 if (ic->internal_hash) in dm_integrity_dtr()
4611 crypto_free_shash(ic->internal_hash); in dm_integrity_dtr()
4612 free_alg(&ic->internal_hash_alg); in dm_integrity_dtr()
4614 if (ic->journal_crypt) in dm_integrity_dtr()
4615 crypto_free_skcipher(ic->journal_crypt); in dm_integrity_dtr()
4616 free_alg(&ic->journal_crypt_alg); in dm_integrity_dtr()
4618 if (ic->journal_mac) in dm_integrity_dtr()
4619 crypto_free_shash(ic->journal_mac); in dm_integrity_dtr()
4620 free_alg(&ic->journal_mac_alg); in dm_integrity_dtr()
4622 kfree(ic); in dm_integrity_dtr()