[PATCH net v3 0/7] net/smc: fix the failover cursor switch and wrap rollover
From: Bryam Vargas via B4 Relay
Date: Thu Dec 03 2026 - 04:16:58 EST
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@xxxxxxxxx/
v1: https://lore.kernel.org/all/20261113-b4-disp-1a9ab9b0-v1-0-4a7c8d85d849@xxxxxxxxx/
[1] https://lore.kernel.org/all/20261112-b4-disp-0287c16e-v9-0-e5e8fa688177@xxxxxxxxx/
[2] https://lore.kernel.org/all/9de0921d-d01c-4cae-8ec2-7d86a3c3f438@xxxxxxxxxxxxx/
[3] https://lore.kernel.org/all/cba71de0-4d7e-4bb2-8e08-ed7ecf0883f4@xxxxxxxxxxxxx/
[4] https://lore.kernel.org/all/9814c137-6b38-40c0-839b-107877f4ef66@xxxxxxxxxxxxx/
[5] https://lore.kernel.org/all/20261128-b4-disp-360e65c5-v2-0-d9c05004d430@xxxxxxxxx/
---
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@xxxxxxxxx>