Linux-NVME Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] nvme-pci: add NVME_QUIRK_APST_BUF_512 for Micron 2100AI/AT
@ 2026-11-27 13:35 Bean Huo
  2026-11-30  8:53 ` Christoph Hellwig
  0 siblings, 1 reply; 2+ messages in thread
From: Bean Huo @ 2026-11-27 13:35 UTC (permalink / raw)
  To: Keith Busch
  Cc: Jens Axboe, Christoph Hellwig, Sagi Grimberg, linux-nvme,
	Bean Huo, Gaurav Sinha

From: Bean Huo <beanhuo@micron.com>

The APST table is 256 bytes and nvme_configure_apst() allocates exactly
that much, so the table can be the last 256 bytes of a page.

The Micron 2100AI/AT (PCI 1344:6001) reads the data for this command
in one 512 byte unit. When the table ends a page, the read reaches into
the next page, and with an IOMMU enabled this can be reported as a
fault. The command itself still completes.

Add NVME_QUIRK_APST_BUF_512 for this device. With the quirk, allocate
and map 512 zeroed bytes. kmalloc aligns a power-of-two size to that
size, so the buffer never crosses a page. PRPs carry no length, so the
command is unchanged.

The table format and the APST policy do not change. While here, use
the product name in the comment of this PCI entry.

Signed-off-by: Bean Huo <beanhuo@micron.com>
Signed-off-by: Gaurav Sinha <gsinha@micron.com>
---
Note: this only changes the APST command that the driver sends from
nvme_configure_apst(). Userspace cannot send this command since commit
1161be71d1ec ("nvme: reject passthrough of driver-managed Set
Features"). nvmet passthru can still send it, and is not changed.

 drivers/nvme/host/core.c | 14 ++++++++++++--
 drivers/nvme/host/nvme.h |  7 +++++++
 drivers/nvme/host/pci.c  |  5 +++--
 3 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index f43582e5f6c4..6f351757e909 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -2972,6 +2972,7 @@ static bool nvme_apst_get_transition_time(u64 total_latency,
 static int nvme_configure_apst(struct nvme_ctrl *ctrl)
 {
 	struct nvme_feat_auto_pst *table;
+	size_t len = sizeof(*table);
 	unsigned apste = 0;
 	u64 max_lat_us = 0;
 	__le64 target = 0;
@@ -2992,7 +2993,16 @@ static int nvme_configure_apst(struct nvme_ctrl *ctrl)
 		return 0;
 	}
 
-	table = kzalloc_obj(*table);
+	/*
+	 * Some controllers fetch 512 bytes for the 256 byte table.  Give them
+	 * a zeroed 512 byte buffer.  kmalloc aligns a power-of-two size to
+	 * that size, so the buffer never crosses a page and the extra fetch
+	 * stays inside it.
+	 */
+	if (ctrl->quirks & NVME_QUIRK_APST_BUF_512)
+		len = 512;
+
+	table = kzalloc(len, GFP_KERNEL);
 	if (!table)
 		return 0;
 
@@ -3067,7 +3077,7 @@ static int nvme_configure_apst(struct nvme_ctrl *ctrl)
 
 done:
 	ret = nvme_set_features(ctrl, NVME_FEAT_AUTO_PST, apste,
-				table, sizeof(*table), NULL);
+				table, len, NULL);
 	if (ret)
 		dev_err(ctrl->device, "failed to set APST feature (%d)\n", ret);
 	kfree(table);
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
index 2543e52d6358..ae195f28d3ed 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -198,6 +198,11 @@ enum nvme_quirks {
 	 * do not advertise FUA so the block layer emulates it.
 	 */
 	NVME_QUIRK_NO_FUA			= (1 << 24),
+
+	/*
+	 * The controller fetches 512 bytes for the 256 byte APST table
+	 */
+	NVME_QUIRK_APST_BUF_512			= (1 << 25),
 };
 
 static inline char *nvme_quirk_name(enum nvme_quirks q)
@@ -253,6 +258,8 @@ static inline char *nvme_quirk_name(enum nvme_quirks q)
 		return "admin_page_align";
 	case NVME_QUIRK_NO_FUA:
 		return "no_fua";
+	case NVME_QUIRK_APST_BUF_512:
+		return "apst_buf_512";
 	}
 
 	return "unknown";
diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index 076603df01ab..0b7f69d73f3b 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -4416,8 +4416,9 @@ static const struct pci_device_id nvme_id_table[] = {
 				NVME_QUIRK_IGNORE_DEV_SUBNQN, },
 	 { PCI_DEVICE(0x1344, 0x5407), /* Micron Technology Inc NVMe SSD */
 		.driver_data = NVME_QUIRK_IGNORE_DEV_SUBNQN },
-	 { PCI_DEVICE(0x1344, 0x6001),   /* Micron Nitro NVMe */
-		 .driver_data = NVME_QUIRK_BOGUS_NID, },
+	 { PCI_DEVICE(0x1344, 0x6001),   /* Micron 2100AI/AT NVMe SSD */
+		 .driver_data = NVME_QUIRK_BOGUS_NID |
+				NVME_QUIRK_APST_BUF_512, },
 	{ PCI_DEVICE(0x1344, 0x6004),	/* Micron 4100AT */
 		.driver_data = NVME_QUIRK_DMAPOOL_ALIGN_512, },
 	{ PCI_DEVICE(0x1e0f, 0x0032),	/* KIOXIA XG10d */


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] nvme-pci: add NVME_QUIRK_APST_BUF_512 for Micron 2100AI/AT
  2026-11-27 13:35 [PATCH] nvme-pci: add NVME_QUIRK_APST_BUF_512 for Micron 2100AI/AT Bean Huo
@ 2026-11-30  8:53 ` Christoph Hellwig
  0 siblings, 0 replies; 2+ messages in thread
From: Christoph Hellwig @ 2026-11-30  8:53 UTC (permalink / raw)
  To: Bean Huo
  Cc: Keith Busch, Jens Axboe, Christoph Hellwig, Sagi Grimberg,
	linux-nvme, Bean Huo, Gaurav Sinha

On Fri, Nov 27, 2026 at 02:35:38PM +0100, Bean Huo wrote:
> From: Bean Huo <beanhuo@micron.com>
> 
> The APST table is 256 bytes and nvme_configure_apst() allocates exactly
> that much, so the table can be the last 256 bytes of a page.
> 
> The Micron 2100AI/AT (PCI 1344:6001) reads the data for this command
> in one 512 byte unit. When the table ends a page, the read reaches into
> the next page, and with an IOMMU enabled this can be reported as a
> fault. The command itself still completes.
> 
> Add NVME_QUIRK_APST_BUF_512 for this device. With the quirk, allocate
> and map 512 zeroed bytes. kmalloc aligns a power-of-two size to that
> size, so the buffer never crosses a page. PRPs carry no length, so the
> command is unchanged.
> 
> The table format and the APST policy do not change. While here, use
> the product name in the comment of this PCI entry.

Meh.  Why does everyone fuck up their devices so much?

I guess we have to live with this, so:

Reviewed-by: Christoph Hellwig <hch@lst.de>
> 


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-30  8:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-27 13:35 [PATCH] nvme-pci: add NVME_QUIRK_APST_BUF_512 for Micron 2100AI/AT Bean Huo
2026-11-30  8:53 ` Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox