Skip to contentSkip to conversation

nvme/pci: remap BAR0 to cover admin CQ doorbell for large stride

PATCH Superseded Xu Yu 2 participants 3 messages May 17, 2017 – May 19, 2017 NVMe

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Xu Yu

author
#0 lore raw

PATCH 1/1 nvme/pci: remap BAR0 to cover admin CQ doorbell for large stride

The existing driver initially maps 8192 bytes of BAR0 which is intended to cover doorbells of admin SQ and CQ. However, if a large stride, e.g. 10, is used, the doorbell of admin CQ will be out of 8192 bytes. Consequently, a page fault will be raised when the admin CQ doorbell is accessed in nvme_configure_admin_queue().

This patch fixes this issue by remapping BAR0 before accessing admin CQ doorbell if the initial mapping is not enough.

Signed-off-by "Xu, Yu A" <yu.a.xu at intel.com>
---
 drivers/nvme/host/pci.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/nvme/host/pci.c +11 -0
index 9d4640a..7c991eb 100644
@@ -1322,6 +1322,17 @@ static int nvme_configure_admin_queue(struct nvme_dev *dev)
 	u32 aqa;
 	u64 cap = lo_hi_readq(dev->bar + NVME_REG_CAP);
 	struct nvme_queue *nvmeq;
+	struct pci_dev *pdev = to_pci_dev(dev->dev);
+	unsigned long size;
+
+	size = 4096 + 2 * 4 * dev->db_stride;
+	if (size > 8192) {
+		iounmap(dev->bar);
+		dev->bar = ioremap(pci_resource_start(pdev, 0), size);
+		if (!dev->bar)
+			return -ENOMEM;
+		dev->dbs = dev->bar + 4096;
+	}
 
 	dev->subsystem = readl(dev->bar + NVME_REG_VS) >= NVME_VS(1, 1, 0) ?
 						NVME_CAP_NSSRC(cap) : 0;
Signature · 1 line
2.10.1
#1 lore raw
Quoted 23 lines · Xu Yu

The existing driver initially maps 8192 bytes of BAR0 which is intended to cover doorbells of admin SQ and CQ. However, if a large stride, e.g. 10, is used, the doorbell of admin CQ will be out of 8192 bytes. Consequently, a page fault will be raised when the admin CQ doorbell is accessed in nvme_configure_admin_queue().

This patch fixes this issue by remapping BAR0 before accessing admin CQ doorbell if the initial mapping is not enough.

Signed-off-by "Xu, Yu A" <yu.a.xu at intel.com>
---
 drivers/nvme/host/pci.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/nvme/host/pci.c +1 -0
index 9d4640a..7c991eb 100644
@@ -1322,6 +1322,17 @@ static int nvme_configure_admin_queue(struct nvme_dev *dev)
 	u32 aqa;
 	u64 cap = lo_hi_readq(dev->bar + NVME_REG_CAP);
 	struct nvme_queue *nvmeq;
+	struct pci_dev *pdev = to_pci_dev(dev->dev);

drivers/nvme/host/pci.c static int nvme_configure_admin_queue(struct nvme_dev *dev) · line 1335

Quoted 10 lines
drivers/nvme/host/pci.c +10 -0
+	unsigned long size;
+
+	size = 4096 + 2 * 4 * dev->db_stride;
+	if (size > 8192) {
+		iounmap(dev->bar);
+		dev->bar = ioremap(pci_resource_start(pdev, 0), size);
+		if (!dev->bar)
+			return -ENOMEM;
+		dev->dbs = dev->bar + 4096;
+	}

This code duplicates logic in db_bar_size / nvme_setup_io_queues. Please reuse the db_bar_size helper by passing 0 to, and try to figure out if we can factor this whole sequence into a new helper as well.

Bonus points for adding constants to nvme.h for the 4096 offset of the first db register, and our magic 8192 threshold.

author
#2 lore raw

Thanks for your suggestion, we will try to make it better and resend the patch soon.

-----Original Message-----
From: Christoph Hellwig [mailto:[email protected]]
Sent: Thursday, May 18, 2017 9:44 PM
To: Xu, Yu A <yu.a.xu at intel.com>
Cc: linux-nvme at lists.infradead.org; linux-kernel at vger.kernel.org; Busch, Keith <keith.busch at intel.com>; axboe at fb.com; hch at lst.de; sagi at grimberg.me; Zhang, Haozhong <haozhong.zhang at intel.com>
Subject: Re: [PATCH] nvme/pci: remap BAR0 to cover admin CQ doorbell for large stride

Quoted 23 lines · Xu Yu

The existing driver initially maps 8192 bytes of BAR0 which is intended to cover doorbells of admin SQ and CQ. However, if a large stride, e.g. 10, is used, the doorbell of admin CQ will be out of 8192 bytes. Consequently, a page fault will be raised when the admin CQ doorbell is accessed in nvme_configure_admin_queue().

This patch fixes this issue by remapping BAR0 before accessing admin CQ doorbell if the initial mapping is not enough.

Signed-off-by "Xu, Yu A" <yu.a.xu at intel.com>
---
 drivers/nvme/host/pci.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/nvme/host/pci.c index renamed from drivers/nvme/host/pci.c +0 -0

9d4640a..7c991eb 100644

drivers/nvme/host/pci.c +1 -0
@@ -1322,6 +1322,17 @@ static int nvme_configure_admin_queue(struct nvme_dev *dev)
 	u32 aqa;
 	u64 cap = lo_hi_readq(dev->bar + NVME_REG_CAP);
 	struct nvme_queue *nvmeq;
+	struct pci_dev *pdev = to_pci_dev(dev->dev);

drivers/nvme/host/pci.c static int nvme_configure_admin_queue(struct nvme_dev *dev) · line 1335

Quoted 10 lines
drivers/nvme/host/pci.c +10 -0
+	unsigned long size;
+
+	size = 4096 + 2 * 4 * dev->db_stride;
+	if (size > 8192) {
+		iounmap(dev->bar);
+		dev->bar = ioremap(pci_resource_start(pdev, 0), size);
+		if (!dev->bar)
+			return -ENOMEM;
+		dev->dbs = dev->bar + 4096;
+	}

This code duplicates logic in db_bar_size / nvme_setup_io_queues.
Please reuse the db_bar_size helper by passing 0 to, and try to figure out if we can factor this whole sequence into a new helper as well.

Bonus points for adding constants to nvme.h for the 4096 offset of the first db register, and our magic 8192 threshold.