Skip to content

Commit aebb224

Browse files
Dylan Yudakenaxboe
authored andcommitted
io_uring: for requests that require async, force it
Some requests require being run async as they do not support non-blocking. Instead of trying to issue these requests, getting -EAGAIN and then queueing them for async issue, rather just force async upfront. Add WARN_ON_ONCE to make sure surprising code paths do not come up, however in those cases the bug would end up being a blocking io_uring_enter(2) which should not be critical. Signed-off-by: Dylan Yudaken <dylany@meta.com> Link: https://lore.kernel.org/r/20230127135227.3646353-3-dylany@meta.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 6bb3085 commit aebb224

File tree

7 files changed

+33
-34
lines changed

7 files changed

+33
-34
lines changed

io_uring/advise.c

Lines changed: 2 additions & 2 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);

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);

io_uring/net.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ int io_shutdown_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
9090
return -EINVAL;
9191

9292
shutdown->how = READ_ONCE(sqe->len);
93+
req->flags |= REQ_F_FORCE_ASYNC;
9394
return 0;
9495
}
9596

@@ -99,8 +100,7 @@ int io_shutdown(struct io_kiocb *req, unsigned int issue_flags)
99100
struct socket *sock;
100101
int ret;
101102

102-
if (issue_flags & IO_URING_F_NONBLOCK)
103-
return -EAGAIN;
103+
WARN_ON_ONCE(issue_flags & IO_URING_F_NONBLOCK);
104104

105105
sock = sock_from_file(req->file);
106106
if (unlikely(!sock))

io_uring/splice.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ static int __io_splice_prep(struct io_kiocb *req,
3434
if (unlikely(sp->flags & ~valid_flags))
3535
return -EINVAL;
3636
sp->splice_fd_in = READ_ONCE(sqe->splice_fd_in);
37+
req->flags |= REQ_F_FORCE_ASYNC;
3738
return 0;
3839
}
3940

@@ -52,8 +53,7 @@ int io_tee(struct io_kiocb *req, unsigned int issue_flags)
5253
struct file *in;
5354
long ret = 0;
5455

55-
if (issue_flags & IO_URING_F_NONBLOCK)
56-
return -EAGAIN;
56+
WARN_ON_ONCE(issue_flags & IO_URING_F_NONBLOCK);
5757

5858
if (sp->flags & SPLICE_F_FD_IN_FIXED)
5959
in = io_file_get_fixed(req, sp->splice_fd_in, issue_flags);
@@ -94,8 +94,7 @@ int io_splice(struct io_kiocb *req, unsigned int issue_flags)
9494
struct file *in;
9595
long ret = 0;
9696

97-
if (issue_flags & IO_URING_F_NONBLOCK)
98-
return -EAGAIN;
97+
WARN_ON_ONCE(issue_flags & IO_URING_F_NONBLOCK);
9998

10099
if (sp->flags & SPLICE_F_FD_IN_FIXED)
101100
in = io_file_get_fixed(req, sp->splice_fd_in, issue_flags);

io_uring/statx.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ int io_statx_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
4848
}
4949

5050
req->flags |= REQ_F_NEED_CLEANUP;
51+
req->flags |= REQ_F_FORCE_ASYNC;
5152
return 0;
5253
}
5354

@@ -56,8 +57,7 @@ int io_statx(struct io_kiocb *req, unsigned int issue_flags)
5657
struct io_statx *sx = io_kiocb_to_cmd(req, struct io_statx);
5758
int ret;
5859

59-
if (issue_flags & IO_URING_F_NONBLOCK)
60-
return -EAGAIN;
60+
WARN_ON_ONCE(issue_flags & IO_URING_F_NONBLOCK);
6161

6262
ret = do_statx(sx->dfd, sx->filename, sx->flags, sx->mask, sx->buffer);
6363
io_req_set_res(req, ret, 0);

io_uring/sync.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ int io_sfr_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
3232
sync->off = READ_ONCE(sqe->off);
3333
sync->len = READ_ONCE(sqe->len);
3434
sync->flags = READ_ONCE(sqe->sync_range_flags);
35+
req->flags |= REQ_F_FORCE_ASYNC;
36+
3537
return 0;
3638
}
3739

@@ -41,8 +43,7 @@ int io_sync_file_range(struct io_kiocb *req, unsigned int issue_flags)
4143
int ret;
4244

4345
/* sync_file_range always requires a blocking context */
44-
if (issue_flags & IO_URING_F_NONBLOCK)
45-
return -EAGAIN;
46+
WARN_ON_ONCE(issue_flags & IO_URING_F_NONBLOCK);
4647

4748
ret = sync_file_range(req->file, sync->off, sync->len, sync->flags);
4849
io_req_set_res(req, ret, 0);
@@ -62,6 +63,7 @@ int io_fsync_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
6263

6364
sync->off = READ_ONCE(sqe->off);
6465
sync->len = READ_ONCE(sqe->len);
66+
req->flags |= REQ_F_FORCE_ASYNC;
6567
return 0;
6668
}
6769

@@ -72,8 +74,7 @@ int io_fsync(struct io_kiocb *req, unsigned int issue_flags)
7274
int ret;
7375

7476
/* fsync always requires a blocking context */
75-
if (issue_flags & IO_URING_F_NONBLOCK)
76-
return -EAGAIN;
77+
WARN_ON_ONCE(issue_flags & IO_URING_F_NONBLOCK);
7778

7879
ret = vfs_fsync_range(req->file, sync->off, end > 0 ? end : LLONG_MAX,
7980
sync->flags & IORING_FSYNC_DATASYNC);
@@ -91,6 +92,7 @@ int io_fallocate_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
9192
sync->off = READ_ONCE(sqe->off);
9293
sync->len = READ_ONCE(sqe->addr);
9394
sync->mode = READ_ONCE(sqe->len);
95+
req->flags |= REQ_F_FORCE_ASYNC;
9496
return 0;
9597
}
9698

@@ -100,8 +102,8 @@ int io_fallocate(struct io_kiocb *req, unsigned int issue_flags)
100102
int ret;
101103

102104
/* fallocate always requiring blocking context */
103-
if (issue_flags & IO_URING_F_NONBLOCK)
104-
return -EAGAIN;
105+
WARN_ON_ONCE(issue_flags & IO_URING_F_NONBLOCK);
106+
105107
ret = vfs_fallocate(req->file, sync->mode, sync->off, sync->len);
106108
if (ret >= 0)
107109
fsnotify_modify(req->file);

io_uring/xattr.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ static int __io_getxattr_prep(struct io_kiocb *req,
7575
}
7676

7777
req->flags |= REQ_F_NEED_CLEANUP;
78+
req->flags |= REQ_F_FORCE_ASYNC;
7879
return 0;
7980
}
8081

@@ -109,8 +110,7 @@ int io_fgetxattr(struct io_kiocb *req, unsigned int issue_flags)
109110
struct io_xattr *ix = io_kiocb_to_cmd(req, struct io_xattr);
110111
int ret;
111112

112-
if (issue_flags & IO_URING_F_NONBLOCK)
113-
return -EAGAIN;
113+
WARN_ON_ONCE(issue_flags & IO_URING_F_NONBLOCK);
114114

115115
ret = do_getxattr(mnt_idmap(req->file->f_path.mnt),
116116
req->file->f_path.dentry,
@@ -127,8 +127,7 @@ int io_getxattr(struct io_kiocb *req, unsigned int issue_flags)
127127
struct path path;
128128
int ret;
129129

130-
if (issue_flags & IO_URING_F_NONBLOCK)
131-
return -EAGAIN;
130+
WARN_ON_ONCE(issue_flags & IO_URING_F_NONBLOCK);
132131

133132
retry:
134133
ret = filename_lookup(AT_FDCWD, ix->filename, lookup_flags, &path, NULL);
@@ -174,6 +173,7 @@ static int __io_setxattr_prep(struct io_kiocb *req,
174173
}
175174

176175
req->flags |= REQ_F_NEED_CLEANUP;
176+
req->flags |= REQ_F_FORCE_ASYNC;
177177
return 0;
178178
}
179179

@@ -222,8 +222,7 @@ int io_fsetxattr(struct io_kiocb *req, unsigned int issue_flags)
222222
{
223223
int ret;
224224

225-
if (issue_flags & IO_URING_F_NONBLOCK)
226-
return -EAGAIN;
225+
WARN_ON_ONCE(issue_flags & IO_URING_F_NONBLOCK);
227226

228227
ret = __io_setxattr(req, issue_flags, &req->file->f_path);
229228
io_xattr_finish(req, ret);
@@ -237,8 +236,7 @@ int io_setxattr(struct io_kiocb *req, unsigned int issue_flags)
237236
struct path path;
238237
int ret;
239238

240-
if (issue_flags & IO_URING_F_NONBLOCK)
241-
return -EAGAIN;
239+
WARN_ON_ONCE(issue_flags & IO_URING_F_NONBLOCK);
242240

243241
retry:
244242
ret = filename_lookup(AT_FDCWD, ix->filename, lookup_flags, &path, NULL);

0 commit comments

Comments
 (0)