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. The switch's 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. A connection in
SMC_APPCLOSEWAIT1, where data can still be sent, is moved to the new
link without a resend and without a failover validation message.
1/8 takes the socket spinlock around the switch. 2/8 tags each CDC pend
with a switch generation. It credits a completion only if the completion
is from the current generation and its cursor is not behind tx_curs_fin;
both checks rely on 1/8's lock. 3/8 makes the switch work on copies of
the cursors and store each one once. 4/8 computes the catch-up from the
signed cursor distance, bounds it by tx_curs_prep and advances the RMB
cursors across wraps. 5/8 uses the signed distance for the urgent mark,
in SIOCATMARK too, and makes SIOCATMARK test the urgent state. 6/8 takes
the socket spinlock around the reader's two test-and-set sequences on
the urgent state and around SIOCATMARK. 7/8 lets recv(MSG_OOB) skip the
urgent byte when it is the next unread byte. 8/8 switches a connection
in SMC_APPCLOSEWAIT1 like one in SMC_ACTIVE. From 2/8 to 7/8, each patch
needs the ones before it; 8/8 needs 2/8.
For SMC_APPCLOSEWAIT1, 8/8 answers Sidraya's question on v2 [2]. The
AI review of v3 [3] showed what goes wrong in that state with 2/8 alone:
a late old-link completion is credited once tx_curs_fin is more than
32768 wraps ahead of its cursor. As with SMC_ACTIVE, the switch can now
wait for a free slot after it drops conns_lock, and fails if none is
free in time. While the link group is listed, a close() that meanwhile
frees the connection waits in smcr_buf_unuse(). It waits there for the
LLC flow that the switch runs in, if any, and for llc_conf_mutex. Every
caller of smc_switch_conns() holds llc_conf_mutex.
Tested like v3 [4], on the same 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. No KASAN report or WARN in any run
below with v4.
New in v4:
- 8/8, data in flight: the server in SMC_APPCLOSEWAIT1 (the client
has called shutdown(SHUT_WR) and keeps reading), 8192 bytes of its
writes flushed with an error on the failing link, then the rest of
its stream. On net, with v3 and with v4 without 8/8, the stream the
client reads breaks at the first flushed byte. With v4 it arrives
intact and a validation message is sent. With both sides in
SMC_ACTIVE, it arrives intact on v3 and v4.
- 8/8, the case in [3]: the same state with a 16 KiB send buffer and
RMB, one old-link completion held at the failover, then 32770 send
buffers' worth of data sent and read on the new link, then the held
completion handed back with success, then one send() of as many bytes
as sndbuf_space says. On net, with v3 and with v4 without 8/8, the
completion is credited, sndbuf_space reads 32768, and that send()
copies past the end of the send buffer: with vmalloc'ed buffers, the
copy stops at the guard page and the send() continues. With v4
nothing is credited and the stream arrives intact. With 32768 in place
of 32770, v3 and v4 credit nothing, while net does.
- 8/8, the whole send buffer in flight on the failing link, its
completions held and handed back with success: the stream completes
on v3, on v4 and on v4 without 8/8.
- 8/8, close() during the switch: the server in SMC_APPCLOSEWAIT1 after
the client's close(), the switch held for 2 s right after it drops
conns_lock, and the server's close() called during the hold. The
close() returns only after the hold ends, the switch moves the
connection before it is freed, and each link's conn_cnt matches its
connections. With a test build whose smc_conn_free() skips
smc_buf_unuse(), the connection is freed first and the switch then
counts it on the new link.
- 3/8: two failovers, the first one's resend held, the peer reading in
between, a pause right after the credit to sndbuf_space in
smc_switch_cursor() and a send() during it. With v3's order,
tx_curs_prep gets 69536 bytes ahead of tx_curs_sent with a 64 KiB send
buffer; with v4's, 65536 at most.
- 4/8: local_tx_ctrl_fin.count set to 2^32 - 4096 just before the
switch, with a 128 KiB peer RMB and the peer's consumer cursor 8192
bytes past it. With v3, the wrap after the switch is wrong; with v4,
it matches the 64-bit result.
- 6/8, SIOCATMARK: the reader on the last byte of wrap 65535 with no
urgent data so far, a pause between SIOCATMARK's copy of urg_curs and
its test of urg_state, and the peer's urgent byte, 100 bytes further
on, received during the pause. v3, and v4 without the new lock,
return 1; v4 returns 0 because the receive handler waits for the
lock. With no urgent byte sent, all three return 0.
- 6/8, two stress tests with 20000 urgent bytes, each after 32 bytes of
data: in one, a thread calls SIOCATMARK in a loop while another reads;
in the other, the reader runs alone, one byte per recv(). No
SIOCATMARK call fails. With the reader alone, the data arrives in
order, without the urgent bytes. With the SIOCATMARK thread, the data
arrives the same way when the reader waits in poll(). That reader ran
only on the KCSAN build below. With the SIOCATMARK thread and a reader
that waits in recv(), both runs stalled on the lone urgent byte
described under "Not fixed here".
Run again with v4: 40 tests from v2 and v3, with the same results as
v3 had (as v2 had, for the tests without a v3 result).
On a PROVE_LOCKING build of the same kernel, there is no lockdep report
with v4 in these tests: the failover test, the SMC_APPCLOSEWAIT1 tests
with data in flight and with a held completion, the SIOCATMARK pause
test, the SIOCATMARK test with a skip pending, 6/8's test with a second
urgent byte arriving during recv(MSG_OOB), and 8/8's close() test.
Without the BH disable in SIOCATMARK, lockdep reports an inconsistent
lock state.
On a KCSAN build of the same kernel, with a reader that waits in poll()
instead of in recv(), 6/8's two stress tests give no KCSAN report on
urg_state with v4. Without 6/8's READ_ONCE() and WRITE_ONCE(), both do.
The series is on net and does not depend on the CDC cursor bounds
series [1], which is marked "changes requested". 1/8, 2/8 and
5/8 to 8/8 apply on top of [1] as they are. 3/8 and 4/8 rewrite the
block of smc_switch_cursor() that [1] 6/6 changes. They replace that
change and keep its 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. The peer's reader then gets wrong data, as on net. See v3 [4].
- 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
the RMB and is refused, and the link group is terminated ([1] 5/6
keeps that write inside the RMB).
- The other closing states: SMC_PEERCLOSEWAIT1/2, SMC_APPCLOSEWAIT2,
SMC_APPFINCLOSEWAIT and SMC_PEERFINCLOSEWAIT. smc_sendmsg() takes no
data there, but the close waits only until the last writes are posted,
so they and the close CDC can still be in flight when the link fails.
They are not sent again. Tested with the server's last 8192 bytes and
its shutdown(SHUT_WR) flushed on the failing link, in
SMC_PEERCLOSEWAIT1, SMC_PEERCLOSEWAIT2 and SMC_APPCLOSEWAIT2: on net,
with v3 and with v4, the client gets the bytes before them and then
times out without EOF. The same test without a failover ends with all
bytes and EOF.
- SIOCATMARK once the reader has read up to the urgent byte: 0 on net
and with the series, 1 on TCP. See v3 [4].
- SO_OOBINLINE switched on between recv(MSG_OOB) and the read that
reaches the urgent byte: the byte is never skipped and the sender's
next send() times out, on net and with the series.
- A reader can sleep through a lone urgent byte: smc_rx_recvmsg()
skips an urgent byte with no data after it only before the wait, and
the wait does not count a valid mark. A byte wakes nobody if it
arrives between the skip and the wait; the byte is not skipped and
both sides wait until their timeouts. Seen in some runs of the stress
tests above, on net and with the series; other runs complete.
Test patch and logs on request.
v4:
- 8/8: new [2], [3].
- 2/8: the comments above smc_curs_sdiff() and in smc_cdc_tx_handler()
reworded.
- 3/8: the credit to sndbuf_space comes after the stores of
tx_curs_sent and local_tx_ctrl.prod [3].
- 4/8: smc_curs_advance() adds in 64 bits [3].
- 5/8: the stable note names the two patches it needs; one sentence
about SIOCATMARK made exact.
- 6/8: SIOCATMARK reads the mark and its state under the socket
spinlock [3]. READ_ONCE() for the reads of urg_state outside the
spinlock, WRITE_ONCE() for the writes they can race with [3].
- Commit messages of 2/8, 4/8, 5/8 and 6/8 reworded.
- Reviewed-by dropped from 3/8, 4/8 and 6/8, whose code changed; kept
on 1/8. Reported-by lines for the AI review dropped; its Closes:
links stay.
- On net c1c39137dcc3, like v3.
v3: https://lore.kernel.org/all/2026…@proton.me/
v2: https://lore.kernel.org/all/2026…@proton.me/
v1: https://lore.kernel.org/all/2026…@proton.me/
[1] https://lore.kernel.org/all/2026…@proton.me/
[2] https://lore.kernel.org/all/9814…@linux.ibm.com/
[3] https://lore.kernel.org/all/sash…@kernel.org/
[4] https://lore.kernel.org/all/2026…@proton.me/
---
Bryam Vargas (8):
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: switch the cursors of a connection in SMC_APPCLOSEWAIT1
net/smc/af_smc.c | 16 +++++--
net/smc/smc.h | 3 ++
net/smc/smc_cdc.c | 15 +++++--
net/smc/smc_cdc.h | 30 +++++++++----
net/smc/smc_core.c | 70 +++++++++++++++++++----------
net/smc/smc_rx.c | 126 ++++++++++++++++++++++++++++++++---------------------
6 files changed, 172 insertions(+), 88 deletions(-)
---
base-commit: c1c39137dcc3134010566ff29a81c93124efa539
change-id: 20261206-b4-disp-7aa83bc6-2a301bf2d735
Best regards,
--
Bryam Vargas <hexl…@proton.me>
[PATCH net v4 0/8] net/smc: fix the failover cursor switch and wrap rollover
- From
- devn…@kernel.org (Bryam Vargas via B4 Relay)
- Organization
- Usenet Network
- Message-ID
- <2026…@proton.me>
- Date
- Newsgroups
- linux.kernel.netdev