]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
block: require LBA dma_alignment when using PI
authorChristoph Hellwig <hch@lst.de>
Wed, 22 Oct 2025 08:33:31 +0000 (10:33 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 29 Oct 2025 13:10:28 +0000 (14:10 +0100)
[ Upstream commit 4c8cf6bd28d6fea23819f082ddc8063fd6fa963a ]

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 851c4c96db00
("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: bf8d08532bc1 ("iomap: add support for dma aligned direct-io")
Fixes: b1a000d3b8ec ("block: relax direct io memory alignment")
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
Reviewed-by: Keith Busch <kbusch@kernel.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
block/blk-settings.c

index 8fa52914e16b026ec7eccddea20dcaf749184af0..c3e131f4f908352727ebf4ffab9610002dc5ce97 100644 (file)
@@ -184,6 +184,16 @@ static int blk_validate_integrity_limits(struct queue_limits *lim)
        if (!bi->interval_exp)
                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
+        * never generated, and that each buffer is aligned as expected.
+        */
+       if (bi->csum_type) {
+               lim->dma_alignment = max(lim->dma_alignment,
+                                       (1U << bi->interval_exp) - 1);
+       }
+
        return 0;
 }