Re: [PATCH v5 bpf-next 05/11] tcp: Migrate TCP_ESTABLISHED/TCP_SYN_RECV sockets in accept queues.

From: Martin KaFai Lau
Date: Fri May 14 2021 - 21:06:47 EST


On Mon, May 10, 2021 at 12:44:27PM +0900, Kuniyuki Iwashima wrote:
> diff --git a/net/core/request_sock.c b/net/core/request_sock.c
> index f35c2e998406..7879a3660c52 100644
> --- a/net/core/request_sock.c
> +++ b/net/core/request_sock.c
> @@ -130,3 +130,42 @@ void reqsk_fastopen_remove(struct sock *sk, struct request_sock *req,
> out:
> spin_unlock_bh(&fastopenq->lock);
> }
> +
> +struct request_sock *reqsk_clone(struct request_sock *req, struct sock *sk)
> +{
> + struct sock *req_sk, *nreq_sk;
> + struct request_sock *nreq;
> +
> + nreq = kmem_cache_alloc(req->rsk_ops->slab, GFP_ATOMIC | __GFP_NOWARN);
> + if (!nreq) {
> + /* paired with refcount_inc_not_zero() in reuseport_migrate_sock() */
> + sock_put(sk);
> + return NULL;
> + }
> +
> + req_sk = req_to_sk(req);
> + nreq_sk = req_to_sk(nreq);
> +
> + memcpy(nreq_sk, req_sk,
> + offsetof(struct sock, sk_dontcopy_begin));
> + memcpy(&nreq_sk->sk_dontcopy_end, &req_sk->sk_dontcopy_end,
> + req->rsk_ops->obj_size - offsetof(struct sock, sk_dontcopy_end));
> +
> + sk_node_init(&nreq_sk->sk_node);
> + nreq_sk->sk_tx_queue_mapping = req_sk->sk_tx_queue_mapping;
> +#ifdef CONFIG_XPS
> + nreq_sk->sk_rx_queue_mapping = req_sk->sk_rx_queue_mapping;
> +#endif
> + nreq_sk->sk_incoming_cpu = req_sk->sk_incoming_cpu;
> + refcount_set(&nreq_sk->sk_refcnt, 0);
> +
> + nreq->rsk_listener = sk;
> +
> + /* We need not acquire fastopenq->lock
> + * because the child socket is locked in inet_csk_listen_stop().
> + */
> + if (tcp_rsk(nreq)->tfo_listener)
Should IPPROTO_TCP be tested first like other similar situations
in inet_connection_sock.c?

Also, reqsk_clone() is only used in inet_connection_sock.c.
Can it be moved to inet_connection_sock.c instead and renamed to
inet_reqsk_clone()?