Re: [PATCH net v2 2/2] net/smc: bound the DMB-nocopy send-buffer credit as well
From: Piyus Kedia
Date: Tue Nov 24 2026 - 13:03:58 EST
Thank you - both of these were worth the mail. The first changed the patch:
the bound is now the one you suggest. The second is pre-existing, as you
say, and I have answered its two questions below rather than fold an
unrelated counter into this one.
v3 of this patch is posted as a separate thread:
[PATCH net v3] net/smc: bound the DMB-nocopy send-buffer credit by what
was sent
Each patch of the v2 series drew its own review, so each is respun in its own
thread; the other one is answered where it was reviewed. The v3 changelog is
under the --- line with a Link: back to the v2 posting.
1. Is len - sndbuf_space the right bound here?
> The peer can only consume up to the producer cursor it was given.
> smc_tx_rdma_writes() advances that cursor together with tx_curs_sent. A
> consumer cursor that claims more than tx_curs_sent is therefore clamped
> only to prep - fin. The smc_curs_add() above can then move tx_curs_fin
> past tx_curs_sent.
> Would that break the fin <= sent <= prep ordering implied by the
> tx_curs_sent ("sent data") and tx_curs_fin ("confirmed by peer") field
> comments in smc.h?
It is not the right bound, and yes it would. The ordering is what those
comments say:
union smc_host_cursor tx_curs_prep; /* tx - prepared data */
union smc_host_cursor tx_curs_sent; /* tx - sent data */
union smc_host_cursor tx_curs_fin; /* tx - confirmed by peer */
and nothing else in this branch moves tx_curs_sent, so the clamp was the only
thing standing between a forged cursor and fin > sent. Your consequence
follows too: once fin is past sent, a later smc_tx_sendmsg() can wrap out of
tx_curs_prep into [tx_curs_sent, tx_curs_prep) and overwrite data that has
been queued but not yet advertised - on this path, in the peer's DMB.
v3 uses the bound you give:
unconfirmed = smc_curs_diff(conn->sndbuf_desc->len,
&conn->tx_curs_fin, &conn->tx_curs_sent);
diff_tx = min_t(int, diff_tx, unconfirmed);
The honest-peer case is unchanged: a cursor that reflects real consumption
cannot be past the producer cursor the peer was given, so it is at most
tx_curs_sent and the bound does not bind. smc_curs_diff() already returns 0
rather than a negative value, so the max_t() that guarded the subtraction is
gone with it. The variable is no longer called "sent", and neither the
comment nor the commit message says "outstanding" any more - as you note,
that described a tighter bound than the code computed.
Your reading of smc_switch_cursor() is right as well: it rewinds tx_curs_sent
to tx_curs_fin and then advances both, so the order holds there even with the
longer distance. That patch has a review of its own and v3 of it stops
clamping altogether - a cursor that claims more than was prepared is treated
as a protocol violation and the connection is dropped - so the two patches no
longer share a formula.
2. peer_rmbe_space is credited with no bound (pre-existing)
> With a forged cursor, can peer_rmbe_space exceed peer_rmbe_size here?
> That would make the comment false.
Yes. diff_cons is bounded only by peer_rmbe_size, since that is the size
passed to smc_curs_diff(); the atomic_add() applies no clamp, and the only
thing that lowers peer_rmbe_space is smc_tx_rdma_writes() as it writes. So a
cursor that reports consumption this side never produced raises it without
limit, and the "guarantee 0 <= peer_rmbe_space <= peer_rmbe_size" above it is
not a guarantee. It runs for every SMC-R and SMC-D connection, as you say,
not only the nocopy ones.
> Would an inflated peer_rmbe_space mean the urgent data sender is never
> woken through that path?
Through that path, yes. The wake-up tests equality:
if (diff_cons && conn->urg_tx_pend &&
atomic_read(&conn->peer_rmbe_space) == conn->peer_rmbe_size) {
so while the counter sits above peer_rmbe_size the test cannot become true
and urg_tx_pend stays set. I have not traced whether another route clears it
in practice, so I would not claim more than that the condition here can no
longer be met.
And your point that the two counters can now disagree is fair: after this
patch sndbuf_space and tx_curs_fin are bounded while peer_rmbe_space still
takes the full diff_cons, and the comment above the nocopy branch does speak
of both being updated because "peer has already consumed the data".
I have left it out of this patch rather than fixed it quietly. It is a
different counter with a different Fixes: tag, it is not confined to the
loopback-only branch this patch is about, and the natural bound is a
different quantity - the distance from cons_old to the producer cursor the
peer has actually been given, rather than anything derived from the send
buffer. Getting that wrong would stall flow control on every connection, and
we have no SMC-R setup here to exercise it on; the route to this patch's
branch is loopback-ism, which is why this one is hardening rather than a fix.
So I would rather post it on its own, or leave it to the SMC maintainers if
they would prefer to take it. Either way it should not be lost - it is the
same class of bug on a path that every connection uses.