Thread (28 messages) flat view 28 messages, 3 authors, 2021-05-15

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

From: Kuniyuki Iwashima <hidden>
Date: 2021-05-15 04:14:53
Also in: bpf, lkml

From:   Martin KaFai Lau <redacted>
Date:   Fri, 14 May 2021 18:06:16 -0700
On Mon, May 10, 2021 at 12:44:27PM +0900, Kuniyuki Iwashima wrote:
quoted
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?
I've written this way because migration happens only in TCP for now, but I
agree that test of IPPROTO_TCP makes less error-prone in the future. So,
I'll test it first in the next spin.

Thank you!

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()?
I'll do that.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help