From: Stefano Garzarella <sgarzare@redhat.com>
To: Michal Luczaj <mhal@rbox.co>
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 3/5] vsock: Enforce no-transport invariant for TCP_LISTEN sockets
Date: Thu, 24 Sep 2026 12:17:04 +0200 [thread overview]
Message-ID: <arT3jXoS7OaU6Tsc@sgarzare-redhat> (raw)
In-Reply-To: <0bc40e5c-8790-4a36-84bc-80e0bfe6b504@rbox.co>
On Tue, Sep 22, 2026 at 03:18:13PM +0200, Michal Luczaj wrote:
>On 9/16/26 14:30, Stefano Garzarella wrote:
>> On Tue, Sep 15, 2026 at 03:15:14PM +0200, Michal Luczaj wrote:
>>> A non-blocking connect() running in parallel with a blocking connect(),
>>> combined with a racy listen() that hits right after a connect timeout:
>>> TCP_SYN_SENT -> TCP_CLOSE -> TCP_LISTEN, while the connect() loop is still
>>> in progress.
>>>
>>> Enforce the invariant. Prevent a socket from becoming a listener after
>>> acquiring a transport.
>>
>> We should improve this comment; it's not entirely clear to me, TBH.
>
>The race I was thinking about:
>
>sk is CLOSE UNCONNECTED
>non-blocking connect():
> sk := SYN_SENT CONNECTING
> enqueue vsock_connect_timeout()
> blocking connect():
> release_sock()
> schedule_timeout()
>vsock_connect_timeout():
> sk := CLOSE UNCONNECTED
>listen():
> sk := LISTEN UNCONNECTED
> lock_sock()
> sk is TCP_LISTEN UNCONNECTED
>
>It's not really critical (blocking connect() just timeouts), but I thought
>the invariant should be enforced once and for all.
I see, would it better to do this change in net-next?
>
>>> @@ -1973,13 +1973,13 @@ static int vsock_listen(struct socket *sock, int backlog)
>>> goto out;
>>> }
>>>
>>> - if (sock->state != SS_UNCONNECTED) {
>>> + vsk = vsock_sk(sk);
>>> +
>>> + if (sock->state != SS_UNCONNECTED || vsk->transport) {
>>
>> Are we changing the behavior when an error occurs?
>>
>> If we call `connect()` on a socket (with no others running in parallel),
>> it fails, and then when we call `listen()`, it now fails, whereas before
>> it didn't. Can this happen? Is that what we want?
>
>Ah, true, I didn't consider that. So yeah, we'd changing the behaviour.
>
>> If so, we should mention it at least in the commit description; if not,
>> perhaps we should unassign the transport in the `connect` call.
>
>Do you mean immediately un-assign on every transition from SYN_SENT to
>CLOSE (failure, timeout, signal)? Then we could also drop the re-assign
>logic. I think that's a nice idea.
yeah, that!
>
>---
>
>I've addressed all your other comments for v2 and went through Ashiko's
>reports (side effects of lockless peer_shutdown write, imperfect
>no-transport TCP_LISTENER enforcement). I've decided to try the
>eager-unassign approach. I think/hope this way we sidestep the lockless
>writes and enforce the invariant without breaking the API, while fixing the
>bugs.
>
>This should probably be RFC, but I'm posting as v3[1] so netdev's LLM can
>have a go (too). Hope I'm not breaking any workflow. Let me know what you
>think.
I think you can add RFC also on a v3 patch, just to make it clear you
are not sure it's ready to be merged.
That said, thanks for that :-) I'll take a look today or next week
because I'm off tomorrow.
I'm just worried it's becoming too big for net. Anyway, I'll comment
there.
Thanks,
Stefano
next prev parent reply other threads:[~2026-09-24 10:17 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 [this message]
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
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=arT3jXoS7OaU6Tsc@sgarzare-redhat \
--to=sgarzare@redhat.com \
--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=mhal@rbox.co \
--cc=mst@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@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®