Re: [PATCH net v2 1/2] net/smc: bound the failover cursor catch-up by what is outstanding

From: Piyus Kedia

Date: Tue Nov 24 2026 - 12:31:43 EST


Thank you for the review. All three points were checked against net.git at
af6737b90668 before answering, and two of them changed the patch rather than
its wording: the clamp is gone, and v3 drops the connection instead. The
third is real but is a pre-existing bug independent of this patch, and I
would rather not fix it blind alongside it - details below.

v3 of this patch is posted as a separate thread:

[PATCH net v3] net/smc: drop the connection when the peer's failover
cursor is impossible

Only this patch is respun; 2/2 of the v2 series is unchanged and is being
answered separately. The v3 changelog is under the --- line with a Link:
back to the v2 posting.

Point by point.


1. [High] Old-link CDC completions racing the switch

> Does this bound keep sndbuf_space <= sndbuf_desc->len on the DELETE_LINK
> path, given that the old link's CDC completions can still run?
> Do the old link's TX completions also need to be quiesced or serialized
> with the switch?

No, it does not, and yes, they do. The locking is exactly as you describe:

smc_switch_conns()
spin_lock_bh(&conn->send_lock);
smc_switch_cursor()
atomic_add(diff, &conn->sndbuf_space);
smc_curs_add(len, &conn->tx_curs_fin, diff);

smc_cdc_tx_handler()
bh_lock_sock(&smc->sk);
atomic_add(diff, &conn->sndbuf_space);
smc_curs_copy(&conn->tx_curs_fin, &cdcpend->cursor, conn);

Two writers of sndbuf_space and of tx_curs_fin, under two different locks,
with no lock in common. That is true before this patch as well: the
unpatched smc_switch_cursor() performs the same atomic_add() and the same
tx_curs_fin advance under send_lock alone. The late-completion arithmetic
you give - (len - prep.count) + C.count exceeding len when the wraps differ -
is likewise reachable without the patch, since the unpatched code moves
tx_curs_fin by an unbounded diff and so can place it at or beyond prep. So
this is a second bug on the same path, not a consequence of the change.

What this patch is for is the route that needs no race at all: a forged
cons on an otherwise quiet connection inflates the credit deterministically.
v3 closes that by dropping the connection rather than crediting anything.

On the race itself, the shape of the fix looks like the drain, not a new
lock: smc_cdc_wait_pend_tx_wr(conn) in smc_switch_conns() before the
send_lock is taken, in the region whose comment already says it may sleep
("pre-fetch buffer outside of send_lock, might sleep"). I have not put it
in this series for two reasons.

- It is a different bug with a different Fixes: tag and a different
trigger - it needs a completion to land in the window, not a hostile
cursor - and netdev asks for one logical change per patch.

- I cannot test it, and I think it may be wrong as stated.
smc_cdc_wait_pend_tx_wr() waits for conn->cdc_pend_tx_wr to reach zero.
On the smcr_link_down() path into smc_switch_conns() the old QP may
already be dead, and those completions arrive only once the QP is moved
to error and flushed in smcr_link_clear(), which happens after the
switch. A drain there would then stall on exactly the path it is meant
to protect. Ignoring completions whose cursor is behind tx_curs_fin,
your second suggestion, has no such problem, but it changes the meaning
of a counter three call sites rely on.

We have no multi-link SMC-R group with two RDMA devices here - the route to
smc_switch_cursor() in this patch comes from reading the code, as the commit
message says - so I would be shipping an untested locking change bundled
with a memory-safety fix. I am happy to post it separately if the drain is
the right shape, or to leave it to the SMC maintainers, who can exercise
failover. Either way it should be recorded; it is a real hole.


2. [Low] "sent" is the wrong name for sndbuf_desc->len - sndbuf_space

> Is sent the right name for this value? Does "what this side has
> outstanding" in the comment describe it accurately?

It is not, and it does not. The value is tx_curs_prep - tx_curs_fin -
prepared and not yet confirmed - because smc_tx_sendmsg() lowers
sndbuf_space when data is copied in, not when it is RDMA-written. v3 names
it unconfirmed and says so:

/* ... It cannot honestly exceed what this side has prepared and not yet
* had confirmed, which is sndbuf_desc->len - sndbuf_space:
* smc_tx_sendmsg() lowers sndbuf_space as data is copied in, and
* smc_cdc_tx_handler() raises it again as the peer confirms. ... */

The subject and the commit message no longer claim to bound the catch-up by
"what is outstanding" either.

Your related observation is also right and is why v3 stops trying to repair
the state: smc_switch_cursor() opens with

smc_curs_copy(&conn->tx_curs_sent, &conn->tx_curs_fin, conn);

so the pre-switch send position is already gone by the time the check runs.
There is nothing reliable left to rebuild a correct cursor from, which makes
"carry on with a smaller number" the wrong answer in principle. And you are
right that the clamp hid the violation: out_of_sync stayed 0 and the
connection was not aborted. v3 sets out_of_sync and peer_conn_abort and
queues abort_work, as smc_cdc_msg_validate() does for a sequence number
that cannot be honest.


3. [Low] Where local_tx_ctrl.prod ends up when the clamp fires

> Should the clamp firing be treated as a protocol violation that aborts the
> connection, rather than continuing with inconsistent flow-control state?

Yes. This is the point that replaced the patch, and the arithmetic holds as
you give it. With diff clamped, prod = fin + clamped_diff stays behind cons,
which is the inversion the "now prod is smaller than cons. Fix that." comment
exists to repair. smc_write_space() then computes

space = peer_rmbe_size - smc_curs_diff(peer_rmbe_size, &cons, &prod);

over that inverted pair. Equal wraps give 0, so space becomes the whole
buffer - wrong, but harmless. cons.wrap == prod.wrap + 1 gives
(size - cons.count) + prod.count: for size 100, prod (0,90) and cons (1,10),
space = 100 - 180 = -80. smc_tx_rdma_writes() returns early on

if (rmbespace <= 0) {

for every later call, and smc_cdc_msg_recv_action() only adds diff_cons on
top of that base, so it never recovers. The clamp traded an out-of-bounds
write for a connection that is memory-safe and permanently mute.

v3 therefore drops the connection and leaves every cursor alone. There is
no partially-advanced state to be inconsistent, nothing to name wrongly, and
for a correct peer the branch is not reached at all.


Thanks again - two of these were defects in the patch, and the third is a
bug in the path that was there before it.

pw-bot: cr