poll fixes
cover poll fixes
Several poll and apoll fixes for 5.19. I don't know if problems in 2-3 were occuring prior to "io_uring: poll rework", but let's at least back port it to that point.
I'll also be sending another clean up series for 5.20.
Pavel Begunkov (3):
io_uring: fail links when poll fails
io_uring: fix wrong arm_poll error handling
io_uring: fix double poll leak on repolling
fs/io_uring.c | 4 ++++ 1 file changed, 4 insertions(+)
Signature · 1 line
2.36.1
PATCH 1/3 io_uring: fail links when poll fails
Don't forget to cancel all linked requests of poll request when __io_arm_poll_handler() failed.
--- fs/io_uring.c | 2 ++ 1 file changed, 2 insertions(+)
fs/io_uring.c +2 -0
@@ -7405,6 +7405,8 @@ static int io_poll_add(struct io_kiocb *req, unsigned int issue_flags) ipt.pt._qproc = io_poll_queue_proc; ret =__io_arm_poll_handler (req, &req->poll, &ipt, poll->events); +if (!ret && ipt.error) +req_set_fail (req); ret = ret ?: ipt.error;if (ret)__io_req_complete (req, issue_flags, ret,0 );
Signature · 1 line
2.36.1
Jens Axboe
maintainerRe: [PATCH 5.19 1/3] io_uring: fail links when poll fails
Quoted 14 lines · Pavel Begunkov
Don't forget to cancel all linked requests of poll request when
__io_arm_poll_handler()failed.Fixes aa43477b04025 ("io_uring: poll rework")Signed-off-by Pavel Begunkov <[email protected]>--- fs/io_uring.c | 2 ++ 1 file changed, 2 insertions(+)fs/io_uring.c +0
-0
fs/io_uring.c static int io_poll_add(struct io_kiocb *req, unsigned int issue_flags) · line 7412
Quoted 8 lines
fs/io_uring.c +2
-0@@ -7405,6 +7405,8 @@ static int io_poll_add(struct io_kiocb *req, unsigned int issue_flags) ipt.pt._qproc = io_poll_queue_proc; ret =__io_arm_poll_handler (req, &req->poll, &ipt, poll->events); +if (!ret && ipt.error) +req_set_fail (req); ret = ret ?: ipt.error;if (ret)__io_req_complete (req, issue_flags, ret,0 );
We could make this:
if (!ret && ipt.error) {
req_set_fail(req);
ret = ipt.error;
}and kill that ternary, but we could also then go a bit further with the completion. So let's just leave that for 5.20.
Signature · 1 line
Jens Axboe
PATCH 2/3 io_uring: fix wrong arm_poll error handling
In reply to Pavel BegunkovLeaving ip.error set when a request was punted to task_work execution is problematic, don't forget to clear it.
--- fs/io_uring.c | 1 + 1 file changed, 1 insertion(+)
fs/io_uring.c +1 -0
@@ -7145,6 +7145,7 @@ static int __io_arm_poll_handler(struct io_kiocb *req,if (unlikely (ipt->error || !ipt->nr_entries)) { poll->events |=EPOLLONESHOT ; req->apoll_events |=EPOLLONESHOT ; + ipt->error =0 ; }__io_poll_execute (req, mask, poll->events);return 0 ;
Signature · 1 line
2.36.1
PATCH 3/3 io_uring: fix double poll leak on repolling
In reply to Pavel BegunkovWe have re-polling for partial IO, so a request can be polled twice. If it used two poll entries the first time then on the second io_arm_poll_handler() it will find the old apoll entry and NULL kmalloc()'ed second entry, i.e. apoll->double_poll, so leaking it.
--- fs/io_uring.c | 1 + 1 file changed, 1 insertion(+)
fs/io_uring.c +1 -0
@@ -7208,6 +7208,7 @@ static int io_arm_poll_handler(struct io_kiocb *req, unsigned issue_flags) mask |=EPOLLEXCLUSIVE ;if (req->flags &REQ_F_POLLED ) { apoll = req->apoll; +kfree (apoll->double_poll); }else if (!(issue_flags &IO_URING_F_UNLOCKED ) && !list_empty (&ctx->apoll_cache)) { apoll = list_first_entry(&ctx->apoll_cache, struct async_poll,
Signature · 1 line
2.36.1
Jens Axboe
maintainerRe: [PATCH 5.19 3/3] io_uring: fix double poll leak on repolling
Quoted 16 lines · Pavel Begunkov
We have re-polling for partial IO, so a request can be polled twice. If it used two poll entries the first time then on the second
io_arm_poll_handler()it will find the old apoll entry and NULL kmalloc()'ed second entry, i.e.apoll->double_poll, so leaking it.Fixes 10c873334feba ("io_uring: allow re-poll if we made progress")Signed-off-by Pavel Begunkov <[email protected]>--- fs/io_uring.c | 1 + 1 file changed, 1 insertion(+)fs/io_uring.c +0
-0
fs/io_uring.c static int io_arm_poll_handler(struct io_kiocb *req, unsigned issue_flags) · line 7214
Quoted 7 lines
fs/io_uring.c +1
-0@@ -7208,6 +7208,7 @@ static int io_arm_poll_handler(struct io_kiocb *req, unsigned issue_flags) mask |=EPOLLEXCLUSIVE ;if (req->flags &REQ_F_POLLED ) { apoll = req->apoll; +kfree (apoll->double_poll); }else if (!(issue_flags &IO_URING_F_UNLOCKED ) && !list_empty (&ctx->apoll_cache)) { apoll = list_first_entry(&ctx->apoll_cache, struct async_poll,
Looks good, my only question was on whether we should clear ->double_poll here, but we do that right below so all's good.
Signature · 1 line
Jens Axboe
Jens Axboe
maintainerQuoted 5 lines · Pavel Begunkov
Several poll and apoll fixes for 5.19. I don't know if problems in 2-3 were occuring prior to "
io_uring: poll rework", but let's at least back port it to that point.I'll also be sending another clean up series for 5.20.
Looks good to me, a few comments in the patches. As mentioned privately, I think we should write a dummy char driver that allows us to exercise all types of poll (single, poll, pollfree, etc) and be able to trigger the error paths with it too. I'll give that a shot. We can probably just make it a debugfs file or something like that, and have it be configurable too as a debug option for test purposes.
Signature · 1 line
Jens Axboe
Quoted 4 lines · Pavel Begunkov
Several poll and apoll fixes for 5.19. I don't know if problems in 2-3 were occuring prior to "
io_uring: poll rework", but let's at least back port it to that point.
Quoted 8 lines
I'll also be sending another clean up series for 5.20.
Pavel Begunkov (3):
io_uring: fail links when poll fails
io_uring: fix wrongarm_pollerror handling
io_uring: fix double poll leak on repolling[...]
Applied, thanks!
[1/3] io_uring: fail links when poll fails
commit: c487a5ad48831afa6784b368ec40d0ee50f2fe1b
[2/3] io_uring: fix wrong arm_poll error handling
commit: 9d2ad2947a53abf5e5e6527a9eeed50a3a4cbc72
[3/3] io_uring: fix double poll leak on repolling
commit: c0737fa9a5a5cf5a053bcc983f72d58919b997c6Best regards,
Signature · 1 line
Jens Axboe