From: Jens Axboe <axboe@kernel.dk>
To: Pavel Begunkov <asml.silence@gmail.com>,
Nitesh Shetty <nj.shetty@samsung.com>
Cc: io-uring@vger.kernel.org
Subject: Re: [PATCH 4/4] io_uring/rsrc: send exact nr_segs for fixed buffer
Date: Thu, 17 Apr 2025 07:57:33 -0600 [thread overview]
Message-ID: <f8e4d7d9-fb06-4a1b-9cba-0a42982bce48@kernel.dk> (raw)
In-Reply-To: <603628d3-78ec-47a3-804a-ee6dc93639fd@kernel.dk>
On 4/17/25 7:41 AM, Jens Axboe wrote:
> I'll turn the test case into something we can add to liburing, and fold
> in that change.
Here's what I tested, fwiw, and it reliably blows up pre the fixup. I'll
turn it into a normal test case, and then folks can add more invariants
to this one if they wish.
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <liburing.h>
static struct iovec vec;
static int read_it(struct io_uring *ring, int fd, int len, int off)
{
struct io_uring_sqe *sqe;
struct io_uring_cqe *cqe;
int ret;
sqe = io_uring_get_sqe(ring);
io_uring_prep_read_fixed(sqe, fd, vec.iov_base + off, len, 0, 0);
sqe->user_data = 1;
io_uring_submit(ring);
ret = io_uring_wait_cqe(ring, &cqe);
if (ret) {
fprintf(stderr, "wait %d\n", ret);
return 1;
}
if (cqe->res < 0) {
fprintf(stderr, "cqe res %s\n", strerror(-cqe->res));
return 1;
}
if (cqe->res != len) {
fprintf(stderr, "Bad read amount: %d\n", cqe->res);
return 1;
}
io_uring_cqe_seen(ring, cqe);
return 0;
}
static int test(struct io_uring *ring, int fd, int vec_off)
{
struct iovec v = vec;
int ret;
v.iov_base += vec_off;
v.iov_len -= vec_off;
ret = io_uring_register_buffers(ring, &v, 1);
if (ret) {
fprintf(stderr, "Vec register: %d\n", ret);
return 1;
}
ret = read_it(ring, fd, 4096, vec_off);
if (ret) {
fprintf(stderr, "4096 0 failed\n");
return 1;
}
ret = read_it(ring, fd, 8192, 4096);
if (ret) {
fprintf(stderr, "8192 4096 failed\n");
return 1;
}
ret = read_it(ring, fd, 4096, 4096);
if (ret) {
fprintf(stderr, "4096 4096 failed\n");
return 1;
}
io_uring_unregister_buffers(ring);
return 0;
}
int main(int argc, char *argv[])
{
struct io_uring ring;
int fd, ret;
if (argc == 1) {
printf("%s: <file>\n", argv[0]);
return 1;
}
fd = open(argv[1], O_RDONLY | O_DIRECT);
if (fd < 0) {
perror("open");
return 1;
}
posix_memalign(&vec.iov_base, 4096, 512*1024);
vec.iov_len = 512*1024;
io_uring_queue_init(32, &ring, 0);
ret = test(&ring, fd, 0);
if (ret) {
fprintf(stderr, "test 0 failed\n");
return 1;
}
ret = test(&ring, fd, 512);
if (ret) {
fprintf(stderr, "test 512 failed\n");
return 1;
}
close(fd);
io_uring_queue_exit(&ring);
return 0;
}
--
Jens Axboe
next prev parent reply other threads:[~2025-04-17 13:57 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-17 9:32 [PATCH 0/4] io_import_fixed cleanups and optimisation Pavel Begunkov
2025-04-17 9:32 ` [PATCH 1/4] io_uring/rsrc: don't skip offset calculation Pavel Begunkov
2025-04-17 9:32 ` [PATCH 2/4] io_uring/rsrc: separate kbuf offset adjustments Pavel Begunkov
2025-04-17 9:32 ` [PATCH 3/4] io_uring/rsrc: refactor io_import_fixed Pavel Begunkov
2025-04-17 9:32 ` [PATCH 4/4] io_uring/rsrc: send exact nr_segs for fixed buffer Pavel Begunkov
2025-04-17 9:34 ` Pavel Begunkov
[not found] ` <CGME20250417103133epcas5p32c1e004e7f8a5135c4c7e3662b087470@epcas5p3.samsung.com>
2025-04-17 10:23 ` Nitesh Shetty
2025-04-17 11:50 ` Nitesh Shetty
2025-04-17 12:56 ` Pavel Begunkov
2025-04-17 13:41 ` Jens Axboe
2025-04-17 13:57 ` Jens Axboe [this message]
2025-04-17 14:02 ` Pavel Begunkov
2025-04-17 14:05 ` Jens Axboe
2025-04-17 12:31 ` [PATCH 0/4] io_import_fixed cleanups and optimisation Jens Axboe
[not found] ` <CGME20250417142334epcas5p36df55874d21c896115d92e505f9793fd@epcas5p3.samsung.com>
2025-04-17 14:15 ` Nitesh Shetty
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=f8e4d7d9-fb06-4a1b-9cba-0a42982bce48@kernel.dk \
--to=axboe@kernel.dk \
--cc=asml.silence@gmail.com \
--cc=io-uring@vger.kernel.org \
--cc=nj.shetty@samsung.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