Skip to contentSkip to conversation

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

PATCH Superseded David Wei 2 participants 4 messages Apr 1, 2025

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

David Wei

author
#0 lore raw

PATCH 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.

---
 io_uring/zcrx.c | 2 ++
 1 file changed, 2 insertions(+)
io_uring/zcrx.c +2 -0
index 9c95b5b6ec4e..d1dd25e7cf4a 100644
@@ -818,6 +818,8 @@ io_zcrx_recv_skb(read_descriptor_t *desc, struct sk_buff *skb,
 	int ret = 0;
 
 	len = min_t(size_t, len, desc->count);
+	if (!len)
+		goto out;
 	if (unlikely(args->nr_skbs++ > IO_SKBS_PER_CALL_LIMIT))
 		return -EAGAIN;
 
Signature · 1 line
2.47.1
maintainer
#1 lore raw
Quoted 7 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.

Needs a Fixes tag, which looks like it should be:

Fixes 6699ec9a23f8 ("io_uring/zcrx: add a read limit to recvzc requests")

?

Quoted 10 lines
---
 io_uring/zcrx.c | 2 ++
 1 file changed, 2 insertions(+)
io_uring/zcrx.c +0 -0
index 9c95b5b6ec4e..d1dd25e7cf4a 100644

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

Quoted 5 lines
io_uring/zcrx.c +2 -0
@@ -818,6 +818,8 @@ io_zcrx_recv_skb(read_descriptor_t *desc, struct sk_buff *skb,
 	int ret = 0;
 
 	len = min_t(size_t, len, desc->count);
+	if (!len)
+		goto out;

just return 0 here? Jumping to out would make more sense if there are things to fixup/account at this point, but it's just going to find offset == start_off and return 'ret', which is 0 anyway.

Signature · 1 line
Jens Axboe
author
#2 lore raw
Quoted 6 lines · Jens Axboe
Quoted 5 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.

Quoted 8 lines
Quoted 2 lines

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

Needs a Fixes tag, which looks like it should be:

Fixes 6699ec9a23f8 ("io_uring/zcrx: add a read limit to recvzc requests")

?

Sorry I missed that, will add the tag.

Quoted 13 lines
Quoted 13 lines
---
 io_uring/zcrx.c | 2 ++
 1 file changed, 2 insertions(+)
io_uring/zcrx.c +0 -0
index 9c95b5b6ec4e..d1dd25e7cf4a 100644
@@ -818,6 +818,8 @@ io_zcrx_recv_skb(read_descriptor_t *desc, struct sk_buff *skb,
 	int ret = 0;
 
Quoted 8 lines

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

Quoted 3 lines
io_uring/zcrx.c +2 -0
 	len = min_t(size_t, len, desc->count);
+	if (!len)
+		goto out;

just return 0 here? Jumping to out would make more sense if there are things to fixup/account at this point, but it's just going to find offset == start_off and return 'ret', which is 0 anyway.

Makes sense, yeah. I'll return 0 here early.

maintainer
#3 lore raw
Quoted 40 lines · David Wei
Quoted 6 lines · Jens Axboe
Quoted 5 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.

Quoted 8 lines
Quoted 2 lines

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

Needs a Fixes tag, which looks like it should be:

Fixes 6699ec9a23f8 ("io_uring/zcrx: add a read limit to recvzc requests")

?

Sorry I missed that, will add the tag.

Quoted 13 lines
Quoted 13 lines
---
 io_uring/zcrx.c | 2 ++
 1 file changed, 2 insertions(+)
io_uring/zcrx.c +0 -0
index 9c95b5b6ec4e..d1dd25e7cf4a 100644
@@ -818,6 +818,8 @@ io_zcrx_recv_skb(read_descriptor_t *desc, struct sk_buff *skb,
 	int ret = 0;
 
Quoted 8 lines

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

Quoted 3 lines
io_uring/zcrx.c +2 -0
 	len = min_t(size_t, len, desc->count);
+	if (!len)
+		goto out;

just return 0 here? Jumping to out would make more sense if there are things to fixup/account at this point, but it's just going to find offset == start_off and return 'ret', which is 0 anyway.

Quoted 1 line

Makes sense, yeah. I'll return 0 here early.

Probably augment that with an unlikely() as well for v2, it's definitely an error/unexpected case.

Signature · 1 line
Jens Axboe