Thread View: linux.kernel.netdev
2 messages
2 total messages
Started by Amery Hung
Wed, 07 Oct 2026 23:06
Re: [PATCH v4 bpf-next 09/10] bpf: tcp: Add kfunc to adjust sk->sk_rcvlowat.
Author: Amery Hung
Date: Wed, 07 Oct 2026 23:06
Date: Wed, 07 Oct 2026 23:06
53 lines
11637 bytes
11637 bytes
On Tue, Oct 6, 2026 at 12:26 PM Kuniyuki Iwashima <kuniyu@google.com> wrote:
>
> bpf_tcp_ops.{enqueue,dequeue}_rcvq() were added to parse skb and
> adjust sk->sk_rcvlowat dynamically to suppress unnecessary wakeups.
>
> Let's add a new kfunc to set sk->sk_rcvlowat.
>
> Negative values are clamped to INT_MAX, consistent with SO_RCVLOWAT.
>
> For enqueue_rcvq(), wakeup is set to false because:
>
> * tcp_data_ready() is always called after the hooks in
> tcp_queue_rcv() and tcp_ofo_queue().
>
> * when tcp_fastopen_add_skb() is called for TFO SYN, the socket is
> not yet accept()ed, and when called for TFO SYN+ACK, the socket
> is woken up by sk->sk_state_change() anyway.
>
> For dequeue_rcvq(), wakeup is set to true because tcp_data_ready()
> is not called in that path.
>
> An alternative would be to support bpf_setsockopt() for these
> hooks.
>
> However, that approach involves excessive conditionals and an
> unnecessary memcpy(), costs we do not want to pay for every skb
> in the TCP fast path.
>
> Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
> Acked-by: Stanislav Fomichev <sdf@fomichev.me>
> Tested-by: Clément Léger <cleger@meta.com>
> Reviewed-by: Emil Tsalapatis <emil@etsalapatis.com>
> ---
> net/ipv4/bpf_tcp_ops.c | 46 ++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 46 insertions(+)
>
> diff --git a/net/ipv4/bpf_tcp_ops.c b/net/ipv4/bpf_tcp_ops.c
> index 8182037c4269..2ba73dd6c52c 100644
> --- a/net/ipv4/bpf_tcp_ops.c
> +++ b/net/ipv4/bpf_tcp_ops.c
> @@ -361,12 +361,31 @@ __bpf_kfunc int bpf_tcp_ops_set_flags(struct tcp_sock *tp, u32 enable, u32 disab
> return 0;
> }
>
> +__bpf_kfunc int bpf_tcp_ops_set_rcvlowat(struct sock *sk, int rcvlowat,
> + const struct bpf_prog_aux *aux)
> +{
Is there a reason this takes struct sock * instead of struct tcp_sock
*, like bpf_tcp_ops_set_flags() in patch 2?
Re: [PATCH v4 bpf-next 09/10] bpf: tcp: Add kfunc to adjust sk->sk_rcvlowat.
Author: Amery Hung
Date: Wed, 07 Oct 2026 23:42
Date: Wed, 07 Oct 2026 23:42
71 lines
12465 bytes
12465 bytes
On Wed, Oct 7, 2026 at 4:22 PM Kuniyuki Iwashima <kuniyu@google.com> wrote:
>
> On Wed, Oct 7, 2026 at 4:06 PM Amery Hung <ameryhung@gmail.com> wrote:
> >
> > On Tue, Oct 6, 2026 at 12:26 PM Kuniyuki Iwashima <kuniyu@google.com> wrote:
> > >
> > > bpf_tcp_ops.{enqueue,dequeue}_rcvq() were added to parse skb and
> > > adjust sk->sk_rcvlowat dynamically to suppress unnecessary wakeups.
> > >
> > > Let's add a new kfunc to set sk->sk_rcvlowat.
> > >
> > > Negative values are clamped to INT_MAX, consistent with SO_RCVLOWAT.
> > >
> > > For enqueue_rcvq(), wakeup is set to false because:
> > >
> > > * tcp_data_ready() is always called after the hooks in
> > > tcp_queue_rcv() and tcp_ofo_queue().
> > >
> > > * when tcp_fastopen_add_skb() is called for TFO SYN, the socket is
> > > not yet accept()ed, and when called for TFO SYN+ACK, the socket
> > > is woken up by sk->sk_state_change() anyway.
> > >
> > > For dequeue_rcvq(), wakeup is set to true because tcp_data_ready()
> > > is not called in that path.
> > >
> > > An alternative would be to support bpf_setsockopt() for these
> > > hooks.
> > >
> > > However, that approach involves excessive conditionals and an
> > > unnecessary memcpy(), costs we do not want to pay for every skb
> > > in the TCP fast path.
> > >
> > > Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
> > > Acked-by: Stanislav Fomichev <sdf@fomichev.me>
> > > Tested-by: Clément Léger <cleger@meta.com>
> > > Reviewed-by: Emil Tsalapatis <emil@etsalapatis.com>
> > > ---
> > > net/ipv4/bpf_tcp_ops.c | 46 ++++++++++++++++++++++++++++++++++++++++++
> > > 1 file changed, 46 insertions(+)
> > >
> > > diff --git a/net/ipv4/bpf_tcp_ops.c b/net/ipv4/bpf_tcp_ops.c
> > > index 8182037c4269..2ba73dd6c52c 100644
> > > --- a/net/ipv4/bpf_tcp_ops.c
> > > +++ b/net/ipv4/bpf_tcp_ops.c
> > > @@ -361,12 +361,31 @@ __bpf_kfunc int bpf_tcp_ops_set_flags(struct tcp_sock *tp, u32 enable, u32 disab
> > > return 0;
> > > }
> > >
> > > +__bpf_kfunc int bpf_tcp_ops_set_rcvlowat(struct sock *sk, int rcvlowat,
> > > + const struct bpf_prog_aux *aux)
> > > +{
> >
> > Is there a reason this takes struct sock * instead of struct tcp_sock
> > *, like bpf_tcp_ops_set_flags() in patch 2?
>
> It also works, but bpf prog needs to cast sk to tcp_sock.
>
> This patch is straightforward and rather patch 2 has a
> reason to enforce bpf tcp_sk helper use in cgroup hooks.
Make sense. Thanks.
Reviewed-by: Amery Hung <ameryhung@gmail.com>
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads