[PATCH 9/9] nvme-pci: set min_align_mask

Khalid Elmously khalid.elmously at canonical.com
Tue Sep 21 01:28:36 UTC 2021


From: Jianxiong Gao <jxgao at google.com>

BugLink: https://bugs.launchpad.net/bugs/1943902

The PRP addressing scheme requires all PRP entries except for the
first one to have a zero offset into the NVMe controller pages (which
can be different from the Linux PAGE_SIZE).  Use the min_align_mask
device parameter to ensure that swiotlb does not change the address
of the buffer modulo the device page size to ensure that the PRPs
won't be malformed.

Signed-off-by: Jianxiong Gao <jxgao at google.com>
Signed-off-by: Christoph Hellwig <hch at lst.de>
Tested-by: Jianxiong Gao <jxgao at google.com>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk at oracle.com>
(backported from commit 3d2d861eb03e8ee96dc430a54361c900cbe28afd)
[ kmously: added definitions for NVME_NVME_CTRL_PAGE_SHIFT and
 NVME_CTRL_PAGE_SIZE from 6c3c05b087ada8947cd31895f67e43307044 ]
Signed-off-by: Khalid Elmously <khalid.elmously at canonical.com>
---
 drivers/nvme/host/pci.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index af516c35afe6f..414df0e0786d0 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -2631,6 +2631,15 @@ static void nvme_reset_work(struct work_struct *work)
 	 */
 	dma_set_max_seg_size(dev->dev, 0xffffffff);
 
+	/*
+	 * LP #1943902
+	 * The following 2 defines are from 6c3c05b087ada8947cd31895f67e433070446234
+	 * in Linux 5.12 and not intended to be changed.
+	 */
+	#define NVME_CTRL_PAGE_SHIFT   12
+	#define NVME_CTRL_PAGE_SIZE    (1 << NVME_CTRL_PAGE_SHIFT)
+	dma_set_min_align_mask(dev->dev, NVME_CTRL_PAGE_SIZE - 1);
+
 	mutex_unlock(&dev->shutdown_lock);
 
 	/*
-- 
2.17.1




More information about the kernel-team mailing list