[RFC,1/2] io_uring: clear req->result always before issuing a read/write request
diff mbox series

Message ID 1579142266-64789-2-git-send-email-bijan.mottahedeh@oracle.com
State New
Headers show
Series
  • Fixes for fio io_uring polled mode test failures
Related show

Commit Message

Bijan Mottahedeh Jan. 16, 2020, 2:37 a.m. UTC
req->result is cleared when io_issue_sqe() calls io_read/write_pre()
routines.  Those routines however are not called when the sqe
argument is NULL, which is the case when io_issue_sqe() is called from
io_wq_submit_work().  io_issue_sqe() may then examine a stale result if
a polled request had previously failed with -EAGAIN:

        if (ctx->flags & IORING_SETUP_IOPOLL) {
                if (req->result == -EAGAIN)
                        return -EAGAIN;

                io_iopoll_req_issued(req);
        }

and in turn cause a subsequently completed request to be re-issued in
io_wq_submit_work().

Signed-off-by: Bijan Mottahedeh <bijan.mottahedeh@oracle.com>
---
 fs/io_uring.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Jens Axboe Jan. 16, 2020, 4:34 a.m. UTC | #1
On 1/15/20 7:37 PM, Bijan Mottahedeh wrote:
> req->result is cleared when io_issue_sqe() calls io_read/write_pre()
> routines.  Those routines however are not called when the sqe
> argument is NULL, which is the case when io_issue_sqe() is called from
> io_wq_submit_work().  io_issue_sqe() may then examine a stale result if
> a polled request had previously failed with -EAGAIN:
> 
>         if (ctx->flags & IORING_SETUP_IOPOLL) {
>                 if (req->result == -EAGAIN)
>                         return -EAGAIN;
> 
>                 io_iopoll_req_issued(req);
>         }
> 
> and in turn cause a subsequently completed request to be re-issued in
> io_wq_submit_work().

Looks good, thanks.

Patch
diff mbox series

diff --git a/fs/io_uring.c b/fs/io_uring.c
index 6ffab9aaf..d015ce8 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -2180,6 +2180,7 @@  static int io_read(struct io_kiocb *req, struct io_kiocb **nxt,
 	if (!force_nonblock)
 		req->rw.kiocb.ki_flags &= ~IOCB_NOWAIT;
 
+	req->result = 0;
 	io_size = ret;
 	if (req->flags & REQ_F_LINK)
 		req->result = io_size;
@@ -2267,6 +2268,7 @@  static int io_write(struct io_kiocb *req, struct io_kiocb **nxt,
 	if (!force_nonblock)
 		req->rw.kiocb.ki_flags &= ~IOCB_NOWAIT;
 
+	req->result = 0;
 	io_size = ret;
 	if (req->flags & REQ_F_LINK)
 		req->result = io_size;