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

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'for-5.18/dm-fixes-2' of git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm

Pull device mapper fixes from Mike Snitzer:

- Fix memory corruption in DM integrity target when tag_size is less
than digest size.

- Fix DM multipath's historical-service-time path selector to not use
sched_clock() and ktime_get_ns(); only use ktime_get_ns().

- Fix dm_io->orig_bio NULL pointer dereference in dm_zone_map_bio() due
to 5.18 changes that overlooked DM zone's use of ->orig_bio

- Fix for regression that broke the use of dm_accept_partial_bio() for
"abnormal" IO (e.g. WRITE ZEROES) that does not need duplicate bios

- Fix DM's issuing of empty flush bio so that it's size is 0.

* tag 'for-5.18/dm-fixes-2' of git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm:
dm: fix bio length of empty flush
dm: allow dm_accept_partial_bio() for dm_io without duplicate bios
dm zone: fix NULL pointer dereference in dm_zone_map_bio
dm mpath: only use ktime_get_ns() in historical selector
dm integrity: fix memory corruption when tag_size is less than digest size

+45 -40
+5 -2
drivers/md/dm-integrity.c
··· 4399 4399 } 4400 4400 4401 4401 if (ic->internal_hash) { 4402 + size_t recalc_tags_size; 4402 4403 ic->recalc_wq = alloc_workqueue("dm-integrity-recalc", WQ_MEM_RECLAIM, 1); 4403 4404 if (!ic->recalc_wq ) { 4404 4405 ti->error = "Cannot allocate workqueue"; ··· 4413 4412 r = -ENOMEM; 4414 4413 goto bad; 4415 4414 } 4416 - ic->recalc_tags = kvmalloc_array(RECALC_SECTORS >> ic->sb->log2_sectors_per_block, 4417 - ic->tag_size, GFP_KERNEL); 4415 + recalc_tags_size = (RECALC_SECTORS >> ic->sb->log2_sectors_per_block) * ic->tag_size; 4416 + if (crypto_shash_digestsize(ic->internal_hash) > ic->tag_size) 4417 + recalc_tags_size += crypto_shash_digestsize(ic->internal_hash) - ic->tag_size; 4418 + ic->recalc_tags = kvmalloc(recalc_tags_size, GFP_KERNEL); 4418 4419 if (!ic->recalc_tags) { 4419 4420 ti->error = "Cannot allocate tags for recalculating"; 4420 4421 r = -ENOMEM;
+5 -6
drivers/md/dm-ps-historical-service-time.c
··· 27 27 #include <linux/blkdev.h> 28 28 #include <linux/slab.h> 29 29 #include <linux/module.h> 30 - #include <linux/sched/clock.h> 31 30 32 31 33 32 #define DM_MSG_PREFIX "multipath historical-service-time" ··· 432 433 { 433 434 struct selector *s = ps->context; 434 435 struct path_info *pi = NULL, *best = NULL; 435 - u64 time_now = sched_clock(); 436 + u64 time_now = ktime_get_ns(); 436 437 struct dm_path *ret = NULL; 437 438 unsigned long flags; 438 439 ··· 473 474 474 475 static u64 path_service_time(struct path_info *pi, u64 start_time) 475 476 { 476 - u64 sched_now = ktime_get_ns(); 477 + u64 now = ktime_get_ns(); 477 478 478 479 /* if a previous disk request has finished after this IO was 479 480 * sent to the hardware, pretend the submission happened ··· 482 483 if (time_after64(pi->last_finish, start_time)) 483 484 start_time = pi->last_finish; 484 485 485 - pi->last_finish = sched_now; 486 - if (time_before64(sched_now, start_time)) 486 + pi->last_finish = now; 487 + if (time_before64(now, start_time)) 487 488 return 0; 488 489 489 - return sched_now - start_time; 490 + return now - start_time; 490 491 } 491 492 492 493 static int hst_end_io(struct path_selector *ps, struct dm_path *path,
+28 -21
drivers/md/dm-zone.c
··· 360 360 return 0; 361 361 } 362 362 363 + struct orig_bio_details { 364 + unsigned int op; 365 + unsigned int nr_sectors; 366 + }; 367 + 363 368 /* 364 369 * First phase of BIO mapping for targets with zone append emulation: 365 370 * check all BIO that change a zone writer pointer and change zone 366 371 * append operations into regular write operations. 367 372 */ 368 373 static bool dm_zone_map_bio_begin(struct mapped_device *md, 369 - struct bio *orig_bio, struct bio *clone) 374 + unsigned int zno, struct bio *clone) 370 375 { 371 376 sector_t zsectors = blk_queue_zone_sectors(md->queue); 372 - unsigned int zno = bio_zone_no(orig_bio); 373 377 unsigned int zwp_offset = READ_ONCE(md->zwp_offset[zno]); 374 378 375 379 /* ··· 388 384 WRITE_ONCE(md->zwp_offset[zno], zwp_offset); 389 385 } 390 386 391 - switch (bio_op(orig_bio)) { 387 + switch (bio_op(clone)) { 392 388 case REQ_OP_ZONE_RESET: 393 389 case REQ_OP_ZONE_FINISH: 394 390 return true; ··· 405 401 * target zone. 406 402 */ 407 403 clone->bi_opf = REQ_OP_WRITE | REQ_NOMERGE | 408 - (orig_bio->bi_opf & (~REQ_OP_MASK)); 409 - clone->bi_iter.bi_sector = 410 - orig_bio->bi_iter.bi_sector + zwp_offset; 404 + (clone->bi_opf & (~REQ_OP_MASK)); 405 + clone->bi_iter.bi_sector += zwp_offset; 411 406 break; 412 407 default: 413 408 DMWARN_LIMIT("Invalid BIO operation"); ··· 426 423 * data written to a zone. Note that at this point, the remapped clone BIO 427 424 * may already have completed, so we do not touch it. 428 425 */ 429 - static blk_status_t dm_zone_map_bio_end(struct mapped_device *md, 430 - struct bio *orig_bio, 426 + static blk_status_t dm_zone_map_bio_end(struct mapped_device *md, unsigned int zno, 427 + struct orig_bio_details *orig_bio_details, 431 428 unsigned int nr_sectors) 432 429 { 433 - unsigned int zno = bio_zone_no(orig_bio); 434 430 unsigned int zwp_offset = READ_ONCE(md->zwp_offset[zno]); 435 431 436 432 /* The clone BIO may already have been completed and failed */ ··· 437 435 return BLK_STS_IOERR; 438 436 439 437 /* Update the zone wp offset */ 440 - switch (bio_op(orig_bio)) { 438 + switch (orig_bio_details->op) { 441 439 case REQ_OP_ZONE_RESET: 442 440 WRITE_ONCE(md->zwp_offset[zno], 0); 443 441 return BLK_STS_OK; ··· 454 452 * Check that the target did not truncate the write operation 455 453 * emulating a zone append. 456 454 */ 457 - if (nr_sectors != bio_sectors(orig_bio)) { 455 + if (nr_sectors != orig_bio_details->nr_sectors) { 458 456 DMWARN_LIMIT("Truncated write for zone append"); 459 457 return BLK_STS_IOERR; 460 458 } ··· 490 488 bio_clear_flag(clone, BIO_ZONE_WRITE_LOCKED); 491 489 } 492 490 493 - static bool dm_need_zone_wp_tracking(struct bio *orig_bio) 491 + static bool dm_need_zone_wp_tracking(struct bio *bio) 494 492 { 495 493 /* 496 494 * Special processing is not needed for operations that do not need the ··· 498 496 * zones and all operations that do not modify directly a sequential 499 497 * zone write pointer. 500 498 */ 501 - if (op_is_flush(orig_bio->bi_opf) && !bio_sectors(orig_bio)) 499 + if (op_is_flush(bio->bi_opf) && !bio_sectors(bio)) 502 500 return false; 503 - switch (bio_op(orig_bio)) { 501 + switch (bio_op(bio)) { 504 502 case REQ_OP_WRITE_ZEROES: 505 503 case REQ_OP_WRITE: 506 504 case REQ_OP_ZONE_RESET: 507 505 case REQ_OP_ZONE_FINISH: 508 506 case REQ_OP_ZONE_APPEND: 509 - return bio_zone_is_seq(orig_bio); 507 + return bio_zone_is_seq(bio); 510 508 default: 511 509 return false; 512 510 } ··· 521 519 struct dm_target *ti = tio->ti; 522 520 struct mapped_device *md = io->md; 523 521 struct request_queue *q = md->queue; 524 - struct bio *orig_bio = io->orig_bio; 525 522 struct bio *clone = &tio->clone; 523 + struct orig_bio_details orig_bio_details; 526 524 unsigned int zno; 527 525 blk_status_t sts; 528 526 int r; ··· 531 529 * IOs that do not change a zone write pointer do not need 532 530 * any additional special processing. 533 531 */ 534 - if (!dm_need_zone_wp_tracking(orig_bio)) 532 + if (!dm_need_zone_wp_tracking(clone)) 535 533 return ti->type->map(ti, clone); 536 534 537 535 /* Lock the target zone */ 538 - zno = bio_zone_no(orig_bio); 536 + zno = bio_zone_no(clone); 539 537 dm_zone_lock(q, zno, clone); 538 + 539 + orig_bio_details.nr_sectors = bio_sectors(clone); 540 + orig_bio_details.op = bio_op(clone); 540 541 541 542 /* 542 543 * Check that the bio and the target zone write pointer offset are 543 544 * both valid, and if the bio is a zone append, remap it to a write. 544 545 */ 545 - if (!dm_zone_map_bio_begin(md, orig_bio, clone)) { 546 + if (!dm_zone_map_bio_begin(md, zno, clone)) { 546 547 dm_zone_unlock(q, zno, clone); 547 548 return DM_MAPIO_KILL; 548 549 } ··· 565 560 * The target submitted the clone BIO. The target zone will 566 561 * be unlocked on completion of the clone. 567 562 */ 568 - sts = dm_zone_map_bio_end(md, orig_bio, *tio->len_ptr); 563 + sts = dm_zone_map_bio_end(md, zno, &orig_bio_details, 564 + *tio->len_ptr); 569 565 break; 570 566 case DM_MAPIO_REMAPPED: 571 567 /* ··· 574 568 * unlock the target zone here as the clone will not be 575 569 * submitted. 576 570 */ 577 - sts = dm_zone_map_bio_end(md, orig_bio, *tio->len_ptr); 571 + sts = dm_zone_map_bio_end(md, zno, &orig_bio_details, 572 + *tio->len_ptr); 578 573 if (sts != BLK_STS_OK) 579 574 dm_zone_unlock(q, zno, clone); 580 575 break;
+7 -11
drivers/md/dm.c
··· 1323 1323 } 1324 1324 1325 1325 static void alloc_multiple_bios(struct bio_list *blist, struct clone_info *ci, 1326 - struct dm_target *ti, unsigned num_bios, 1327 - unsigned *len) 1326 + struct dm_target *ti, unsigned num_bios) 1328 1327 { 1329 1328 struct bio *bio; 1330 1329 int try; ··· 1334 1335 if (try) 1335 1336 mutex_lock(&ci->io->md->table_devices_lock); 1336 1337 for (bio_nr = 0; bio_nr < num_bios; bio_nr++) { 1337 - bio = alloc_tio(ci, ti, bio_nr, len, 1338 + bio = alloc_tio(ci, ti, bio_nr, NULL, 1338 1339 try ? GFP_NOIO : GFP_NOWAIT); 1339 1340 if (!bio) 1340 1341 break; ··· 1362 1363 break; 1363 1364 case 1: 1364 1365 clone = alloc_tio(ci, ti, 0, len, GFP_NOIO); 1365 - dm_tio_set_flag(clone_to_tio(clone), DM_TIO_IS_DUPLICATE_BIO); 1366 1366 __map_bio(clone); 1367 1367 break; 1368 1368 default: 1369 - alloc_multiple_bios(&blist, ci, ti, num_bios, len); 1369 + /* dm_accept_partial_bio() is not supported with shared tio->len_ptr */ 1370 + alloc_multiple_bios(&blist, ci, ti, num_bios); 1370 1371 while ((clone = bio_list_pop(&blist))) { 1371 1372 dm_tio_set_flag(clone_to_tio(clone), DM_TIO_IS_DUPLICATE_BIO); 1372 1373 __map_bio(clone); ··· 1391 1392 1392 1393 ci->bio = &flush_bio; 1393 1394 ci->sector_count = 0; 1395 + ci->io->tio.clone.bi_iter.bi_size = 0; 1394 1396 1395 1397 while ((ti = dm_table_get_target(ci->map, target_nr++))) 1396 1398 __send_duplicate_bios(ci, ti, ti->num_flush_bios, NULL); ··· 1407 1407 len = min_t(sector_t, ci->sector_count, 1408 1408 max_io_len_target_boundary(ti, dm_target_offset(ti, ci->sector))); 1409 1409 1410 - /* 1411 - * dm_accept_partial_bio cannot be used with duplicate bios, 1412 - * so update clone_info cursor before __send_duplicate_bios(). 1413 - */ 1410 + __send_duplicate_bios(ci, ti, num_bios, &len); 1411 + 1414 1412 ci->sector += len; 1415 1413 ci->sector_count -= len; 1416 - 1417 - __send_duplicate_bios(ci, ti, num_bios, &len); 1418 1414 } 1419 1415 1420 1416 static bool is_abnormal_io(struct bio *bio)