nvme-pci: qdepth 1 quirk
Subsystems (2)
PATCH 1/1 nvme-pci: qdepth 1 quirk
From: Keith Busch <[email protected]>
Another device has been reported to be unreliable if we have more than one outstanding command. In this new case, data corruption may occur. Since we have two devices now needing this quirky behavior, make a generic quirk flag.
The same Apple quirk is clearly not "temporary", so update the comment while moving it.
--- drivers/nvme/host/nvme.h | 5 +++++ drivers/nvme/host/pci.c | 18 +++++++++--------- 2 files changed, 14 insertions(+), 9 deletions(-)
drivers/nvme/host/nvme.h +5 -0
@@ -90,6 +90,11 @@ enum nvme_quirks {*/ NVME_QUIRK_NO_DEEPEST_PS = (1 <<5 ), +/* +* Problems seen with concurrent commands +*/ + NVME_QUIRK_QDEPTH_ONE = (1 << 6), +/* * Set MEDIUM priority on SQ creation */
drivers/nvme/host/pci.c +9 -9
@@ -2557,15 +2557,8 @@ static int nvme_pci_enable(struct nvme_dev *dev)else dev->io_sqes =NVME_NVM_IOSQES ; -/* -* Temporary fix for the Apple controller found in the MacBook8,1 and -* some MacBook7,1 to avoid controller resets and data loss. -*/ -if (pdev->vendor ==PCI_VENDOR_ID_APPLE && pdev->device ==0x2001 ) { +if (dev->ctrl.quirks &NVME_QUIRK_QDEPTH_ONE ) { dev->q_depth =2 ; -dev_warn (dev->ctrl.device,"detected Apple NVMe controller, " -"set queue depth=%u to work around controller resets\n" , - dev->q_depth); }else if (pdev->vendor ==PCI_VENDOR_ID_SAMSUNG && (pdev->device ==0xa821 || pdev->device ==0xa822 ) &&NVME_CAP_MQES (dev->ctrl.cap) ==0 ) {
@@ -3425,6 +3418,8 @@ static const struct pci_device_id nvme_id_table[] = { NVME_QUIRK_BOGUS_NID, }, { PCI_VDEVICE(REDHAT, 0x0010), /* Qemu emulated controller */ .driver_data = NVME_QUIRK_BOGUS_NID, }, + { PCI_DEVICE(0x1217, 0x8760), + .driver_data = NVME_QUIRK_QDEPTH_ONE }, { PCI_DEVICE(0x126f, 0x2262), /* Silicon Motion generic */ .driver_data = NVME_QUIRK_NO_DEEPEST_PS | NVME_QUIRK_BOGUS_NID, },
@@ -3559,7 +3554,12 @@ static const struct pci_device_id nvme_id_table[] = { { PCI_DEVICE(PCI_VENDOR_ID_AMAZON, 0xcd02), .driver_data = NVME_QUIRK_DMA_ADDRESS_BITS_48, }, { PCI_DEVICE(PCI_VENDOR_ID_APPLE, 0x2001), - .driver_data = NVME_QUIRK_SINGLE_VECTOR }, +/* +* Fix for the Apple controller found in the MacBook8,1 and +* some MacBook7,1 to avoid controller resets and data loss. +*/ + .driver_data = NVME_QUIRK_SINGLE_VECTOR | + NVME_QUIRK_QDEPTH_ONE }, { PCI_DEVICE(PCI_VENDOR_ID_APPLE, 0x2003) }, { PCI_DEVICE(PCI_VENDOR_ID_APPLE, 0x2005), .driver_data = NVME_QUIRK_SINGLE_VECTOR |
Signature · 1 line
2.43.5
drivers/nvme/host/pci.c static const struct pci_device_id nvme_id_table[] = { · line 3422
Quoted 2 lines
drivers/nvme/host/pci.c +2
-0+ { PCI_DEVICE(0x1217, 0x8760), + .driver_data = NVME_QUIRK_QDEPTH_ONE },
Do we have some kind of name for this device? That always feels useful when googling for it or finding patterns.
Otherwise looks good:
---- On Thu, 12 Sep 2024 07:57:16 +0100 Christoph Hellwig wrote ---
Quoted 5 lines
Quoted 2 lines
+ {
PCI_DEVICE(0x1217, 0x8760),
+ .driver_data =NVME_QUIRK_QDEPTH_ONE},Do we have some kind of name for this device? That always feels useful when googling for it or finding patterns.
The device is the 64GB Steam Deck from Valve.
Quoted 6 lines
Otherwise looks good:
Reviewed-by Christoph Hellwig [email protected]>
PATCH 1/1 nvme-pci: Remove O2 Queue Depth quirk
PCI_DEVICE(0x1217, 0x8760) (O2 Micro, Inc. FORESEE E2M2 NVMe SSD) is a NMVe to eMMC bridge, that can be used with different eMMC memory devices.
The NVMe device name contains the eMMC device name, for instance:BAYHUB SanDisk-DA4128-91904055-128GB
The bridge is known to work with many eMMC devices, we need to limit the queue depth once we know which eMMC device is behind the bridge.
--- drivers/nvme/host/pci.c | 2 -- 1 file changed, 2 deletions(-)
drivers/nvme/host/pci.c +0 -2
@@ -3448,8 +3448,6 @@ static const struct pci_device_id nvme_id_table[] = { NVME_QUIRK_BOGUS_NID, }, { PCI_VDEVICE(REDHAT, 0x0010), /* Qemu emulated controller */ .driver_data = NVME_QUIRK_BOGUS_NID, }, - { PCI_DEVICE(0x1217, 0x8760), /* O2 Micro 64GB Steam Deck */ - .driver_data = NVME_QUIRK_QDEPTH_ONE }, { PCI_DEVICE(0x126f, 0x2262), /* Silicon Motion generic */ .driver_data = NVME_QUIRK_NO_DEEPEST_PS | NVME_QUIRK_BOGUS_NID, },
Signature · 1 line
2.47.0.163.g1226f6d8fa-goog
Greg KH
maintainerRe: [PATCH] nvme-pci: Remove O2 Queue Depth quirk
Quoted 10 lines · Gwendal Grignou
PCI_DEVICE(0x1217, 0x8760)(O2 Micro, Inc. FORESEE E2M2 NVMe SSD) is a NMVe to eMMC bridge, that can be used with different eMMC memory devices.
The NVMe device name contains the eMMC device name, for instance:BAYHUB SanDisk-DA4128-91904055-128GBThe bridge is known to work with many eMMC devices, we need to limit the queue depth once we know which eMMC device is behind the bridge.
Fixes commit 83bdfcbdbe5d ("nvme-pci: qdepth 1 quirk")
Nit, no need for "commit" here, and no blank line after this one.
thanks,
greg k-h
Christoph Hellwig
maintainerRe: [PATCH] nvme-pci: Remove O2 Queue Depth quirk
In reply to Gwendal GrignouQuoted 3 lines · Gwendal Grignou
PCI_DEVICE(0x1217, 0x8760)(O2 Micro, Inc. FORESEE E2M2 NVMe SSD) is a NMVe to eMMC bridge, that can be used with different eMMC memory devices.
Holy f**k, what an awful idea..
Quoted 5 lines
The NVMe device name contains the eMMC device name, for instance:
BAYHUB SanDisk-DA4128-91904055-128GBThe bridge is known to work with many eMMC devices, we need to limit the queue depth once we know which eMMC device is behind the bridge.
Please work with Tobert to quirk based on the identify data for "his" device to keep it quirked instead of regressing it.
Re: [PATCH] nvme-pci: Remove O2 Queue Depth quirk
Quoted 8 lines · Christoph Hellwig
Quoted 3 lines · Gwendal Grignou
PCI_DEVICE(0x1217, 0x8760)(O2 Micro, Inc. FORESEE E2M2 NVMe SSD) is a NMVe to eMMC bridge, that can be used with different eMMC memory devices.Holy f**k, what an awful idea..
Quoted 8 lines
Quoted 5 lines
The NVMe device name contains the eMMC device name, for instance:
BAYHUB SanDisk-DA4128-91904055-128GBThe bridge is known to work with many eMMC devices, we need to limit the queue depth once we know which eMMC device is behind the bridge.
Please work with Tobert to quirk based on the identify data for "his" device to keep it quirked instead of regressing it.
The issue is we would need to base the quirk on the model name (subsys->model) that is not available in nvme_id_table. Beside, q_depth is set in nvme_pci_enable, called at probe time before calling nvme_init_ctrl_finish that will indirectly populate subsys.
Bob, to address the data corruption problem from user space, adding a udev rule to set queue/nr_requests to 1 when device/model matches the device used in the Steam Deck would most likely be too late in the boot process, wouldn't it?
Gwendal.
Keith Busch
maintainerRe: [PATCH] nvme-pci: Remove O2 Queue Depth quirk
Quoted 24 lines · Gwendal Grignou
Quoted 8 lines · Christoph Hellwig
Quoted 3 lines · Gwendal Grignou
PCI_DEVICE(0x1217, 0x8760)(O2 Micro, Inc. FORESEE E2M2 NVMe SSD) is a NMVe to eMMC bridge, that can be used with different eMMC memory devices.Holy f**k, what an awful idea..
Quoted 8 lines
Quoted 5 lines
The NVMe device name contains the eMMC device name, for instance:
BAYHUB SanDisk-DA4128-91904055-128GBThe bridge is known to work with many eMMC devices, we need to limit the queue depth once we know which eMMC device is behind the bridge.
Please work with Tobert to quirk based on the identify data for "his" device to keep it quirked instead of regressing it.
The issue is we would need to base the quirk on the model name (
subsys->model) that is not available innvme_id_table. Beside,q_depthis set innvme_pci_enable, called at probe time before callingnvme_init_ctrl_finishthat will indirectly populatesubsys.
Quoted 4 lines
Bob, to address the data corruption problem from user space, adding a udev rule to set
queue/nr_requeststo 1 whendevice/modelmatches the device used in the Steam Deck would most likely be too late in the boot process, wouldn't it?
I think that is too late. There's the module parameter, 'nvme.io_queue_depth=2', that accomplishes the same thing as this quirk, if adding kernel parameters isn't too inconvenient to use here.
Alternatively, you could put the quirk in the core_quirks, which do take a model name. The pci driver would have to move this check until after init_ctrl_finish, as you noticed, but that looks okay to do. We just need to be careful to update both dev->q_depth and ctrl->sqsize after the "finish".
PATCH 1/1 nvme-pci: 512 byte dma pool segment quirk
From: Robert Beckett <[email protected]>
We initially put in a quick fix of limiting the queue depth to 1 as experimentation showed that it fixed data corruption on 64GB steamdecks.
After further experimentation, it appears that the corruption is fixed by increasing the small dma pool segment size to 512 bytes. Testing via desync image verification shows that it now passes thousands of verification loops, where previously it never managed above 7.
Currently it is not known why this fixes the corruption. Perhaps it is doing something nasty like using an mmc page as a cache for the prp lists (mmc min. page size is 512 bytes) and not invalidating properly, so that the dma pool change to treats segment list as a stack ends up giving a previous segment in the same cached page.
This fixes the previous queue depth limitation as it fixes the corruption without incurring a 37% tested performance degredation.
--- drivers/nvme/host/nvme.h | 5 +++++ drivers/nvme/host/pci.c | 17 ++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-)
drivers/nvme/host/nvme.h +5 -0
@@ -173,6 +173,11 @@ enum nvme_quirks {* MSI (but not MSI-X) interrupts are broken and never fire. */ NVME_QUIRK_BROKEN_MSI = (1 <<21 ), + +/* +* Min. dma pool segment size 512 bytes +*/ + NVME_QUIRK_SMALL_DMAPOOL_512 = (1 << 22), };/*
drivers/nvme/host/pci.c +12 -5
@@ -141,6 +141,7 @@ struct nvme_dev {struct nvme_ctrl ctrl;u32 last_ps;bool hmb; +u32 small_dmapool_seg_size;mempool_t *iod_mempool;
@@ -611,7 +612,7 @@ static blk_status_t nvme_pci_setup_prps(struct nvme_dev *dev, } nprps =DIV_ROUND_UP (length,NVME_CTRL_PAGE_SIZE ); -if (nprps <= (256 /8 )) { +if (nprps <= (dev->small_dmapool_seg_size /8 )) { pool = dev->prp_small_pool; iod->nr_allocations =0 ; }else {
@@ -701,7 +702,7 @@ static blk_status_t nvme_pci_setup_sgls(struct nvme_dev *dev,return BLK_STS_OK ; } -if (entries <= (256 /sizeof (struct nvme_sgl_desc ))) { +if (entries <= (dev->small_dmapool_seg_size /sizeof (struct nvme_sgl_desc ))) { pool = dev->prp_small_pool; iod->nr_allocations =0 ; }else {
@@ -2700,8 +2701,9 @@ static int nvme_setup_prp_pools(struct nvme_dev *dev)return -ENOMEM ;/* Optimisation for I/Os between 4k and 128k */ - dev->prp_small_pool =dma_pool_create ("prp list 256" , dev->dev, -256 ,256 ,0 ); + dev->prp_small_pool =dma_pool_create ("prp list small" , dev->dev, + dev->small_dmapool_seg_size, + dev->small_dmapool_seg_size,0 );if (!dev->prp_small_pool) {dma_pool_destroy (dev->prp_page_pool);return -ENOMEM ;
@@ -3063,6 +3065,11 @@ static struct nvme_dev *nvme_pci_alloc_dev(struct pci_dev *pdev,* a single integrity segment for the separate metadata pointer. */ dev->ctrl.max_integrity_segments =1 ; + +if (dev->ctrl.quirks &NVME_QUIRK_SMALL_DMAPOOL_512 ) + dev->small_dmapool_seg_size =512 ; +else + dev->small_dmapool_seg_size =256 ;return dev; out_put_device:
@@ -3449,7 +3456,7 @@ static const struct pci_device_id nvme_id_table[] = { { PCI_VDEVICE(REDHAT, 0x0010), /* Qemu emulated controller */ .driver_data = NVME_QUIRK_BOGUS_NID, }, { PCI_DEVICE(0x1217, 0x8760), /* O2 Micro 64GB Steam Deck */ - .driver_data = NVME_QUIRK_QDEPTH_ONE }, + .driver_data = NVME_QUIRK_SMALL_DMAPOOL_512 }, { PCI_DEVICE(0x126f, 0x2262), /* Silicon Motion generic */ .driver_data = NVME_QUIRK_NO_DEEPEST_PS | NVME_QUIRK_BOGUS_NID, },
Signature · 1 line
2.45.2
Keith Busch
maintainerRe: [PATCH] nvme-pci: 512 byte dma pool segment quirk
drivers/nvme/host/pci.c static blk_status_t nvme_pci_setup_prps(struct nvme_dev *dev, · line 618
Quoted 9 lines · Bob Beckett
drivers/nvme/host/pci.c +1
-1@@ -611,7 +612,7 @@ static blk_status_t nvme_pci_setup_prps(struct nvme_dev *dev, } nprps =DIV_ROUND_UP (length,NVME_CTRL_PAGE_SIZE ); -if (nprps <= (256 /8 )) { +if (nprps <= (dev->small_dmapool_seg_size /8 )) { pool = dev->prp_small_pool; iod->nr_allocations =0 ; }else {
We have a constant expression currently, and this is changing it a full division in the IO path. :(
Could we leave the pool selection check size as-is and just say the cost of the quirk is additional memory overhead?
drivers/nvme/host/pci.c static int nvme_setup_prp_pools(struct nvme_dev *dev) · line 2706
Quoted 9 lines
drivers/nvme/host/pci.c +3
-2@@ -2700,8 +2701,9 @@ static int nvme_setup_prp_pools(struct nvme_dev *dev)return -ENOMEM ;/* Optimisation for I/Os between 4k and 128k */ - dev->prp_small_pool =dma_pool_create ("prp list 256" , dev->dev, -256 ,256 ,0 ); + dev->prp_small_pool =dma_pool_create ("prp list small" , dev->dev, + dev->small_dmapool_seg_size, + dev->small_dmapool_seg_size,0 );
I think it should work if we only change the alignment property of the pool. Something like this:
if (dev->ctrl.quirks & NVME_QUIRK_SMALL_DMAPOOL_512)
dev->prp_small_pool = dma_pool_create("prp list 256", dev->dev,
256, 512, 0);
else
dev->prp_small_pool = dma_pool_create("prp list 256", dev->dev,
256, 256, 0);Re: [PATCH] nvme-pci: 512 byte dma pool segment quirk
---- On Thu, 07 Nov 2024 17:19:30 +0000 Keith Busch wrote ---
Quoted 13 lines · Bob Beckett
drivers/nvme/host/pci.c static blk_status_t nvme_pci_setup_prps(struct nvme_dev *dev, · line 618
Quoted 9 lines
drivers/nvme/host/pci.c +1
-1@@ -611,7 +612,7 @@ static blk_status_t nvme_pci_setup_prps(struct nvme_dev *dev, } nprps = DIV_ROUND_UP(length, NVME_CTRL_PAGE_SIZE); - if (nprps <= (256 / 8)) { + if (nprps small_dmapool_seg_size / 8)) { pool = dev->prp_small_pool; iod->nr_allocations = 0; } else {We have a constant expression currently, and this is changing it a full division in the IO path. :(
yeah, that's fair. Does it get high enough throughput that this is a significant issue here? (I have little intuition for this driver).
how about pre-computing the nprps threshold during pool creation where we detect the quirk, it would then be variable comparison instead of a const comparison, but no divide?
Quoted 17 lines
Could we leave the pool selection check size as-is and just say the cost of the quirk is additional memory overhead?
drivers/nvme/host/pci.c static int nvme_setup_prp_pools(struct nvme_dev *dev) · line 2706
Quoted 9 lines
drivers/nvme/host/pci.c +3
-2@@ -2700,8 +2701,9 @@ static int nvme_setup_prp_pools(struct nvme_dev *dev) return -ENOMEM; /* Optimisation for I/Os between 4k and 128k */ - dev->prp_small_pool = dma_pool_create("prp list 256", dev->dev, - 256, 256, 0); + dev->prp_small_pool = dma_pool_create("prp list small", dev->dev, + dev->small_dmapool_seg_size, + dev->small_dmapool_seg_size, 0);I think it should work if we only change the alignment property of the pool. Something like this:
Quoted 3 lines
if (
dev->ctrl.quirks&NVME_QUIRK_SMALL_DMAPOOL_512)dev->prp_small_pool=dma_pool_create("prp list 256", dev->dev, 256, 512, 0);
I actually already tested a change of 512, 512 while keeping the 256 devision above during testing (i.e. waste half of the segment). I'll confirm with a test again against latest and send a v2 assuming it tests fine.
Quoted 4 lines
else
dev->prp_small_pool =dma_pool_create("prp list 256", dev->dev, 256, 256, 0);
Christoph Hellwig
maintainerRe: [PATCH] nvme-pci: 512 byte dma pool segment quirk
In reply to Keith BuschQuoted 2 lines · Keith Busch
We have a constant expression currently, and this is changing it a full division in the IO path. :(
Yeah. Given that the device is broken I'd just have it pay the price and never use the small prp pool instead, which just adds a single extra branch to the fast path.
Re: [PATCH] nvme-pci: Remove O2 Queue Depth quirk
In reply to Gwendal Grignou---- On Tue, 29 Oct 2024 18:58:40 +0000 Gwendal Grignou wrote ---
Quoted 24 lines · On Tue, Oct 29, 2024 at 12:41 AM Christoph Hellwig [email protected]> wrote:
Quoted 8 lines · Gwendal Grignou
Quoted 3 lines
PCI_DEVICE(0x1217, 0x8760)(O2 Micro, Inc. FORESEE E2M2 NVMe SSD) is a NMVe to eMMC bridge, that can be used with different eMMC memory devices.Holy f**k, what an awful idea..
Quoted 8 lines
Quoted 5 lines
The NVMe device name contains the eMMC device name, for instance:
BAYHUB SanDisk-DA4128-91904055-128GBThe bridge is known to work with many eMMC devices, we need to limit the queue depth once we know which eMMC device is behind the bridge.
Please work with Tobert to quirk based on the identify data for "his" device to keep it quirked instead of regressing it.
The issue is we would need to base the quirk on the model name (
subsys->model) that is not available innvme_id_table. Beside,q_depthis set innvme_pci_enable, called at probe time before callingnvme_init_ctrl_finishthat will indirectly populatesubsys.
Quoted 4 lines
Bob, to address the data corruption problem from user space, adding a udev rule to set
queue/nr_requeststo 1 whendevice/modelmatches the device used in the Steam Deck would most likely be too late in the boot process, wouldn't it?
I've never seen the corruption outside of severe stress testing.
In the field, people reported it during and after os image updates (more stress testing). However, as this concerns data integrity, it seems risky to me to rely on a fix after bootup.
Quoted 3 lines
Gwendal.
Re: [PATCH] nvme-pci: Remove O2 Queue Depth quirk
Quoted 36 lines · Robert Beckett
---- On Tue, 29 Oct 2024 18:58:40 +0000 Gwendal Grignou wrote ---
Quoted 24 lines · On Tue, Oct 29, 2024 at 12:41 AM Christoph Hellwig [email protected]> wrote:
Quoted 8 lines · Gwendal Grignou
Quoted 3 lines
PCI_DEVICE(0x1217, 0x8760)(O2 Micro, Inc. FORESEE E2M2 NVMe SSD) is a NMVe to eMMC bridge, that can be used with different eMMC memory devices.Holy f**k, what an awful idea..
Quoted 8 lines
Quoted 5 lines
The NVMe device name contains the eMMC device name, for instance:
BAYHUB SanDisk-DA4128-91904055-128GBThe bridge is known to work with many eMMC devices, we need to limit the queue depth once we know which eMMC device is behind the bridge.
Please work with Tobert to quirk based on the identify data for "his" device to keep it quirked instead of regressing it.
The issue is we would need to base the quirk on the model name (
subsys->model) that is not available innvme_id_table. Beside,q_depthis set innvme_pci_enable, called at probe time before callingnvme_init_ctrl_finishthat will indirectly populatesubsys.Quoted 4 lines
Bob, to address the data corruption problem from user space, adding a udev rule to set
queue/nr_requeststo 1 whendevice/modelmatches the device used in the Steam Deck would most likely be too late in the boot process, wouldn't it?
Quoted 4 lines
I've never seen the corruption outside of severe stress testing.
In the field, people reported it during and after os image updates (more stress testing). However, as this concerns data integrity, it seems risky to me to rely on a fix after bootup.
Since limiting the queue depth to 2 is only needed for a small subset of eMMC memory modules that can be connected behind the bridge, would it make sense to apply this patch, but add the kernel module parameter mentioned earlier for impacted devices?
Gwendal.
Quoted 5 lines
Quoted 4 lines
Gwendal.
Keith Busch
maintainerRe: [PATCH] nvme-pci: Remove O2 Queue Depth quirk
Quoted 4 lines · Gwendal Grignou
Since limiting the queue depth to 2 is only needed for a small subset of eMMC memory modules that can be connected behind the bridge, would it make sense to apply this patch, but add the kernel module parameter mentioned earlier for impacted devices?
I don't think qd2 is needed for anyone, though. The problem sounds like it was root caused to a boundary condition, which is addressed in a different patch. But I am not 100% sure, as the thread was left hanging for some external confirmation:
Sasha Levin
maintainer[ Sasha's backport helper bot ]
Hi,
Found matching upstream commit: 83bdfcbdbe5d901c5fa432decf12e1725a840a56
WARNING: Author mismatch between patch and found commit:
Backport author: Keith Busch <[email protected]> Commit author: Keith Busch <[email protected]>
Status in newer kernel trees:
6.12.y | Present (exact SHA1)
Note: The patch differs from the upstream commit:
---
Failed to apply patch cleanly, falling back to interdiff...
---
Results of testing on various branches:
| Branch | Patch Apply | Build Test | |---------------------------|-------------|------------| | stable/linux-6.12.y | Failed | N/A | | stable/linux-6.6.y | Failed | N/A | | stable/linux-6.1.y | Failed | N/A | | stable/linux-5.15.y | Failed | N/A | | stable/linux-5.10.y | Failed | N/A | | stable/linux-5.4.y | Failed | N/A |