diff mbox series

[net,v2,2/6] vsock: Allow retrying on connect() failure

Message ID 20250121-vsock-transport-vs-autobind-v2-2-aad6069a4e8c@rbox.co (mailing list archive)
State New
Delegated to: Netdev Maintainers
Headers show
Series vsock: Transport reassignment and error handling issues | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers warning 1 maintainers not CCed: virtualization@lists.linux.dev
netdev/build_clang success Errors and warnings before: 1 this patch: 1
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 11 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Michal Luczaj Jan. 21, 2025, 2:44 p.m. UTC
sk_err is set when a (connectible) connect() fails. Effectively, this makes
an otherwise still healthy SS_UNCONNECTED socket impossible to use for any
subsequent connection attempts.

Clear sk_err upon trying to establish a connection.

Fixes: d021c344051a ("VSOCK: Introduce VM Sockets")
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Signed-off-by: Michal Luczaj <mhal@rbox.co>
---
 net/vmw_vsock/af_vsock.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Luigi Leonardi Jan. 22, 2025, 4:28 p.m. UTC | #1
On Tue, Jan 21, 2025 at 03:44:03PM +0100, Michal Luczaj wrote:
>sk_err is set when a (connectible) connect() fails. Effectively, this makes
>an otherwise still healthy SS_UNCONNECTED socket impossible to use for any
>subsequent connection attempts.
>
>Clear sk_err upon trying to establish a connection.
>
>Fixes: d021c344051a ("VSOCK: Introduce VM Sockets")
>Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
>Signed-off-by: Michal Luczaj <mhal@rbox.co>
>---
> net/vmw_vsock/af_vsock.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
>diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
>index cfe18bc8fdbe7ced073c6b3644d635fdbfa02610..075695173648d3a4ecbd04e908130efdbb393b41 100644
>--- a/net/vmw_vsock/af_vsock.c
>+++ b/net/vmw_vsock/af_vsock.c
>@@ -1523,6 +1523,11 @@ static int vsock_connect(struct socket *sock, struct sockaddr *addr,
> 		if (err < 0)
> 			goto out;
>
>+		/* sk_err might have been set as a result of an earlier
>+		 * (failed) connect attempt.
>+		 */
>+		sk->sk_err = 0;
Just to understand: Why do you reset sk_error after calling to 
transport->connect and not before?

My worry is that a transport might check this field and return an error.
IIUC with virtio-based transports this is not the case.
>+
> 		/* Mark sock as connecting and set the error code to in
> 		 * progress in case this is a non-blocking connect.
> 		 */
>
>-- 
>2.48.1
>

Thanks,
Luigi
Michal Luczaj Jan. 22, 2025, 9:06 p.m. UTC | #2
On 1/22/25 17:28, Luigi Leonardi wrote:
> On Tue, Jan 21, 2025 at 03:44:03PM +0100, Michal Luczaj wrote:
>> sk_err is set when a (connectible) connect() fails. Effectively, this makes
>> an otherwise still healthy SS_UNCONNECTED socket impossible to use for any
>> subsequent connection attempts.
>>
>> Clear sk_err upon trying to establish a connection.
>>
>> Fixes: d021c344051a ("VSOCK: Introduce VM Sockets")
>> Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
>> Signed-off-by: Michal Luczaj <mhal@rbox.co>
>> ---
>> net/vmw_vsock/af_vsock.c | 5 +++++
>> 1 file changed, 5 insertions(+)
>>
>> diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
>> index cfe18bc8fdbe7ced073c6b3644d635fdbfa02610..075695173648d3a4ecbd04e908130efdbb393b41 100644
>> --- a/net/vmw_vsock/af_vsock.c
>> +++ b/net/vmw_vsock/af_vsock.c
>> @@ -1523,6 +1523,11 @@ static int vsock_connect(struct socket *sock, struct sockaddr *addr,
>> 		if (err < 0)
>> 			goto out;
>>
>> +		/* sk_err might have been set as a result of an earlier
>> +		 * (failed) connect attempt.
>> +		 */
>> +		sk->sk_err = 0;
>
> Just to understand: Why do you reset sk_error after calling to 
> transport->connect and not before?

transport->connect() can fail. In such case, I thought, it would be better
to keep the old value of sk_err. Otherwise we'd have an early failing
vsock_connect() that clears sk_err.

> My worry is that a transport might check this field and return an error.
> IIUC with virtio-based transports this is not the case.

Right, transport might check, but currently none of the transports do.
Luigi Leonardi Jan. 23, 2025, 11:42 a.m. UTC | #3
On Wed, Jan 22, 2025 at 10:06:51PM +0100, Michal Luczaj wrote:
>On 1/22/25 17:28, Luigi Leonardi wrote:
>> On Tue, Jan 21, 2025 at 03:44:03PM +0100, Michal Luczaj wrote:
>>> sk_err is set when a (connectible) connect() fails. Effectively, this makes
>>> an otherwise still healthy SS_UNCONNECTED socket impossible to use for any
>>> subsequent connection attempts.
>>>
>>> Clear sk_err upon trying to establish a connection.
>>>
>>> Fixes: d021c344051a ("VSOCK: Introduce VM Sockets")
>>> Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
>>> Signed-off-by: Michal Luczaj <mhal@rbox.co>
>>> ---
>>> net/vmw_vsock/af_vsock.c | 5 +++++
>>> 1 file changed, 5 insertions(+)
>>>
>>> diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
>>> index cfe18bc8fdbe7ced073c6b3644d635fdbfa02610..075695173648d3a4ecbd04e908130efdbb393b41 100644
>>> --- a/net/vmw_vsock/af_vsock.c
>>> +++ b/net/vmw_vsock/af_vsock.c
>>> @@ -1523,6 +1523,11 @@ static int vsock_connect(struct socket *sock, struct sockaddr *addr,
>>> 		if (err < 0)
>>> 			goto out;
>>>
>>> +		/* sk_err might have been set as a result of an earlier
>>> +		 * (failed) connect attempt.
>>> +		 */
>>> +		sk->sk_err = 0;
>>
>> Just to understand: Why do you reset sk_error after calling to
>> transport->connect and not before?
>
>transport->connect() can fail. In such case, I thought, it would be better
>to keep the old value of sk_err. Otherwise we'd have an early failing
>vsock_connect() that clears sk_err.
That's a good point, transport->connect doesn't set sk_err if it fails.
Thanks for the clarification :)

Reviewed-by: Luigi Leonardi <leonardi@redhat.com>
>
>> My worry is that a transport might check this field and return an error.
>> IIUC with virtio-based transports this is not the case.
>
>Right, transport might check, but currently none of the transports do.
>
diff mbox series

Patch

diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
index cfe18bc8fdbe7ced073c6b3644d635fdbfa02610..075695173648d3a4ecbd04e908130efdbb393b41 100644
--- a/net/vmw_vsock/af_vsock.c
+++ b/net/vmw_vsock/af_vsock.c
@@ -1523,6 +1523,11 @@  static int vsock_connect(struct socket *sock, struct sockaddr *addr,
 		if (err < 0)
 			goto out;
 
+		/* sk_err might have been set as a result of an earlier
+		 * (failed) connect attempt.
+		 */
+		sk->sk_err = 0;
+
 		/* Mark sock as connecting and set the error code to in
 		 * progress in case this is a non-blocking connect.
 		 */