blk-integrity: support arbitrary buffer alignment
Subsystems (2)
PATCH v7 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 align 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.
---v6->v7:
Incorporated review comments from Caleb:
* Replaced mp_bvec_iter_bvec with bvec_iter_bvec for all places that kmap it
* Moved a declaration to the scope that uses it
Since it was just the one iter change, I've retained the previous reviews.
block/blk-settings.c | 12 +- block/t10-pi.c | 819 +++++++++++++++++++--------------- drivers/nvme/host/core.c | 1 + include/linux/blk-integrity.h | 1 + 4 files changed, 466 insertions(+), 367 deletions(-)
block/blk-settings.c +8 -4
@@ -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->flags &BLK_SPLIT_INTERVAL_CAPABLE ) && bi->csum_type) { lim->dma_alignment =max (lim->dma_alignment, (1U << bi->interval_exp) -1 ); }
@@ -1001,10 +1001,14 @@ bool queue_limits_stack_integrity(struct queue_limits *t,if ((ti->flags &BLK_INTEGRITY_REF_TAG ) != (bi->flags &BLK_INTEGRITY_REF_TAG )) goto incompatible; +if ((ti->flags &BLK_SPLIT_INTERVAL_CAPABLE ) && + !(bi->flags &BLK_SPLIT_INTERVAL_CAPABLE )) + ti->flags &= ~BLK_SPLIT_INTERVAL_CAPABLE ; }else { ti->flags =BLK_INTEGRITY_STACKED ; ti->flags |= (bi->flags &BLK_INTEGRITY_DEVICE_CAPABLE ) | - (bi->flags &BLK_INTEGRITY_REF_TAG ); + (bi->flags &BLK_INTEGRITY_REF_TAG ) | + (bi->flags &BLK_SPLIT_INTERVAL_CAPABLE ); ti->csum_type = bi->csum_type; ti->pi_tuple_size = bi->pi_tuple_size; ti->metadata_size = bi->metadata_size;
block/t10-pi.c +456 -363
918 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->flags |=BLK_SPLIT_INTERVAL_CAPABLE ; bi->metadata_size = head->ms;if (bi->csum_type) { bi->pi_tuple_size = head->pi_size;
include/linux/blk-integrity.h +1 -0
@@ -19,6 +19,7 @@ enum blk_integrity_flags {BLK_INTEGRITY_DEVICE_CAPABLE =1 <<2 ,BLK_INTEGRITY_REF_TAG =1 <<3 ,BLK_INTEGRITY_STACKED =1 <<4 , + BLK_SPLIT_INTERVAL_CAPABLE = 1 << 5, };const char *blk_integrity_profile_name (struct blk_integrity *bi);
Signature · 1 line
2.47.3
Keith Busch
maintainerQuoted 20 lines · Keith Busch
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 align 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_uringuser metadata. The generate/verify, however, only ever accessed the firstbip_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.
Quoted 7 lines
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.
Hi Jens,
It just came to my attention that this one is still outstanding. Any thoughts about pulling this in? I may have to rebase it, but just want to check before doing that.
Jens Axboe
maintainerQuoted 29 lines · Keith Busch
Quoted 20 lines · Keith Busch
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 align 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_uringuser metadata. The generate/verify, however, only ever accessed the firstbip_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.
Quoted 7 lines
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.
Quoted 4 lines
Hi Jens,
It just came to my attention that this one is still outstanding. Any thoughts about pulling this in? I may have to rebase it, but just want to check before doing that.
Looks like that got missed. If you rebase it, let's take a look and see if we can do it for this kernel release. It is on the bigger side though for this deep into the merge window... But since it's still early days for the release as a whole, we may be able to sneak it in.
Signature · 1 line
Jens Axboe
Keith Busch
maintainerQuoted 4 lines · Jens Axboe
Looks like that got missed. If you rebase it, let's take a look and see if we can do it for this kernel release. It is on the bigger side though for this deep into the merge window... But since it's still early days for the release as a whole, we may be able to sneak it in.
Just resent it. That would be cool if you want to squeeze this into 7.0, but it's also fine if you decide to wait for 7.1. As long as it's staged somewhere for upstream inclusion, I'm happy to backport this as needed.
Jens Axboe
maintainerQuoted 9 lines · Keith Busch
Quoted 4 lines · Jens Axboe
Looks like that got missed. If you rebase it, let's take a look and see if we can do it for this kernel release. It is on the bigger side though for this deep into the merge window... But since it's still early days for the release as a whole, we may be able to sneak it in.
Just resent it. That would be cool if you want to squeeze this into 7.0, but it's also fine if you decide to wait for 7.1. As long as it's staged somewhere for upstream inclusion, I'm happy to backport this as needed.
Let's just go for 7.1 if it isn't a huge deal. I'll queue it up.
Signature · 1 line
Jens Axboe