Skip to contentSkip to conversation

blk-integrity: support arbitrary buffer alignment

PATCH Superseded Keith Busch 4 participants 4 messages Nov 7, 2025 – Nov 11, 2025 Block layer

v3 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 blk-integrity: support arbitrary buffer alignment

From: Keith Busch <[email protected]>

A bio segment might have partial block data with the rest continuing into the next segments.

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. Further, it may be possible to have 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.

---
v2->v3:

Folded in cleanups from Christoph

A fix for the crc64 ref tag remapping

I ported the liburing's test to blktests here:

https://lore.kernel.org/linux-block/[email protected]/

 block/blk-settings.c |  10 -
 block/t10-pi.c       | 791 +++++++++++++++++++++++--------------------
 2 files changed, 431 insertions(+), 370 deletions(-)
block/blk-settings.c +0 -10
index 78dfef1176231..e0d0b035f39d2 100644
@@ -197,16 +197,6 @@ 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);
-	}
-
 	/*
 	 * The block layer automatically adds integrity data for bios that don't
 	 * already have it.  Limit the I/O size so that a single maximum size
block/t10-pi.c +431 -360

889 lines not on this page · raw message

Signature · 1 line
2.47.3
#1 lore raw

Hi Keith!

block/t10-pi.c line 16

Quoted 10 lines
block/t10-pi.c +2 -0
index 0c4ed97021460..6266ce0043280 100644
@@ -12,231 +12,136 @@
 #include <linux/unaligned.h>
 #include "blk.h"
 
+#define APP_TAG_ESCAPE 0xffff
+#define REF_TAG_ESCAPTE 0xffffffff

ESCAPE

block/t10-pi.c line 40

Quoted 2 lines
block/t10-pi.c +2 -0
+static void blk_crc(struct blk_integrity_iter *iter, void *data,
+		    unsigned int len)

Maybe blk_calculate_checksum() or blk_calculate_guard()? It's a bit weird to refer to the IP checksum as a CRC.

To my knowledge, no SCSI controller can handle PI split across segments and the PI tuples are required to be naturally aligned in memory. SCSI controllers probably can't handle split data segments either since the design constraint is one PI segment per protection interval sized data segment.

Signature · 1 line
Martin K. Petersen
#2 lore raw
Quoted 5 lines · Martin K. Petersen

block/t10-pi.c line 40

Quoted 2 lines
block/t10-pi.c +2 -0
+static void blk_crc(struct blk_integrity_iter *iter, void *data,
+		    unsigned int len)

Maybe blk_calculate_checksum() or blk_calculate_guard()? It's a bit weird to refer to the IP checksum as a CRC.

Sounds good.

Quoted 5 lines

To my knowledge, no SCSI controller can handle PI split across segments and the PI tuples are required to be naturally aligned in memory. SCSI controllers probably can't handle split data segments either since the design constraint is one PI segment per protection interval sized data segment.

There are not many nvme controllers that can handle split pi segments either. Anything setting ID_CTRL SGLS.MSDS can do it, but it's a rarely advertised capability. For everyone else, metadata buffers have a single segment limit.

As for interval data split across segments, that's totally fine for any nvme that supports PI formats. That kind of data was mainly what I was initially trying to handle here since that's sufficient to reinstate the lower dma_alignment limit. It wasn't much more work to support split pi though, unlikely as it is to have hardware capable of it.

#3 lore raw
Quoted 11 lines · Keith Busch
Quoted 5 lines

To my knowledge, no SCSI controller can handle PI split across segments and the PI tuples are required to be naturally aligned in memory. SCSI controllers probably can't handle split data segments either since the design constraint is one PI segment per protection interval sized data segment.

There are not many nvme controllers that can handle split pi segments either. Anything setting ID_CTRL SGLS.MSDS can do it, but it's a rarely advertised capability. For everyone else, metadata buffers have a single segment limit.

Quoted 5 lines

As for interval data split across segments, that's totally fine for any nvme that supports PI formats. That kind of data was mainly what I was initially trying to handle here since that's sufficient to reinstate the lower dma_alignment limit. It wasn't much more work to support split pi though, unlikely as it is to have hardware capable of it.

I guess we'll just need a flag to distinguish the SCSI vs NVMe (or HBA vs integrated) semantics here.