Article View: linux.kernel.netdev
Article #17154Re: [PATCH net v9 3/6] net/smc: bound the send length to the send buffer in smc_tx_sendmsg()
From: netdev-bot+sashiko
Date: Mon, 16 Nov 2026 13:00
Date: Mon, 16 Nov 2026 13:00
201 lines
16441 bytes
16441 bytes
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The patch changes the sndbuf_space invariant comment to "can be
out of range" in smc_cdc_tx_handler() (net/smc/smc_cdc.c:46) and after…
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but the clamp in
smc_tx_sendmsg() limits writespace to sndbuf_desc->len (the allocation…
- [High] This problem wasn't introduced by this patch, but the failover
catch-up in smc_switch_cursor() and the completion handler…
--
net/smc: bound the send length to the send buffer in smc_tx_sendmsg()
This commit clamps writespace in smc_tx_sendmsg() to sndbuf_desc->len,
negative values included. The goal is to keep the copy inside the send
buffer when conn->sndbuf_space has been over-credited after an SMC-R
link failover or through SMC-D DMB merge. It also rewrites the
sndbuf_space invariant comments in smc_cdc_tx_handler() and
smc_tx_sendmsg().
> diff --git a/net/smc/smc_cdc.c b/net/smc/smc_cdc.c
> index e2c765ff2ba35..90a79a983b485 100644
> --- a/net/smc/smc_cdc.c
> +++ b/net/smc/smc_cdc.c
> @@ -43,7 +43,7 @@ static void smc_cdc_tx_handler(struct smc_wr_tx_pend_priv *pnd_snd,
> /* sndbuf_space is decreased in smc_sendmsg */
> smp_mb__before_atomic();
> atomic_add(diff, &cdcpend->conn->sndbuf_space);
> - /* guarantee 0 <= sndbuf_space <= sndbuf_desc->len */
> + /* can be out of range, see smc_tx_sendmsg() */
[Severity: Low]
The comment is updated here and after the atomic_sub() in
smc_tx_sendmsg(). Two other sndbuf_space credit sites in smc_cdc.c still
have the old wording.
The dmb_nocopy branch of smc_cdc_msg_recv_action():
atomic_add(diff_tx, &conn->sndbuf_space);
/* guarantee 0 <= sndbuf_space <= sndbuf_desc->len */
and smcd_cdc_msg_send():
atomic_add(diff, &conn->sndbuf_space);
/* guarantee 0 <= sndbuf_space <= sndbuf_desc->len */
The new comment in smc_tx_sendmsg() and the commit message both list the
DMB merge path as a way for sndbuf_space to go out of range ("with SMC-D
DMB merge it follows the peer's consumer cursor"). That makes the comment
in smc_cdc_msg_recv_action() contradict them.
Should these two comments be updated too? As far as I can see, no later
patch in the series touches smc_cdc.c, so both are still there at the
end of the series.
> smp_mb__after_atomic();
> smc_curs_copy(&conn->tx_curs_fin, &cdcpend->cursor, conn);
> smc_curs_copy(&conn->local_tx_ctrl_fin, &cdcpend->p_cursor,
[Severity: High]
This is a pre-existing issue and was not introduced by this patch. Is
the failover catch-up in smc_switch_cursor() serialized against this
handler at all?
smc_switch_conns() holds only the send_lock:
spin_lock_bh(&conn->send_lock);
smc_switch_link_and_count(conn, to_lnk);
rc = smc_switch_cursor(smc, pend, wr_buf);
spin_unlock_bh(&conn->send_lock);
smc_cdc_tx_handler() runs from the old link's CQ tasklet and holds only
bh_lock_sock(&smc->sk). Both read tx_curs_fin and local_tx_ctrl_fin, and
both credit conn->sndbuf_space.
Can this interleaving credit the same bytes twice?
CPU1 smc_switch_cursor()
smc_curs_copy(&conn->tx_curs_sent, &conn->tx_curs_fin, conn);
smc_curs_copy(&fin, &conn->local_tx_ctrl_fin, conn);
CPU2 smc_cdc_tx_handler() (late completion from the old link)
atomic_add(diff, &cdcpend->conn->sndbuf_space);
smc_curs_copy(&conn->tx_curs_fin, &cdcpend->cursor, conn);
smc_curs_copy(&conn->local_tx_ctrl_fin, &cdcpend->p_cursor, conn);
CPU1
diff = smc_curs_diff(conn->peer_rmbe_size, &fin, &cons);
...
atomic_add(diff, &conn->sndbuf_space);
CPU1 computes diff from its stale fin snapshot, so it credits again the
bytes that CPU2 already credited.
In this commit, smc_switch_cursor() also updates tx_curs_fin and
local_tx_ctrl_fin with a plain read-modify-write smc_curs_add(), and
that can tear against the handler's smc_curs_copy(). The later patch in
this series, "net/smc: bound the link failover cursor advance to the
send buffer", replaces those adds with smc_curs_copy() and fixes the
tearing. Its commit message says the double credit remains:
"The switch is still not serialized against the handler: a completion
handled inside it is still credited more than once and can make the
next write hand the peer bytes it has already read."
The result is an inflated sndbuf_space. The clamp in smc_tx_sendmsg()
only bounds it where it is used.
> diff --git a/net/smc/smc_tx.c b/net/smc/smc_tx.c
> index 0f0c6df3bf2ce..3913ef103b356 100644
> --- a/net/smc/smc_tx.c
> +++ b/net/smc/smc_tx.c
> @@ -233,6 +233,14 @@ int smc_tx_sendmsg(struct smc_sock *smc, struct msghdr *msg, size_t len)
> /* initialize variables for 1st iteration of subsequent loop */
> /* could be just 1 byte, even after smc_tx_wait above */
> writespace = atomic_read(&conn->sndbuf_space);
> + /* sndbuf_space can be out of range: late completions of an
> + * old SMC-R link credit it again after a failover, and with
> + * SMC-D DMB merge it follows the peer's consumer cursor.
> + * Bound writespace, which sizes the copy; a negative value
> + * would become huge in the size_t min_t() below.
> + */
> + if (writespace < 0 || writespace > conn->sndbuf_desc->len)
> + writespace = conn->sndbuf_desc->len;
[Severity: High]
This isn't a bug introduced by this patch, but with writespace clamped
only to sndbuf_desc->len, can the send ring still overwrite data that
has not been sent or acknowledged?
The clamp limits the copy to the size of the allocation. It does not
limit it to the space that is actually free between tx_curs_fin and
tx_curs_prep.
Suppose sndbuf_space holds S > len. Each loop iteration copies up to len
bytes starting at tx_curs_prep.count, then does:
atomic_sub(copylen, &conn->sndbuf_space);
That leaves S - len > 0, so this check stops neither the loop nor later
sendmsg() calls:
if (!atomic_read(&conn->sndbuf_space) || conn->urg_tx_pend) {
A few consequences seem to follow.
First, memcpy_from_msg() overwrites [tx_curs_fin, tx_curs_prep). That
range holds bytes that are prepared but not yet sent and, for SMC-R,
bytes still being read by posted RDMA WRITEs. With SMC-D dmb_nocopy the
range is the peer's DMB. Either way, the peer silently receives the
wrong data.
Second, tx_curs_prep can get more than one ring ahead of tx_curs_sent.
smc_curs_diff() handles only a single wrap:
if (old->wrap != new->wrap)
return max_t(int, 0,
((size - old->count) + new->count));
so to_send in smc_tx_rdma_writes() comes out wrong, and bytes get
duplicated or lost. When peer_rmbe_size > sndbuf_desc->len, a single
write can carry more than sndbuf_desc->len bytes. The source reads stay
in bounds because the second source chunk is at most prep.count, which
is less than len.
Third, smc_tx_should_cork() pushes only once sndbuf_space reaches 0:
if ((msg->msg_flags & MSG_MORE ||
smc_tx_is_corked(smc)) &&
atomic_read(&conn->sndbuf_space))
return true;
With MSG_MORE or TCP_CORK set and an inflated value, corked data can be
overwritten before it is flushed.
A conforming peer can still trigger the over-credit at the end of the
series. A late completion from the old link in smc_cdc_tx_handler()
does smc_curs_copy(&conn->tx_curs_fin, &cdcpend->cursor, conn), which
moves fin back. The next completion then credits the same bytes again.
The commit message acknowledges this: "send() can still overwrite data
in the send buffer that the peer has not received".
Could writespace also be bounded by len minus the bytes outstanding
between tx_curs_fin and tx_curs_prep? Or is a follow-up planned that
fixes the credit in smc_cdc_tx_handler()?
> /* not more than what user space asked for */
> copylen = min_t(size_t, send_remaining, writespace);
> /* determine start of sndbuf */
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112-b4-disp-0287c16e-v9-0-e5e8fa688177%40proton.me
Technical Details
Message-ID:
<179483403722.3136.1364122923722036240@kernel.org>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-364316-linux-kernel-netdev=dewy.ruReferences:
<20261112-b4-disp-0287c16e-v9-3-e5e8fa688177@proton.me>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-364316-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net v9 3/6] net/smc: bound the send length to the send buffer in smc_tx_sendmsg() Date: Mon, 16 Nov 2026 13:00:37 +0000 Organization: Usenet Network Message-ID: <179483403722.3136.1364122923722036240@kernel.org> References: <20261112-b4-disp-0287c16e-v9-3-e5e8fa688177@proton.me> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="2067020"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:e3mz4KHSI/Lg7x3VzUv49Y7/IWE= sha256:z3eM//amcFuJ/MV1gSwrYZxhDn8hC0NW7rg8qCT+jzg= sha1:3gx02VZA2d6iC7fS96XZItbupdA= sha256:9EBbs5M7AYuIvY92ooka06SXpHPegMyTceRpgILf6Zc= 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 6E7E7114C10; Mon, 16 Nov 2026 16:01:22 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.4 X-Spam-Status: No, score=-3.4 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, URIBL_BLOCKED=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 d5YKR-uw7orU; Mon, 16 Nov 2026 16:01:17 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-364316-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 tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id 63EF3114C08; Mon, 16 Nov 2026 16:01:07 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id C720F2DC8E; Mon, 16 Nov 2026 13:00:49 +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=1794834044; b=TtuoMGWtM931/YgJnQKzKUQiEVfr1Q/kkcsEJ6K5l/bHxd9QJW1dDfD/i+nY7YjD59N3 FuZ360p69txPCV7xsJh6Zq1H19Xr3YxltiaPa2InJ5d/6WOvva6WEUMmAX8QGdpXsGDPK iCKN52fOzAipzQ84arKSS98fE6zFpEDSFmzZKbgfrnBZf3cGExBqOlKg2711kn+3IW0LH C7sldHZ7SKzYYUSfKhQcdbn0tH4ZMPz8mWEvYqTs1NbTs6Mki3BwApDamfKziAlLalQR/ zwyimfyurO/qQ2iiva/Hm44BH9s0PN+ewcCGRytPIowN+DPZILN2XQJke23xo1es4vw== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794834044; 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=3B7OyocIRHjJ2dbD2X+MT3B53RHHwGiwuhiBvqIoS8w=; b=ER388hL0b0odIllu7U/2pxoXjBXOCxS4zxgC88abZZjxnP25r5ArL+OHH+owvNYVVdIG Z5jGSSSb17V5FA1t/G0CXAOCJIwvKo1YSE3RgEfgsdm9ZNGJXuizT7a5nghZoxg/U88li k4n/4m6bduHt/Zjbn0JT0ffdANrVWR7ghhr5LLTzQkbC/AUt2H3j1zDwInpmQJwjDrtHh WkBfgEVqFESRCTfokF3bgtxu3drMGg+1Km6RtNnhsmUQP1gMBZykKAs21jmyhqbEKmGxP zK/CzWHCSDqBMROeI8cUuAz58MdTEeSWaYTedtnmRIuXjYPgldhUBk05HmavP+mFUkg== 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=nIdxuvzt; 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 DA92B606A336; Mon, 16 Nov 2026 13:00:44 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=nIdxuvzt 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=1794834039; b=w7XKtbhVFxwhL0Cy3wi2qCaLeg3NrS/5XpzpBr+QY7dcMbbIeX36gKRZdLWoTZb8Jmyb pWPvU/FIcdpyFyudahW76QUG+3/Gr43wZ+eouqHlldNG8+5rp8TLKn+pRZL2pKE6eDiXM gioxzioj34G9u/05w8lo/AdcjBUKyLcVLxWPDB/d56xZZqYC+rnW5ZD6CUmRg4K6amp0X ZrLpuXZPbSS2dg6mYMIxi/3NNvNazWL8TlSo/uPXsxs/zjzflGzvvXohcTwPb7H0lzDPh 2LoycfChzhcPN6WjFU5yUu3RQemWOr/pcnTY30BZc49imQ4x4hfegNxu+THksCH78lw== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794834039; 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=3B7OyocIRHjJ2dbD2X+MT3B53RHHwGiwuhiBvqIoS8w=; b=BfEgD2sFUZrZCPJzNECWJFvUZ2RvMaZ7cWbUZW/co4BS+YDaMc2kw3zeRYrjIW2hLEno /Vom8X0jUrsDv7mhjNJdYBQepRVnkNRNKmxEbrOXmhu5WvJrV2PxTYezEOIsXloac6ivG bL8UFOxa7+4xNHzRItuygzj3lIHfRwSMGcmNTKfqvrbST36DBTQncJK8e5lhZScy8rgAO B24s4Lk0JDcT4efg8mVf3D5wI21IoS+Eg+nnqICtKelskhQcXlC+8sei+U9V2psyzZ0Yy Tdnbk1h4fOfIRa+tY5t67ZevOcz3+OW62tlbrfNTG0aA+m8IgSOCPjnxxdXdpQTdSxA== 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=nIdxuvzt; 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 05A19606A33A; Mon, 16 Nov 2026 13:00:38 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id A6C0F1F000C4; Mon, 16 Nov 2026 13:00:37 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794834038; bh=3B7OyocIRHjJ2dbD2X+MT3B53RHHwGiwuhiBvqIoS8w=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=nIdxuvztI9+VcvKL/NpmGo+VzFJG/gXvgbpa025zQE6xcLzZdsdZFtH7CxrCPVtSK av2dHzf4ETYtjRhrH6/LEhMZ1fBteknXOZL22Y1B1p8dO39DNy+p86BIAJxOFEmlur 9i1pClXcTcYVJ7xXn7hDd5Vto79uO1brepfdiTy7MrtgRaOk1cd+Dkmj8S9DY0YBBA +ZjgkT/DNy+vsknbFxcDWoQk/0C/38hsWSmBl3clchGyRy3wZEYmw3eecVVugg9Gbj +Mot1TKSofGdo08QRAyKNWRlygtKESEOnmxckO5CyOl6dvim1JDTvTOLycXmR/xB8Y zlRShn5fT4D3w== X-Cc: mjambigi@linux.ibm.com, dust.li@linux.alibaba.com, edumazet@kernel.org, pabeni@redhat.com, davem@davemloft.net, kuba@kernel.org, alibuda@linux.alibaba.com, sidraya@linux.ibm.com, ubraun@linux.ibm.com, wenjia@linux.ibm.com, raspl@linux.ibm.com, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, guwen@linux.alibaba.com, tonylu@linux.alibaba.com, horms@kernel.org, guangguan.wang@linux.alibaba.com, linux-rdma@vger.kernel.org, netdev@vger.kernel.org, hidayath@linux.ibm.com X-In-Reply-To: <20261112-b4-disp-0287c16e-v9-3-e5e8fa688177@proton.me> X-sashiko-severity: Low 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