Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: hexlabsecurity@proton.me
Cc: edumazet@kernel.org, pabeni@redhat.com, davem@davemloft.net,
	kuba@kernel.org, mjambigi@linux.ibm.com, sidraya@linux.ibm.com,
	alibuda@linux.alibaba.com, willemb@google.com,
	dust.li@linux.alibaba.com, guwen@linux.alibaba.com,
	guangguan.wang@linux.alibaba.com, tonylu@linux.alibaba.com,
	ubraun@linux.ibm.com, linux-rdma@vger.kernel.org,
	linux-s390@vger.kernel.org, hidayath@linux.ibm.com,
	horms@kernel.org, wenjia@linux.ibm.com,
	linux-kernel@vger.kernel.org, raspl@linux.ibm.com,
	netdev@vger.kernel.org
Subject: Re: [PATCH net v3 2/7] net/smc: do not credit stale CDC completions after a link switch
Date: Fri, 04 Dec 2026 09:49:29 +0000	[thread overview]
Message-ID: <179637776924.3146.12706685496080448498@kernel.org> (raw)
In-Reply-To: <20261203-b4-disp-ba1ad55e-v3-2-6834ff90c5d0@proton.me>

Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 1 · High: 0 (1) · Medium: 0 · Low: 1

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).

- [Critical] net/smc: stale CDC completion wraparound overflows
  sndbuf_space
- [Low] Undocumented stable backport dependency.

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but connections in
  closing states lose in-flight data on a link switch.

--

net/smc: do not credit stale CDC completions after a link switch

Each CDC pending send now carries a switch generation, and
smc_switch_cursor() bumps that generation. smc_cdc_tx_handler() then credits
sndbuf_space only for completions of the current generation whose cursor is
not behind tx_curs_fin. The goal is to stop rewound bytes from being
credited, and to stop the same bytes being credited twice after a link
switch.

> diff --git a/net/smc/smc_cdc.c b/net/smc/smc_cdc.c
> index 32d6d03df3214..d1f346376c08c 100644
> --- a/net/smc/smc_cdc.c
> +++ b/net/smc/smc_cdc.c
> @@ -36,7 +36,15 @@ static void smc_cdc_tx_handler(struct smc_wr_tx_pend_priv *pnd_snd,
>  	sndbuf_desc = conn->sndbuf_desc;
>  	smc = container_of(conn, struct smc_sock, conn);
>  	bh_lock_sock(&smc->sk);
> -	if (!wc_status && sndbuf_desc) {
> +	/* A CDC posted before a link switch rewound the cursors: its bytes
> +	 * are resent on the new link or credited by the switch's catch-up.
> +	 * A cursor behind tx_curs_fin (completions on two links in any
> +	 * order) was credited already.
> +	 */
> +	if (!wc_status && sndbuf_desc &&
> +	    cdcpend->switch_gen == conn->tx_switch_gen &&
> +	    smc_curs_sdiff(sndbuf_desc->len, &conn->tx_curs_fin,
> +			   &cdcpend->cursor) >= 0) {
>  		diff = smc_curs_diff(sndbuf_desc->len,
>  				     &cdcpend->conn->tx_curs_fin,
>  				     &cdcpend->cursor);

[Severity: Critical]
Can a stale completion from the old link still pass this check once
the connection has streamed far enough on the new link?

The closing-state branch in smc_switch_conns() moves SMC_APPCLOSEWAIT1
connections with smc_switch_link_and_count() only and never calls
smc_switch_cursor(), so tx_switch_gen is not bumped on that path. A CDC
still pending on the old link keeps the current generation, and the
switch_gen comparison does not filter it out.

smc_sendmsg() keeps accepting data in SMC_APPCLOSEWAIT1, so the
application can go on streaming on the new link. The old CDC does not
have to fail either. smc_ib_modify_qp_rts() sets rnr_retry to
SMC_QP_RNR_RETRY (7, retry forever), and after smc_switch_conns()
smc_llc_process_srv_delete_link() then waits in
smc_wr_tx_wait_no_pending_sends(lnk_del) with no timeout while lnk_del
stays in RTS. A peer that withholds receive WQEs on that link can keep
the WR outstanding for as long as it likes.

The comment on smc_curs_sdiff() says it only holds for cursors less
than 32768 rings apart, and nothing bounds that here. With a 16 KiB
send buffer that is 512 MiB, which does not take long on RoCE. Once
tx_curs_fin.wrap is more than 32768 ahead of cdcpend->cursor.wrap, the
s16 cast turns the negative wrap difference positive, smc_curs_sdiff()
returns a large positive value, and the >= 0 test passes.

smc_curs_diff() then only checks whether the wraps differ and returns
(sndbuf_desc->len - tx_curs_fin.count) + cdcpend->cursor.count, up to
2 * sndbuf_desc->len - 1. That is added to sndbuf_space and tx_curs_fin
is moved back to the stale cursor.

With sndbuf_space above sndbuf_desc->len, smc_tx_sendmsg() can pick a
copylen larger than the send buffer. The second chunk then calls
memcpy_from_msg() at sndbuf_base with chunk_len > sndbuf_desc->len and
writes past the end of sndbuf_desc->cpu_addr. smc_curs_add() also
leaves tx_curs_prep.count >= sndbuf_desc->len, and the next
sndbuf_desc->len - tx_cnt_prep underflows.

Bounding the check by sndbuf_desc->len would narrow this, but the u16
wrap counter aliases back after 65536 rings, so it would not close it.
Bumping tx_switch_gen in the closing-state branch alone would leave the
bytes in flight on the old link uncredited, since that branch does not
rewind or resend them. How should completions from the old link be
handled on that path, so they cannot be credited once the wrap
distance has gone past what smc_curs_sdiff() can represent?

Nothing later in the series appears to change smc_cdc_tx_handler() or
smc_switch_conns() for this.

[Severity: High]
This isn't a bug introduced by this patch, but can a connection in a
closing state lose in-flight data on a link switch?

The commit message says closing-state connections move to the new link
without a rewind. In smc_switch_conns() that branch only does this:

	if (smc->sk.sk_state == SMC_CLOSED ||
	    ...
	    smc->sk.sk_state == SMC_APPCLOSEWAIT1 ||
	    ...
	    smc->sk.sk_state == SMC_PROCESSABORT) {
		spin_lock_bh(&conn->send_lock);
		smc_switch_link_and_count(conn, to_lnk);
		spin_unlock_bh(&conn->send_lock);
		continue;
	}

So tx_curs_sent and local_tx_ctrl.prod are not rewound, and nothing is
resent.

smc_sendmsg() still accepts writes in SMC_APPCLOSEWAIT1:

	} else if ((sk->sk_state != SMC_ACTIVE) &&
		   (sk->sk_state != SMC_APPCLOSEWAIT1) &&
		   (sk->sk_state != SMC_INIT)) {

That means RDMA writes and CDCs can still be outstanding on the old link
when it fails. smcr_link_clear()->smc_ib_modify_qp_error() flushes those
WRs. They reach smc_cdc_tx_handler() through smc_wr_tx_process_cqe() with a
non-zero wc_status, so nothing is credited.

tx_curs_fin stays behind, but tx_curs_sent and local_tx_ctrl.prod already
point past the flushed range.

The next CDC posted on the new link then carries a prod cursor past the
lost range. That could be a later smc_tx_rdma_writes() send, a consumer
cursor update, or the close CDC from smc_close_wr(). Would the peer then
read stale RMB contents as stream data?

When that CDC completes, it has the current tx_switch_gen and its cursor is
ahead of tx_curs_fin. The new check accepts it, and smc_curs_diff() credits
sndbuf_space for the whole range, including the bytes that were never
delivered.

This has been present since c6f02ebeea3a ("net/smc: switch connections to
alternate link"). Nothing later in the series appears to fix the missing
resend.

[ ... ]

> diff --git a/net/smc/smc_core.c b/net/smc/smc_core.c
> index 73e86100e6db2..fb9f6a4eb6835 100644
> --- a/net/smc/smc_core.c
> +++ b/net/smc/smc_core.c
> @@ -1058,6 +1058,7 @@ static int smc_switch_cursor(struct smc_sock *smc, struct smc_cdc_tx_pend *pend,
>  	int rc = 0;
>  	int diff;
>  
> +	conn->tx_switch_gen++;	/* completions of earlier sends: no credit */
>  	smc_curs_copy(&conn->tx_curs_sent, &conn->tx_curs_fin, conn);
>  	smc_curs_copy(&fin, &conn->local_tx_ctrl_fin, conn);
>  	/* set prod cursor to old state, enforce tx_rdma_writes() */

[Severity: Low]
Does this rely on the preceding patch in the series, "net/smc: take the
socket spinlock across the failover cursor switch"?

smc_cdc_tx_handler() reads tx_switch_gen and tx_curs_fin under
bh_lock_sock() only. The handler sees this bump and the rewind after it
as atomic only because the preceding patch takes the socket spinlock
around the call in smc_switch_conns():

	local_bh_disable();
	bh_lock_sock(&smc->sk);
	spin_lock(&conn->send_lock);
	smc_switch_link_and_count(conn, to_lnk);
	rc = smc_switch_cursor(smc, pend, wr_buf);

Without that patch, smc_switch_cursor() runs under send_lock only. The
completion handler on another CPU can then see switch_gen == tx_switch_gen
just before the bump, and credit and overwrite tx_curs_fin while the switch
is rewinding it.

This hunk applies and builds without the preceding patch, and both patches
carry Cc: stable with the same Fixes: tag. "net/smc: order the urgent mark
across the cursor wrap rollover" in the same series has a "# depends on"
note. Should this commit have one too, so a stable backport does not take
it alone?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261203-b4-disp-ba1ad55e-v3-0-6834ff90c5d0%40proton.me

  reply	other threads:[~2026-12-04  9:49 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03  9:15 [PATCH net v3 0/7] net/smc: fix the failover cursor switch and wrap rollover Bryam Vargas via B4 Relay
2026-12-03  9:15 ` [PATCH net v3 1/7] net/smc: take the socket spinlock across the failover cursor switch Bryam Vargas via B4 Relay
2026-12-03  9:15 ` [PATCH net v3 2/7] net/smc: do not credit stale CDC completions after a link switch Bryam Vargas via B4 Relay
2026-12-04  9:49   ` netdev-bot+sashiko [this message]
2026-12-03  9:15 ` [PATCH net v3 3/7] net/smc: store each cursor once in smc_switch_cursor() Bryam Vargas via B4 Relay
2026-12-03  9:15 ` [PATCH net v3 4/7] net/smc: fix the failover catch-up across the cursor wrap rollover Bryam Vargas via B4 Relay
2026-12-03  9:15 ` [PATCH net v3 5/7] net/smc: order the urgent mark " Bryam Vargas via B4 Relay
2026-12-03  9:15 ` [PATCH net v3 6/7] net/smc: update the urgent state under the socket spinlock Bryam Vargas via B4 Relay
2026-12-04  9:49   ` netdev-bot+sashiko
2026-12-03  9:15 ` [PATCH net v3 7/7] net/smc: skip the urgent byte when it is the next unread byte Bryam Vargas via B4 Relay
2026-12-04  9:49   ` 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=179637776924.3146.12706685496080448498@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=alibuda@linux.alibaba.com \
    --cc=davem@davemloft.net \
    --cc=dust.li@linux.alibaba.com \
    --cc=edumazet@kernel.org \
    --cc=guangguan.wang@linux.alibaba.com \
    --cc=guwen@linux.alibaba.com \
    --cc=hexlabsecurity@proton.me \
    --cc=hidayath@linux.ibm.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=mjambigi@linux.ibm.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=raspl@linux.ibm.com \
    --cc=sidraya@linux.ibm.com \
    --cc=tonylu@linux.alibaba.com \
    --cc=ubraun@linux.ibm.com \
    --cc=wenjia@linux.ibm.com \
    --cc=willemb@google.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