Skip to content

Commit 6ae91ac

Browse files
isilenceaxboe
authored andcommitted
io_uring/net: don't skip notifs for failed requests
We currently only add a notification CQE when the send succeded, i.e. cqe.res >= 0. However, it'd be more robust to do buffer notifications for failed requests as well in case drivers decide do something fanky. Always return a buffer notification after initial prep, don't hide it. This behaviour is better aligned with documentation and the patch also helps the userspace to respect it. Cc: [email protected] # 6.0 Suggested-by: Stefan Metzmacher <[email protected]> Signed-off-by: Pavel Begunkov <[email protected]> Link: https://lore.kernel.org/r/9c8bead87b2b980fcec441b8faef52188b4a6588.1664292100.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <[email protected]>
1 parent c278d9f commit 6ae91ac

File tree

1 file changed

+8
-21
lines changed

1 file changed

+8
-21
lines changed

io_uring/net.c

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,6 @@ void io_send_zc_cleanup(struct io_kiocb *req)
916916
kfree(io->free_iov);
917917
}
918918
if (zc->notif) {
919-
zc->notif->flags |= REQ_F_CQE_SKIP;
920919
io_notif_flush(zc->notif);
921920
zc->notif = NULL;
922921
}
@@ -1047,7 +1046,7 @@ int io_send_zc(struct io_kiocb *req, unsigned int issue_flags)
10471046
struct msghdr msg;
10481047
struct iovec iov;
10491048
struct socket *sock;
1050-
unsigned msg_flags, cflags;
1049+
unsigned msg_flags;
10511050
int ret, min_ret = 0;
10521051

10531052
sock = sock_from_file(req->file);
@@ -1115,8 +1114,6 @@ int io_send_zc(struct io_kiocb *req, unsigned int issue_flags)
11151114
req->flags |= REQ_F_PARTIAL_IO;
11161115
return io_setup_async_addr(req, &__address, issue_flags);
11171116
}
1118-
if (ret < 0 && !zc->done_io)
1119-
zc->notif->flags |= REQ_F_CQE_SKIP;
11201117
if (ret == -ERESTARTSYS)
11211118
ret = -EINTR;
11221119
req_set_fail(req);
@@ -1129,8 +1126,7 @@ int io_send_zc(struct io_kiocb *req, unsigned int issue_flags)
11291126

11301127
io_notif_flush(zc->notif);
11311128
req->flags &= ~REQ_F_NEED_CLEANUP;
1132-
cflags = ret >= 0 ? IORING_CQE_F_MORE : 0;
1133-
io_req_set_res(req, ret, cflags);
1129+
io_req_set_res(req, ret, IORING_CQE_F_MORE);
11341130
return IOU_OK;
11351131
}
11361132

@@ -1139,7 +1135,7 @@ int io_sendmsg_zc(struct io_kiocb *req, unsigned int issue_flags)
11391135
struct io_sr_msg *sr = io_kiocb_to_cmd(req, struct io_sr_msg);
11401136
struct io_async_msghdr iomsg, *kmsg;
11411137
struct socket *sock;
1142-
unsigned flags, cflags;
1138+
unsigned flags;
11431139
int ret, min_ret = 0;
11441140

11451141
sock = sock_from_file(req->file);
@@ -1178,8 +1174,6 @@ int io_sendmsg_zc(struct io_kiocb *req, unsigned int issue_flags)
11781174
req->flags |= REQ_F_PARTIAL_IO;
11791175
return io_setup_async_msg(req, kmsg, issue_flags);
11801176
}
1181-
if (ret < 0 && !sr->done_io)
1182-
sr->notif->flags |= REQ_F_CQE_SKIP;
11831177
if (ret == -ERESTARTSYS)
11841178
ret = -EINTR;
11851179
req_set_fail(req);
@@ -1196,27 +1190,20 @@ int io_sendmsg_zc(struct io_kiocb *req, unsigned int issue_flags)
11961190

11971191
io_notif_flush(sr->notif);
11981192
req->flags &= ~REQ_F_NEED_CLEANUP;
1199-
cflags = ret >= 0 ? IORING_CQE_F_MORE : 0;
1200-
io_req_set_res(req, ret, cflags);
1193+
io_req_set_res(req, ret, IORING_CQE_F_MORE);
12011194
return IOU_OK;
12021195
}
12031196

12041197
void io_sendrecv_fail(struct io_kiocb *req)
12051198
{
12061199
struct io_sr_msg *sr = io_kiocb_to_cmd(req, struct io_sr_msg);
1207-
int res = req->cqe.res;
12081200

12091201
if (req->flags & REQ_F_PARTIAL_IO)
1210-
res = sr->done_io;
1202+
req->cqe.res = sr->done_io;
1203+
12111204
if ((req->flags & REQ_F_NEED_CLEANUP) &&
1212-
(req->opcode == IORING_OP_SEND_ZC || req->opcode == IORING_OP_SENDMSG_ZC)) {
1213-
/* preserve notification for partial I/O */
1214-
if (res < 0)
1215-
sr->notif->flags |= REQ_F_CQE_SKIP;
1216-
io_notif_flush(sr->notif);
1217-
sr->notif = NULL;
1218-
}
1219-
io_req_set_res(req, res, req->cqe.flags);
1205+
(req->opcode == IORING_OP_SEND_ZC || req->opcode == IORING_OP_SENDMSG_ZC))
1206+
req->cqe.flags |= IORING_CQE_F_MORE;
12201207
}
12211208

12221209
int io_accept_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)

0 commit comments

Comments
 (0)