Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
* [PATCH net v3 0/7] net/smc: fix the failover cursor switch and wrap rollover
@ 2026-12-03  9:15 Bryam Vargas via B4 Relay
  2026-12-03  9:15 ` [PATCH net v3 1/7] net/smc: take the socket spinlock across the failover cursor switch Bryam Vargas via B4 Relay
                   ` (7 more replies)
  0 siblings, 8 replies; 17+ messages in thread
From: Bryam Vargas via B4 Relay @ 2026-12-03  9:15 UTC (permalink / raw)
  To: Eric Dumazet, Paolo Abeni, David S. Miller, Jakub Kicinski,
	Mahanta Jambigi, Sidraya Jayagond, D. Wythe, Willem de Bruijn,
	Dust Li
  Cc: Wen Gu, Guangguan Wang, Tony Lu, Ursula Braun, linux-rdma,
	linux-s390, Hidayath Khan, Simon Horman, Wenjia Zhang,
	linux-kernel, Stefan Raspl, netdev

smc_switch_cursor() runs at SMC-R link failover under send_lock only,
while smc_cdc_tx_handler() and the CDC receive handler update the same
cursors under the socket spinlock. Its catch-up orders the peer's
consumer cursor against local_tx_ctrl_fin with smc_curs_comp(), which
misorders two cursors across the u16 wrap rollover. A successful
old-link completion still credits bytes that are being resent if it is
handled after the switch. The urgent mark has the same rollover problem,
in recv() and in SIOCATMARK. recv() also tests and sets the urgent state
under the socket lock only, while the CDC receive handler sets it under
the socket spinlock. recv(MSG_OOB) does not skip an urgent byte that is
the next unread byte, and the sender then stalls.

1/7 takes the socket spinlock around the switch. 2/7 tags each CDC pend
with a switch generation and credits a completion only from the current
generation and never backwards; both checks rely on 1/7's lock. 3/7
makes the switch work on copies of the cursors and store each one once.
4/7 computes the catch-up from the signed cursor distance, bounds it by
tx_curs_prep and advances the RMB cursors across wraps. 5/7 uses the
signed distance for the urgent mark, in SIOCATMARK too, where it also
tests the urgent state. 6/7 takes the socket spinlock around the
reader's two test-and-set sequences on the urgent state. 7/7 lets
recv(MSG_OOB) skip the urgent byte when it is the next unread byte.
From 2/7 on, each patch needs the ones before it.

Sidraya's review of v2 had four points. SIOCATMARK [2] is in 5/7 with
the check he wrote, and 5/7 has the stable note he asked for. The fix he
asked for after 6/6 [3] is 7/7. A failover in SMC_APPCLOSEWAIT1 [4] is
not changed here (last item of "Not fixed here"). 1/7 to 4/7 and 6/7
are v2's patches.

Tested the same way as v2 [5], now on a v7.4-rc5 KASAN kernel: x86 KVM
guest, net/smc from the base below built as a module, soft-RoCE on veth
between two network namespaces, RMB 16 KiB, sndbuf 64 KiB. No KASAN
report or WARN in any run.

New in v3:

- SIOCATMARK on a connection that never had urgent data. With 32767
  bytes read, net and v2 return 1; v3 returns 0. With 32766, all
  return 0. After 2^30 - 1 bytes, with the reader on wrap 65535, net
  and v2 return 1 and v3 returns 0; with the signed distance but
  without the state check, it is 1 again.
- SIOCATMARK with a valid mark 32767 bytes behind the reader (the
  reader kept reading past the mark with SO_OOBINLINE set): net and v2
  return 1, v3 returns 0; with the state check but with
  smc_curs_diff() kept, it is 1 again.
- SIOCATMARK with a skip pending and the state SMC_URG_READ:
  recv(MSG_OOB) with 1000 bytes in front of the urgent byte, then
  SO_OOBINLINE switched on, then one recv() of the 1000 bytes. net, v2,
  v3 and TCP return 1; v3 without the urg_rx_skip_pend operand returns
  0. With 999 bytes read, all return 0.
- recv(MSG_OOB) after a one-byte send(MSG_OOB) to a reader that has
  read everything. On net and with v2 it returns the byte and the
  sender's next send() of 4096 bytes times out. With v3 the 4096 bytes
  arrive. The same with a zero-length recv(MSG_OOB), which returns 0
  and MSG_TRUNC. With "> 0" in 7/7 but the call to
  smc_rx_update_consumer() left inside the len > 0 check, the
  zero-length case still times out; with "> 1" kept, both do.
- SIOCATMARK around that recv(MSG_OOB). Before it: 1 on net, with v2,
  with v3 and on TCP. After it: 1 on net and with v2, 0 with 1/7 to
  6/7 and with v3, 1 on TCP (third item of "Not fixed here").

Run again on this kernel with v3, with the same results as v2: the
three forged cursor tests and their control, the two tests with a peer
that reads between the switch and the resend and their control, the
failover with local_tx_ctrl_fin on wrap 65535 and its control, the held
CDC and its control, and recv(MSG_OOB) with the consumer cursor past
the mark on the RMB's next wrap and its control. net and v2 were not
run again in these tests. Not run again on this kernel: v1's tests, the
two-failover test and 6/7's first test with a second urgent byte (it
ran under lockdep, below, with the same result as v2). 6/7's second
test ran without the recv() between the held recv() and the
recv(MSG_OOB): with v3, recv(MSG_OOB) returns the byte and the data
that follows it arrives.

On a PROVE_LOCKING build of the same kernel there is no lockdep report
with v3 in three of the SIOCATMARK tests above (the mark behind the
reader, the pending skip, around recv(MSG_OOB)), in the recv(MSG_OOB)
test after a one-byte send(MSG_OOB) and in 6/7's test with a second
urgent byte arriving during recv(MSG_OOB). Without the BH disable in
smc_rx_update_consumer(), lockdep reports an inconsistent lock state.
The failover tests were not run again under lockdep.

With 6/7, smc_rx_update_consumer() takes the socket spinlock only while
an urgent mark is valid or its skip is pending; a first check without
the lock keeps every other read as it is. SIOCATMARK copies urg_curs
and then tests the urgent state under the socket lock, not under the
spinlock. A mark that arrives between the two is paired with the old
cursor. That gives a wrong 1 only if the old cursor is one byte ahead
of the reader, IOW the reader is 65536 RMB sizes minus one byte past
it: e.g. a connection with no urgent data so far and the reader on the
last byte of wrap 65535. By inspection. tcp_ioctl() reads urg_data and
urg_seq with no lock at all.

The series is on net and does not depend on the CDC cursor bounds
series [1], which is marked changes requested. 1/7, 2/7 and 5/7 to 7/7
apply on top of [1] as they are. 3/7 and 4/7 rewrite the block that
[1] 6/6 changes in smc_switch_cursor() and replace it, with the same
bound, tx_curs_prep.

Not fixed here:

- A peer whose consumer cursor is past tx_curs_prep, IOW past every
  byte queued for it. The catch-up stops at tx_curs_prep and leaves the
  producer cursor behind the consumer cursor, so peer_rmbe_space is
  wrong. In the forged cursor test, 1000 bytes past: the next write
  covers bytes the peer has not read and its reader gets wrong data,
  as on net. One wrap ahead: tx stops. A count beyond the RMB: the next
  RDMA write ends past the RMB and is refused, and the link group is
  terminated, as on net. It is the forging peer's own link group.
- A conforming peer that keeps reading between the switch and the
  resend. Its consumer cursor passes the rewound producer cursor, as on
  net; if it crosses the end of the RMB the resend's write ends past it
  and is refused, and the link group is terminated ([1] 5/6 keeps that
  write inside the RMB; not run with this series). Run with a knob
  holding the resend, on net and with v2 (both on v7.4-rc4) and with
  v3 (on v7.4-rc5): same result.
- SIOCATMARK once the reader has read up to the urgent byte. SMC skips
  the byte at the read that reaches it, TCP at the read that goes past
  it. After a read up to the mark, SIOCATMARK returns 0 on net and
  with the series, 1 on TCP. With 5/7's check it also returns 0 after
  recv(MSG_OOB) of a byte with nothing in front of it (run with 1/7 to
  6/7 and with v3); net returns 1 there and stalls the sender. If a
  reader calls recv(MSG_OOB) and then reads until SIOCATMARK returns
  1, with the series it keeps reading. Returning 1 there needs one
  more state: that case looks the same as a new connection, which is
  in SMC_URG_READ with both cursors zero.
- SO_OOBINLINE switched on between recv(MSG_OOB) and the read that
  reaches the urgent byte (the pending-skip test above). The byte is
  never skipped and the sender's next send() times out, on net and
  with v3. Over TCP the data arrives.
- A failover with the socket in SMC_APPCLOSEWAIT1 [4]. The connection
  is moved to the new link without smc_switch_cursor(), and
  smc_sendmsg() still takes data in that state, so writes flushed on
  the old link are not sent again. By inspection, not run.

Test patch and logs on request.

v3:
 - 5/7: SIOCATMARK uses the signed distance and tests the urgent
   state [2]; a note for stable that it needs 2/7 and 4/7.
 - 7/7: new. Lets recv(MSG_OOB) skip the urgent byte when it is the
   next unread byte, and when the length is zero [3].
 - 1/7 to 4/7, 6/7: unchanged. Reviewed-by added to 1/7, 3/7, 4/7 and
   6/7.
 - On net c1c39137dcc3; net/smc has not changed since v2's base.
v2: https://lore.kernel.org/all/20261128-b4-disp-360e65c5-v2-0-d9c05004d430@proton.me/
v1: https://lore.kernel.org/all/20261113-b4-disp-1a9ab9b0-v1-0-4a7c8d85d849@proton.me/

[1] https://lore.kernel.org/all/20261112-b4-disp-0287c16e-v9-0-e5e8fa688177@proton.me/
[2] https://lore.kernel.org/all/9de0921d-d01c-4cae-8ec2-7d86a3c3f438@linux.ibm.com/
[3] https://lore.kernel.org/all/cba71de0-4d7e-4bb2-8e08-ed7ecf0883f4@linux.ibm.com/
[4] https://lore.kernel.org/all/9814c137-6b38-40c0-839b-107877f4ef66@linux.ibm.com/
[5] https://lore.kernel.org/all/20261128-b4-disp-360e65c5-v2-0-d9c05004d430@proton.me/

---
Bryam Vargas (7):
      net/smc: take the socket spinlock across the failover cursor switch
      net/smc: do not credit stale CDC completions after a link switch
      net/smc: store each cursor once in smc_switch_cursor()
      net/smc: fix the failover catch-up across the cursor wrap rollover
      net/smc: order the urgent mark across the cursor wrap rollover
      net/smc: update the urgent state under the socket spinlock
      net/smc: skip the urgent byte when it is the next unread byte

 net/smc/af_smc.c   |   6 ++-
 net/smc/smc.h      |   3 ++
 net/smc/smc_cdc.c  |  11 ++++-
 net/smc/smc_cdc.h  |  28 ++++++++-----
 net/smc/smc_core.c |  59 +++++++++++++++++----------
 net/smc/smc_rx.c   | 117 ++++++++++++++++++++++++++++++++---------------------
 6 files changed, 144 insertions(+), 80 deletions(-)
---
base-commit: c1c39137dcc3134010566ff29a81c93124efa539
change-id: 20261203-b4-disp-ba1ad55e-ebd1eb94512c

Best regards,
--  
Bryam Vargas <hexlabsecurity@proton.me>



^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH net v3 1/7] net/smc: take the socket spinlock across the failover cursor switch
  2026-12-03  9:15 [PATCH net v3 0/7] net/smc: fix the failover cursor switch and wrap rollover Bryam Vargas via B4 Relay
@ 2026-12-03  9:15 ` Bryam Vargas via B4 Relay
  2026-12-03  9:15 ` [PATCH net v3 2/7] net/smc: do not credit stale CDC completions after a link switch Bryam Vargas via B4 Relay
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 17+ messages in thread
From: Bryam Vargas via B4 Relay @ 2026-12-03  9:15 UTC (permalink / raw)
  To: Eric Dumazet, Paolo Abeni, David S. Miller, Jakub Kicinski,
	Mahanta Jambigi, Sidraya Jayagond, D. Wythe, Willem de Bruijn,
	Dust Li
  Cc: Wen Gu, Guangguan Wang, Tony Lu, Ursula Braun, linux-rdma,
	linux-s390, Hidayath Khan, Simon Horman, Wenjia Zhang,
	linux-kernel, Stefan Raspl, netdev

From: Bryam Vargas <hexlabsecurity@proton.me>

smc_switch_cursor() rewrites the send cursors, sndbuf_space and
peer_rmbe_space under send_lock only. smc_cdc_tx_handler() updates
tx_curs_fin, local_tx_ctrl_fin and sndbuf_space, and
smc_cdc_msg_recv_action() updates the peer's consumer cursor and
peer_rmbe_space, under bh_lock_sock(). A CDC completion handled during a
link switch can credit its bytes twice and leave tx_curs_fin ahead of
tx_curs_sent, or leave tx_curs_sent and the producer cursor out of step,
so the resend writes at the wrong RMB offset. A CDC received at the same
time can be counted twice in peer_rmbe_space.

Take bh_lock_sock() around the link change and the cursor switch, in
the order the receive path already uses (the socket spinlock, then
send_lock).

Fixes: c6f02ebeea3a ("net/smc: switch connections to alternate link")
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261029-b4-disp-33001ace-v8-0-f9bb96e17827%40proton.me?part=4
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 | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/net/smc/smc_core.c b/net/smc/smc_core.c
index a3164201c142..73e86100e6db 100644
--- a/net/smc/smc_core.c
+++ b/net/smc/smc_core.c
@@ -1171,11 +1171,18 @@ struct smc_link *smc_switch_conns(struct smc_link_group *lgr,
 		/* pre-fetch buffer outside of send_lock, might sleep */
 		rc = smc_cdc_get_free_slot(conn, to_lnk, &wr_buf, NULL, &pend);
 		if (!rc) {
-			/* avoid race with smcr_tx_sndbuf_nonempty() */
-			spin_lock_bh(&conn->send_lock);
+			/* the CDC completion handler and the receive path
+			 * update the same cursors under the socket's spinlock,
+			 * smcr_tx_sndbuf_nonempty() under send_lock
+			 */
+			local_bh_disable();
+			bh_lock_sock(&smc->sk);
+			spin_lock(&conn->send_lock);
 			smc_switch_link_and_count(conn, to_lnk);
 			rc = smc_switch_cursor(smc, pend, wr_buf);
-			spin_unlock_bh(&conn->send_lock);
+			spin_unlock(&conn->send_lock);
+			bh_unlock_sock(&smc->sk);
+			local_bh_enable();
 		}
 		sock_put(&smc->sk);
 		if (rc)

-- 
2.56.1



^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH net v3 2/7] net/smc: do not credit stale CDC completions after a link switch
  2026-12-03  9:15 [PATCH net v3 0/7] net/smc: fix the failover cursor switch and wrap rollover Bryam Vargas via B4 Relay
  2026-12-03  9:15 ` [PATCH net v3 1/7] net/smc: take the socket spinlock across the failover cursor switch Bryam Vargas via B4 Relay
@ 2026-12-03  9:15 ` Bryam Vargas via B4 Relay
  2026-12-04  9:15   ` sashiko-bot
  2026-12-04  9:49   ` netdev-bot+sashiko
  2026-12-03  9:15 ` [PATCH net v3 3/7] net/smc: store each cursor once in smc_switch_cursor() Bryam Vargas via B4 Relay
                   ` (5 subsequent siblings)
  7 siblings, 2 replies; 17+ messages in thread
From: Bryam Vargas via B4 Relay @ 2026-12-03  9:15 UTC (permalink / raw)
  To: Eric Dumazet, Paolo Abeni, David S. Miller, Jakub Kicinski,
	Mahanta Jambigi, Sidraya Jayagond, D. Wythe, Willem de Bruijn,
	Dust Li
  Cc: Wen Gu, Guangguan Wang, Tony Lu, Ursula Braun, linux-rdma,
	linux-s390, Hidayath Khan, Simon Horman, Wenjia Zhang,
	linux-kernel, Stefan Raspl, netdev

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() */

-- 
2.56.1



^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH net v3 3/7] net/smc: store each cursor once in smc_switch_cursor()
  2026-12-03  9:15 [PATCH net v3 0/7] net/smc: fix the failover cursor switch and wrap rollover Bryam Vargas via B4 Relay
  2026-12-03  9:15 ` [PATCH net v3 1/7] net/smc: take the socket spinlock across the failover cursor switch Bryam Vargas via B4 Relay
  2026-12-03  9:15 ` [PATCH net v3 2/7] net/smc: do not credit stale CDC completions after a link switch Bryam Vargas via B4 Relay
@ 2026-12-03  9:15 ` Bryam Vargas via B4 Relay
  2026-12-04  9:15   ` sashiko-bot
  2026-12-03  9:15 ` [PATCH net v3 4/7] net/smc: fix the failover catch-up across the cursor wrap rollover Bryam Vargas via B4 Relay
                   ` (4 subsequent siblings)
  7 siblings, 1 reply; 17+ messages in thread
From: Bryam Vargas via B4 Relay @ 2026-12-03  9:15 UTC (permalink / raw)
  To: Eric Dumazet, Paolo Abeni, David S. Miller, Jakub Kicinski,
	Mahanta Jambigi, Sidraya Jayagond, D. Wythe, Willem de Bruijn,
	Dust Li
  Cc: Wen Gu, Guangguan Wang, Tony Lu, Ursula Braun, linux-rdma,
	linux-s390, Hidayath Khan, Simon Horman, Wenjia Zhang,
	linux-kernel, Stefan Raspl, netdev

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



^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH net v3 4/7] net/smc: fix the failover catch-up across the cursor wrap rollover
  2026-12-03  9:15 [PATCH net v3 0/7] net/smc: fix the failover cursor switch and wrap rollover Bryam Vargas via B4 Relay
                   ` (2 preceding siblings ...)
  2026-12-03  9:15 ` [PATCH net v3 3/7] net/smc: store each cursor once in smc_switch_cursor() Bryam Vargas via B4 Relay
@ 2026-12-03  9:15 ` Bryam Vargas via B4 Relay
  2026-12-04  9:15   ` sashiko-bot
  2026-12-03  9:15 ` [PATCH net v3 5/7] net/smc: order the urgent mark " Bryam Vargas via B4 Relay
                   ` (3 subsequent siblings)
  7 siblings, 1 reply; 17+ messages in thread
From: Bryam Vargas via B4 Relay @ 2026-12-03  9:15 UTC (permalink / raw)
  To: Eric Dumazet, Paolo Abeni, David S. Miller, Jakub Kicinski,
	Mahanta Jambigi, Sidraya Jayagond, D. Wythe, Willem de Bruijn,
	Dust Li
  Cc: Wen Gu, Guangguan Wang, Tony Lu, Ursula Braun, linux-rdma,
	linux-s390, Hidayath Khan, Simon Horman, Wenjia Zhang,
	linux-kernel, Stefan Raspl, netdev

From: Bryam Vargas <hexlabsecurity@proton.me>

smc_switch_cursor() orders the peer's consumer cursor against
local_tx_ctrl_fin with smc_curs_comp(), which misorders them across the
65535 -> 0 rollover of the u16 wrap. A consumer cursor that is behind
reads as ahead: the catch-up can credit sndbuf_space for bytes never
sent and tell the peer they are in its RMB, so the next send() can copy
past the end of the send buffer. One that is ahead reads as behind and
the catch-up is skipped. With a send buffer larger than the peer's RMB,
the catch-up can also be short once the peer is more than one RMB past
local_tx_ctrl_fin, and the connection then stalls.

Use the signed cursor distance, advance the RMB cursors across any
number of wraps, and bound the catch-up by tx_curs_prep: a conforming
peer has read no further, and unlike tx_curs_sent no failover rewinds
it. The bound also caps what a forged consumer cursor, which is taken
off the wire unchecked, can add to sndbuf_space.

Fixes: c6f02ebeea3a ("net/smc: switch connections to alternate link")
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261029-b4-disp-33001ace-v8-0-f9bb96e17827%40proton.me?part=4
Cc: stable@vger.kernel.org
Reviewed-by: Sidraya Jayagond <sidraya@linux.ibm.com>
Signed-off-by: Bryam Vargas <hexlabsecurity@proton.me>
---
 net/smc/smc_cdc.h  | 10 ++++++++++
 net/smc/smc_core.c | 16 +++++++++++-----
 2 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/net/smc/smc_cdc.h b/net/smc/smc_cdc.h
index 597acb2e123f..4b586a20dfc2 100644
--- a/net/smc/smc_cdc.h
+++ b/net/smc/smc_cdc.h
@@ -97,6 +97,16 @@ static inline void smc_curs_add(int size, union smc_host_cursor *curs,
 	}
 }
 
+/* smc_curs_add() for a value that may span more than one ring */
+static inline void smc_curs_advance(unsigned int size,
+				    union smc_host_cursor *curs, u32 value)
+{
+	u32 count = curs->count + value;
+
+	curs->wrap += count / size;
+	curs->count = count % size;
+}
+
 /* Copy cursor src into tgt */
 static inline void smc_curs_copy(union smc_host_cursor *tgt,
 				 union smc_host_cursor *src,
diff --git a/net/smc/smc_core.c b/net/smc/smc_core.c
index 4ee9e6f0d659..22a9a818a046 100644
--- a/net/smc/smc_core.c
+++ b/net/smc/smc_core.c
@@ -1054,9 +1054,9 @@ 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, prod, sent;
+	union smc_host_cursor cons, prep, prod, sent;
 	int rc = 0;
-	int diff;
+	s64 diff;
 
 	conn->tx_switch_gen++;	/* completions of earlier sends: no credit */
 	/* The cursors of the connection have readers outside send_lock and
@@ -1065,14 +1065,20 @@ static int smc_switch_cursor(struct smc_sock *smc, struct smc_cdc_tx_pend *pend,
 	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);
+	smc_curs_copy(&prep, &conn->tx_curs_prep, conn);
 
-	if (smc_curs_comp(conn->peer_rmbe_size, &cons, &prod) < 0) {
+	/* cons comes off the wire: go no further than tx_curs_prep, which
+	 * a conforming peer has not read past and no failover rewinds. That
+	 * also keeps diff within one send buffer for smc_curs_add().
+	 */
+	diff = min(smc_curs_sdiff(conn->peer_rmbe_size, &prod, &cons),
+		   smc_curs_sdiff(conn->sndbuf_desc->len, &sent, &prep));
+	if (diff > 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, &prod, &cons);
 		smc_curs_add(conn->sndbuf_desc->len, &sent, diff);
-		smc_curs_add(conn->peer_rmbe_size, &prod, diff);
+		smc_curs_advance(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);
 

-- 
2.56.1



^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH net v3 5/7] net/smc: order the urgent mark across the cursor wrap rollover
  2026-12-03  9:15 [PATCH net v3 0/7] net/smc: fix the failover cursor switch and wrap rollover Bryam Vargas via B4 Relay
                   ` (3 preceding siblings ...)
  2026-12-03  9:15 ` [PATCH net v3 4/7] net/smc: fix the failover catch-up across the cursor wrap rollover Bryam Vargas via B4 Relay
@ 2026-12-03  9:15 ` Bryam Vargas via B4 Relay
  2026-12-04  9:15   ` sashiko-bot
  2026-12-03  9:15 ` [PATCH net v3 6/7] net/smc: update the urgent state under the socket spinlock Bryam Vargas via B4 Relay
                   ` (2 subsequent siblings)
  7 siblings, 1 reply; 17+ messages in thread
From: Bryam Vargas via B4 Relay @ 2026-12-03  9:15 UTC (permalink / raw)
  To: Eric Dumazet, Paolo Abeni, David S. Miller, Jakub Kicinski,
	Mahanta Jambigi, Sidraya Jayagond, D. Wythe, Willem de Bruijn,
	Dust Li
  Cc: Wen Gu, Guangguan Wang, Tony Lu, Ursula Braun, linux-rdma,
	linux-s390, Hidayath Khan, Simon Horman, Wenjia Zhang,
	linux-kernel, Stefan Raspl, netdev

From: Bryam Vargas <hexlabsecurity@proton.me>

smc_rx_update_consumer() orders the consumer cursor against urg_curs
with smc_curs_comp(), which misorders them across the 65535 -> 0
rollover of the RMB wrap. Without SO_OOBINLINE, with the reader on wrap
65535 and the urgent byte on wrap 0, the mark reads as already passed:
urg_state becomes SMC_URG_READ before the byte is reached and
recv(MSG_OOB) fails with -EINVAL. The urgent byte, which bytes_to_rcv
leaves out, is then never skipped. The sender waits for its urgent data
to be consumed before it sends more, so the connection stalls.
smc_rx_recv_urg() compares the same two cursors with smc_curs_diff(). A
consumer cursor that is past the mark on the RMB's next wrap reads as
far behind it, and urg_rx_skip_pend is set with nothing left to skip.
SIOCATMARK uses smc_curs_diff() as well and does not test urg_state:
with urg_curs at the start of the RMB, a reader one byte short of the
RMB's end is told it is at the mark on every wrap except the mark's
own. That includes a connection that never received urgent data, where
urg_curs is zero.

Use smc_curs_sdiff(), which orders the two cursors across the wrap
rollover, in all three places, and let SIOCATMARK report the mark only
while it is valid or a skip of its byte is pending. smc_curs_comp() has
no other user; remove it.

Fixes: de8474eb9d50 ("net/smc: urgent data support")
Cc: stable@vger.kernel.org # depends on 2/7 and 4/7
Signed-off-by: Bryam Vargas <hexlabsecurity@proton.me>
---
 net/smc/af_smc.c  |  6 ++++--
 net/smc/smc_cdc.h | 13 -------------
 net/smc/smc_rx.c  | 11 ++++++-----
 3 files changed, 10 insertions(+), 20 deletions(-)

diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c
index bfc0c7e71a12..3877a3a4cbae 100644
--- a/net/smc/af_smc.c
+++ b/net/smc/af_smc.c
@@ -3277,8 +3277,10 @@ int smc_ioctl(struct socket *sock, unsigned int cmd,
 		} else {
 			smc_curs_copy(&cons, &conn->local_tx_ctrl.cons, conn);
 			smc_curs_copy(&urg, &conn->urg_curs, conn);
-			answ = smc_curs_diff(conn->rmb_desc->len,
-					     &cons, &urg) == 1;
+			answ = (conn->urg_state == SMC_URG_VALID ||
+				conn->urg_rx_skip_pend) &&
+			       smc_curs_sdiff(conn->rmb_desc->len,
+					      &cons, &urg) == 1;
 		}
 		break;
 	default:
diff --git a/net/smc/smc_cdc.h b/net/smc/smc_cdc.h
index 4b586a20dfc2..eecd0cc5bb79 100644
--- a/net/smc/smc_cdc.h
+++ b/net/smc/smc_cdc.h
@@ -167,19 +167,6 @@ static inline int smc_curs_diff(unsigned int size,
 	return max_t(int, 0, (new->count - old->count));
 }
 
-/* calculate cursor difference between old and new - returns negative
- * value in case old > new
- */
-static inline int smc_curs_comp(unsigned int size,
-				union smc_host_cursor *old,
-				union smc_host_cursor *new)
-{
-	if (old->wrap > new->wrap ||
-	    (old->wrap == new->wrap && old->count > new->count))
-		return -smc_curs_diff(size, new, old);
-	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
diff --git a/net/smc/smc_rx.c b/net/smc/smc_rx.c
index 63c178c10bf1..564b976426ca 100644
--- a/net/smc/smc_rx.c
+++ b/net/smc/smc_rx.c
@@ -62,14 +62,15 @@ static int smc_rx_update_consumer(struct smc_sock *smc,
 	struct smc_connection *conn = &smc->conn;
 	struct sock *sk = &smc->sk;
 	bool force = false;
-	int diff, rc = 0;
+	int rc = 0;
+	s64 diff;
 
 	smc_curs_add(conn->rmb_desc->len, &cons, len);
 
 	/* did we process urgent data? */
 	if (conn->urg_state == SMC_URG_VALID || conn->urg_rx_skip_pend) {
-		diff = smc_curs_comp(conn->rmb_desc->len, &cons,
-				     &conn->urg_curs);
+		diff = smc_curs_sdiff(conn->rmb_desc->len, &cons,
+				      &conn->urg_curs);
 		if (sock_flag(sk, SOCK_URGINLINE)) {
 			if (diff == 0) {
 				force = true;
@@ -330,8 +331,8 @@ static int smc_rx_recv_urg(struct smc_sock *smc, struct msghdr *msg, int len,
 				rc = memcpy_to_msg(msg, &conn->urg_rx_byte, 1);
 			len = 1;
 			smc_curs_copy(&cons, &conn->local_tx_ctrl.cons, conn);
-			if (smc_curs_diff(conn->rmb_desc->len, &cons,
-					  &conn->urg_curs) > 1)
+			if (smc_curs_sdiff(conn->rmb_desc->len, &cons,
+					   &conn->urg_curs) > 1)
 				conn->urg_rx_skip_pend = true;
 			/* Urgent Byte was already accounted for, but trigger
 			 * skipping the urgent byte in non-inline case

-- 
2.56.1



^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH net v3 6/7] net/smc: update the urgent state under the socket spinlock
  2026-12-03  9:15 [PATCH net v3 0/7] net/smc: fix the failover cursor switch and wrap rollover Bryam Vargas via B4 Relay
                   ` (4 preceding siblings ...)
  2026-12-03  9:15 ` [PATCH net v3 5/7] net/smc: order the urgent mark " Bryam Vargas via B4 Relay
@ 2026-12-03  9:15 ` Bryam Vargas via B4 Relay
  2026-12-04  9:15   ` sashiko-bot
  2026-12-04  9:49   ` netdev-bot+sashiko
  2026-12-03  9:15 ` [PATCH net v3 7/7] net/smc: skip the urgent byte when it is the next unread byte Bryam Vargas via B4 Relay
  2026-12-04  9:15 ` [PATCH net v3 0/7] net/smc: fix the failover cursor switch and wrap rollover sashiko-bot
  7 siblings, 2 replies; 17+ messages in thread
From: Bryam Vargas via B4 Relay @ 2026-12-03  9:15 UTC (permalink / raw)
  To: Eric Dumazet, Paolo Abeni, David S. Miller, Jakub Kicinski,
	Mahanta Jambigi, Sidraya Jayagond, D. Wythe, Willem de Bruijn,
	Dust Li
  Cc: Wen Gu, Guangguan Wang, Tony Lu, Ursula Braun, linux-rdma,
	linux-s390, Hidayath Khan, Simon Horman, Wenjia Zhang,
	linux-kernel, Stefan Raspl, netdev

From: Bryam Vargas <hexlabsecurity@proton.me>

smc_cdc_msg_recv_action() sets a new urgent mark, byte and state under
the socket spinlock, even while a reader owns the socket, and the
reader tests and changes urg_state under the socket lock only. In
smc_rx_recv_urg() a second urgent byte that arrives after the state was
set to SMC_URG_READ is returned in place of the first, and the next
recv(MSG_OOB) returns it again. In smc_rx_update_consumer() a mark set
after the test is overwritten with SMC_URG_READ: its byte is neither
returned nor skipped, and the sender, which waits for its urgent data
to be consumed, stalls.

Take the socket spinlock around both test-and-set sequences.
smc_rx_update_consumer() takes it only after a test without the lock
finds a mark or a pending skip, so a read with no urgent data is
unchanged. The lines of smc_rx_recv_urg() after its SMC_URG_VALID block
could only be reached through this race; drop them.

Fixes: de8474eb9d50 ("net/smc: urgent data support")
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://lore.kernel.org/all/sashiko-outbox-215220@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_rx.c | 102 +++++++++++++++++++++++++++++++++----------------------
 1 file changed, 62 insertions(+), 40 deletions(-)

diff --git a/net/smc/smc_rx.c b/net/smc/smc_rx.c
index 564b976426ca..2680b91e882b 100644
--- a/net/smc/smc_rx.c
+++ b/net/smc/smc_rx.c
@@ -67,26 +67,38 @@ static int smc_rx_update_consumer(struct smc_sock *smc,
 
 	smc_curs_add(conn->rmb_desc->len, &cons, len);
 
-	/* did we process urgent data? */
+	/* did we process urgent data? smc_cdc_msg_recv_action() sets a new
+	 * mark under the socket spinlock, even while we own the socket:
+	 * test again under it. A mark set after the first test is left to
+	 * the next call, like one set after the unlock.
+	 */
 	if (conn->urg_state == SMC_URG_VALID || conn->urg_rx_skip_pend) {
-		diff = smc_curs_sdiff(conn->rmb_desc->len, &cons,
-				      &conn->urg_curs);
-		if (sock_flag(sk, SOCK_URGINLINE)) {
-			if (diff == 0) {
-				force = true;
-				rc = 1;
-				conn->urg_state = SMC_URG_READ;
+		local_bh_disable();
+		bh_lock_sock(sk);
+		if (conn->urg_state == SMC_URG_VALID ||
+		    conn->urg_rx_skip_pend) {
+			diff = smc_curs_sdiff(conn->rmb_desc->len, &cons,
+					      &conn->urg_curs);
+			if (sock_flag(sk, SOCK_URGINLINE)) {
+				if (diff == 0) {
+					force = true;
+					rc = 1;
+					conn->urg_state = SMC_URG_READ;
+				}
+			} else {
+				if (diff == 1) {
+					/* skip urgent byte */
+					force = true;
+					smc_curs_add(conn->rmb_desc->len,
+						     &cons, 1);
+					conn->urg_rx_skip_pend = false;
+				} else if (diff < -1)
+					/* we read past urgent byte */
+					conn->urg_state = SMC_URG_READ;
 			}
-		} else {
-			if (diff == 1) {
-				/* skip urgent byte */
-				force = true;
-				smc_curs_add(conn->rmb_desc->len, &cons, 1);
-				conn->urg_rx_skip_pend = false;
-			} else if (diff < -1)
-				/* we read past urgent byte */
-				conn->urg_state = SMC_URG_READ;
 		}
+		bh_unlock_sock(sk);
+		local_bh_enable();
 	}
 
 	smc_curs_copy(&conn->local_tx_ctrl.cons, &cons, conn);
@@ -314,42 +326,52 @@ static int smc_rx_recv_urg(struct smc_sock *smc, struct msghdr *msg, int len,
 	struct smc_connection *conn = &smc->conn;
 	union smc_host_cursor cons;
 	struct sock *sk = &smc->sk;
+	bool valid;
+	char byte;
 	int rc = 0;
 
-	if (sock_flag(sk, SOCK_URGINLINE) ||
-	    !(conn->urg_state == SMC_URG_VALID) ||
-	    conn->urg_state == SMC_URG_READ)
+	if (sock_flag(sk, SOCK_URGINLINE))
 		return -EINVAL;
 
-	SMC_STAT_INC(smc, urg_data_cnt);
-	if (conn->urg_state == SMC_URG_VALID) {
-		if (!(flags & MSG_PEEK))
-			smc->conn.urg_state = SMC_URG_READ;
-		msg->msg_flags |= MSG_OOB;
+	/* smc_cdc_msg_recv_action() sets a new mark and byte under the
+	 * socket spinlock, even while we own the socket: take the byte
+	 * together with the state it belongs to.
+	 */
+	local_bh_disable();
+	bh_lock_sock(sk);
+	valid = conn->urg_state == SMC_URG_VALID;
+	if (valid) {
+		byte = conn->urg_rx_byte;
 		if (len > 0) {
-			if (!(flags & MSG_TRUNC))
-				rc = memcpy_to_msg(msg, &conn->urg_rx_byte, 1);
-			len = 1;
 			smc_curs_copy(&cons, &conn->local_tx_ctrl.cons, conn);
 			if (smc_curs_sdiff(conn->rmb_desc->len, &cons,
 					   &conn->urg_curs) > 1)
 				conn->urg_rx_skip_pend = true;
-			/* Urgent Byte was already accounted for, but trigger
-			 * skipping the urgent byte in non-inline case
-			 */
-			if (!(flags & MSG_PEEK))
-				smc_rx_update_consumer(smc, cons, 0);
-		} else {
-			msg->msg_flags |= MSG_TRUNC;
 		}
-
-		return rc ? -EFAULT : len;
+		if (!(flags & MSG_PEEK))
+			conn->urg_state = SMC_URG_READ;
 	}
+	bh_unlock_sock(sk);
+	local_bh_enable();
+	if (!valid)
+		return -EINVAL;
 
-	if (sk->sk_state == SMC_CLOSED || sk->sk_shutdown & RCV_SHUTDOWN)
-		return 0;
+	SMC_STAT_INC(smc, urg_data_cnt);
+	msg->msg_flags |= MSG_OOB;
+	if (len > 0) {
+		if (!(flags & MSG_TRUNC))
+			rc = memcpy_to_msg(msg, &byte, 1);
+		len = 1;
+		/* Urgent Byte was already accounted for, but trigger
+		 * skipping the urgent byte in non-inline case
+		 */
+		if (!(flags & MSG_PEEK))
+			smc_rx_update_consumer(smc, cons, 0);
+	} else {
+		msg->msg_flags |= MSG_TRUNC;
+	}
 
-	return -EAGAIN;
+	return rc ? -EFAULT : len;
 }
 
 static bool smc_rx_recvmsg_data_available(struct smc_sock *smc, size_t peeked)

-- 
2.56.1



^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH net v3 7/7] net/smc: skip the urgent byte when it is the next unread byte
  2026-12-03  9:15 [PATCH net v3 0/7] net/smc: fix the failover cursor switch and wrap rollover Bryam Vargas via B4 Relay
                   ` (5 preceding siblings ...)
  2026-12-03  9:15 ` [PATCH net v3 6/7] net/smc: update the urgent state under the socket spinlock Bryam Vargas via B4 Relay
@ 2026-12-03  9:15 ` Bryam Vargas via B4 Relay
  2026-12-04  9:49   ` netdev-bot+sashiko
  2026-12-04  9:15 ` [PATCH net v3 0/7] net/smc: fix the failover cursor switch and wrap rollover sashiko-bot
  7 siblings, 1 reply; 17+ messages in thread
From: Bryam Vargas via B4 Relay @ 2026-12-03  9:15 UTC (permalink / raw)
  To: Eric Dumazet, Paolo Abeni, David S. Miller, Jakub Kicinski,
	Mahanta Jambigi, Sidraya Jayagond, D. Wythe, Willem de Bruijn,
	Dust Li
  Cc: Wen Gu, Guangguan Wang, Tony Lu, Ursula Braun, linux-rdma,
	linux-s390, Hidayath Khan, Simon Horman, Wenjia Zhang,
	linux-kernel, Stefan Raspl, netdev

From: Bryam Vargas <hexlabsecurity@proton.me>

recv(MSG_OOB) returns the urgent byte and relies on
smc_rx_update_consumer() to skip the byte's place in the RMB.
recv(MSG_OOB) asks for that skip by setting urg_rx_skip_pend, but only
when there is unread data in front of the byte. When the urgent byte is
the next unread byte, e.g. after a one-byte send(MSG_OOB) to a reader
that has read everything else, no skip is pending and urg_state is
SMC_URG_READ: the byte is never skipped, and the sender, which waits
for its urgent data to be consumed, stalls on its next send(). A
zero-length recv(MSG_OOB) consumes the byte as well, but neither sets
urg_rx_skip_pend nor calls smc_rx_update_consumer().

Set urg_rx_skip_pend whenever the reader has not passed the urgent
byte, and call smc_rx_update_consumer() for any length.

Fixes: de8474eb9d50 ("net/smc: urgent data support")
Suggested-by: Sidraya Jayagond <sidraya@linux.ibm.com>
Cc: stable@vger.kernel.org
Signed-off-by: Bryam Vargas <hexlabsecurity@proton.me>
---
 net/smc/smc_rx.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/net/smc/smc_rx.c b/net/smc/smc_rx.c
index 2680b91e882b..579ee008900c 100644
--- a/net/smc/smc_rx.c
+++ b/net/smc/smc_rx.c
@@ -342,12 +342,14 @@ static int smc_rx_recv_urg(struct smc_sock *smc, struct msghdr *msg, int len,
 	valid = conn->urg_state == SMC_URG_VALID;
 	if (valid) {
 		byte = conn->urg_rx_byte;
-		if (len > 0) {
-			smc_curs_copy(&cons, &conn->local_tx_ctrl.cons, conn);
-			if (smc_curs_sdiff(conn->rmb_desc->len, &cons,
-					   &conn->urg_curs) > 1)
-				conn->urg_rx_skip_pend = true;
-		}
+		/* The reader has not passed the urgent byte: have
+		 * smc_rx_update_consumer() skip it once it is the next
+		 * unread byte.
+		 */
+		smc_curs_copy(&cons, &conn->local_tx_ctrl.cons, conn);
+		if (smc_curs_sdiff(conn->rmb_desc->len, &cons,
+				   &conn->urg_curs) > 0)
+			conn->urg_rx_skip_pend = true;
 		if (!(flags & MSG_PEEK))
 			conn->urg_state = SMC_URG_READ;
 	}
@@ -362,14 +364,14 @@ static int smc_rx_recv_urg(struct smc_sock *smc, struct msghdr *msg, int len,
 		if (!(flags & MSG_TRUNC))
 			rc = memcpy_to_msg(msg, &byte, 1);
 		len = 1;
-		/* Urgent Byte was already accounted for, but trigger
-		 * skipping the urgent byte in non-inline case
-		 */
-		if (!(flags & MSG_PEEK))
-			smc_rx_update_consumer(smc, cons, 0);
 	} else {
 		msg->msg_flags |= MSG_TRUNC;
 	}
+	/* Urgent Byte was already accounted for, but trigger
+	 * skipping the urgent byte in non-inline case
+	 */
+	if (!(flags & MSG_PEEK))
+		smc_rx_update_consumer(smc, cons, 0);
 
 	return rc ? -EFAULT : len;
 }

-- 
2.56.1



^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Re: [PATCH net v3 2/7] net/smc: do not credit stale CDC completions after a link switch
  2026-12-03  9:15 ` [PATCH net v3 2/7] net/smc: do not credit stale CDC completions after a link switch Bryam Vargas via B4 Relay
@ 2026-12-04  9:15   ` sashiko-bot
  2026-12-04  9:49   ` netdev-bot+sashiko
  1 sibling, 0 replies; 17+ messages in thread
From: sashiko-bot @ 2026-12-04  9:15 UTC (permalink / raw)
  To: Bryam Vargas
  Cc: linux-rdma, linux-s390, Heiko Carstens, Vasily Gorbik,
	Alexander Gordeev, Christian Borntraeger

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Critical] net/smc: stale CDC completion wraparound overflows
  sndbuf_space
--

commit 9ac2c46d0b76eff999e2445956bc66d5ca01126d
Author: Bryam Vargas <hexlabsecurity@proton.me>

net/smc: do not credit stale CDC completions after a link switch

This commit adds a tx_switch_gen counter to struct smc_connection that
smc_switch_cursor() increments, and checks both the generation and a signed
cursor difference in smc_cdc_tx_handler() before crediting sndbuf_space.

> diff --git a/net/smc/smc_cdc.c b/net/smc/smc_cdc.c
> index 32d6d03df3214..d1f346376c08c 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);

[Severity: Critical]
Can a stale completion on the old link still wrap smc_curs_sdiff() and
overflow conn->sndbuf_space for an SMC_APPCLOSEWAIT1 socket?

In smc_switch_conns(), an SMC_APPCLOSEWAIT1 socket is moved to the new link
without calling smc_switch_cursor(), so conn->tx_switch_gen is not bumped.
Unlike the other closing states, smc_sendmsg() still permits unlimited local
sends in SMC_APPCLOSEWAIT1.

A remote peer can half-close its write side, withhold receive WQEs on the
old link (where SMC-R QPs use infinite RNR retries while link deletion waits
in smc_wr_tx_wait_no_pending_sends()), and trigger a link switch. Once 32768
send-buffer rings complete on the new link (512 MiB for a 16 KiB buffer),
tx_curs_fin.wrap is 32768 ahead of the stale cdcpend->cursor.wrap.

When that stale completion arrives, switch_gen still matches and the s16
cast in smc_curs_sdiff() flips the wrap difference to positive, passing >= 0
with no upper bound. smc_curs_diff() then adds up to 2 * sndbuf_desc->len - 1
bytes to conn->sndbuf_space and rewinds tx_curs_fin.

On the next smc_tx_sendmsg(), writespace exceeds sndbuf_desc->len, so the
second chunk's memcpy_from_msg() writes past the end of
sndbuf_desc->cpu_addr and causes a kernel out-of-bounds write, while
smc_curs_add() leaves tx_curs_prep.count >= sndbuf_desc->len.

An upper bound check on smc_curs_sdiff() alone would still be bypassed after
65536 rings when the u16 wrap counter aliases back to 0; bumping
tx_switch_gen (or rejecting completions from the old link) for
SMC_APPCLOSEWAIT1 switches would invalidate prior-link completions.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203-b4-disp-ba1ad55e-v3-0-6834ff90c5d0@proton.me?part=2

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH net v3 3/7] net/smc: store each cursor once in smc_switch_cursor()
  2026-12-03  9:15 ` [PATCH net v3 3/7] net/smc: store each cursor once in smc_switch_cursor() Bryam Vargas via B4 Relay
@ 2026-12-04  9:15   ` sashiko-bot
  0 siblings, 0 replies; 17+ messages in thread
From: sashiko-bot @ 2026-12-04  9:15 UTC (permalink / raw)
  To: Bryam Vargas
  Cc: linux-rdma, linux-s390, Heiko Carstens, Vasily Gorbik,
	Alexander Gordeev, Christian Borntraeger

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 <hexlabsecurity@proton.me>

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 = &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);

[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.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203-b4-disp-ba1ad55e-v3-0-6834ff90c5d0@proton.me?part=3

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH net v3 4/7] net/smc: fix the failover catch-up across the cursor wrap rollover
  2026-12-03  9:15 ` [PATCH net v3 4/7] net/smc: fix the failover catch-up across the cursor wrap rollover Bryam Vargas via B4 Relay
@ 2026-12-04  9:15   ` sashiko-bot
  0 siblings, 0 replies; 17+ messages in thread
From: sashiko-bot @ 2026-12-04  9:15 UTC (permalink / raw)
  To: Bryam Vargas
  Cc: linux-rdma, linux-s390, Heiko Carstens, Vasily Gorbik,
	Alexander Gordeev, Christian Borntraeger

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] net/smc: 32-bit overflow in smc_curs_advance() on peer-inflated
  cursor
--

commit 52e3a4c92279019fc58cd954b752fde02a52614b
Author: Bryam Vargas <hexlabsecurity@proton.me>

net/smc: fix the failover catch-up across the cursor wrap rollover

This commit replaces smc_curs_comp() and smc_curs_diff() in
smc_switch_cursor() with smc_curs_sdiff() bounded by tx_curs_prep, and adds
smc_curs_advance() to advance the peer RMB producer cursor across multiple
wraps during link failover.

> diff --git a/net/smc/smc_cdc.h b/net/smc/smc_cdc.h
> index 597acb2e123f5..4b586a20dfc2c 100644
> --- a/net/smc/smc_cdc.h
> +++ b/net/smc/smc_cdc.h
> @@ -97,6 +97,16 @@ static inline void smc_curs_add(int size, union smc_host_cursor *curs,
>  	}
>  }
>  
> +/* smc_curs_add() for a value that may span more than one ring */
> +static inline void smc_curs_advance(unsigned int size,
> +				    union smc_host_cursor *curs, u32 value)
> +{
> +	u32 count = curs->count + value;
> +
> +	curs->wrap += count / size;
> +	curs->count = count % size;
> +}
> +
>  /* Copy cursor src into tgt */
>  static inline void smc_curs_copy(union smc_host_cursor *tgt,
>  				 union smc_host_cursor *src,

[Severity: Low]
Can curs->count + value overflow 32 bits here?

When sndbuf_desc->len exceeds conn->peer_rmbe_size, a remote peer can send
unchecked cons updates to smc_cdc_msg_recv_action() that inflate
conn->peer_rmbe_space past peer_rmbe_size.  Each send larger than
peer_rmbe_size then calls smc_curs_add() in smc_tx_advance_cursors().

Because smc_curs_add() subtracts peer_rmbe_size only once, repeated sends
walk local_tx_ctrl_fin.count up toward 2^32.  If link failover runs
smc_switch_cursor() and passes that cursor to smc_curs_advance(), the 32-bit
addition wraps modulo 2^32.

For peer_rmbe_size >= 128KB, wrapping count drops 2^(32 - k) wraps (where
peer_rmbe_size is 2^k) and corrupts local_tx_ctrl_fin.wrap and
local_tx_ctrl.prod.wrap on that connection.  Using u64 for count with
div_u64_rem() avoids the overflow.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203-b4-disp-ba1ad55e-v3-0-6834ff90c5d0@proton.me?part=4

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH net v3 5/7] net/smc: order the urgent mark across the cursor wrap rollover
  2026-12-03  9:15 ` [PATCH net v3 5/7] net/smc: order the urgent mark " Bryam Vargas via B4 Relay
@ 2026-12-04  9:15   ` sashiko-bot
  0 siblings, 0 replies; 17+ messages in thread
From: sashiko-bot @ 2026-12-04  9:15 UTC (permalink / raw)
  To: Bryam Vargas
  Cc: linux-rdma, linux-s390, Heiko Carstens, Vasily Gorbik,
	Alexander Gordeev, Christian Borntraeger

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] net/smc: race between urg_curs copy and urg_state check in
  smc_ioctl()
--

commit f0a9404787457616babe9aded75f7a3fe0de2944
Author: Bryam Vargas <hexlabsecurity@proton.me>

net/smc: order the urgent mark across the cursor wrap rollover

This commit replaces urgent-mark cursor comparisons in
smc_rx_update_consumer(), smc_rx_recv_urg(), and smc_ioctl() with
smc_curs_sdiff() to handle the 16-bit wrap rollover, removes
smc_curs_comp(), and gates SIOCATMARK on urg_state or urg_rx_skip_pend.

> diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c
> index bfc0c7e71a12b..3877a3a4cbae0 100644
> --- a/net/smc/af_smc.c
> +++ b/net/smc/af_smc.c
> @@ -3277,8 +3277,10 @@ int smc_ioctl(struct socket *sock, unsigned int cmd,
>  		} else {
>  			smc_curs_copy(&cons, &conn->local_tx_ctrl.cons, conn);
>  			smc_curs_copy(&urg, &conn->urg_curs, conn);
> -			answ = smc_curs_diff(conn->rmb_desc->len,
> -					     &cons, &urg) == 1;
> +			answ = (conn->urg_state == SMC_URG_VALID ||
> +				conn->urg_rx_skip_pend) &&
> +			       smc_curs_sdiff(conn->rmb_desc->len,
> +					      &cons, &urg) == 1;
>  		}
>  		break;
>  	default:

[Severity: Medium]
Can SIOCATMARK race with smc_cdc_handle_urg_data_arrival() and test
conn->urg_state against a stale copy of conn->urg_curs?

smc_ioctl() holds lock_sock(&smc->sk), whereas smc_cdc_msg_recv() runs
in tasklet context under bh_lock_sock(&smc->sk) without checking
sock_owned_by_user(&smc->sk), so the two execute concurrently:

CPU0 (smc_ioctl)                  CPU1 (tasklet: smc_cdc_msg_recv)
lock_sock(&smc->sk)
smc_curs_copy(&cons, ...)
smc_curs_copy(&urg, &conn->urg_curs)
                                  bh_lock_sock(&smc->sk)
                                  ...
                                  smc_cdc_handle_urg_data_arrival()
                                    smc_curs_copy(&conn->urg_curs, ...)
                                    conn->urg_state = SMC_URG_VALID
                                  bh_unlock_sock(&smc->sk)
conn->urg_state == SMC_URG_VALID
smc_curs_sdiff(..., &cons, &urg)  <-- compares against stale urg_curs

If cons is one byte before the wrap rollover (wrap 65535, count
rmb_desc->len - 1) on a connection with stale urg_curs {0, 0}, and a new
urgent byte arrives further ahead between the copy and the state check,
SIOCATMARK sees SMC_URG_VALID and falsely returns 1 to userspace.

Protecting the urg_state check and urg_curs copy with local_bh_disable()
and bh_lock_sock(&smc->sk) would keep them consistent.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203-b4-disp-ba1ad55e-v3-0-6834ff90c5d0@proton.me?part=5

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH net v3 6/7] net/smc: update the urgent state under the socket spinlock
  2026-12-03  9:15 ` [PATCH net v3 6/7] net/smc: update the urgent state under the socket spinlock Bryam Vargas via B4 Relay
@ 2026-12-04  9:15   ` sashiko-bot
  2026-12-04  9:49   ` netdev-bot+sashiko
  1 sibling, 0 replies; 17+ messages in thread
From: sashiko-bot @ 2026-12-04  9:15 UTC (permalink / raw)
  To: Bryam Vargas
  Cc: linux-rdma, linux-s390, Heiko Carstens, Vasily Gorbik,
	Alexander Gordeev, Christian Borntraeger

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] net/smc: unlocked SIOCATMARK urgent state read in smc_ioctl()
- [Low] net/smc: unmarked lockless conn->urg_state access in
  smc_rx_update_consumer()
--

commit ecdc0ee1be6bad8560d17f7bb2467d0c7e080ab9
Author: Bryam Vargas <hexlabsecurity@proton.me>

net/smc: update the urgent state under the socket spinlock

This commit takes bh_lock_sock() around the urgent state checks and updates
in smc_rx_update_consumer() and smc_rx_recv_urg() to serialize them with
smc_cdc_msg_recv_action().

> Take the socket spinlock around both test-and-set sequences.

[Severity: Medium]
Does smc_ioctl() also need bh_lock_sock() around its SIOCATMARK read of
conn->urg_curs and conn->urg_state?

Earlier in this series, commit "net/smc: order the urgent mark across the
cursor wrap rollover" updated the SIOCATMARK path to check conn->urg_state
alongside conn->urg_curs while holding only lock_sock():

net/smc/af_smc.c:smc_ioctl() {
	...
			smc_curs_copy(&cons, &conn->local_tx_ctrl.cons, conn);
			smc_curs_copy(&urg, &conn->urg_curs, conn);
			answ = (conn->urg_state == SMC_URG_VALID ||
				conn->urg_rx_skip_pend) &&
			       smc_curs_sdiff(conn->rmb_desc->len,
					      &cons, &urg) == 1;
	...
}

Because smc_ioctl() copies conn->urg_curs before testing conn->urg_state, it
reads them in the opposite order from smc_cdc_handle_urg_data_arrival():

CPU0 (user)                       CPU1 (softirq)
smc_ioctl(SIOCATMARK)
  lock_sock(&smc->sk)
  urg = conn->urg_curs
                                  smc_cdc_msg_recv()
                                    bh_lock_sock(&smc->sk)
                                    smc_cdc_handle_urg_data_arrival()
                                      conn->urg_curs = prod
                                      conn->urg_state = SMC_URG_VALID
                                    bh_unlock_sock(&smc->sk)
  test conn->urg_state
    <-- pairs stale urg with new SMC_URG_VALID

As a result, ioctl(SIOCATMARK) can observe a torn snapshot and return a false
positive or false negative, in addition to an unmarked data race on
conn->urg_state.  Taking local_bh_disable() and bh_lock_sock(&smc->sk) around
the SIOCATMARK read would fix both.

[ ... ]

> diff --git a/net/smc/smc_rx.c b/net/smc/smc_rx.c
> index 564b976426caa..2680b91e882b9 100644
> --- a/net/smc/smc_rx.c
> +++ b/net/smc/smc_rx.c
> @@ -67,26 +67,38 @@ static int smc_rx_update_consumer(struct smc_sock *smc,
>  
>  	smc_curs_add(conn->rmb_desc->len, &cons, len);
>  
> -	/* did we process urgent data? */
> +	/* did we process urgent data? smc_cdc_msg_recv_action() sets a new
> +	 * mark under the socket spinlock, even while we own the socket:
> +	 * test again under it. A mark set after the first test is left to
> +	 * the next call, like one set after the unlock.
> +	 */
>  	if (conn->urg_state == SMC_URG_VALID || conn->urg_rx_skip_pend) {
> -		diff = smc_curs_sdiff(conn->rmb_desc->len, &cons,
> -				      &conn->urg_curs);
> -		if (sock_flag(sk, SOCK_URGINLINE)) {
> -			if (diff == 0) {
> -				force = true;
> -				rc = 1;
> -				conn->urg_state = SMC_URG_READ;
> +		local_bh_disable();
> +		bh_lock_sock(sk);
> +		if (conn->urg_state == SMC_URG_VALID ||
> +		    conn->urg_rx_skip_pend) {

[Severity: Low]
Should this lockless fast-path read use READ_ONCE(conn->urg_state) paired
with WRITE_ONCE() on the writers?

smc_cdc_handle_urg_data_arrival() and smc_cdc_msg_recv_action() update
conn->urg_state under bh_lock_sock(sk) only, concurrently with this plain
unlocked load, which causes KCSAN data-race reports.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203-b4-disp-ba1ad55e-v3-0-6834ff90c5d0@proton.me?part=6

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH net v3 0/7] net/smc: fix the failover cursor switch and wrap rollover
  2026-12-03  9:15 [PATCH net v3 0/7] net/smc: fix the failover cursor switch and wrap rollover Bryam Vargas via B4 Relay
                   ` (6 preceding siblings ...)
  2026-12-03  9:15 ` [PATCH net v3 7/7] net/smc: skip the urgent byte when it is the next unread byte Bryam Vargas via B4 Relay
@ 2026-12-04  9:15 ` sashiko-bot
  7 siblings, 0 replies; 17+ messages in thread
From: sashiko-bot @ 2026-12-04  9:15 UTC (permalink / raw)
  To: Bryam Vargas
  Cc: linux-rdma, linux-s390, Heiko Carstens, Vasily Gorbik,
	Alexander Gordeev, Christian Borntraeger

Sashiko has finished reviewing this 7-patch series:

- Patches 1 and 7: no issues found.
- Patch 2 ("net/smc: do not credit stale CDC completions after a..."): 1
  potential issue (1 Critical)
- Patch 3 ("net/smc: store each cursor once in smc_switch_cursor()"): 1
  potential issue (1 Medium)
- Patch 4 ("net/smc: fix the failover catch-up across the cursor..."): 1
  potential issue (1 Low)
- Patch 5 ("net/smc: order the urgent mark across the cursor wra..."): 1
  potential issue (1 Medium)
- Patch 6 ("net/smc: update the urgent state under the socket sp..."): 2
  potential issues (1 Medium, 1 Low)

Detailed reviews have been sent as separate replies to patches 2-6.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203-b4-disp-ba1ad55e-v3-0-6834ff90c5d0@proton.me

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH net v3 2/7] net/smc: do not credit stale CDC completions after a link switch
  2026-12-03  9:15 ` [PATCH net v3 2/7] net/smc: do not credit stale CDC completions after a link switch Bryam Vargas via B4 Relay
  2026-12-04  9:15   ` sashiko-bot
@ 2026-12-04  9:49   ` netdev-bot+sashiko
  1 sibling, 0 replies; 17+ messages in thread
From: netdev-bot+sashiko @ 2026-12-04  9:49 UTC (permalink / raw)
  To: hexlabsecurity
  Cc: edumazet, pabeni, davem, kuba, mjambigi, sidraya, alibuda,
	willemb, dust.li, guwen, guangguan.wang, tonylu, ubraun,
	linux-rdma, linux-s390, hidayath, horms, wenjia, linux-kernel,
	raspl, netdev

Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 1 · High: 0 (1) · Medium: 0 · Low: 1

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Critical] net/smc: stale CDC completion wraparound overflows
  sndbuf_space
- [Low] Undocumented stable backport dependency.

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but connections in
  closing states lose in-flight data on a link switch.

--

net/smc: do not credit stale CDC completions after a link switch

Each CDC pending send now carries a switch generation, and
smc_switch_cursor() bumps that generation. smc_cdc_tx_handler() then credits
sndbuf_space only for completions of the current generation whose cursor is
not behind tx_curs_fin. The goal is to stop rewound bytes from being
credited, and to stop the same bytes being credited twice after a link
switch.

> diff --git a/net/smc/smc_cdc.c b/net/smc/smc_cdc.c
> index 32d6d03df3214..d1f346376c08c 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);

[Severity: Critical]
Can a stale completion from the old link still pass this check once
the connection has streamed far enough on the new link?

The closing-state branch in smc_switch_conns() moves SMC_APPCLOSEWAIT1
connections with smc_switch_link_and_count() only and never calls
smc_switch_cursor(), so tx_switch_gen is not bumped on that path. A CDC
still pending on the old link keeps the current generation, and the
switch_gen comparison does not filter it out.

smc_sendmsg() keeps accepting data in SMC_APPCLOSEWAIT1, so the
application can go on streaming on the new link. The old CDC does not
have to fail either. smc_ib_modify_qp_rts() sets rnr_retry to
SMC_QP_RNR_RETRY (7, retry forever), and after smc_switch_conns()
smc_llc_process_srv_delete_link() then waits in
smc_wr_tx_wait_no_pending_sends(lnk_del) with no timeout while lnk_del
stays in RTS. A peer that withholds receive WQEs on that link can keep
the WR outstanding for as long as it likes.

The comment on smc_curs_sdiff() says it only holds for cursors less
than 32768 rings apart, and nothing bounds that here. With a 16 KiB
send buffer that is 512 MiB, which does not take long on RoCE. Once
tx_curs_fin.wrap is more than 32768 ahead of cdcpend->cursor.wrap, the
s16 cast turns the negative wrap difference positive, smc_curs_sdiff()
returns a large positive value, and the >= 0 test passes.

smc_curs_diff() then only checks whether the wraps differ and returns
(sndbuf_desc->len - tx_curs_fin.count) + cdcpend->cursor.count, up to
2 * sndbuf_desc->len - 1. That is added to sndbuf_space and tx_curs_fin
is moved back to the stale cursor.

With sndbuf_space above sndbuf_desc->len, smc_tx_sendmsg() can pick a
copylen larger than the send buffer. The second chunk then calls
memcpy_from_msg() at sndbuf_base with chunk_len > sndbuf_desc->len and
writes past the end of sndbuf_desc->cpu_addr. smc_curs_add() also
leaves tx_curs_prep.count >= sndbuf_desc->len, and the next
sndbuf_desc->len - tx_cnt_prep underflows.

Bounding the check by sndbuf_desc->len would narrow this, but the u16
wrap counter aliases back after 65536 rings, so it would not close it.
Bumping tx_switch_gen in the closing-state branch alone would leave the
bytes in flight on the old link uncredited, since that branch does not
rewind or resend them. How should completions from the old link be
handled on that path, so they cannot be credited once the wrap
distance has gone past what smc_curs_sdiff() can represent?

Nothing later in the series appears to change smc_cdc_tx_handler() or
smc_switch_conns() for this.

[Severity: High]
This isn't a bug introduced by this patch, but can a connection in a
closing state lose in-flight data on a link switch?

The commit message says closing-state connections move to the new link
without a rewind. In smc_switch_conns() that branch only does this:

	if (smc->sk.sk_state == SMC_CLOSED ||
	    ...
	    smc->sk.sk_state == SMC_APPCLOSEWAIT1 ||
	    ...
	    smc->sk.sk_state == SMC_PROCESSABORT) {
		spin_lock_bh(&conn->send_lock);
		smc_switch_link_and_count(conn, to_lnk);
		spin_unlock_bh(&conn->send_lock);
		continue;
	}

So tx_curs_sent and local_tx_ctrl.prod are not rewound, and nothing is
resent.

smc_sendmsg() still accepts writes in SMC_APPCLOSEWAIT1:

	} else if ((sk->sk_state != SMC_ACTIVE) &&
		   (sk->sk_state != SMC_APPCLOSEWAIT1) &&
		   (sk->sk_state != SMC_INIT)) {

That means RDMA writes and CDCs can still be outstanding on the old link
when it fails. smcr_link_clear()->smc_ib_modify_qp_error() flushes those
WRs. They reach smc_cdc_tx_handler() through smc_wr_tx_process_cqe() with a
non-zero wc_status, so nothing is credited.

tx_curs_fin stays behind, but tx_curs_sent and local_tx_ctrl.prod already
point past the flushed range.

The next CDC posted on the new link then carries a prod cursor past the
lost range. That could be a later smc_tx_rdma_writes() send, a consumer
cursor update, or the close CDC from smc_close_wr(). Would the peer then
read stale RMB contents as stream data?

When that CDC completes, it has the current tx_switch_gen and its cursor is
ahead of tx_curs_fin. The new check accepts it, and smc_curs_diff() credits
sndbuf_space for the whole range, including the bytes that were never
delivered.

This has been present since c6f02ebeea3a ("net/smc: switch connections to
alternate link"). Nothing later in the series appears to fix the missing
resend.

[ ... ]

> diff --git a/net/smc/smc_core.c b/net/smc/smc_core.c
> index 73e86100e6db2..fb9f6a4eb6835 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() */

[Severity: Low]
Does this rely on the preceding patch in the series, "net/smc: take the
socket spinlock across the failover cursor switch"?

smc_cdc_tx_handler() reads tx_switch_gen and tx_curs_fin under
bh_lock_sock() only. The handler sees this bump and the rewind after it
as atomic only because the preceding patch takes the socket spinlock
around the call in smc_switch_conns():

	local_bh_disable();
	bh_lock_sock(&smc->sk);
	spin_lock(&conn->send_lock);
	smc_switch_link_and_count(conn, to_lnk);
	rc = smc_switch_cursor(smc, pend, wr_buf);

Without that patch, smc_switch_cursor() runs under send_lock only. The
completion handler on another CPU can then see switch_gen == tx_switch_gen
just before the bump, and credit and overwrite tx_curs_fin while the switch
is rewinding it.

This hunk applies and builds without the preceding patch, and both patches
carry Cc: stable with the same Fixes: tag. "net/smc: order the urgent mark
across the cursor wrap rollover" in the same series has a "# depends on"
note. Should this commit have one too, so a stable backport does not take
it alone?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261203-b4-disp-ba1ad55e-v3-0-6834ff90c5d0%40proton.me

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH net v3 6/7] net/smc: update the urgent state under the socket spinlock
  2026-12-03  9:15 ` [PATCH net v3 6/7] net/smc: update the urgent state under the socket spinlock Bryam Vargas via B4 Relay
  2026-12-04  9:15   ` sashiko-bot
@ 2026-12-04  9:49   ` netdev-bot+sashiko
  1 sibling, 0 replies; 17+ messages in thread
From: netdev-bot+sashiko @ 2026-12-04  9:49 UTC (permalink / raw)
  To: hexlabsecurity
  Cc: edumazet, pabeni, davem, kuba, mjambigi, sidraya, alibuda,
	willemb, dust.li, guwen, guangguan.wang, tonylu, ubraun,
	linux-rdma, linux-s390, hidayath, horms, wenjia, linux-kernel,
	raspl, netdev

Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] net/smc: unmarked lockless conn->urg_state access in
  smc_rx_update_consumer()

--

> diff --git a/net/smc/smc_rx.c b/net/smc/smc_rx.c
> --- a/net/smc/smc_rx.c
> +++ b/net/smc/smc_rx.c
> @@ -67,26 +67,38 @@ static int smc_rx_update_consumer(struct smc_sock *smc,
>  
>  	smc_curs_add(conn->rmb_desc->len, &cons, len);
>  
> -	/* did we process urgent data? */
> +	/* did we process urgent data? smc_cdc_msg_recv_action() sets a new
> +	 * mark under the socket spinlock, even while we own the socket:
> +	 * test again under it. A mark set after the first test is left to
> +	 * the next call, like one set after the unlock.
> +	 */
>  	if (conn->urg_state == SMC_URG_VALID || conn->urg_rx_skip_pend) {
> -		diff = smc_curs_sdiff(conn->rmb_desc->len, &cons,
> -				      &conn->urg_curs);
> -		if (sock_flag(sk, SOCK_URGINLINE)) {
> -			if (diff == 0) {
> -				force = true;
> -				rc = 1;
> -				conn->urg_state = SMC_URG_READ;
> +		local_bh_disable();
> +		bh_lock_sock(sk);
> +		if (conn->urg_state == SMC_URG_VALID ||
> +		    conn->urg_rx_skip_pend) {
> +			diff = smc_curs_sdiff(conn->rmb_desc->len, &cons,
> +					      &conn->urg_curs);
> +			if (sock_flag(sk, SOCK_URGINLINE)) {
> +				if (diff == 0) {
> +					force = true;
> +					rc = 1;
> +					conn->urg_state = SMC_URG_READ;
> +				}
> +			} else {
> +				if (diff == 1) {
> +					/* skip urgent byte */
> +					force = true;
> +					smc_curs_add(conn->rmb_desc->len,
> +						     &cons, 1);
> +					conn->urg_rx_skip_pend = false;
> +				} else if (diff < -1)
> +					/* we read past urgent byte */
> +					conn->urg_state = SMC_URG_READ;
>  			}
> -		} else {
> -			if (diff == 1) {
> -				/* skip urgent byte */
> -				force = true;
> -				smc_curs_add(conn->rmb_desc->len, &cons, 1);
> -				conn->urg_rx_skip_pend = false;
> -			} else if (diff < -1)
> -				/* we read past urgent byte */
> -				conn->urg_state = SMC_URG_READ;
>  		}
> +		bh_unlock_sock(sk);
> +		local_bh_enable();
>  	}
>  
>  	smc_curs_copy(&conn->local_tx_ctrl.cons, &cons, conn);

[Severity: Low]
With this patch the outer test becomes an intentional lockless fast
path. It is still a plain load of conn->urg_state and
conn->urg_rx_skip_pend. Meanwhile smc_cdc_handle_urg_data_arrival()
and smc_cdc_msg_recv_action() store to conn->urg_state from
softirq/tasklet context while holding only bh_lock_sock().

Nothing breaks functionally. The re-check under the spinlock decides
what actually happens, and a mark missed by the outer test is picked
up on the next call, as your comment says. But KCSAN will report this
as a data race, and the compiler is free to fuse or reload the
unmarked access.

Since the patch deliberately turns this into a double-checked
pattern, could the outer test use READ_ONCE() for both fields? The
writers would then need matching WRITE_ONCE(): the cdc paths, plus
the stores in smc_rx_update_consumer() and smc_rx_recv_urg().

The other lockless readers of urg_state already have the same issue:
smc_rx_recvmsg_data_available(), smc_rx_recvmsg() and smc_poll(). If
you would rather keep this fix minimal for stable, a follow-up that
annotates all of them would be fine too.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261203-b4-disp-ba1ad55e-v3-0-6834ff90c5d0%40proton.me

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH net v3 7/7] net/smc: skip the urgent byte when it is the next unread byte
  2026-12-03  9:15 ` [PATCH net v3 7/7] net/smc: skip the urgent byte when it is the next unread byte Bryam Vargas via B4 Relay
@ 2026-12-04  9:49   ` netdev-bot+sashiko
  0 siblings, 0 replies; 17+ messages in thread
From: netdev-bot+sashiko @ 2026-12-04  9:49 UTC (permalink / raw)
  To: hexlabsecurity
  Cc: edumazet, pabeni, davem, kuba, mjambigi, sidraya, alibuda,
	willemb, dust.li, guwen, guangguan.wang, tonylu, ubraun,
	linux-rdma, linux-s390, hidayath, horms, wenjia, linux-kernel,
	raspl, netdev

Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The stable backport prerequisites are not stated.
- [Low] The patch changes what urg_rx_skip_pend means but leaves its
  definition comment alone.

--

net/smc: skip the urgent byte when it is the next unread byte

With this patch, smc_rx_recv_urg() sets urg_rx_skip_pend whenever the
reader has not yet passed the urgent byte. Before, it was set only when
regular data was in front of that byte. The patch also calls
smc_rx_update_consumer() for a zero-length recv(MSG_OOB), so the urgent
byte is skipped and the sender does not stall.

> Fixes: de8474eb9d50 ("net/smc: urgent data support")
> Suggested-by: Sidraya Jayagond <sidraya@linux.ibm.com>
> Cc: stable@vger.kernel.org

[Severity: Low]
Should this stable tag name the patches this one depends on?

The hunk in smc_rx_recv_urg() only applies on top of two earlier patches
in this series:

  "net/smc: update the urgent state under the socket spinlock" adds the
  valid and byte locals, the bh_lock_sock() block and the if (len > 0)
  layout that this patch rewrites.

  "net/smc: order the urgent mark across the cursor wrap rollover" adds
  the smc_curs_sdiff(...) > 1 test that this patch changes to > 0.

At the baseline, smc_curs_sdiff() does not exist anywhere in net/smc/.

The cursor wrap patch already marks its own dependencies with
"Cc: stable@vger.kernel.org # depends on 2/7 and 4/7". Could this patch
carry a similar note? Without one, anyone who backports it alone based on
the Fixes: tag will hit a context conflict and won't know which patches
to take first.

> diff --git a/net/smc/smc_rx.c b/net/smc/smc_rx.c
> index 2680b91e882b9..579ee008900ce 100644
> --- a/net/smc/smc_rx.c
> +++ b/net/smc/smc_rx.c
> @@ -342,12 +342,14 @@ static int smc_rx_recv_urg(struct smc_sock *smc, struct msghdr *msg, int len,
>  	valid = conn->urg_state == SMC_URG_VALID;
>  	if (valid) {
>  		byte = conn->urg_rx_byte;
> -		if (len > 0) {
> -			smc_curs_copy(&cons, &conn->local_tx_ctrl.cons, conn);
> -			if (smc_curs_sdiff(conn->rmb_desc->len, &cons,
> -					   &conn->urg_curs) > 1)
> -				conn->urg_rx_skip_pend = true;
> -		}
> +		/* The reader has not passed the urgent byte: have
> +		 * smc_rx_update_consumer() skip it once it is the next
> +		 * unread byte.
> +		 */
> +		smc_curs_copy(&cons, &conn->local_tx_ctrl.cons, conn);
> +		if (smc_curs_sdiff(conn->rmb_desc->len, &cons,
> +				   &conn->urg_curs) > 0)
> +			conn->urg_rx_skip_pend = true;

[Severity: Low]
This isn't a bug, but should the comment on urg_rx_skip_pend in struct
smc_connection in net/smc/smc.h be updated as well? It still reads:

	bool			urg_rx_skip_pend;
					/* indicate urgent oob data
					 * read, but previous regular
					 * data still pending
					 */

With the old > 1 test, the flag meant at least one regular byte was in
front of the urgent byte, which matched that comment.

With the new > 0 test, which no longer depends on len, the flag is also
set when sdiff == 1. In that case the urgent byte is itself the next
unread byte and no regular data is pending, for example after
recv(MSG_OOB|MSG_PEEK) at the mark.

The SIOCATMARK handling in af_smc.c checks urg_rx_skip_pend together with
sdiff == 1, and smc_rx_update_consumer() is gated on the flag. From the
smc.h text, someone could conclude that this combination cannot occur,
but after this patch it happens routinely.

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261203-b4-disp-ba1ad55e-v3-0-6834ff90c5d0%40proton.me

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2026-12-04  9:49 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03  9:15 [PATCH net v3 0/7] net/smc: fix the failover cursor switch and wrap rollover Bryam Vargas via B4 Relay
2026-12-03  9:15 ` [PATCH net v3 1/7] net/smc: take the socket spinlock across the failover cursor switch Bryam Vargas via B4 Relay
2026-12-03  9:15 ` [PATCH net v3 2/7] net/smc: do not credit stale CDC completions after a link switch Bryam Vargas via B4 Relay
2026-12-04  9:15   ` sashiko-bot
2026-12-04  9:49   ` netdev-bot+sashiko
2026-12-03  9:15 ` [PATCH net v3 3/7] net/smc: store each cursor once in smc_switch_cursor() Bryam Vargas via B4 Relay
2026-12-04  9:15   ` sashiko-bot
2026-12-03  9:15 ` [PATCH net v3 4/7] net/smc: fix the failover catch-up across the cursor wrap rollover Bryam Vargas via B4 Relay
2026-12-04  9:15   ` sashiko-bot
2026-12-03  9:15 ` [PATCH net v3 5/7] net/smc: order the urgent mark " Bryam Vargas via B4 Relay
2026-12-04  9:15   ` sashiko-bot
2026-12-03  9:15 ` [PATCH net v3 6/7] net/smc: update the urgent state under the socket spinlock Bryam Vargas via B4 Relay
2026-12-04  9:15   ` sashiko-bot
2026-12-04  9:49   ` netdev-bot+sashiko
2026-12-03  9:15 ` [PATCH net v3 7/7] net/smc: skip the urgent byte when it is the next unread byte Bryam Vargas via B4 Relay
2026-12-04  9:49   ` netdev-bot+sashiko
2026-12-04  9:15 ` [PATCH net v3 0/7] net/smc: fix the failover cursor switch and wrap rollover sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox