From:   Martin KaFai Lau <ka...@fb.com>
Date:   Mon, 7 Dec 2020 22:54:18 -0800
> On Tue, Dec 01, 2020 at 11:44:10PM +0900, Kuniyuki Iwashima wrote:
> 
> > @@ -242,8 +244,12 @@ void reuseport_detach_sock(struct sock *sk)
> >  
> >             reuse->num_socks--;
> >             reuse->socks[i] = reuse->socks[reuse->num_socks];
> > +           prog = rcu_dereference(reuse->prog);
> >  
> >             if (sk->sk_protocol == IPPROTO_TCP) {
> > +                   if (reuse->num_socks && !prog)
> > +                           nsk = i == reuse->num_socks ? reuse->socks[i - 
> > 1] : reuse->socks[i];
> I asked in the earlier thread if the primary use case is to only
> use the bpf prog to pick.  That thread did not come to
> a solid answer but did conclude that the sysctl should not
> control the behavior of the BPF_SK_REUSEPORT_SELECT_OR_MIGRATE prog.
> 
> From this change here, it seems it is still desired to only depend
> on the kernel to random pick even when no bpf prog is attached.

I wrote this way only to split patches into tcp and bpf parts.
So, in the 10th patch, eBPF prog is run if the type is
BPF_SK_REUSEPORT_SELECT_OR_MIGRATE.
https://lore.kernel.org/netdev/20201201144418.35045-11-kun...@amazon.co.jp/

But, it makes a breakage, so I will move
BPF_SK_REUSEPORT_SELECT_OR_MIGRATE validation into 10th patch so that the
type is only available after 10th patch.

---8<---
        case BPF_PROG_TYPE_SK_REUSEPORT:
                switch (expected_attach_type) {
                case BPF_SK_REUSEPORT_SELECT:
                case BPF_SK_REUSEPORT_SELECT_OR_MIGRATE: <- move to 10th.
                        return 0;
                default:
                        return -EINVAL;
                }
---8<---


> If that is the case, a sysctl to guard here for not changing
> the current behavior makes sense.
> It should still only control the non-bpf-pick behavior:
> when the sysctl is on, the kernel will still do a random pick
> when there is no bpf prog attached to the reuseport group.
> Thoughts?

If different applications listen on the same port without eBPF prog, I
think sysctl is necessary. But honestly, I am not sure there is really such
a case and sysctl is necessary.

If patcheset with sysctl is more acceptable, I will add it back in the next
spin.


> > +
> >                     reuse->num_closed_socks++;
> >                     reuse->socks[reuse->max_socks - 
> > reuse->num_closed_socks] = sk;
> >             } else {
> > @@ -264,6 +270,8 @@ void reuseport_detach_sock(struct sock *sk)
> >             call_rcu(&reuse->rcu, reuseport_free_rcu);
> >  out:
> >     spin_unlock_bh(&reuseport_lock);
> > +
> > +   return nsk;
> >  }
> >  EXPORT_SYMBOL(reuseport_detach_sock);

Reply via email to