Skip to content

Commit a37b8c0

Browse files
committed
Merge branch 'for-6.11/block' into for-next
* for-6.11/block: block: remove bio_integrity_process block: switch on bio operation in bio_integrity_prep block: remove allocation failure warnings in bio_integrity_prep block: simplify adding the payload in bio_integrity_prep block: only zero non-PI metadata tuples in bio_integrity_prep
2 parents 857b257 + d19b463 commit a37b8c0

File tree

4 files changed

+96
-118
lines changed

4 files changed

+96
-118
lines changed

block/bio-integrity.c

Lines changed: 19 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -396,44 +396,6 @@ int bio_integrity_map_user(struct bio *bio, void __user *ubuf, ssize_t bytes,
396396
}
397397
EXPORT_SYMBOL_GPL(bio_integrity_map_user);
398398

399-
/**
400-
* bio_integrity_process - Process integrity metadata for a bio
401-
* @bio: bio to generate/verify integrity metadata for
402-
* @proc_iter: iterator to process
403-
*/
404-
static blk_status_t bio_integrity_process(struct bio *bio,
405-
struct bvec_iter *proc_iter)
406-
{
407-
struct blk_integrity *bi = blk_get_integrity(bio->bi_bdev->bd_disk);
408-
struct blk_integrity_iter iter;
409-
struct bvec_iter bviter;
410-
struct bio_vec bv;
411-
struct bio_integrity_payload *bip = bio_integrity(bio);
412-
blk_status_t ret = BLK_STS_OK;
413-
414-
iter.disk_name = bio->bi_bdev->bd_disk->disk_name;
415-
iter.interval = 1 << bi->interval_exp;
416-
iter.seed = proc_iter->bi_sector;
417-
iter.prot_buf = bvec_virt(bip->bip_vec);
418-
419-
__bio_for_each_segment(bv, bio, bviter, *proc_iter) {
420-
void *kaddr = bvec_kmap_local(&bv);
421-
422-
iter.data_buf = kaddr;
423-
iter.data_size = bv.bv_len;
424-
if (bio_data_dir(bio) == WRITE)
425-
blk_integrity_generate(&iter, bi);
426-
else
427-
ret = blk_integrity_verify(&iter, bi);
428-
kunmap_local(kaddr);
429-
430-
if (ret)
431-
break;
432-
433-
}
434-
return ret;
435-
}
436-
437399
/**
438400
* bio_integrity_prep - Prepare bio for integrity I/O
439401
* @bio: bio to prepare
@@ -450,57 +412,50 @@ bool bio_integrity_prep(struct bio *bio)
450412
{
451413
struct bio_integrity_payload *bip;
452414
struct blk_integrity *bi = blk_get_integrity(bio->bi_bdev->bd_disk);
415+
unsigned int len;
453416
void *buf;
454-
unsigned long start, end;
455-
unsigned int len, nr_pages;
456-
unsigned int bytes, offset, i;
457417
gfp_t gfp = GFP_NOIO;
458418

459419
if (!bi)
460420
return true;
461421

462-
if (bio_op(bio) != REQ_OP_READ && bio_op(bio) != REQ_OP_WRITE)
463-
return true;
464-
465422
if (!bio_sectors(bio))
466423
return true;
467424

468425
/* Already protected? */
469426
if (bio_integrity(bio))
470427
return true;
471428

472-
if (bio_data_dir(bio) == READ) {
429+
switch (bio_op(bio)) {
430+
case REQ_OP_READ:
473431
if (bi->flags & BLK_INTEGRITY_NOVERIFY)
474432
return true;
475-
} else {
433+
break;
434+
case REQ_OP_WRITE:
476435
if (bi->flags & BLK_INTEGRITY_NOGENERATE)
477436
return true;
478437

479438
/*
480439
* Zero the memory allocated to not leak uninitialized kernel
481-
* memory to disk. For PI this only affects the app tag, but
482-
* for non-integrity metadata it affects the entire metadata
483-
* buffer.
440+
* memory to disk for non-integrity metadata where nothing else
441+
* initializes the memory.
484442
*/
485-
gfp |= __GFP_ZERO;
443+
if (bi->csum_type == BLK_INTEGRITY_CSUM_NONE)
444+
gfp |= __GFP_ZERO;
445+
break;
446+
default:
447+
return true;
486448
}
487449

488450
/* Allocate kernel buffer for protection data */
489451
len = bio_integrity_bytes(bi, bio_sectors(bio));
490452
buf = kmalloc(len, gfp);
491453
if (unlikely(buf == NULL)) {
492-
printk(KERN_ERR "could not allocate integrity buffer\n");
493454
goto err_end_io;
494455
}
495456

496-
end = (((unsigned long) buf) + len + PAGE_SIZE - 1) >> PAGE_SHIFT;
497-
start = ((unsigned long) buf) >> PAGE_SHIFT;
498-
nr_pages = end - start;
499-
500-
/* Allocate bio integrity payload and integrity vectors */
501-
bip = bio_integrity_alloc(bio, GFP_NOIO, nr_pages);
457+
bip = bio_integrity_alloc(bio, GFP_NOIO, 1);
502458
if (IS_ERR(bip)) {
503-
printk(KERN_ERR "could not allocate data integrity bioset\n");
504459
kfree(buf);
505460
goto err_end_io;
506461
}
@@ -511,28 +466,15 @@ bool bio_integrity_prep(struct bio *bio)
511466
if (bi->csum_type == BLK_INTEGRITY_CSUM_IP)
512467
bip->bip_flags |= BIP_IP_CHECKSUM;
513468

514-
/* Map it */
515-
offset = offset_in_page(buf);
516-
for (i = 0; i < nr_pages && len > 0; i++) {
517-
bytes = PAGE_SIZE - offset;
518-
519-
if (bytes > len)
520-
bytes = len;
521-
522-
if (bio_integrity_add_page(bio, virt_to_page(buf),
523-
bytes, offset) < bytes) {
524-
printk(KERN_ERR "could not attach integrity payload\n");
525-
goto err_end_io;
526-
}
527-
528-
buf += bytes;
529-
len -= bytes;
530-
offset = 0;
469+
if (bio_integrity_add_page(bio, virt_to_page(buf), len,
470+
offset_in_page(buf)) < len) {
471+
printk(KERN_ERR "could not attach integrity payload\n");
472+
goto err_end_io;
531473
}
532474

533475
/* Auto-generate integrity metadata if this is a write */
534476
if (bio_data_dir(bio) == WRITE)
535-
bio_integrity_process(bio, &bio->bi_iter);
477+
blk_integrity_generate(bio);
536478
else
537479
bip->bio_iter = bio->bi_iter;
538480
return true;
@@ -558,12 +500,7 @@ static void bio_integrity_verify_fn(struct work_struct *work)
558500
container_of(work, struct bio_integrity_payload, bip_work);
559501
struct bio *bio = bip->bip_bio;
560502

561-
/*
562-
* At the moment verify is called bio's iterator was advanced
563-
* during split and completion, we need to rewind iterator to
564-
* it's original position.
565-
*/
566-
bio->bi_status = bio_integrity_process(bio, &bip->bio_iter);
503+
blk_integrity_verify(bio);
567504
bio_integrity_free(bio);
568505
bio_endio(bio);
569506
}

block/blk.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include <xen/xen.h>
1010
#include "blk-crypto-internal.h"
1111

12-
struct blk_integrity_iter;
1312
struct elevator_type;
1413

1514
/* Max future timer expiry for timeouts */
@@ -681,10 +680,8 @@ int bdev_open(struct block_device *bdev, blk_mode_t mode, void *holder,
681680
const struct blk_holder_ops *hops, struct file *bdev_file);
682681
int bdev_permission(dev_t dev, blk_mode_t mode, void *holder);
683682

684-
void blk_integrity_generate(struct blk_integrity_iter *iter,
685-
struct blk_integrity *bi);
686-
blk_status_t blk_integrity_verify(struct blk_integrity_iter *iter,
687-
struct blk_integrity *bi);
683+
void blk_integrity_generate(struct bio *bio);
684+
void blk_integrity_verify(struct bio *bio);
688685
void blk_integrity_prepare(struct request *rq);
689686
void blk_integrity_complete(struct request *rq, unsigned int nr_bytes);
690687

block/t10-pi.c

Lines changed: 75 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@
1313
#include <asm/unaligned.h>
1414
#include "blk.h"
1515

16+
struct blk_integrity_iter {
17+
void *prot_buf;
18+
void *data_buf;
19+
sector_t seed;
20+
unsigned int data_size;
21+
unsigned short interval;
22+
const char *disk_name;
23+
};
24+
1625
static __be16 t10_pi_csum(__be16 csum, void *data, unsigned int len,
1726
unsigned char csum_type)
1827
{
@@ -364,33 +373,77 @@ static void ext_pi_type1_complete(struct request *rq, unsigned int nr_bytes)
364373
}
365374
}
366375

367-
void blk_integrity_generate(struct blk_integrity_iter *iter,
368-
struct blk_integrity *bi)
376+
void blk_integrity_generate(struct bio *bio)
369377
{
370-
switch (bi->csum_type) {
371-
case BLK_INTEGRITY_CSUM_CRC64:
372-
ext_pi_crc64_generate(iter, bi);
373-
break;
374-
case BLK_INTEGRITY_CSUM_CRC:
375-
case BLK_INTEGRITY_CSUM_IP:
376-
t10_pi_generate(iter, bi);
377-
break;
378-
default:
379-
break;
378+
struct blk_integrity *bi = blk_get_integrity(bio->bi_bdev->bd_disk);
379+
struct bio_integrity_payload *bip = bio_integrity(bio);
380+
struct blk_integrity_iter iter;
381+
struct bvec_iter bviter;
382+
struct bio_vec bv;
383+
384+
iter.disk_name = bio->bi_bdev->bd_disk->disk_name;
385+
iter.interval = 1 << bi->interval_exp;
386+
iter.seed = bio->bi_iter.bi_sector;
387+
iter.prot_buf = bvec_virt(bip->bip_vec);
388+
bio_for_each_segment(bv, bio, bviter) {
389+
void *kaddr = bvec_kmap_local(&bv);
390+
391+
iter.data_buf = kaddr;
392+
iter.data_size = bv.bv_len;
393+
switch (bi->csum_type) {
394+
case BLK_INTEGRITY_CSUM_CRC64:
395+
ext_pi_crc64_generate(&iter, bi);
396+
break;
397+
case BLK_INTEGRITY_CSUM_CRC:
398+
case BLK_INTEGRITY_CSUM_IP:
399+
t10_pi_generate(&iter, bi);
400+
break;
401+
default:
402+
break;
403+
}
404+
kunmap_local(kaddr);
380405
}
381406
}
382407

383-
blk_status_t blk_integrity_verify(struct blk_integrity_iter *iter,
384-
struct blk_integrity *bi)
408+
void blk_integrity_verify(struct bio *bio)
385409
{
386-
switch (bi->csum_type) {
387-
case BLK_INTEGRITY_CSUM_CRC64:
388-
return ext_pi_crc64_verify(iter, bi);
389-
case BLK_INTEGRITY_CSUM_CRC:
390-
case BLK_INTEGRITY_CSUM_IP:
391-
return t10_pi_verify(iter, bi);
392-
default:
393-
return BLK_STS_OK;
410+
struct blk_integrity *bi = blk_get_integrity(bio->bi_bdev->bd_disk);
411+
struct bio_integrity_payload *bip = bio_integrity(bio);
412+
struct blk_integrity_iter iter;
413+
struct bvec_iter bviter;
414+
struct bio_vec bv;
415+
416+
/*
417+
* At the moment verify is called bi_iter has been advanced during split
418+
* and completion, so use the copy created during submission here.
419+
*/
420+
iter.disk_name = bio->bi_bdev->bd_disk->disk_name;
421+
iter.interval = 1 << bi->interval_exp;
422+
iter.seed = bip->bio_iter.bi_sector;
423+
iter.prot_buf = bvec_virt(bip->bip_vec);
424+
__bio_for_each_segment(bv, bio, bviter, bip->bio_iter) {
425+
void *kaddr = bvec_kmap_local(&bv);
426+
blk_status_t ret = BLK_STS_OK;
427+
428+
iter.data_buf = kaddr;
429+
iter.data_size = bv.bv_len;
430+
switch (bi->csum_type) {
431+
case BLK_INTEGRITY_CSUM_CRC64:
432+
ret = ext_pi_crc64_verify(&iter, bi);
433+
break;
434+
case BLK_INTEGRITY_CSUM_CRC:
435+
case BLK_INTEGRITY_CSUM_IP:
436+
ret = t10_pi_verify(&iter, bi);
437+
break;
438+
default:
439+
break;
440+
}
441+
kunmap_local(kaddr);
442+
443+
if (ret) {
444+
bio->bi_status = ret;
445+
return;
446+
}
394447
}
395448
}
396449

include/linux/blk-integrity.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,6 @@ enum blk_integrity_flags {
1414
BLK_INTEGRITY_STACKED = 1 << 4,
1515
};
1616

17-
struct blk_integrity_iter {
18-
void *prot_buf;
19-
void *data_buf;
20-
sector_t seed;
21-
unsigned int data_size;
22-
unsigned short interval;
23-
const char *disk_name;
24-
};
25-
2617
const char *blk_integrity_profile_name(struct blk_integrity *bi);
2718
bool queue_limits_stack_integrity(struct queue_limits *t,
2819
struct queue_limits *b);

0 commit comments

Comments
 (0)