misc update for openclose and provided buffer
cover misc update for openclose and provided buffer
From: Hao Xu <[email protected]>
Patch 1 and 2 are bug fixes for openclose Patch 3 is to support better close logic Patch 4 is code clean
Patch 5 is a bug fix for ring-mapped provided buffer
Hao Xu (5):
io_uring: openclose: fix bug of closing wrong fixed file
io_uring: openclose: fix bug of unexpected return value in
IORING_CLOSE_FD_AND_FILE_SLOT mode
io_uring: openclose: support separate return value for
IORING_CLOSE_FD_AND_FILE_SLOT
io_uring: remove duplicate kbuf release
io_uring: kbuf: consume ring buffer in partial io case
io_uring/io_uring.c | 6 ------ io_uring/kbuf.c | 9 +++++++-- io_uring/kbuf.h | 10 ++++++++-- io_uring/openclose.c | 10 +++++++--- io_uring/rsrc.c | 2 +- 5 files changed, 23 insertions(+), 14 deletions(-)
Signature · 1 line
2.25.1
PATCH 1/5 io_uring: openclose: fix bug of closing wrong fixed file
From: Hao Xu <[email protected]>
Don't update ret until fixed file is closed, otherwise the file slot becomes the error code.
--- io_uring/rsrc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
io_uring/rsrc.c +1 -1
@@ -705,8 +705,8 @@ static int io_files_update_with_index_alloc(struct io_kiocb *req,if (ret <0 )break ;if (copy_to_user (&fds[done], &ret,sizeof (ret))) { - ret = -EFAULT ;__io_close_fixed (req, issue_flags, ret); + ret = -EFAULT ;break ; } }
Signature · 1 line
2.25.1
PATCH 2/5 io_uring: openclose: fix bug of unexpected return value in IORING_CLOSE_FD_AND_FILE_SLOT mode
In reply to Hao XuFrom: Hao Xu <[email protected]>
In IORING_CLOSE_FD_AND_FILE_SLOT mode, if we successfully close fixed file but fails in close->fd >= fdt->max_fds check, cqe-res = 0 is returned, which should be -EBADF.
--- io_uring/openclose.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
io_uring/openclose.c +2 -1
@@ -248,7 +248,7 @@ int io_close(struct io_kiocb *req, unsigned int issue_flags)struct io_close *close =io_kiocb_to_cmd (req);struct fdtable *fdt;struct file *file; -int ret = -EBADF ; +int ret;if (close->file_slot) { ret =io_close_fixed (req, issue_flags);
@@ -256,6 +256,7 @@ int io_close(struct io_kiocb *req, unsigned int issue_flags) goto err; } + ret = -EBADF ;spin_lock (&files->file_lock); fdt =files_fdtable (files);if (close->fd >= fdt->max_fds) {
Signature · 1 line
2.25.1
PATCH 3/5 io_uring: openclose: support separate return value for IORING_CLOSE_FD_AND_FILE_SLOT
In reply to Hao XuFrom: Hao Xu <[email protected]>
In IORING_CLOSE_FD_AND_FILE_SLOT mode, we just stop and return error code if either of fixed or normal file close fails. But we can actually continue to do the close even one of them fails. What we need to do is put the two result in two place: for normal file close, put the result in cqe->res like the previous behaviour, while for fixed file close, put it in cqe->flags. Users should check both member to get the status of fixed and normal file close.
--- io_uring/openclose.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
io_uring/openclose.c +6 -3
@@ -248,12 +248,15 @@ int io_close(struct io_kiocb *req, unsigned int issue_flags)struct io_close *close =io_kiocb_to_cmd (req);struct fdtable *fdt;struct file *file; -int ret; +int ret, ret2;if (close->file_slot) { ret =io_close_fixed (req, issue_flags); -if (ret || !(close->flags &IORING_CLOSE_FD_AND_FILE_SLOT )) +if (!(close->flags &IORING_CLOSE_FD_AND_FILE_SLOT )) goto err; +else + ret2 = ret; + } ret = -EBADF ;
@@ -286,6 +289,6 @@ int io_close(struct io_kiocb *req, unsigned int issue_flags) err:if (ret <0 )req_set_fail (req); -io_req_set_res (req, ret,0 ); +io_req_set_res (req, ret, ret2);return IOU_OK ; }
Signature · 1 line
2.25.1
PATCH 4/5 io_uring: remove duplicate kbuf release
In reply to Hao XuFrom: Hao Xu <[email protected]>
__io_req_complete_put() is called by __io_req_complete_post, and before that we already put kbuf, no need to do that in __io_req_complete_put() again.
--- io_uring/io_uring.c | 6 ------ 1 file changed, 6 deletions(-)
io_uring/io_uring.c +0 -6
@@ -1245,12 +1245,6 @@ static void __io_req_complete_put(struct io_kiocb *req) } }io_req_put_rsrc (req); -/* -* Selected buffer deallocation in io_clean_op() assumes that -* we don't hold ->completion_lock. Clean them here to avoid -* deadlocks. -*/ -io_put_kbuf_comp (req);io_dismantle_req (req);io_put_task (req->task,1 );wq_list_add_head (&req->comp_list, &ctx->locked_free_list);
Signature · 1 line
2.25.1
PATCH 5/5 io_uring: kbuf: fix bug of not consuming ring buffer in partial io case
In reply to Hao XuFrom: Hao Xu <[email protected]>
When we use ring-mapped provided buffer, we should consume it before arm poll if partial io has been done. Otherwise the buffer may be used by other requests and thus we lost the data.
--- io_uring/kbuf.c | 9 +++++++-- io_uring/kbuf.h | 10 ++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-)
io_uring/kbuf.c +7 -2
@@ -49,8 +49,13 @@ void __io_kbuf_recycle(struct io_kiocb *req, unsigned issue_flags)*/ if (req->flags &REQ_F_BUFFER_RING ) {if (req->buf_list) { - req->buf_index = req->buf_list->bgid; - req->flags &= ~REQ_F_BUFFER_RING ; +if (req->flags &REQ_F_PARTIAL_IO ) { + req->buf_list->head++; + req->buf_list =NULL ; + }else { + req->buf_index = req->buf_list->bgid; + req->flags &= ~REQ_F_BUFFER_RING ; + } }return ; }
io_uring/kbuf.h +8 -2
@@ -58,8 +58,14 @@ static inline void io_kbuf_recycle(struct io_kiocb *req, unsigned issue_flags) {if (!(req->flags & (REQ_F_BUFFER_SELECTED |REQ_F_BUFFER_RING )))return ; -/* don't recycle if we already did IO to this buffer */ -if (req->flags &REQ_F_PARTIAL_IO ) +/* +* For legacy provided buffer mode, don't recycle if we already did +* IO to this buffer. For ring-mapped provided buffer mode, we should +* increment ring->head to explicitly monopolize the buffer to avoid +* multiple use. +*/ +if ((req->flags &REQ_F_BUFFER_SELECTED ) && + (req->flags &REQ_F_PARTIAL_IO ))return ;__io_kbuf_recycle (req, issue_flags); }
Signature · 1 line
2.25.1
Quoted 6 lines · Hao Xu
From: Hao Xu <[email protected]>
Patch 1 and 2 are bug fixes for openclose Patch 3 is to support better close logic Patch 4 is code clean
Patch 5 is a bug fix for ring-mapped provided buffer
Looks that at least the problem from 1/5 also exists in 5.19, can you split out 5.19 fixes and send them separately?
Quoted 16 lines
Hao Xu (5):
io_uring: openclose: fix bug of closing wrong fixed file
io_uring: openclose: fix bug of unexpected return value in
IORING_CLOSE_FD_AND_FILE_SLOTmode
io_uring: openclose: support separate return value for
IORING_CLOSE_FD_AND_FILE_SLOT
io_uring: remove duplicate kbuf release
io_uring: kbuf: consume ring buffer in partial io caseio_uring/io_uring.c | 6 ------ io_uring/kbuf.c | 9 +++++++-- io_uring/kbuf.h | 10 ++++++++-- io_uring/openclose.c | 10 +++++++--- io_uring/rsrc.c | 2 +- 5 files changed, 23 insertions(+), 14 deletions(-)
Signature · 1 line
Pavel Begunkov
Quoted 10 lines · Pavel Begunkov
Quoted 6 lines · Hao Xu
From: Hao Xu <[email protected]>
Patch 1 and 2 are bug fixes for openclose Patch 3 is to support better close logic Patch 4 is code clean
Patch 5 is a bug fix for ring-mapped provided bufferLooks that at least the problem from 1/5 also exists in 5.19, can you split out 5.19 fixes and send them separately?
Sure.
Quoted 19 lines
Quoted 18 lines
Hao Xu (5):
io_uring: openclose: fix bug of closing wrong fixed file
io_uring: openclose: fix bug of unexpected return value inIORING_CLOSE_FD_AND_FILE_SLOTmode
io_uring: openclose: support separate return value forIORING_CLOSE_FD_AND_FILE_SLOT
io_uring: remove duplicate kbuf release
io_uring: kbuf: consume ring buffer in partial io caseio_uring/io_uring.c | 6 ------ io_uring/kbuf.c | 9 +++++++-- io_uring/kbuf.h | 10 ++++++++--
io_uring/openclose.c| 10 +++++++--- io_uring/rsrc.c | 2 +-5 files changed, 23 insertions(+), 14 deletions(-)