Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Bryam Vargas" <hexlabsecurity@proton.me>
Cc: linux-rdma@vger.kernel.org, linux-s390@vger.kernel.org,
	"Heiko Carstens" <hca@linux.ibm.com>,
	"Vasily Gorbik" <gor@linux.ibm.com>,
	"Alexander Gordeev" <agordeev@linux.ibm.com>,
	"Christian Borntraeger" <borntraeger@linux.ibm.com>
Subject: Re: [PATCH net v3 3/7] net/smc: store each cursor once in smc_switch_cursor()
Date: Fri, 04 Dec 2026 09:15:19 +0000	[thread overview]
Message-ID: <sashiko-outbox-249475@kernel.org> (raw)
In-Reply-To: <20261203-b4-disp-ba1ad55e-v3-3-6834ff90c5d0@proton.me>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] net/smc: smc_switch_cursor() credits sndbuf_space before
  tx_curs_sent
--

commit 540f0a930275621fedaa9a30d8ce826c2015e9b6
Author: Bryam Vargas <hexlabsecurity@proton.me>

net/smc: store each cursor once in smc_switch_cursor()

This commit updates smc_switch_cursor() to compute the new tx_curs_sent,
tx_curs_fin, local_tx_ctrl.prod, and local_tx_ctrl_fin cursor values on
local copies and store each connection cursor once with smc_curs_copy().

> diff --git a/net/smc/smc_core.c b/net/smc/smc_core.c
> index fb9f6a4eb6835..4ee9e6f0d659c 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);

[Severity: Medium]
Can crediting conn->sndbuf_space before updating conn->tx_curs_sent let
smc_tx_sendmsg() push conn->tx_curs_prep more than one buffer length ahead
of the old conn->tx_curs_sent?

smc_switch_conns() calls smc_switch_cursor() under bh_lock_sock() and
conn->send_lock, which do not serialize against smc_tx_sendmsg() or
smc_ioctl() holding lock_sock().

When sent advances past the previous conn->tx_curs_sent (for example on a
second link failover while userspace holds the socket lock), a concurrent
sender can consume the newly added sndbuf_space before tx_curs_sent updates:

CPU0                            CPU1
smc_switch_conns()
  bh_lock_sock(&smc->sk)
  spin_lock(&conn->send_lock)
  smc_switch_cursor()
    atomic_add(diff,
               &conn->sndbuf_space)
                                smc_tx_sendmsg()  /* holds lock_sock() */
                                  atomic_read(&conn->sndbuf_space)
                                  smc_curs_copy(&conn->tx_curs_prep, ...)
                                  ...
                                    smc_tx_prepared_sends()
                                      smc_curs_diff(...)  <-- stale sent
    smc_curs_copy(&conn->tx_curs_sent,
                  &sent, conn)

With tx_curs_prep more than sndbuf_desc->len ahead of tx_curs_sent,
smc_curs_diff() breaks its single-ring assumption: SIOCOUTQNSD in
smc_ioctl() can return a count larger than sndbuf_desc->len or under-report
by a full buffer length, and smc_should_autocork() can spuriously autocork.

Storing conn->tx_curs_sent and conn->local_tx_ctrl.prod before
smp_mb__before_atomic() and atomic_add(diff, &conn->sndbuf_space) would
keep the single-store guarantee while preserving the cursor ordering.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203-b4-disp-ba1ad55e-v3-0-6834ff90c5d0@proton.me?part=3

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

Thread overview: 17+ 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:15   ` sashiko-bot
2026-12-04  9:49   ` netdev-bot+sashiko
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-04  9:15   ` sashiko-bot [this message]
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-04  9:15   ` sashiko-bot
2026-12-03  9:15 ` [PATCH net v3 5/7] net/smc: order the urgent mark " Bryam Vargas via B4 Relay
2026-12-04  9:15   ` sashiko-bot
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:15   ` sashiko-bot
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
2026-12-04  9:15 ` [PATCH net v3 0/7] 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=sashiko-outbox-249475@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=agordeev@linux.ibm.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=hexlabsecurity@proton.me \
    --cc=linux-rdma@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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