net/smc: set the lkey of every SGE in smcr_tx_rdma_writes()
Subsystems (5)
PATCH 1/1 net/smc: set the lkey of every SGE in smcr_tx_rdma_writes()
smcr_tx_rdma_writes() sets the lkey of an SGE only for a virtually contiguous send buffer; for a physically contiguous one it leaves the lkey the work request slot already holds. With net.smc.smcr_buf_type=2 a send buffer falls back to vzalloc() when alloc_pages() fails, so one link carries both kinds, and a slot last used by a virtually contiguous buffer posts the DMA address of a physically contiguous one under the earlier buffer's MR lkey. That write fails, the link goes down and, with no link to switch to, the link group is terminated with all of its connections.
Set the lkey on both branches: the MR's for a virtually contiguous buffer, local_dma_lkey otherwise.
---
Repro on SMC-Rv2 with soft-RoCE (rxe) over a veth pair between two namespaces, one link, 64 KiB send buffers; smc.ko built from the base-commit below, with and without the patch, on a v7.4-rc2 KASAN kernel. smcr_buf_type=2 is set in init_net, where the rxe devices are. A test-only knob in smc.ko fails alloc_pages() for the server's first send buffer, so connection A gets a virtually contiguous send buffer and connection B a physically contiguous one. The server sends 1 MiB on A, then 1 MiB on B, in 16 KiB writes.
Unpatched, B's first RDMA write is posted with the lkey of A's MR (recorded by test code added to smc.ko). None of its 16384 bytes reach the peer, though send() returned 16384. The write and the CDC message behind it both complete with IB_WC_WR_FLUSH_ERR. By reading rxe (not measured), the requester rejects the write, puts the QP in the error state and flushes the send queue. The link goes down and the link group is terminated, so A is aborted too: its next send() fails with EPIPE. Patched, both streams arrive intact and the link stays up. Both builds also deliver both streams intact with smcr_buf_type=0, with smcr_buf_type=1, and with smcr_buf_type=2 without the knob. No KASAN splat in any run.
--- net/smc/smc_tx.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
net/smc/smc_tx.c +3 -3
@@ -393,9 +393,9 @@ static int smcr_tx_rdma_writes(struct smc_connection *conn, size_t len, sge[srcchunk].addr = conn->sndbuf_desc->is_vm ? (virt_addr + src_off) : (base_addr + src_off); sge[srcchunk].length = src_len; -if (conn->sndbuf_desc->is_vm) - sge[srcchunk].lkey = - conn->sndbuf_desc->mr[link->link_idx]->lkey; + sge[srcchunk].lkey = conn->sndbuf_desc->is_vm ? + conn->sndbuf_desc->mr[link->link_idx]->lkey : + link->roce_pd->local_dma_lkey; num_sges++; src_off += src_len;
---
base-commit: ead6fa9a0ab194f02a2f36d634b193e9c5f9a1c6
change-id: 20261114-b4-disp-dd99cd41-246f1595153d
Best regards,
Signature · 1 line
Bryam Vargas <[email protected]>
[email protected]
AI reviewSashiko has reviewed this patch and found no issues.
Quoted 12 lines
From: Bryam Vargas <[email protected]>
smcr_tx_rdma_writes()sets the lkey of an SGE only for a virtually contiguous send buffer; for a physically contiguous one it leaves the lkey the work request slot already holds. With net.smc.smcr_buf_type=2 a send buffer falls back tovzalloc()whenalloc_pages()fails, so one link carries both kinds, and a slot last used by a virtually contiguous buffer posts the DMA address of a physically contiguous one under the earlier buffer's MR lkey. That write fails, the link goes down and, with no link to switch to, the link group is terminated with all of its connections.
Quoted 6 lines
Set the lkey on both branches: the MR's for a virtually contiguous buffer,
local_dma_lkeyotherwise.Fixes b8d199451c99 ("net/smc: Allow virtually contiguous sndbufs or RMBs for SMC-R")Signed-off-by Bryam Vargas <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 12 lines · On Sat, 14 Nov 2026 09:14:58 -0500 you wrote:
From: Bryam Vargas <[email protected]>
smcr_tx_rdma_writes()sets the lkey of an SGE only for a virtually contiguous send buffer; for a physically contiguous one it leaves the lkey the work request slot already holds. With net.smc.smcr_buf_type=2 a send buffer falls back tovzalloc()whenalloc_pages()fails, so one link carries both kinds, and a slot last used by a virtually contiguous buffer posts the DMA address of a physically contiguous one under the earlier buffer's MR lkey. That write fails, the link goes down and, with no link to switch to, the link group is terminated with all of its connections.
Quoted 1 line
[...]
Here is the summary with links:
- [net] net/smc: set the lkey of every SGE in smcr_tx_rdma_writes()
https://git.kernel.org/netdev/net-next/c/752c59c85423
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html