Article View: linux.kernel.netdev
Article #26238[PATCH net v3 3/7] net/smc: store each cursor once in smc_switch_cursor()
From: Bryam Vargas via B4 Relay
Date: Thu, 03 Dec 2026 09:15
Date: Thu, 03 Dec 2026 09:15
87 lines
14378 bytes
14378 bytes
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
Reviewed-by: Sidraya Jayagond <sidraya@linux.ibm.com>
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));
--
2.56.1
Technical Details
Message-ID:
<20261203-b4-disp-ba1ad55e-v3-3-6834ff90c5d0@proton.me>Path:
mbox-mo1.pugleaf.net!srl.newsdeef.eu.MISMATCH!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376432-linux-kernel-netdev=dewy.ruReferences:
<20261203-b4-disp-ba1ad55e-v3-0-6834ff90c5d0@proton.me>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srl.newsdeef.eu.MISMATCH!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376432-linux-kernel-netdev=dewy.ru From: devnull+hexlabsecurity.proton.me@kernel.org (Bryam Vargas via B4 Relay) Newsgroups: linux.kernel.netdev Subject: [PATCH net v3 3/7] net/smc: store each cursor once in smc_switch_cursor() Date: Thu, 03 Dec 2026 04:15:05 -0500 Organization: Usenet Network Message-ID: <20261203-b4-disp-ba1ad55e-v3-3-6834ff90c5d0@proton.me> References: <20261203-b4-disp-ba1ad55e-v3-0-6834ff90c5d0@proton.me> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Injection-Info: usenet.network; logging-data="2445874"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:MWXdwhF1o9wk6QQULXr+9JNT/Fk= sha256:qaxWhu/ERkrNYs4m4Y5q455TU+bXYRcEIBaHProteZE= sha1:ht1gR2+LZD/mFG/2pq2Et4Gfpgo= sha256:My25cxtWOs/tGuLDK7w5BOs8uv1P7LKbR2EBuCXHt00= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 5328911789D; Thu, 3 Dec 2026 12:16:02 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.401 X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id IoUi3jNEvO1K; Thu, 3 Dec 2026 12:15:58 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-376432-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id 4BAC2117896; Thu, 3 Dec 2026 12:15:49 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id 685A7304AB; Thu, 3 Dec 2026 09:15:16 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=3; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796289307; b=FYuOjz8O5prYLgpL4upyUcgCancORTnbSaTlHoYRhFT01Mf9IhDvaHfrKvWLF4O4mQoI 7ARgRmKlFK1Nh0nOgWFKabk+cezCDznMe6vDZGjicpPZOxtnXdywm1DF0RRdcCNHbMx+I 09rhvPFkz6Y/xCK1PqdwuDnBkmarUwvmvC2BzxZ3YNfxHx1M2WYOQ+pPKgka+VtlYEZmv +0HIAEQCyYMSmMaQZxTniduk3weqZMnn/vBq0Jmgl9A/Gs6ULeIl9KRytS/yEpYT8K2FD Q6iM1vFTo/rHnSFqQ/4fFfXOPLQyqC40gfbuu+G5q9iXuUvuQ/VYpiHVHUsNywjIKAA== X-ARC-Message-Signature: i=3; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796289307; h=X-Original-To:Received:Received:DKIM-Signature:Received:From:Date: Subject:X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe: List-Unsubscribe:List-Owner:Precedence:MIME-Version:Content-Type: Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=BjNPtBkp63IC+3O/VmuyEi2l6PsikSAVujtpRlkUQC4=; b=W2IrmBv02amnEDBRIAvsFUFfz5OgSQ/LOItzxC9MQSLGw7ksq4ccvG132gf0/Wa2+GlE btjMZTc8DPQBdJ4RCp6ccw5iCRbofS1NhkhWpv0WykRfBJhzTY49OVy1qqtZYTOc10raV 8HKnw+HmGsTlnGDEhNmQ6DAFn5J6I6VohU0vTOLr1jVDU+HwLOiST7esBbmfNoXQwLsmr jrt5ybcPAoeK9FfxoU4uEeed+l/UyExB70VX3myNOTChEm3IttawHwgSOyxCZFNuuFvvd 9nmoZL95G9L+laA6ZrK6YT8k9/ZmC18QefGDFWi/35clxZ7I0O0lTb5oz6KI02Gd1cg== X-ARC-Authentication-Results: i=3; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=CypXliiG; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E25D860A263B; Thu, 3 Dec 2026 09:15:06 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=CypXliiG X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796289306; b=f1ep+n0klNrD9JdBIs6AvsU+4QCsn23oX2GoEFKMW7/j7FHm4/RUpXRkSnKOo9Rxpjm0 EtQ4e5duOJ/glCx7zqZl6JMaTpF6JycniZ93q6pbJ3IOVDwM7dAj9k+NhJ/IeJB+43mxd nWb7YUn997Eqv2nuL/6FviiQPDOpAWEivlzIiyvme3Y504qis/PFFXQpiJeIayebCgGyq Xqk07pp2uS1JIUb1ZrBMIu+gDzBgscyM6pHH6+mFtW29L7AFbN8mfMQXdjrA2AOgjQ1Wz NTDy3yffeseQ8CfyG08vXwtN+zKTxCSEh6/OOx93oJhWC5dw9fQvWnfw3sxOCgOV4cg== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796289306; h=Received:DKIM-Signature:Received:From:Date:Subject:MIME-Version: Content-Type:Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=BjNPtBkp63IC+3O/VmuyEi2l6PsikSAVujtpRlkUQC4=; b=RBMOO/MuoToUwzY4nMUl5ufwJq+CgSlRbGaXGdW7BAFCtllBeziFsZBsOVnekmoTKYoW mL8IxYlAEy0O1Stv3VLcItLH4LeA5yCqC+bpNJwYuz48wiMA9WHpONp+B1ef3ijuSZns9 BexIEhSGcogsRLfNg7OTl1cn13yWc78GHj9XTopT1jXwfSXZVtgoNr2wakxiHldpIWdTO gKsHCSOvODHn7YbecazQEDpaEwLIe/vZAOPCOgAKYTFv8ZJyz+tyi3tphXufay4tw2kRj ZNUbx3eK4IwHId7W3hRTgpxFHBPwHAnFF3KDMd9zHddUbNy1emua03irPmIx+q8H5mQ== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=CypXliiG; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 06C67606A690; Thu, 3 Dec 2026 09:15:06 +0000 (UTC) X-Authentication-Results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 X-ARC-Seal: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; cv=none; t=1796289305; b=LH+2hNssefWc0ksds7vInaqjD04jGiINzeokvVQBhkFJGwKFuAWSi41lUCtf3gRsJgFP O9qxjR6AS2vHlQ+Qg/jzGIgAk1Q9CFs2ngF/BV+B0u+oP5rgbbeE426NfZi25r72URlSR nHhdrYFUD306diimBwS//S+N443qw7OnW04Qo/vkKRM3MetyZIRJRCdK3LZThMv76OZ9g W3Krs2imP8y6oyzMVjC7p/c8Rl7M880My4piSR3MplLErck0aBZGZggRmRiLUQzOrPLK+ yv5fMLo5DO47vZvWS60LF2Er6863WBmAZQgOJ9oNFzljSjrLlBSczZT3MHxbEoW9NOw== X-ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1796289305; h=DKIM-Signature:Received:From:Date:Subject:MIME-Version:Content-Type: Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=BjNPtBkp63IC+3O/VmuyEi2l6PsikSAVujtpRlkUQC4=; b=hHIbljYH+xkSq6124GQXYiwERUpZMBPXEd2eec7DM/xv3OYzIQx9kG9gvTyNapq07MIc gXkRCU0zOBFl6RXS/XC6MtqGpc9pLHqGFcK3gwe4+ImQy2HGUV7S+YeVeExcw4sagzcZa eNsInLjzrloW3sBX4psh2KjIivGYLWjsOAdWNi2U651ss02EqoRblznvXpPP+xKuGerfg OUxKxUKUdbhSodu3rhNrp7of33ZXXbNSg5C/puRP5jLkaTpnei0LBVLOW3s0MMufuKtYQ IUdAzNVodL6rANqYiYhX7R/v3R9b+ZQfyKQswv4tXZde3yoZvKWdrSn40yWkXgkWWBg== X-ARC-Authentication-Results: i=1; smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 X-Received: from lkml.kernel.org (nexus.subspace.kernel.org [100.80.115.77]) (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.kernel.org (Postfix) with ESMTPS id 5B8FF1F00927; Thu, 3 Dec 2026 09:15:04 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796289305; bh=BjNPtBkp63IC+3O/VmuyEi2l6PsikSAVujtpRlkUQC4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To; b=CypXliiGCi4KHTlcfGKbUbWcLLOBfCxrOau1QCk6cXRjP7GvsWR+duRTPY+7Spic8 UK4eD4SFYL9YZwWc0iFfzbuIHjZKBKp94/HHnWQ70KqHMPtGzGsz1kikoMfdBjJxzm wLdxcjmdxNFBWv4UajTxQ/v6G74i2hmos/6hICaul4+Rb56wozsDz+oARSOZ6RCMd1 npUeTVb7ckrAdNgWRQhf9RNzPoVC5jD8TRsenLTXX+u5JCw50O5OHT/RpX4yMl7o1/ k5wILJOz/aaENcXGZ70oNBrp48XzMHXJI5EuArOkDmaRWTM4P+RGif9q73t9b/3uS+ WZFIDFRiR9eUQ== X-Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id D85364F8B3; Thu, 3 Dec 2026 09:15:03 +0000 (UTC) X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list X-In-Reply-To: <20261203-b4-disp-ba1ad55e-v3-0-6834ff90c5d0@proton.me> X-Cc: Wen Gu <guwen@linux.alibaba.com>, Guangguan Wang <guangguan.wang@linux.alibaba.com>, Tony Lu <tonylu@linux.alibaba.com>, Ursula Braun <ubraun@linux.ibm.com>, linux-rdma@vger.kernel.org, linux-s390@vger.kernel.org, Hidayath Khan <hidayath@linux.ibm.com>, Simon Horman <horms@kernel.org>, Wenjia Zhang <wenjia@linux.ibm.com>, linux-kernel@vger.kernel.org, Stefan Raspl <raspl@linux.ibm.com>, netdev@vger.kernel.org X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1796289302; l=3629; i=hexlabsecurity@proton.me; s=default; h=from:subject:message-id; bh=oYnEmux8unFnNETFFf+66pd3x73pZDNVfX9qI1/xUPg=; b=Z+zCKiRn3pkC7O6GyBKnozdBhXr3q0BkYmRbmmPYZbniTppmPLBkHKoZQNm88OZEKl1mG+9EH x+G5f2PlUjJBsw7NIhtu2YPTIpDP/b5KhXTu7V/+EB8i10Gx/9iqwHT X-Developer-Key: i=hexlabsecurity@proton.me; a=ed25519; pk=xw1AhCtQdvuoQc+bOQIYy9o8G++cp4/VniI2G/tc3G8= X-Endpoint-Received: by B4 Relay for hexlabsecurity@proton.me/default with auth_id=893 X-Original-From: Bryam Vargas <hexlabsecurity@proton.me> X-Reply-To: hexlabsecurity@proton.me