From: Martin KaFai Lau <martin.lau@linux.dev>
To: Kuniyuki Iwashima <kuniyu@amazon.com>, jordan@jrife.io
Cc: alexei.starovoitov@gmail.com, bpf@vger.kernel.org,
daniel@iogearbox.net, netdev@vger.kernel.org,
willemdebruijn.kernel@gmail.com
Subject: Re: [PATCH v1 bpf-next 03/10] bpf: tcp: Get rid of st_bucket_done
Date: Fri, 23 May 2025 15:07:32 -0700 [thread overview]
Message-ID: <495201b0-36b9-4a97-8eb3-aedd57e039a9@linux.dev> (raw)
In-Reply-To: <20250522204443.78455-1-kuniyu@amazon.com>
On 5/22/25 1:42 PM, Kuniyuki Iwashima wrote:
> From: Jordan Rife <jordan@jrife.io>
> Date: Thu, 22 May 2025 11:16:13 -0700
>>>>> static void bpf_iter_tcp_put_batch(struct bpf_tcp_iter_state *iter)
>>>>> {
>>>>> - while (iter->cur_sk < iter->end_sk)
>>>>> - sock_gen_put(iter->batch[iter->cur_sk++]);
>>>>> + unsigned int cur_sk = iter->cur_sk;
>>>>> +
>>>>> + while (cur_sk < iter->end_sk)
>>>>> + sock_gen_put(iter->batch[cur_sk++]);
>>>>
>>>> Why is this chunk included in this patch ?
>>>
>>> This should be in patch 5 to keep cur_sk for find_cookie
>>
>> Without this, iter->cur_sk is mutated when iteration stops, and we lose
>> our place. When iteration resumes and we call bpf_iter_tcp_batch the
>> iter->cur_sk == iter->end_sk condition will always be true, so we will
>> skip to the next bucket without seeking to the offset.
>>
>> Before, we relied on st_bucket_done to tell us if we had remaining items
>> in the current bucket to process but now need to preserve iter->cur_sk
>> through iterations to make the behavior equivalent to what we had before.
>
> Thanks for explanation, I was confused by calling tcp_seek_last_pos()
> multiple times, and I think we need to preserve/restore st->offset too
> in patch 2 and need this change.
>
> diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
> index ac00015d5e7a..0816f20bfdff 100644
> --- a/net/ipv4/tcp_ipv4.c
> +++ b/net/ipv4/tcp_ipv4.c
> @@ -2791,6 +2791,7 @@ static void *tcp_seek_last_pos(struct seq_file *seq)
> break;
> st->bucket = 0;
> st->state = TCP_SEQ_STATE_ESTABLISHED;
> + offset = 0;
This seems like an existing bug not necessarily related to this set.
The patch 5 has also removed the tcp_seek_last_pos() dependency, so I think it
can be a standalone fix on its own.
> fallthrough;
> case TCP_SEQ_STATE_ESTABLISHED:
> if (st->bucket > hinfo->ehash_mask)>
>
> Let's say we are resuming at an offset (10) in the last lhash bucket
> but a few sockets (3) disappeared, then we go to the ehash part with
> a non-zero offset (3), which will overwrite st->offset (3).
>
> If the ehash does not fit into the batch size, we need to allocate
> a new batch and retry, but the offset (3) is different from the
> first try (10).
next prev parent reply other threads:[~2025-05-23 22:07 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-20 14:50 [PATCH v1 bpf-next 00/10] bpf: tcp: Exactly-once socket iteration Jordan Rife
2025-05-20 14:50 ` [PATCH v1 bpf-next 01/10] bpf: tcp: Make mem flags configurable through bpf_iter_tcp_realloc_batch Jordan Rife
2025-05-21 18:54 ` Kuniyuki Iwashima
2025-05-20 14:50 ` [PATCH v1 bpf-next 02/10] bpf: tcp: Make sure iter->batch always contains a full bucket snapshot Jordan Rife
2025-05-21 22:20 ` Kuniyuki Iwashima
2025-05-20 14:50 ` [PATCH v1 bpf-next 03/10] bpf: tcp: Get rid of st_bucket_done Jordan Rife
2025-05-21 22:57 ` Kuniyuki Iwashima
2025-05-21 23:17 ` Kuniyuki Iwashima
2025-05-22 18:16 ` Jordan Rife
2025-05-22 20:42 ` Kuniyuki Iwashima
2025-05-23 22:07 ` Martin KaFai Lau [this message]
2025-05-24 21:09 ` Jordan Rife
2025-05-27 18:19 ` Martin KaFai Lau
2025-05-20 14:50 ` [PATCH v1 bpf-next 04/10] bpf: tcp: Use bpf_tcp_iter_batch_item for bpf_tcp_iter_state batch items Jordan Rife
2025-05-21 22:59 ` Kuniyuki Iwashima
2025-05-20 14:50 ` [PATCH v1 bpf-next 05/10] bpf: tcp: Avoid socket skips and repeats during iteration Jordan Rife
2025-05-23 23:05 ` Martin KaFai Lau
2025-05-24 1:24 ` Jordan Rife
2025-05-20 14:50 ` [PATCH v1 bpf-next 06/10] selftests/bpf: Add tests for bucket resume logic in listening sockets Jordan Rife
2025-05-20 14:50 ` [PATCH v1 bpf-next 07/10] selftests/bpf: Allow for iteration over multiple ports Jordan Rife
2025-05-20 14:50 ` [PATCH v1 bpf-next 08/10] selftests/bpf: Make ehash buckets configurable in socket iterator tests Jordan Rife
2025-05-20 14:50 ` [PATCH v1 bpf-next 09/10] selftests/bpf: Create established sockets " Jordan Rife
2025-05-20 14:50 ` [PATCH v1 bpf-next 10/10] selftests/bpf: Add tests for bucket resume logic in established sockets Jordan Rife
2025-05-28 0:51 ` Martin KaFai Lau
2025-05-28 18:32 ` Jordan Rife
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=495201b0-36b9-4a97-8eb3-aedd57e039a9@linux.dev \
--to=martin.lau@linux.dev \
--cc=alexei.starovoitov@gmail.com \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=jordan@jrife.io \
--cc=kuniyu@amazon.com \
--cc=netdev@vger.kernel.org \
--cc=willemdebruijn.kernel@gmail.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox