Skip to content

Commit a85f310

Browse files
committed
io_uring/nop: add support for testing registered files and buffers
Useful for testing performance/efficiency impact of registered files and buffers, vs (particularly) non-registered files. Signed-off-by: Jens Axboe <[email protected]>
1 parent aa00f67 commit a85f310

File tree

2 files changed

+47
-5
lines changed

2 files changed

+47
-5
lines changed

include/uapi/linux/io_uring.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,9 @@ enum io_uring_msg_ring_flags {
416416
* IORING_NOP_INJECT_RESULT Inject result from sqe->result
417417
*/
418418
#define IORING_NOP_INJECT_RESULT (1U << 0)
419+
#define IORING_NOP_FILE (1U << 1)
420+
#define IORING_NOP_FIXED_FILE (1U << 2)
421+
#define IORING_NOP_FIXED_BUFFER (1U << 3)
419422

420423
/*
421424
* IO completion data structure (Completion Queue Entry)

io_uring/nop.c

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,74 @@
88
#include <uapi/linux/io_uring.h>
99

1010
#include "io_uring.h"
11+
#include "rsrc.h"
1112
#include "nop.h"
1213

1314
struct io_nop {
1415
/* NOTE: kiocb has the file as the first member, so don't do it here */
1516
struct file *file;
1617
int result;
18+
int fd;
19+
int buffer;
20+
unsigned int flags;
1721
};
1822

23+
#define NOP_FLAGS (IORING_NOP_INJECT_RESULT | IORING_NOP_FIXED_FILE | \
24+
IORING_NOP_FIXED_BUFFER | IORING_NOP_FILE)
25+
1926
int io_nop_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
2027
{
21-
unsigned int flags;
2228
struct io_nop *nop = io_kiocb_to_cmd(req, struct io_nop);
2329

24-
flags = READ_ONCE(sqe->nop_flags);
25-
if (flags & ~IORING_NOP_INJECT_RESULT)
30+
nop->flags = READ_ONCE(sqe->nop_flags);
31+
if (nop->flags & ~NOP_FLAGS)
2632
return -EINVAL;
2733

28-
if (flags & IORING_NOP_INJECT_RESULT)
34+
if (nop->flags & IORING_NOP_INJECT_RESULT)
2935
nop->result = READ_ONCE(sqe->len);
3036
else
3137
nop->result = 0;
38+
if (nop->flags & IORING_NOP_FIXED_FILE)
39+
nop->fd = READ_ONCE(sqe->fd);
40+
if (nop->flags & IORING_NOP_FIXED_BUFFER)
41+
nop->buffer = READ_ONCE(sqe->buf_index);
3242
return 0;
3343
}
3444

3545
int io_nop(struct io_kiocb *req, unsigned int issue_flags)
3646
{
3747
struct io_nop *nop = io_kiocb_to_cmd(req, struct io_nop);
48+
int ret = nop->result;
49+
50+
if (nop->flags & IORING_NOP_FILE) {
51+
if (nop->flags & IORING_NOP_FIXED_FILE) {
52+
req->file = io_file_get_fixed(req, nop->fd, issue_flags);
53+
req->flags |= REQ_F_FIXED_FILE;
54+
} else {
55+
req->file = io_file_get_normal(req, nop->fd);
56+
}
57+
if (!req->file) {
58+
ret = -EBADF;
59+
goto done;
60+
}
61+
}
62+
if (nop->flags & IORING_NOP_FIXED_BUFFER) {
63+
struct io_ring_ctx *ctx = req->ctx;
64+
struct io_mapped_ubuf *imu;
65+
int idx;
3866

39-
if (nop->result < 0)
67+
ret = -EFAULT;
68+
io_ring_submit_lock(ctx, issue_flags);
69+
if (nop->buffer < ctx->nr_user_bufs) {
70+
idx = array_index_nospec(nop->buffer, ctx->nr_user_bufs);
71+
imu = READ_ONCE(ctx->user_bufs[idx]);
72+
io_req_set_rsrc_node(req, ctx);
73+
ret = 0;
74+
}
75+
io_ring_submit_unlock(ctx, issue_flags);
76+
}
77+
done:
78+
if (ret < 0)
4079
req_set_fail(req);
4180
io_req_set_res(req, nop->result, 0);
4281
return IOU_OK;

0 commit comments

Comments
 (0)