Skip to contentSkip to conversation

io_uring/zcrx: return early from io_zcrx_recv_skb if readlen is 0

PATCH Applied David Wei 2 participants 3 messages Apr 1, 2025

Subsystems (2)
lore
Share & tools
lore

David Wei

author
#0 lore raw

PATCH v2 1/1 io_uring/zcrx: return early from io_zcrx_recv_skb if readlen is 0

When readlen is set for a recvzc request, tcp_read_sock() will call io_zcrx_recv_skb() one final time with len == desc->count == 0. This is caused by the !desc->count check happening too late. The offset + 1 != skb->len happens earlier and causes the while loop to continue.

Fix this in io_zcrx_recv_skb() instead of tcp_read_sock(). Return early if len is 0 i.e. the read is done.

Changes in v2:
--------------
* Add Fixes tag
* Return 0 directly
* Add comment explaining why the !len check is needed

Fixes 6699ec9a23f8 ("io_uring/zcrx: add a read limit to recvzc requests")
---
 io_uring/zcrx.c | 7 +++++++
 1 file changed, 7 insertions(+)
io_uring/zcrx.c +7 -0
index 9c95b5b6ec4e..2c8b29c745c5 100644
@@ -818,6 +818,13 @@ io_zcrx_recv_skb(read_descriptor_t *desc, struct sk_buff *skb,
 	int ret = 0;
 
 	len = min_t(size_t, len, desc->count);
+	/* __tcp_read_sock() always calls io_zcrx_recv_skb one last time, even
+	 * if desc->count is already 0. This is caused by the if (offset + 1 !=
+	 * skb->len) check. Return early in this case to break out of
+	 * __tcp_read_sock().
+	 */
+	if (!len)
+		return 0;
 	if (unlikely(args->nr_skbs++ > IO_SKBS_PER_CALL_LIMIT))
 		return -EAGAIN;
 
Signature · 1 line
2.47.1
maintainer
#1 lore raw
Quoted 27 lines · David Wei

When readlen is set for a recvzc request, tcp_read_sock() will call io_zcrx_recv_skb() one final time with len == desc->count == 0. This is caused by the !desc->count check happening too late. The offset + 1 != skb->len happens earlier and causes the while loop to continue.

Fix this in io_zcrx_recv_skb() instead of tcp_read_sock(). Return early if len is 0 i.e. the read is done.

Changes in v2:
--------------
* Add Fixes tag
* Return 0 directly
* Add comment explaining why the !len check is needed

Fixes 6699ec9a23f8 ("io_uring/zcrx: add a read limit to recvzc requests")
---
 io_uring/zcrx.c | 7 +++++++
 1 file changed, 7 insertions(+)
io_uring/zcrx.c +0 -0
index 9c95b5b6ec4e..2c8b29c745c5 100644
@@ -818,6 +818,13 @@ io_zcrx_recv_skb(read_descriptor_t *desc, struct sk_buff *skb,
 	int ret = 0;
 

io_uring/zcrx.c io_zcrx_recv_skb(read_descriptor_t *desc, struct sk_buff *skb, · line 829

Quoted 10 lines
io_uring/zcrx.c +7 -0
 	len = min_t(size_t, len, desc->count);
+	/* __tcp_read_sock() always calls io_zcrx_recv_skb one last time, even
+	 * if desc->count is already 0. This is caused by the if (offset + 1 !=
+	 * skb->len) check. Return early in this case to break out of
+	 * __tcp_read_sock().
+	 */
+	if (!len)
+		return 0;
 	if (unlikely(args->nr_skbs++ > IO_SKBS_PER_CALL_LIMIT))
 		return -EAGAIN;

Bad comment format, but I can fix it up while applying. Thanks!

Signature · 1 line
Jens Axboe
maintainer Applied
#2 lore raw
In reply to David Wei
Quoted 9 lines · David Wei

When readlen is set for a recvzc request, tcp_read_sock() will call io_zcrx_recv_skb() one final time with len == desc->count == 0. This is caused by the !desc->count check happening too late. The offset + 1 != skb->len happens earlier and causes the while loop to continue.

Fix this in io_zcrx_recv_skb() instead of tcp_read_sock(). Return early if len is 0 i.e. the read is done.

[...]

Applied, thanks!

[1/1] io_uring/zcrx: return early from io_zcrx_recv_skb if readlen is 0

      commit: fcfd94d6967a98e88b834c9fd81e73c5f04d83dc

Best regards,

Signature · 1 line
Jens Axboe