]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
vsock: introduce vsock_pending_to_accept() helper
authorRaf Dickson <rafdog35@gmail.com>
Fri, 12 Jun 2026 04:52:13 +0000 (04:52 +0000)
committerJakub Kicinski <kuba@kernel.org>
Sat, 13 Jun 2026 17:38:27 +0000 (10:38 -0700)
Add vsock_pending_to_accept() to move a socket directly from the
pending list to the accept queue in a single operation, avoiding
the sock_put/sock_hold dance and the sk_acceptq_removed()/
sk_acceptq_added() pair that would otherwise be needed when
calling vsock_remove_pending() followed by vsock_enqueue_accept().

Use it in vmci_transport_recv_connecting_server() where a completed
handshake transitions the socket from pending to accept queue.

Suggested-by: Stefano Garzarella <sgarzare@redhat.com>
Signed-off-by: Raf Dickson <rafdog35@gmail.com>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Reviewed-by: Luigi Leonardi <leonardi@redhat.com>
Reviewed-by: Bobby Eshleman <bobbyeshleman@meta.com>
Link: https://patch.msgid.link/20260612045216.105796-2-rafdog35@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
include/net/af_vsock.h
net/vmw_vsock/af_vsock.c
net/vmw_vsock/vmci_transport.c

index 4e40063adab47bae1bd9cdab7b5a71e40f2ce809..30046a3c20f735e484a9add6e1617cbe1b08feb7 100644 (file)
@@ -220,6 +220,7 @@ static inline bool __vsock_in_connected_table(struct vsock_sock *vsk)
 void vsock_add_pending(struct sock *listener, struct sock *pending);
 void vsock_remove_pending(struct sock *listener, struct sock *pending);
 void vsock_enqueue_accept(struct sock *listener, struct sock *connected);
+void vsock_pending_to_accept(struct sock *listener, struct sock *pending);
 void vsock_insert_connected(struct vsock_sock *vsk);
 void vsock_remove_bound(struct vsock_sock *vsk);
 void vsock_remove_connected(struct vsock_sock *vsk);
index 1b20ec4985186c9304daf5cab8ddc8a830d198d0..2a267283aef80440dc4ec2db04bb315aefb88cb6 100644 (file)
@@ -497,6 +497,16 @@ void vsock_remove_pending(struct sock *listener, struct sock *pending)
 }
 EXPORT_SYMBOL_GPL(vsock_remove_pending);
 
+void vsock_pending_to_accept(struct sock *listener, struct sock *pending)
+{
+       struct vsock_sock *vpending = vsock_sk(pending);
+       struct vsock_sock *vlistener = vsock_sk(listener);
+
+       list_del_init(&vpending->pending_links);
+       list_add_tail(&vpending->accept_queue, &vlistener->accept_queue);
+}
+EXPORT_SYMBOL_GPL(vsock_pending_to_accept);
+
 void vsock_enqueue_accept(struct sock *listener, struct sock *connected)
 {
        struct vsock_sock *vlistener;
index 56503bee3165bf0cb35efbc1615d2e34e3daa2c5..af64fd57c0c85deffb1aaa3e530ba1b58495c1d0 100644 (file)
@@ -1258,8 +1258,7 @@ vmci_transport_recv_connecting_server(struct sock *listener,
         * listener's pending list to the accept queue so callers of accept()
         * can find it.
         */
-       vsock_remove_pending(listener, pending);
-       vsock_enqueue_accept(listener, pending);
+       vsock_pending_to_accept(listener, pending);
 
        /* Callers of accept() will be waiting on the listening socket, not
         * the pending socket.