nvme-pci: set virt boundary according to capability
Subsystems (2)
PATCH 1/1 nvme-pci: set virt boundary according to capability
Some controllers advertise DWORD alignment for SGLs, so configure the virtual boundary correctly for those devices.
--- drivers/nvme/host/pci.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/nvme/host/pci.c +3 -1
@@ -3326,7 +3326,9 @@ static unsigned long nvme_pci_get_virt_boundary(struct nvme_ctrl *ctrl, {if (!nvme_ctrl_sgl_supported (ctrl) || is_admin)return NVME_CTRL_PAGE_SIZE -1 ; -return 0 ; +else if (ctrl->sgls &NVME_CTRL_SGLS_BYTE_ALIGNED ) +return 0 ; +return 3 ; }static const struct nvme_ctrl_ops nvme_pci_ctrl_ops = {
Signature · 1 line
2.43.5
Christoph Hellwig
maintainerQuoted 13 lines · Max Gurtovoy
Some controllers advertise DWORD alignment for SGLs, so configure the virtual boundary correctly for those devices.
Signed-off-by Max Gurtovoy <[email protected]>--- drivers/nvme/host/pci.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/nvme/host/pci.c +0
-0
drivers/nvme/host/pci.c static unsigned long nvme_pci_get_virt_boundary(struct nvme_ctrl *ctrl, · line 3331
Quoted 7 lines
drivers/nvme/host/pci.c +3
-1@@ -3326,7 +3326,9 @@ static unsigned long nvme_pci_get_virt_boundary(struct nvme_ctrl *ctrl, {if (!nvme_ctrl_sgl_supported (ctrl) || is_admin)return NVME_CTRL_PAGE_SIZE -1 ; -return 0 ; +else if (ctrl->sgls &NVME_CTRL_SGLS_BYTE_ALIGNED ) +return 0 ; +return 3 ;
I don't think this is correct. NVME_CTRL_SGLS_BYTE_ALIGNED requires each SGL to be aligned, but is not a virt boundary. The dma_alignment value in the queue_limits already takes care of that.
Quoted 9 lines · Christoph Hellwig
Quoted 8 lines · Max Gurtovoy
Some controllers advertise DWORD alignment for SGLs, so configure the virtual boundary correctly for those devices.
Signed-off-by Max Gurtovoy <[email protected]>--- drivers/nvme/host/pci.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
Quoted 15 lines
drivers/nvme/host/pci.c static unsigned long nvme_pci_get_virt_boundary(struct nvme_ctrl *ctrl, · line 3331
Quoted 12 lines
drivers/nvme/host/pci.c +3
-1@@ -3326,7 +3326,9 @@ static unsigned long nvme_pci_get_virt_boundary(struct nvme_ctrl *ctrl, {if (!nvme_ctrl_sgl_supported (ctrl) || is_admin)return NVME_CTRL_PAGE_SIZE -1 ; -return 0 ; +else if (ctrl->sgls &NVME_CTRL_SGLS_BYTE_ALIGNED ) +return 0 ; +return 3 ;I don't think this is correct.
NVME_CTRL_SGLS_BYTE_ALIGNEDrequires each SGL to be aligned, but is not a virt boundary. Thedma_alignmentvalue in thequeue_limitsalready takes care of that.
I see. The virt boundary handles the gaps.
Should we modify:
dma_set_min_align_mask(dev->dev, NVME_CTRL_PAGE_SIZE - 1);
and
lim->dma_alignment = 3;
to ease the restriction for capable devices with NVME_CTRL_SGLS_BYTE_ALIGNED support ?
Quoted 1 line
Keith Busch
maintainerQuoted 8 lines · Max Gurtovoy
dma_set_min_align_mask(dev->dev, NVME_CTRL_PAGE_SIZE - 1);and
lim->dma_alignment= 3;to ease the restriction for capable devices with
NVME_CTRL_SGLS_BYTE_ALIGNEDsupport ?
Yeah, the dma_alignment is the limit you'd need to change. Note, you can't actually set the dma_alignment to be byte aligned as it's a mask, so you'd want the value to be 0 to allow any alignment, but the block layer currently won't let it be 0, so you'd have to set it to 1, for word alignment.
But I'm surprised to hear of a device that can do byte aligned SGLs, as PCIe fundamentally can't do byte aligned DMA. It's all dword based, so if you have a device that does report byte alignment, it's still sending dwords over the wire. It's just using the "byte enable" fields in the TLP header to have the receiver strip off preceding and/or trailing bytes, so it is a bit inefficient way to transfer data.
Quoted 15 lines · Keith Busch
Quoted 8 lines · Max Gurtovoy
dma_set_min_align_mask(dev->dev, NVME_CTRL_PAGE_SIZE - 1);and
lim->dma_alignment= 3;to ease the restriction for capable devices with
NVME_CTRL_SGLS_BYTE_ALIGNEDsupport ?Yeah, the
dma_alignmentis the limit you'd need to change. Note, you can't actually set thedma_alignmentto be byte aligned as it's a mask, so you'd want the value to be 0 to allow any alignment, but the block layer currently won't let it be 0, so you'd have to set it to 1, for word alignment.
Quoted 6 lines
But I'm surprised to hear of a device that can do byte aligned SGLs, as PCIe fundamentally can't do byte aligned DMA. It's all dword based, so if you have a device that does report byte alignment, it's still sending dwords over the wire. It's just using the "byte enable" fields in the TLP header to have the receiver strip off preceding and/or trailing bytes, so it is a bit inefficient way to transfer data.
I saw some devices that report byte alignment. But if it's actually sending dwords over the wire than it's useless.
what about dma_set_min_align_mask(dev->dev, NVME_CTRL_PAGE_SIZE - 1); ? won't it mandate 4K alignment ?