On Mon, Apr 28, 2025 at 08:22:25PM +0300, Leon Romanovsky wrote: > 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, Yeah, They're different because the SQE has 16 bytes available for the data map, so the command can fit an SGL descriptor directly in its submission entry. The metadata field only has 8 bytes in the SQE, so we have to set it to the address of an external SGL segment descriptor.