Skip to content

Commit aacf2f9

Browse files
isilenceaxboe
authored andcommitted
io_uring: fix req->apoll_events
apoll_events should be set once in the beginning of poll arming just as poll->events and not change after. However, currently io_uring resets it on each __io_poll_execute() for no clear reason. There is also a place in __io_arm_poll_handler() where we add EPOLLONESHOT to downgrade a multishot, but forget to do the same thing with ->apoll_events, which is buggy. Fixes: 8145935 ("io_uring: cache req->apoll->events in req->cflags") Signed-off-by: Pavel Begunkov <[email protected]> Reviewed-by: Hao Xu <[email protected]> Link: https://lore.kernel.org/r/0aef40399ba75b1a4d2c2e85e6e8fd93c02fc6e4.1655814213.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <[email protected]>
1 parent b60cac1 commit aacf2f9

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

fs/io_uring.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6950,7 +6950,8 @@ static void io_apoll_task_func(struct io_kiocb *req, bool *locked)
69506950
io_req_complete_failed(req, ret);
69516951
}
69526952

6953-
static void __io_poll_execute(struct io_kiocb *req, int mask, __poll_t events)
6953+
static void __io_poll_execute(struct io_kiocb *req, int mask,
6954+
__poll_t __maybe_unused events)
69546955
{
69556956
req->cqe.res = mask;
69566957
/*
@@ -6959,7 +6960,6 @@ static void __io_poll_execute(struct io_kiocb *req, int mask, __poll_t events)
69596960
* CPU. We want to avoid pulling in req->apoll->events for that
69606961
* case.
69616962
*/
6962-
req->apoll_events = events;
69636963
if (req->opcode == IORING_OP_POLL_ADD)
69646964
req->io_task_work.func = io_poll_task_func;
69656965
else
@@ -7110,6 +7110,8 @@ static int __io_arm_poll_handler(struct io_kiocb *req,
71107110
io_init_poll_iocb(poll, mask, io_poll_wake);
71117111
poll->file = req->file;
71127112

7113+
req->apoll_events = poll->events;
7114+
71137115
ipt->pt._key = mask;
71147116
ipt->req = req;
71157117
ipt->error = 0;
@@ -7140,8 +7142,10 @@ static int __io_arm_poll_handler(struct io_kiocb *req,
71407142

71417143
if (mask) {
71427144
/* can't multishot if failed, just queue the event we've got */
7143-
if (unlikely(ipt->error || !ipt->nr_entries))
7145+
if (unlikely(ipt->error || !ipt->nr_entries)) {
71447146
poll->events |= EPOLLONESHOT;
7147+
req->apoll_events |= EPOLLONESHOT;
7148+
}
71457149
__io_poll_execute(req, mask, poll->events);
71467150
return 0;
71477151
}
@@ -7388,7 +7392,7 @@ static int io_poll_add_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe
73887392
return -EINVAL;
73897393

73907394
io_req_set_refcount(req);
7391-
req->apoll_events = poll->events = io_poll_parse_events(sqe, flags);
7395+
poll->events = io_poll_parse_events(sqe, flags);
73927396
return 0;
73937397
}
73947398

0 commit comments

Comments
 (0)