From: Logan Gunthorpe <logang@deltatee.com>
To: Mykola Marzhan <mykola@meshstor.io>, Jens Axboe <axboe@kernel.dk>,
Song Liu <song@kernel.org>, Yu Kuai <yukuai@fygo.io>,
Keith Busch <kbusch@kernel.org>, Christoph Hellwig <hch@lst.de>,
Sagi Grimberg <sagi@grimberg.me>,
linux-block@vger.kernel.org, linux-raid@vger.kernel.org,
linux-nvme@lists.infradead.org
Cc: Li Nan <magiclinan@didiglobal.com>, Xiao Ni <xiao@kernel.org>,
Guoqing Jiang <guoqing.jiang@linux.dev>,
Leon Romanovsky <leon@kernel.org>, Jason Gunthorpe <jgg@ziepe.ca>,
Kiran Kumar Modukuri <kmodukuri@nvidia.com>,
Chaitanya Kulkarni <kch@nvidia.com>,
Bjorn Helgaas <bhelgaas@google.com>,
Shivaji Kant <shivajikant@google.com>,
Pranjal Shrivastava <praan@google.com>,
Henrique Carvalho <henrique.carvalho@suse.com>,
stable@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-rdma@vger.kernel.org, linux-pci@vger.kernel.org
Subject: Re: [PATCH v5 09/10] nvme-rdma: use ib_dma_map_sgtable_attrs()
Date: Fri, 24 Jul 2026 12:47:16 -0600 [thread overview]
Message-ID: <23b0a3ae-7f11-4ae9-8c1b-0401db0fd299@deltatee.com> (raw)
In-Reply-To: <20260723204206.76930-10-mykola@meshstor.io>
On 2026-07-23 2:42 p.m., Mykola Marzhan wrote:
> ib_dma_map_sg() folds every mapping error into a zero return, losing
> the DMA layer's error code. Switch both scatterlist mappings to
> ib_dma_map_sgtable_attrs(), which preserves it for the next patch to
> act on. No behavior change: failures are still reported as -EIO.
>
> A local sg_table is needed: dma_map_sgtable() maps orig_nents
> entries, and the embedded table's orig_nents is the allocated count,
> not the count blk_rq_map_sg() produced. rdma_rw_ctx_init() does the
> same.
>
> Assisted-by: Claude:claude-fable-5
> Cc: stable@vger.kernel.org # v7.1
> Signed-off-by: Mykola Marzhan <mykola@meshstor.io>
I don't know. I think this could still use a bit more cleanup (see
thoughts below). But the cleanup is probably too much to ask for this
series. See my thoughts below.
Reviewd-by: Logan Gunthorpe <logang@deltatee.com>
> ---
> drivers/nvme/host/rdma.c | 23 +++++++++++++++--------
> 1 file changed, 15 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/nvme/host/rdma.c b/drivers/nvme/host/rdma.c
> index 6909e3542794..63830334c73e 100644
> --- a/drivers/nvme/host/rdma.c
> +++ b/drivers/nvme/host/rdma.c
> @@ -1469,6 +1469,7 @@ static int nvme_rdma_dma_map_req(struct ib_device *ibdev, struct request *rq,
> int *count, int *pi_count)
> {
> struct nvme_rdma_request *req = blk_mq_rq_to_pdu(rq);
> + struct sg_table sgt;
> int ret;
>
> req->data_sgl.sg_table.sgl = (struct scatterlist *)(req + 1);
> @@ -1480,12 +1481,16 @@ static int nvme_rdma_dma_map_req(struct ib_device *ibdev, struct request *rq,
>
> req->data_sgl.nents = blk_rq_map_sg(rq, req->data_sgl.sg_table.sgl);
>
> - *count = ib_dma_map_sg(ibdev, req->data_sgl.sg_table.sgl,
> - req->data_sgl.nents, rq_dma_dir(rq));
> - if (unlikely(*count <= 0)) {
> + sgt = (struct sg_table) {
> + .sgl = req->data_sgl.sg_table.sgl,
> + .orig_nents = req->data_sgl.nents,
> + };
> + ret = ib_dma_map_sgtable_attrs(ibdev, &sgt, rq_dma_dir(rq), 0);
> + if (unlikely(ret)) {
> ret = -EIO;
> goto out_free_table;
> }
> + *count = sgt.nents;
This really makes these calls really complicated and harder to reason
about just to get an appropriate return code in the next patch. Though I
see the complexity here and I feel like I'm confused by the semantics of
nents and orig_nents all the time. It seems like some cases really need
to track three counts: the number of valid DMA addresses (nents), the
number of valid segments and the number actually allocated. sg_table
only has two fields, and orig_nents ends up doing double duty — the DMA
API reads it as the valid-segment count, while
sg_alloc/free_table_chained() treat it as the allocation size. When
those two differ, as they do here, it creates this complexity.
One cheap thought that might clean up this patch series is to create a
helper that can be used for both the data and the metadata, but that's
only slightly better and I don't know if it is worth the effort.
A better long term option might be to introduce a dma_map_sgtable like
helper that also takes the number of valid segments which would clean
this up pretty nicley. But that would be much more work.
Thanks,
Logan
next prev parent reply other threads:[~2026-07-24 18:48 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-23 20:41 [PATCH v5 00/10] block,md,nvme: correct handling of unsupported P2PDMA transfers Mykola Marzhan
2026-07-23 20:41 ` [PATCH v5 01/10] block: add BLK_STS_P2PDMA for unsupported peer-to-peer transfers Mykola Marzhan
2026-07-23 20:41 ` [PATCH v5 02/10] md: ensure REQ_NOMERGE is set on P2PDMA bios Mykola Marzhan
2026-07-23 20:41 ` [PATCH v5 03/10] md/raid1: serialize non-write-behind writes on CollisionCheck rdevs Mykola Marzhan
2026-07-23 20:42 ` [PATCH v5 04/10] md/raid1: don't use write-behind for P2PDMA bios Mykola Marzhan
2026-07-23 20:42 ` [PATCH v5 05/10] md/raid1,raid10: factor out raid1_write_error() helper Mykola Marzhan
2026-07-23 20:42 ` [PATCH v5 06/10] md/raid1,raid10: keep REQ_NOMERGE on narrow_write_error() retry clones Mykola Marzhan
2026-07-23 20:42 ` [PATCH v5 07/10] md/raid1,raid10: skip futile retries on P2PDMA mapping failures Mykola Marzhan
2026-07-24 15:11 ` Logan Gunthorpe
2026-07-23 20:42 ` [PATCH v5 08/10] md/raid1,raid10: set IO_BLOCKED in case of BLK_STS_P2PDMA Mykola Marzhan
2026-07-23 20:42 ` [PATCH v5 09/10] nvme-rdma: use ib_dma_map_sgtable_attrs() Mykola Marzhan
2026-07-24 18:47 ` Logan Gunthorpe [this message]
2026-07-23 20:42 ` [PATCH v5 10/10] nvme-rdma: return BLK_STS_P2PDMA for unsupported P2P transfers Mykola Marzhan
2026-07-24 18:50 ` Logan Gunthorpe
2026-07-24 10:21 ` [PATCH v5 00/10] block,md,nvme: correct handling of unsupported P2PDMA transfers Thorsten Leemhuis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=23b0a3ae-7f11-4ae9-8c1b-0401db0fd299@deltatee.com \
--to=logang@deltatee.com \
--cc=axboe@kernel.dk \
--cc=bhelgaas@google.com \
--cc=guoqing.jiang@linux.dev \
--cc=hch@lst.de \
--cc=henrique.carvalho@suse.com \
--cc=jgg@ziepe.ca \
--cc=kbusch@kernel.org \
--cc=kch@nvidia.com \
--cc=kmodukuri@nvidia.com \
--cc=leon@kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux-raid@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=magiclinan@didiglobal.com \
--cc=mykola@meshstor.io \
--cc=praan@google.com \
--cc=sagi@grimberg.me \
--cc=shivajikant@google.com \
--cc=song@kernel.org \
--cc=stable@vger.kernel.org \
--cc=xiao@kernel.org \
--cc=yukuai@fygo.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®