Skip to contentSkip to conversation

nvme-pci: set virt boundary according to capability

PATCH In review Max Gurtovoy 3 participants 5 messages Dec 8, 2025 – Dec 10, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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
index e5ca8301bb8b..eacc89cd25eb 100644
@@ -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
#1 lore raw
Quoted 13 lines · Max Gurtovoy

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 +0 -0
index e5ca8301bb8b..eacc89cd25eb 100644

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.

#2 lore raw
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.

---
  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
index e5ca8301bb8b..eacc89cd25eb 100644
@@ -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.

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
maintainer
#3 lore raw
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_ALIGNED support ?

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.

#4 lore raw
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_ALIGNED support ?

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.

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 ?