Merge branch 'vsock-consolidate-acceptq-accounting-into-core-helpers'

Raf Dickson says:

====================
vsock: consolidate acceptq accounting into core helpers

These patches follow up on commit c05fa14db4
("vsock/vmci: fix sk_ack_backlog leak on failed handshake")
by consolidating sk_acceptq_added() and sk_acceptq_removed() into
the core vsock helpers so transports cannot forget them.

Link: https://lore.kernel.org/netdev/20260611021317.69362-1-rafdog35@gmail.com/
====================

Link: https://patch.msgid.link/20260612045216.105796-1-rafdog35@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Jakub Kicinski 2026-06-13 10:39:32 -07:00
commit 30b81fc779
5 changed files with 16 additions and 10 deletions

View 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);

View File

@ -484,6 +484,7 @@ void vsock_add_pending(struct sock *listener, struct sock *pending)
sock_hold(pending);
sock_hold(listener);
list_add_tail(&vpending->pending_links, &vlistener->pending_links);
sk_acceptq_added(listener);
}
EXPORT_SYMBOL_GPL(vsock_add_pending);
@ -494,9 +495,20 @@ void vsock_remove_pending(struct sock *listener, struct sock *pending)
list_del_init(&vpending->pending_links);
sock_put(listener);
sock_put(pending);
sk_acceptq_removed(listener);
}
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;
@ -508,6 +520,7 @@ void vsock_enqueue_accept(struct sock *listener, struct sock *connected)
sock_hold(connected);
sock_hold(listener);
list_add_tail(&vconnected->accept_queue, &vlistener->accept_queue);
sk_acceptq_added(listener);
}
EXPORT_SYMBOL_GPL(vsock_enqueue_accept);
@ -761,8 +774,6 @@ static void vsock_pending_work(struct work_struct *work)
if (vsock_is_pending(sk)) {
vsock_remove_pending(listener, sk);
sk_acceptq_removed(listener);
} else if (!vsk->rejected) {
/* We are not on the pending list and accept() did not reject
* us, so we must have been accepted by our user process. We

View File

@ -410,7 +410,6 @@ static void hvs_open_connection(struct vmbus_channel *chan)
if (conn_from_host) {
new->sk_state = TCP_ESTABLISHED;
sk_acceptq_added(sk);
hvs_new->vm_srv_id = *if_type;
hvs_new->host_srv_id = *if_instance;

View File

@ -1582,7 +1582,6 @@ virtio_transport_recv_listen(struct sock *sk, struct sk_buff *skb,
return ret;
}
sk_acceptq_added(sk);
if (virtio_transport_space_update(child, skb))
child->sk_write_space(child);

View File

@ -980,10 +980,8 @@ static int vmci_transport_recv_listen(struct sock *sk,
err = -EINVAL;
}
if (err < 0) {
if (err < 0)
vsock_remove_pending(sk, pending);
sk_acceptq_removed(sk);
}
release_sock(pending);
vmci_transport_release_pending(pending);
@ -1109,7 +1107,6 @@ static int vmci_transport_recv_listen(struct sock *sk,
}
vsock_add_pending(sk, pending);
sk_acceptq_added(sk);
pending->sk_state = TCP_SYN_SENT;
vmci_trans(vpending)->produce_size =
@ -1258,8 +1255,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.