mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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 2/6] net/smc: do not credit stale CDC completions after a link switch
Date: Tue, 1 Dec 2026 14:30:27 +0530	[thread overview]
Message-ID: <9814c137-6b38-40c0-839b-107877f4ef66@linux.ibm.com> (raw)
In-Reply-To: <20261128-b4-disp-360e65c5-v2-2-d9c05004d430@proton.me>



On 28/11/26 7:53 pm, Bryam Vargas via B4 Relay wrote:
> From: Bryam Vargas <hexlabsecurity@proton.me>
> 
> A successful completion on the old link handled after
> smc_switch_cursor() credits bytes that were rewound for resend, so the
> application can overwrite send buffer data before it is resent. A
> connection in a closing state is moved to the new link without a rewind;
> when completions on the two links are then handled out of order, one
> whose cursor is behind tx_curs_fin moves tx_curs_fin back and the same
> bytes are credited again, which can take sndbuf_space past the send
> buffer size.
> 
> Tag each CDC pend with a switch generation that smc_switch_cursor()
> bumps, and credit a completion only if it is of the current generation
> and its cursor is not behind tx_curs_fin.
> 
> Fixes: c6f02ebeea3a ("net/smc: switch connections to alternate link")
> Cc: stable@vger.kernel.org
> Signed-off-by: Bryam Vargas <hexlabsecurity@proton.me>
> ---
>  net/smc/smc.h      |  3 +++
>  net/smc/smc_cdc.c  | 11 ++++++++++-
>  net/smc/smc_cdc.h  | 13 +++++++++++++
>  net/smc/smc_core.c |  1 +
>  4 files changed, 27 insertions(+), 1 deletion(-)
> 
> diff --git a/net/smc/smc.h b/net/smc/smc.h
> index 36b243b34a9a..96f017938b9c 100644
> --- a/net/smc/smc.h
> +++ b/net/smc/smc.h
> @@ -233,6 +233,9 @@ struct smc_connection {
>  	atomic_t		sndbuf_space;	/* remaining space in sndbuf */
>  	u16			tx_cdc_seq;	/* sequence # for CDC send */
>  	u16			tx_cdc_seq_fin;	/* sequence # - tx completed */
> +	u16			tx_switch_gen;	/* bumped when a link switch
> +						 * rewinds the tx cursors
> +						 */
>  	spinlock_t		send_lock;	/* protect wr_sends */
>  	atomic_t		cdc_pend_tx_wr; /* number of pending tx CDC wqe
>  						 * - inc when post wqe,
> diff --git a/net/smc/smc_cdc.c b/net/smc/smc_cdc.c
> index 32d6d03df321..d1f346376c08 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);
> @@ -107,6 +115,7 @@ static inline void smc_cdc_add_pending_send(struct smc_connection *conn,
>  	pend->cursor = conn->tx_curs_sent;
>  	pend->p_cursor = conn->local_tx_ctrl.prod;
>  	pend->ctrl_seq = conn->tx_cdc_seq;
> +	pend->switch_gen = conn->tx_switch_gen;
>  }
>  
>  int smc_cdc_msg_send(struct smc_connection *conn,
> diff --git a/net/smc/smc_cdc.h b/net/smc/smc_cdc.h
> index 696cc11f2303..597acb2e123f 100644
> --- a/net/smc/smc_cdc.h
> +++ b/net/smc/smc_cdc.h
> @@ -170,6 +170,18 @@ static inline int smc_curs_comp(unsigned int size,
>  	return smc_curs_diff(size, old, new);
>  }
>  
> +/* signed distance from old to new; the wrap difference is taken as s16,
> + * so it holds across the u16 wrap rollover, for cursors less than 32768
> + * rings apart
> + */
> +static inline s64 smc_curs_sdiff(unsigned int size,
> +				 union smc_host_cursor *old,
> +				 union smc_host_cursor *new)
> +{
> +	return (s64)(s16)(new->wrap - old->wrap) * size +
> +	       (s64)new->count - old->count;
> +}
> +
>  /* calculate cursor difference between old and new, where old <= new and
>   * difference may exceed size
>   */
> @@ -284,6 +296,7 @@ struct smc_cdc_tx_pend {
>  	union smc_host_cursor	cursor;		/* tx sndbuf cursor sent */
>  	union smc_host_cursor	p_cursor;	/* rx RMBE cursor produced */
>  	u16			ctrl_seq;	/* conn. tx sequence # */
> +	u16			switch_gen;	/* tx_switch_gen at send */
>  };
>  
>  int smc_cdc_get_free_slot(struct smc_connection *conn,
> diff --git a/net/smc/smc_core.c b/net/smc/smc_core.c
> index 73e86100e6db..fb9f6a4eb683 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() */
> 

This patch takes care of the double credit. The missing rewind
itself can lose data, though, and that is not covered in this
series.

smc_sendmsg() still accepts sends in SMC_APPCLOSEWAIT1 (the peer did
shutdown(SHUT_WR) and still reads). RDMA writes queued on the failed
link complete as flushed. Your change correctly does not credit them,
but nothing sends them again either. tx_curs_sent and
local_tx_ctrl.prod stay where they were, so the next CDC on the new
link advertises a producer cursor that covers the lost range, and the
peer reads stale RMB contents. tx_switch_gen is not bumped on this
path either, so the first completion on the new link credits that
range too.

I don't think this needs to hold up the series, but should the
closing states that can still have data in flight (at least
SMC_APPCLOSEWAIT1) go through smc_switch_cursor() as well? A
follow-up patch would be fine.

>  	sndbuf_desc = conn->sndbuf_desc;
>  	smc = container_of(conn, struct smc_sock, conn);
>  	bh_lock_sock(&smc->sk);
> -	if (!wc_status && sndbuf_desc) {
> +	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) {

The change itself looks good to me. A stale completion still drops
cdc_pend_tx_wr, and skipping the tx_cdc_seq_fin and
local_tx_ctrl_fin updates for it is what we want.

Thanks,
Sidraya

  reply	other threads:[~2026-12-01  9:00 UTC|newest]

Thread overview: 13+ 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 [this message]
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
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

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=9814c137-6b38-40c0-839b-107877f4ef66@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

all inboxes | Powered by JetHome®