Linux filesystem development
 help / color / mirror / Atom feed
From: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
To: Keith Busch <kbusch@meta.com>
Cc: linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	 dm-devel@lists.linux.dev, hch@lst.de, axboe@kernel.dk,
	brauner@kernel.org,  djwong@kernel.org, viro@zeniv.linux.org.uk,
	Keith Busch <kbusch@kernel.org>,
	 stable@vger.kernel.org, Hannes Reinecke <hare@kernel.org>,
	0wnerD1ed <l7z@0b1t.tech>
Subject: Re: [PATCH RESEND 5/5] block: validate user space vectors during extraction
Date: Thu, 6 Aug 2026 17:03:53 +0900	[thread overview]
Message-ID: <anQ-28nxOqBmQjxu@shinmob> (raw)
In-Reply-To: <anMscoGkR5BYjSGy@shinmob>

On Aug 05, 2026 / 21:46, Shin'ichiro Kawasaki wrote:
> Cc+: 0wnerD1ed
> 
> On Jul 20, 2026 / 13:10, Keith Busch wrote:
> > From: Keith Busch <kbusch@kernel.org>
> > 
> > The bio-based drivers don't necessarily check the alignment split, and
> > stacking block drivers don't always handle a misalignment detected after
> > submitting the bio. Validate user vectors against the device's
> > dma_alignment as the bio is built from the iov_iter, rejecting
> > misaligned early with -EINVAL.
> 
> Recently, the new test case block/045 was added to blkests through a GitHub PR
> [1]. The test case passes with the Linux master branch tags v7.2-rcX. Today, I
> found that it fails with block/for-next branch tip [2]. I bisected and found
> that this patch triggers the failure.
> 
> 0wnerDied, Keith, may I ask your help to resolve the failure? I'm guessing
> the test case needs to care device's dma alignment, but not so sure.

I took a closer look. I modified the test case to respect the dma alignment [*],
and now the test case passes. This approach looks working. Will post the change
as a formal patch for review.

[*] fix trial patch for blktests

diff --git a/src/bio-full-trim.c b/src/bio-full-trim.c
index e304b2c..7cea3f9 100644
--- a/src/bio-full-trim.c
+++ b/src/bio-full-trim.c
@@ -12,20 +12,38 @@
 #include <sys/mman.h>
 #include <unistd.h>
 
+int msb(unsigned int v)
+{
+	unsigned int b = 0;
+
+	while (v >>= 1)
+		b++;
+
+	return b;
+}
+
 int main(int argc, char **argv)
 {
 	unsigned int block_size;
 	unsigned char *p;
 	long page_size;
+	unsigned int dma_alignment;
+	unsigned int dma_aligned_offset;
 	ssize_t ret;
 	int fd;
 
-	if (argc != 2)
+	if (argc != 3)
 		return EXIT_FAILURE;
+
 	page_size = sysconf(_SC_PAGESIZE);
 	if (page_size <= 0)
 		errx(EXIT_FAILURE, "invalid page size");
 
+	dma_alignment = atoi(argv[2]);
+	dma_aligned_offset = 1 << (msb(dma_alignment) + 1);
+	if (dma_aligned_offset >= page_size)
+		err(EXIT_FAILURE, "unexpected dma_alignment");
+
 	fd = open(argv[1], O_RDONLY | O_DIRECT);
 	if (fd < 0)
 		err(EXIT_FAILURE, "open %s", argv[1]);
@@ -40,7 +58,7 @@ int main(int argc, char **argv)
 		err(EXIT_FAILURE, "mprotect");
 
 	errno = 0;
-	ret = pread(fd, p + page_size - 1, block_size, 0);
+	ret = pread(fd, p + page_size - dma_aligned_offset, block_size, 0);
 	if (ret == -1 && errno == EFAULT)
 		return EXIT_SUCCESS;
 	errx(EXIT_FAILURE, "pread returned %zd (errno %d)", ret, errno);
diff --git a/tests/block/045 b/tests/block/045
index 65bfcb9..6e112b6 100755
--- a/tests/block/045
+++ b/tests/block/045
@@ -25,7 +25,8 @@ test() {
 		return 1
 	fi
 
-	if ! src/bio-full-trim /dev/nullb1; then
+	if ! src/bio-full-trim /dev/nullb1 \
+	     $(< /sys/block/nullb1/queue/dma_alignment); then
 		echo "bio-full-trim helper failed"
 	fi
 
-- 
2.55.0


  reply	other threads:[~2026-08-06  8:04 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-20 20:10 [PATCH RESEND 0/5] block: validate direct I/O memory alignment Keith Busch
2026-07-20 20:10 ` [PATCH RESEND 1/5] block: use blkdev_iov_iter_get_pages status for errors Keith Busch
2026-07-20 20:10 ` [PATCH RESEND 2/5] block: fix dio leak on metadata mapping error Keith Busch
2026-07-20 20:10 ` [PATCH RESEND 3/5] loop: set dma_alignment from the backing file for direct I/O Keith Busch
2026-07-20 20:10 ` [PATCH RESEND 4/5] zloop: set dma_alignment from the backing files " Keith Busch
2026-07-20 20:10 ` [PATCH RESEND 5/5] block: validate user space vectors during extraction Keith Busch
2026-08-05 12:46   ` Shin'ichiro Kawasaki
2026-08-06  8:03     ` Shin'ichiro Kawasaki [this message]
2026-08-06  8:29       ` 0wnerD1ed
2026-08-06  9:54         ` Shin'ichiro Kawasaki
2026-07-29 19:15 ` [PATCH RESEND 0/5] block: validate direct I/O memory alignment Keith Busch
2026-07-29 19:18   ` Jens Axboe
2026-07-29 20:03     ` Keith Busch
2026-07-29 23:34       ` Jens Axboe
2026-07-30 11:26       ` Christoph Hellwig
2026-07-30 12:52         ` Keith Busch
2026-07-30 16:22           ` Jens Axboe
2026-07-30 13:25         ` Thorsten Leemhuis
2026-07-30 16:23           ` Jens Axboe
2026-07-30 16:46             ` Linus Torvalds
2026-07-31 14:11 ` Jens Axboe

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=anQ-28nxOqBmQjxu@shinmob \
    --to=shinichiro.kawasaki@wdc.com \
    --cc=axboe@kernel.dk \
    --cc=brauner@kernel.org \
    --cc=djwong@kernel.org \
    --cc=dm-devel@lists.linux.dev \
    --cc=hare@kernel.org \
    --cc=hch@lst.de \
    --cc=kbusch@kernel.org \
    --cc=kbusch@meta.com \
    --cc=l7z@0b1t.tech \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /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