public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Keith Busch <kbusch@kernel.org>
To: Jens Axboe <axboe@kernel.dk>
Cc: Keith Busch <kbusch@meta.com>,
	linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	linux-kernel@vger.kernel.org, snitzer@kernel.org, dw@davidwei.uk,
	brauner@kernel.org
Subject: Re: [PATCH 0/7] direct-io: even more flexible io vectors
Date: Mon, 4 Aug 2025 11:06:12 -0600	[thread overview]
Message-ID: <aJDohO7v7lMWxn7V@kbusch-mbp> (raw)
In-Reply-To: <43716438-2fb9-4377-a4a0-6f803d7b8aec@kernel.dk>

On Sat, Aug 02, 2025 at 09:37:32AM -0600, Jens Axboe wrote:
> Did you write some test cases for this?

I have some crude unit tests to hit specific conditions that might
happen with nvme.

Note, the "second" test here will fail with the wrong result with this
version of the patchset due to the issue I mentioned on patch 2, but
I've a fix for it ready for the next version.

---
/*
 * This test is aligned to NVMe's PRP virtual boundary. It is intended to
 * execute on such a device with 4k formatted logical block size.
 *
 * The first test will submit a vectored read with a total size aligned to a 4k
 * block, but individual vectors may not be. This should be successful.
 *
 * The second test will submit a vectored read with a total size aligned to a
 * 4k block, but the first vector contains an invalid address. This should get
 * EFAULT.
 *
 * The third one will submit an IO with a total size aligned to a 4k block,
 * but it will fail the virtual boundary condition, which should result in a
 * split to a 0 length bio. This should get an EINVAL.
 *
 * The fourth test will submit IO with a total size aligned to a 4k block, but
 * with invalid DMA offsets. This should get an EINVAL.
 *
 * The last test will submit a large IO with a page offset that should exceed
 * the bio max vectors limit, resulting in reverting part of a bio iteration.
 * This should be successful.
 */
#define _GNU_SOURCE
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <sys/uio.h>
#include <string.h>

#define BSIZE (8 * 1024 * 1024)
#define VECS 4

int main(int argc, char **argv)
{
        int fd, ret, i, j;
        struct iovec iov[VECS];
        char *buf;

        if (argc < 2)
                return -1;

        fd = open(argv[1], O_RDONLY | O_DIRECT);
        if (fd < 0)
                return fd;

        ret = posix_memalign((void **)&buf, 4096, BSIZE);
        if (ret)
                return ret;

        memset(buf, 0, BSIZE);

        iov[0].iov_base = buf + 3072;
        iov[0].iov_len = 1024;

        iov[1].iov_base = buf + (2 * 4096);
        iov[1].iov_len = 4096;

        iov[2].iov_base = buf + (8 * 4096);
        iov[2].iov_len = 4096;

        iov[3].iov_base = buf + (16 * 4096);
        iov[3].iov_len = 3072;

        ret = preadv(fd, iov, VECS, 0);
        if (ret < 0)
                perror("unexpected read failure");

        iov[0].iov_base = 0;
        ret = preadv(fd, iov, VECS, 0);
        if (ret < 0)
                perror("expected read failure for invalid address");

        iov[0].iov_base = buf;
        iov[0].iov_len = 1024;

        iov[1].iov_base = buf + (2 * 4096);
        iov[1].iov_len = 1024;

        iov[2].iov_base = buf + (8 * 4096);
        iov[2].iov_len = 1024;

        iov[3].iov_base = buf + (16 * 4096);
        iov[3].iov_len = 1024;

        ret = preadv(fd, iov, VECS, 0);
        if (ret < 0)
                perror("expected read for invalid virtual boundary");

        iov[0].iov_base = buf + 3072;
        iov[0].iov_len = 1025;

        iov[1].iov_base = buf + (2 * 4096);
        iov[1].iov_len = 4096;

        iov[2].iov_base = buf + (8 * 4096);
        iov[2].iov_len = 4096;

        iov[3].iov_base = buf + (16 * 4096);
        iov[3].iov_len = 3073;

        ret = preadv(fd, iov, VECS, 0);
        if (ret < 0)
                perror("expected read for invalid dma boundary");

        ret = pread(fd, buf + 2048, BSIZE - 8192, 0);
        if (ret < 0)
                perror("unexpected large read failure");

        free(buf);
        return errno;
}
--

  reply	other threads:[~2025-08-04 17:06 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-01 23:47 [PATCH 0/7] direct-io: even more flexible io vectors Keith Busch
2025-08-01 23:47 ` [PATCH 1/7] block: check for valid bio while splitting Keith Busch
2025-08-04  6:54   ` Hannes Reinecke
2025-08-01 23:47 ` [PATCH 2/7] block: align the bio after building it Keith Busch
2025-08-04  6:54   ` Hannes Reinecke
2025-08-04 14:08     ` Keith Busch
2025-08-04 16:47       ` Keith Busch
2025-08-05  6:54       ` Hannes Reinecke
2025-08-01 23:47 ` [PATCH 3/7] block: simplify direct io validity check Keith Busch
2025-08-04  6:55   ` Hannes Reinecke
2025-08-04 17:11     ` Keith Busch
2025-08-05  6:57       ` Hannes Reinecke
2025-08-01 23:47 ` [PATCH 4/7] iomap: " Keith Busch
2025-08-04  6:57   ` Hannes Reinecke
2025-08-01 23:47 ` [PATCH 5/7] block: remove bdev_iter_is_aligned Keith Busch
2025-08-04  6:57   ` Hannes Reinecke
2025-08-01 23:47 ` [PATCH 6/7] blk-integrity: use simpler alignment check Keith Busch
2025-08-04  6:58   ` Hannes Reinecke
2025-08-01 23:47 ` [PATCH 7/7] iov_iter: remove iov_iter_is_aligned Keith Busch
2025-08-02  2:02   ` Mike Snitzer
2025-08-04 14:16     ` Keith Busch
2025-08-04 15:25       ` Mike Snitzer
2025-08-04 15:27         ` Mike Snitzer
2025-08-04 22:26         ` Mike Snitzer
2025-08-04 22:57           ` Keith Busch
2025-08-05  0:24   ` Mike Snitzer
2025-08-02 15:37 ` [PATCH 0/7] direct-io: even more flexible io vectors Jens Axboe
2025-08-04 17:06   ` Keith Busch [this message]
2025-08-04 23:45     ` Keith Busch

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=aJDohO7v7lMWxn7V@kbusch-mbp \
    --to=kbusch@kernel.org \
    --cc=axboe@kernel.dk \
    --cc=brauner@kernel.org \
    --cc=dw@davidwei.uk \
    --cc=kbusch@meta.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=snitzer@kernel.org \
    /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