From: Martin KaFai Lau <martin.lau@linux.dev>
To: Jordan Rife <jordan@jrife.io>
Cc: netdev@vger.kernel.org, bpf@vger.kernel.org,
Aditi Ghag <aditi.ghag@isovalent.com>,
Daniel Borkmann <daniel@iogearbox.net>,
Willem de Bruijn <willemdebruijn.kernel@gmail.com>,
Kuniyuki Iwashima <kuniyu@amazon.com>,
Alexei Starovoitov <alexei.starovoitov@gmail.com>
Subject: Re: [PATCH v6 bpf-next 3/7] bpf: udp: Get rid of st_bucket_done
Date: Thu, 1 May 2025 11:28:31 -0700 [thread overview]
Message-ID: <4fc1f65c-d950-42a5-b3d2-8e7adfcb4d45@linux.dev> (raw)
In-Reply-To: <20250428180036.369192-4-jordan@jrife.io>
On 4/28/25 11:00 AM, Jordan Rife wrote:
> Get rid of the st_bucket_done field to simplify UDP iterator state and
> logic. Before, st_bucket_done could be false if bpf_iter_udp_batch
> returned a partial batch; however, with the last patch ("bpf: udp: Make
> sure iter->batch always contains a full bucket snapshot"),
> st_bucket_done == true is equivalent to iter->cur_sk == iter->end_sk.
>
> Signed-off-by: Jordan Rife <jordan@jrife.io>
> ---
> net/ipv4/udp.c | 14 ++++++--------
> 1 file changed, 6 insertions(+), 8 deletions(-)
>
> diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
> index 5fe22f4f43d7..57ac84a77e3d 100644
> --- a/net/ipv4/udp.c
> +++ b/net/ipv4/udp.c
> @@ -3397,7 +3397,6 @@ struct bpf_udp_iter_state {
> unsigned int max_sk;
> int offset;
> struct sock **batch;
> - bool st_bucket_done;
> };
>
> static int bpf_iter_udp_realloc_batch(struct bpf_udp_iter_state *iter,
> @@ -3418,7 +3417,7 @@ static struct sock *bpf_iter_udp_batch(struct seq_file *seq)
> resume_offset = iter->offset;
>
> /* The current batch is done, so advance the bucket. */
> - if (iter->st_bucket_done)
> + if (iter->cur_sk == iter->end_sk)
> state->bucket++;
I think the very first bucket will be skipped.
>
> udptable = udp_get_table_seq(seq, net);
> @@ -3433,7 +3432,6 @@ static struct sock *bpf_iter_udp_batch(struct seq_file *seq)
> */
> iter->cur_sk = 0;
> iter->end_sk = 0;
> - iter->st_bucket_done = true;
> batch_sks = 0;
>
> for (; state->bucket <= udptable->mask; state->bucket++) {
> @@ -3596,8 +3594,10 @@ static int bpf_iter_udp_seq_show(struct seq_file *seq, void *v)
>
> static void bpf_iter_udp_put_batch(struct bpf_udp_iter_state *iter)
> {
> - while (iter->cur_sk < iter->end_sk)
> - sock_put(iter->batch[iter->cur_sk++]);
> + unsigned int cur_sk = iter->cur_sk;
> +
> + while (cur_sk < iter->end_sk)
> + sock_put(iter->batch[cur_sk++]);
> }
>
> static void bpf_iter_udp_seq_stop(struct seq_file *seq, void *v)
> @@ -3613,10 +3613,8 @@ static void bpf_iter_udp_seq_stop(struct seq_file *seq, void *v)
> (void)udp_prog_seq_show(prog, &meta, v, 0, 0);
> }
>
> - if (iter->cur_sk < iter->end_sk) {
> + if (iter->cur_sk < iter->end_sk)
> bpf_iter_udp_put_batch(iter);
> - iter->st_bucket_done = false;
> - }
> }
>
> static const struct seq_operations bpf_iter_udp_seq_ops = {
next prev parent reply other threads:[~2025-05-01 18:28 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-28 18:00 [PATCH v6 bpf-next 0/7] bpf: udp: Exactly-once socket iteration Jordan Rife
2025-04-28 18:00 ` [PATCH v6 bpf-next 1/7] bpf: udp: Make mem flags configurable through bpf_iter_udp_realloc_batch Jordan Rife
2025-04-28 18:00 ` [PATCH v6 bpf-next 2/7] bpf: udp: Make sure iter->batch always contains a full bucket snapshot Jordan Rife
2025-04-28 18:00 ` [PATCH v6 bpf-next 3/7] bpf: udp: Get rid of st_bucket_done Jordan Rife
2025-05-01 18:28 ` Martin KaFai Lau [this message]
2025-04-28 18:00 ` [PATCH v6 bpf-next 4/7] bpf: udp: Use bpf_udp_iter_batch_item for bpf_udp_iter_state batch items Jordan Rife
2025-05-01 18:54 ` Martin KaFai Lau
2025-05-02 16:08 ` Jordan Rife
2025-04-28 18:00 ` [PATCH v6 bpf-next 5/7] bpf: udp: Avoid socket skips and repeats during iteration Jordan Rife
2025-05-01 18:51 ` Martin KaFai Lau
2025-05-02 16:10 ` Jordan Rife
2025-04-28 18:00 ` [PATCH v6 bpf-next 6/7] selftests/bpf: Return socket cookies from sock_iter_batch progs Jordan Rife
2025-04-28 18:00 ` [PATCH v6 bpf-next 7/7] selftests/bpf: Add tests for bucket resume logic in UDP socket iterators Jordan Rife
2025-05-01 19:00 ` Martin KaFai Lau
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=4fc1f65c-d950-42a5-b3d2-8e7adfcb4d45@linux.dev \
--to=martin.lau@linux.dev \
--cc=aditi.ghag@isovalent.com \
--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