From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=148.163.158.5 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796115651; b=VOWhcUC25JOoDlYePDNz38zeHtwXeoCVh6wThrS6yBRCY3qrqUgL6mh5utRRBjBSzLmY R0hi0CwYvR3GT2z0/7qLTVOUiTotbdS54DeCbDBMEqijL/8QjhGO2ITNdwai4zsxoaCnn nhzUtGEshQaiiMucF+1Eak+Uy28g7RZCkC9mVZBmTpXJXuttu+uf2zgLNsR4iQAr9Xu32 baVKoW+fpVMy0nKsDVXswW6/FLXeZ1yIVfNCHhc/mdVW2v/KzvXsN9IiZWX31RiLCK5h0 lNz7vaclJYeD9dd0TFf1QIZq9CxCqB9zqax1Irs+2blFvRx5izTSxieRuYFvoAUjv6A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796115651; h=DMARC-Filter:Received:DKIM-Signature:Received:Received:Received: Received:Received:Received:Received:Message-ID:Date:MIME-Version: User-Agent:Subject:To:Cc:References:Content-Language:From:In-Reply-To: Content-Type:Content-Transfer-Encoding:X-TM-AS-GCONF: X-Proofpoint-Reinject:X-Proofpoint-Spam-Info:X-Authority-Analysis: X-Proofpoint-Spam-Details-Enc:X-Proofpoint-GUID: X-Proofpoint-ORIG-GUID:X-Proofpoint-Virus-Version: X-Proofpoint-Spam-Details; bh=IRZM00y5DcFsxy8ROnWs7v0kkHvErPgO07nyfMcv7lc=; b=03KXeCJFTPjZNB0Id2/YV7XW+6r7M6tHrqLAjSb2B+YIJFepOv0O7Eg3FIvNVMsVohkq UHy5SZdcn/VOe+6O3m8sGZezzOIuTacWN2Vc7hkkLUpkynYJfcj2BqsFmG1NNLACx60EL w71sL4aJnON1d12Wi6giU6NibnGMZErKUUbeC/C+EateOWRts4l2euMjCk5xJEV/PLfRy MTdiZ3uXrDvOL16WDBzBBM/h1CZnMmQ1JqqIp07aUcG9sWmMENNH4dl3qA8HbvWeXPJ2L FqRa8gv3xbx0fB+9rktT4ifU9yW9AmBnhVJxohniYvpO279Jdhd/4W1wPmAANzJ7mCg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=EOZVNLn0; arc=none smtp.remote-ip=148.163.158.5 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8E78F606A31A; Tue, 1 Dec 2026 09:00:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8E78F606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=EOZVNLn0 Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6B12ZIFb599736; Tue, 1 Dec 2026 09:00:39 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pp1; bh=IRZM00 y5DcFsxy8ROnWs7v0kkHvErPgO07nyfMcv7lc=; b=EOZVNLn0WkVg5d2HRH8x/6 X8N3ieFNtzYhf7UVRQtcMwgO0I7JDJK+bJDsMMOC0vlNaavKXU1+shdKjLVtmoY1 zW/lZmC7BsVVezr2KSs6icJsKZ/lJ9KSLwrxGUGBp3IaAyVwj3yfIxFF0AdKukvG xROWRxgiOxmqONKgbYGZqhXKssoUA84ifmSDQQO1gICEVN8tUn+eeOxMPkgiBRUP xw5D0xoPfJ+caG1tyV0vmFPzx/k2IEqMezCyPwoJBAmX6W+Cr/dRwqTvCgp9kNcB e173hrB543q/hvedVj7dTYBAYqa4dRqhTXn1NaWd3jSuj7crBO9nBH7gF6upNA2w == Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4j7mckbm8f-1 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 01 Dec 2026 09:00:38 +0000 (GMT) Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.18.1.11/8.18.1.11) with ESMTP id 6B17jGap939116; Tue, 1 Dec 2026 09:00:38 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 4j8byy07ts-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 01 Dec 2026 09:00:38 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 6B190V9v48038280 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 1 Dec 2026 09:00:32 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CDE7D2004B; Tue, 1 Dec 2026 09:00:31 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6AFE22005A; Tue, 1 Dec 2026 09:00:28 +0000 (GMT) Received: from [9.123.13.84] (unknown [9.123.13.84]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 1 Dec 2026 09:00:28 +0000 (GMT) Message-ID: <9814c137-6b38-40c0-839b-107877f4ef66@linux.ibm.com> Date: Tue, 1 Dec 2026 14:30:27 +0530 X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH net v2 2/6] net/smc: do not credit stale CDC completions after a link switch To: hexlabsecurity@proton.me, Mahanta Jambigi , "D. Wythe" , Eric Dumazet , "David S. Miller" , Paolo Abeni , Jakub Kicinski , Dust Li Cc: Stefan Raspl , Simon Horman , Guangguan Wang , Wen Gu , linux-s390@vger.kernel.org, linux-rdma@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Tony Lu , Ursula Braun , Hidayath Khan , Wenjia Zhang References: <20261128-b4-disp-360e65c5-v2-0-d9c05004d430@proton.me> <20261128-b4-disp-360e65c5-v2-2-d9c05004d430@proton.me> Content-Language: en-US From: Sidraya Jayagond In-Reply-To: <20261128-b4-disp-360e65c5-v2-2-d9c05004d430@proton.me> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Proofpoint-Spam-Info: AW1haW4tMjYxMjAxMDAzNCBTYWx0ZWRfX/Ax6Ut9RPtIu cSKYNsj0h3Z/2dQv5kfVAu7saNcKIMZHleK20Hdrb7/6+x1Wtan4u6iJC9BL0K3RJ+1MuJ5tYCz 7K08OrmGRQT4arQ2hLYoyibrgf23hiM= X-Authority-Analysis: v=2.4 cv=MtfHeGae c=1 sm=1 tr=0 ts=6b0e8cb7 cx=c_pps a=aDMHemPKRhS1OARIsFnwRA==:117 a=aDMHemPKRhS1OARIsFnwRA==:17 a=IkcTkHD0fZMA:10 a=pUM-KoujPXoA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=Y2IxJ9c9Rs8Kov3niI8_:22 a=VwQbUJbxAAAA:8 a=mLURUl8222k3K8YlQbMA:9 a=QEXdDO2ut3YA:10 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMjAxMDAzNCBTYWx0ZWRfX0KR2f/cw6vkF rlGDsmNgRR5epR8PdSdPd5qusOWHoITp0w46LoTbHbGWhEia+dNbTJm691w1TxyVfD9V/JzvmyU SjtUX/JUQi827U5NmjXPVGJzEk/x9v6f/2DfsR7+ENgyBa2X6W1xKld6+oV9DnpSqy5bUexBDCS 3sC0WXeKlO1bD20mWdhu1e2ywdS2+7t2tSGmMIzY47ei2TzBOGfFJ2Bqc470md2+9zirbwFZLBI 5HtiGaNEk/Jym/gROU2FQGGEImBKaamj4HgDPDcjOT0UeBf4Z2XuDmOjRh904YcSbSGxyfIsYNm HGstwTMFTlnVRHlITDsMAOyLaX/qFZzE5m+SkclTLi2SItKSWxVaSSZw22ZpPSgoUxxqdlSELV7 tZUFsrZKD3AAU3kpnAF0FZV/kAefSqg6F9NnzQlE6xc94jH8eYSPL1prLrxPhB4W68rFJ7QlmZU AvU/jrQn4/ycy0sM5wg== X-Proofpoint-GUID: CpbTDkPQeFSlkMbulSLcBG1HuhC7bR3Z X-Proofpoint-ORIG-GUID: rAQ0Nr7QvAmYS-BPf2angZLGOqu0fnx1 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-12-01_01,2026-11-30_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 bulkscore=0 malwarescore=0 spamscore=0 phishscore=0 clxscore=1015 priorityscore=1501 lowpriorityscore=0 suspectscore=0 impostorscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2612010034 On 28/11/26 7:53 pm, Bryam Vargas via B4 Relay wrote: > From: Bryam Vargas > > 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 > --- > 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