๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #11944

Re: [PATCH net] net/smc: fix handshake abort on a terminating link group

#11944
From: netdev-bot+sashiko
Date: Fri, 06 Nov 2026 00:40
211 lines
15688 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 ยท High: 2 ยท Medium: 0 ยท Low: 0

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [High] The patch leaves the stale lgr->conns_all entry in place.
- [High] The new ownership check in smc_lgr_cleanup_early()
  (net/smc/smc_core.c:691) only tests list_empty(&lgr->list).

--

net/smc: fix handshake abort on a terminating link group

This patch makes smc_lgr_cleanup_early() return early when the link group
has already been removed from the lgr list. It also makes smc_conn_kill()
only unregister a connection that is already freed, without the full
connection and socket teardown. The goal is to avoid a self-deadlock and a
wrong abort of a fallback clcsock when a handshake abort races with link
group termination.

> diff --git a/net/smc/smc_core.c b/net/smc/smc_core.c
> index 6021322253e93..4e10da5bd8142 100644
> --- a/net/smc/smc_core.c
> +++ b/net/smc/smc_core.c
> @@ -688,9 +688,15 @@ void smc_lgr_cleanup_early(struct smc_link_group *lgr)
>
>  	smc_lgr_list_head(lgr, &lgr_lock);
>  	spin_lock_bh(lgr_lock);
> +	if (list_empty(&lgr->list)) {
> +		/* another context already removed the link group from the
> +		 * list and will terminate it
> +		 */
> +		spin_unlock_bh(lgr_lock);
> +		return;
> +	}
>  	/* do not use this link group for new connections */
> -	if (!list_empty(&lgr->list))
> -		list_del_init(&lgr->list);
> +	list_del_init(&lgr->list);
>  	spin_unlock_bh(lgr_lock);
>  	__smc_lgr_terminate(lgr, true);
>  }

[Severity: High]

Is list_empty() enough to tell that another context already owns this link
group?

smc_smcd_terminate(), smc_smcd_terminate_all() and
smc_smcr_terminate_all(NULL) move the lgr onto a private list on the stack
while holding lgr_lock, and set lgr->freeing = 1. They then walk that list
with no lock held:

net/smc/smc_core.c:smc_smcd_terminate_all() {
    ...
	spin_lock_bh(&smcd->lgr_lock);
	list_splice_init(&smcd->lgr_list, &lgr_free_list);
	list_for_each_entry(lgr, &lgr_free_list, list)
		lgr->freeing = 1;
	spin_unlock_bh(&smcd->lgr_lock);

	list_for_each_entry_safe(lgr, lg, &lgr_free_list, list) {
		list_del_init(&lgr->list);
		__smc_lgr_terminate(lgr, false);
	}
    ...
}

While the lgr is on that private list, lgr->list is not empty. A
first-contact handshake abort that reaches smc_lgr_cleanup_early() in that
window still passes the new check.

In that case, list_del_init(&lgr->list) unlinks the lgr from the other
context's private list while that list is being walked without a lock. If
this lgr is the cached next entry, it is now linked to itself, and the
walk can loop on it.

__smc_lgr_terminate() would also run at the same time as the other
context's termination. The only thing serialising them is this unlocked
check:

	if (lgr->terminating)
		return;	/* lgr already terminating */
	...
	lgr->terminating = 1;

If smc_lgr_cleanup_early() ends up freeing the lgr,
smc_smcd_terminate_all() or smc_smcr_terminate_all() can later reach the
freed lgr as their cached next element. smc_smcd_terminate() can instead
call schedule_work() on the terminate_work inside the freed lgr.

The peer can trigger smc_smcd_terminate() by sending
ISM_EVENT_CODE_SHUTDOWN, which is one way to reach this window.

The commit message says "Do not terminate a link group that another
context has already removed from the link group list". These contexts
have already removed the lgr from dev->lgr_list or smc_lgr_list.

smc_lgr_terminate_sched() already uses:

	if (list_empty(&lgr->list) || lgr->terminating || lgr->freeing) {

lgr->freeing is written under the same lgr_lock that is held here. Could
this check also test lgr->freeing and lgr->terminating?

> @@ -1519,6 +1525,17 @@ static void smc_conn_kill(struct smc_connection *conn, bool soft)
>  {
>  	struct smc_sock *smc = container_of(conn, struct smc_sock, conn);
>
> +	if (conn->freed) {
> +		/* connection was already freed, e.g. by an aborted
> +		 * handshake, but kept its entry because smc_conn_free() skips
> +		 * the unregister for a link group that is no longer on the lgr
> +		 * list. Remove the stale entry, but do not kill a socket that
> +		 * may be an established fallback connection.
> +		 */
> +		smc_lgr_unregister_conn(conn);
> +		return;
> +	}
> +

[Severity: High]

Can the stale conns_all entry still be reached through the server
handshake retry path?

When smc_conn_free() sees list_empty(&lgr->list), it skips the
unregister:

net/smc/smc_core.c:smc_conn_free() {
    ...
	if (!list_empty(&lgr->list)) {
		smc_buf_unuse(conn, lgr); /* allow buffer reuse */
		smc_lgr_unregister_conn(conn);
	}
    ...
}

After that, conn->alert_token_local is still non-zero, and conn->alert_node
is still linked in link group A's conns_all, with conn->freed = 1. Because
smc_lgr_cleanup_early() now returns early, the handshake thread carries
on instead of deadlocking.

The server device selection code can then call smc_conn_create() again on
the same new_smc->conn. One example is when smc_buf_create() fails inside
smc_listen_ism_init() with -ENOSPC on DMB exhaustion, or with -ENOMEM:

net/smc/af_smc.c:smc_find_ism_v2_device_serv() {
    ...
		rc = smc_listen_ism_init(new_smc, ini);
		if (rc) {
			smc_init_info_store_rc(rc, ini);
			/* try next active ISM device */
			continue;
		}
    ...
}

The same applies to the fall-through to ISM v1, SMC-R v2 and SMC-R v1,
and to the failure paths in smc_listen_rdma_init() and
smc_listen_rdma_reg().

On the second registration, smc_lgr_register_conn() runs:

	sock_hold(&smc->sk); /* sock_put in smc_lgr_unregister_conn() */
	while (!conn->alert_token_local) {
		...
	}
	smc_lgr_add_alert_token(conn);

The stale token means the token loop is skipped. smc_lgr_add_alert_token()
then inserts an alert_node that is still linked in A's tree into link
group B's tree. A second sock_hold() is taken, but only one sock_put()
will follow. smc_conn_create() then sets conn->freed = 0, so the new
conn->freed check in smc_conn_kill() no longer matches.

A's terminator cannot get in first, because it blocks in lock_sock() and
smc_listen_work() holds that lock for the whole handshake. Once it gets
the lock, smc_conn_kill() runs the full abort on the live connection,
which now belongs to B.

smc_lgr_unregister_conn() then erases the node from conn->lgr (B), not
from A. alert_token_local is now 0, so every later call returns early.
__smc_lgr_terminate(A) keeps getting the same node back from
rb_first(&lgr->conns_all) and never finishes.

If smcr_lgr_conn_assign_link() fails on the retry instead,
smc_lgr_register_conn() sets conn->lgr = NULL and conn->freed stays 1.
The new branch is taken, but smc_lgr_unregister_conn() returns early
because smc_conn_lgr_valid() fails, and the same endless loop follows.

Would it be more robust to do the unregister in
smc_conn_free()/smc_conn_abort() regardless of lgr->list? At minimum that
would be the rb_erase() plus clearing alert_token_local. It would replace
the conn->freed check added to smc_conn_kill().

>  	if (conn->lgr->is_smcd && conn->lgr->peer_shutdown)
>  		conn->local_tx_ctrl.conn_state_flags.peer_conn_abort = 1;
>  	else

[ ... ]

-- 
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261103123955.47454-1-mjambigi%40linux.ibm.com
Technical Details
Message-ID: <179392563025.994134.873801434242167831@kernel.org>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-357689-linux-kernel-netdev=dewy.ru
References: <20261103123955.47454-1-mjambigi@linux.ibm.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-357689-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net] net/smc: fix handshake abort on a terminating link group
Date: Fri, 06 Nov 2026 00:40:30 +0000
Organization: Usenet Network
Message-ID: <179392563025.994134.873801434242167831@kernel.org>
References: <20261103123955.47454-1-mjambigi@linux.ibm.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="3764597"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:UpbV2eqEqGFNMHFnFDDgDloYzFo= sha256:6HNSQXYFSeDD1QNy8fCHGa31crt81lUqs9cp7Ayq+Ms=
	sha1:1VsV5S0oJF3hU7i+s0mw5/m5DGY= sha256:r9QZEHV1Adwit755ZCOR+RqfbA26zVws8z0iDfrMjBs=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 6C49B113122; Fri,  6 Nov 2026 03:42:21 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id EOSbrlynViqr;
	Fri,  6 Nov 2026 03:42:17 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-357689-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 0F9DE11311E; Fri,  6 Nov 2026 03:42:09 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id A4FE72CFD3; Fri,  6 Nov 2026 00:41:08 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1793925668;
	b=bV2v1B/RwAcegaTOfuIEpWNXIAPLhR6iLced6Dcp8R4UbLWzLze5BDMmg66wKz1UX+0k
	 aDVOu8VX+XVWV1+yUVHa/Eui+Uyyyp817vcuq220PPZYVkZtWnaeqzKe/8Q9Cq51ars5r
	 P+v//XNL/kFmQoAQEFd1y3rzqg2GggkwPc6fWV2u5VtDiqpF8NydJzmQ30zbMTISDTjyz
	 mW1zF/SpkxTBK2YpP2QL1Km/BqE1VOo/F7mXj7hy1BhmJnn0sJgugIL5fDfDcs3ZUmDDi
	 u2myDX+LP5R5FpR1qITrHD6LJTuzciIZIWk2H8Kr6oY6wwwdgzFyqQbGg6gJkXsVbbQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793925668;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=+VTnnReeTMGUa8p0Zi4PIK2C6S9LMHUZpVAmJU+0osw=;
	b=v+/fOokq5aP013C90+9oiOLeYXHHmCxhhldrF8bbgqvrWBfQdcxE8sMcaNi1lfy557tY
	 giAyjyTWrnzc9yBp2jY4JVY1Q7phLSHJBHL+YvdHvHcTllCTg6yPFKHHqCKANPx053JIb
	 IKalIhsceXM9pxanUy+FEuE/f4dAYIcnTvZvdB4ZMBtsjI1Gl9aLQ0D2KHKMTKXPYQc35
	 lxBWVrNFB9oCm3t7PD+pa8hugTD/xIBOh62UD+hBKnhNjbO0tQBGYSdKzCTWbht+1AKB9
	 ZRJdGaxpnjy8kDR4USrdgWkEGp8fHY1Uxwde2p8lD7ua+fMEv3F1TVpCzMqigNZ+76g==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=eEI3jxPh;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 76424606A32C;
	Fri,  6 Nov 2026 00:41:08 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=eEI3jxPh
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1793925632;
	b=U0eyCZIfzWD4hxDy2DDn7hVdQiGvIgd7m3P3joDV5xY7Xd74QSCTmZOTjtHlTrQI/V/8
	 D/uP96D/D0cV+kXh6IfT9Kmri9Shh1ybmVpSnCxCRbYu8+1uJCO0wHXZ1Hyk1rSYzuE9U
	 iHetnvozuFtTmcVE9ungVpP/z4fK/ehG/XqZl/wFiN5Wamgx//je1n4/lMRk7NEzhjPSW
	 ypGESV4gzclKkWkfLE8xp81YpbkiLN6IJAR/SOWY9H3Jz9X6uAhoRNgxEq2OkZEZOZ3RB
	 oz088i3dURtXYQCRGSPQL0ZimCgRqUthlvs8g6g77NZ/G/DL9Q2+yeaFjiGeNZLZYKA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793925632;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=+VTnnReeTMGUa8p0Zi4PIK2C6S9LMHUZpVAmJU+0osw=;
	b=YUEOswJaU5aGt0vsOBbWRlyLns3pWdY8iE42VE1Nhqu6C4LxxgPfT4di/sXmjHk3d6vL
	 fASp72pQVRvvl/8wIKV5jfnsEt59LDiW3hJSPljrFIkdu91l+EHdhPIwTTulWbBhD6dR9
	 fzfEbrij4zUVR9kWq0YpTIPAl74vdy+eQAO56T4MRyKuPzv0CW+UEGNpbVkkqrtY0VvJq
	 tM2yMzB2Zx4Pa0uMjo9xJsODslEakxdx3JxX0mPuC3oaaUVDSKw0IZ/fT1wXXM0lM3o6/
	 5Qpf978NvIjEH5CxFPlTBlBVMWW0YNzMxDz61QrJle6R9guYwgUoadLmHT87FV6FNHA==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=eEI3jxPh;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 24803606A31B;
	Fri,  6 Nov 2026 00:40:32 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id C317D1F008A1;
	Fri,  6 Nov 2026 00:40:30 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1793925631;
	bh=+VTnnReeTMGUa8p0Zi4PIK2C6S9LMHUZpVAmJU+0osw=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=eEI3jxPhCniy53wZTmteEvNL1J+te4fsqAE+R2hcvZ3xHg4ZC6mcqo7voWJ7qfPU3
	 E5Z3wkbGquhb/wuPOGyj+V5K4RVyeG3KG+QPSEDod00Qm8UIw6wLfcGygxNSkzt1Zh
	 mtPFnl3wFEUwI00cD7v1xDJNOKuZkQzqpMX1dRw2AXntQTNDnbSuDINJYnb1kv137U
	 i2+ezkB6GHcbgmn8I0zYzO1YH/MpfLu363sYzFWM8NNEOIEl+OBED46lSYQODGBgD0
	 TSm7ts9wx6YGKosHkklzc4K8g3nmHWCeWQQVzv7SeLY+KCvzX6RxzASgPnyYp2uxIQ
	 H/spUgZP6d4Vg==
X-Cc: andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com,
 kuba@kernel.org, pabeni@redhat.com, alibuda@linux.alibaba.com,
 dust.li@linux.alibaba.com, sidraya@linux.ibm.com, hidayath@linux.ibm.com,
 pasic@linux.ibm.com, horms@kernel.org, tonylu@linux.alibaba.com,
 guwen@linux.alibaba.com, stable@vger.kernel.org, netdev@vger.kernel.org,
 linux-s390@vger.kernel.org, linux-rdma@vger.kernel.org
X-In-Reply-To: <20261103123955.47454-1-mjambigi@linux.ibm.com>
X-sashiko-severity: High
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list