* [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
` (5 subsequent siblings)
6 siblings, 0 replies; 11+ 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] 11+ 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: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
` (4 subsequent siblings)
6 siblings, 1 reply; 11+ 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] 11+ 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:49 ` netdev-bot+sashiko
0 siblings, 0 replies; 11+ 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] 11+ 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-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
` (3 subsequent siblings)
6 siblings, 0 replies; 11+ 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] 11+ 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-03 9:15 ` [PATCH net v3 5/7] net/smc: order the urgent mark " Bryam Vargas via B4 Relay
` (2 subsequent siblings)
6 siblings, 0 replies; 11+ 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] 11+ 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-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 ` [PATCH net v3 7/7] net/smc: skip the urgent byte when it is the next unread byte Bryam Vargas via B4 Relay
6 siblings, 0 replies; 11+ 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] 11+ 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: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
6 siblings, 1 reply; 11+ 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] 11+ 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:49 ` netdev-bot+sashiko
0 siblings, 0 replies; 11+ 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] 11+ 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
6 siblings, 1 reply; 11+ 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] 11+ 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; 11+ 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] 11+ messages in thread