blk-integrity: support arbitrary buffer alignment
RFC PATCH 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.
Note, this strives to be a very general solution that should work in scenarios that I think unlikely to ever encounter in real life. The original goal was to simply remove the 'lim->dma_alignment' that protection information was imposing, and it wasn't too much further to support even arbitrary integrity buffers either.
--- block/blk-settings.c | 10 - block/t10-pi.c | 858 ++++++++++++++++++++++++----------------- include/linux/t10-pi.h | 4 +- 3 files changed, 505 insertions(+), 367 deletions(-)
block/blk-settings.c +0 -10
@@ -184,16 +184,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 ); - } -return 0 ; }
block/t10-pi.c +503 -355
960 lines not on this page · raw message
include/linux/t10-pi.h +2 -2
@@ -34,8 +34,8 @@ struct t10_pi_tuple {__be32 ref_tag;/* Target LBA or indirect LBA */ }; -#define T10_PI_APP_ESCAPE cpu_to_be16(0xffff) -#define T10_PI_REF_ESCAPE cpu_to_be32(0xffffffff) +#define T10_PI_APP_ESCAPE 0xffff +#define T10_PI_REF_ESCAPE 0xffffffffstatic inline u32 t10_pi_ref_tag (struct request *rq) {
Signature · 1 line
2.47.3
I have a hard time understanding how this actually works, mostly due to "union pi_tuple". What does that union of two pointers buy us over just passing a void pointer and deriving the type we need deeper down? Also given that taking the address and the comparing it (at thbeginning of blk_tuple_remap_end) how is this actually going to work?
Quoted 5 lines · Christoph Hellwig
I have a hard time understanding how this actually works, mostly due to "union
pi_tuple". What does that union of two pointers buy us over just passing a void pointer and deriving the type we need deeper down? Also given that taking the address and the comparing it (at thbeginning ofblk_tuple_remap_end) how is this actually going to work?
It's a good question.
This generally does pass 'void *' to contiguous protection data. If the actual protection payload is spread across multiple segments, though, we don't have contiguous data, so we have to bounce it through something. Declaring the union on the stack provides this memory for that unusual case. If the bip segment is big enough, we point the 'void *' directly at it; if not, we point it to the temporary onstack allocation. Using a union ensures that it's definitely big enough for any checksum type.
Again, it's a weird corner case. The kernel auto-pi wouldn't allocate that way unless you have very weird metadata format, like with an odd number of bytes preceding or following the DIF (never encountered such a thing, but the specs allow it). User space can send weird alignemnts with io_uring now, too.
Quoted 1 line · Keith Busch
On Wed, Nov 05, 2025 at 03:15:04PM +0100, Christoph Hellwig wrote:
...
Quoted 1 line
Quoted 1 line
What does that union of two pointers
...
Quoted 2 lines
Using a union ensures that it's definitely big enough for any checksum type.
Oh geez, it should have been a union of the structs, not pointers to those types... So this is a mistake in the code, but I hope the intention is more clear.
Quoted 7 lines · Keith Busch
This generally does pass 'void *' to contiguous protection data. If the actual protection payload is spread across multiple segments, though, we don't have contiguous data, so we have to bounce it through something. Declaring the union on the stack provides this memory for that unusual case. If the bip segment is big enough, we point the 'void *' directly at it; if not, we point it to the temporary onstack allocation. Using a union ensures that it's definitely big enough for any checksum type.
The union contains pointers, which are always 8 bytes. But I guess I can see now how this didn't blow up, assuming this was only tested on classic PI, as the tuples are just 8 bytes and you just used the pointer as storage? I.e. these aren't supposed to be pointers, but values?
Quoted 9 lines · Christoph Hellwig
Quoted 7 lines · Keith Busch
This generally does pass 'void *' to contiguous protection data. If the actual protection payload is spread across multiple segments, though, we don't have contiguous data, so we have to bounce it through something. Declaring the union on the stack provides this memory for that unusual case. If the bip segment is big enough, we point the 'void *' directly at it; if not, we point it to the temporary onstack allocation. Using a union ensures that it's definitely big enough for any checksum type.
Quoted 5 lines
The union contains pointers, which are always 8 bytes. But I guess I can see now how this didn't blow up, assuming this was only tested on classic PI, as the tuples are just 8 bytes and you just used the pointer as storage? I.e. these aren't supposed to be pointers, but values?
Yeah, should have been values, not pointers. My mistake.
We don't hit the condition that needs the copy buffer with the kernel's auto-pi, so the bug would never get hit in that path.
I have an io_uring test program that sends pi with offsets such that the field straddles pages. It does not look like it's hitting any of the ref tag remapping code though, so still looking into that.
kernel test robot
build botkernel test robot noticed the following build warnings:
Hi Keith,
[This is a private test report for your RFC patch.] kernel test robot noticed the following build warnings:
[auto build test WARNING on linus/master]
[also build test WARNING on v6.18-rc4]
[cannot apply to axboe-block/for-next hch-configfs/for-next next-20251106] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Keith-Busch/blk-integrity-support-arbitrary-buffer-alignment/20251105-064500 base: linus/master patch link: https://lore.kernel.org/r/20251104224045.3396384-1-kbusch%40meta.com patch subject: [RFC PATCH] blk-integrity: support arbitrary buffer alignment config: sh-randconfig-001-20251106 (https://download.01.org/0day-ci/archive/20251106/[email protected]/config) compiler: sh4-linux-gcc (GCC) 11.5.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251106/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> Warning: block/t10-pi.c:56 function parameter 'iter' not described in 'blk_integrity_crc_offset' >> Warning: block/t10-pi.c:93 function parameter 'iter' not described in 'blk_integrity_copy_from_tuple' >> Warning: block/t10-pi.c:93 function parameter 'tuple' not described in 'blk_integrity_copy_from_tuple' >> Warning: block/t10-pi.c:118 function parameter 'iter' not described in 'blk_integrity_copy_to_tuple' >> Warning: block/t10-pi.c:118 function parameter 'tuple' not described in 'blk_integrity_copy_to_tuple' >> Warning: block/t10-pi.c:406 function parameter 'bi' not described in 'blk_pi_advance_offset' >> Warning: block/t10-pi.c:406 function parameter 'bip' not described in 'blk_pi_advance_offset' >> Warning: block/t10-pi.c:406 function parameter 'iter' not described in 'blk_pi_advance_offset'
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki