bio-integrity.c (899ee2c3829c5ac14bfc7d3c4a5846c0b709b78f) bio-integrity.c (e9f5f44ad3725335d9c559c3c22cd3726152a7b1)
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * bio-integrity.c - bio data integrity extensions
4 *
5 * Copyright (C) 2007, 2008, 2009 Oracle Corporation
6 * Written by: Martin K. Petersen <martin.petersen@oracle.com>
7 */
8

--- 364 unchanged lines hidden (view full) ---

373 return ret;
374}
375EXPORT_SYMBOL_GPL(bio_integrity_map_user);
376
377/**
378 * bio_integrity_process - Process integrity metadata for a bio
379 * @bio: bio to generate/verify integrity metadata for
380 * @proc_iter: iterator to process
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * bio-integrity.c - bio data integrity extensions
4 *
5 * Copyright (C) 2007, 2008, 2009 Oracle Corporation
6 * Written by: Martin K. Petersen <martin.petersen@oracle.com>
7 */
8

--- 364 unchanged lines hidden (view full) ---

373 return ret;
374}
375EXPORT_SYMBOL_GPL(bio_integrity_map_user);
376
377/**
378 * bio_integrity_process - Process integrity metadata for a bio
379 * @bio: bio to generate/verify integrity metadata for
380 * @proc_iter: iterator to process
381 * @proc_fn: Pointer to the relevant processing function
382 */
383static blk_status_t bio_integrity_process(struct bio *bio,
381 */
382static blk_status_t bio_integrity_process(struct bio *bio,
384 struct bvec_iter *proc_iter, integrity_processing_fn *proc_fn)
383 struct bvec_iter *proc_iter)
385{
386 struct blk_integrity *bi = blk_get_integrity(bio->bi_bdev->bd_disk);
387 struct blk_integrity_iter iter;
388 struct bvec_iter bviter;
389 struct bio_vec bv;
390 struct bio_integrity_payload *bip = bio_integrity(bio);
391 blk_status_t ret = BLK_STS_OK;
392
393 iter.disk_name = bio->bi_bdev->bd_disk->disk_name;
394 iter.interval = 1 << bi->interval_exp;
384{
385 struct blk_integrity *bi = blk_get_integrity(bio->bi_bdev->bd_disk);
386 struct blk_integrity_iter iter;
387 struct bvec_iter bviter;
388 struct bio_vec bv;
389 struct bio_integrity_payload *bip = bio_integrity(bio);
390 blk_status_t ret = BLK_STS_OK;
391
392 iter.disk_name = bio->bi_bdev->bd_disk->disk_name;
393 iter.interval = 1 << bi->interval_exp;
395 iter.tuple_size = bi->tuple_size;
396 iter.seed = proc_iter->bi_sector;
397 iter.prot_buf = bvec_virt(bip->bip_vec);
394 iter.seed = proc_iter->bi_sector;
395 iter.prot_buf = bvec_virt(bip->bip_vec);
398 iter.pi_offset = bi->pi_offset;
399
400 __bio_for_each_segment(bv, bio, bviter, *proc_iter) {
401 void *kaddr = bvec_kmap_local(&bv);
402
403 iter.data_buf = kaddr;
404 iter.data_size = bv.bv_len;
396
397 __bio_for_each_segment(bv, bio, bviter, *proc_iter) {
398 void *kaddr = bvec_kmap_local(&bv);
399
400 iter.data_buf = kaddr;
401 iter.data_size = bv.bv_len;
405 ret = proc_fn(&iter);
402 if (bio_data_dir(bio) == WRITE)
403 blk_integrity_generate(&iter, bi);
404 else
405 ret = blk_integrity_verify(&iter, bi);
406 kunmap_local(kaddr);
407
408 if (ret)
409 break;
410
411 }
412 return ret;
413}

--- 29 unchanged lines hidden (view full) ---

443 if (!bio_sectors(bio))
444 return true;
445
446 /* Already protected? */
447 if (bio_integrity(bio))
448 return true;
449
450 if (bio_data_dir(bio) == READ) {
406 kunmap_local(kaddr);
407
408 if (ret)
409 break;
410
411 }
412 return ret;
413}

--- 29 unchanged lines hidden (view full) ---

443 if (!bio_sectors(bio))
444 return true;
445
446 /* Already protected? */
447 if (bio_integrity(bio))
448 return true;
449
450 if (bio_data_dir(bio) == READ) {
451 if (!bi->profile->verify_fn ||
452 !(bi->flags & BLK_INTEGRITY_VERIFY))
451 if (!(bi->flags & BLK_INTEGRITY_VERIFY))
453 return true;
454 } else {
452 return true;
453 } else {
455 if (!bi->profile->generate_fn ||
456 !(bi->flags & BLK_INTEGRITY_GENERATE))
454 if (!(bi->flags & BLK_INTEGRITY_GENERATE))
457 return true;
458
459 /*
460 * Zero the memory allocated to not leak uninitialized kernel
461 * memory to disk. For PI this only affects the app tag, but
462 * for non-integrity metadata it affects the entire metadata
463 * buffer.
464 */

--- 18 unchanged lines hidden (view full) ---

483 printk(KERN_ERR "could not allocate data integrity bioset\n");
484 kfree(buf);
485 goto err_end_io;
486 }
487
488 bip->bip_flags |= BIP_BLOCK_INTEGRITY;
489 bip_set_seed(bip, bio->bi_iter.bi_sector);
490
455 return true;
456
457 /*
458 * Zero the memory allocated to not leak uninitialized kernel
459 * memory to disk. For PI this only affects the app tag, but
460 * for non-integrity metadata it affects the entire metadata
461 * buffer.
462 */

--- 18 unchanged lines hidden (view full) ---

481 printk(KERN_ERR "could not allocate data integrity bioset\n");
482 kfree(buf);
483 goto err_end_io;
484 }
485
486 bip->bip_flags |= BIP_BLOCK_INTEGRITY;
487 bip_set_seed(bip, bio->bi_iter.bi_sector);
488
491 if (bi->flags & BLK_INTEGRITY_IP_CHECKSUM)
489 if (bi->csum_type == BLK_INTEGRITY_CSUM_IP)
492 bip->bip_flags |= BIP_IP_CHECKSUM;
493
494 /* Map it */
495 offset = offset_in_page(buf);
496 for (i = 0; i < nr_pages && len > 0; i++) {
497 bytes = PAGE_SIZE - offset;
498
499 if (bytes > len)

--- 6 unchanged lines hidden (view full) ---

506 }
507
508 buf += bytes;
509 len -= bytes;
510 offset = 0;
511 }
512
513 /* Auto-generate integrity metadata if this is a write */
490 bip->bip_flags |= BIP_IP_CHECKSUM;
491
492 /* Map it */
493 offset = offset_in_page(buf);
494 for (i = 0; i < nr_pages && len > 0; i++) {
495 bytes = PAGE_SIZE - offset;
496
497 if (bytes > len)

--- 6 unchanged lines hidden (view full) ---

504 }
505
506 buf += bytes;
507 len -= bytes;
508 offset = 0;
509 }
510
511 /* Auto-generate integrity metadata if this is a write */
514 if (bio_data_dir(bio) == WRITE) {
515 bio_integrity_process(bio, &bio->bi_iter,
516 bi->profile->generate_fn);
517 } else {
512 if (bio_data_dir(bio) == WRITE)
513 bio_integrity_process(bio, &bio->bi_iter);
514 else
518 bip->bio_iter = bio->bi_iter;
515 bip->bio_iter = bio->bi_iter;
519 }
520 return true;
521
522err_end_io:
523 bio->bi_status = BLK_STS_RESOURCE;
524 bio_endio(bio);
525 return false;
526}
527EXPORT_SYMBOL(bio_integrity_prep);

--- 6 unchanged lines hidden (view full) ---

534 * request. The function verifies the transferred integrity metadata
535 * and then calls the original bio end_io function.
536 */
537static void bio_integrity_verify_fn(struct work_struct *work)
538{
539 struct bio_integrity_payload *bip =
540 container_of(work, struct bio_integrity_payload, bip_work);
541 struct bio *bio = bip->bip_bio;
516 return true;
517
518err_end_io:
519 bio->bi_status = BLK_STS_RESOURCE;
520 bio_endio(bio);
521 return false;
522}
523EXPORT_SYMBOL(bio_integrity_prep);

--- 6 unchanged lines hidden (view full) ---

530 * request. The function verifies the transferred integrity metadata
531 * and then calls the original bio end_io function.
532 */
533static void bio_integrity_verify_fn(struct work_struct *work)
534{
535 struct bio_integrity_payload *bip =
536 container_of(work, struct bio_integrity_payload, bip_work);
537 struct bio *bio = bip->bip_bio;
542 struct blk_integrity *bi = blk_get_integrity(bio->bi_bdev->bd_disk);
543
544 /*
545 * At the moment verify is called bio's iterator was advanced
546 * during split and completion, we need to rewind iterator to
547 * it's original position.
548 */
538
539 /*
540 * At the moment verify is called bio's iterator was advanced
541 * during split and completion, we need to rewind iterator to
542 * it's original position.
543 */
549 bio->bi_status = bio_integrity_process(bio, &bip->bio_iter,
550 bi->profile->verify_fn);
544 bio->bi_status = bio_integrity_process(bio, &bip->bio_iter);
551 bio_integrity_free(bio);
552 bio_endio(bio);
553}
554
555/**
556 * __bio_integrity_endio - Integrity I/O completion function
557 * @bio: Protected bio
558 *

--- 5 unchanged lines hidden (view full) ---

564 * accordingly.
565 */
566bool __bio_integrity_endio(struct bio *bio)
567{
568 struct blk_integrity *bi = blk_get_integrity(bio->bi_bdev->bd_disk);
569 struct bio_integrity_payload *bip = bio_integrity(bio);
570
571 if (bio_op(bio) == REQ_OP_READ && !bio->bi_status &&
545 bio_integrity_free(bio);
546 bio_endio(bio);
547}
548
549/**
550 * __bio_integrity_endio - Integrity I/O completion function
551 * @bio: Protected bio
552 *

--- 5 unchanged lines hidden (view full) ---

558 * accordingly.
559 */
560bool __bio_integrity_endio(struct bio *bio)
561{
562 struct blk_integrity *bi = blk_get_integrity(bio->bi_bdev->bd_disk);
563 struct bio_integrity_payload *bip = bio_integrity(bio);
564
565 if (bio_op(bio) == REQ_OP_READ && !bio->bi_status &&
572 (bip->bip_flags & BIP_BLOCK_INTEGRITY) && bi->profile->verify_fn) {
566 (bip->bip_flags & BIP_BLOCK_INTEGRITY) && bi->csum_type) {
573 INIT_WORK(&bip->bip_work, bio_integrity_verify_fn);
574 queue_work(kintegrityd_wq, &bip->bip_work);
575 return false;
576 }
577
578 bio_integrity_free(bio);
579 return true;
580}

--- 105 unchanged lines hidden ---
567 INIT_WORK(&bip->bip_work, bio_integrity_verify_fn);
568 queue_work(kintegrityd_wq, &bip->bip_work);
569 return false;
570 }
571
572 bio_integrity_free(bio);
573 return true;
574}

--- 105 unchanged lines hidden ---