Re: [PATCH v10 23/24] nvme-pci: convert to blk_rq_dma_map

Leon Romanovsky
2025-04-28T17:22:29Z

On Mon, Apr 28, 2025 at 10:46:19AM -0600, Keith Busch wrote:
> On Mon, Apr 28, 2025 at 12:22:29PM +0300, Leon Romanovsky wrote:
> > + do {
> > + if (WARN_ON_ONCE(mapped == entries)) {
> > + iter.status = BLK_STS_IOERR;
> > + break;
> > + }
> > + nvme_pci_sgl_set_data(&sg_list[mapped++], &iter);
>
> I think this should say "++mapped" so that the data blocks start at
> index 1 (continued below...)
>
> > + iod->total_len += iter.len;
> > + } while (blk_rq_dma_map_iter_next(req, dev->dev, &iod->dma_meta_state,
> > + &iter));
> >
> > -out_unmap_sg:
> > - dma_unmap_sgtable(dev->dev, &iod->meta_sgt, rq_dma_dir(req), 0);
> > -out_free_sg:
> > - mempool_free(iod->meta_sgt.sgl, dev->iod_meta_mempool);
> > - return BLK_STS_RESOURCE;
> > + nvme_pci_sgl_set_seg(sg_list, sgl_dma, mapped);
>
> because this here is setting sg_list index 0 to be the segment
> descriptor.
>
> And you also need to increment sgl_dma to point to the element after
> sg_list, otherwise it's pointing right back to itself, creating a looped
> list.

Thanks for pointing to the difference between data_map and metadata_map,
I see it now:
sgl_dma += sizeof(*sg_list);
nvme_pci_sgl_set_seg(sg_list, sgl_dma, entries);
for_each_sg(sgl, sg, entries, i)
nvme_pci_sgl_set_data(&sg_list[i + 1], sg);

Thanks

>
> > + if (unlikely(iter.status))
> > + nvme_unmap_metadata(dev, req);
> > + return iter.status;
> > }