blk-integrity: support arbitrary buffer alignment
Subsystems (2)
PATCH 1/1 blk-integrity: support arbitrary buffer alignment
From: Keith Busch <[email protected]>
A bio segment may have partial interval block data with the rest continuing into the next segments because direct-io data payloads only need to aligned in memory to the device's DMA limits.
At the same time, the protection information may also be split in multiple segments. The most likely way that may happen is if two requests merge, or if we're directly using the io_uring user metadata. The generate/verify, however, only ever accessed the first bip_vec.
Further, it may be possible to unalign the protection fields from the user space buffer, or if there are odd additional opaque bytes in front or in back of the protection information metadata region.
Change up the iteration to allow spanning multiple segments. This patch is mostly a re-write of the protection information handling to allow any arbitrary alignments, so it's probably easier to review the end result rather than the diff.
Martin reports many SCSI controllers are not able to handle interval data composed of multiple segments when PI is used, so this patch introduces a new integrity limit that a low level driver can set to notify that it is capable of handling that, default to false. The nvme driver is the first one to enable it in this patch. Everyone else will force DMA alignment to the logical block size to ensure interval data is always aligned within a single segment.
---v4->v5:
* Fixed up ip checksum when it's split among intervals. The previous version would happen to work if the data interval was aligned in a single segment, but it would have gotten the wrong final result if it had to do multiple partial updates.
Testing this type was a little more difficult than it sounds. The scsi_debug driver would force alignment, so it would never hit the partial condition that was previously broken.
To test it, I hacked up a nvme qemu emulation for this checksum type, taking some liberty with the protocol's undefined fields. qemu has its own checksum implementation, 'net_raw_checksum()', and it is calculating the same result through its contiguous bounce buffer as the kernel's partial + fold implementation, so I think it's okay now.
* Fixed up some naming issues that Martin requested from an even earlier version of this patch.
block/blk-settings.c | 6 +- block/t10-pi.c | 825 ++++++++++++++++++++++----------------- drivers/nvme/host/core.c | 1 + include/linux/blkdev.h | 1 + 4 files changed, 468 insertions(+), 365 deletions(-)
block/blk-settings.c +3 -3
@@ -198,11 +198,11 @@ static int blk_validate_integrity_limits(struct queue_limits *lim) bi->interval_exp =ilog2 (lim->logical_block_size);/* -* The PI generation / validation helpers do not expect intervals to -* straddle multiple bio_vecs. Enforce alignment so that those are +* Some IO controllers can not handle data intervals straddling +* multiple bio_vecs. For those, enforce alignment so that those are * never generated, and that each buffer is aligned as expected. */ -if (bi->csum_type) { +if (!bi->split_interval_capable && bi->csum_type) { lim->dma_alignment =max (lim->dma_alignment, (1U << bi->interval_exp) -1 ); }
block/t10-pi.c +463 -362
925 lines not on this page · raw message
drivers/nvme/host/core.c +1 -0
@@ -1874,6 +1874,7 @@ static bool nvme_init_integrity(struct nvme_ns_head *head,break ; } + bi->split_interval_capable = true; bi->metadata_size = head->ms;if (bi->csum_type) { bi->pi_tuple_size = head->pi_size;
include/linux/blkdev.h +1 -0
@@ -122,6 +122,7 @@ struct blk_integrity {unsigned char interval_exp;unsigned char tag_size;unsigned char pi_tuple_size; +bool split_interval_capable; };typedef unsigned int __bitwise blk_mode_t ;
Signature · 1 line
2.47.3
Christoph Hellwig
maintainerQuoted 5 lines · Keith Busch
* Fixed up ip checksum when it's split among intervals. The previous version would happen to work if the data interval was aligned in a single segment, but it would have gotten the wrong final result if it had to do multiple partial updates.
Quoted 8 lines
Testing this type was a little more difficult than it sounds. The
scsi_debugdriver would force alignment, so it would never hit the partial condition that was previously broken.To test it, I hacked up a nvme qemu emulation for this checksum type, taking some liberty with the protocol's undefined fields. qemu has its own checksum implementation, '
net_raw_checksum()', and it is calculating the same result through its contiguous bounce buffer as
Hah. Even if it doesn't work for the IP checksum, can we wire up some of your tests in blktests?
I think the new split_interval_capable need to be stacked as we still build I/O to limits. Not just for that it might be nice to turn it into a BLK_FEAT_* bit.
Otherwise this looks good to me.
Keith Busch
maintainerQuoted 10 lines · Christoph Hellwig
Quoted 9 lines · Keith Busch
* Fixed up ip checksum when it's split among intervals. The previous version would happen to work if the data interval was aligned in a single segment, but it would have gotten the wrong final result if it had to do multiple partial updates.
Testing this type was a little more difficult than it sounds. The
scsi_debugdriver would force alignment, so it would never hit the partial condition that was previously broken.
Quoted 7 lines
Quoted 4 lines
To test it, I hacked up a nvme qemu emulation for this checksum type, taking some liberty with the protocol's undefined fields. qemu has its own checksum implementation, '
net_raw_checksum()', and it is calculating the same result through its contiguous bounce buffer asHah. Even if it doesn't work for the IP checksum, can we wire up some of your tests in blktests?
Certainly. New versions are being prepared for the mailing list, but these tests are still fine to hit the kernel's edge cases.
Forcing partial checksum comes from the dio-offsets test here:
https://lore.kernel.org/linux-block/[email protected]/
And to test out the reftag seed mapping/unmapping, I have this one for liburing:
https://lore.kernel.org/io-uring/[email protected]/
Both of these require nvme for the interesting multi-segment use cases since PI formats for anyone else forces single segment alignment.
Quoted 3 lines
I think the new
split_interval_capableneed to be stacked as we still build I/O to limits. Not just for that it might be nice to turn it into a BLK_FEAT_* bit.
Yes, sounds good.