max_hw_sectors error caused by recent NVMe driver commit

Michael Kelley (LINUX) mikelley at microsoft.com
Fri Feb 10 21:33:33 PST 2023


Commit 3f30a79c2e2c ("nvme-pci: set constant paramters in nvme_pci_alloc_ctrl")
appears to have introduced an error in how max_hw_sectors is calculated.  The
value of max_hw_sectors is based on dma_max_mapping_size(), which indirectly
uses dma_addressing_limited() to decide if swiotlb_max_mapping_size() should
be used.

In this commit, setting max_hw_sectors is moved to nvme_pci_alloc_dev().
But dma_addressing_limited() depends on the dev->dma_mask, which hasn't
been set.  dma_addressing_limited() returns "true", and the swiotlb max mapping
size is used, limiting NVMe transfers to 504 sectors (252 Kbytes).

Prior to this commit, max_hw_sectors isn't set until after the call to
dma_set_mask_and_coherent() in nvme_pci_enable(), as called from
nvme_reset_work().   max_hw_sectors is correctly determined based on
values reported by the NVMe controller.

I haven't provided a fix because I'm not that familiar with the overall structure
of the code and the intent of the code reorganization.  I'm not sure if setting
the DMA mask should be moved earlier, or setting max_hw_sectors should
be moved back to its original location.

Michael





More information about the Linux-nvme mailing list