Skip to contentSkip to conversation

LAZY_WAKE misuse fixes

PATCH Applied Pavel Begunkov 2 participants 4 messages Apr 30, 2024 io_uring

lore
Share & tools
lore
#0 lore raw

cover LAZY_WAKE misuse fixes

LAZY_WAKE can't be used with requests for which users expect >1 CQE, otherwise wait(nr=2) may get stuck waiting for a tw that will never arrive. Fix up invalid use of LAZY_WAKE with sendzc.

Pavel Begunkov (2):
io_uring/net: fix sendzc lazy wake polling io_uring/notif: disable LAZY_WAKE for linked notifs

 io_uring/net.c   | 1 +
 io_uring/notif.c | 5 ++++-
 2 files changed, 5 insertions(+), 1 deletion(-)
Signature · 1 line
2.44.0
#1 lore raw

PATCH 1/2 io_uring/net: fix sendzc lazy wake polling

SEND[MSG]_ZC produces multiple CQEs via notifications, LAZY_WAKE doesn't handle it and so disable LAZY_WAKE for sendzc polling. It should be fine, sends are not likely to be polled in the first place.

Fixes 6ce4a93dbb5b ("io_uring/poll: use IOU_F_TWQ_LAZY_WAKE for wakeups")
---
 io_uring/net.c | 1 +
 1 file changed, 1 insertion(+)
io_uring/net.c +1 -0
index 51c41d771c50..503debecad32 100644
@@ -1198,6 +1198,7 @@ int io_send_zc_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
 	struct io_kiocb *notif;
 
 	zc->done_io = 0;
+	req->flags |= REQ_F_POLL_NO_LAZY;
 
 	if (unlikely(READ_ONCE(sqe->__pad2[0]) || READ_ONCE(sqe->addr3)))
 		return -EINVAL;
Signature · 1 line
2.44.0
#2 lore raw

PATCH 2/2 io_uring/notif: disable LAZY_WAKE for linked notifs

In reply to Pavel Begunkov

Notifications may now be linked and thus a single tw can post multiple CQEs, it's not safe to use LAZY_WAKE with them. Disable LAZY_WAKE for now, if that'd prove to be a problem we can count them and pass the expected number of CQEs into __io_req_task_work_add().

Fixes 6fe4220912d19 ("io_uring/notif: implement notification stacking")
---
 io_uring/notif.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
io_uring/notif.c +4 -1
index d58cdc01e691..28859ae3ee6e 100644
@@ -38,6 +38,7 @@ void io_tx_ubuf_complete(struct sk_buff *skb, struct ubuf_info *uarg,
 {
 	struct io_notif_data *nd = container_of(uarg, struct io_notif_data, uarg);
 	struct io_kiocb *notif = cmd_to_io_kiocb(nd);
+	unsigned tw_flags;
 
 	if (nd->zc_report) {
 		if (success && !nd->zc_used && skb)
@@ -53,8 +54,10 @@ void io_tx_ubuf_complete(struct sk_buff *skb, struct ubuf_info *uarg,
 		io_tx_ubuf_complete(skb, &nd->head->uarg, success);
 		return;
 	}
+
+	tw_flags = nd->next ? 0 : IOU_F_TWQ_LAZY_WAKE;
 	notif->io_task_work.func = io_notif_tw_complete;
-	__io_req_task_work_add(notif, IOU_F_TWQ_LAZY_WAKE);
+	__io_req_task_work_add(notif, tw_flags);
 }
 
 static int io_link_skb(struct sk_buff *skb, struct ubuf_info *uarg)
Signature · 1 line
2.44.0
maintainer Applied
#3 lore raw
In reply to Pavel Begunkov
Quoted 9 lines · Pavel Begunkov

LAZY_WAKE can't be used with requests for which users expect >1 CQE, otherwise wait(nr=2) may get stuck waiting for a tw that will never arrive. Fix up invalid use of LAZY_WAKE with sendzc.

Pavel Begunkov (2):
io_uring/net: fix sendzc lazy wake polling io_uring/notif: disable LAZY_WAKE for linked notifs

[...]

Applied, thanks!

[1/2] io_uring/net: fix sendzc lazy wake polling

      commit: ef42b85a5609cd822ca0a68dd2bef2b12b5d1ca3
[2/2] io_uring/notif: disable LAZY_WAKE for linked notifs
      commit: 19352a1d395424b5f8c03289a85fbd6622d6601a

Best regards,

Signature · 1 line
Jens Axboe