public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
From: Keith Busch <kbusch@kernel.org>
To: Hans Holmberg <Hans.Holmberg@wdc.com>
Cc: Jens Axboe <axboe@kernel.dk>,
	"linux-block@vger.kernel.org" <linux-block@vger.kernel.org>,
	Damien Le Moal <dlemoal@kernel.org>,
	Johannes Thumshirn <Johannes.Thumshirn@wdc.com>, hch <hch@lst.de>,
	Shinichiro Kawasaki <shinichiro.kawasaki@wdc.com>,
	Andreas Hindborg <a.hindborg@kernel.org>
Subject: Re: [PATCH] null_blk: set dma alignment to logical block size
Date: Wed, 29 Oct 2025 10:06:31 -0600	[thread overview]
Message-ID: <aQI7hyET6f-nXnmp@kbusch-mbp> (raw)
In-Reply-To: <49749a76-5849-410f-966d-6011dd4d5f41@wdc.com>

On Wed, Oct 29, 2025 at 03:32:30PM +0000, Hans Holmberg wrote:
> Hmm, the data is actually copied nullb->dev->blocksize sized chunks
> 
> see copy_to_nullb:
> 
> temp = min_t(size_t, nullb->dev->blocksize, n - count);

That's just saying blocksize is the largest it will transfer. It can be
smaller if there's less data than a block size in the bvec.

> ..
> memcpy_page(t_page->page, offset, source, off + count, temp);
> 
> Just to verify that nullblk was missbehaving I enabled debugging
> for the copy and hit a bug_on in memcpy_page:
> 
> VM_BUG_ON(dst_off + len > PAGE_SIZE || src_off + len > PAGE_SIZE);
> 
> (This was a 4k block size nullblk with the default 511 byte dma limit)

Oh, I see. It's that the source buffer with its weird offsets that don't
align can cause a problem. This should fix it:

---
diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c
index f982027e8c858..385fe6523ec12 100644
--- a/drivers/block/null_blk/main.c
+++ b/drivers/block/null_blk/main.c
@@ -1143,6 +1143,7 @@ static int copy_to_nullb(struct nullb *nullb, struct page *source,
 			null_make_cache_space(nullb, PAGE_SIZE);
 
 		offset = (sector & SECTOR_MASK) << SECTOR_SHIFT;
+		temp = min_t(size_t, temp, PAGE_SIZE - offset);
 		t_page = null_insert_page(nullb, sector,
 			!null_cache_active(nullb) || is_fua);
 		if (!t_page)
@@ -1172,6 +1173,7 @@ static int copy_from_nullb(struct nullb *nullb, struct page *dest,
 		temp = min_t(size_t, nullb->dev->blocksize, n - count);
 
 		offset = (sector & SECTOR_MASK) << SECTOR_SHIFT;
+		temp = min_t(size_t, temp, PAGE_SIZE - offset);
 		t_page = null_lookup_page(nullb, sector, false,
 			!null_cache_active(nullb));
 
--

After this, you can set dma_alignment to 1.

  parent reply	other threads:[~2025-10-29 16:06 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-29 13:39 [PATCH] null_blk: set dma alignment to logical block size Hans Holmberg
2025-10-29 13:51 ` Christoph Hellwig
2025-10-29 13:51   ` Christoph Hellwig
2025-10-29 14:12 ` Keith Busch
2025-10-29 15:32   ` Hans Holmberg
2025-10-29 16:01     ` Hans Holmberg
2025-10-29 16:06     ` Keith Busch [this message]
2025-10-29 16:15       ` Keith Busch
2025-10-30 12:32         ` Hans Holmberg
2025-10-31  9:00 ` Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aQI7hyET6f-nXnmp@kbusch-mbp \
    --to=kbusch@kernel.org \
    --cc=Hans.Holmberg@wdc.com \
    --cc=Johannes.Thumshirn@wdc.com \
    --cc=a.hindborg@kernel.org \
    --cc=axboe@kernel.dk \
    --cc=dlemoal@kernel.org \
    --cc=hch@lst.de \
    --cc=linux-block@vger.kernel.org \
    --cc=shinichiro.kawasaki@wdc.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox