* [PATCH net v2 1/6] net/smc: take the socket spinlock across the failover cursor switch
2026-11-28 14:23 [PATCH net v2 0/6] net/smc: fix the failover cursor switch and wrap rollover Bryam Vargas via B4 Relay
@ 2026-11-28 14:23 ` Bryam Vargas via B4 Relay
2026-11-28 14:23 ` [PATCH net v2 2/6] net/smc: do not credit stale CDC completions after a link switch Bryam Vargas via B4 Relay
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Bryam Vargas via B4 Relay @ 2026-11-28 14:23 UTC (permalink / raw)
To: Mahanta Jambigi, D. Wythe, Eric Dumazet, David S. Miller,
Sidraya Jayagond, Paolo Abeni, Jakub Kicinski, Dust Li
Cc: Stefan Raspl, Simon Horman, Guangguan Wang, Wen Gu, linux-s390,
linux-rdma, netdev, linux-kernel, Tony Lu, Ursula Braun,
Hidayath Khan, Wenjia Zhang
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
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] 8+ messages in thread* [PATCH net v2 2/6] net/smc: do not credit stale CDC completions after a link switch
2026-11-28 14:23 [PATCH net v2 0/6] net/smc: fix the failover cursor switch and wrap rollover Bryam Vargas via B4 Relay
2026-11-28 14:23 ` [PATCH net v2 1/6] net/smc: take the socket spinlock across the failover cursor switch Bryam Vargas via B4 Relay
@ 2026-11-28 14:23 ` Bryam Vargas via B4 Relay
2026-11-28 14:23 ` [PATCH net v2 3/6] net/smc: store each cursor once in smc_switch_cursor() Bryam Vargas via B4 Relay
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Bryam Vargas via B4 Relay @ 2026-11-28 14:23 UTC (permalink / raw)
To: Mahanta Jambigi, D. Wythe, Eric Dumazet, David S. Miller,
Sidraya Jayagond, Paolo Abeni, Jakub Kicinski, Dust Li
Cc: Stefan Raspl, Simon Horman, Guangguan Wang, Wen Gu, linux-s390,
linux-rdma, netdev, linux-kernel, Tony Lu, Ursula Braun,
Hidayath Khan, Wenjia Zhang
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] 8+ messages in thread* [PATCH net v2 3/6] net/smc: store each cursor once in smc_switch_cursor()
2026-11-28 14:23 [PATCH net v2 0/6] net/smc: fix the failover cursor switch and wrap rollover Bryam Vargas via B4 Relay
2026-11-28 14:23 ` [PATCH net v2 1/6] net/smc: take the socket spinlock across the failover cursor switch Bryam Vargas via B4 Relay
2026-11-28 14:23 ` [PATCH net v2 2/6] net/smc: do not credit stale CDC completions after a link switch Bryam Vargas via B4 Relay
@ 2026-11-28 14:23 ` Bryam Vargas via B4 Relay
2026-11-28 14:23 ` [PATCH net v2 4/6] net/smc: fix the failover catch-up across the cursor wrap rollover Bryam Vargas via B4 Relay
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Bryam Vargas via B4 Relay @ 2026-11-28 14:23 UTC (permalink / raw)
To: Mahanta Jambigi, D. Wythe, Eric Dumazet, David S. Miller,
Sidraya Jayagond, Paolo Abeni, Jakub Kicinski, Dust Li
Cc: Stefan Raspl, Simon Horman, Guangguan Wang, Wen Gu, linux-s390,
linux-rdma, netdev, linux-kernel, Tony Lu, Ursula Braun,
Hidayath Khan, Wenjia Zhang
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
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] 8+ messages in thread* [PATCH net v2 4/6] net/smc: fix the failover catch-up across the cursor wrap rollover
2026-11-28 14:23 [PATCH net v2 0/6] net/smc: fix the failover cursor switch and wrap rollover Bryam Vargas via B4 Relay
` (2 preceding siblings ...)
2026-11-28 14:23 ` [PATCH net v2 3/6] net/smc: store each cursor once in smc_switch_cursor() Bryam Vargas via B4 Relay
@ 2026-11-28 14:23 ` Bryam Vargas via B4 Relay
2026-11-28 14:23 ` [PATCH net v2 5/6] net/smc: order the urgent mark " Bryam Vargas via B4 Relay
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Bryam Vargas via B4 Relay @ 2026-11-28 14:23 UTC (permalink / raw)
To: Mahanta Jambigi, D. Wythe, Eric Dumazet, David S. Miller,
Sidraya Jayagond, Paolo Abeni, Jakub Kicinski, Dust Li
Cc: Stefan Raspl, Simon Horman, Guangguan Wang, Wen Gu, linux-s390,
linux-rdma, netdev, linux-kernel, Tony Lu, Ursula Braun,
Hidayath Khan, Wenjia Zhang
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
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] 8+ messages in thread* [PATCH net v2 5/6] net/smc: order the urgent mark across the cursor wrap rollover
2026-11-28 14:23 [PATCH net v2 0/6] net/smc: fix the failover cursor switch and wrap rollover Bryam Vargas via B4 Relay
` (3 preceding siblings ...)
2026-11-28 14:23 ` [PATCH net v2 4/6] net/smc: fix the failover catch-up across the cursor wrap rollover Bryam Vargas via B4 Relay
@ 2026-11-28 14:23 ` Bryam Vargas via B4 Relay
2026-11-28 14:23 ` [PATCH net v2 6/6] net/smc: update the urgent state under the socket spinlock Bryam Vargas via B4 Relay
2026-11-28 14:43 ` [PATCH net v2 0/6] net/smc: fix the failover cursor switch and wrap rollover sashiko-bot
6 siblings, 0 replies; 8+ messages in thread
From: Bryam Vargas via B4 Relay @ 2026-11-28 14:23 UTC (permalink / raw)
To: Mahanta Jambigi, D. Wythe, Eric Dumazet, David S. Miller,
Sidraya Jayagond, Paolo Abeni, Jakub Kicinski, Dust Li
Cc: Stefan Raspl, Simon Horman, Guangguan Wang, Wen Gu, linux-s390,
linux-rdma, netdev, linux-kernel, Tony Lu, Ursula Braun,
Hidayath Khan, Wenjia Zhang
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.
Use smc_curs_sdiff() in both, which orders the two cursors whatever
their wraps. smc_curs_comp() has no other user; remove it.
Fixes: de8474eb9d50 ("net/smc: urgent data support")
Cc: stable@vger.kernel.org
Signed-off-by: Bryam Vargas <hexlabsecurity@proton.me>
---
net/smc/smc_cdc.h | 13 -------------
net/smc/smc_rx.c | 11 ++++++-----
2 files changed, 6 insertions(+), 18 deletions(-)
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] 8+ messages in thread* [PATCH net v2 6/6] net/smc: update the urgent state under the socket spinlock
2026-11-28 14:23 [PATCH net v2 0/6] net/smc: fix the failover cursor switch and wrap rollover Bryam Vargas via B4 Relay
` (4 preceding siblings ...)
2026-11-28 14:23 ` [PATCH net v2 5/6] net/smc: order the urgent mark " Bryam Vargas via B4 Relay
@ 2026-11-28 14:23 ` Bryam Vargas via B4 Relay
2026-11-28 14:43 ` [PATCH net v2 0/6] net/smc: fix the failover cursor switch and wrap rollover sashiko-bot
6 siblings, 0 replies; 8+ messages in thread
From: Bryam Vargas via B4 Relay @ 2026-11-28 14:23 UTC (permalink / raw)
To: Mahanta Jambigi, D. Wythe, Eric Dumazet, David S. Miller,
Sidraya Jayagond, Paolo Abeni, Jakub Kicinski, Dust Li
Cc: Stefan Raspl, Simon Horman, Guangguan Wang, Wen Gu, linux-s390,
linux-rdma, netdev, linux-kernel, Tony Lu, Ursula Braun,
Hidayath Khan, Wenjia Zhang
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
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] 8+ messages in thread* Re: [PATCH net v2 0/6] net/smc: fix the failover cursor switch and wrap rollover
2026-11-28 14:23 [PATCH net v2 0/6] net/smc: fix the failover cursor switch and wrap rollover Bryam Vargas via B4 Relay
` (5 preceding siblings ...)
2026-11-28 14:23 ` [PATCH net v2 6/6] net/smc: update the urgent state under the socket spinlock Bryam Vargas via B4 Relay
@ 2026-11-28 14:43 ` sashiko-bot
6 siblings, 0 replies; 8+ messages in thread
From: sashiko-bot @ 2026-11-28 14:43 UTC (permalink / raw)
To: Bryam Vargas
Cc: linux-s390, linux-rdma, Heiko Carstens, Vasily Gorbik,
Alexander Gordeev, Christian Borntraeger
Sashiko has reviewed this 6-patch series and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261128-b4-disp-360e65c5-v2-0-d9c05004d430@proton.me
^ permalink raw reply [flat|nested] 8+ messages in thread