for-next cleanups
cover for-next cleanups
random 5.17 cleanups
Pavel Begunkov (4):
io_uring: simplify reissue in kiocb_done
io_uring: improve send/recv error handling
io_uring: clean __io_import_iovec()
io_uring: improve argument types of kiocb_done()
fs/io_uring.c | 102 ++++++++++++++++++++++++++------------------------ 1 file changed, 53 insertions(+), 49 deletions(-)
Signature · 1 line
2.33.1
PATCH 1/4 io_uring: simplify reissue in kiocb_done
Simplify failed resubmission prep in kiocb_done(), it's a bit ugly with conditional logic and hand handling cflags / select buffers. Instead, punt to tw and use io_req_task_complete() already handling all the cases.
--- fs/io_uring.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-)
fs/io_uring.c +3 -10
@@ -2948,17 +2948,10 @@ static void kiocb_done(struct kiocb *kiocb, ssize_t ret,if (io_resubmit_prep (req)) {io_req_task_queue_reissue (req); }else { -unsigned int cflags =io_put_rw_kbuf (req); -struct io_ring_ctx *ctx = req->ctx; -req_set_fail (req); -if (issue_flags &IO_URING_F_UNLOCKED ) { -mutex_lock (&ctx->uring_lock); -__io_req_complete (req, issue_flags, ret, cflags); -mutex_unlock (&ctx->uring_lock); - }else { -__io_req_complete (req, issue_flags, ret, cflags); - } + req->result = ret; + req->io_task_work.func = io_req_task_complete; +io_req_task_work_add (req); } } }
Signature · 1 line
2.33.1
PATCH 2/4 io_uring: improve send/recv error handling
In reply to Pavel BegunkovHide all error handling under common if block, removes two extra ifs on the success path and keeps the handling more condensed.
--- fs/io_uring.c | 55 +++++++++++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 24 deletions(-)
fs/io_uring.c +31 -24
@@ -4788,17 +4788,18 @@ static int io_sendmsg(struct io_kiocb *req, unsigned int issue_flags) min_ret =iov_iter_count (&kmsg->msg.msg_iter); ret =__sys_sendmsg_sock (sock, &kmsg->msg, flags); -if ((issue_flags &IO_URING_F_NONBLOCK ) && ret == -EAGAIN ) -return io_setup_async_msg (req, kmsg); -if (ret == -ERESTARTSYS ) - ret = -EINTR ; +if (ret < min_ret) { +if (ret == -EAGAIN && (issue_flags &IO_URING_F_NONBLOCK )) +return io_setup_async_msg (req, kmsg); +if (ret == -ERESTARTSYS ) + ret = -EINTR ; +req_set_fail (req); + }/* fast path, check for non-NULL to avoid function call */ if (kmsg->free_iov)kfree (kmsg->free_iov); req->flags &= ~REQ_F_NEED_CLEANUP ; -if (ret < min_ret) -req_set_fail (req);__io_req_complete (req, issue_flags, ret,0 );return 0 ; }
@@ -4834,13 +4835,13 @@ static int io_send(struct io_kiocb *req, unsigned int issue_flags) msg.msg_flags = flags; ret =sock_sendmsg (sock, &msg); -if ((issue_flags &IO_URING_F_NONBLOCK ) && ret == -EAGAIN ) -return -EAGAIN ; -if (ret == -ERESTARTSYS ) - ret = -EINTR ; - -if (ret < min_ret) +if (ret < min_ret) { +if (ret == -EAGAIN && (issue_flags &IO_URING_F_NONBLOCK )) +return -EAGAIN ; +if (ret == -ERESTARTSYS ) + ret = -EINTR ;req_set_fail (req); + }__io_req_complete (req, issue_flags, ret,0 );return 0 ; }
@@ -5017,10 +5018,15 @@ static int io_recvmsg(struct io_kiocb *req, unsigned int issue_flags) ret =__sys_recvmsg_sock (sock, &kmsg->msg, req->sr_msg.umsg, kmsg->uaddr, flags); -if (force_nonblock && ret == -EAGAIN ) -return io_setup_async_msg (req, kmsg); -if (ret == -ERESTARTSYS ) - ret = -EINTR ; +if (ret < min_ret) { +if (ret == -EAGAIN && force_nonblock) +return io_setup_async_msg (req, kmsg); +if (ret == -ERESTARTSYS ) + ret = -EINTR ; +req_set_fail (req); + }else if ((flags &MSG_WAITALL ) && (kmsg->msg.msg_flags & (MSG_TRUNC |MSG_CTRUNC ))) { +req_set_fail (req); + }if (req->flags &REQ_F_BUFFER_SELECTED ) cflags =io_put_recv_kbuf (req);
@@ -5028,8 +5034,6 @@ static int io_recvmsg(struct io_kiocb *req, unsigned int issue_flags)if (kmsg->free_iov)kfree (kmsg->free_iov); req->flags &= ~REQ_F_NEED_CLEANUP ; -if (ret < min_ret || ((flags &MSG_WAITALL ) && (kmsg->msg.msg_flags & (MSG_TRUNC |MSG_CTRUNC )))) -req_set_fail (req);__io_req_complete (req, issue_flags, ret, cflags);return 0 ; }
@@ -5076,15 +5080,18 @@ static int io_recv(struct io_kiocb *req, unsigned int issue_flags) min_ret =iov_iter_count (&msg.msg_iter); ret =sock_recvmsg (sock, &msg, flags); -if (force_nonblock && ret == -EAGAIN ) -return -EAGAIN ; -if (ret == -ERESTARTSYS ) - ret = -EINTR ; out_free: +if (ret < min_ret) { +if (ret == -EAGAIN && force_nonblock) +return -EAGAIN ; +if (ret == -ERESTARTSYS ) + ret = -EINTR ; +req_set_fail (req); + }else if ((flags &MSG_WAITALL ) && (msg.msg_flags & (MSG_TRUNC |MSG_CTRUNC ))) { +req_set_fail (req); + }if (req->flags &REQ_F_BUFFER_SELECTED ) cflags =io_put_recv_kbuf (req); -if (ret < min_ret || ((flags &MSG_WAITALL ) && (msg.msg_flags & (MSG_TRUNC |MSG_CTRUNC )))) -req_set_fail (req);__io_req_complete (req, issue_flags, ret, cflags);return 0 ; }
Signature · 1 line
2.33.1
PATCH 3/4 io_uring: clean __io_import_iovec()
In reply to Pavel BegunkovApparently, implicit 0 to NULL conversion with ERR_PTR is not recommended and makes some tooling like Smatch to complain. Handle it explicitly, compilers are perfectly capable to optimise it out.
--- fs/io_uring.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-)
fs/io_uring.c +13 -8
@@ -3179,10 +3179,12 @@ static struct iovec *__io_import_iovec(int rw, struct io_kiocb *req,size_t sqe_len;ssize_t ret; -BUILD_BUG_ON (ERR_PTR (0 ) !=NULL ); - -if (opcode ==IORING_OP_READ_FIXED || opcode ==IORING_OP_WRITE_FIXED ) -return ERR_PTR (io_import_fixed (req, rw, iter)); +if (opcode ==IORING_OP_READ_FIXED || opcode ==IORING_OP_WRITE_FIXED ) { + ret =io_import_fixed (req, rw, iter); +if (ret) +return ERR_PTR (ret); +return NULL ; + }/* buffer index only valid with fixed read/write, or buffer select */ if (unlikely (req->buf_index && !(req->flags &REQ_F_BUFFER_SELECT )))
@@ -3200,15 +3202,18 @@ static struct iovec *__io_import_iovec(int rw, struct io_kiocb *req, } ret =import_single_range (rw, buf, sqe_len, s->fast_iov, iter); -return ERR_PTR (ret); +if (ret) +return ERR_PTR (ret); +return NULL ; } iovec = s->fast_iov;if (req->flags &REQ_F_BUFFER_SELECT ) { ret =io_iov_buffer_select (req, iovec, issue_flags); -if (!ret) -iov_iter_init (iter, rw, iovec,1 , iovec->iov_len); -return ERR_PTR (ret); +if (ret) +return ERR_PTR (ret); +iov_iter_init (iter, rw, iovec,1 , iovec->iov_len); +return NULL ; } ret = __import_iovec(rw, buf, sqe_len, UIO_FASTIOV, &iovec, iter,
Signature · 1 line
2.33.1
PATCH 4/4 io_uring: improve argument types of kiocb_done()
In reply to Pavel Begunkovkiocb_done() accepts a pointer to struct kiocb, pass struct io_kiocb (i.e. io_uring's request) instead so we can get rid of useless container_of().
--- fs/io_uring.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
fs/io_uring.c +6 -7
@@ -2922,10 +2922,9 @@ static inline void io_rw_done(struct kiocb *kiocb, ssize_t ret) } } -static void kiocb_done (struct kiocb *kiocb,ssize_t ret, +static void kiocb_done (struct io_kiocb *req,ssize_t ret,unsigned int issue_flags) { - struct io_kiocb *req = container_of(kiocb, struct io_kiocb, rw.kiocb);struct io_async_rw *io = req->async_data;/* add previously done IO, if any */
@@ -2937,11 +2936,11 @@ static void kiocb_done(struct kiocb *kiocb, ssize_t ret, }if (req->flags &REQ_F_CUR_POS ) - req->file->f_pos = kiocb->ki_pos; -if (ret >=0 && (kiocb->ki_complete == io_complete_rw)) + req->file->f_pos = req->rw.kiocb.ki_pos; +if (ret >=0 && (req->rw.kiocb.ki_complete == io_complete_rw))__io_complete_rw (req, ret,0 , issue_flags);else -io_rw_done (kiocb, ret); +io_rw_done (&req->rw.kiocb, ret);if (req->flags &REQ_F_REISSUE ) { req->flags &= ~REQ_F_REISSUE ;
@@ -3584,7 +3583,7 @@ static int io_read(struct io_kiocb *req, unsigned int issue_flags)iov_iter_restore (&s->iter, &s->iter_state); }while (ret >0 ); done: -kiocb_done (kiocb, ret, issue_flags); +kiocb_done (req, ret, issue_flags); out_free:/* it's faster to check here then delegate to kfree */ if (iovec)
@@ -3681,7 +3680,7 @@ static int io_write(struct io_kiocb *req, unsigned int issue_flags)if (ret2 == -EAGAIN && (req->ctx->flags &IORING_SETUP_IOPOLL )) goto copy_iov; done: -kiocb_done (kiocb, ret2, issue_flags); +kiocb_done (req, ret2, issue_flags); }else { copy_iov:iov_iter_restore (&s->iter, &s->iter_state);
Signature · 1 line
2.33.1
Re: [PATCH 3/4] io_uring: clean __io_import_iovec()
In reply to Pavel BegunkovQuoted 7 lines · Pavel Begunkov
Apparently, implicit 0 to NULL conversion with
ERR_PTRis not recommended and makes some tooling like Smatch to complain. Handle it explicitly, compilers are perfectly capable to optimise it out.
I like that this this code is now really explicit that the NULL returns are intentional. I had figured that out from the git log already.
Passing zero to ERR_PTR() is valid. Linus complained about this Smatch warning. But I'm not going to delete the check because probably around 70% (complete guess) of the cases in new code are bugs. In older kernels the Smatch warnings tend to be 100% false positives because we fix the real bugs. Also the kbuild-bot hits a bunch of error pointer false positives for cross compile builds but I don't have a cross compile system set up so I haven't debugged that. :/ It has something to do with pointers being treated as signed on those arches.
But what I really like to see is documentation explaining when a function is going to return NULL vs an error pointer.
regards,
dan carpenter
Quoted 9 lines · Pavel Begunkov
random 5.17 cleanups
Pavel Begunkov (4):
io_uring: simplify reissue inkiocb_done
io_uring: improve send/recv error handling
io_uring: clean__io_import_iovec()
io_uring: improve argument types ofkiocb_done()[...]
Applied, thanks!
[1/4] io_uring: simplify reissue in kiocb_done
commit: 06bdea20c1076471f7ab7d3ad7f35cbcbd59a8e3
[2/4] io_uring: improve send/recv error handling
commit: 7297ce3d59449de49d3c9e1f64ae25488750a1fc
[3/4] io_uring: clean __io_import_iovec()
commit: f3251183b298912e09297cb22614361c63122e82
[4/4] io_uring: improve argument types of kiocb_done()
commit: 2ea537ca02b12e6e03dfcac82013ff289a75eed8Best regards,
Signature · 1 line
Jens Axboe