Skip to content

Commit cce5fe5

Browse files
committed
Merge tag 'for-6.3/io_uring-2023-02-16' of git://git.kernel.dk/linux
Pull io_uring updates from Jens Axboe: - Cleanup series making the async prep and handling of REQ_F_FORCE_ASYNC easier to follow and verify (Dylan) - Enable specifying specific flags for OP_MSG_RING (Breno) - Enable use of KASAN with the internal request cache (Breno) - Split the opcode definition structs into a hot and cold part (Breno) - OP_MSG_RING fixes (Pavel, me) - Fix an issue with IOPOLL cancelation and PREEMPT_NONE (me) - Handle TIF_NOTIFY_RESUME for the io-wq threads that never return to userspace (me) - Add support for using io_uring_register() with a registered ring fd (Josh) - Improve handling of poll on the ring fd (Pavel) - Series improving the task_work handling (Pavel) - Misc cleanups, fixes, improvements (Dmitrii, Quanfa, Richard, Pavel, me) * tag 'for-6.3/io_uring-2023-02-16' of git://git.kernel.dk/linux: (51 commits) io_uring: Support calling io_uring_register with a registered ring fd io_uring,audit: don't log IORING_OP_MADVISE io_uring: mark task TASK_RUNNING before handling resume/task work io_uring: always go async for unsupported open flags io_uring: always go async for unsupported fadvise flags io_uring: for requests that require async, force it io_uring: if a linked request has REQ_F_FORCE_ASYNC then run it async io_uring: add reschedule point to handle_tw_list() io_uring: add a conditional reschedule to the IOPOLL cancelation loop io_uring: return normal tw run linking optimisation io_uring: refactor tctx_task_work io_uring: refactor io_put_task helpers io_uring: refactor req allocation io_uring: improve io_get_sqe io_uring: kill outdated comment about overflow flush io_uring: use user visible tail in io_uring_poll() io_uring: pass in io_issue_def to io_assign_file() io_uring: Enable KASAN for request cache io_uring: handle TIF_NOTIFY_RESUME when checking for task_work io_uring/msg-ring: ensure flags passing works for task_work completions ...
2 parents eca3a04 + 7d3fd88 commit cce5fe5

File tree

20 files changed

+699
-409
lines changed

20 files changed

+699
-409
lines changed

include/linux/io_uring_types.h

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -195,21 +195,23 @@ struct io_alloc_cache {
195195
struct io_ring_ctx {
196196
/* const or read-mostly hot data */
197197
struct {
198-
struct percpu_ref refs;
199-
200-
struct io_rings *rings;
201198
unsigned int flags;
202-
enum task_work_notify_mode notify_method;
203-
unsigned int compat: 1;
204199
unsigned int drain_next: 1;
205200
unsigned int restricted: 1;
206201
unsigned int off_timeout_used: 1;
207202
unsigned int drain_active: 1;
208-
unsigned int drain_disabled: 1;
209203
unsigned int has_evfd: 1;
210-
unsigned int syscall_iopoll: 1;
211204
/* all CQEs should be posted only by the submitter task */
212205
unsigned int task_complete: 1;
206+
unsigned int syscall_iopoll: 1;
207+
unsigned int poll_activated: 1;
208+
unsigned int drain_disabled: 1;
209+
unsigned int compat: 1;
210+
211+
enum task_work_notify_mode notify_method;
212+
struct io_rings *rings;
213+
struct task_struct *submitter_task;
214+
struct percpu_ref refs;
213215
} ____cacheline_aligned_in_smp;
214216

215217
/* submission data */
@@ -293,6 +295,7 @@ struct io_ring_ctx {
293295
spinlock_t completion_lock;
294296

295297
bool poll_multi_queue;
298+
bool cq_waiting;
296299

297300
/*
298301
* ->iopoll_list is protected by the ctx->uring_lock for
@@ -318,9 +321,8 @@ struct io_ring_ctx {
318321
} ____cacheline_aligned_in_smp;
319322

320323
/* Keep this last, we don't need it for the fast path */
321-
324+
struct wait_queue_head poll_wq;
322325
struct io_restriction restrictions;
323-
struct task_struct *submitter_task;
324326

325327
/* slow path rsrc auxilary data, used by update/register */
326328
struct io_rsrc_node *rsrc_backup_node;
@@ -357,6 +359,7 @@ struct io_ring_ctx {
357359
u32 iowq_limits[2];
358360
bool iowq_limits_set;
359361

362+
struct callback_head poll_wq_task_work;
360363
struct list_head defer_list;
361364
unsigned sq_thread_idle;
362365
/* protected by ->completion_lock */

include/uapi/linux/io_uring.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,8 @@ enum {
347347
* applicable for IORING_MSG_DATA, obviously.
348348
*/
349349
#define IORING_MSG_RING_CQE_SKIP (1U << 0)
350+
/* Pass through the flags from sqe->file_index to cqe->flags */
351+
#define IORING_MSG_RING_FLAGS_PASS (1U << 1)
350352

351353
/*
352354
* IO completion data structure (Completion Queue Entry)
@@ -470,6 +472,7 @@ struct io_uring_params {
470472
#define IORING_FEAT_RSRC_TAGS (1U << 10)
471473
#define IORING_FEAT_CQE_SKIP (1U << 11)
472474
#define IORING_FEAT_LINKED_FILE (1U << 12)
475+
#define IORING_FEAT_REG_REG_RING (1U << 13)
473476

474477
/*
475478
* io_uring_register(2) opcodes and arguments
@@ -517,7 +520,10 @@ enum {
517520
IORING_REGISTER_FILE_ALLOC_RANGE = 25,
518521

519522
/* this goes last */
520-
IORING_REGISTER_LAST
523+
IORING_REGISTER_LAST,
524+
525+
/* flag added to the opcode to use a registered ring fd */
526+
IORING_REGISTER_USE_REGISTERED_RING = 1U << 31
521527
};
522528

523529
/* io-wq worker categories */

io_uring/advise.c

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ int io_madvise_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
3939
ma->addr = READ_ONCE(sqe->addr);
4040
ma->len = READ_ONCE(sqe->len);
4141
ma->advice = READ_ONCE(sqe->fadvise_advice);
42+
req->flags |= REQ_F_FORCE_ASYNC;
4243
return 0;
4344
#else
4445
return -EOPNOTSUPP;
@@ -51,8 +52,7 @@ int io_madvise(struct io_kiocb *req, unsigned int issue_flags)
5152
struct io_madvise *ma = io_kiocb_to_cmd(req, struct io_madvise);
5253
int ret;
5354

54-
if (issue_flags & IO_URING_F_NONBLOCK)
55-
return -EAGAIN;
55+
WARN_ON_ONCE(issue_flags & IO_URING_F_NONBLOCK);
5656

5757
ret = do_madvise(current->mm, ma->addr, ma->len, ma->advice);
5858
io_req_set_res(req, ret, 0);
@@ -62,6 +62,18 @@ int io_madvise(struct io_kiocb *req, unsigned int issue_flags)
6262
#endif
6363
}
6464

65+
static bool io_fadvise_force_async(struct io_fadvise *fa)
66+
{
67+
switch (fa->advice) {
68+
case POSIX_FADV_NORMAL:
69+
case POSIX_FADV_RANDOM:
70+
case POSIX_FADV_SEQUENTIAL:
71+
return false;
72+
default:
73+
return true;
74+
}
75+
}
76+
6577
int io_fadvise_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
6678
{
6779
struct io_fadvise *fa = io_kiocb_to_cmd(req, struct io_fadvise);
@@ -72,6 +84,8 @@ int io_fadvise_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
7284
fa->offset = READ_ONCE(sqe->off);
7385
fa->len = READ_ONCE(sqe->len);
7486
fa->advice = READ_ONCE(sqe->fadvise_advice);
87+
if (io_fadvise_force_async(fa))
88+
req->flags |= REQ_F_FORCE_ASYNC;
7589
return 0;
7690
}
7791

@@ -80,16 +94,7 @@ int io_fadvise(struct io_kiocb *req, unsigned int issue_flags)
8094
struct io_fadvise *fa = io_kiocb_to_cmd(req, struct io_fadvise);
8195
int ret;
8296

83-
if (issue_flags & IO_URING_F_NONBLOCK) {
84-
switch (fa->advice) {
85-
case POSIX_FADV_NORMAL:
86-
case POSIX_FADV_RANDOM:
87-
case POSIX_FADV_SEQUENTIAL:
88-
break;
89-
default:
90-
return -EAGAIN;
91-
}
92-
}
97+
WARN_ON_ONCE(issue_flags & IO_URING_F_NONBLOCK && io_fadvise_force_async(fa));
9398

9499
ret = vfs_fadvise(req->file, fa->offset, fa->len, fa->advice);
95100
if (ret < 0)

io_uring/fs.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ int io_renameat_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
7474
}
7575

7676
req->flags |= REQ_F_NEED_CLEANUP;
77+
req->flags |= REQ_F_FORCE_ASYNC;
7778
return 0;
7879
}
7980

@@ -82,8 +83,7 @@ int io_renameat(struct io_kiocb *req, unsigned int issue_flags)
8283
struct io_rename *ren = io_kiocb_to_cmd(req, struct io_rename);
8384
int ret;
8485

85-
if (issue_flags & IO_URING_F_NONBLOCK)
86-
return -EAGAIN;
86+
WARN_ON_ONCE(issue_flags & IO_URING_F_NONBLOCK);
8787

8888
ret = do_renameat2(ren->old_dfd, ren->oldpath, ren->new_dfd,
8989
ren->newpath, ren->flags);
@@ -123,6 +123,7 @@ int io_unlinkat_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
123123
return PTR_ERR(un->filename);
124124

125125
req->flags |= REQ_F_NEED_CLEANUP;
126+
req->flags |= REQ_F_FORCE_ASYNC;
126127
return 0;
127128
}
128129

@@ -131,8 +132,7 @@ int io_unlinkat(struct io_kiocb *req, unsigned int issue_flags)
131132
struct io_unlink *un = io_kiocb_to_cmd(req, struct io_unlink);
132133
int ret;
133134

134-
if (issue_flags & IO_URING_F_NONBLOCK)
135-
return -EAGAIN;
135+
WARN_ON_ONCE(issue_flags & IO_URING_F_NONBLOCK);
136136

137137
if (un->flags & AT_REMOVEDIR)
138138
ret = do_rmdir(un->dfd, un->filename);
@@ -170,6 +170,7 @@ int io_mkdirat_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
170170
return PTR_ERR(mkd->filename);
171171

172172
req->flags |= REQ_F_NEED_CLEANUP;
173+
req->flags |= REQ_F_FORCE_ASYNC;
173174
return 0;
174175
}
175176

@@ -178,8 +179,7 @@ int io_mkdirat(struct io_kiocb *req, unsigned int issue_flags)
178179
struct io_mkdir *mkd = io_kiocb_to_cmd(req, struct io_mkdir);
179180
int ret;
180181

181-
if (issue_flags & IO_URING_F_NONBLOCK)
182-
return -EAGAIN;
182+
WARN_ON_ONCE(issue_flags & IO_URING_F_NONBLOCK);
183183

184184
ret = do_mkdirat(mkd->dfd, mkd->filename, mkd->mode);
185185

@@ -220,6 +220,7 @@ int io_symlinkat_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
220220
}
221221

222222
req->flags |= REQ_F_NEED_CLEANUP;
223+
req->flags |= REQ_F_FORCE_ASYNC;
223224
return 0;
224225
}
225226

@@ -228,8 +229,7 @@ int io_symlinkat(struct io_kiocb *req, unsigned int issue_flags)
228229
struct io_link *sl = io_kiocb_to_cmd(req, struct io_link);
229230
int ret;
230231

231-
if (issue_flags & IO_URING_F_NONBLOCK)
232-
return -EAGAIN;
232+
WARN_ON_ONCE(issue_flags & IO_URING_F_NONBLOCK);
233233

234234
ret = do_symlinkat(sl->oldpath, sl->new_dfd, sl->newpath);
235235

@@ -265,6 +265,7 @@ int io_linkat_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
265265
}
266266

267267
req->flags |= REQ_F_NEED_CLEANUP;
268+
req->flags |= REQ_F_FORCE_ASYNC;
268269
return 0;
269270
}
270271

@@ -273,8 +274,7 @@ int io_linkat(struct io_kiocb *req, unsigned int issue_flags)
273274
struct io_link *lnk = io_kiocb_to_cmd(req, struct io_link);
274275
int ret;
275276

276-
if (issue_flags & IO_URING_F_NONBLOCK)
277-
return -EAGAIN;
277+
WARN_ON_ONCE(issue_flags & IO_URING_F_NONBLOCK);
278278

279279
ret = do_linkat(lnk->old_dfd, lnk->oldpath, lnk->new_dfd,
280280
lnk->newpath, lnk->flags);

0 commit comments

Comments
 (0)