From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796375720; b=nmU/JjN4GbQaO3gskCmgahUrxNGdWWjE5vG0kpKHwpMmwDK+kGefsLLWhXHoaTrTzp6O YJo4MLSPNAcR9L9OrJKclxgGFnqYmajpQhtnzpWPhdy+lVKvFtAlLINirZHT6WevFqN/G T6SUMfAqkdPNIzsgLvgOzb10M5HumIjxkyDkBaeZbvN1JzA7Hw/tRyJrrcSt8EXnZIwAL LbHxYTHBAJ+Ikgp2Fmo1mM6bIHLMn02ESzGEycDets9AXCW+hVuAv6M5Dr7THKbiHcf1K k8K4BGbFi8/HgvJ+i3TvtC0dom+rCFIpLTwxeGyhGK78J7YhHh8syWlYb8jiSav0LfQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796375720; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=qfEhDU0jNPu5NQacuG4Pdax5ZstijcA98MntD/xuGCk=; b=pbc6et1EL47atJKSCS9bS2MgfwSuh6c9siMML3ZJIZW6XYMac5FADf9emDjEeAFyXW0v iaRej/yG/6Eup5u35ts/ll4NJFJ8iI9QCjBEYcMNNH1MgPXRChBloxQsEGs/av6ltfCL5 UUBn9sjflz8yOF+sHb6UHgyWN6VP01wVzv0h7F77iJeYGR42ucSmdfu8XtplDhi+pnpCi qTzskvJaHCUaypuY6MuXJ05BcPG6KmI9BARQgLSDDdTWaLG2tC742U1PmqfDnWMtx81JD 9/gmtP3fApTDJVuygayP2DrKUvikYYsVBvyD+Mb/7f7Jbek01CXhlgxaaP4Ysu2nU+g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=fqGAoHCA; arc=none smtp.remote-ip=100.103.45.18 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 91E42606A337; Fri, 4 Dec 2026 09:15:20 +0000 (UTC) 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=fqGAoHCA Received: by smtp.kernel.org (Postfix) with ESMTPSA id 271AA1F00931; Fri, 4 Dec 2026 09:15:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796375720; bh=qfEhDU0jNPu5NQacuG4Pdax5ZstijcA98MntD/xuGCk=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=fqGAoHCAwTLvc6sKUWj6Ux41sN+CznTP+mWsR/Cu3Hf2Lb1rXuouc/QHRXD/bEv33 04uyujQJZTKY8xQZZ73NqVHCtqYLK+ER75jskRP0hza8AQ3HueQYFcYhpr6l1mZTK1 fZdJvGsqenbwshT8b6adHSXFQCQ237//0beMSt0Vzle/qWk1LtlFckk0HNOZebCeGc 8IlYlv4WENTHc7ZXXVFEAEMwMcS+c+ij5pBHVW7x8EeSBjom6/KRQbOwwNLLN3kyxR QEu49t3PfGgKpXUnE7oe0yAwTCMuGQMzqjUo6f9QE1WoYmjqE1PJqsoxl/p19mhH9J RVqvFUy2d2vBw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH net v3 3/7] net/smc: store each cursor once in smc_switch_cursor() Reply-To: sashiko-reviews@lists.linux.dev To: "Bryam Vargas" Cc: linux-rdma@vger.kernel.org, linux-s390@vger.kernel.org, "Heiko Carstens" , "Vasily Gorbik" , "Alexander Gordeev" , "Christian Borntraeger" In-Reply-To: <20261203-b4-disp-ba1ad55e-v3-3-6834ff90c5d0@proton.me> References: <20261203-b4-disp-ba1ad55e-v3-0-6834ff90c5d0@proton.me> <20261203-b4-disp-ba1ad55e-v3-3-6834ff90c5d0@proton.me> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 09:15:19 +0000 X-Mailing-List: linux-s390@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 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 =3D &smc->conn; > - union smc_host_cursor cons, fin; > + union smc_host_cursor cons, prod, sent; > int rc =3D 0; > int diff; > =20 > 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); > =20 > - 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 =3D 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 =3D 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); > =20 > 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203-b4-disp-ba= 1ad55e-v3-0-6834ff90c5d0@proton.me?part=3D3