Skip to content

Commit 0b0861e

Browse files
committed
Merge tag 'io_uring-6.0-2022-08-26' of git://git.kernel.dk/linux-block
Pull io_uring fixes from Jens Axboe: - Add missing header file to the MAINTAINERS entry for io_uring (Ammar) - liburing and the kernel ship the same io_uring.h header, but one change we've had for a long time only in liburing is to ensure it's C++ safe. Add extern C around it, so we can more easily sync them in the future (Ammar) - Fix an off-by-one in the sync cancel added in this merge window (me) - Error handling fix for passthrough (Kanchan) - Fix for address saving for async execution for the zc tx support (Pavel) - Fix ordering for TCP zc notifications, so we always have them ordered correctly between "data was sent" and "data was acked". This isn't strictly needed with the notification slots, but we've been pondering disabling the slot support for 6.0 - and if we do, then we do require the ordering to be sane. Regardless of that, it's the sane thing to do in terms of API (Pavel) - Minor cleanup for indentation and lockdep annotation (Pavel) * tag 'io_uring-6.0-2022-08-26' of git://git.kernel.dk/linux-block: io_uring/net: save address for sendzc async execution io_uring: conditional ->async_data allocation io_uring/notif: order notif vs send CQEs io_uring/net: fix indentation io_uring/net: fix zc send link failing io_uring/net: fix must_hold annotation io_uring: fix submission-failure handling for uring-cmd io_uring: fix off-by-one in sync cancelation file check io_uring: uapi: Add `extern "C"` in io_uring.h for liburing MAINTAINERS: Add `include/linux/io_uring_types.h`
2 parents 5373081 + 581711c commit 0b0861e

File tree

10 files changed

+74
-17
lines changed

10 files changed

+74
-17
lines changed

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10659,6 +10659,7 @@ T: git git://git.kernel.dk/linux-block
1065910659
T: git git://git.kernel.dk/liburing
1066010660
F: io_uring/
1066110661
F: include/linux/io_uring.h
10662+
F: include/linux/io_uring_types.h
1066210663
F: include/uapi/linux/io_uring.h
1066310664
F: tools/io_uring/
1066410665

include/uapi/linux/io_uring.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
#include <linux/types.h>
1313
#include <linux/time_types.h>
1414

15+
#ifdef __cplusplus
16+
extern "C" {
17+
#endif
18+
1519
/*
1620
* IO submission data structure (Submission Queue Entry)
1721
*/
@@ -661,4 +665,8 @@ struct io_uring_recvmsg_out {
661665
__u32 flags;
662666
};
663667

668+
#ifdef __cplusplus
669+
}
670+
#endif
671+
664672
#endif

io_uring/cancel.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ static int __io_sync_cancel(struct io_uring_task *tctx,
218218
(cd->flags & IORING_ASYNC_CANCEL_FD_FIXED)) {
219219
unsigned long file_ptr;
220220

221-
if (unlikely(fd > ctx->nr_user_files))
221+
if (unlikely(fd >= ctx->nr_user_files))
222222
return -EBADF;
223223
fd = array_index_nospec(fd, ctx->nr_user_files);
224224
file_ptr = io_fixed_file_slot(&ctx->file_table, fd)->file_ptr;

io_uring/io_uring.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,9 +1450,10 @@ int io_req_prep_async(struct io_kiocb *req)
14501450
return 0;
14511451
if (WARN_ON_ONCE(req_has_async_data(req)))
14521452
return -EFAULT;
1453-
if (io_alloc_async_data(req))
1454-
return -EAGAIN;
1455-
1453+
if (!io_op_defs[req->opcode].manual_alloc) {
1454+
if (io_alloc_async_data(req))
1455+
return -EAGAIN;
1456+
}
14561457
return def->prep_async(req);
14571458
}
14581459

io_uring/net.c

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,37 @@ static int io_sendmsg_copy_hdr(struct io_kiocb *req,
182182
&iomsg->free_iov);
183183
}
184184

185+
int io_sendzc_prep_async(struct io_kiocb *req)
186+
{
187+
struct io_sendzc *zc = io_kiocb_to_cmd(req, struct io_sendzc);
188+
struct io_async_msghdr *io;
189+
int ret;
190+
191+
if (!zc->addr || req_has_async_data(req))
192+
return 0;
193+
if (io_alloc_async_data(req))
194+
return -ENOMEM;
195+
196+
io = req->async_data;
197+
ret = move_addr_to_kernel(zc->addr, zc->addr_len, &io->addr);
198+
return ret;
199+
}
200+
201+
static int io_setup_async_addr(struct io_kiocb *req,
202+
struct sockaddr_storage *addr,
203+
unsigned int issue_flags)
204+
{
205+
struct io_async_msghdr *io;
206+
207+
if (!addr || req_has_async_data(req))
208+
return -EAGAIN;
209+
if (io_alloc_async_data(req))
210+
return -ENOMEM;
211+
io = req->async_data;
212+
memcpy(&io->addr, addr, sizeof(io->addr));
213+
return -EAGAIN;
214+
}
215+
185216
int io_sendmsg_prep_async(struct io_kiocb *req)
186217
{
187218
int ret;
@@ -944,7 +975,7 @@ static int io_sg_from_iter(struct sock *sk, struct sk_buff *skb,
944975

945976
int io_sendzc(struct io_kiocb *req, unsigned int issue_flags)
946977
{
947-
struct sockaddr_storage address;
978+
struct sockaddr_storage __address, *addr = NULL;
948979
struct io_ring_ctx *ctx = req->ctx;
949980
struct io_sendzc *zc = io_kiocb_to_cmd(req, struct io_sendzc);
950981
struct io_notif_slot *notif_slot;
@@ -978,18 +1009,25 @@ int io_sendzc(struct io_kiocb *req, unsigned int issue_flags)
9781009
msg.msg_namelen = 0;
9791010

9801011
if (zc->addr) {
981-
ret = move_addr_to_kernel(zc->addr, zc->addr_len, &address);
982-
if (unlikely(ret < 0))
983-
return ret;
984-
msg.msg_name = (struct sockaddr *)&address;
1012+
if (req_has_async_data(req)) {
1013+
struct io_async_msghdr *io = req->async_data;
1014+
1015+
msg.msg_name = addr = &io->addr;
1016+
} else {
1017+
ret = move_addr_to_kernel(zc->addr, zc->addr_len, &__address);
1018+
if (unlikely(ret < 0))
1019+
return ret;
1020+
msg.msg_name = (struct sockaddr *)&__address;
1021+
addr = &__address;
1022+
}
9851023
msg.msg_namelen = zc->addr_len;
9861024
}
9871025

9881026
if (zc->flags & IORING_RECVSEND_FIXED_BUF) {
9891027
ret = io_import_fixed(WRITE, &msg.msg_iter, req->imu,
9901028
(u64)(uintptr_t)zc->buf, zc->len);
9911029
if (unlikely(ret))
992-
return ret;
1030+
return ret;
9931031
} else {
9941032
ret = import_single_range(WRITE, zc->buf, zc->len, &iov,
9951033
&msg.msg_iter);
@@ -1013,16 +1051,18 @@ int io_sendzc(struct io_kiocb *req, unsigned int issue_flags)
10131051

10141052
if (unlikely(ret < min_ret)) {
10151053
if (ret == -EAGAIN && (issue_flags & IO_URING_F_NONBLOCK))
1016-
return -EAGAIN;
1054+
return io_setup_async_addr(req, addr, issue_flags);
1055+
10171056
if (ret > 0 && io_net_retry(sock, msg.msg_flags)) {
10181057
zc->len -= ret;
10191058
zc->buf += ret;
10201059
zc->done_io += ret;
10211060
req->flags |= REQ_F_PARTIAL_IO;
1022-
return -EAGAIN;
1061+
return io_setup_async_addr(req, addr, issue_flags);
10231062
}
10241063
if (ret == -ERESTARTSYS)
10251064
ret = -EINTR;
1065+
req_set_fail(req);
10261066
} else if (zc->flags & IORING_RECVSEND_NOTIF_FLUSH) {
10271067
io_notif_slot_flush_submit(notif_slot, 0);
10281068
}

io_uring/net.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ struct io_async_connect {
3131
int io_shutdown_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe);
3232
int io_shutdown(struct io_kiocb *req, unsigned int issue_flags);
3333

34+
int io_sendzc_prep_async(struct io_kiocb *req);
3435
int io_sendmsg_prep_async(struct io_kiocb *req);
3536
void io_sendmsg_recvmsg_cleanup(struct io_kiocb *req);
3637
int io_sendmsg_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe);

io_uring/notif.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,18 @@ struct io_kiocb *io_alloc_notif(struct io_ring_ctx *ctx,
7373
}
7474

7575
void io_notif_slot_flush(struct io_notif_slot *slot)
76-
__must_hold(&ctx->uring_lock)
76+
__must_hold(&slot->notif->ctx->uring_lock)
7777
{
7878
struct io_kiocb *notif = slot->notif;
7979
struct io_notif_data *nd = io_notif_to_data(notif);
8080

8181
slot->notif = NULL;
8282

8383
/* drop slot's master ref */
84-
if (refcount_dec_and_test(&nd->uarg.refcnt))
85-
io_notif_complete(notif);
84+
if (refcount_dec_and_test(&nd->uarg.refcnt)) {
85+
notif->io_task_work.func = __io_notif_complete_tw;
86+
io_req_task_work_add(notif);
87+
}
8688
}
8789

8890
__cold int io_notif_unregister(struct io_ring_ctx *ctx)

io_uring/opdef.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,13 +478,15 @@ const struct io_op_def io_op_defs[] = {
478478
.pollout = 1,
479479
.audit_skip = 1,
480480
.ioprio = 1,
481+
.manual_alloc = 1,
481482
#if defined(CONFIG_NET)
483+
.async_size = sizeof(struct io_async_msghdr),
482484
.prep = io_sendzc_prep,
483485
.issue = io_sendzc,
486+
.prep_async = io_sendzc_prep_async,
484487
#else
485488
.prep = io_eopnotsupp_prep,
486489
#endif
487-
488490
},
489491
};
490492

io_uring/opdef.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ struct io_op_def {
2525
unsigned ioprio : 1;
2626
/* supports iopoll */
2727
unsigned iopoll : 1;
28+
/* opcode specific path will handle ->async_data allocation if needed */
29+
unsigned manual_alloc : 1;
2830
/* size of async data needed, if any */
2931
unsigned short async_size;
3032

io_uring/uring_cmd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ int io_uring_cmd(struct io_kiocb *req, unsigned int issue_flags)
112112
if (ret < 0)
113113
req_set_fail(req);
114114
io_req_set_res(req, ret, 0);
115-
return IOU_OK;
115+
return ret;
116116
}
117117

118118
return IOU_ISSUE_SKIP_COMPLETE;

0 commit comments

Comments
 (0)