On Fri, 13 Nov 2026, Mike Snitzer wrote:

> On Tue, Nov 03, 2026 at 10:31:27AM -0700, Keith Busch wrote:
> > On Tue, Nov 03, 2026 at 02:03:28AM -0800, Christoph Hellwig wrote:
> > > On Thu, Oct 22, 2026 at 01:01:10PM -0400, Mike Snitzer wrote:
> > > > On Thu, Jul 09, 2026 at 09:15:17AM -0700, Keith Busch wrote:
> > > > > From: Keith Busch <[email protected]>
> > > > > 
> > > > > All device mappers that want to override the dma_alignment do so.
> > > 
> > > Don't start a patch description by quoting another mail.
> > > 
> > > > Direct I/O from memory every member accepts is therefore rejected at
> > > > the stacking device, and callers that check the advertised alignment
> > > > (for instance through STATX_DIOALIGN) fall back to buffered I/O.
> > > > 
> > > > Leave dma_alignment at zero in blk_set_stacking_limits() so that the
> > > > stacked value is the strictest of the members'.  blk_validate_limits()
> > > > still applies the SECTOR_SIZE - 1 default when nothing was stacked,
> > > > such as for a table with no devices.  Targets that process the data
> > > > themselves and need logical-block-aligned memory already set
> > > > dma_alignment in their io_hints (dm-crypt, dm-integrity, dm-verity,
> > > > dm-log-writes), and NVMe multipath sets its own.
> > > 
> > > Chances are very high that this will introduce bugs somewhere,
> > > as a lot of drivers are historically not ready to deal with lower
> > > alignments, and will creeat nasty exploitable bugs.
> > > 
> > > So you'll need to audit each driver that wants to relax this
> > > individually, and then override the value for them.  Alternatively
> > > we could start with 0 in the block layer, but then you need to
> > > lift the current setting into each caller first, and only remove
> > > them one-by-one with a commit per driver explaining why that is safe
> > > (and sensible).
> > 
> > I suppose it would be safer to have each stacking driver that can
> > tolerate lower alignment granularity explicitly override the limit to 0
> > to inherit whatever the stacking members require. For md-raid,
> > that's not too bad as it can set lim.dma_alignment = 0 in
> > raid0_set_limits() after md_init_stacking_limits(). But other device
> > mappers don't have a way to override it so I guess something has to
> > happen in dm_calculate_queue_limits() to allow this option.
> 
> DM devices have the ability to change limits really well, both in DM
> core and the individual DM targets using .io_hints hook in their
> target_type struct.  Mikulas knows what is needed for DM.
> 
> Mike

The problem is that the limits may change. I.e. for example, you can have 
a linear device on the top of a disk that allows unaligned bio vectors, 
you take a snapshot of the device, and suddenly, the dm device stops 
supporting unaligned bio vectors.

There would be a race condition:
1. you check queue limits, see that it supports unaligned vectors
2. you construct a bio with unaligned vectors
3. you reload the dm table with a target that doesn't support unaligned 
vectors
4. you submit the bio
5. the bio with unaligned vectors is delivered to a target that doesn't 
support them and misbehaves on them (for example, dm-raid1 used to 
livelock if it received unaligned vectors, and other targets may misbehave 
as well because they were written in the era when all vectors were 
aligned)

So, if we want to support unaligned vectors in dm, we must make sure that 
device mapper never misbehaves on unaligned bio vector, regardless of 
which dm target is used.

Auditing and rewriting all the targets to support unaligned vectors 
doesn't seem practical.

One possibility how to support it would be to make per-target flag whether 
the target accepts unaligned vectors. Then, we would have a per-table flag 
that is true if all the targets in the table support unaligned vectors.

Then, if dm receives a bio and the table doesn't have the flag set, we 
would check the alignment of bio vectors in the dm core and terminate the 
bio with BLK_STS_INVAL without giving it to the target.

I just don't know how much this extra walk through the bio vector would 
degrade performance for the common case (i.e. no unaligned vectors).

Mikulas


Reply via email to