mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Michal Luczaj <mhal@rbox.co>
To: Stefano Garzarella <sgarzare@redhat.com>
Cc: "Stefan Hajnoczi" <stefanha@redhat.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Jason Wang" <jasowangio@gmail.com>,
	"Eugenio Pérez" <eperezma@redhat.com>,
	"David S. Miller" <davem@davemloft.net>,
	"Xuan Zhuo" <xuanzhuo@linux.alibaba.com>,
	"Eric Dumazet" <edumazet@google.com>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Paolo Abeni" <pabeni@redhat.com>,
	"Simon Horman" <horms@kernel.org>, "Asias He" <asias@redhat.com>,
	kvm@vger.kernel.org, virtualization@lists.linux.dev,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net v2 5/5] vsock: Handle sudden TCP_CLOSE during connect
Date: Tue, 22 Sep 2026 15:18:05 +0200	[thread overview]
Message-ID: <036cb16f-c3b6-4e94-9c3d-42e40d160833@rbox.co> (raw)
In-Reply-To: <aqqIuUadZ_E1skmR@sgarzare-redhat>

On 9/16/26 14:31, Stefano Garzarella wrote:
> On Tue, Sep 15, 2026 at 03:15:16PM +0200, Michal Luczaj wrote:
>> Virtio/PM events are serviced by virtio_vsock_reset_sock(), which resets
> 
> What "PM" means here?

Power Management, namely virtio_vsock_driver.freeze which is defined under
CONFIG_PM_SLEEP. I'll generalize this comment, as suggested below.

>> each connected socket. The reset is done under vsock_table_lock but without
>> taking lock_sock(), so from the point of view of vsock_connect() -
>> locklessly. The same pattern exists in VMCI's
>> vmci_transport_handle_detach() and vhost's vhost_vsock_reset_orphans().
>>
>> The complexity of connect() comes from the fact that:
>> 1. the virtio transport can be reassigned, so the old transport must be
>>   safely released;
>> 2. a failed connect can be followed by a retry, so the socket must be
>>   reverted to a sensible state.
>> Both cases apply only as long as the socket has not yet established a
>> connection.
>>
>> While connect() waits for TCP_SYN_SENT -> TCP_ESTABLISHED, other
>> transitions can also occur:
>>
>>  TCP_SYN_SENT -> TCP_CLOSE on connection failure, timeout or signal
>>  TCP_SYN_SENT -> TCP_ESTABLISHED -> TCP_CLOSING on VIRTIO_VSOCK_OP_RST
>>  TCP_SYN_SENT -> TCP_ESTABLISHED -> [TCP_CLOSING ->] TCP_CLOSE on event
>>
>> This further complicates connect(). Rather than making every event handler
>> drop the socket from connected_table or adapting connect() to handle more
>> transitions (while missing proper locking), use vsk->peer_shutdown as a
>> poison flag. Whatever state an event leaves the socket in, the flag bricks
>> it and prevents suspicious transport reassignments or TCP_SYN_SENT
>> retransmissions.
>>
>> Fixes: d021c344051a ("VSOCK: Introduce VM Sockets")
>> Signed-off-by: Michal Luczaj <mhal@rbox.co>
>> ---
>> net/vmw_vsock/af_vsock.c | 6 ++++++
>> 1 file changed, 6 insertions(+)
>>
>> diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
>> index adf3f018347e..972952d04a81 100644
>> --- a/net/vmw_vsock/af_vsock.c
>> +++ b/net/vmw_vsock/af_vsock.c
>> @@ -1743,6 +1743,12 @@ static int vsock_connect(struct socket *sock, struct sockaddr_unsized *addr,
>> 			goto out;
>> 		}
>>
>> +		/* Virtio/PM events are serviced locklessly. */
> 
> IMO we should be generic here (i.e. don't mention virtio or mention it 
> like one of the transport, but IIUC also VMCI does something similar) 
> and also we should explain better why we are doing this, like you did in 
> the commit description.

Sure, will do.

> Maybe we should document this behaviour also on top of this file.

OK, do you mind if I do that as a follow up? I worry top of the file needs
few more updates.

>> +		if (READ_ONCE(vsk->peer_shutdown)) {
>> +			err = -ECONNRESET;
> 
> Is ECONNRESET a valid connect() error to return?
> 
>> +			goto out;
>> +		}
>> +
> 
>  From LLM reviewing, can you check if it's valid? :
>    - M (net/vmw_vsock/af_vsock.c:1747): VMCI regression.  vmci_transport_handle_detach() sets
>      peer_shutdown = SHUTDOWN_MASK unconditionally and then special-cases TCP_SYN_SENT with the
>      comment "we treat the detach event like a reset" — i.e. a connect() retry is the expected
>      recovery. It is reachable for a non-connected socket via vmci_transport_peer_detach_cb() (which
>      uses trans->sk, not the connected table). Since vsock_assign_transport() only clears
>      peer_shutdown when the transport actually changes (af_vsock.c:671-689), the retry now hits the
>      new check and returns -ECONNRESET forever: the fd is permanently bricked where it previously
>      reconnected.

I'm not sure I follow the logic. SHUTDOWN_MASK gets set no matter what's
the state at vmci_transport_handle_detach(). That means even if vmci's
reconnect succeeds, all the recvmsg()/sendmsg() at af_vsock layer would
fail anyway. Am I missing something?

thanks,
Michal


  reply	other threads:[~2026-09-22 13:18 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-15 13:15 [PATCH net v2 0/5] vsock: Fix connect() races Michal Luczaj
2026-09-15 13:15 ` [PATCH net v2 1/5] vhost/vsock: Fix socket state constant Michal Luczaj
2026-09-16 12:28   ` Stefano Garzarella
2026-09-15 13:15 ` [PATCH net v2 2/5] vsock/virtio: Streamline socket reset on transport/PM event Michal Luczaj
2026-09-16 12:30   ` Stefano Garzarella
2026-09-22 13:17     ` Michal Luczaj
2026-09-24 10:06       ` Stefano Garzarella
2026-09-24 21:26         ` Michal Luczaj
2026-09-16 23:39   ` netdev-bot+sashiko
2026-09-15 13:15 ` [PATCH net v2 3/5] vsock: Enforce no-transport invariant for TCP_LISTEN sockets Michal Luczaj
2026-09-16 12:30   ` Stefano Garzarella
2026-09-22 13:18     ` Michal Luczaj
2026-09-24 10:17       ` Stefano Garzarella
2026-09-24 21:26         ` Michal Luczaj
2026-09-28 10:31           ` Stefano Garzarella
2026-09-16 23:39   ` netdev-bot+sashiko
2026-09-15 13:15 ` [PATCH net v2 4/5] vsock: Do not reset a TCP_CLOSING socket Michal Luczaj
2026-09-16 12:30   ` Stefano Garzarella
2026-09-22 13:17     ` Michal Luczaj
2026-09-16 23:39   ` netdev-bot+sashiko
2026-09-15 13:15 ` [PATCH net v2 5/5] vsock: Handle sudden TCP_CLOSE during connect Michal Luczaj
2026-09-16 12:31   ` Stefano Garzarella
2026-09-22 13:18     ` Michal Luczaj [this message]
2026-09-28 10:44       ` Stefano Garzarella
2026-09-16 23:39   ` netdev-bot+sashiko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=036cb16f-c3b6-4e94-9c3d-42e40d160833@rbox.co \
    --to=mhal@rbox.co \
    --cc=asias@redhat.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=eperezma@redhat.com \
    --cc=horms@kernel.org \
    --cc=jasowangio@gmail.com \
    --cc=kuba@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sgarzare@redhat.com \
    --cc=stefanha@redhat.com \
    --cc=virtualization@lists.linux.dev \
    --cc=xuanzhuo@linux.alibaba.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®