From: Sidraya Jayagond <sidraya@linux.ibm.com>
To: hexlabsecurity@proton.me,
Mahanta Jambigi <mjambigi@linux.ibm.com>,
"D. Wythe" <alibuda@linux.alibaba.com>,
Eric Dumazet <edumazet@kernel.org>,
"David S. Miller" <davem@davemloft.net>,
Paolo Abeni <pabeni@redhat.com>, Jakub Kicinski <kuba@kernel.org>,
Dust Li <dust.li@linux.alibaba.com>
Cc: Stefan Raspl <raspl@linux.ibm.com>,
Simon Horman <horms@kernel.org>,
Guangguan Wang <guangguan.wang@linux.alibaba.com>,
Wen Gu <guwen@linux.alibaba.com>,
linux-s390@vger.kernel.org, linux-rdma@vger.kernel.org,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
Tony Lu <tonylu@linux.alibaba.com>,
Ursula Braun <ubraun@linux.ibm.com>,
Hidayath Khan <hidayath@linux.ibm.com>,
Wenjia Zhang <wenjia@linux.ibm.com>
Subject: Re: [PATCH net v2 3/6] net/smc: store each cursor once in smc_switch_cursor()
Date: Tue, 1 Dec 2026 14:33:06 +0530 [thread overview]
Message-ID: <a4e68c5b-4cf1-4b0e-b4fb-fb7c84fc5f28@linux.ibm.com> (raw)
In-Reply-To: <20261128-b4-disp-360e65c5-v2-3-d9c05004d430@proton.me>
On 28/11/26 7:53 pm, Bryam Vargas via B4 Relay wrote:
> From: Bryam Vargas <hexlabsecurity@proton.me>
>
> smc_switch_cursor() rewinds tx_curs_sent and local_tx_ctrl.prod, then
> advances them and the two fin cursors in place with smc_curs_add(),
> which updates count and wrap in separate steps. smc_tx_prepared_sends()
> reads tx_curs_sent without send_lock or the socket spinlock, e.g. from
> smc_close_stream_wait(): a cursor caught between the wrap increment and
> the reduction of the count reads as nothing left to send, and close()
> stops waiting while data is still queued.
>
> Compute the cursors on local copies and store each of them once with
> smc_curs_copy(), as smc_tx_rdma_writes() does.
>
> Fixes: c6f02ebeea3a ("net/smc: switch connections to alternate link")
> Reported-by: Sashiko <sashiko-bot@kernel.org>
> Closes: https://lore.kernel.org/all/sashiko-outbox-215218@kernel.org/
> Cc: stable@vger.kernel.org
> Signed-off-by: Bryam Vargas <hexlabsecurity@proton.me>
> ---
> net/smc/smc_core.c | 37 +++++++++++++++++++------------------
> 1 file changed, 19 insertions(+), 18 deletions(-)
>
> diff --git a/net/smc/smc_core.c b/net/smc/smc_core.c
> index fb9f6a4eb683..4ee9e6f0d659 100644
> --- a/net/smc/smc_core.c
> +++ b/net/smc/smc_core.c
> @@ -1054,36 +1054,37 @@ static int smc_switch_cursor(struct smc_sock *smc, struct smc_cdc_tx_pend *pend,
> struct smc_wr_buf *wr_buf)
> {
> struct smc_connection *conn = &smc->conn;
> - union smc_host_cursor cons, fin;
> + union smc_host_cursor cons, prod, sent;
> 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() */
> - smc_curs_copy(&conn->local_tx_ctrl.prod, &fin, conn);
> + /* The cursors of the connection have readers outside send_lock and
> + * the socket spinlock: work on copies and store each cursor once.
> + */
> + smc_curs_copy(&sent, &conn->tx_curs_fin, conn);
> + smc_curs_copy(&prod, &conn->local_tx_ctrl_fin, conn);
> smc_curs_copy(&cons, &conn->local_rx_ctrl.cons, conn);
>
> - if (smc_curs_comp(conn->peer_rmbe_size, &cons, &fin) < 0) {
> - /* cons cursor advanced more than fin, and prod was set
> - * fin above, so now prod is smaller than cons. Fix that.
> + if (smc_curs_comp(conn->peer_rmbe_size, &cons, &prod) < 0) {
> + /* cons cursor advanced more than fin: the peer has read
> + * that far, so resend from there and count it as confirmed.
> */
> - diff = smc_curs_diff(conn->peer_rmbe_size, &fin, &cons);
> - smc_curs_add(conn->sndbuf_desc->len,
> - &conn->tx_curs_sent, diff);
> - smc_curs_add(conn->sndbuf_desc->len,
> - &conn->tx_curs_fin, diff);
> + diff = smc_curs_diff(conn->peer_rmbe_size, &prod, &cons);
> + smc_curs_add(conn->sndbuf_desc->len, &sent, diff);
> + smc_curs_add(conn->peer_rmbe_size, &prod, diff);
> + smc_curs_copy(&conn->tx_curs_fin, &sent, conn);
> + smc_curs_copy(&conn->local_tx_ctrl_fin, &prod, conn);
>
> smp_mb__before_atomic();
> atomic_add(diff, &conn->sndbuf_space);
> smp_mb__after_atomic();
> -
> - smc_curs_add(conn->peer_rmbe_size,
> - &conn->local_tx_ctrl.prod, diff);
> - smc_curs_add(conn->peer_rmbe_size,
> - &conn->local_tx_ctrl_fin, diff);
> }
> + /* set the sent and prod cursors to the resend's start, enforce
> + * tx_rdma_writes()
> + */
> + smc_curs_copy(&conn->tx_curs_sent, &sent, conn);
> + smc_curs_copy(&conn->local_tx_ctrl.prod, &prod, conn);
> /* recalculate, value is used by tx_rdma_writes() */
> atomic_set(&smc->conn.peer_rmbe_space, smc_write_space(conn));
>
>
Agreed. smc_curs_add() leaves count >= size, and then wrap + 1 with
the old count,for a moment. smc_tx_prepared_sends() can read zero in
that window.
The rework keeps the old arithmetic and stores eachcursor once.
Reviewed-by: Sidraya Jayagond <sidraya@linux.ibm.com>
Thanks,
Sidraya
next prev parent reply other threads:[~2026-12-01 9:03 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-28 14:23 [PATCH net v2 0/6] net/smc: fix the failover cursor switch and wrap rollover Bryam Vargas via B4 Relay
2026-11-28 14:23 ` [PATCH net v2 1/6] net/smc: take the socket spinlock across the failover cursor switch Bryam Vargas via B4 Relay
2026-12-01 8:47 ` Sidraya Jayagond
2026-11-28 14:23 ` [PATCH net v2 2/6] net/smc: do not credit stale CDC completions after a link switch Bryam Vargas via B4 Relay
2026-12-01 9:00 ` Sidraya Jayagond
2026-11-28 14:23 ` [PATCH net v2 3/6] net/smc: store each cursor once in smc_switch_cursor() Bryam Vargas via B4 Relay
2026-12-01 9:03 ` Sidraya Jayagond [this message]
2026-11-28 14:23 ` [PATCH net v2 4/6] net/smc: fix the failover catch-up across the cursor wrap rollover Bryam Vargas via B4 Relay
2026-12-01 9:08 ` Sidraya Jayagond
2026-11-28 14:23 ` [PATCH net v2 5/6] net/smc: order the urgent mark " Bryam Vargas via B4 Relay
2026-12-01 8:18 ` Sidraya Jayagond
2026-11-28 14:23 ` [PATCH net v2 6/6] net/smc: update the urgent state under the socket spinlock Bryam Vargas via B4 Relay
2026-12-01 9:32 ` Sidraya Jayagond
2026-11-28 14:43 ` [PATCH net v2 0/6] net/smc: fix the failover cursor switch and wrap rollover sashiko-bot
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=a4e68c5b-4cf1-4b0e-b4fb-fb7c84fc5f28@linux.ibm.com \
--to=sidraya@linux.ibm.com \
--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=tonylu@linux.alibaba.com \
--cc=ubraun@linux.ibm.com \
--cc=wenjia@linux.ibm.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