[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20201206044117.30859-1-kuniyu@amazon.co.jp>
Date: Sun, 6 Dec 2020 13:41:17 +0900
From: Kuniyuki Iwashima <kuniyu@...zon.co.jp>
To: <kuniyu@...zon.co.jp>
CC: <kuni1840@...il.com>, <netdev@...r.kernel.org>,
<bpf@...r.kernel.org>, <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v1 bpf-next 03/11] tcp: Migrate TCP_ESTABLISHED/TCP_SYN_RECV sockets in accept queues.
I'm sending this mail just for logging because I failed to send mails only
to LKML, netdev, and bpf yesterday.
From: Martin KaFai Lau <kafai@...com>
Date: Fri, 4 Dec 2020 17:42:41 -0800
> On Tue, Dec 01, 2020 at 11:44:10PM +0900, Kuniyuki Iwashima wrote:
> [ ... ]
> > diff --git a/net/core/sock_reuseport.c b/net/core/sock_reuseport.c
> > index fd133516ac0e..60d7c1f28809 100644
> > --- a/net/core/sock_reuseport.c
> > +++ b/net/core/sock_reuseport.c
> > @@ -216,9 +216,11 @@ int reuseport_add_sock(struct sock *sk, struct sock *sk2, bool bind_inany)
> > }
> > EXPORT_SYMBOL(reuseport_add_sock);
> >
> > -void reuseport_detach_sock(struct sock *sk)
> > +struct sock *reuseport_detach_sock(struct sock *sk)
> > {
> > struct sock_reuseport *reuse;
> > + struct bpf_prog *prog;
> > + struct sock *nsk = NULL;
> > int i;
> >
> > spin_lock_bh(&reuseport_lock);
> > @@ -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);
> Is it under rcu_read_lock() here?
reuseport_lock is locked in this function, and we do not modify the prog,
but is rcu_dereference_protected() preferable?
---8<---
prog = rcu_dereference_protected(reuse->prog,
lockdep_is_held(&reuseport_lock));
---8<---
> > if (sk->sk_protocol == IPPROTO_TCP) {
> > + if (reuse->num_socks && !prog)
> > + nsk = i == reuse->num_socks ? reuse->socks[i - 1] : reuse->socks[i];
> > +
> > 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);
> >
> > diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
> > index 1451aa9712b0..b27241ea96bd 100644
> > --- a/net/ipv4/inet_connection_sock.c
> > +++ b/net/ipv4/inet_connection_sock.c
> > @@ -992,6 +992,36 @@ struct sock *inet_csk_reqsk_queue_add(struct sock *sk,
> > }
> > EXPORT_SYMBOL(inet_csk_reqsk_queue_add);
> >
> > +void inet_csk_reqsk_queue_migrate(struct sock *sk, struct sock *nsk)
> > +{
> > + struct request_sock_queue *old_accept_queue, *new_accept_queue;
> > +
> > + old_accept_queue = &inet_csk(sk)->icsk_accept_queue;
> > + new_accept_queue = &inet_csk(nsk)->icsk_accept_queue;
> > +
> > + spin_lock(&old_accept_queue->rskq_lock);
> > + spin_lock(&new_accept_queue->rskq_lock);
> I am also not very thrilled on this double spin_lock.
> Can this be done in (or like) inet_csk_listen_stop() instead?
It will be possible to migrate sockets in inet_csk_listen_stop(), but I
think it is better to do it just after reuseport_detach_sock() becuase we
can select a different listener (almost) every time at a lower cost by
selecting the moved socket and pass it to inet_csk_reqsk_queue_migrate()
easily.
sk_hash of the listener is 0, so we would have to generate a random number
in inet_csk_listen_stop().
Powered by blists - more mailing lists