Skip to contentSkip to conversation

io_uring/net: fix zc fixed buf lifetime

PATCH Applied Pavel Begunkov 3 participants 5 messages Sep 16, 2022 – Sep 18, 2022 io_uring

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 io_uring/net: fix zc fixed buf lifetime

Notifications usually outlive requests, so we need to pin buffers with it by assigning a rsrc to it instead of the request.

Fixed: b48c312be05e8 ("io_uring/net: simplify zerocopy send user API")

---
 io_uring/net.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
io_uring/net.c +8 -8
index e9efed40cf3d..60e392f7f2dc 100644
@@ -905,6 +905,13 @@ int io_sendzc_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
 	if (zc->flags & ~(IORING_RECVSEND_POLL_FIRST |
 			  IORING_RECVSEND_FIXED_BUF))
 		return -EINVAL;
+	notif = zc->notif = io_alloc_notif(ctx);
+	if (!notif)
+		return -ENOMEM;
+	notif->cqe.user_data = req->cqe.user_data;
+	notif->cqe.res = 0;
+	notif->cqe.flags = IORING_CQE_F_NOTIF;
+	req->flags |= REQ_F_NEED_CLEANUP;
 	if (zc->flags & IORING_RECVSEND_FIXED_BUF) {
 		unsigned idx = READ_ONCE(sqe->buf_index);
 
@@ -912,15 +919,8 @@ int io_sendzc_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
 			return -EFAULT;
 		idx = array_index_nospec(idx, ctx->nr_user_bufs);
 		req->imu = READ_ONCE(ctx->user_bufs[idx]);
-		io_req_set_rsrc_node(req, ctx, 0);
+		io_req_set_rsrc_node(notif, ctx, 0);
 	}
-	notif = zc->notif = io_alloc_notif(ctx);
-	if (!notif)
-		return -ENOMEM;
-	notif->cqe.user_data = req->cqe.user_data;
-	notif->cqe.res = 0;
-	notif->cqe.flags = IORING_CQE_F_NOTIF;
-	req->flags |= REQ_F_NEED_CLEANUP;
 
 	zc->buf = u64_to_user_ptr(READ_ONCE(sqe->addr));
 	zc->len = READ_ONCE(sqe->len);
Signature · 1 line
2.37.2
#1 lore raw

Am 17.09.22 um 00:22 schrieb Pavel Begunkov:

Quoted 5 lines

Notifications usually outlive requests, so we need to pin buffers with it by assigning a rsrc to it instead of the request.

Fixed: b48c312be05e8 ("io_uring/net: simplify zerocopy send user API")

Looks good to me :-)

metze

maintainer
#2 lore raw
Quoted 8 lines · Stefan Metzmacher

Am 17.09.22 um 00:22 schrieb Pavel Begunkov:

Quoted 5 lines

Notifications usually outlive requests, so we need to pin buffers with it by assigning a rsrc to it instead of the request.

Fixed: b48c312be05e8 ("io_uring/net: simplify zerocopy send user API")

Looks good to me :-)

Can I turn that into an acked-by or reviewed-by?

Signature · 1 line
Jens Axboe
#3 lore raw

Am 17.09.22 um 13:58 schrieb Jens Axboe:

Quoted 11 lines · Stefan Metzmacher
Quoted 8 lines

Am 17.09.22 um 00:22 schrieb Pavel Begunkov:

Quoted 5 lines

Notifications usually outlive requests, so we need to pin buffers with it by assigning a rsrc to it instead of the request.

Fixed: b48c312be05e8 ("io_uring/net: simplify zerocopy send user API")

Looks good to me :-)

Can I turn that into an acked-by or reviewed-by?

reviewed-by is fine.

metze

maintainer Applied
#4 lore raw
In reply to Pavel Begunkov
Quoted 4 lines · Pavel Begunkov

Notifications usually outlive requests, so we need to pin buffers with it by assigning a rsrc to it instead of the request.

Applied, thanks!

[1/1] io_uring/net: fix zc fixed buf lifetime

      commit: e3366e0234971a09f0e16f0e6fa16f4cbae45e47

Best regards,

Signature · 1 line
Jens Axboe