* [PATCH v2] smb: smbdirect: fix MR registration for coalesced SG lists
@ 2026-04-29 10:00 Yi Kuo
0 siblings, 0 replies; 4+ messages in thread
From: Yi Kuo @ 2026-04-29 10:00 UTC (permalink / raw)
To: smfrench, linkinjeon
Cc: metze, tom, linux-cifs, samba-technical, linux-kernel, Yi Kuo
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: de5ef8ec3c46 ("smb: smbdirect: introduce smbdirect_mr.c with client mr code")
Closes: https://bugzilla.kernel.org/show_bug.cgi?id=221408
Signed-off-by: Yi Kuo <yi@yikuo.dev>
---
v2:
- Add proper -EIO error assignment on mapping/registration failures.
- Add Fixes and Closes tags.
fs/smb/smbdirect/mr.c | 21 ++++++++++++---------
1 file changed, 12 insertions(+), 9 deletions(-)
diff --git a/fs/smb/smbdirect/mr.c b/fs/smb/smbdirect/mr.c
index 5228e699cd5d..5a428ff1b369 100644
--- a/fs/smb/smbdirect/mr.c
+++ b/fs/smb/smbdirect/mr.c
@@ -269,7 +269,7 @@ smbdirect_connection_register_mr_io(struct smbdirect_socket *sc,
{
const struct smbdirect_socket_parameters *sp = &sc->parameters;
struct smbdirect_mr_io *mr;
- int ret, num_pages;
+ int ret, num_pages, num_mapped;
struct ib_reg_wr *reg_wr;
num_pages = iov_iter_npages(iter, sp->max_frmr_depth + 1);
@@ -300,19 +300,22 @@ smbdirect_connection_register_mr_io(struct smbdirect_socket *sc,
num_pages, iov_iter_count(iter), sp->max_frmr_depth);
smbdirect_iter_to_sgt(iter, &mr->sgt, sp->max_frmr_depth);
- ret = ib_dma_map_sg(sc->ib.dev, mr->sgt.sgl, mr->sgt.nents, mr->dir);
- if (!ret) {
+ num_mapped = ib_dma_map_sg(sc->ib.dev, mr->sgt.sgl, mr->sgt.nents, mr->dir);
+ if (!num_mapped) {
smbdirect_log_rdma_mr(sc, SMBDIRECT_LOG_ERR,
- "ib_dma_map_sg num_pages=%u dir=%x ret=%d (%1pe)\n",
- num_pages, mr->dir, ret, SMBDIRECT_DEBUG_ERR_PTR(ret));
+ "ib_dma_map_sg num_pages=%u dir=%x num_mapped=%d\n",
+ num_pages, mr->dir, num_mapped);
+ ret = -EIO;
goto dma_map_error;
}
- ret = ib_map_mr_sg(mr->mr, mr->sgt.sgl, mr->sgt.nents, NULL, PAGE_SIZE);
- if (ret != mr->sgt.nents) {
+ ret = ib_map_mr_sg(mr->mr, mr->sgt.sgl, num_mapped, NULL, PAGE_SIZE);
+ if (ret != num_mapped) {
smbdirect_log_rdma_mr(sc, SMBDIRECT_LOG_ERR,
- "ib_map_mr_sg failed ret = %d nents = %u\n",
- ret, mr->sgt.nents);
+ "ib_map_mr_sg failed ret = %d num_mapped = %u\n",
+ ret, num_mapped);
+ if (ret >= 0)
+ ret = -EIO;
goto map_mr_error;
}
--
2.54.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] smb: smbdirect: fix MR registration for coalesced SG lists
[not found] <5b221fc2.AXEAAJjZnuQAAAAAAAAABAMtJJkAAYKKIjQAAAAAAC-ZZgBp8da7@mailjet.com>
@ 2026-04-29 10:02 ` Stefan Metzmacher
0 siblings, 0 replies; 4+ messages in thread
From: Stefan Metzmacher @ 2026-04-29 10:02 UTC (permalink / raw)
To: Yi Kuo, smfrench, linkinjeon
Cc: tom, linux-cifs, samba-technical, linux-kernel
Am 29.04.26 um 12:00 schrieb Yi Kuo:
> 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: de5ef8ec3c46 ("smb: smbdirect: introduce smbdirect_mr.c with client mr code")
> Closes: https://bugzilla.kernel.org/show_bug.cgi?id=221408
> Signed-off-by: Yi Kuo <yi@yikuo.dev>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
Thanks!
metze
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] smb: smbdirect: fix MR registration for coalesced SG lists
[not found] <85118db1.AWEAAJaZP3EAAAAAAAAABAMtJJUAAYKKIjQAAAAAAC-ZZgBp8da6@mailjet.com>
@ 2026-04-29 10:17 ` Namjae Jeon
2026-04-29 16:00 ` Steve French
0 siblings, 1 reply; 4+ messages in thread
From: Namjae Jeon @ 2026-04-29 10:17 UTC (permalink / raw)
To: Yi Kuo; +Cc: smfrench, metze, tom, linux-cifs, samba-technical, linux-kernel
On Wed, Apr 29, 2026 at 7:00 PM Yi Kuo <yi@yikuo.dev> wrote:
>
> 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: de5ef8ec3c46 ("smb: smbdirect: introduce smbdirect_mr.c with client mr code")
> Closes: https://bugzilla.kernel.org/show_bug.cgi?id=221408
> Signed-off-by: Yi Kuo <yi@yikuo.dev>
Acked-by: Namjae Jeon <linkinjeon@kernel.org>
Thanks!
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] smb: smbdirect: fix MR registration for coalesced SG lists
2026-04-29 10:17 ` Namjae Jeon
@ 2026-04-29 16:00 ` Steve French
0 siblings, 0 replies; 4+ messages in thread
From: Steve French @ 2026-04-29 16:00 UTC (permalink / raw)
To: Namjae Jeon; +Cc: Yi Kuo, metze, tom, linux-cifs, samba-technical, linux-kernel
merged into ksmbd-for-next
On Wed, Apr 29, 2026 at 5:17 AM Namjae Jeon <linkinjeon@kernel.org> wrote:
>
> On Wed, Apr 29, 2026 at 7:00 PM Yi Kuo <yi@yikuo.dev> wrote:
> >
> > 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: de5ef8ec3c46 ("smb: smbdirect: introduce smbdirect_mr.c with client mr code")
> > Closes: https://bugzilla.kernel.org/show_bug.cgi?id=221408
> > Signed-off-by: Yi Kuo <yi@yikuo.dev>
> Acked-by: Namjae Jeon <linkinjeon@kernel.org>
> Thanks!
--
Thanks,
Steve
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-04-29 16:00 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <5b221fc2.AXEAAJjZnuQAAAAAAAAABAMtJJkAAYKKIjQAAAAAAC-ZZgBp8da7@mailjet.com>
2026-04-29 10:02 ` [PATCH v2] smb: smbdirect: fix MR registration for coalesced SG lists Stefan Metzmacher
[not found] <85118db1.AWEAAJaZP3EAAAAAAAAABAMtJJUAAYKKIjQAAAAAAC-ZZgBp8da6@mailjet.com>
2026-04-29 10:17 ` Namjae Jeon
2026-04-29 16:00 ` Steve French
2026-04-29 10:00 Yi Kuo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox