Re: [PATCH] iomap: enforce DIO alignment check in iomap
From: Carlos Maiolino <cem@kernel.org>
Date: 2026-06-11 10:05:27
Also in:
linux-ext4, linux-fsdevel, linux-xfs
On Thu, Jun 11, 2026 at 07:57:44AM +0200, Christoph Hellwig wrote:
On Wed, Jun 10, 2026 at 04:52:11PM +0200, cem@kernel.org wrote:quoted
From: Carlos Maiolino <cem@kernel.org> The DIO alignment check has been lifted from iomap layer to rely on the block layer to enforce proper alignment when issuing direct IO operations. This though, depending on the IO size and buffer address passed to the IO operation may lead to user-visible behavior change. This has been caught initially by LTP test diotest4 running on PPC architecture, where the test fails because a read() operation with a supposedly misaligned buffer succeeds instead of an expected -EINVAL. This has no direct relationship with PPC, but seems to do with the IO size crossing page borders or not.I don't understand the problem here. Why do we want to insist on a failure when we can support it? I think the test is just broken.
The problem I see here from my POV is this changed the behavior expected from the syscalls when the passed in buffer is misaligned as the read() (in the test) succeeds when the passed in buffer does not match the alignment requirements (see below). I am pretty happy in declaring this a test bug, but I thought it would be worth starting a discussion about the sudden/unexpected behavior change. Not to mention now different filesystems will have different alignment requirements which seems at least "weird" to me. I mean, now suddenly iomap-based filesystems have a more relaxed alignment constraint than for example btrfs.
quoted
The problematic behavior is reproducible on x86 by reducing the IO size to something < PAGE_SIZE, so the misaligned read()s will also be accepted by the block layer.What do you mean with misaligned here? For a long time the kernel supports basically arbitrary low memory alignment for diret I/O, just bounded by the device capabilities (typical 4 byte alignment).
The test sends to read() a buffer misplaced by 1 byte (see below) which doesn't match the system's alignment constraints at least from the user passed buffer perspective. I've been assuming it should match device's dma_alignment constraints. The typical 4 byte alignment indeed is the requirement from my PPC machine, but not for my x86:
The supported memory alignment is reported in the statx dio_mem_align. What does that say compared to the alignment expectations in this test?
From my x86: dio_mem_align: 512 dio_offset_align: 512 From PPC: dio_mem_align: 4 dio_offset_align: 512 But this does not explain how the following call would succeed in either case (below one taken from PPC): openat(dirfd=AT_FDCWD, pathname="testdata-4.135256", flags=O_RDWR|O_DIRECT) = 3 _llseek(fd=3, offset=4096, result=[4096], whence=SEEK_SET) = 0 read(arg1=0x3, arg2=0x1003af80001, arg3=0x1000) = 0x1000 The passed in address 0x1003af80001 is one byte misaligned and shouldn't (at least in theory) ever be accepted no? Or am I missing something else?