vsock: consolidate acceptq accounting into core helpers
Subsystems (7)
v3 cover vsock: consolidate acceptq accounting into core helpers
These patches follow up on commit c05fa14db43e ("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.
Changes since v2:
- Add vsock_pending_to_accept() helper for the vmci pending->accept transition, avoiding a double sk_acceptq_added() (Stefano Garzarella)
- Split into 4 patches for bisectability (Stefano Garzarella)
- Fold sk_acceptq_added() into vsock_add_pending() as a separate patch
Raf Dickson (4):
vsock: introduce vsock_pending_to_accept() helper
vsock: fold sk_acceptq_added() into vsock_add_pending()
vsock: fold sk_acceptq_added() into vsock_enqueue_accept()
vsock: fold sk_acceptq_removed() into vsock_remove_pending()
include/net/af_vsock.h | 1 + net/vmw_vsock/af_vsock.c | 14 +++++++++++++- net/vmw_vsock/hyperv_transport.c | 1 - net/vmw_vsock/virtio_transport_common.c | 1 - net/vmw_vsock/vmci_transport.c | 8 ++------ 5 files changed, 16 insertions(+), 9 deletions(-)
Signature · 1 line
2.54.0
PATCH v3 1/4 vsock: introduce vsock_pending_to_accept() helper
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.
--- include/net/af_vsock.h | 1 + net/vmw_vsock/af_vsock.c | 10 ++++++++++ net/vmw_vsock/vmci_transport.c | 3 +-- 3 files changed, 12 insertions(+), 2 deletions(-)
include/net/af_vsock.h +1 -0
@@ -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);
net/vmw_vsock/af_vsock.c +10 -0
@@ -496,6 +496,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;
net/vmw_vsock/vmci_transport.c +1 -2
@@ -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.
Signature · 1 line
2.54.0
Re: [PATCH net-next v3 1/4] vsock: introduce vsock_pending_to_accept() helper
Quoted 9 lines · Raf Dickson
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 callingvsock_remove_pending()followed byvsock_enqueue_accept().Use it in
vmci_transport_recv_connecting_server()where a completed handshake transitions the socket from pending to accept queue.
Quoted 7 lines
Suggested-by Stefano Garzarella <[email protected]>Signed-off-by Raf Dickson <[email protected]>---
include/net/af_vsock.h | 1 + net/vmw_vsock/af_vsock.c | 10 ++++++++++ net/vmw_vsock/vmci_transport.c | 3 +-- 3 files changed, 12 insertions(+), 2 deletions(-)
Re: [PATCH net-next v3 1/4] vsock: introduce vsock_pending_to_accept() helper
In reply to Raf DicksonQuoted 11 lines · Raf Dickson
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 callingvsock_remove_pending()followed byvsock_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 <[email protected]>Signed-off-by Raf Dickson <[email protected]>
Re: [PATCH net-next v3 1/4] vsock: introduce vsock_pending_to_accept() helper
In reply to Raf DicksonQuoted 67 lines · Raf Dickson
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 callingvsock_remove_pending()followed byvsock_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 <[email protected]>Signed-off-by Raf Dickson <[email protected]>--- include/net/af_vsock.h | 1 + net/vmw_vsock/af_vsock.c | 10 ++++++++++ net/vmw_vsock/vmci_transport.c | 3 +-- 3 files changed, 12 insertions(+), 2 deletions(-)include/net/af_vsock.h +1
-0@@ -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);net/vmw_vsock/af_vsock.c +10
-0@@ -496,6 +496,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;net/vmw_vsock/vmci_transport.c +1
-2@@ -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. Signature · 1 line
2.54.0
PATCH v3 2/4 vsock: fold sk_acceptq_added() into vsock_add_pending()
In reply to Raf DicksonMove sk_acceptq_added() into vsock_add_pending() so callers cannot forget it. vmci is the only transport using the pending list and is updated accordingly.
--- net/vmw_vsock/af_vsock.c | 1 + net/vmw_vsock/vmci_transport.c | 1 - 2 files changed, 1 insertion(+), 1 deletion(-)
net/vmw_vsock/af_vsock.c +1 -0
@@ -483,6 +483,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);
net/vmw_vsock/vmci_transport.c +0 -1
@@ -1109,7 +1109,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 =
Signature · 1 line
2.54.0
Re: [PATCH net-next v3 2/4] vsock: fold sk_acceptq_added() into vsock_add_pending()
Quoted 10 lines · Raf Dickson
Move
sk_acceptq_added()intovsock_add_pending()so callers cannot forget it. vmci is the only transport using the pending list and is updated accordingly.Suggested-by Stefano Garzarella <[email protected]>Signed-off-by Raf Dickson <[email protected]>---
net/vmw_vsock/af_vsock.c| 1 +net/vmw_vsock/vmci_transport.c| 1 -2 files changed, 1 insertion(+), 1 deletion(-)
Re: [PATCH net-next v3 2/4] vsock: fold sk_acceptq_added() into vsock_add_pending()
In reply to Raf DicksonQuoted 6 lines · Raf Dickson
Move
sk_acceptq_added()intovsock_add_pending()so callers cannot forget it. vmci is the only transport using the pending list and is updated accordingly.Suggested-by Stefano Garzarella <[email protected]>Signed-off-by Raf Dickson <[email protected]>
Re: [PATCH net-next v3 2/4] vsock: fold sk_acceptq_added() into vsock_add_pending()
In reply to Raf DicksonQuoted 38 lines · Raf Dickson
Move
sk_acceptq_added()intovsock_add_pending()so callers cannot forget it. vmci is the only transport using the pending list and is updated accordingly.Suggested-by Stefano Garzarella <[email protected]>Signed-off-by Raf Dickson <[email protected]>--- net/vmw_vsock/af_vsock.c | 1 + net/vmw_vsock/vmci_transport.c | 1 - 2 files changed, 1 insertion(+), 1 deletion(-)net/vmw_vsock/af_vsock.c +1
-0@@ -483,6 +483,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);net/vmw_vsock/vmci_transport.c +0
-1@@ -1109,7 +1109,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 =Signature · 1 line
2.54.0
PATCH v3 3/4 vsock: fold sk_acceptq_added() into vsock_enqueue_accept()
In reply to Raf Dicksonvirtio and hyperv call sk_acceptq_added() immediately before vsock_enqueue_accept(). Move the call into vsock_enqueue_accept() itself so callers cannot forget it and the accounting is consistent.
--- net/vmw_vsock/af_vsock.c | 1 + net/vmw_vsock/hyperv_transport.c | 1 - net/vmw_vsock/virtio_transport_common.c | 1 - 3 files changed, 1 insertion(+), 2 deletions(-)
net/vmw_vsock/af_vsock.c +1 -0
@@ -518,6 +518,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);
net/vmw_vsock/hyperv_transport.c +0 -1
@@ -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;
net/vmw_vsock/virtio_transport_common.c +0 -1
@@ -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);
Signature · 1 line
2.54.0
Re: [PATCH net-next v3 3/4] vsock: fold sk_acceptq_added() into vsock_enqueue_accept()
Quoted 4 lines · Raf Dickson
virtio and hyperv call
sk_acceptq_added()immediately beforevsock_enqueue_accept(). Move the call intovsock_enqueue_accept()itself so callers cannot forget it and the accounting is consistent.
Quoted 8 lines
Suggested-by Paolo Abeni <[email protected]>Suggested-by Stefano Garzarella <[email protected]>Signed-off-by Raf Dickson <[email protected]>---
net/vmw_vsock/af_vsock.c | 1 + net/vmw_vsock/hyperv_transport.c | 1 - net/vmw_vsock/virtio_transport_common.c | 1 - 3 files changed, 1 insertion(+), 2 deletions(-)
Re: [PATCH net-next v3 3/4] vsock: fold sk_acceptq_added() into vsock_enqueue_accept()
In reply to Raf DicksonQuoted 7 lines · Raf Dickson
virtio and hyperv call
sk_acceptq_added()immediately beforevsock_enqueue_accept(). Move the call intovsock_enqueue_accept()itself so callers cannot forget it and the accounting is consistent.Suggested-by Paolo Abeni <[email protected]>Suggested-by Stefano Garzarella <[email protected]>Signed-off-by Raf Dickson <[email protected]>
Re: [PATCH net-next v3 3/4] vsock: fold sk_acceptq_added() into vsock_enqueue_accept()
In reply to Raf DicksonQuoted 52 lines · Raf Dickson
virtio and hyperv call
sk_acceptq_added()immediately beforevsock_enqueue_accept(). Move the call intovsock_enqueue_accept()itself so callers cannot forget it and the accounting is consistent.Suggested-by Paolo Abeni <[email protected]>Suggested-by Stefano Garzarella <[email protected]>Signed-off-by Raf Dickson <[email protected]>--- net/vmw_vsock/af_vsock.c | 1 + net/vmw_vsock/hyperv_transport.c | 1 - net/vmw_vsock/virtio_transport_common.c | 1 - 3 files changed, 1 insertion(+), 2 deletions(-)net/vmw_vsock/af_vsock.c +1
-0@@ -518,6 +518,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);net/vmw_vsock/hyperv_transport.c +0
-1@@ -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;net/vmw_vsock/virtio_transport_common.c +0
-1@@ -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);Signature · 1 line
2.54.0
PATCH v3 4/4 vsock: fold sk_acceptq_removed() into vsock_remove_pending()
In reply to Raf DicksonCallers of vsock_remove_pending() must also call sk_acceptq_removed() to keep sk_ack_backlog consistent. Move the call into vsock_remove_pending() itself to make it automatic and prevent future callers from forgetting it.
--- net/vmw_vsock/af_vsock.c | 2 +- net/vmw_vsock/vmci_transport.c | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-)
net/vmw_vsock/af_vsock.c +1 -1
@@ -494,6 +494,7 @@ 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);
@@ -773,7 +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
net/vmw_vsock/vmci_transport.c +1 -3
@@ -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);
Signature · 1 line
2.54.0
Re: [PATCH net-next v3 4/4] vsock: fold sk_acceptq_removed() into vsock_remove_pending()
Quoted 25 lines · Raf Dickson
Callers of
vsock_remove_pending()must also callsk_acceptq_removed()to keepsk_ack_backlogconsistent. Move the call intovsock_remove_pending()itself to make it automatic and prevent future callers from forgetting it.Suggested-by Stefano Garzarella <[email protected]>Signed-off-by Raf Dickson <[email protected]>---
net/vmw_vsock/af_vsock.c| 2 +-net/vmw_vsock/vmci_transport.c| 4 +---2 files changed, 2 insertions(+), 4 deletions(-)net/vmw_vsock/af_vsock.c +1
-0@@ -494,6 +494,7 @@ 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);
net/vmw_vsock/af_vsock.c static void vsock_pending_work(struct work_struct *work) · line 776
Quoted 3 lines
net/vmw_vsock/af_vsock.c +0
-0@@ -773,7 +774,6 @@ static void vsock_pending_work(struct work_struct *work)if (vsock_is_pending (sk)) {vsock_remove_pending (listener, sk);
^^
There is an extra blank line that we can now remove here.
BTW, the code LGTM:
Quoted 23 lines
net/vmw_vsock/af_vsock.c +0
-1-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 net/vmw_vsock/vmci_transport.c +1
-3@@ -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);Signature · 1 line
2.54.0
Jakub Kicinski
maintainerRe: [PATCH net-next v3 4/4] vsock: fold sk_acceptq_removed() into vsock_remove_pending()
Quoted 8 lines · On Fri, 12 Jun 2026 12:48:14 +0200 Stefano Garzarella wrote:
net/vmw_vsock/af_vsock.c static void vsock_pending_work(struct work_struct *work) · line 776
Quoted 4 lines
net/vmw_vsock/af_vsock.c +0
-0@@ -773,7 +774,6 @@ static void vsock_pending_work(struct work_struct *work)if (vsock_is_pending (sk)) {vsock_remove_pending (listener, sk);^^There is an extra blank line that we can now remove here.
BTW, the code LGTM:
Since the merge window is upon us - also updated when applying.
Re: [PATCH net-next v3 4/4] vsock: fold sk_acceptq_removed() into vsock_remove_pending()
In reply to Raf DicksonQuoted 7 lines · Raf Dickson
Callers of
vsock_remove_pending()must also callsk_acceptq_removed()to keepsk_ack_backlogconsistent. Move the call intovsock_remove_pending()itself to make it automatic and prevent future callers from forgetting it.Suggested-by Stefano Garzarella <[email protected]>Signed-off-by Raf Dickson <[email protected]>
Re: [PATCH net-next v3 4/4] vsock: fold sk_acceptq_removed() into vsock_remove_pending()
In reply to Raf DicksonQuoted 51 lines · Raf Dickson
Callers of
vsock_remove_pending()must also callsk_acceptq_removed()to keepsk_ack_backlogconsistent. Move the call intovsock_remove_pending()itself to make it automatic and prevent future callers from forgetting it.Suggested-by Stefano Garzarella <[email protected]>Signed-off-by Raf Dickson <[email protected]>--- net/vmw_vsock/af_vsock.c | 2 +- net/vmw_vsock/vmci_transport.c | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-)net/vmw_vsock/af_vsock.c +1
-1@@ -494,6 +494,7 @@ 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);@@ -773,7 +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 net/vmw_vsock/vmci_transport.c +1
-3@@ -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);Signature · 1 line
2.54.0
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 5 lines · On Fri, 12 Jun 2026 04:52:12 +0000 you wrote:
These patches follow up on commit
c05fa14db43e("vsock/vmci: fixsk_ack_backlogleak on failed handshake") by consolidatingsk_acceptq_added()andsk_acceptq_removed()into the core vsock helpers so transports cannot forget them.
Quoted 7 lines
Changes since v2:
- Addvsock_pending_to_accept()helper for the vmcipending->accepttransition, avoiding a doublesk_acceptq_added()(Stefano Garzarella)
- Split into 4 patches for bisectability (Stefano Garzarella)
- Foldsk_acceptq_added()intovsock_add_pending()as a separate patch[...]
Here is the summary with links:
- [net-next,v3,1/4] vsock: introduce vsock_pending_to_accept() helper
https://git.kernel.org/netdev/net-next/c/77eee189397d - [net-next,v3,2/4] vsock: fold sk_acceptq_added() into vsock_add_pending() https://git.kernel.org/netdev/net-next/c/a6fd2cfdcdf5 - [net-next,v3,3/4] vsock: fold sk_acceptq_added() into vsock_enqueue_accept() https://git.kernel.org/netdev/net-next/c/6f6f9b65a991 - [net-next,v3,4/4] vsock: fold sk_acceptq_removed() into vsock_remove_pending() https://git.kernel.org/netdev/net-next/c/27fc25bb82e6
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html