Linux s390 Architecture development
 help / color / mirror / Atom feed
* [PATCH net] net/smc: fix missing sk_err when TCP handshake fails
@ 2026-05-06  1:41 D. Wythe
  2026-05-07 15:03 ` Dust Li
  2026-05-07 15:50 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: D. Wythe @ 2026-05-06  1:41 UTC (permalink / raw)
  To: David S. Miller, Dust Li, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Sidraya Jayagond, Wenjia Zhang
  Cc: Karsten Graul, Mahanta Jambigi, Simon Horman, Tony Lu,
	Ursula Braun, Wen Gu, linux-kernel, linux-rdma, linux-s390,
	netdev, oliver.yang, pasic

In smc_connect_work(), when the underlying TCP handshake fails, the error
code (rc) must be propagated to sk_err to ensure userspace can correctly
retrieve the error status via SO_ERROR. Currently, the code only handles
a restricted set of error codes (e.g., EPIPE, ECONNREFUSED). If other
errors occurs, such as EHOSTUNREACH, sk_err remains unset (zero).

This affects applications that rely on SO_ERROR to determine connect
outcome. For example, higher versions of Go's netpoller treats
SO_ERROR == 0 combined with a failed getpeername() as a spurious wakeup
and re-enters epoll_wait(). Under ET mode, no further edge will be
generated since the socket is already in a terminal state, causing the
connect to hang indefinitely or until a user-specified timeout, if one
is set.

Fixes: 50717a37db03 ("net/smc: nonblocking connect rework")
Signed-off-by: D. Wythe <alibuda@linux.alibaba.com>
---
 net/smc/af_smc.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c
index 1a565095376a..185dbed7de5d 100644
--- a/net/smc/af_smc.c
+++ b/net/smc/af_smc.c
@@ -1628,12 +1628,8 @@ static void smc_connect_work(struct work_struct *work)
 	lock_sock(&smc->sk);
 	if (rc != 0 || smc->sk.sk_err) {
 		smc->sk.sk_state = SMC_CLOSED;
-		if (rc == -EPIPE || rc == -EAGAIN)
-			smc->sk.sk_err = EPIPE;
-		else if (rc == -ECONNREFUSED)
-			smc->sk.sk_err = ECONNREFUSED;
-		else if (signal_pending(current))
-			smc->sk.sk_err = -sock_intr_errno(timeo);
+		if (!smc->sk.sk_err)
+			smc->sk.sk_err = (rc == -EAGAIN) ? EPIPE : -rc;
 		sock_put(&smc->sk); /* passive closing */
 		goto out;
 	}
-- 
2.45.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net] net/smc: fix missing sk_err when TCP handshake fails
  2026-05-06  1:41 [PATCH net] net/smc: fix missing sk_err when TCP handshake fails D. Wythe
@ 2026-05-07 15:03 ` Dust Li
  2026-05-07 15:50 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Dust Li @ 2026-05-07 15:03 UTC (permalink / raw)
  To: D. Wythe, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Sidraya Jayagond, Wenjia Zhang
  Cc: Karsten Graul, Mahanta Jambigi, Simon Horman, Tony Lu,
	Ursula Braun, Wen Gu, linux-kernel, linux-rdma, linux-s390,
	netdev, oliver.yang, pasic

On 2026-05-06 09:41:05, D. Wythe wrote:
>In smc_connect_work(), when the underlying TCP handshake fails, the error
>code (rc) must be propagated to sk_err to ensure userspace can correctly
>retrieve the error status via SO_ERROR. Currently, the code only handles
>a restricted set of error codes (e.g., EPIPE, ECONNREFUSED). If other
>errors occurs, such as EHOSTUNREACH, sk_err remains unset (zero).
>
>This affects applications that rely on SO_ERROR to determine connect
>outcome. For example, higher versions of Go's netpoller treats
>SO_ERROR == 0 combined with a failed getpeername() as a spurious wakeup
>and re-enters epoll_wait(). Under ET mode, no further edge will be
>generated since the socket is already in a terminal state, causing the
>connect to hang indefinitely or until a user-specified timeout, if one
>is set.
>
>Fixes: 50717a37db03 ("net/smc: nonblocking connect rework")
>Signed-off-by: D. Wythe <alibuda@linux.alibaba.com>

Reviewed-by: Dust Li <dust.li@linux.alibaba.com>

Best regards,
Dust

>---
> net/smc/af_smc.c | 8 ++------
> 1 file changed, 2 insertions(+), 6 deletions(-)
>
>diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c
>index 1a565095376a..185dbed7de5d 100644
>--- a/net/smc/af_smc.c
>+++ b/net/smc/af_smc.c
>@@ -1628,12 +1628,8 @@ static void smc_connect_work(struct work_struct *work)
> 	lock_sock(&smc->sk);
> 	if (rc != 0 || smc->sk.sk_err) {
> 		smc->sk.sk_state = SMC_CLOSED;
>-		if (rc == -EPIPE || rc == -EAGAIN)
>-			smc->sk.sk_err = EPIPE;
>-		else if (rc == -ECONNREFUSED)
>-			smc->sk.sk_err = ECONNREFUSED;
>-		else if (signal_pending(current))
>-			smc->sk.sk_err = -sock_intr_errno(timeo);
>+		if (!smc->sk.sk_err)
>+			smc->sk.sk_err = (rc == -EAGAIN) ? EPIPE : -rc;
> 		sock_put(&smc->sk); /* passive closing */
> 		goto out;
> 	}
>-- 
>2.45.0

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net] net/smc: fix missing sk_err when TCP handshake fails
  2026-05-06  1:41 [PATCH net] net/smc: fix missing sk_err when TCP handshake fails D. Wythe
  2026-05-07 15:03 ` Dust Li
@ 2026-05-07 15:50 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-05-07 15:50 UTC (permalink / raw)
  To: D. Wythe
  Cc: davem, dust.li, edumazet, kuba, pabeni, sidraya, wenjia, kgraul,
	mjambigi, horms, tonylu, ubraun, guwen, linux-kernel, linux-rdma,
	linux-s390, netdev, oliver.yang, pasic

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Wed,  6 May 2026 09:41:05 +0800 you wrote:
> In smc_connect_work(), when the underlying TCP handshake fails, the error
> code (rc) must be propagated to sk_err to ensure userspace can correctly
> retrieve the error status via SO_ERROR. Currently, the code only handles
> a restricted set of error codes (e.g., EPIPE, ECONNREFUSED). If other
> errors occurs, such as EHOSTUNREACH, sk_err remains unset (zero).
> 
> This affects applications that rely on SO_ERROR to determine connect
> outcome. For example, higher versions of Go's netpoller treats
> SO_ERROR == 0 combined with a failed getpeername() as a spurious wakeup
> and re-enters epoll_wait(). Under ET mode, no further edge will be
> generated since the socket is already in a terminal state, causing the
> connect to hang indefinitely or until a user-specified timeout, if one
> is set.
> 
> [...]

Here is the summary with links:
  - [net] net/smc: fix missing sk_err when TCP handshake fails
    https://git.kernel.org/netdev/net/c/9032f7676935

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-05-07 15:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-06  1:41 [PATCH net] net/smc: fix missing sk_err when TCP handshake fails D. Wythe
2026-05-07 15:03 ` Dust Li
2026-05-07 15:50 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox