From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=148.163.156.1 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796115807; b=RS8UQo5QUwMLHAaLqvnrRdvrLyhQXzJbPzKPdaqKR/7ofsTLCEiz6zyElpMRhDPQi0Jp 1ofAuP1Yh49BLxzu71KBPTaAxtjbDeXDRp8yCO3FxXIkB+F5MGKbwf/axgtpM0Fw/DcBd 0LZ44w5oqqs1ZewIxZeQubjlyLmN8wvn0+7HLCMid3NWTlM6hrHu5IZ1t86VfaBVy2K2x V7ROCU38FLa3eYgj6ChffSk24uSJaBX+NmmiWA6zQ3kvJe4PF9JFsjaEbbPo5oZ4HeueQ CU+lb7hDYFRUxxstj+/3QhzmFVo9gByogRkj4+PGEegEOQACjsewK+PRJ9OggeJyIOQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796115807; 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-GUID:X-Proofpoint-Spam-Info: X-Proofpoint-Spam-Details-Enc:X-Authority-Analysis: X-Proofpoint-ORIG-GUID:X-Proofpoint-Virus-Version: X-Proofpoint-Spam-Details; bh=OKgs3WQfB9NiKb8ZUJWX/twBjmZgmvJDG+dI8h8ZZZ8=; b=FUNw+JTUYYdXJhuk3WrGzly+T/lytIiCa9huuMuj/WafBmylcJHdhAlRdNvPXQ82Z7jx iF+jd6PvG7LktJdQvexdQWmHnWn0LNpO/jsUSiDQL9W9J+hrsYkZpxb+J+a2H8cZJwHAx zrG62D8NgD03UCWgCZxCxLUGXiPW8QvxkBOKCglXNQ1J5+/jCx1zM9HDTXsBKjORC8ZXa PMdZmrV+9v3XhaTMoaXzUqVTgYjD5Dy3sf46hxIxGQoDBpKsSUOpVJdA3dypRN3URljSs GHCgvQgxiqNVGQX9ismvFq2RBtAs2jynaz6XXtsG4UQzwEobnAS6TBpgC/BmJIE/4Bg== 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=lNhJ+YhB; arc=none smtp.remote-ip=148.163.156.1 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (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 49D79606A31A; Tue, 1 Dec 2026 09:03:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 49D79606A31A 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) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=lNhJ+YhB Received: from pps.filterd (m0356517.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6B12ZnvK645666; Tue, 1 Dec 2026 09:03:18 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=OKgs3W QfB9NiKb8ZUJWX/twBjmZgmvJDG+dI8h8ZZZ8=; b=lNhJ+YhBVhQJDrV6LEspPt 3jV4W58KrhIPMDV6F5Y75IPApdI03CWpqHDZlUx1n9W7BmmHsxy9U/vxBllvH3au y9+VqtH90sggt05xb3+gNf61qLOs8QD6ElnhATdyP5n2SeTU4K059JFP7ZNjim6e VyI4nNGd1/GAynEU4mEPiWLZwpShV5oQDNFCjMqvofefBWNoqc4wty4lKzDVIJ1g PDOopKxZUFbQeq4C462ajB1OREISkRpDm5onZW/E+8CElMK8RHNTOgn/F4wYpk2t tVWVtspQdPa0TwjccUGrpJQgs9motBosMtr3y6QhjEfUetnzXC3NX3MEYps8vI4g == Received: from ppma12.dal12v.mail.ibm.com (dc.9e.1632.ip4.static.sl-reverse.com [50.22.158.220]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4j7pp5uvhr-1 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 01 Dec 2026 09:03:17 +0000 (GMT) Received: from pps.filterd (ppma12.dal12v.mail.ibm.com [127.0.0.1]) by ppma12.dal12v.mail.ibm.com (8.18.1.11/8.18.1.11) with ESMTP id 6B17eVoV822092; Tue, 1 Dec 2026 09:03:17 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 4j899s8nyg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 01 Dec 2026 09:03:17 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 6B193Bbb53150044 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 1 Dec 2026 09:03:11 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1D6042006C; Tue, 1 Dec 2026 09:03:11 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AEF0B20067; Tue, 1 Dec 2026 09:03:07 +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:03:07 +0000 (GMT) Message-ID: Date: Tue, 1 Dec 2026 14:33:06 +0530 X-Mailing-List: linux-s390@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 3/6] net/smc: store each cursor once in smc_switch_cursor() 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-3-d9c05004d430@proton.me> Content-Language: en-US From: Sidraya Jayagond In-Reply-To: <20261128-b4-disp-360e65c5-v2-3-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-GUID: LEB4VQasCcCdrr4Wpzo8_9pouVMV_Y1n X-Proofpoint-Spam-Info: AW1haW4tMjYxMjAxMDAzNCBTYWx0ZWRfXwlaL6rWRrGMB F11mvyZo0cEvpwYce3qtiFn69lXWbnVu4f4d2oWZ3+TXNzhitNafAGo9Na5c8Fi3sP+ct/o0EOe YmLr2xxQkopDoNoCxITNlNwhz5uFBaY= X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMjAxMDAzNCBTYWx0ZWRfX01NnVeYqAFoQ RXHncwYzJ5HfwEBGeV4Q0KNPmKwrkxl/LL3Fo45/WDwgJBFlkfOEROgxAcCpUGfD3MDin3DM+/8 6dgOkhx/kzKA8pwpS5u7svTfXHWfpG2svG/eX3BLyZrA1zcs6/hlLaFDs7EEpTgcxXlXQMEfFMk kAEHEmJLiWMp8zvmvt/lrJtePGMZynjJrxrBmXDn+LwEfiPqRJP06xpVjLUZB0Lh8jfIWMp1lH4 MWhcoMaKxaqXAZ2aMD25OuRFC3OOCoqws5TzLadz6b5itwokigKQ/ahle7RuCW0ZxvpGXfr6J8+ zcEfxvu12KfZWOQQ9FeUBjhSo2l5jmU5S6aIQdUij9OGhgervmRkoEDnn5NX9TcNlp2XUK+mu5D 3y3r/EJWXyYhOZNP2rkjJjLK7f2KSCKdRAOXvI1XSrTn6W7cTIrqfi9PDxzjcygkcLxpNmkLoUl qsQZzOSdY6Z6IA8zxaw== X-Authority-Analysis: v=2.4 cv=Ae8kjHXG c=1 sm=1 tr=0 ts=6b0e8d56 cx=c_pps a=bLidbwmWQ0KltjZqbj+ezA==:117 a=bLidbwmWQ0KltjZqbj+ezA==:17 a=IkcTkHD0fZMA:10 a=pUM-KoujPXoA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=U7nrCbtTmkRpXpFmAIza:22 a=VwQbUJbxAAAA:8 a=VnNF1IyMAAAA:8 a=Gbe8TRwyPYOFa5_HTVYA:9 a=QEXdDO2ut3YA:10 X-Proofpoint-ORIG-GUID: NmxI_4m0ZVEycxSVrDoP3VM2wXc47SGW 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 suspectscore=0 adultscore=0 spamscore=0 malwarescore=0 phishscore=0 lowpriorityscore=0 bulkscore=0 priorityscore=1501 impostorscore=0 clxscore=1015 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 > > 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 > Closes: https://lore.kernel.org/all/sashiko-outbox-215218@kernel.org/ > Cc: stable@vger.kernel.org > Signed-off-by: Bryam Vargas > --- > 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 Thanks, Sidraya