io_uring/net: don't lose partial send_zc on fail
authorPavel Begunkov <asml.silence@gmail.com>
Wed, 21 Sep 2022 11:17:49 +0000 (12:17 +0100)
committerJens Axboe <axboe@kernel.dk>
Wed, 21 Sep 2022 19:15:02 +0000 (13:15 -0600)
Partial zc send may end up in io_req_complete_failed(), which not only
would return invalid result but also mask out the notification leading
to lifetime issues.

Cc: stable@vger.kernel.org
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Link: https://lore.kernel.org/r/5673285b5e83e6ceca323727b4ddaa584b5cc91e.1663668091.git.asml.silence@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
io_uring/net.c
io_uring/net.h
io_uring/opdef.c

index 4aabd47..8d90f8e 100644 (file)
@@ -1103,6 +1103,22 @@ void io_sendrecv_fail(struct io_kiocb *req)
        io_req_set_res(req, res, req->cqe.flags);
 }
 
+void io_send_zc_fail(struct io_kiocb *req)
+{
+       struct io_sr_msg *sr = io_kiocb_to_cmd(req, struct io_sr_msg);
+       int res = req->cqe.res;
+
+       if (req->flags & REQ_F_PARTIAL_IO) {
+               if (req->flags & REQ_F_NEED_CLEANUP) {
+                       io_notif_flush(sr->notif);
+                       sr->notif = NULL;
+                       req->flags &= ~REQ_F_NEED_CLEANUP;
+               }
+               res = sr->done_io;
+       }
+       io_req_set_res(req, res, req->cqe.flags);
+}
+
 int io_accept_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
 {
        struct io_accept *accept = io_kiocb_to_cmd(req, struct io_accept);
index 109ffb3..e7366aa 100644 (file)
@@ -58,6 +58,7 @@ int io_connect(struct io_kiocb *req, unsigned int issue_flags);
 int io_sendzc(struct io_kiocb *req, unsigned int issue_flags);
 int io_sendzc_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe);
 void io_sendzc_cleanup(struct io_kiocb *req);
+void io_send_zc_fail(struct io_kiocb *req);
 
 void io_netmsg_cache_free(struct io_cache_entry *entry);
 #else
index f0f4ae3..4fbefb7 100644 (file)
@@ -497,6 +497,7 @@ const struct io_op_def io_op_defs[] = {
                .issue                  = io_sendzc,
                .prep_async             = io_sendzc_prep_async,
                .cleanup                = io_sendzc_cleanup,
+               .fail                   = io_send_zc_fail,
 #else
                .prep                   = io_eopnotsupp_prep,
 #endif