Skip to content

Commit e3e72fe

Browse files
committed
Merge branch 'for-6.11/block-limits' into for-6.11/block
Pull in block limits branch, which exists as a shared branch for both the block and SCSI tree. * for-6.11/block-limits: (26 commits) block: move integrity information into queue_limits block: invert the BLK_INTEGRITY_{GENERATE,VERIFY} flags block: bypass the STABLE_WRITES flag for protection information block: don't require stable pages for non-PI metadata block: use kstrtoul in flag_store block: factor out flag_{store,show} helper for integrity block: remove the blk_flush_integrity call in blk_integrity_unregister block: remove the blk_integrity_profile structure dm-integrity: use the nop integrity profile md/raid1: don't free conf on raid0_run failure md/raid0: don't free conf on raid0_run failure block: initialize integrity buffer to zero before writing it to media block: add special APIs for run-time disabling of discard and friends block: remove unused queue limits API sr: convert to the atomic queue limits API sd: convert to the atomic queue limits API sd: cleanup zoned queue limits initialization sd: factor out a sd_discard_mode helper sd: simplify the disable case in sd_config_discard sd: add a sd_disable_write_same helper ...
2 parents d37a9ab + c6e56cf commit e3e72fe

39 files changed

+735
-1277
lines changed

Documentation/block/data-integrity.rst

Lines changed: 3 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -153,18 +153,11 @@ bio_free() will automatically free the bip.
153153
4.2 Block Device
154154
----------------
155155

156-
Because the format of the protection data is tied to the physical
157-
disk, each block device has been extended with a block integrity
158-
profile (struct blk_integrity). This optional profile is registered
159-
with the block layer using blk_integrity_register().
160-
161-
The profile contains callback functions for generating and verifying
162-
the protection data, as well as getting and setting application tags.
163-
The profile also contains a few constants to aid in completing,
164-
merging and splitting the integrity metadata.
156+
Block devices can set up the integrity information in the integrity
157+
sub-struture of the queue_limits structure.
165158

166159
Layered block devices will need to pick a profile that's appropriate
167-
for all subdevices. blk_integrity_compare() can help with that. DM
160+
for all subdevices. queue_limits_stack_integrity() can help with that. DM
168161
and MD linear, RAID0 and RAID1 are currently supported. RAID4/5/6
169162
will require extra work due to the application tag.
170163

@@ -250,42 +243,6 @@ will require extra work due to the application tag.
250243
integrity upon completion.
251244

252245

253-
5.4 Registering A Block Device As Capable Of Exchanging Integrity Metadata
254-
--------------------------------------------------------------------------
255-
256-
To enable integrity exchange on a block device the gendisk must be
257-
registered as capable:
258-
259-
`int blk_integrity_register(gendisk, blk_integrity);`
260-
261-
The blk_integrity struct is a template and should contain the
262-
following::
263-
264-
static struct blk_integrity my_profile = {
265-
.name = "STANDARDSBODY-TYPE-VARIANT-CSUM",
266-
.generate_fn = my_generate_fn,
267-
.verify_fn = my_verify_fn,
268-
.tuple_size = sizeof(struct my_tuple_size),
269-
.tag_size = <tag bytes per hw sector>,
270-
};
271-
272-
'name' is a text string which will be visible in sysfs. This is
273-
part of the userland API so chose it carefully and never change
274-
it. The format is standards body-type-variant.
275-
E.g. T10-DIF-TYPE1-IP or T13-EPP-0-CRC.
276-
277-
'generate_fn' generates appropriate integrity metadata (for WRITE).
278-
279-
'verify_fn' verifies that the data buffer matches the integrity
280-
metadata.
281-
282-
'tuple_size' must be set to match the size of the integrity
283-
metadata per sector. I.e. 8 for DIF and EPP.
284-
285-
'tag_size' must be set to identify how many bytes of tag space
286-
are available per hardware sector. For DIF this is either 2 or
287-
0 depending on the value of the Control Mode Page ATO bit.
288-
289246
----------------------------------------------------------------------
290247

291248
2007-12-24 Martin K. Petersen <[email protected]>

arch/um/drivers/ubd_kern.c

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -447,43 +447,31 @@ static int bulk_req_safe_read(
447447
return n;
448448
}
449449

450-
/* Called without dev->lock held, and only in interrupt context. */
451-
static void ubd_handler(void)
450+
static void ubd_end_request(struct io_thread_req *io_req)
452451
{
453-
int n;
454-
int count;
455-
456-
while(1){
457-
n = bulk_req_safe_read(
458-
thread_fd,
459-
irq_req_buffer,
460-
&irq_remainder,
461-
&irq_remainder_size,
462-
UBD_REQ_BUFFER_SIZE
463-
);
464-
if (n < 0) {
465-
if(n == -EAGAIN)
466-
break;
467-
printk(KERN_ERR "spurious interrupt in ubd_handler, "
468-
"err = %d\n", -n);
469-
return;
470-
}
471-
for (count = 0; count < n/sizeof(struct io_thread_req *); count++) {
472-
struct io_thread_req *io_req = (*irq_req_buffer)[count];
473-
474-
if ((io_req->error == BLK_STS_NOTSUPP) && (req_op(io_req->req) == REQ_OP_DISCARD)) {
475-
blk_queue_max_discard_sectors(io_req->req->q, 0);
476-
blk_queue_max_write_zeroes_sectors(io_req->req->q, 0);
477-
}
478-
blk_mq_end_request(io_req->req, io_req->error);
479-
kfree(io_req);
480-
}
452+
if (io_req->error == BLK_STS_NOTSUPP) {
453+
if (req_op(io_req->req) == REQ_OP_DISCARD)
454+
blk_queue_disable_discard(io_req->req->q);
455+
else if (req_op(io_req->req) == REQ_OP_WRITE_ZEROES)
456+
blk_queue_disable_write_zeroes(io_req->req->q);
481457
}
458+
blk_mq_end_request(io_req->req, io_req->error);
459+
kfree(io_req);
482460
}
483461

484462
static irqreturn_t ubd_intr(int irq, void *dev)
485463
{
486-
ubd_handler();
464+
int len, i;
465+
466+
while ((len = bulk_req_safe_read(thread_fd, irq_req_buffer,
467+
&irq_remainder, &irq_remainder_size,
468+
UBD_REQ_BUFFER_SIZE)) >= 0) {
469+
for (i = 0; i < len / sizeof(struct io_thread_req *); i++)
470+
ubd_end_request((*irq_req_buffer)[i]);
471+
}
472+
473+
if (len < 0 && len != -EAGAIN)
474+
pr_err("spurious interrupt in %s, err = %d\n", __func__, len);
487475
return IRQ_HANDLED;
488476
}
489477

block/Kconfig

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ config BLK_DEV_BSGLIB
6262

6363
config BLK_DEV_INTEGRITY
6464
bool "Block layer data integrity support"
65+
select CRC_T10DIF
66+
select CRC64_ROCKSOFT
6567
help
6668
Some storage devices allow extra information to be
6769
stored/retrieved to help protect the data. The block layer
@@ -72,12 +74,6 @@ config BLK_DEV_INTEGRITY
7274
T10/SCSI Data Integrity Field or the T13/ATA External Path
7375
Protection. If in doubt, say N.
7476

75-
config BLK_DEV_INTEGRITY_T10
76-
tristate
77-
depends on BLK_DEV_INTEGRITY
78-
select CRC_T10DIF
79-
select CRC64_ROCKSOFT
80-
8177
config BLK_DEV_WRITE_MOUNTED
8278
bool "Allow writing to mounted block devices"
8379
default y

block/Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ obj-$(CONFIG_MQ_IOSCHED_KYBER) += kyber-iosched.o
2626
bfq-y := bfq-iosched.o bfq-wf2q.o bfq-cgroup.o
2727
obj-$(CONFIG_IOSCHED_BFQ) += bfq.o
2828

29-
obj-$(CONFIG_BLK_DEV_INTEGRITY) += bio-integrity.o blk-integrity.o
30-
obj-$(CONFIG_BLK_DEV_INTEGRITY_T10) += t10-pi.o
29+
obj-$(CONFIG_BLK_DEV_INTEGRITY) += bio-integrity.o blk-integrity.o t10-pi.o
3130
obj-$(CONFIG_BLK_MQ_PCI) += blk-mq-pci.o
3231
obj-$(CONFIG_BLK_MQ_VIRTIO) += blk-mq-virtio.o
3332
obj-$(CONFIG_BLK_DEV_ZONED) += blk-zoned.o

block/bio-integrity.c

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -378,10 +378,9 @@ EXPORT_SYMBOL_GPL(bio_integrity_map_user);
378378
* bio_integrity_process - Process integrity metadata for a bio
379379
* @bio: bio to generate/verify integrity metadata for
380380
* @proc_iter: iterator to process
381-
* @proc_fn: Pointer to the relevant processing function
382381
*/
383382
static 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)
385384
{
386385
struct blk_integrity *bi = blk_get_integrity(bio->bi_bdev->bd_disk);
387386
struct blk_integrity_iter iter;
@@ -392,17 +391,18 @@ static blk_status_t bio_integrity_process(struct bio *bio,
392391

393392
iter.disk_name = bio->bi_bdev->bd_disk->disk_name;
394393
iter.interval = 1 << bi->interval_exp;
395-
iter.tuple_size = bi->tuple_size;
396394
iter.seed = proc_iter->bi_sector;
397395
iter.prot_buf = bvec_virt(bip->bip_vec);
398-
iter.pi_offset = bi->pi_offset;
399396

400397
__bio_for_each_segment(bv, bio, bviter, *proc_iter) {
401398
void *kaddr = bvec_kmap_local(&bv);
402399

403400
iter.data_buf = kaddr;
404401
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);
406406
kunmap_local(kaddr);
407407

408408
if (ret)
@@ -432,6 +432,7 @@ bool bio_integrity_prep(struct bio *bio)
432432
unsigned long start, end;
433433
unsigned int len, nr_pages;
434434
unsigned int bytes, offset, i;
435+
gfp_t gfp = GFP_NOIO;
435436

436437
if (!bi)
437438
return true;
@@ -447,18 +448,24 @@ bool bio_integrity_prep(struct bio *bio)
447448
return true;
448449

449450
if (bio_data_dir(bio) == READ) {
450-
if (!bi->profile->verify_fn ||
451-
!(bi->flags & BLK_INTEGRITY_VERIFY))
451+
if (bi->flags & BLK_INTEGRITY_NOVERIFY)
452452
return true;
453453
} else {
454-
if (!bi->profile->generate_fn ||
455-
!(bi->flags & BLK_INTEGRITY_GENERATE))
454+
if (bi->flags & BLK_INTEGRITY_NOGENERATE)
456455
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+
*/
463+
gfp |= __GFP_ZERO;
457464
}
458465

459466
/* Allocate kernel buffer for protection data */
460467
len = bio_integrity_bytes(bi, bio_sectors(bio));
461-
buf = kmalloc(len, GFP_NOIO);
468+
buf = kmalloc(len, gfp);
462469
if (unlikely(buf == NULL)) {
463470
printk(KERN_ERR "could not allocate integrity buffer\n");
464471
goto err_end_io;
@@ -479,7 +486,7 @@ bool bio_integrity_prep(struct bio *bio)
479486
bip->bip_flags |= BIP_BLOCK_INTEGRITY;
480487
bip_set_seed(bip, bio->bi_iter.bi_sector);
481488

482-
if (bi->flags & BLK_INTEGRITY_IP_CHECKSUM)
489+
if (bi->csum_type == BLK_INTEGRITY_CSUM_IP)
483490
bip->bip_flags |= BIP_IP_CHECKSUM;
484491

485492
/* Map it */
@@ -502,12 +509,10 @@ bool bio_integrity_prep(struct bio *bio)
502509
}
503510

504511
/* Auto-generate integrity metadata if this is a write */
505-
if (bio_data_dir(bio) == WRITE) {
506-
bio_integrity_process(bio, &bio->bi_iter,
507-
bi->profile->generate_fn);
508-
} else {
512+
if (bio_data_dir(bio) == WRITE)
513+
bio_integrity_process(bio, &bio->bi_iter);
514+
else
509515
bip->bio_iter = bio->bi_iter;
510-
}
511516
return true;
512517

513518
err_end_io:
@@ -530,15 +535,13 @@ static void bio_integrity_verify_fn(struct work_struct *work)
530535
struct bio_integrity_payload *bip =
531536
container_of(work, struct bio_integrity_payload, bip_work);
532537
struct bio *bio = bip->bip_bio;
533-
struct blk_integrity *bi = blk_get_integrity(bio->bi_bdev->bd_disk);
534538

535539
/*
536540
* At the moment verify is called bio's iterator was advanced
537541
* during split and completion, we need to rewind iterator to
538542
* it's original position.
539543
*/
540-
bio->bi_status = bio_integrity_process(bio, &bip->bio_iter,
541-
bi->profile->verify_fn);
544+
bio->bi_status = bio_integrity_process(bio, &bip->bio_iter);
542545
bio_integrity_free(bio);
543546
bio_endio(bio);
544547
}
@@ -560,7 +563,7 @@ bool __bio_integrity_endio(struct bio *bio)
560563
struct bio_integrity_payload *bip = bio_integrity(bio);
561564

562565
if (bio_op(bio) == REQ_OP_READ && !bio->bi_status &&
563-
(bip->bip_flags & BIP_BLOCK_INTEGRITY) && bi->profile->verify_fn) {
566+
(bip->bip_flags & BIP_BLOCK_INTEGRITY) && bi->csum_type) {
564567
INIT_WORK(&bip->bip_work, bio_integrity_verify_fn);
565568
queue_work(kintegrityd_wq, &bip->bip_work);
566569
return false;

0 commit comments

Comments
 (0)