* [PATCH bpf] bpf: tcp: Use sock_gen_put instead of sock_put in bpf_iter_tcp
@ 2023-03-28 0:42 Martin KaFai Lau
2023-03-28 8:53 ` Daniel Borkmann
0 siblings, 1 reply; 2+ messages in thread
From: Martin KaFai Lau @ 2023-03-28 0:42 UTC (permalink / raw)
To: bpf
Cc: 'Alexei Starovoitov ', 'Andrii Nakryiko ',
'Daniel Borkmann ',
netdev, kernel-team
From: Martin KaFai Lau <martin.lau@kernel.org>
While reviewing the udp-iter batching patches, notice the bpf_iter_tcp
calling sock_put() is incorrect. It should call sock_gen_put instead
because bpf_iter_tcp is iterating the ehash table which has the
req sk and tw sk. This patch replaces all sock_put with sock_gen_put
in the bpf_iter_tcp codepath.
Fixes: 04c7820b776f ("bpf: tcp: Bpf iter batching and lock_sock")
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
---
net/ipv4/tcp_ipv4.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index ea370afa70ed..b9d55277cb85 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -2780,7 +2780,7 @@ static int tcp_prog_seq_show(struct bpf_prog *prog, struct bpf_iter_meta *meta,
static void bpf_iter_tcp_put_batch(struct bpf_tcp_iter_state *iter)
{
while (iter->cur_sk < iter->end_sk)
- sock_put(iter->batch[iter->cur_sk++]);
+ sock_gen_put(iter->batch[iter->cur_sk++]);
}
static int bpf_iter_tcp_realloc_batch(struct bpf_tcp_iter_state *iter,
@@ -2941,7 +2941,7 @@ static void *bpf_iter_tcp_seq_next(struct seq_file *seq, void *v, loff_t *pos)
* st->bucket. See tcp_seek_last_pos().
*/
st->offset++;
- sock_put(iter->batch[iter->cur_sk++]);
+ sock_gen_put(iter->batch[iter->cur_sk++]);
}
if (iter->cur_sk < iter->end_sk)
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH bpf] bpf: tcp: Use sock_gen_put instead of sock_put in bpf_iter_tcp
2023-03-28 0:42 [PATCH bpf] bpf: tcp: Use sock_gen_put instead of sock_put in bpf_iter_tcp Martin KaFai Lau
@ 2023-03-28 8:53 ` Daniel Borkmann
0 siblings, 0 replies; 2+ messages in thread
From: Daniel Borkmann @ 2023-03-28 8:53 UTC (permalink / raw)
To: Martin KaFai Lau, bpf
Cc: 'Alexei Starovoitov ', 'Andrii Nakryiko ',
netdev, kernel-team
On 3/28/23 2:42 AM, Martin KaFai Lau wrote:
> From: Martin KaFai Lau <martin.lau@kernel.org>
>
> While reviewing the udp-iter batching patches, notice the bpf_iter_tcp
> calling sock_put() is incorrect. It should call sock_gen_put instead
> because bpf_iter_tcp is iterating the ehash table which has the
> req sk and tw sk. This patch replaces all sock_put with sock_gen_put
> in the bpf_iter_tcp codepath.
>
> Fixes: 04c7820b776f ("bpf: tcp: Bpf iter batching and lock_sock")
> Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
Looks like patchbot is on vacation :( The below looks good to me, so I
applied it to bpf, thanks!
> net/ipv4/tcp_ipv4.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
> index ea370afa70ed..b9d55277cb85 100644
> --- a/net/ipv4/tcp_ipv4.c
> +++ b/net/ipv4/tcp_ipv4.c
> @@ -2780,7 +2780,7 @@ static int tcp_prog_seq_show(struct bpf_prog *prog, struct bpf_iter_meta *meta,
> static void bpf_iter_tcp_put_batch(struct bpf_tcp_iter_state *iter)
> {
> while (iter->cur_sk < iter->end_sk)
> - sock_put(iter->batch[iter->cur_sk++]);
> + sock_gen_put(iter->batch[iter->cur_sk++]);
> }
>
> static int bpf_iter_tcp_realloc_batch(struct bpf_tcp_iter_state *iter,
> @@ -2941,7 +2941,7 @@ static void *bpf_iter_tcp_seq_next(struct seq_file *seq, void *v, loff_t *pos)
> * st->bucket. See tcp_seek_last_pos().
> */
> st->offset++;
> - sock_put(iter->batch[iter->cur_sk++]);
> + sock_gen_put(iter->batch[iter->cur_sk++]);
> }
>
> if (iter->cur_sk < iter->end_sk)
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-03-28 8:53 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-28 0:42 [PATCH bpf] bpf: tcp: Use sock_gen_put instead of sock_put in bpf_iter_tcp Martin KaFai Lau
2023-03-28 8:53 ` Daniel Borkmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).