Re: [PATCH net v3] net/smc: bound the DMB-nocopy send-buffer credit by what was sent

From: Piyus Kedia

Date: Thu Nov 26 2026 - 10:07:03 EST


Thank you - the finding is right on both halves, and the remedy is the one
you name. v4 is posted separately.

[Medium] torn cursor read and non-atomic update in
smc_cdc_msg_recv_action()

Confirmed. smc_curs_diff() reads wrap and count with plain loads:

if (old->wrap != new->wrap)
return max_t(int, 0, ((size - old->count) + new->count));

and this path runs in a tasklet under bh_lock_sock(), which does not
exclude smc_tx_rdma_writes() advancing conn->tx_curs_sent under
conn->send_lock. So passing &conn->tx_curs_sent in place can pair a
pre-wrap wrap with a post-wrap count, exactly as your interleaving shows.
Both outcomes you describe follow: the difference collapses to zero and
the credit is lost after local_rx_ctrl.cons has already moved, or it
exceeds sndbuf_desc->len and the bound does nothing.

The second half is right as well. smc_curs_add() is

curs->count += value;
if (curs->count >= size) {
curs->wrap++;
curs->count -= size;
}

so in place it sets count and then wrap with plain stores and transiently
leaves count >= sndbuf_desc->len, where the code it replaced wrote the
cursor with a single atomic64 store through smc_curs_copy().

v4 does what you suggest, and what smc_tx_prepared_sends() already does
here: it snapshots both cursors with smc_curs_copy(), computes both
differences from the snapshots, advances the local copy of tx_curs_fin and
writes it back with smc_curs_copy(). The cursor update is one atomic
64-bit write again and neither read can tear.

One note for the record: the torn read is not only in the line v3 added.
The diff_tx computation read &conn->tx_curs_fin in place before this
series, and the snapshot closes that too.

What is bounded, and the bound itself, are unchanged from v3.

Tested on 7.3.1 with KASAN; net/smc/smc_cdc.o builds clean at W=1.

pw-bot: cr