All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] null_blk: set dma alignment to logical block size
@ 2025-10-31  9:02 Hans Holmberg
  2025-10-31  9:07 ` Christoph Hellwig
  0 siblings, 1 reply; 2+ messages in thread
From: Hans Holmberg @ 2025-10-31  9:02 UTC (permalink / raw)
  To: Jens Axboe, linux-block
  Cc: Keith Busch, Damien Le Moal, Johannes Thumshirn,
	Christoph Hellwig, Shinichiro Kawasaki, Andreas Hindborg,
	Hans Holmberg

This driver assumes that bio vectors are memory aligned to the logical
block size, so set the queue limit to reflect that.

Unless we set up the limit based on the logical block size, we will go
out of page bounds in copy_to_nullb / copy_from_nullb.

Fixes: bf8d08532bc1 ("iomap: add support for dma aligned direct-io")
Fixes: b1a000d3b8ec ("block: relax direct io memory alignment")
Signed-off-by: Hans Holmberg <hans.holmberg@wdc.com>
---

Changes in v2:
* Added fixes tags from Christoph
* Added reviewed-bys from Keith and Christoph

v1: https://lore.kernel.org/all/20251029133956.19554-1-hans.holmberg@wdc.com/


 drivers/block/null_blk/main.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c
index f982027e8c85..0ee55f889cfd 100644
--- a/drivers/block/null_blk/main.c
+++ b/drivers/block/null_blk/main.c
@@ -1949,6 +1949,7 @@ static int null_add_dev(struct nullb_device *dev)
 		.logical_block_size	= dev->blocksize,
 		.physical_block_size	= dev->blocksize,
 		.max_hw_sectors		= dev->max_sectors,
+		.dma_alignment		= dev->blocksize - 1,
 	};
 
 	struct nullb *nullb;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] null_blk: set dma alignment to logical block size
  2025-10-31  9:02 [PATCH v2] null_blk: set dma alignment to logical block size Hans Holmberg
@ 2025-10-31  9:07 ` Christoph Hellwig
  0 siblings, 0 replies; 2+ messages in thread
From: Christoph Hellwig @ 2025-10-31  9:07 UTC (permalink / raw)
  To: Hans Holmberg
  Cc: Jens Axboe, linux-block, Keith Busch, Damien Le Moal,
	Johannes Thumshirn, Christoph Hellwig, Shinichiro Kawasaki,
	Andreas Hindborg

On Fri, Oct 31, 2025 at 10:02:09AM +0100, Hans Holmberg wrote:
> This driver assumes that bio vectors are memory aligned to the logical
> block size, so set the queue limit to reflect that.
> 
> Unless we set up the limit based on the logical block size, we will go
> out of page bounds in copy_to_nullb / copy_from_nullb.

Please also add something like:

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 generates unaligned I/O, which now lead
to memory corruption when using null_blk.

> Fixes: bf8d08532bc1 ("iomap: add support for dma aligned direct-io")
> Fixes: b1a000d3b8ec ("block: relax direct io memory alignment")
> Signed-off-by: Hans Holmberg <hans.holmberg@wdc.com>
> ---
> 
> Changes in v2:
> * Added fixes tags from Christoph
> * Added reviewed-bys from Keith and Christoph

I don't actually see the Reviewed-by tags above..


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-10-31  9:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-31  9:02 [PATCH v2] null_blk: set dma alignment to logical block size Hans Holmberg
2025-10-31  9:07 ` Christoph Hellwig

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.