All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jens Axboe <axboe@kernel.dk>
To: David Wei <dw@davidwei.uk>, io-uring@vger.kernel.org
Cc: Pavel Begunkov <asml.silence@gmail.com>
Subject: Re: [PATCH v2] io_uring/zcrx: return early from io_zcrx_recv_skb if readlen is 0
Date: Tue, 1 Apr 2025 13:59:24 -0600	[thread overview]
Message-ID: <3d64246c-e907-44bd-b098-a5373740347b@kernel.dk> (raw)
In-Reply-To: <20250401195355.1613813-1-dw@davidwei.uk>

On 4/1/25 1:53 PM, David Wei wrote:
> 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")
> Signed-off-by: David Wei <dw@davidwei.uk>
> ---
>  io_uring/zcrx.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/io_uring/zcrx.c b/io_uring/zcrx.c
> index 9c95b5b6ec4e..2c8b29c745c5 100644
> --- a/io_uring/zcrx.c
> +++ b/io_uring/zcrx.c
> @@ -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;

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

-- 
Jens Axboe


  reply	other threads:[~2025-04-01 19:59 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-01 19:53 [PATCH v2] io_uring/zcrx: return early from io_zcrx_recv_skb if readlen is 0 David Wei
2025-04-01 19:59 ` Jens Axboe [this message]
2025-04-01 20:01 ` Jens Axboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3d64246c-e907-44bd-b098-a5373740347b@kernel.dk \
    --to=axboe@kernel.dk \
    --cc=asml.silence@gmail.com \
    --cc=dw@davidwei.uk \
    --cc=io-uring@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.