Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'for-6.11/dm-changes' of git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm

Pull device mapper updates from Mikulas Patocka:

- Optimize processing of flush bios in the dm-linear and dm-stripe
targets

- Dm-io cleansups and refactoring

- Remove unused 'struct thunk' in dm-cache

- Handle minor device numbers > 255 in dm-init

- Dm-verity refactoring & enabling platform keyring

- Fix warning in dm-raid

- Improve dm-crypt performance - split bios to smaller pieces, so that
They could be processed concurrently

- Stop using blk_limits_io_{min,opt}

- Dm-vdo cleanup and refactoring

- Remove max_write_zeroes_granularity and max_secure_erase_granularity

- Dm-multipath cleanup & refactoring

- Add dm-crypt and dm-integrity support for non-power-of-2 sector size

- Fix reshape in dm-raid

- Make dm_block_validator const

* tag 'for-6.11/dm-changes' of git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm: (33 commits)
dm vdo: fix a minor formatting issue in vdo.rst
dm vdo int-map: fix kerneldoc formatting
dm vdo repair: add missing kerneldoc fields
dm: Constify struct dm_block_validator
dm-integrity: introduce the Inline mode
dm: introduce the target flag mempool_needs_integrity
dm raid: fix stripes adding reshape size issues
dm raid: move _get_reshape_sectors() as prerequisite to fixing reshape size issues
dm-crypt: support for per-sector NVMe metadata
dm mpath: don't call dm_get_device in multipath_message
dm: factor out helper function from dm_get_device
dm-verity: fix dm_is_verity_target() when dm-verity is builtin
dm: Remove max_secure_erase_granularity
dm: Remove max_write_zeroes_granularity
dm vdo indexer: use swap() instead of open coding it
dm vdo: remove unused struct 'uds_attribute'
dm: stop using blk_limits_io_{min,opt}
dm-crypt: limit the size of encryption requests
dm verity: add support for signature verification with platform keyring
dm-raid: Fix WARN_ON_ONCE check for sync_thread in raid_resume
...

+948 -583
+11
Documentation/admin-guide/device-mapper/dm-crypt.rst
··· 160 160 The <iv_offset> must be multiple of <sector_size> (in 512 bytes units) 161 161 if this flag is specified. 162 162 163 + 164 + Module parameters:: 165 + max_read_size 166 + max_write_size 167 + Maximum size of read or write requests. When a request larger than this size 168 + is received, dm-crypt will split the request. The splitting improves 169 + concurrency (the split requests could be encrypted in parallel by multiple 170 + cores), but it also causes overhead. The user should tune these parameters to 171 + fit the actual workload. 172 + 173 + 163 174 Example scripts 164 175 =============== 165 176 LUKS (Linux Unified Key Setup) is now the preferred way to set up disk
+1
Documentation/admin-guide/device-mapper/vdo.rst
··· 241 241 All vdo devices accept messages in the form: 242 242 243 243 :: 244 + 244 245 dmsetup message <target-name> 0 <message-name> <message-parameters> 245 246 246 247 The messages are:
+10
drivers/md/Kconfig
··· 540 540 541 541 If unsure, say N. 542 542 543 + config DM_VERITY_VERIFY_ROOTHASH_SIG_PLATFORM_KEYRING 544 + bool "Verity data device root hash signature verification with platform keyring" 545 + default DM_VERITY_VERIFY_ROOTHASH_SIG_SECONDARY_KEYRING 546 + depends on DM_VERITY_VERIFY_ROOTHASH_SIG 547 + depends on INTEGRITY_PLATFORM_KEYRING 548 + help 549 + Rely also on the platform keyring to verify dm-verity signatures. 550 + 551 + If unsure, say N. 552 + 543 553 config DM_VERITY_FEC 544 554 bool "Verity forward error correction support" 545 555 depends on DM_VERITY
+3 -12
drivers/md/dm-cache-metadata.c
··· 170 170 */ 171 171 #define SUPERBLOCK_CSUM_XOR 9031977 172 172 173 - static void sb_prepare_for_write(struct dm_block_validator *v, 173 + static void sb_prepare_for_write(const struct dm_block_validator *v, 174 174 struct dm_block *b, 175 175 size_t sb_block_size) 176 176 { ··· 195 195 return 0; 196 196 } 197 197 198 - static int sb_check(struct dm_block_validator *v, 198 + static int sb_check(const struct dm_block_validator *v, 199 199 struct dm_block *b, 200 200 size_t sb_block_size) 201 201 { ··· 228 228 return check_metadata_version(disk_super); 229 229 } 230 230 231 - static struct dm_block_validator sb_validator = { 231 + static const struct dm_block_validator sb_validator = { 232 232 .name = "superblock", 233 233 .prepare_for_write = sb_prepare_for_write, 234 234 .check = sb_check ··· 1281 1281 1282 1282 return r; 1283 1283 } 1284 - 1285 - struct thunk { 1286 - load_mapping_fn fn; 1287 - void *context; 1288 - 1289 - struct dm_cache_metadata *cmd; 1290 - bool respect_dirty_flags; 1291 - bool hints_valid; 1292 - }; 1293 1284 1294 1285 static bool policy_unchanged(struct dm_cache_metadata *cmd, 1295 1286 struct dm_cache_policy *policy)
+2 -2
drivers/md/dm-cache-target.c
··· 3416 3416 */ 3417 3417 if (io_opt_sectors < cache->sectors_per_block || 3418 3418 do_div(io_opt_sectors, cache->sectors_per_block)) { 3419 - blk_limits_io_min(limits, cache->sectors_per_block << SECTOR_SHIFT); 3420 - blk_limits_io_opt(limits, cache->sectors_per_block << SECTOR_SHIFT); 3419 + limits->io_min = cache->sectors_per_block << SECTOR_SHIFT; 3420 + limits->io_opt = cache->sectors_per_block << SECTOR_SHIFT; 3421 3421 } 3422 3422 3423 3423 disable_passdown_if_not_supported(cache);
+3 -3
drivers/md/dm-clone-metadata.c
··· 163 163 /* 164 164 * Superblock validation. 165 165 */ 166 - static void sb_prepare_for_write(struct dm_block_validator *v, 166 + static void sb_prepare_for_write(const struct dm_block_validator *v, 167 167 struct dm_block *b, size_t sb_block_size) 168 168 { 169 169 struct superblock_disk *sb; ··· 177 177 sb->csum = cpu_to_le32(csum); 178 178 } 179 179 180 - static int sb_check(struct dm_block_validator *v, struct dm_block *b, 180 + static int sb_check(const struct dm_block_validator *v, struct dm_block *b, 181 181 size_t sb_block_size) 182 182 { 183 183 struct superblock_disk *sb; ··· 220 220 return 0; 221 221 } 222 222 223 - static struct dm_block_validator sb_validator = { 223 + static const struct dm_block_validator sb_validator = { 224 224 .name = "superblock", 225 225 .prepare_for_write = sb_prepare_for_write, 226 226 .check = sb_check
+2 -2
drivers/md/dm-clone-target.c
··· 2073 2073 */ 2074 2074 if (io_opt_sectors < clone->region_size || 2075 2075 do_div(io_opt_sectors, clone->region_size)) { 2076 - blk_limits_io_min(limits, clone->region_size << SECTOR_SHIFT); 2077 - blk_limits_io_opt(limits, clone->region_size << SECTOR_SHIFT); 2076 + limits->io_min = clone->region_size << SECTOR_SHIFT; 2077 + limits->io_opt = clone->region_size << SECTOR_SHIFT; 2078 2078 } 2079 2079 2080 2080 disable_passdown_if_not_supported(clone);
+2
drivers/md/dm-core.h
··· 206 206 207 207 bool integrity_supported:1; 208 208 bool singleton:1; 209 + /* set if all the targets in the table have "flush_bypasses_map" set */ 210 + bool flush_bypasses_map:1; 209 211 210 212 /* 211 213 * Indicates the rw permissions for the new logical device. This
+52 -25
drivers/md/dm-crypt.c
··· 214 214 215 215 unsigned int integrity_tag_size; 216 216 unsigned int integrity_iv_size; 217 - unsigned int on_disk_tag_size; 217 + unsigned int used_tag_size; 218 + unsigned int tuple_size; 218 219 219 220 /* 220 221 * pool for per bio private data, crypto requests, ··· 242 241 static volatile unsigned long dm_crypt_pages_per_client; 243 242 #define DM_CRYPT_MEMORY_PERCENT 2 244 243 #define DM_CRYPT_MIN_PAGES_PER_CLIENT (BIO_MAX_VECS * 16) 244 + #define DM_CRYPT_DEFAULT_MAX_READ_SIZE 131072 245 + #define DM_CRYPT_DEFAULT_MAX_WRITE_SIZE 131072 246 + 247 + static unsigned int max_read_size = 0; 248 + module_param(max_read_size, uint, 0644); 249 + MODULE_PARM_DESC(max_read_size, "Maximum size of a read request"); 250 + static unsigned int max_write_size = 0; 251 + module_param(max_write_size, uint, 0644); 252 + MODULE_PARM_DESC(max_write_size, "Maximum size of a write request"); 253 + static unsigned get_max_request_size(struct crypt_config *cc, bool wrt) 254 + { 255 + unsigned val, sector_align; 256 + val = !wrt ? READ_ONCE(max_read_size) : READ_ONCE(max_write_size); 257 + if (likely(!val)) 258 + val = !wrt ? DM_CRYPT_DEFAULT_MAX_READ_SIZE : DM_CRYPT_DEFAULT_MAX_WRITE_SIZE; 259 + if (wrt || cc->used_tag_size) { 260 + if (unlikely(val > BIO_MAX_VECS << PAGE_SHIFT)) 261 + val = BIO_MAX_VECS << PAGE_SHIFT; 262 + } 263 + sector_align = max(bdev_logical_block_size(cc->dev->bdev), (unsigned)cc->sector_size); 264 + val = round_down(val, sector_align); 265 + if (unlikely(!val)) 266 + val = sector_align; 267 + return val >> SECTOR_SHIFT; 268 + } 245 269 246 270 static void crypt_endio(struct bio *clone); 247 271 static void kcryptd_queue_crypt(struct dm_crypt_io *io); ··· 1177 1151 unsigned int tag_len; 1178 1152 int ret; 1179 1153 1180 - if (!bio_sectors(bio) || !io->cc->on_disk_tag_size) 1154 + if (!bio_sectors(bio) || !io->cc->tuple_size) 1181 1155 return 0; 1182 1156 1183 1157 bip = bio_integrity_alloc(bio, GFP_NOIO, 1); 1184 1158 if (IS_ERR(bip)) 1185 1159 return PTR_ERR(bip); 1186 1160 1187 - tag_len = io->cc->on_disk_tag_size * (bio_sectors(bio) >> io->cc->sector_shift); 1161 + tag_len = io->cc->tuple_size * (bio_sectors(bio) >> io->cc->sector_shift); 1188 1162 1189 1163 bip->bip_iter.bi_sector = io->cc->start + io->sector; 1190 1164 ··· 1208 1182 return -EINVAL; 1209 1183 } 1210 1184 1211 - if (bi->tag_size != cc->on_disk_tag_size || 1212 - bi->tuple_size != cc->on_disk_tag_size) { 1185 + if (bi->tuple_size < cc->used_tag_size) { 1213 1186 ti->error = "Integrity profile tag size mismatch."; 1214 1187 return -EINVAL; 1215 1188 } 1189 + cc->tuple_size = bi->tuple_size; 1216 1190 if (1 << bi->interval_exp != cc->sector_size) { 1217 1191 ti->error = "Integrity profile sector size mismatch."; 1218 1192 return -EINVAL; 1219 1193 } 1220 1194 1221 1195 if (crypt_integrity_aead(cc)) { 1222 - cc->integrity_tag_size = cc->on_disk_tag_size - cc->integrity_iv_size; 1196 + cc->integrity_tag_size = cc->used_tag_size - cc->integrity_iv_size; 1223 1197 DMDEBUG("%s: Integrity AEAD, tag size %u, IV size %u.", dm_device_name(md), 1224 1198 cc->integrity_tag_size, cc->integrity_iv_size); 1225 1199 ··· 1231 1205 DMDEBUG("%s: Additional per-sector space %u bytes for IV.", dm_device_name(md), 1232 1206 cc->integrity_iv_size); 1233 1207 1234 - if ((cc->integrity_tag_size + cc->integrity_iv_size) != bi->tag_size) { 1208 + if ((cc->integrity_tag_size + cc->integrity_iv_size) > cc->tuple_size) { 1235 1209 ti->error = "Not enough space for integrity tag in the profile."; 1236 1210 return -EINVAL; 1237 1211 } ··· 1310 1284 struct dm_crypt_io *io = container_of(ctx, struct dm_crypt_io, ctx); 1311 1285 1312 1286 return &io->integrity_metadata[*org_tag_of_dmreq(cc, dmreq) * 1313 - cc->on_disk_tag_size]; 1287 + cc->tuple_size]; 1314 1288 } 1315 1289 1316 1290 static void *iv_tag_from_dmreq(struct crypt_config *cc, ··· 1391 1365 aead_request_set_crypt(req, dmreq->sg_in, dmreq->sg_out, 1392 1366 cc->sector_size, iv); 1393 1367 r = crypto_aead_encrypt(req); 1394 - if (cc->integrity_tag_size + cc->integrity_iv_size != cc->on_disk_tag_size) 1368 + if (cc->integrity_tag_size + cc->integrity_iv_size != cc->tuple_size) 1395 1369 memset(tag + cc->integrity_tag_size + cc->integrity_iv_size, 0, 1396 - cc->on_disk_tag_size - (cc->integrity_tag_size + cc->integrity_iv_size)); 1370 + cc->tuple_size - (cc->integrity_tag_size + cc->integrity_iv_size)); 1397 1371 } else { 1398 1372 aead_request_set_crypt(req, dmreq->sg_in, dmreq->sg_out, 1399 1373 cc->sector_size + cc->integrity_tag_size, iv); ··· 1823 1797 return; 1824 1798 1825 1799 if (likely(!io->ctx.aead_recheck) && unlikely(io->ctx.aead_failed) && 1826 - cc->on_disk_tag_size && bio_data_dir(base_bio) == READ) { 1800 + cc->used_tag_size && bio_data_dir(base_bio) == READ) { 1827 1801 io->ctx.aead_recheck = true; 1828 1802 io->ctx.aead_failed = false; 1829 1803 io->error = 0; ··· 3207 3181 ti->error = "Invalid integrity arguments"; 3208 3182 return -EINVAL; 3209 3183 } 3210 - cc->on_disk_tag_size = val; 3184 + cc->used_tag_size = val; 3211 3185 sval = strchr(opt_string + strlen("integrity:"), ':') + 1; 3212 3186 if (!strcasecmp(sval, "aead")) { 3213 3187 set_bit(CRYPT_MODE_INTEGRITY_AEAD, &cc->cipher_flags); ··· 3419 3393 if (ret) 3420 3394 goto bad; 3421 3395 3422 - cc->tag_pool_max_sectors = POOL_ENTRY_SIZE / cc->on_disk_tag_size; 3396 + cc->tag_pool_max_sectors = POOL_ENTRY_SIZE / cc->tuple_size; 3423 3397 if (!cc->tag_pool_max_sectors) 3424 3398 cc->tag_pool_max_sectors = 1; 3425 3399 3426 3400 ret = mempool_init_kmalloc_pool(&cc->tag_pool, MIN_IOS, 3427 - cc->tag_pool_max_sectors * cc->on_disk_tag_size); 3401 + cc->tag_pool_max_sectors * cc->tuple_size); 3428 3402 if (ret) { 3429 3403 ti->error = "Cannot allocate integrity tags mempool"; 3430 3404 goto bad; ··· 3500 3474 { 3501 3475 struct dm_crypt_io *io; 3502 3476 struct crypt_config *cc = ti->private; 3477 + unsigned max_sectors; 3503 3478 3504 3479 /* 3505 3480 * If bio is REQ_PREFLUSH or REQ_OP_DISCARD, just bypass crypt queues. ··· 3519 3492 /* 3520 3493 * Check if bio is too large, split as needed. 3521 3494 */ 3522 - if (unlikely(bio->bi_iter.bi_size > (BIO_MAX_VECS << PAGE_SHIFT)) && 3523 - (bio_data_dir(bio) == WRITE || cc->on_disk_tag_size)) 3524 - dm_accept_partial_bio(bio, ((BIO_MAX_VECS << PAGE_SHIFT) >> SECTOR_SHIFT)); 3495 + max_sectors = get_max_request_size(cc, bio_data_dir(bio) == WRITE); 3496 + if (unlikely(bio_sectors(bio) > max_sectors)) 3497 + dm_accept_partial_bio(bio, max_sectors); 3525 3498 3526 3499 /* 3527 3500 * Ensure that bio is a multiple of internal sector encryption size ··· 3536 3509 io = dm_per_bio_data(bio, cc->per_bio_data_size); 3537 3510 crypt_io_init(io, cc, bio, dm_target_offset(ti, bio->bi_iter.bi_sector)); 3538 3511 3539 - if (cc->on_disk_tag_size) { 3540 - unsigned int tag_len = cc->on_disk_tag_size * (bio_sectors(bio) >> cc->sector_shift); 3512 + if (cc->tuple_size) { 3513 + unsigned int tag_len = cc->tuple_size * (bio_sectors(bio) >> cc->sector_shift); 3541 3514 3542 3515 if (unlikely(tag_len > KMALLOC_MAX_SIZE)) 3543 3516 io->integrity_metadata = NULL; ··· 3609 3582 num_feature_args += test_bit(DM_CRYPT_NO_WRITE_WORKQUEUE, &cc->flags); 3610 3583 num_feature_args += cc->sector_size != (1 << SECTOR_SHIFT); 3611 3584 num_feature_args += test_bit(CRYPT_IV_LARGE_SECTORS, &cc->cipher_flags); 3612 - if (cc->on_disk_tag_size) 3585 + if (cc->used_tag_size) 3613 3586 num_feature_args++; 3614 3587 if (num_feature_args) { 3615 3588 DMEMIT(" %d", num_feature_args); ··· 3625 3598 DMEMIT(" no_read_workqueue"); 3626 3599 if (test_bit(DM_CRYPT_NO_WRITE_WORKQUEUE, &cc->flags)) 3627 3600 DMEMIT(" no_write_workqueue"); 3628 - if (cc->on_disk_tag_size) 3629 - DMEMIT(" integrity:%u:%s", cc->on_disk_tag_size, cc->cipher_auth); 3601 + if (cc->used_tag_size) 3602 + DMEMIT(" integrity:%u:%s", cc->used_tag_size, cc->cipher_auth); 3630 3603 if (cc->sector_size != (1 << SECTOR_SHIFT)) 3631 3604 DMEMIT(" sector_size:%d", cc->sector_size); 3632 3605 if (test_bit(CRYPT_IV_LARGE_SECTORS, &cc->cipher_flags)) ··· 3648 3621 DMEMIT(",iv_large_sectors=%c", test_bit(CRYPT_IV_LARGE_SECTORS, &cc->cipher_flags) ? 3649 3622 'y' : 'n'); 3650 3623 3651 - if (cc->on_disk_tag_size) 3624 + if (cc->used_tag_size) 3652 3625 DMEMIT(",integrity_tag_size=%u,cipher_auth=%s", 3653 - cc->on_disk_tag_size, cc->cipher_auth); 3626 + cc->used_tag_size, cc->cipher_auth); 3654 3627 if (cc->sector_size != (1 << SECTOR_SHIFT)) 3655 3628 DMEMIT(",sector_size=%d", cc->sector_size); 3656 3629 if (cc->cipher_string) ··· 3758 3731 3759 3732 static struct target_type crypt_target = { 3760 3733 .name = "crypt", 3761 - .version = {1, 26, 0}, 3734 + .version = {1, 27, 0}, 3762 3735 .module = THIS_MODULE, 3763 3736 .ctr = crypt_ctr, 3764 3737 .dtr = crypt_dtr,
+1 -1
drivers/md/dm-ebs-target.c
··· 428 428 limits->logical_block_size = to_bytes(ec->e_bs); 429 429 limits->physical_block_size = to_bytes(ec->u_bs); 430 430 limits->alignment_offset = limits->physical_block_size; 431 - blk_limits_io_min(limits, limits->logical_block_size); 431 + limits->io_min = limits->logical_block_size; 432 432 } 433 433 434 434 static int ebs_iterate_devices(struct dm_target *ti,
+5 -5
drivers/md/dm-era-target.c
··· 196 196 * Superblock validation 197 197 *-------------------------------------------------------------- 198 198 */ 199 - static void sb_prepare_for_write(struct dm_block_validator *v, 199 + static void sb_prepare_for_write(const struct dm_block_validator *v, 200 200 struct dm_block *b, 201 201 size_t sb_block_size) 202 202 { ··· 221 221 return 0; 222 222 } 223 223 224 - static int sb_check(struct dm_block_validator *v, 224 + static int sb_check(const struct dm_block_validator *v, 225 225 struct dm_block *b, 226 226 size_t sb_block_size) 227 227 { ··· 254 254 return check_metadata_version(disk); 255 255 } 256 256 257 - static struct dm_block_validator sb_validator = { 257 + static const struct dm_block_validator sb_validator = { 258 258 .name = "superblock", 259 259 .prepare_for_write = sb_prepare_for_write, 260 260 .check = sb_check ··· 1733 1733 */ 1734 1734 if (io_opt_sectors < era->sectors_per_block || 1735 1735 do_div(io_opt_sectors, era->sectors_per_block)) { 1736 - blk_limits_io_min(limits, 0); 1737 - blk_limits_io_opt(limits, era->sectors_per_block << SECTOR_SHIFT); 1736 + limits->io_min = 0; 1737 + limits->io_opt = era->sectors_per_block << SECTOR_SHIFT; 1738 1738 } 1739 1739 } 1740 1740
+3 -1
drivers/md/dm-init.c
··· 212 212 strscpy(dev->dmi.uuid, field[1], sizeof(dev->dmi.uuid)); 213 213 /* minor */ 214 214 if (strlen(field[2])) { 215 - if (kstrtoull(field[2], 0, &dev->dmi.dev)) 215 + if (kstrtoull(field[2], 0, &dev->dmi.dev) || 216 + dev->dmi.dev >= (1 << MINORBITS)) 216 217 return ERR_PTR(-EINVAL); 218 + dev->dmi.dev = huge_encode_dev((dev_t)dev->dmi.dev); 217 219 dev->dmi.flags |= DM_PERSISTENT_DEV_FLAG; 218 220 } 219 221 /* flags */
+361 -47
drivers/md/dm-integrity.c
··· 44 44 #define BITMAP_FLUSH_INTERVAL (10 * HZ) 45 45 #define DISCARD_FILLER 0xf6 46 46 #define SALT_SIZE 16 47 + #define RECHECK_POOL_SIZE 256 47 48 48 49 /* 49 50 * Warning - DEBUG_PRINT prints security-sensitive data to the log, ··· 63 62 #define SB_VERSION_3 3 64 63 #define SB_VERSION_4 4 65 64 #define SB_VERSION_5 5 65 + #define SB_VERSION_6 6 66 66 #define SB_SECTORS 8 67 67 #define MAX_SECTORS_PER_BLOCK 8 68 68 ··· 88 86 #define SB_FLAG_DIRTY_BITMAP 0x4 89 87 #define SB_FLAG_FIXED_PADDING 0x8 90 88 #define SB_FLAG_FIXED_HMAC 0x10 89 + #define SB_FLAG_INLINE 0x20 91 90 92 91 #define JOURNAL_ENTRY_ROUNDUP 8 93 92 ··· 169 166 struct dm_dev *meta_dev; 170 167 unsigned int tag_size; 171 168 __s8 log2_tag_size; 169 + unsigned int tuple_size; 172 170 sector_t start; 173 171 mempool_t journal_io_mempool; 174 172 struct dm_io_client *io; ··· 283 279 atomic64_t number_of_mismatches; 284 280 285 281 mempool_t recheck_pool; 282 + struct bio_set recheck_bios; 286 283 287 284 struct notifier_block reboot_notifier; 288 285 }; ··· 319 314 struct completion *completion; 320 315 321 316 struct dm_bio_details bio_details; 317 + 318 + char *integrity_payload; 319 + bool integrity_payload_from_mempool; 322 320 }; 323 321 324 322 struct journal_completion { ··· 359 351 #endif 360 352 361 353 static void dm_integrity_map_continue(struct dm_integrity_io *dio, bool from_map); 354 + static int dm_integrity_map_inline(struct dm_integrity_io *dio); 362 355 static void integrity_bio_wait(struct work_struct *w); 363 356 static void dm_integrity_dtr(struct dm_target *ti); 364 357 ··· 469 460 470 461 static void sb_set_version(struct dm_integrity_c *ic) 471 462 { 472 - if (ic->sb->flags & cpu_to_le32(SB_FLAG_FIXED_HMAC)) 463 + if (ic->sb->flags & cpu_to_le32(SB_FLAG_INLINE)) 464 + ic->sb->version = SB_VERSION_6; 465 + else if (ic->sb->flags & cpu_to_le32(SB_FLAG_FIXED_HMAC)) 473 466 ic->sb->version = SB_VERSION_5; 474 467 else if (ic->sb->flags & cpu_to_le32(SB_FLAG_FIXED_PADDING)) 475 468 ic->sb->version = SB_VERSION_4; ··· 1905 1894 dec_in_flight(dio); 1906 1895 } 1907 1896 1897 + static inline bool dm_integrity_check_limits(struct dm_integrity_c *ic, sector_t logical_sector, struct bio *bio) 1898 + { 1899 + if (unlikely(logical_sector + bio_sectors(bio) > ic->provided_data_sectors)) { 1900 + DMERR("Too big sector number: 0x%llx + 0x%x > 0x%llx", 1901 + logical_sector, bio_sectors(bio), 1902 + ic->provided_data_sectors); 1903 + return false; 1904 + } 1905 + if (unlikely((logical_sector | bio_sectors(bio)) & (unsigned int)(ic->sectors_per_block - 1))) { 1906 + DMERR("Bio not aligned on %u sectors: 0x%llx, 0x%x", 1907 + ic->sectors_per_block, 1908 + logical_sector, bio_sectors(bio)); 1909 + return false; 1910 + } 1911 + if (ic->sectors_per_block > 1 && likely(bio_op(bio) != REQ_OP_DISCARD)) { 1912 + struct bvec_iter iter; 1913 + struct bio_vec bv; 1914 + 1915 + bio_for_each_segment(bv, bio, iter) { 1916 + if (unlikely(bv.bv_len & ((ic->sectors_per_block << SECTOR_SHIFT) - 1))) { 1917 + DMERR("Bio vector (%u,%u) is not aligned on %u-sector boundary", 1918 + bv.bv_offset, bv.bv_len, ic->sectors_per_block); 1919 + return false; 1920 + } 1921 + } 1922 + } 1923 + return true; 1924 + } 1925 + 1908 1926 static int dm_integrity_map(struct dm_target *ti, struct bio *bio) 1909 1927 { 1910 1928 struct dm_integrity_c *ic = ti->private; ··· 1945 1905 dio->ic = ic; 1946 1906 dio->bi_status = 0; 1947 1907 dio->op = bio_op(bio); 1908 + 1909 + if (ic->mode == 'I') 1910 + return dm_integrity_map_inline(dio); 1948 1911 1949 1912 if (unlikely(dio->op == REQ_OP_DISCARD)) { 1950 1913 if (ti->max_io_len) { ··· 1978 1935 */ 1979 1936 bio->bi_opf &= ~REQ_FUA; 1980 1937 } 1981 - if (unlikely(dio->range.logical_sector + bio_sectors(bio) > ic->provided_data_sectors)) { 1982 - DMERR("Too big sector number: 0x%llx + 0x%x > 0x%llx", 1983 - dio->range.logical_sector, bio_sectors(bio), 1984 - ic->provided_data_sectors); 1938 + if (unlikely(!dm_integrity_check_limits(ic, dio->range.logical_sector, bio))) 1985 1939 return DM_MAPIO_KILL; 1986 - } 1987 - if (unlikely((dio->range.logical_sector | bio_sectors(bio)) & (unsigned int)(ic->sectors_per_block - 1))) { 1988 - DMERR("Bio not aligned on %u sectors: 0x%llx, 0x%x", 1989 - ic->sectors_per_block, 1990 - dio->range.logical_sector, bio_sectors(bio)); 1991 - return DM_MAPIO_KILL; 1992 - } 1993 - 1994 - if (ic->sectors_per_block > 1 && likely(dio->op != REQ_OP_DISCARD)) { 1995 - struct bvec_iter iter; 1996 - struct bio_vec bv; 1997 - 1998 - bio_for_each_segment(bv, bio, iter) { 1999 - if (unlikely(bv.bv_len & ((ic->sectors_per_block << SECTOR_SHIFT) - 1))) { 2000 - DMERR("Bio vector (%u,%u) is not aligned on %u-sector boundary", 2001 - bv.bv_offset, bv.bv_len, ic->sectors_per_block); 2002 - return DM_MAPIO_KILL; 2003 - } 2004 - } 2005 - } 2006 1940 2007 1941 bip = bio_integrity(bio); 2008 1942 if (!ic->internal_hash) { ··· 2395 2375 do_endio_flush(ic, dio); 2396 2376 } 2397 2377 2378 + static int dm_integrity_map_inline(struct dm_integrity_io *dio) 2379 + { 2380 + struct dm_integrity_c *ic = dio->ic; 2381 + struct bio *bio = dm_bio_from_per_bio_data(dio, sizeof(struct dm_integrity_io)); 2382 + struct bio_integrity_payload *bip; 2383 + unsigned payload_len, digest_size, extra_size, ret; 2384 + 2385 + dio->integrity_payload = NULL; 2386 + dio->integrity_payload_from_mempool = false; 2387 + 2388 + if (unlikely(bio_integrity(bio))) { 2389 + bio->bi_status = BLK_STS_NOTSUPP; 2390 + bio_endio(bio); 2391 + return DM_MAPIO_SUBMITTED; 2392 + } 2393 + 2394 + bio_set_dev(bio, ic->dev->bdev); 2395 + if (unlikely((bio->bi_opf & REQ_PREFLUSH) != 0)) 2396 + return DM_MAPIO_REMAPPED; 2397 + 2398 + retry: 2399 + payload_len = ic->tuple_size * (bio_sectors(bio) >> ic->sb->log2_sectors_per_block); 2400 + digest_size = crypto_shash_digestsize(ic->internal_hash); 2401 + extra_size = unlikely(digest_size > ic->tag_size) ? digest_size - ic->tag_size : 0; 2402 + payload_len += extra_size; 2403 + dio->integrity_payload = kmalloc(payload_len, GFP_NOIO | __GFP_NORETRY | __GFP_NOMEMALLOC | __GFP_NOWARN); 2404 + if (unlikely(!dio->integrity_payload)) { 2405 + const unsigned x_size = PAGE_SIZE << 1; 2406 + if (payload_len > x_size) { 2407 + unsigned sectors = ((x_size - extra_size) / ic->tuple_size) << ic->sb->log2_sectors_per_block; 2408 + if (WARN_ON(!sectors || sectors >= bio_sectors(bio))) { 2409 + bio->bi_status = BLK_STS_NOTSUPP; 2410 + bio_endio(bio); 2411 + return DM_MAPIO_SUBMITTED; 2412 + } 2413 + dm_accept_partial_bio(bio, sectors); 2414 + goto retry; 2415 + } 2416 + dio->integrity_payload = page_to_virt((struct page *)mempool_alloc(&ic->recheck_pool, GFP_NOIO)); 2417 + dio->integrity_payload_from_mempool = true; 2418 + } 2419 + 2420 + bio->bi_iter.bi_sector = dm_target_offset(ic->ti, bio->bi_iter.bi_sector); 2421 + dio->bio_details.bi_iter = bio->bi_iter; 2422 + 2423 + if (unlikely(!dm_integrity_check_limits(ic, bio->bi_iter.bi_sector, bio))) { 2424 + return DM_MAPIO_KILL; 2425 + } 2426 + 2427 + bio->bi_iter.bi_sector += ic->start + SB_SECTORS; 2428 + 2429 + bip = bio_integrity_alloc(bio, GFP_NOIO, 1); 2430 + if (unlikely(IS_ERR(bip))) { 2431 + bio->bi_status = errno_to_blk_status(PTR_ERR(bip)); 2432 + bio_endio(bio); 2433 + return DM_MAPIO_SUBMITTED; 2434 + } 2435 + 2436 + if (dio->op == REQ_OP_WRITE) { 2437 + unsigned pos = 0; 2438 + while (dio->bio_details.bi_iter.bi_size) { 2439 + struct bio_vec bv = bio_iter_iovec(bio, dio->bio_details.bi_iter); 2440 + const char *mem = bvec_kmap_local(&bv); 2441 + if (ic->tag_size < ic->tuple_size) 2442 + memset(dio->integrity_payload + pos + ic->tag_size, 0, ic->tuple_size - ic->tuple_size); 2443 + integrity_sector_checksum(ic, dio->bio_details.bi_iter.bi_sector, mem, dio->integrity_payload + pos); 2444 + kunmap_local(mem); 2445 + pos += ic->tuple_size; 2446 + bio_advance_iter_single(bio, &dio->bio_details.bi_iter, ic->sectors_per_block << SECTOR_SHIFT); 2447 + } 2448 + } 2449 + 2450 + ret = bio_integrity_add_page(bio, virt_to_page(dio->integrity_payload), 2451 + payload_len, offset_in_page(dio->integrity_payload)); 2452 + if (unlikely(ret != payload_len)) { 2453 + bio->bi_status = BLK_STS_RESOURCE; 2454 + bio_endio(bio); 2455 + return DM_MAPIO_SUBMITTED; 2456 + } 2457 + 2458 + return DM_MAPIO_REMAPPED; 2459 + } 2460 + 2461 + static inline void dm_integrity_free_payload(struct dm_integrity_io *dio) 2462 + { 2463 + struct dm_integrity_c *ic = dio->ic; 2464 + if (unlikely(dio->integrity_payload_from_mempool)) 2465 + mempool_free(virt_to_page(dio->integrity_payload), &ic->recheck_pool); 2466 + else 2467 + kfree(dio->integrity_payload); 2468 + dio->integrity_payload = NULL; 2469 + dio->integrity_payload_from_mempool = false; 2470 + } 2471 + 2472 + static void dm_integrity_inline_recheck(struct work_struct *w) 2473 + { 2474 + struct dm_integrity_io *dio = container_of(w, struct dm_integrity_io, work); 2475 + struct bio *bio = dm_bio_from_per_bio_data(dio, sizeof(struct dm_integrity_io)); 2476 + struct dm_integrity_c *ic = dio->ic; 2477 + struct bio *outgoing_bio; 2478 + void *outgoing_data; 2479 + 2480 + dio->integrity_payload = page_to_virt((struct page *)mempool_alloc(&ic->recheck_pool, GFP_NOIO)); 2481 + dio->integrity_payload_from_mempool = true; 2482 + 2483 + outgoing_data = dio->integrity_payload + PAGE_SIZE; 2484 + 2485 + while (dio->bio_details.bi_iter.bi_size) { 2486 + char digest[HASH_MAX_DIGESTSIZE]; 2487 + int r; 2488 + struct bio_integrity_payload *bip; 2489 + struct bio_vec bv; 2490 + char *mem; 2491 + 2492 + outgoing_bio = bio_alloc_bioset(ic->dev->bdev, 1, REQ_OP_READ, GFP_NOIO, &ic->recheck_bios); 2493 + 2494 + r = bio_add_page(outgoing_bio, virt_to_page(outgoing_data), ic->sectors_per_block << SECTOR_SHIFT, 0); 2495 + if (unlikely(r != (ic->sectors_per_block << SECTOR_SHIFT))) { 2496 + bio_put(outgoing_bio); 2497 + bio->bi_status = BLK_STS_RESOURCE; 2498 + bio_endio(bio); 2499 + return; 2500 + } 2501 + 2502 + bip = bio_integrity_alloc(outgoing_bio, GFP_NOIO, 1); 2503 + if (unlikely(IS_ERR(bip))) { 2504 + bio_put(outgoing_bio); 2505 + bio->bi_status = errno_to_blk_status(PTR_ERR(bip)); 2506 + bio_endio(bio); 2507 + return; 2508 + } 2509 + 2510 + r = bio_integrity_add_page(outgoing_bio, virt_to_page(dio->integrity_payload), ic->tuple_size, 0); 2511 + if (unlikely(r != ic->tuple_size)) { 2512 + bio_put(outgoing_bio); 2513 + bio->bi_status = BLK_STS_RESOURCE; 2514 + bio_endio(bio); 2515 + return; 2516 + } 2517 + 2518 + outgoing_bio->bi_iter.bi_sector = dio->bio_details.bi_iter.bi_sector + ic->start + SB_SECTORS; 2519 + 2520 + r = submit_bio_wait(outgoing_bio); 2521 + if (unlikely(r != 0)) { 2522 + bio_put(outgoing_bio); 2523 + bio->bi_status = errno_to_blk_status(r); 2524 + bio_endio(bio); 2525 + return; 2526 + } 2527 + bio_put(outgoing_bio); 2528 + 2529 + integrity_sector_checksum(ic, dio->bio_details.bi_iter.bi_sector, outgoing_data, digest); 2530 + if (unlikely(memcmp(digest, dio->integrity_payload, min(crypto_shash_digestsize(ic->internal_hash), ic->tag_size)))) { 2531 + DMERR_LIMIT("%pg: Checksum failed at sector 0x%llx", 2532 + ic->dev->bdev, dio->bio_details.bi_iter.bi_sector); 2533 + atomic64_inc(&ic->number_of_mismatches); 2534 + dm_audit_log_bio(DM_MSG_PREFIX, "integrity-checksum", 2535 + bio, dio->bio_details.bi_iter.bi_sector, 0); 2536 + 2537 + bio->bi_status = BLK_STS_PROTECTION; 2538 + bio_endio(bio); 2539 + return; 2540 + } 2541 + 2542 + bv = bio_iter_iovec(bio, dio->bio_details.bi_iter); 2543 + mem = bvec_kmap_local(&bv); 2544 + memcpy(mem, outgoing_data, ic->sectors_per_block << SECTOR_SHIFT); 2545 + kunmap_local(mem); 2546 + 2547 + bio_advance_iter_single(bio, &dio->bio_details.bi_iter, ic->sectors_per_block << SECTOR_SHIFT); 2548 + } 2549 + 2550 + bio_endio(bio); 2551 + } 2552 + 2553 + static int dm_integrity_end_io(struct dm_target *ti, struct bio *bio, blk_status_t *status) 2554 + { 2555 + struct dm_integrity_c *ic = ti->private; 2556 + if (ic->mode == 'I') { 2557 + struct dm_integrity_io *dio = dm_per_bio_data(bio, sizeof(struct dm_integrity_io)); 2558 + if (dio->op == REQ_OP_READ && likely(*status == BLK_STS_OK)) { 2559 + unsigned pos = 0; 2560 + while (dio->bio_details.bi_iter.bi_size) { 2561 + char digest[HASH_MAX_DIGESTSIZE]; 2562 + struct bio_vec bv = bio_iter_iovec(bio, dio->bio_details.bi_iter); 2563 + char *mem = bvec_kmap_local(&bv); 2564 + //memset(mem, 0xff, ic->sectors_per_block << SECTOR_SHIFT); 2565 + integrity_sector_checksum(ic, dio->bio_details.bi_iter.bi_sector, mem, digest); 2566 + if (unlikely(memcmp(digest, dio->integrity_payload + pos, 2567 + min(crypto_shash_digestsize(ic->internal_hash), ic->tag_size)))) { 2568 + kunmap_local(mem); 2569 + dm_integrity_free_payload(dio); 2570 + INIT_WORK(&dio->work, dm_integrity_inline_recheck); 2571 + queue_work(ic->offload_wq, &dio->work); 2572 + return DM_ENDIO_INCOMPLETE; 2573 + } 2574 + kunmap_local(mem); 2575 + pos += ic->tuple_size; 2576 + bio_advance_iter_single(bio, &dio->bio_details.bi_iter, ic->sectors_per_block << SECTOR_SHIFT); 2577 + } 2578 + } 2579 + if (likely(dio->op == REQ_OP_READ) || likely(dio->op == REQ_OP_WRITE)) { 2580 + dm_integrity_free_payload(dio); 2581 + } 2582 + } 2583 + return DM_ENDIO_DONE; 2584 + } 2398 2585 2399 2586 static void integrity_bio_wait(struct work_struct *w) 2400 2587 { ··· 2639 2412 struct bio *flushes; 2640 2413 2641 2414 del_timer(&ic->autocommit_timer); 2415 + 2416 + if (ic->mode == 'I') 2417 + return; 2642 2418 2643 2419 spin_lock_irq(&ic->endio_wait.lock); 2644 2420 flushes = bio_list_get(&ic->flush_bio_list); ··· 3701 3471 if (ic->sectors_per_block > 1) { 3702 3472 limits->logical_block_size = ic->sectors_per_block << SECTOR_SHIFT; 3703 3473 limits->physical_block_size = ic->sectors_per_block << SECTOR_SHIFT; 3704 - blk_limits_io_min(limits, ic->sectors_per_block << SECTOR_SHIFT); 3474 + limits->io_min = ic->sectors_per_block << SECTOR_SHIFT; 3705 3475 limits->dma_alignment = limits->logical_block_size - 1; 3706 3476 limits->discard_granularity = ic->sectors_per_block << SECTOR_SHIFT; 3707 3477 } ··· 3745 3515 return -EINVAL; 3746 3516 ic->initial_sectors = initial_sectors; 3747 3517 3748 - if (!ic->meta_dev) { 3518 + if (ic->mode == 'I') { 3519 + if (ic->initial_sectors + ic->provided_data_sectors > ic->meta_device_sectors) 3520 + return -EINVAL; 3521 + } else if (!ic->meta_dev) { 3749 3522 sector_t last_sector, last_area, last_offset; 3750 3523 3751 3524 /* we have to maintain excessive padding for compatibility with existing volumes */ ··· 3811 3578 3812 3579 memset(ic->sb, 0, SB_SECTORS << SECTOR_SHIFT); 3813 3580 memcpy(ic->sb->magic, SB_MAGIC, 8); 3581 + if (ic->mode == 'I') 3582 + ic->sb->flags |= cpu_to_le32(SB_FLAG_INLINE); 3814 3583 ic->sb->integrity_tag_size = cpu_to_le16(ic->tag_size); 3815 3584 ic->sb->log2_sectors_per_block = __ffs(ic->sectors_per_block); 3816 3585 if (ic->journal_mac_alg.alg_string) ··· 3822 3587 journal_sections = journal_sectors / ic->journal_section_sectors; 3823 3588 if (!journal_sections) 3824 3589 journal_sections = 1; 3590 + if (ic->mode == 'I') 3591 + journal_sections = 0; 3825 3592 3826 3593 if (ic->fix_hmac && (ic->internal_hash_alg.alg_string || ic->journal_mac_alg.alg_string)) { 3827 3594 ic->sb->flags |= cpu_to_le32(SB_FLAG_FIXED_HMAC); ··· 4372 4135 } 4373 4136 4374 4137 if (!strcmp(argv[3], "J") || !strcmp(argv[3], "B") || 4375 - !strcmp(argv[3], "D") || !strcmp(argv[3], "R")) { 4138 + !strcmp(argv[3], "D") || !strcmp(argv[3], "R") || 4139 + !strcmp(argv[3], "I")) { 4376 4140 ic->mode = argv[3][0]; 4377 4141 } else { 4378 - ti->error = "Invalid mode (expecting J, B, D, R)"; 4142 + ti->error = "Invalid mode (expecting J, B, D, R, I)"; 4379 4143 r = -EINVAL; 4380 4144 goto bad; 4381 4145 } ··· 4522 4284 else 4523 4285 ic->log2_tag_size = -1; 4524 4286 4287 + if (ic->mode == 'I') { 4288 + struct blk_integrity *bi; 4289 + if (ic->meta_dev) { 4290 + r = -EINVAL; 4291 + ti->error = "Metadata device not supported in inline mode"; 4292 + goto bad; 4293 + } 4294 + if (!ic->internal_hash_alg.alg_string) { 4295 + r = -EINVAL; 4296 + ti->error = "Internal hash not set in inline mode"; 4297 + goto bad; 4298 + } 4299 + if (ic->journal_crypt_alg.alg_string || ic->journal_mac_alg.alg_string) { 4300 + r = -EINVAL; 4301 + ti->error = "Journal crypt not supported in inline mode"; 4302 + goto bad; 4303 + } 4304 + if (ic->discard) { 4305 + r = -EINVAL; 4306 + ti->error = "Discards not supported in inline mode"; 4307 + goto bad; 4308 + } 4309 + bi = blk_get_integrity(ic->dev->bdev->bd_disk); 4310 + if (!bi || bi->csum_type != BLK_INTEGRITY_CSUM_NONE) { 4311 + r = -EINVAL; 4312 + ti->error = "Integrity profile not supported"; 4313 + goto bad; 4314 + } 4315 + /*printk("tag_size: %u, tuple_size: %u\n", bi->tag_size, bi->tuple_size);*/ 4316 + if (bi->tuple_size < ic->tag_size) { 4317 + r = -EINVAL; 4318 + ti->error = "The integrity profile is smaller than tag size"; 4319 + goto bad; 4320 + } 4321 + if ((unsigned long)bi->tuple_size > PAGE_SIZE / 2) { 4322 + r = -EINVAL; 4323 + ti->error = "Too big tuple size"; 4324 + goto bad; 4325 + } 4326 + ic->tuple_size = bi->tuple_size; 4327 + if (1 << bi->interval_exp != ic->sectors_per_block << SECTOR_SHIFT) { 4328 + r = -EINVAL; 4329 + ti->error = "Integrity profile sector size mismatch"; 4330 + goto bad; 4331 + } 4332 + } 4333 + 4525 4334 if (ic->mode == 'B' && !ic->internal_hash) { 4526 4335 r = -EINVAL; 4527 4336 ti->error = "Bitmap mode can be only used with internal hash"; ··· 4599 4314 goto bad; 4600 4315 } 4601 4316 4602 - r = mempool_init_page_pool(&ic->recheck_pool, 1, 0); 4317 + r = mempool_init_page_pool(&ic->recheck_pool, 1, ic->mode == 'I' ? 1 : 0); 4603 4318 if (r) { 4604 4319 ti->error = "Cannot allocate mempool"; 4605 4320 goto bad; 4321 + } 4322 + 4323 + if (ic->mode == 'I') { 4324 + r = bioset_init(&ic->recheck_bios, RECHECK_POOL_SIZE, 0, BIOSET_NEED_BVECS); 4325 + if (r) { 4326 + ti->error = "Cannot allocate bio set"; 4327 + goto bad; 4328 + } 4329 + r = bioset_integrity_create(&ic->recheck_bios, RECHECK_POOL_SIZE); 4330 + if (r) { 4331 + ti->error = "Cannot allocate bio integrity set"; 4332 + r = -ENOMEM; 4333 + goto bad; 4334 + } 4606 4335 } 4607 4336 4608 4337 ic->metadata_wq = alloc_workqueue("dm-integrity-metadata", ··· 4695 4396 should_write_sb = true; 4696 4397 } 4697 4398 4698 - if (!ic->sb->version || ic->sb->version > SB_VERSION_5) { 4399 + if (!ic->sb->version || ic->sb->version > SB_VERSION_6) { 4699 4400 r = -EINVAL; 4700 4401 ti->error = "Unknown version"; 4402 + goto bad; 4403 + } 4404 + if (!!(ic->sb->flags & cpu_to_le32(SB_FLAG_INLINE)) != (ic->mode == 'I')) { 4405 + r = -EINVAL; 4406 + ti->error = "Inline flag mismatch"; 4701 4407 goto bad; 4702 4408 } 4703 4409 if (le16_to_cpu(ic->sb->integrity_tag_size) != ic->tag_size) { ··· 4715 4411 ti->error = "Block size doesn't match the information in superblock"; 4716 4412 goto bad; 4717 4413 } 4718 - if (!le32_to_cpu(ic->sb->journal_sections)) { 4414 + if (!le32_to_cpu(ic->sb->journal_sections) != (ic->mode == 'I')) { 4719 4415 r = -EINVAL; 4720 - ti->error = "Corrupted superblock, journal_sections is 0"; 4416 + if (ic->mode != 'I') 4417 + ti->error = "Corrupted superblock, journal_sections is 0"; 4418 + else 4419 + ti->error = "Corrupted superblock, journal_sections is not 0"; 4721 4420 goto bad; 4722 4421 } 4723 4422 /* make sure that ti->max_io_len doesn't overflow */ ··· 4772 4465 bits_in_journal = ((__u64)ic->journal_section_sectors * ic->journal_sections) << (SECTOR_SHIFT + 3); 4773 4466 if (bits_in_journal > UINT_MAX) 4774 4467 bits_in_journal = UINT_MAX; 4775 - while (bits_in_journal < (ic->provided_data_sectors + ((sector_t)1 << log2_sectors_per_bitmap_bit) - 1) >> log2_sectors_per_bitmap_bit) 4776 - log2_sectors_per_bitmap_bit++; 4468 + if (bits_in_journal) 4469 + while (bits_in_journal < (ic->provided_data_sectors + ((sector_t)1 << log2_sectors_per_bitmap_bit) - 1) >> log2_sectors_per_bitmap_bit) 4470 + log2_sectors_per_bitmap_bit++; 4777 4471 4778 4472 log2_blocks_per_bitmap_bit = log2_sectors_per_bitmap_bit - ic->sb->log2_sectors_per_block; 4779 4473 ic->log2_blocks_per_bitmap_bit = log2_blocks_per_bitmap_bit; ··· 4793 4485 ti->error = "Not enough provided sectors for requested mapping size"; 4794 4486 goto bad; 4795 4487 } 4796 - 4797 4488 4798 4489 threshold = (__u64)ic->journal_entries * (100 - journal_watermark); 4799 4490 threshold += 50; ··· 4845 4538 goto bad; 4846 4539 } 4847 4540 4848 - ic->bufio = dm_bufio_client_create(ic->meta_dev ? ic->meta_dev->bdev : ic->dev->bdev, 4849 - 1U << (SECTOR_SHIFT + ic->log2_buffer_sectors), 1, 0, NULL, NULL, 0); 4850 - if (IS_ERR(ic->bufio)) { 4851 - r = PTR_ERR(ic->bufio); 4852 - ti->error = "Cannot initialize dm-bufio"; 4853 - ic->bufio = NULL; 4854 - goto bad; 4541 + if (ic->mode != 'I') { 4542 + ic->bufio = dm_bufio_client_create(ic->meta_dev ? ic->meta_dev->bdev : ic->dev->bdev, 4543 + 1U << (SECTOR_SHIFT + ic->log2_buffer_sectors), 1, 0, NULL, NULL, 0); 4544 + if (IS_ERR(ic->bufio)) { 4545 + r = PTR_ERR(ic->bufio); 4546 + ti->error = "Cannot initialize dm-bufio"; 4547 + ic->bufio = NULL; 4548 + goto bad; 4549 + } 4550 + dm_bufio_set_sector_offset(ic->bufio, ic->start + ic->initial_sectors); 4855 4551 } 4856 - dm_bufio_set_sector_offset(ic->bufio, ic->start + ic->initial_sectors); 4857 4552 4858 - if (ic->mode != 'R') { 4553 + if (ic->mode != 'R' && ic->mode != 'I') { 4859 4554 r = create_journal(ic, &ti->error); 4860 4555 if (r) 4861 4556 goto bad; ··· 4917 4608 ic->just_formatted = true; 4918 4609 } 4919 4610 4920 - if (!ic->meta_dev) { 4611 + if (!ic->meta_dev && ic->mode != 'I') { 4921 4612 r = dm_set_target_max_io_len(ti, 1U << ic->sb->log2_interleave_sectors); 4922 4613 if (r) 4923 4614 goto bad; ··· 4940 4631 ti->flush_supported = true; 4941 4632 if (ic->discard) 4942 4633 ti->num_discard_bios = 1; 4634 + 4635 + if (ic->mode == 'I') 4636 + ti->mempool_needs_integrity = true; 4943 4637 4944 4638 dm_audit_log_ctr(DM_MSG_PREFIX, ti, 1); 4945 4639 return 0; ··· 4977 4665 kvfree(ic->bbs); 4978 4666 if (ic->bufio) 4979 4667 dm_bufio_client_destroy(ic->bufio); 4668 + bioset_exit(&ic->recheck_bios); 4980 4669 mempool_exit(&ic->recheck_pool); 4981 4670 mempool_exit(&ic->journal_io_mempool); 4982 4671 if (ic->io) ··· 5031 4718 5032 4719 static struct target_type integrity_target = { 5033 4720 .name = "integrity", 5034 - .version = {1, 11, 0}, 4721 + .version = {1, 12, 0}, 5035 4722 .module = THIS_MODULE, 5036 4723 .features = DM_TARGET_SINGLETON | DM_TARGET_INTEGRITY, 5037 4724 .ctr = dm_integrity_ctr, 5038 4725 .dtr = dm_integrity_dtr, 5039 4726 .map = dm_integrity_map, 4727 + .end_io = dm_integrity_end_io, 5040 4728 .postsuspend = dm_integrity_postsuspend, 5041 4729 .resume = dm_integrity_resume, 5042 4730 .status = dm_integrity_status,
+32 -52
drivers/md/dm-io.c
··· 347 347 break; 348 348 default: 349 349 num_bvecs = bio_max_segs(dm_sector_div_up(remaining, 350 - (PAGE_SIZE >> SECTOR_SHIFT))); 350 + (PAGE_SIZE >> SECTOR_SHIFT)) + 1); 351 351 } 352 352 353 353 bio = bio_alloc_bioset(where->bdev, num_bvecs, opf, GFP_NOIO, ··· 384 384 385 385 static void dispatch_io(blk_opf_t opf, unsigned int num_regions, 386 386 struct dm_io_region *where, struct dpages *dp, 387 - struct io *io, int sync, unsigned short ioprio) 387 + struct io *io, unsigned short ioprio) 388 388 { 389 389 int i; 390 390 struct dpages old_pages = *dp; 391 391 392 392 BUG_ON(num_regions > DM_IO_MAX_REGIONS); 393 - 394 - if (sync) 395 - opf |= REQ_SYNC; 396 393 397 394 /* 398 395 * For multiple regions we need to be careful to rewind ··· 406 409 * the io being completed too early. 407 410 */ 408 411 dec_count(io, 0, 0); 412 + } 413 + 414 + static void async_io(struct dm_io_client *client, unsigned int num_regions, 415 + struct dm_io_region *where, blk_opf_t opf, 416 + struct dpages *dp, io_notify_fn fn, void *context, 417 + unsigned short ioprio) 418 + { 419 + struct io *io; 420 + 421 + io = mempool_alloc(&client->pool, GFP_NOIO); 422 + io->error_bits = 0; 423 + atomic_set(&io->count, 1); /* see dispatch_io() */ 424 + io->client = client; 425 + io->callback = fn; 426 + io->context = context; 427 + 428 + io->vma_invalidate_address = dp->vma_invalidate_address; 429 + io->vma_invalidate_size = dp->vma_invalidate_size; 430 + 431 + dispatch_io(opf, num_regions, where, dp, io, ioprio); 409 432 } 410 433 411 434 struct sync_io { ··· 445 428 struct dm_io_region *where, blk_opf_t opf, struct dpages *dp, 446 429 unsigned long *error_bits, unsigned short ioprio) 447 430 { 448 - struct io *io; 449 431 struct sync_io sio; 450 - 451 - if (num_regions > 1 && !op_is_write(opf)) { 452 - WARN_ON(1); 453 - return -EIO; 454 - } 455 432 456 433 init_completion(&sio.wait); 457 434 458 - io = mempool_alloc(&client->pool, GFP_NOIO); 459 - io->error_bits = 0; 460 - atomic_set(&io->count, 1); /* see dispatch_io() */ 461 - io->client = client; 462 - io->callback = sync_io_complete; 463 - io->context = &sio; 464 - 465 - io->vma_invalidate_address = dp->vma_invalidate_address; 466 - io->vma_invalidate_size = dp->vma_invalidate_size; 467 - 468 - dispatch_io(opf, num_regions, where, dp, io, 1, ioprio); 435 + async_io(client, num_regions, where, opf | REQ_SYNC, dp, 436 + sync_io_complete, &sio, ioprio); 469 437 470 438 wait_for_completion_io(&sio.wait); 471 439 ··· 458 456 *error_bits = sio.error_bits; 459 457 460 458 return sio.error_bits ? -EIO : 0; 461 - } 462 - 463 - static int async_io(struct dm_io_client *client, unsigned int num_regions, 464 - struct dm_io_region *where, blk_opf_t opf, 465 - struct dpages *dp, io_notify_fn fn, void *context, 466 - unsigned short ioprio) 467 - { 468 - struct io *io; 469 - 470 - if (num_regions > 1 && !op_is_write(opf)) { 471 - WARN_ON(1); 472 - fn(1, context); 473 - return -EIO; 474 - } 475 - 476 - io = mempool_alloc(&client->pool, GFP_NOIO); 477 - io->error_bits = 0; 478 - atomic_set(&io->count, 1); /* see dispatch_io() */ 479 - io->client = client; 480 - io->callback = fn; 481 - io->context = context; 482 - 483 - io->vma_invalidate_address = dp->vma_invalidate_address; 484 - io->vma_invalidate_size = dp->vma_invalidate_size; 485 - 486 - dispatch_io(opf, num_regions, where, dp, io, 0, ioprio); 487 - return 0; 488 459 } 489 460 490 461 static int dp_init(struct dm_io_request *io_req, struct dpages *dp, ··· 504 529 int r; 505 530 struct dpages dp; 506 531 532 + if (num_regions > 1 && !op_is_write(io_req->bi_opf)) { 533 + WARN_ON(1); 534 + return -EIO; 535 + } 536 + 507 537 r = dp_init(io_req, &dp, (unsigned long)where->count << SECTOR_SHIFT); 508 538 if (r) 509 539 return r; ··· 517 537 return sync_io(io_req->client, num_regions, where, 518 538 io_req->bi_opf, &dp, sync_error_bits, ioprio); 519 539 520 - return async_io(io_req->client, num_regions, where, 521 - io_req->bi_opf, &dp, io_req->notify.fn, 522 - io_req->notify.context, ioprio); 540 + async_io(io_req->client, num_regions, where, io_req->bi_opf, &dp, 541 + io_req->notify.fn, io_req->notify.context, ioprio); 542 + return 0; 523 543 } 524 544 EXPORT_SYMBOL(dm_io); 525 545
+1
drivers/md/dm-linear.c
··· 62 62 ti->num_discard_bios = 1; 63 63 ti->num_secure_erase_bios = 1; 64 64 ti->num_write_zeroes_bios = 1; 65 + ti->flush_bypasses_map = true; 65 66 ti->private = lc; 66 67 return 0; 67 68
+4 -7
drivers/md/dm-mpath.c
··· 1419 1419 /* 1420 1420 * Fail or reinstate all paths that match the provided struct dm_dev. 1421 1421 */ 1422 - static int action_dev(struct multipath *m, struct dm_dev *dev, 1423 - action_fn action) 1422 + static int action_dev(struct multipath *m, dev_t dev, action_fn action) 1424 1423 { 1425 1424 int r = -EINVAL; 1426 1425 struct pgpath *pgpath; ··· 1427 1428 1428 1429 list_for_each_entry(pg, &m->priority_groups, list) { 1429 1430 list_for_each_entry(pgpath, &pg->pgpaths, list) { 1430 - if (pgpath->path.dev == dev) 1431 + if (pgpath->path.dev->bdev->bd_dev == dev) 1431 1432 r = action(pgpath); 1432 1433 } 1433 1434 } ··· 1958 1959 char *result, unsigned int maxlen) 1959 1960 { 1960 1961 int r = -EINVAL; 1961 - struct dm_dev *dev; 1962 + dev_t dev; 1962 1963 struct multipath *m = ti->private; 1963 1964 action_fn action; 1964 1965 unsigned long flags; ··· 2007 2008 goto out; 2008 2009 } 2009 2010 2010 - r = dm_get_device(ti, argv[1], dm_table_get_mode(ti->table), &dev); 2011 + r = dm_devt_from_path(argv[1], &dev); 2011 2012 if (r) { 2012 2013 DMWARN("message: error getting device %s", 2013 2014 argv[1]); ··· 2015 2016 } 2016 2017 2017 2018 r = action_dev(m, dev, action); 2018 - 2019 - dm_put_device(ti, dev); 2020 2019 2021 2020 out: 2022 2021 mutex_unlock(&m->work_mutex);
+40 -25
drivers/md/dm-raid.c
··· 1626 1626 return 0; 1627 1627 } 1628 1628 1629 + /* Get reshape sectors from data_offsets or raid set */ 1630 + static sector_t _get_reshape_sectors(struct raid_set *rs) 1631 + { 1632 + struct md_rdev *rdev; 1633 + sector_t reshape_sectors = 0; 1634 + 1635 + rdev_for_each(rdev, &rs->md) 1636 + if (!test_bit(Journal, &rdev->flags)) { 1637 + reshape_sectors = (rdev->data_offset > rdev->new_data_offset) ? 1638 + rdev->data_offset - rdev->new_data_offset : 1639 + rdev->new_data_offset - rdev->data_offset; 1640 + break; 1641 + } 1642 + 1643 + return max(reshape_sectors, (sector_t) rs->data_offset); 1644 + } 1645 + 1629 1646 /* Calculate the sectors per device and per array used for @rs */ 1630 1647 static int rs_set_dev_and_array_sectors(struct raid_set *rs, sector_t sectors, bool use_mddev) 1631 1648 { ··· 1673 1656 if (sector_div(dev_sectors, data_stripes)) 1674 1657 goto bad; 1675 1658 1676 - array_sectors = (data_stripes + delta_disks) * dev_sectors; 1659 + array_sectors = (data_stripes + delta_disks) * (dev_sectors - _get_reshape_sectors(rs)); 1677 1660 if (sector_div(array_sectors, rs->raid10_copies)) 1678 1661 goto bad; 1679 1662 ··· 1682 1665 1683 1666 else 1684 1667 /* Striped layouts */ 1685 - array_sectors = (data_stripes + delta_disks) * dev_sectors; 1668 + array_sectors = (data_stripes + delta_disks) * (dev_sectors - _get_reshape_sectors(rs)); 1686 1669 1687 1670 mddev->array_sectors = array_sectors; 1688 1671 mddev->dev_sectors = dev_sectors; ··· 1721 1704 struct raid_set *rs = container_of(ws, struct raid_set, md.event_work); 1722 1705 1723 1706 smp_rmb(); /* Make sure we access most actual mddev properties */ 1724 - if (!rs_is_reshaping(rs)) { 1707 + 1708 + /* Only grow size resulting from added stripe(s) after reshape ended. */ 1709 + if (!rs_is_reshaping(rs) && 1710 + rs->array_sectors > rs->md.array_sectors && 1711 + !rs->md.delta_disks && 1712 + rs->md.raid_disks == rs->raid_disks) { 1713 + /* The raid10 personality doesn't provide proper device sizes -> correct. */ 1725 1714 if (rs_is_raid10(rs)) 1726 1715 rs_set_rdev_sectors(rs); 1716 + 1717 + rs->md.array_sectors = rs->array_sectors; 1727 1718 rs_set_capacity(rs); 1728 1719 } 1720 + 1729 1721 dm_table_event(rs->ti->table); 1730 1722 } 1731 1723 ··· 2837 2811 return 0; 2838 2812 } 2839 2813 2840 - /* Get reshape sectors from data_offsets or raid set */ 2841 - static sector_t _get_reshape_sectors(struct raid_set *rs) 2842 - { 2843 - struct md_rdev *rdev; 2844 - sector_t reshape_sectors = 0; 2845 - 2846 - rdev_for_each(rdev, &rs->md) 2847 - if (!test_bit(Journal, &rdev->flags)) { 2848 - reshape_sectors = (rdev->data_offset > rdev->new_data_offset) ? 2849 - rdev->data_offset - rdev->new_data_offset : 2850 - rdev->new_data_offset - rdev->data_offset; 2851 - break; 2852 - } 2853 - 2854 - return max(reshape_sectors, (sector_t) rs->data_offset); 2855 - } 2856 - 2857 2814 /* 2858 2815 * Reshape: 2859 2816 * - change raid layout ··· 3811 3802 struct raid_set *rs = ti->private; 3812 3803 unsigned int chunk_size_bytes = to_bytes(rs->md.chunk_sectors); 3813 3804 3814 - blk_limits_io_min(limits, chunk_size_bytes); 3815 - blk_limits_io_opt(limits, chunk_size_bytes * mddev_data_stripes(rs)); 3805 + limits->io_min = chunk_size_bytes; 3806 + limits->io_opt = chunk_size_bytes * mddev_data_stripes(rs); 3816 3807 } 3817 3808 3818 3809 static void raid_presuspend(struct dm_target *ti) ··· 4032 4023 if (test_and_set_bit(RT_FLAG_RS_PRERESUMED, &rs->runtime_flags)) 4033 4024 return 0; 4034 4025 4026 + /* If different and no explicit grow request, expose MD array size as of superblock. */ 4027 + if (!test_bit(RT_FLAG_RS_GROW, &rs->runtime_flags) && 4028 + rs->array_sectors != mddev->array_sectors) 4029 + rs_set_capacity(rs); 4030 + 4035 4031 /* 4036 4032 * The superblocks need to be updated on disk if the 4037 4033 * array is new or new devices got added (thus zeroed ··· 4115 4101 if (mddev->delta_disks < 0) 4116 4102 rs_set_capacity(rs); 4117 4103 4118 - WARN_ON_ONCE(!test_bit(MD_RECOVERY_FROZEN, &mddev->recovery)); 4119 - WARN_ON_ONCE(test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)); 4120 - clear_bit(RT_FLAG_RS_FROZEN, &rs->runtime_flags); 4121 4104 mddev_lock_nointr(mddev); 4105 + WARN_ON_ONCE(!test_bit(MD_RECOVERY_FROZEN, &mddev->recovery)); 4106 + WARN_ON_ONCE(rcu_dereference_protected(mddev->sync_thread, 4107 + lockdep_is_held(&mddev->reconfig_mutex))); 4108 + clear_bit(RT_FLAG_RS_FROZEN, &rs->runtime_flags); 4122 4109 mddev->ro = 0; 4123 4110 mddev->in_sync = 0; 4124 4111 md_unfrozen_sync_thread(mddev);
+3 -2
drivers/md/dm-stripe.c
··· 157 157 ti->num_discard_bios = stripes; 158 158 ti->num_secure_erase_bios = stripes; 159 159 ti->num_write_zeroes_bios = stripes; 160 + ti->flush_bypasses_map = true; 160 161 161 162 sc->chunk_size = chunk_size; 162 163 if (chunk_size & (chunk_size - 1)) ··· 459 458 struct stripe_c *sc = ti->private; 460 459 unsigned int chunk_size = sc->chunk_size << SECTOR_SHIFT; 461 460 462 - blk_limits_io_min(limits, chunk_size); 463 - blk_limits_io_opt(limits, chunk_size * sc->stripes); 461 + limits->io_min = chunk_size; 462 + limits->io_opt = chunk_size * sc->stripes; 464 463 } 465 464 466 465 static struct target_type stripe_target = {
+33 -11
drivers/md/dm-table.c
··· 160 160 t->type = DM_TYPE_NONE; 161 161 t->mode = mode; 162 162 t->md = md; 163 + t->flush_bypasses_map = true; 163 164 *result = t; 164 165 return 0; 165 166 } ··· 331 330 } 332 331 333 332 /* 334 - * Add a device to the list, or just increment the usage count if 335 - * it's already present. 336 - * 337 333 * Note: the __ref annotation is because this function can call the __init 338 334 * marked early_lookup_bdev when called during early boot code from dm-init.c. 339 335 */ 340 - int __ref dm_get_device(struct dm_target *ti, const char *path, blk_mode_t mode, 341 - struct dm_dev **result) 336 + int __ref dm_devt_from_path(const char *path, dev_t *dev_p) 342 337 { 343 338 int r; 344 339 dev_t dev; 345 340 unsigned int major, minor; 346 341 char dummy; 347 - struct dm_dev_internal *dd; 348 - struct dm_table *t = ti->table; 349 - 350 - BUG_ON(!t); 351 342 352 343 if (sscanf(path, "%u:%u%c", &major, &minor, &dummy) == 2) { 353 344 /* Extract the major/minor numbers */ ··· 355 362 if (r) 356 363 return r; 357 364 } 365 + *dev_p = dev; 366 + return 0; 367 + } 368 + EXPORT_SYMBOL(dm_devt_from_path); 369 + 370 + /* 371 + * Add a device to the list, or just increment the usage count if 372 + * it's already present. 373 + */ 374 + int dm_get_device(struct dm_target *ti, const char *path, blk_mode_t mode, 375 + struct dm_dev **result) 376 + { 377 + int r; 378 + dev_t dev; 379 + struct dm_dev_internal *dd; 380 + struct dm_table *t = ti->table; 381 + 382 + BUG_ON(!t); 383 + 384 + r = dm_devt_from_path(path, &dev); 385 + if (r) 386 + return r; 387 + 358 388 if (dev == disk_devt(t->md->disk)) 359 389 return -EINVAL; 360 390 ··· 764 748 if (ti->limit_swap_bios && !static_key_enabled(&swap_bios_enabled.key)) 765 749 static_branch_enable(&swap_bios_enabled); 766 750 751 + if (!ti->flush_bypasses_map) 752 + t->flush_bypasses_map = false; 753 + 767 754 return 0; 768 755 769 756 bad: ··· 1050 1031 unsigned int min_pool_size = 0, pool_size; 1051 1032 struct dm_md_mempools *pools; 1052 1033 unsigned int bioset_flags = 0; 1034 + bool mempool_needs_integrity = t->integrity_supported; 1053 1035 1054 1036 if (unlikely(type == DM_TYPE_NONE)) { 1055 1037 DMERR("no table type is set, can't allocate mempools"); ··· 1075 1055 1076 1056 per_io_data_size = max(per_io_data_size, ti->per_io_data_size); 1077 1057 min_pool_size = max(min_pool_size, ti->num_flush_bios); 1058 + 1059 + mempool_needs_integrity |= ti->mempool_needs_integrity; 1078 1060 } 1079 1061 pool_size = max(dm_get_reserved_bio_based_ios(), min_pool_size); 1080 1062 front_pad = roundup(per_io_data_size, ··· 1086 1064 __alignof__(struct dm_io)) + DM_IO_BIO_OFFSET; 1087 1065 if (bioset_init(&pools->io_bs, pool_size, io_front_pad, bioset_flags)) 1088 1066 goto out_free_pools; 1089 - if (t->integrity_supported && 1067 + if (mempool_needs_integrity && 1090 1068 bioset_integrity_create(&pools->io_bs, pool_size)) 1091 1069 goto out_free_pools; 1092 1070 init_bs: 1093 1071 if (bioset_init(&pools->bs, pool_size, front_pad, 0)) 1094 1072 goto out_free_pools; 1095 - if (t->integrity_supported && 1073 + if (mempool_needs_integrity && 1096 1074 bioset_integrity_create(&pools->bs, pool_size)) 1097 1075 goto out_free_pools; 1098 1076
+3 -3
drivers/md/dm-thin-metadata.c
··· 249 249 */ 250 250 #define SUPERBLOCK_CSUM_XOR 160774 251 251 252 - static void sb_prepare_for_write(struct dm_block_validator *v, 252 + static void sb_prepare_for_write(const struct dm_block_validator *v, 253 253 struct dm_block *b, 254 254 size_t block_size) 255 255 { ··· 261 261 SUPERBLOCK_CSUM_XOR)); 262 262 } 263 263 264 - static int sb_check(struct dm_block_validator *v, 264 + static int sb_check(const struct dm_block_validator *v, 265 265 struct dm_block *b, 266 266 size_t block_size) 267 267 { ··· 294 294 return 0; 295 295 } 296 296 297 - static struct dm_block_validator sb_validator = { 297 + static const struct dm_block_validator sb_validator = { 298 298 .name = "superblock", 299 299 .prepare_for_write = sb_prepare_for_write, 300 300 .check = sb_check
+3 -3
drivers/md/dm-thin.c
··· 4079 4079 if (io_opt_sectors < pool->sectors_per_block || 4080 4080 !is_factor(io_opt_sectors, pool->sectors_per_block)) { 4081 4081 if (is_factor(pool->sectors_per_block, limits->max_sectors)) 4082 - blk_limits_io_min(limits, limits->max_sectors << SECTOR_SHIFT); 4082 + limits->io_min = limits->max_sectors << SECTOR_SHIFT; 4083 4083 else 4084 - blk_limits_io_min(limits, pool->sectors_per_block << SECTOR_SHIFT); 4085 - blk_limits_io_opt(limits, pool->sectors_per_block << SECTOR_SHIFT); 4084 + limits->io_min = pool->sectors_per_block << SECTOR_SHIFT; 4085 + limits->io_opt = pool->sectors_per_block << SECTOR_SHIFT; 4086 4086 } 4087 4087 4088 4088 /*
-5
drivers/md/dm-vdo/dedupe.c
··· 148 148 #include "vdo.h" 149 149 #include "wait-queue.h" 150 150 151 - struct uds_attribute { 152 - struct attribute attr; 153 - const char *(*show_string)(struct hash_zones *hash_zones); 154 - }; 155 - 156 151 #define DEDUPE_QUERY_TIMER_IDLE 0 157 152 #define DEDUPE_QUERY_TIMER_RUNNING 1 158 153 #define DEDUPE_QUERY_TIMER_FIRED 2
+2 -2
drivers/md/dm-vdo/dm-vdo-target.c
··· 928 928 limits->physical_block_size = VDO_BLOCK_SIZE; 929 929 930 930 /* The minimum io size for random io */ 931 - blk_limits_io_min(limits, VDO_BLOCK_SIZE); 931 + limits->io_min = VDO_BLOCK_SIZE; 932 932 /* The optimal io size for streamed/sequential io */ 933 - blk_limits_io_opt(limits, VDO_BLOCK_SIZE); 933 + limits->io_opt = VDO_BLOCK_SIZE; 934 934 935 935 /* 936 936 * Sets the maximum discard size that will be passed into VDO. This value comes from a
+1 -4
drivers/md/dm-vdo/indexer/index.c
··· 197 197 static int swap_open_chapter(struct index_zone *zone) 198 198 { 199 199 int result; 200 - struct open_chapter_zone *temporary_chapter; 201 200 202 201 result = finish_previous_chapter(zone->index, zone->newest_virtual_chapter); 203 202 if (result != UDS_SUCCESS) 204 203 return result; 205 204 206 - temporary_chapter = zone->open_chapter; 207 - zone->open_chapter = zone->writing_chapter; 208 - zone->writing_chapter = temporary_chapter; 205 + swap(zone->open_chapter, zone->writing_chapter); 209 206 return UDS_SUCCESS; 210 207 } 211 208
+1 -1
drivers/md/dm-vdo/int-map.c
··· 96 96 size_t size; 97 97 /** @capacity: The number of neighborhoods in the map. */ 98 98 size_t capacity; 99 - /* @bucket_count: The number of buckets in the bucket array. */ 99 + /** @bucket_count: The number of buckets in the bucket array. */ 100 100 size_t bucket_count; 101 101 /** @buckets: The array of hash buckets. */ 102 102 struct bucket *buckets;
+5 -3
drivers/md/dm-vdo/repair.c
··· 318 318 /** 319 319 * drain_slab_depot() - Flush out all dirty refcounts blocks now that they have been rebuilt or 320 320 * recovered. 321 + * @completion: The repair completion. 321 322 */ 322 323 static void drain_slab_depot(struct vdo_completion *completion) 323 324 { ··· 654 653 vdo_traverse_forest(vdo->block_map, process_entry, completion); 655 654 } 656 655 657 - /** 658 - * increment_recovery_point() - Move the given recovery point forward by one entry. 659 - */ 660 656 static void increment_recovery_point(struct recovery_point *point) 661 657 { 662 658 if (++point->entry_count < RECOVERY_JOURNAL_ENTRIES_PER_SECTOR) ··· 950 952 /** 951 953 * find_entry_starting_next_page() - Find the first journal entry after a given entry which is not 952 954 * on the same block map page. 955 + * @repair: The repair completion. 953 956 * @current_entry: The entry to search from. 954 957 * @needs_sort: Whether sorting is needed to proceed. 955 958 * ··· 1217 1218 1218 1219 /** 1219 1220 * find_recovery_journal_head_and_tail() - Find the tail and head of the journal. 1221 + * @repair: The repair completion. 1220 1222 * 1221 1223 * Return: True if there were valid journal blocks. 1222 1224 */ ··· 1446 1446 1447 1447 /** 1448 1448 * extract_new_mappings() - Find all valid new mappings to be applied to the block map. 1449 + * @repair: The repair completion. 1449 1450 * 1450 1451 * The mappings are extracted from the journal and stored in a sortable array so that all of the 1451 1452 * mappings to be applied to a given block map page can be done in a single page fetch. ··· 1501 1500 /** 1502 1501 * compute_usages() - Compute the lbns in use and block map data blocks counts from the tail of 1503 1502 * the journal. 1503 + * @repair: The repair completion. 1504 1504 */ 1505 1505 static noinline int compute_usages(struct repair_completion *repair) 1506 1506 {
+5 -27
drivers/md/dm-verity-fec.c
··· 186 186 static int fec_is_erasure(struct dm_verity *v, struct dm_verity_io *io, 187 187 u8 *want_digest, u8 *data) 188 188 { 189 - if (unlikely(verity_hash(v, verity_io_hash_req(v, io), 190 - data, 1 << v->data_dev_block_bits, 189 + if (unlikely(verity_hash(v, io, data, 1 << v->data_dev_block_bits, 191 190 verity_io_real_digest(v, io), true))) 192 191 return 0; 193 192 ··· 387 388 } 388 389 389 390 /* Always re-validate the corrected block against the expected hash */ 390 - r = verity_hash(v, verity_io_hash_req(v, io), fio->output, 391 - 1 << v->data_dev_block_bits, 391 + r = verity_hash(v, io, fio->output, 1 << v->data_dev_block_bits, 392 392 verity_io_real_digest(v, io), true); 393 393 if (unlikely(r < 0)) 394 394 return r; ··· 402 404 return 0; 403 405 } 404 406 405 - static int fec_bv_copy(struct dm_verity *v, struct dm_verity_io *io, u8 *data, 406 - size_t len) 407 - { 408 - struct dm_verity_fec_io *fio = fec_io(io); 409 - 410 - memcpy(data, &fio->output[fio->output_pos], len); 411 - fio->output_pos += len; 412 - 413 - return 0; 414 - } 415 - 416 - /* 417 - * Correct errors in a block. Copies corrected block to dest if non-NULL, 418 - * otherwise to a bio_vec starting from iter. 419 - */ 407 + /* Correct errors in a block. Copies corrected block to dest. */ 420 408 int verity_fec_decode(struct dm_verity *v, struct dm_verity_io *io, 421 - enum verity_block_type type, sector_t block, u8 *dest, 422 - struct bvec_iter *iter) 409 + enum verity_block_type type, sector_t block, u8 *dest) 423 410 { 424 411 int r; 425 412 struct dm_verity_fec_io *fio = fec_io(io); ··· 454 471 goto done; 455 472 } 456 473 457 - if (dest) 458 - memcpy(dest, fio->output, 1 << v->data_dev_block_bits); 459 - else if (iter) { 460 - fio->output_pos = 0; 461 - r = verity_for_bv_block(v, io, iter, fec_bv_copy); 462 - } 474 + memcpy(dest, fio->output, 1 << v->data_dev_block_bits); 463 475 464 476 done: 465 477 fio->level--;
+2 -4
drivers/md/dm-verity-fec.h
··· 57 57 u8 *bufs[DM_VERITY_FEC_BUF_MAX]; /* bufs for deinterleaving */ 58 58 unsigned int nbufs; /* number of buffers allocated */ 59 59 u8 *output; /* buffer for corrected output */ 60 - size_t output_pos; 61 60 unsigned int level; /* recursion level */ 62 61 }; 63 62 ··· 69 70 70 71 extern int verity_fec_decode(struct dm_verity *v, struct dm_verity_io *io, 71 72 enum verity_block_type type, sector_t block, 72 - u8 *dest, struct bvec_iter *iter); 73 + u8 *dest); 73 74 74 75 extern unsigned int verity_fec_status_table(struct dm_verity *v, unsigned int sz, 75 76 char *result, unsigned int maxlen); ··· 99 100 static inline int verity_fec_decode(struct dm_verity *v, 100 101 struct dm_verity_io *io, 101 102 enum verity_block_type type, 102 - sector_t block, u8 *dest, 103 - struct bvec_iter *iter) 103 + sector_t block, u8 *dest) 104 104 { 105 105 return -EOPNOTSUPP; 106 106 }
+234 -251
drivers/md/dm-verity-target.c
··· 48 48 49 49 static DEFINE_STATIC_KEY_FALSE(use_bh_wq_enabled); 50 50 51 + /* Is at least one dm-verity instance using ahash_tfm instead of shash_tfm? */ 52 + static DEFINE_STATIC_KEY_FALSE(ahash_enabled); 53 + 51 54 struct dm_verity_prefetch_work { 52 55 struct work_struct work; 53 56 struct dm_verity *v; ··· 105 102 return block >> (level * v->hash_per_block_bits); 106 103 } 107 104 108 - static int verity_hash_update(struct dm_verity *v, struct ahash_request *req, 105 + static int verity_ahash_update(struct dm_verity *v, struct ahash_request *req, 109 106 const u8 *data, size_t len, 110 107 struct crypto_wait *wait) 111 108 { ··· 138 135 /* 139 136 * Wrapper for crypto_ahash_init, which handles verity salting. 140 137 */ 141 - static int verity_hash_init(struct dm_verity *v, struct ahash_request *req, 138 + static int verity_ahash_init(struct dm_verity *v, struct ahash_request *req, 142 139 struct crypto_wait *wait, bool may_sleep) 143 140 { 144 141 int r; 145 142 146 - ahash_request_set_tfm(req, v->tfm); 143 + ahash_request_set_tfm(req, v->ahash_tfm); 147 144 ahash_request_set_callback(req, 148 145 may_sleep ? CRYPTO_TFM_REQ_MAY_SLEEP | CRYPTO_TFM_REQ_MAY_BACKLOG : 0, 149 146 crypto_req_done, (void *)wait); ··· 158 155 } 159 156 160 157 if (likely(v->salt_size && (v->version >= 1))) 161 - r = verity_hash_update(v, req, v->salt, v->salt_size, wait); 158 + r = verity_ahash_update(v, req, v->salt, v->salt_size, wait); 162 159 163 160 return r; 164 161 } 165 162 166 - static int verity_hash_final(struct dm_verity *v, struct ahash_request *req, 167 - u8 *digest, struct crypto_wait *wait) 163 + static int verity_ahash_final(struct dm_verity *v, struct ahash_request *req, 164 + u8 *digest, struct crypto_wait *wait) 168 165 { 169 166 int r; 170 167 171 168 if (unlikely(v->salt_size && (!v->version))) { 172 - r = verity_hash_update(v, req, v->salt, v->salt_size, wait); 169 + r = verity_ahash_update(v, req, v->salt, v->salt_size, wait); 173 170 174 171 if (r < 0) { 175 172 DMERR("%s failed updating salt: %d", __func__, r); ··· 183 180 return r; 184 181 } 185 182 186 - int verity_hash(struct dm_verity *v, struct ahash_request *req, 183 + int verity_hash(struct dm_verity *v, struct dm_verity_io *io, 187 184 const u8 *data, size_t len, u8 *digest, bool may_sleep) 188 185 { 189 186 int r; 190 - struct crypto_wait wait; 191 187 192 - r = verity_hash_init(v, req, &wait, may_sleep); 193 - if (unlikely(r < 0)) 194 - goto out; 188 + if (static_branch_unlikely(&ahash_enabled) && !v->shash_tfm) { 189 + struct ahash_request *req = verity_io_hash_req(v, io); 190 + struct crypto_wait wait; 195 191 196 - r = verity_hash_update(v, req, data, len, &wait); 197 - if (unlikely(r < 0)) 198 - goto out; 192 + r = verity_ahash_init(v, req, &wait, may_sleep) ?: 193 + verity_ahash_update(v, req, data, len, &wait) ?: 194 + verity_ahash_final(v, req, digest, &wait); 195 + } else { 196 + struct shash_desc *desc = verity_io_hash_req(v, io); 199 197 200 - r = verity_hash_final(v, req, digest, &wait); 201 - 202 - out: 198 + desc->tfm = v->shash_tfm; 199 + r = crypto_shash_import(desc, v->initial_hashstate) ?: 200 + crypto_shash_finup(desc, data, len, digest); 201 + } 202 + if (unlikely(r)) 203 + DMERR("Error hashing block: %d", r); 203 204 return r; 204 205 } 205 206 ··· 332 325 goto release_ret_r; 333 326 } 334 327 335 - r = verity_hash(v, verity_io_hash_req(v, io), 336 - data, 1 << v->hash_dev_block_bits, 328 + r = verity_hash(v, io, data, 1 << v->hash_dev_block_bits, 337 329 verity_io_real_digest(v, io), !io->in_bh); 338 330 if (unlikely(r < 0)) 339 331 goto release_ret_r; ··· 348 342 r = -EAGAIN; 349 343 goto release_ret_r; 350 344 } else if (verity_fec_decode(v, io, DM_VERITY_BLOCK_TYPE_METADATA, 351 - hash_block, data, NULL) == 0) 345 + hash_block, data) == 0) 352 346 aux->hash_verified = 1; 353 347 else if (verity_handle_err(v, 354 348 DM_VERITY_BLOCK_TYPE_METADATA, ··· 410 404 return r; 411 405 } 412 406 413 - /* 414 - * Calculates the digest for the given bio 415 - */ 416 - static int verity_for_io_block(struct dm_verity *v, struct dm_verity_io *io, 417 - struct bvec_iter *iter, struct crypto_wait *wait) 418 - { 419 - unsigned int todo = 1 << v->data_dev_block_bits; 420 - struct bio *bio = dm_bio_from_per_bio_data(io, v->ti->per_io_data_size); 421 - struct scatterlist sg; 422 - struct ahash_request *req = verity_io_hash_req(v, io); 423 - 424 - do { 425 - int r; 426 - unsigned int len; 427 - struct bio_vec bv = bio_iter_iovec(bio, *iter); 428 - 429 - sg_init_table(&sg, 1); 430 - 431 - len = bv.bv_len; 432 - 433 - if (likely(len >= todo)) 434 - len = todo; 435 - /* 436 - * Operating on a single page at a time looks suboptimal 437 - * until you consider the typical block size is 4,096B. 438 - * Going through this loops twice should be very rare. 439 - */ 440 - sg_set_page(&sg, bv.bv_page, len, bv.bv_offset); 441 - ahash_request_set_crypt(req, &sg, NULL, len); 442 - r = crypto_wait_req(crypto_ahash_update(req), wait); 443 - 444 - if (unlikely(r < 0)) { 445 - DMERR("%s crypto op failed: %d", __func__, r); 446 - return r; 447 - } 448 - 449 - bio_advance_iter(bio, iter, len); 450 - todo -= len; 451 - } while (todo); 452 - 453 - return 0; 454 - } 455 - 456 - /* 457 - * Calls function process for 1 << v->data_dev_block_bits bytes in the bio_vec 458 - * starting from iter. 459 - */ 460 - int verity_for_bv_block(struct dm_verity *v, struct dm_verity_io *io, 461 - struct bvec_iter *iter, 462 - int (*process)(struct dm_verity *v, 463 - struct dm_verity_io *io, u8 *data, 464 - size_t len)) 465 - { 466 - unsigned int todo = 1 << v->data_dev_block_bits; 467 - struct bio *bio = dm_bio_from_per_bio_data(io, v->ti->per_io_data_size); 468 - 469 - do { 470 - int r; 471 - u8 *page; 472 - unsigned int len; 473 - struct bio_vec bv = bio_iter_iovec(bio, *iter); 474 - 475 - page = bvec_kmap_local(&bv); 476 - len = bv.bv_len; 477 - 478 - if (likely(len >= todo)) 479 - len = todo; 480 - 481 - r = process(v, io, page, len); 482 - kunmap_local(page); 483 - 484 - if (r < 0) 485 - return r; 486 - 487 - bio_advance_iter(bio, iter, len); 488 - todo -= len; 489 - } while (todo); 490 - 491 - return 0; 492 - } 493 - 494 - static int verity_recheck_copy(struct dm_verity *v, struct dm_verity_io *io, 495 - u8 *data, size_t len) 496 - { 497 - memcpy(data, io->recheck_buffer, len); 498 - io->recheck_buffer += len; 499 - 500 - return 0; 501 - } 502 - 503 407 static noinline int verity_recheck(struct dm_verity *v, struct dm_verity_io *io, 504 - struct bvec_iter start, sector_t cur_block) 408 + sector_t cur_block, u8 *dest) 505 409 { 506 410 struct page *page; 507 411 void *buffer; ··· 434 518 if (unlikely(r)) 435 519 goto free_ret; 436 520 437 - r = verity_hash(v, verity_io_hash_req(v, io), buffer, 438 - 1 << v->data_dev_block_bits, 521 + r = verity_hash(v, io, buffer, 1 << v->data_dev_block_bits, 439 522 verity_io_real_digest(v, io), true); 440 523 if (unlikely(r)) 441 524 goto free_ret; ··· 445 530 goto free_ret; 446 531 } 447 532 448 - io->recheck_buffer = buffer; 449 - r = verity_for_bv_block(v, io, &start, verity_recheck_copy); 450 - if (unlikely(r)) 451 - goto free_ret; 452 - 533 + memcpy(dest, buffer, 1 << v->data_dev_block_bits); 453 534 r = 0; 454 535 free_ret: 455 536 mempool_free(page, &v->recheck_pool); ··· 453 542 return r; 454 543 } 455 544 456 - static int verity_bv_zero(struct dm_verity *v, struct dm_verity_io *io, 457 - u8 *data, size_t len) 545 + static int verity_handle_data_hash_mismatch(struct dm_verity *v, 546 + struct dm_verity_io *io, 547 + struct bio *bio, sector_t blkno, 548 + u8 *data) 458 549 { 459 - memset(data, 0, len); 550 + if (static_branch_unlikely(&use_bh_wq_enabled) && io->in_bh) { 551 + /* 552 + * Error handling code (FEC included) cannot be run in the 553 + * BH workqueue, so fallback to a standard workqueue. 554 + */ 555 + return -EAGAIN; 556 + } 557 + if (verity_recheck(v, io, blkno, data) == 0) { 558 + if (v->validated_blocks) 559 + set_bit(blkno, v->validated_blocks); 560 + return 0; 561 + } 562 + #if defined(CONFIG_DM_VERITY_FEC) 563 + if (verity_fec_decode(v, io, DM_VERITY_BLOCK_TYPE_DATA, blkno, 564 + data) == 0) 565 + return 0; 566 + #endif 567 + if (bio->bi_status) 568 + return -EIO; /* Error correction failed; Just return error */ 569 + 570 + if (verity_handle_err(v, DM_VERITY_BLOCK_TYPE_DATA, blkno)) { 571 + dm_audit_log_bio(DM_MSG_PREFIX, "verify-data", bio, blkno, 0); 572 + return -EIO; 573 + } 460 574 return 0; 461 - } 462 - 463 - /* 464 - * Moves the bio iter one data block forward. 465 - */ 466 - static inline void verity_bv_skip_block(struct dm_verity *v, 467 - struct dm_verity_io *io, 468 - struct bvec_iter *iter) 469 - { 470 - struct bio *bio = dm_bio_from_per_bio_data(io, v->ti->per_io_data_size); 471 - 472 - bio_advance_iter(bio, iter, 1 << v->data_dev_block_bits); 473 575 } 474 576 475 577 /* ··· 490 566 */ 491 567 static int verity_verify_io(struct dm_verity_io *io) 492 568 { 493 - bool is_zero; 494 569 struct dm_verity *v = io->v; 495 - struct bvec_iter start; 570 + const unsigned int block_size = 1 << v->data_dev_block_bits; 496 571 struct bvec_iter iter_copy; 497 572 struct bvec_iter *iter; 498 - struct crypto_wait wait; 499 573 struct bio *bio = dm_bio_from_per_bio_data(io, v->ti->per_io_data_size); 500 574 unsigned int b; 501 575 ··· 507 585 } else 508 586 iter = &io->iter; 509 587 510 - for (b = 0; b < io->n_blocks; b++) { 588 + for (b = 0; b < io->n_blocks; 589 + b++, bio_advance_iter(bio, iter, block_size)) { 511 590 int r; 512 591 sector_t cur_block = io->block + b; 513 - struct ahash_request *req = verity_io_hash_req(v, io); 592 + bool is_zero; 593 + struct bio_vec bv; 594 + void *data; 514 595 515 596 if (v->validated_blocks && bio->bi_status == BLK_STS_OK && 516 - likely(test_bit(cur_block, v->validated_blocks))) { 517 - verity_bv_skip_block(v, io, iter); 597 + likely(test_bit(cur_block, v->validated_blocks))) 518 598 continue; 519 - } 520 599 521 600 r = verity_hash_for_block(v, io, cur_block, 522 601 verity_io_want_digest(v, io), ··· 525 602 if (unlikely(r < 0)) 526 603 return r; 527 604 605 + bv = bio_iter_iovec(bio, *iter); 606 + if (unlikely(bv.bv_len < block_size)) { 607 + /* 608 + * Data block spans pages. This should not happen, 609 + * since dm-verity sets dma_alignment to the data block 610 + * size minus 1, and dm-verity also doesn't allow the 611 + * data block size to be greater than PAGE_SIZE. 612 + */ 613 + DMERR_LIMIT("unaligned io (data block spans pages)"); 614 + return -EIO; 615 + } 616 + 617 + data = bvec_kmap_local(&bv); 618 + 528 619 if (is_zero) { 529 620 /* 530 621 * If we expect a zero block, don't validate, just 531 622 * return zeros. 532 623 */ 533 - r = verity_for_bv_block(v, io, iter, 534 - verity_bv_zero); 535 - if (unlikely(r < 0)) 536 - return r; 537 - 624 + memset(data, 0, block_size); 625 + kunmap_local(data); 538 626 continue; 539 627 } 540 628 541 - r = verity_hash_init(v, req, &wait, !io->in_bh); 542 - if (unlikely(r < 0)) 629 + r = verity_hash(v, io, data, block_size, 630 + verity_io_real_digest(v, io), !io->in_bh); 631 + if (unlikely(r < 0)) { 632 + kunmap_local(data); 543 633 return r; 544 - 545 - start = *iter; 546 - r = verity_for_io_block(v, io, iter, &wait); 547 - if (unlikely(r < 0)) 548 - return r; 549 - 550 - r = verity_hash_final(v, req, verity_io_real_digest(v, io), 551 - &wait); 552 - if (unlikely(r < 0)) 553 - return r; 634 + } 554 635 555 636 if (likely(memcmp(verity_io_real_digest(v, io), 556 637 verity_io_want_digest(v, io), v->digest_size) == 0)) { 557 638 if (v->validated_blocks) 558 639 set_bit(cur_block, v->validated_blocks); 640 + kunmap_local(data); 559 641 continue; 560 - } else if (static_branch_unlikely(&use_bh_wq_enabled) && io->in_bh) { 561 - /* 562 - * Error handling code (FEC included) cannot be run in a 563 - * tasklet since it may sleep, so fallback to work-queue. 564 - */ 565 - return -EAGAIN; 566 - } else if (verity_recheck(v, io, start, cur_block) == 0) { 567 - if (v->validated_blocks) 568 - set_bit(cur_block, v->validated_blocks); 569 - continue; 570 - #if defined(CONFIG_DM_VERITY_FEC) 571 - } else if (verity_fec_decode(v, io, DM_VERITY_BLOCK_TYPE_DATA, 572 - cur_block, NULL, &start) == 0) { 573 - continue; 574 - #endif 575 - } else { 576 - if (bio->bi_status) { 577 - /* 578 - * Error correction failed; Just return error 579 - */ 580 - return -EIO; 581 - } 582 - if (verity_handle_err(v, DM_VERITY_BLOCK_TYPE_DATA, 583 - cur_block)) { 584 - dm_audit_log_bio(DM_MSG_PREFIX, "verify-data", 585 - bio, cur_block, 0); 586 - return -EIO; 587 - } 588 642 } 643 + r = verity_handle_data_hash_mismatch(v, io, bio, cur_block, 644 + data); 645 + kunmap_local(data); 646 + if (unlikely(r)) 647 + return r; 589 648 } 590 649 591 650 return 0; ··· 919 1014 if (limits->physical_block_size < 1 << v->data_dev_block_bits) 920 1015 limits->physical_block_size = 1 << v->data_dev_block_bits; 921 1016 922 - blk_limits_io_min(limits, limits->logical_block_size); 1017 + limits->io_min = limits->logical_block_size; 1018 + 1019 + /* 1020 + * Similar to what dm-crypt does, opt dm-verity out of support for 1021 + * direct I/O that is aligned to less than the traditional direct I/O 1022 + * alignment requirement of logical_block_size. This prevents dm-verity 1023 + * data blocks from crossing pages, eliminating various edge cases. 1024 + */ 1025 + limits->dma_alignment = limits->logical_block_size - 1; 923 1026 } 924 1027 925 1028 static void verity_dtr(struct dm_target *ti) ··· 946 1033 947 1034 kvfree(v->validated_blocks); 948 1035 kfree(v->salt); 1036 + kfree(v->initial_hashstate); 949 1037 kfree(v->root_digest); 950 1038 kfree(v->zero_digest); 951 1039 952 - if (v->tfm) 953 - crypto_free_ahash(v->tfm); 1040 + if (v->ahash_tfm) { 1041 + static_branch_dec(&ahash_enabled); 1042 + crypto_free_ahash(v->ahash_tfm); 1043 + } else { 1044 + crypto_free_shash(v->shash_tfm); 1045 + } 954 1046 955 1047 kfree(v->alg_name); 956 1048 ··· 1001 1083 static int verity_alloc_zero_digest(struct dm_verity *v) 1002 1084 { 1003 1085 int r = -ENOMEM; 1004 - struct ahash_request *req; 1086 + struct dm_verity_io *io; 1005 1087 u8 *zero_data; 1006 1088 1007 1089 v->zero_digest = kmalloc(v->digest_size, GFP_KERNEL); ··· 1009 1091 if (!v->zero_digest) 1010 1092 return r; 1011 1093 1012 - req = kmalloc(v->ahash_reqsize, GFP_KERNEL); 1094 + io = kmalloc(sizeof(*io) + v->hash_reqsize, GFP_KERNEL); 1013 1095 1014 - if (!req) 1096 + if (!io) 1015 1097 return r; /* verity_dtr will free zero_digest */ 1016 1098 1017 1099 zero_data = kzalloc(1 << v->data_dev_block_bits, GFP_KERNEL); ··· 1019 1101 if (!zero_data) 1020 1102 goto out; 1021 1103 1022 - r = verity_hash(v, req, zero_data, 1 << v->data_dev_block_bits, 1104 + r = verity_hash(v, io, zero_data, 1 << v->data_dev_block_bits, 1023 1105 v->zero_digest, true); 1024 1106 1025 1107 out: 1026 - kfree(req); 1108 + kfree(io); 1027 1109 kfree(zero_data); 1028 1110 1029 1111 return r; ··· 1142 1224 } while (argc && !r); 1143 1225 1144 1226 return r; 1227 + } 1228 + 1229 + static int verity_setup_hash_alg(struct dm_verity *v, const char *alg_name) 1230 + { 1231 + struct dm_target *ti = v->ti; 1232 + struct crypto_ahash *ahash; 1233 + struct crypto_shash *shash = NULL; 1234 + const char *driver_name; 1235 + 1236 + v->alg_name = kstrdup(alg_name, GFP_KERNEL); 1237 + if (!v->alg_name) { 1238 + ti->error = "Cannot allocate algorithm name"; 1239 + return -ENOMEM; 1240 + } 1241 + 1242 + /* 1243 + * Allocate the hash transformation object that this dm-verity instance 1244 + * will use. The vast majority of dm-verity users use CPU-based 1245 + * hashing, so when possible use the shash API to minimize the crypto 1246 + * API overhead. If the ahash API resolves to a different driver 1247 + * (likely an off-CPU hardware offload), use ahash instead. Also use 1248 + * ahash if the obsolete dm-verity format with the appended salt is 1249 + * being used, so that quirk only needs to be handled in one place. 1250 + */ 1251 + ahash = crypto_alloc_ahash(alg_name, 0, 1252 + v->use_bh_wq ? CRYPTO_ALG_ASYNC : 0); 1253 + if (IS_ERR(ahash)) { 1254 + ti->error = "Cannot initialize hash function"; 1255 + return PTR_ERR(ahash); 1256 + } 1257 + driver_name = crypto_ahash_driver_name(ahash); 1258 + if (v->version >= 1 /* salt prepended, not appended? */) { 1259 + shash = crypto_alloc_shash(alg_name, 0, 0); 1260 + if (!IS_ERR(shash) && 1261 + strcmp(crypto_shash_driver_name(shash), driver_name) != 0) { 1262 + /* 1263 + * ahash gave a different driver than shash, so probably 1264 + * this is a case of real hardware offload. Use ahash. 1265 + */ 1266 + crypto_free_shash(shash); 1267 + shash = NULL; 1268 + } 1269 + } 1270 + if (!IS_ERR_OR_NULL(shash)) { 1271 + crypto_free_ahash(ahash); 1272 + ahash = NULL; 1273 + v->shash_tfm = shash; 1274 + v->digest_size = crypto_shash_digestsize(shash); 1275 + v->hash_reqsize = sizeof(struct shash_desc) + 1276 + crypto_shash_descsize(shash); 1277 + DMINFO("%s using shash \"%s\"", alg_name, driver_name); 1278 + } else { 1279 + v->ahash_tfm = ahash; 1280 + static_branch_inc(&ahash_enabled); 1281 + v->digest_size = crypto_ahash_digestsize(ahash); 1282 + v->hash_reqsize = sizeof(struct ahash_request) + 1283 + crypto_ahash_reqsize(ahash); 1284 + DMINFO("%s using ahash \"%s\"", alg_name, driver_name); 1285 + } 1286 + if ((1 << v->hash_dev_block_bits) < v->digest_size * 2) { 1287 + ti->error = "Digest size too big"; 1288 + return -EINVAL; 1289 + } 1290 + return 0; 1291 + } 1292 + 1293 + static int verity_setup_salt_and_hashstate(struct dm_verity *v, const char *arg) 1294 + { 1295 + struct dm_target *ti = v->ti; 1296 + 1297 + if (strcmp(arg, "-") != 0) { 1298 + v->salt_size = strlen(arg) / 2; 1299 + v->salt = kmalloc(v->salt_size, GFP_KERNEL); 1300 + if (!v->salt) { 1301 + ti->error = "Cannot allocate salt"; 1302 + return -ENOMEM; 1303 + } 1304 + if (strlen(arg) != v->salt_size * 2 || 1305 + hex2bin(v->salt, arg, v->salt_size)) { 1306 + ti->error = "Invalid salt"; 1307 + return -EINVAL; 1308 + } 1309 + } 1310 + if (v->shash_tfm) { 1311 + SHASH_DESC_ON_STACK(desc, v->shash_tfm); 1312 + int r; 1313 + 1314 + /* 1315 + * Compute the pre-salted hash state that can be passed to 1316 + * crypto_shash_import() for each block later. 1317 + */ 1318 + v->initial_hashstate = kmalloc( 1319 + crypto_shash_statesize(v->shash_tfm), GFP_KERNEL); 1320 + if (!v->initial_hashstate) { 1321 + ti->error = "Cannot allocate initial hash state"; 1322 + return -ENOMEM; 1323 + } 1324 + desc->tfm = v->shash_tfm; 1325 + r = crypto_shash_init(desc) ?: 1326 + crypto_shash_update(desc, v->salt, v->salt_size) ?: 1327 + crypto_shash_export(desc, v->initial_hashstate); 1328 + if (r) { 1329 + ti->error = "Cannot set up initial hash state"; 1330 + return r; 1331 + } 1332 + } 1333 + return 0; 1145 1334 } 1146 1335 1147 1336 /* ··· 1375 1350 } 1376 1351 v->hash_start = num_ll; 1377 1352 1378 - v->alg_name = kstrdup(argv[7], GFP_KERNEL); 1379 - if (!v->alg_name) { 1380 - ti->error = "Cannot allocate algorithm name"; 1381 - r = -ENOMEM; 1353 + r = verity_setup_hash_alg(v, argv[7]); 1354 + if (r) 1382 1355 goto bad; 1383 - } 1384 - 1385 - v->tfm = crypto_alloc_ahash(v->alg_name, 0, 1386 - v->use_bh_wq ? CRYPTO_ALG_ASYNC : 0); 1387 - if (IS_ERR(v->tfm)) { 1388 - ti->error = "Cannot initialize hash function"; 1389 - r = PTR_ERR(v->tfm); 1390 - v->tfm = NULL; 1391 - goto bad; 1392 - } 1393 - 1394 - /* 1395 - * dm-verity performance can vary greatly depending on which hash 1396 - * algorithm implementation is used. Help people debug performance 1397 - * problems by logging the ->cra_driver_name. 1398 - */ 1399 - DMINFO("%s using implementation \"%s\"", v->alg_name, 1400 - crypto_hash_alg_common(v->tfm)->base.cra_driver_name); 1401 - 1402 - v->digest_size = crypto_ahash_digestsize(v->tfm); 1403 - if ((1 << v->hash_dev_block_bits) < v->digest_size * 2) { 1404 - ti->error = "Digest size too big"; 1405 - r = -EINVAL; 1406 - goto bad; 1407 - } 1408 - v->ahash_reqsize = sizeof(struct ahash_request) + 1409 - crypto_ahash_reqsize(v->tfm); 1410 1356 1411 1357 v->root_digest = kmalloc(v->digest_size, GFP_KERNEL); 1412 1358 if (!v->root_digest) { ··· 1393 1397 } 1394 1398 root_hash_digest_to_validate = argv[8]; 1395 1399 1396 - if (strcmp(argv[9], "-")) { 1397 - v->salt_size = strlen(argv[9]) / 2; 1398 - v->salt = kmalloc(v->salt_size, GFP_KERNEL); 1399 - if (!v->salt) { 1400 - ti->error = "Cannot allocate salt"; 1401 - r = -ENOMEM; 1402 - goto bad; 1403 - } 1404 - if (strlen(argv[9]) != v->salt_size * 2 || 1405 - hex2bin(v->salt, argv[9], v->salt_size)) { 1406 - ti->error = "Invalid salt"; 1407 - r = -EINVAL; 1408 - goto bad; 1409 - } 1410 - } 1400 + r = verity_setup_salt_and_hashstate(v, argv[9]); 1401 + if (r) 1402 + goto bad; 1411 1403 1412 1404 argv += 10; 1413 1405 argc -= 10; ··· 1497 1513 goto bad; 1498 1514 } 1499 1515 1500 - ti->per_io_data_size = sizeof(struct dm_verity_io) + 1501 - v->ahash_reqsize + v->digest_size * 2; 1516 + ti->per_io_data_size = sizeof(struct dm_verity_io) + v->hash_reqsize; 1502 1517 1503 1518 r = verity_fec_ctr(v); 1504 1519 if (r) ··· 1519 1536 verity_dtr(ti); 1520 1537 1521 1538 return r; 1522 - } 1523 - 1524 - /* 1525 - * Check whether a DM target is a verity target. 1526 - */ 1527 - bool dm_is_verity_target(struct dm_target *ti) 1528 - { 1529 - return ti->type->module == THIS_MODULE; 1530 1539 } 1531 1540 1532 1541 /* ··· 1573 1598 .io_hints = verity_io_hints, 1574 1599 }; 1575 1600 module_dm(verity); 1601 + 1602 + /* 1603 + * Check whether a DM target is a verity target. 1604 + */ 1605 + bool dm_is_verity_target(struct dm_target *ti) 1606 + { 1607 + return ti->type == &verity_target; 1608 + } 1576 1609 1577 1610 MODULE_AUTHOR("Mikulas Patocka <mpatocka@redhat.com>"); 1578 1611 MODULE_AUTHOR("Mandeep Baines <msb@chromium.org>");
+7
drivers/md/dm-verity-verify-sig.c
··· 126 126 NULL, 127 127 #endif 128 128 VERIFYING_UNSPECIFIED_SIGNATURE, NULL, NULL); 129 + #ifdef CONFIG_DM_VERITY_VERIFY_ROOTHASH_SIG_PLATFORM_KEYRING 130 + if (ret == -ENOKEY) 131 + ret = verify_pkcs7_signature(root_hash, root_hash_len, sig_data, 132 + sig_len, 133 + VERIFY_USE_PLATFORM_KEYRING, 134 + VERIFYING_UNSPECIFIED_SIGNATURE, NULL, NULL); 135 + #endif 129 136 130 137 return ret; 131 138 }
+16 -23
drivers/md/dm-verity.h
··· 39 39 struct dm_target *ti; 40 40 struct dm_bufio_client *bufio; 41 41 char *alg_name; 42 - struct crypto_ahash *tfm; 42 + struct crypto_ahash *ahash_tfm; /* either this or shash_tfm is set */ 43 + struct crypto_shash *shash_tfm; /* either this or ahash_tfm is set */ 43 44 u8 *root_digest; /* digest of the root block */ 44 45 u8 *salt; /* salt: its size is salt_size */ 46 + u8 *initial_hashstate; /* salted initial state, if shash_tfm is set */ 45 47 u8 *zero_digest; /* digest for a zero block */ 46 48 unsigned int salt_size; 47 49 sector_t data_start; /* data offset in 512-byte sectors */ ··· 58 56 bool hash_failed:1; /* set if hash of any block failed */ 59 57 bool use_bh_wq:1; /* try to verify in BH wq before normal work-queue */ 60 58 unsigned int digest_size; /* digest size for the current hash algorithm */ 61 - unsigned int ahash_reqsize;/* the size of temporary space for crypto */ 59 + unsigned int hash_reqsize; /* the size of temporary space for crypto */ 62 60 enum verity_mode mode; /* mode for handling verification errors */ 63 61 unsigned int corrupted_errs;/* Number of errors for corrupted blocks */ 64 62 ··· 91 89 struct work_struct work; 92 90 struct work_struct bh_work; 93 91 94 - char *recheck_buffer; 92 + u8 real_digest[HASH_MAX_DIGESTSIZE]; 93 + u8 want_digest[HASH_MAX_DIGESTSIZE]; 95 94 96 95 /* 97 - * Three variably-size fields follow this struct: 98 - * 99 - * u8 hash_req[v->ahash_reqsize]; 100 - * u8 real_digest[v->digest_size]; 101 - * u8 want_digest[v->digest_size]; 102 - * 103 - * To access them use: verity_io_hash_req(), verity_io_real_digest() 104 - * and verity_io_want_digest(). 96 + * This struct is followed by a variable-sized hash request of size 97 + * v->hash_reqsize, either a struct ahash_request or a struct shash_desc 98 + * (depending on whether ahash_tfm or shash_tfm is being used). To 99 + * access it, use verity_io_hash_req(). 105 100 */ 106 101 }; 107 102 108 - static inline struct ahash_request *verity_io_hash_req(struct dm_verity *v, 109 - struct dm_verity_io *io) 103 + static inline void *verity_io_hash_req(struct dm_verity *v, 104 + struct dm_verity_io *io) 110 105 { 111 - return (struct ahash_request *)(io + 1); 106 + return io + 1; 112 107 } 113 108 114 109 static inline u8 *verity_io_real_digest(struct dm_verity *v, 115 110 struct dm_verity_io *io) 116 111 { 117 - return (u8 *)(io + 1) + v->ahash_reqsize; 112 + return io->real_digest; 118 113 } 119 114 120 115 static inline u8 *verity_io_want_digest(struct dm_verity *v, 121 116 struct dm_verity_io *io) 122 117 { 123 - return (u8 *)(io + 1) + v->ahash_reqsize + v->digest_size; 118 + return io->want_digest; 124 119 } 125 120 126 - extern int verity_for_bv_block(struct dm_verity *v, struct dm_verity_io *io, 127 - struct bvec_iter *iter, 128 - int (*process)(struct dm_verity *v, 129 - struct dm_verity_io *io, 130 - u8 *data, size_t len)); 131 - 132 - extern int verity_hash(struct dm_verity *v, struct ahash_request *req, 121 + extern int verity_hash(struct dm_verity *v, struct dm_verity_io *io, 133 122 const u8 *data, size_t len, u8 *digest, bool may_sleep); 134 123 135 124 extern int verity_hash_for_block(struct dm_verity *v, struct dm_verity_io *io,
+2 -2
drivers/md/dm-zoned-target.c
··· 996 996 limits->logical_block_size = DMZ_BLOCK_SIZE; 997 997 limits->physical_block_size = DMZ_BLOCK_SIZE; 998 998 999 - blk_limits_io_min(limits, DMZ_BLOCK_SIZE); 1000 - blk_limits_io_opt(limits, DMZ_BLOCK_SIZE); 999 + limits->io_min = DMZ_BLOCK_SIZE; 1000 + limits->io_opt = DMZ_BLOCK_SIZE; 1001 1001 1002 1002 limits->discard_alignment = 0; 1003 1003 limits->discard_granularity = DMZ_BLOCK_SIZE;
+38 -16
drivers/md/dm.c
··· 645 645 646 646 /* Set default bdev, but target must bio_set_dev() before issuing IO */ 647 647 clone->bi_bdev = md->disk->part0; 648 - if (unlikely(ti->needs_bio_set_dev)) 648 + if (likely(ti != NULL) && unlikely(ti->needs_bio_set_dev)) 649 649 bio_set_dev(clone, md->disk->part0); 650 650 651 651 if (len) { ··· 1107 1107 blk_status_t error = bio->bi_status; 1108 1108 struct dm_target_io *tio = clone_to_tio(bio); 1109 1109 struct dm_target *ti = tio->ti; 1110 - dm_endio_fn endio = ti->type->end_io; 1110 + dm_endio_fn endio = likely(ti != NULL) ? ti->type->end_io : NULL; 1111 1111 struct dm_io *io = tio->io; 1112 1112 struct mapped_device *md = io->md; 1113 1113 ··· 1154 1154 } 1155 1155 1156 1156 if (static_branch_unlikely(&swap_bios_enabled) && 1157 - unlikely(swap_bios_limit(ti, bio))) 1157 + likely(ti != NULL) && unlikely(swap_bios_limit(ti, bio))) 1158 1158 up(&md->swap_bios_semaphore); 1159 1159 1160 1160 free_tio(bio); ··· 1553 1553 ci->sector_count = 0; 1554 1554 ci->io->tio.clone.bi_iter.bi_size = 0; 1555 1555 1556 - for (unsigned int i = 0; i < t->num_targets; i++) { 1557 - unsigned int bios; 1558 - struct dm_target *ti = dm_table_get_target(t, i); 1556 + if (!t->flush_bypasses_map) { 1557 + for (unsigned int i = 0; i < t->num_targets; i++) { 1558 + unsigned int bios; 1559 + struct dm_target *ti = dm_table_get_target(t, i); 1559 1560 1560 - if (unlikely(ti->num_flush_bios == 0)) 1561 - continue; 1561 + if (unlikely(ti->num_flush_bios == 0)) 1562 + continue; 1562 1563 1563 - atomic_add(ti->num_flush_bios, &ci->io->io_count); 1564 - bios = __send_duplicate_bios(ci, ti, ti->num_flush_bios, 1565 - NULL, GFP_NOWAIT); 1566 - atomic_sub(ti->num_flush_bios - bios, &ci->io->io_count); 1564 + atomic_add(ti->num_flush_bios, &ci->io->io_count); 1565 + bios = __send_duplicate_bios(ci, ti, ti->num_flush_bios, 1566 + NULL, GFP_NOWAIT); 1567 + atomic_sub(ti->num_flush_bios - bios, &ci->io->io_count); 1568 + } 1569 + } else { 1570 + /* 1571 + * Note that there's no need to grab t->devices_lock here 1572 + * because the targets that support flush optimization don't 1573 + * modify the list of devices. 1574 + */ 1575 + struct list_head *devices = dm_table_get_devices(t); 1576 + unsigned int len = 0; 1577 + struct dm_dev_internal *dd; 1578 + list_for_each_entry(dd, devices, list) { 1579 + struct bio *clone; 1580 + /* 1581 + * Note that the structure dm_target_io is not 1582 + * associated with any target (because the device may be 1583 + * used by multiple targets), so we set tio->ti = NULL. 1584 + * We must check for NULL in the I/O processing path, to 1585 + * avoid NULL pointer dereference. 1586 + */ 1587 + clone = alloc_tio(ci, NULL, 0, &len, GFP_NOIO); 1588 + atomic_add(1, &ci->io->io_count); 1589 + bio_set_dev(clone, dd->dm_dev->bdev); 1590 + clone->bi_end_io = clone_endio; 1591 + dm_submit_bio_remap(clone, NULL); 1592 + } 1567 1593 } 1568 1594 1569 1595 /* ··· 1657 1631 case REQ_OP_SECURE_ERASE: 1658 1632 num_bios = ti->num_secure_erase_bios; 1659 1633 max_sectors = limits->max_secure_erase_sectors; 1660 - if (ti->max_secure_erase_granularity) 1661 - max_granularity = max_sectors; 1662 1634 break; 1663 1635 case REQ_OP_WRITE_ZEROES: 1664 1636 num_bios = ti->num_write_zeroes_bios; 1665 1637 max_sectors = limits->max_write_zeroes_sectors; 1666 - if (ti->max_write_zeroes_granularity) 1667 - max_granularity = max_sectors; 1668 1638 break; 1669 1639 default: 1670 1640 break;
+3 -3
drivers/md/persistent-data/dm-array.c
··· 38 38 */ 39 39 #define CSUM_XOR 595846735 40 40 41 - static void array_block_prepare_for_write(struct dm_block_validator *v, 41 + static void array_block_prepare_for_write(const struct dm_block_validator *v, 42 42 struct dm_block *b, 43 43 size_t size_of_block) 44 44 { ··· 50 50 CSUM_XOR)); 51 51 } 52 52 53 - static int array_block_check(struct dm_block_validator *v, 53 + static int array_block_check(const struct dm_block_validator *v, 54 54 struct dm_block *b, 55 55 size_t size_of_block) 56 56 { ··· 77 77 return 0; 78 78 } 79 79 80 - static struct dm_block_validator array_validator = { 80 + static const struct dm_block_validator array_validator = { 81 81 .name = "array", 82 82 .prepare_for_write = array_block_prepare_for_write, 83 83 .check = array_block_check
+6 -6
drivers/md/persistent-data/dm-block-manager.c
··· 345 345 EXPORT_SYMBOL_GPL(dm_block_data); 346 346 347 347 struct buffer_aux { 348 - struct dm_block_validator *validator; 348 + const struct dm_block_validator *validator; 349 349 int write_locked; 350 350 351 351 #ifdef CONFIG_DM_DEBUG_BLOCK_MANAGER_LOCKING ··· 441 441 static int dm_bm_validate_buffer(struct dm_block_manager *bm, 442 442 struct dm_buffer *buf, 443 443 struct buffer_aux *aux, 444 - struct dm_block_validator *v) 444 + const struct dm_block_validator *v) 445 445 { 446 446 if (unlikely(!aux->validator)) { 447 447 int r; ··· 467 467 return 0; 468 468 } 469 469 int dm_bm_read_lock(struct dm_block_manager *bm, dm_block_t b, 470 - struct dm_block_validator *v, 470 + const struct dm_block_validator *v, 471 471 struct dm_block **result) 472 472 { 473 473 struct buffer_aux *aux; ··· 500 500 EXPORT_SYMBOL_GPL(dm_bm_read_lock); 501 501 502 502 int dm_bm_write_lock(struct dm_block_manager *bm, 503 - dm_block_t b, struct dm_block_validator *v, 503 + dm_block_t b, const struct dm_block_validator *v, 504 504 struct dm_block **result) 505 505 { 506 506 struct buffer_aux *aux; ··· 536 536 EXPORT_SYMBOL_GPL(dm_bm_write_lock); 537 537 538 538 int dm_bm_read_try_lock(struct dm_block_manager *bm, 539 - dm_block_t b, struct dm_block_validator *v, 539 + dm_block_t b, const struct dm_block_validator *v, 540 540 struct dm_block **result) 541 541 { 542 542 struct buffer_aux *aux; ··· 569 569 } 570 570 571 571 int dm_bm_write_lock_zero(struct dm_block_manager *bm, 572 - dm_block_t b, struct dm_block_validator *v, 572 + dm_block_t b, const struct dm_block_validator *v, 573 573 struct dm_block **result) 574 574 { 575 575 int r;
+8 -6
drivers/md/persistent-data/dm-block-manager.h
··· 51 51 */ 52 52 struct dm_block_validator { 53 53 const char *name; 54 - void (*prepare_for_write)(struct dm_block_validator *v, struct dm_block *b, size_t block_size); 54 + void (*prepare_for_write)(const struct dm_block_validator *v, 55 + struct dm_block *b, size_t block_size); 55 56 56 57 /* 57 58 * Return 0 if the checksum is valid or < 0 on error. 58 59 */ 59 - int (*check)(struct dm_block_validator *v, struct dm_block *b, size_t block_size); 60 + int (*check)(const struct dm_block_validator *v, 61 + struct dm_block *b, size_t block_size); 60 62 }; 61 63 62 64 /*----------------------------------------------------------------*/ ··· 75 73 * written back to the disk sometime after dm_bm_unlock is called. 76 74 */ 77 75 int dm_bm_read_lock(struct dm_block_manager *bm, dm_block_t b, 78 - struct dm_block_validator *v, 76 + const struct dm_block_validator *v, 79 77 struct dm_block **result); 80 78 81 79 int dm_bm_write_lock(struct dm_block_manager *bm, dm_block_t b, 82 - struct dm_block_validator *v, 80 + const struct dm_block_validator *v, 83 81 struct dm_block **result); 84 82 85 83 /* ··· 87 85 * available immediately. 88 86 */ 89 87 int dm_bm_read_try_lock(struct dm_block_manager *bm, dm_block_t b, 90 - struct dm_block_validator *v, 88 + const struct dm_block_validator *v, 91 89 struct dm_block **result); 92 90 93 91 /* ··· 95 93 * overwrite the block completely. It saves a disk read. 96 94 */ 97 95 int dm_bm_write_lock_zero(struct dm_block_manager *bm, dm_block_t b, 98 - struct dm_block_validator *v, 96 + const struct dm_block_validator *v, 99 97 struct dm_block **result); 100 98 101 99 void dm_bm_unlock(struct dm_block *b);
+1 -1
drivers/md/persistent-data/dm-btree-internal.h
··· 138 138 */ 139 139 int lower_bound(struct btree_node *n, uint64_t key); 140 140 141 - extern struct dm_block_validator btree_node_validator; 141 + extern const struct dm_block_validator btree_node_validator; 142 142 143 143 /* 144 144 * Value type for upper levels of multi-level btrees.
+3 -3
drivers/md/persistent-data/dm-btree-spine.c
··· 16 16 17 17 #define BTREE_CSUM_XOR 121107 18 18 19 - static void node_prepare_for_write(struct dm_block_validator *v, 19 + static void node_prepare_for_write(const struct dm_block_validator *v, 20 20 struct dm_block *b, 21 21 size_t block_size) 22 22 { ··· 29 29 BTREE_CSUM_XOR)); 30 30 } 31 31 32 - static int node_check(struct dm_block_validator *v, 32 + static int node_check(const struct dm_block_validator *v, 33 33 struct dm_block *b, 34 34 size_t block_size) 35 35 { ··· 81 81 return 0; 82 82 } 83 83 84 - struct dm_block_validator btree_node_validator = { 84 + const struct dm_block_validator btree_node_validator = { 85 85 .name = "btree_node", 86 86 .prepare_for_write = node_prepare_for_write, 87 87 .check = node_check
+6 -6
drivers/md/persistent-data/dm-space-map-common.c
··· 22 22 */ 23 23 #define INDEX_CSUM_XOR 160478 24 24 25 - static void index_prepare_for_write(struct dm_block_validator *v, 25 + static void index_prepare_for_write(const struct dm_block_validator *v, 26 26 struct dm_block *b, 27 27 size_t block_size) 28 28 { ··· 34 34 INDEX_CSUM_XOR)); 35 35 } 36 36 37 - static int index_check(struct dm_block_validator *v, 37 + static int index_check(const struct dm_block_validator *v, 38 38 struct dm_block *b, 39 39 size_t block_size) 40 40 { ··· 59 59 return 0; 60 60 } 61 61 62 - static struct dm_block_validator index_validator = { 62 + static const struct dm_block_validator index_validator = { 63 63 .name = "index", 64 64 .prepare_for_write = index_prepare_for_write, 65 65 .check = index_check ··· 72 72 */ 73 73 #define BITMAP_CSUM_XOR 240779 74 74 75 - static void dm_bitmap_prepare_for_write(struct dm_block_validator *v, 75 + static void dm_bitmap_prepare_for_write(const struct dm_block_validator *v, 76 76 struct dm_block *b, 77 77 size_t block_size) 78 78 { ··· 84 84 BITMAP_CSUM_XOR)); 85 85 } 86 86 87 - static int dm_bitmap_check(struct dm_block_validator *v, 87 + static int dm_bitmap_check(const struct dm_block_validator *v, 88 88 struct dm_block *b, 89 89 size_t block_size) 90 90 { ··· 109 109 return 0; 110 110 } 111 111 112 - static struct dm_block_validator dm_sm_bitmap_validator = { 112 + static const struct dm_block_validator dm_sm_bitmap_validator = { 113 113 .name = "sm_bitmap", 114 114 .prepare_for_write = dm_bitmap_prepare_for_write, 115 115 .check = dm_bitmap_check,
+4 -4
drivers/md/persistent-data/dm-transaction-manager.c
··· 237 237 EXPORT_SYMBOL_GPL(dm_tm_commit); 238 238 239 239 int dm_tm_new_block(struct dm_transaction_manager *tm, 240 - struct dm_block_validator *v, 240 + const struct dm_block_validator *v, 241 241 struct dm_block **result) 242 242 { 243 243 int r; ··· 266 266 } 267 267 268 268 static int __shadow_block(struct dm_transaction_manager *tm, dm_block_t orig, 269 - struct dm_block_validator *v, 269 + const struct dm_block_validator *v, 270 270 struct dm_block **result) 271 271 { 272 272 int r; ··· 306 306 } 307 307 308 308 int dm_tm_shadow_block(struct dm_transaction_manager *tm, dm_block_t orig, 309 - struct dm_block_validator *v, struct dm_block **result, 309 + const struct dm_block_validator *v, struct dm_block **result, 310 310 int *inc_children) 311 311 { 312 312 int r; ··· 331 331 EXPORT_SYMBOL_GPL(dm_tm_shadow_block); 332 332 333 333 int dm_tm_read_lock(struct dm_transaction_manager *tm, dm_block_t b, 334 - struct dm_block_validator *v, 334 + const struct dm_block_validator *v, 335 335 struct dm_block **blk) 336 336 { 337 337 if (tm->is_clone) {
+3 -3
drivers/md/persistent-data/dm-transaction-manager.h
··· 64 64 * Zeroes the new block and returns with write lock held. 65 65 */ 66 66 int dm_tm_new_block(struct dm_transaction_manager *tm, 67 - struct dm_block_validator *v, 67 + const struct dm_block_validator *v, 68 68 struct dm_block **result); 69 69 70 70 /* ··· 84 84 * it locked when you call this. 85 85 */ 86 86 int dm_tm_shadow_block(struct dm_transaction_manager *tm, dm_block_t orig, 87 - struct dm_block_validator *v, 87 + const struct dm_block_validator *v, 88 88 struct dm_block **result, int *inc_children); 89 89 90 90 /* ··· 92 92 * on it outstanding then it'll block. 93 93 */ 94 94 int dm_tm_read_lock(struct dm_transaction_manager *tm, dm_block_t b, 95 - struct dm_block_validator *v, 95 + const struct dm_block_validator *v, 96 96 struct dm_block **result); 97 97 98 98 void dm_tm_unlock(struct dm_transaction_manager *tm, struct dm_block *b);
+26 -12
include/linux/device-mapper.h
··· 180 180 void dm_put_device(struct dm_target *ti, struct dm_dev *d); 181 181 182 182 /* 183 + * Helper function for getting devices 184 + */ 185 + int dm_devt_from_path(const char *path, dev_t *dev_p); 186 + 187 + /* 183 188 * Information about a target type 184 189 */ 185 190 ··· 376 371 bool max_discard_granularity:1; 377 372 378 373 /* 379 - * Set if this target requires that secure_erases be split on 380 - * 'max_secure_erase_sectors' boundaries. 381 - */ 382 - bool max_secure_erase_granularity:1; 383 - 384 - /* 385 - * Set if this target requires that write_zeroes be split on 386 - * 'max_write_zeroes_sectors' boundaries. 387 - */ 388 - bool max_write_zeroes_granularity:1; 389 - 390 - /* 391 374 * Set if we need to limit the number of in-flight bios when swapping. 392 375 */ 393 376 bool limit_swap_bios:1; ··· 397 404 * bio_set_dev(). NOTE: ideally a target should _not_ need this. 398 405 */ 399 406 bool needs_bio_set_dev:1; 407 + 408 + /* 409 + * Set if the target supports flush optimization. If all the targets in 410 + * a table have flush_bypasses_map set, the dm core will not send 411 + * flushes to the targets via a ->map method. It will iterate over 412 + * dm_table->devices and send flushes to the devices directly. This 413 + * optimization reduces the number of flushes being sent when multiple 414 + * targets in a table use the same underlying device. 415 + * 416 + * This optimization may be enabled on targets that just pass the 417 + * flushes to the underlying devices without performing any other 418 + * actions on the flush request. Currently, dm-linear and dm-stripe 419 + * support it. 420 + */ 421 + bool flush_bypasses_map:1; 422 + 423 + /* 424 + * Set if the target calls bio_integrity_alloc on bios received 425 + * in the map method. 426 + */ 427 + bool mempool_needs_integrity:1; 400 428 }; 401 429 402 430 void *dm_per_bio_data(struct bio *bio, size_t data_size);