Skip to content

Commit 9494f0d

Browse files
YiProgramsgregkh
authored andcommitted
smb: client/smbdirect: fix MR registration for coalesced SG lists
commit 9900b9f upstream. The stable backport to < 7.1 patches a different file. Also the Fixes tag below is adjusted for the old code path. ib_dma_map_sg() modifies the provided scatterlist and returns the number of mapped entries, which can be fewer than the requested mr->sgt.nents if the DMA controller coalesces contiguous memory segments. Passing the original, uncoalesced count to ib_map_mr_sg() causes memory registration failures if coalescing actually occurs. Capture the actual mapped count returned by ib_dma_map_sg() and pass it to ib_map_mr_sg() to ensure correct MR registration. Also update the ib_dma_map_sg() error logging to drop the error pointer formatting, since the return value is an integer count rather than an error code. Ensure a proper error code (-EIO) is assigned when DMA mapping or MR registration fails. Fixes: c739858 ("CIFS: SMBD: Implement RDMA memory registration") Closes: https://bugzilla.kernel.org/show_bug.cgi?id=221408 Reviewed-by: Stefan Metzmacher <metze@samba.org> Acked-by: Namjae Jeon <linkinjeon@kernel.org> Signed-off-by: Yi Kuo <yi@yikuo.dev> Signed-off-by: Steve French <stfrench@microsoft.com> Cc: stable@vger.kernel.org Signed-off-by: Stefan Metzmacher <metze@samba.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 7c93f35 commit 9494f0d

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

fs/smb/client/smbdirect.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2920,7 +2920,7 @@ struct smbdirect_mr_io *smbd_register_mr(struct smbd_connection *info,
29202920
struct smbdirect_socket *sc = &info->socket;
29212921
struct smbdirect_socket_parameters *sp = &sc->parameters;
29222922
struct smbdirect_mr_io *mr;
2923-
int rc, num_pages;
2923+
int rc, num_pages, num_mapped;
29242924
struct ib_reg_wr *reg_wr;
29252925

29262926
num_pages = iov_iter_npages(iter, sp->max_frmr_depth + 1);
@@ -2948,18 +2948,21 @@ struct smbdirect_mr_io *smbd_register_mr(struct smbd_connection *info,
29482948
num_pages, iov_iter_count(iter), sp->max_frmr_depth);
29492949
smbd_iter_to_mr(iter, &mr->sgt, sp->max_frmr_depth);
29502950

2951-
rc = ib_dma_map_sg(sc->ib.dev, mr->sgt.sgl, mr->sgt.nents, mr->dir);
2952-
if (!rc) {
2953-
log_rdma_mr(ERR, "ib_dma_map_sg num_pages=%x dir=%x rc=%x\n",
2954-
num_pages, mr->dir, rc);
2951+
num_mapped = ib_dma_map_sg(sc->ib.dev, mr->sgt.sgl, mr->sgt.nents, mr->dir);
2952+
if (!num_mapped) {
2953+
log_rdma_mr(ERR, "ib_dma_map_sg num_pages=%x dir=%x num_mapped=%x\n",
2954+
num_pages, mr->dir, num_mapped);
2955+
rc = -EIO;
29552956
goto dma_map_error;
29562957
}
29572958

2958-
rc = ib_map_mr_sg(mr->mr, mr->sgt.sgl, mr->sgt.nents, NULL, PAGE_SIZE);
2959-
if (rc != mr->sgt.nents) {
2959+
rc = ib_map_mr_sg(mr->mr, mr->sgt.sgl, num_mapped, NULL, PAGE_SIZE);
2960+
if (rc != num_mapped) {
29602961
log_rdma_mr(ERR,
2961-
"ib_map_mr_sg failed rc = %d nents = %x\n",
2962-
rc, mr->sgt.nents);
2962+
"ib_map_mr_sg failed rc = %d num_mapped = %x\n",
2963+
rc, num_mapped);
2964+
if (rc >= 0)
2965+
rc = -EIO;
29632966
goto map_mr_error;
29642967
}
29652968

0 commit comments

Comments
 (0)