]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
io_uring/rw: don't lose partial IO result on fail
authorPavel Begunkov <asml.silence@gmail.com>
Wed, 21 Sep 2022 11:17:47 +0000 (12:17 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 21 Oct 2022 10:37:32 +0000 (12:37 +0200)
commit 47b4c68660752facfa6247b1fc9ca9d722b8b601 upstream.

A partially done read/write may end up in io_req_complete_failed() and
loose the result, make sure we return the number of bytes processed.

Cc: stable@vger.kernel.org
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Link: https://lore.kernel.org/r/05e0879c226bcd53b441bf92868eadd4bf04e2fc.1663668091.git.asml.silence@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
io_uring/opdef.c
io_uring/rw.c
io_uring/rw.h

index c4dddd0fd70949c300e519c54c0f6f7d8f13c246..2312196fd23bbea910aa7350414e3ce3a5c965cb 100644 (file)
@@ -69,6 +69,7 @@ const struct io_op_def io_op_defs[] = {
                .issue                  = io_read,
                .prep_async             = io_readv_prep_async,
                .cleanup                = io_readv_writev_cleanup,
+               .fail                   = io_rw_fail,
        },
        [IORING_OP_WRITEV] = {
                .needs_file             = 1,
@@ -85,6 +86,7 @@ const struct io_op_def io_op_defs[] = {
                .issue                  = io_write,
                .prep_async             = io_writev_prep_async,
                .cleanup                = io_readv_writev_cleanup,
+               .fail                   = io_rw_fail,
        },
        [IORING_OP_FSYNC] = {
                .needs_file             = 1,
@@ -105,6 +107,7 @@ const struct io_op_def io_op_defs[] = {
                .name                   = "READ_FIXED",
                .prep                   = io_prep_rw,
                .issue                  = io_read,
+               .fail                   = io_rw_fail,
        },
        [IORING_OP_WRITE_FIXED] = {
                .needs_file             = 1,
@@ -119,6 +122,7 @@ const struct io_op_def io_op_defs[] = {
                .name                   = "WRITE_FIXED",
                .prep                   = io_prep_rw,
                .issue                  = io_write,
+               .fail                   = io_rw_fail,
        },
        [IORING_OP_POLL_ADD] = {
                .needs_file             = 1,
@@ -273,6 +277,7 @@ const struct io_op_def io_op_defs[] = {
                .name                   = "READ",
                .prep                   = io_prep_rw,
                .issue                  = io_read,
+               .fail                   = io_rw_fail,
        },
        [IORING_OP_WRITE] = {
                .needs_file             = 1,
@@ -287,6 +292,7 @@ const struct io_op_def io_op_defs[] = {
                .name                   = "WRITE",
                .prep                   = io_prep_rw,
                .issue                  = io_write,
+               .fail                   = io_rw_fail,
        },
        [IORING_OP_FADVISE] = {
                .needs_file             = 1,
index 76ebcfebc9a6e32f93b78f42fab0da9ae38c9893..30d0fed9fdecfefc4091be4e6246e830111d1ca2 100644 (file)
@@ -984,6 +984,14 @@ static void io_cqring_ev_posted_iopoll(struct io_ring_ctx *ctx)
                io_cqring_wake(ctx);
 }
 
+void io_rw_fail(struct io_kiocb *req)
+{
+       int res;
+
+       res = io_fixup_rw_res(req, req->cqe.res);
+       io_req_set_res(req, res, req->cqe.flags);
+}
+
 int io_do_iopoll(struct io_ring_ctx *ctx, bool force_nonspin)
 {
        struct io_wq_work_node *pos, *start, *prev;
index 0204c3fcafa517d267fb28228fc65048e2f8556e..3b733f4b610ac98baecb635bf3630bcd01ba5205 100644 (file)
@@ -21,3 +21,4 @@ int io_readv_prep_async(struct io_kiocb *req);
 int io_write(struct io_kiocb *req, unsigned int issue_flags);
 int io_writev_prep_async(struct io_kiocb *req);
 void io_readv_writev_cleanup(struct io_kiocb *req);
+void io_rw_fail(struct io_kiocb *req);