Skip to content

Commit 4c8cf6b

Browse files
Christoph Hellwigaxboe
authored andcommitted
block: require LBA dma_alignment when using PI
The block layer PI generation / verification code expects the bio_vecs to have at least LBA size (or more correctly integrity internal) granularity. With the direct I/O alignment relaxation in 2022, user space can now feed bios with less alignment than that, leading to scribbling outside the PI buffers. Apparently this wasn't noticed so far because none of the tests generate such buffers, but since 851c4c9 ("xfs: implement XFS_IOC_DIOINFO in terms of vfs_getattr"), xfstests generic/013 by default generates such I/O now that the relaxed alignment is advertised by the XFS_IOC_DIOINFO ioctl. Fix this by increasing the required alignment when using PI, although handling arbitrary alignment in the long run would be even nicer. Fixes: bf8d085 ("iomap: add support for dma aligned direct-io") Fixes: b1a000d ("block: relax direct io memory alignment") Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Martin K. Petersen <[email protected]> Reviewed-by: Keith Busch <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 81ccca3 commit 4c8cf6b

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

block/blk-settings.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,16 @@ static int blk_validate_integrity_limits(struct queue_limits *lim)
184184
if (!bi->interval_exp)
185185
bi->interval_exp = ilog2(lim->logical_block_size);
186186

187+
/*
188+
* The PI generation / validation helpers do not expect intervals to
189+
* straddle multiple bio_vecs. Enforce alignment so that those are
190+
* never generated, and that each buffer is aligned as expected.
191+
*/
192+
if (bi->csum_type) {
193+
lim->dma_alignment = max(lim->dma_alignment,
194+
(1U << bi->interval_exp) - 1);
195+
}
196+
187197
return 0;
188198
}
189199

0 commit comments

Comments
 (0)