nvme-pci: Disable LTR for simple suspend
PATCH 1/1 nvme-pci: Disable LTR for simple suspend
Some drives from SSSTC are showing stability problems after s0i3 entry when the Linux kernel is in s2idle loop if LTR has been enabled. This leads to failures to resume.
This appears to be a firmware issue specific to SSSTC SSDs, but to avoid this class of problem, disable LTR when going into s2idle and simple suspend has been set.
--- drivers/nvme/host/pci.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
drivers/nvme/host/pci.c +25 -0
@@ -139,6 +139,7 @@ struct nvme_dev {struct nvme_ctrl ctrl;u32 last_ps;bool hmb; +bool restore_ltr;mempool_t *iod_mempool;
@@ -3214,11 +3215,30 @@ static int nvme_set_power_state(struct nvme_ctrl *ctrl, u32 ps)return nvme_set_features (ctrl,NVME_FEAT_POWER_MGMT , ps,NULL ,0 ,NULL ); } +static void nvme_suspend_ltr (struct device *dev,bool disable) +{ +struct pci_dev *pdev =to_pci_dev (dev); +struct nvme_dev *ndev =pci_get_drvdata (pdev); + +if (disable) { +u16 word; + +pcie_capability_read_word (pdev,PCI_EXP_DEVCTL2 , &word); + ndev->restore_ltr = word &PCI_EXP_DEVCTL2_LTR_EN ; +pcie_capability_clear_word (pdev,PCI_EXP_DEVCTL2 , +PCI_EXP_DEVCTL2_LTR_EN ); + }else if (ndev->restore_ltr) { +pcie_capability_set_word (pdev,PCI_EXP_DEVCTL2 , +PCI_EXP_DEVCTL2_LTR_EN ); + } +} +static int nvme_resume (struct device *dev) {struct nvme_dev *ndev =pci_get_drvdata (to_pci_dev (dev));struct nvme_ctrl *ctrl = &ndev->ctrl; +nvme_suspend_ltr (dev, false);if (ndev->last_ps ==U32_MAX ||nvme_set_power_state (ctrl, ndev->last_ps) !=0 ) goto reset;
@@ -3239,6 +3259,11 @@ static int nvme_suspend(struct device *dev) ndev->last_ps =U32_MAX ; +/* If using s2idle with simple suspend, disable LTR to avoid problems. */ +if (pm_suspend_target_state ==PM_SUSPEND_TO_IDLE && + ndev->ctrl.quirks &NVME_QUIRK_SIMPLE_SUSPEND ) +nvme_suspend_ltr (dev, true); +/* * The platform does not remove power for a kernel managed suspend so * use host managed nvme power settings for lowest idle power if
Signature · 1 line
2.34.1
Christoph Hellwig
maintainerQuoted 7 lines · Mario Limonciello
Some drives from SSSTC are showing stability problems after s0i3 entry when the Linux kernel is in s2idle loop if LTR has been enabled. This leads to failures to resume.
This appears to be a firmware issue specific to SSSTC SSDs, but to avoid this class of problem, disable LTR when going into s2idle and simple suspend has been set.
This seems like a giant hammer to do this for all NVMe devices, why not quirk the specific ones?
Quoted 7 lines
drivers/nvme/host/pci.c +7
-0+static void nvme_suspend_ltr (struct device *dev,bool disable) +{ +struct pci_dev *pdev =to_pci_dev (dev); +struct nvme_dev *ndev =pci_get_drvdata (pdev); + +if (disable) { +u16 word;
drivers/nvme/host/pci.c static int nvme_set_power_state(struct nvme_ctrl *ctrl, u32 ps) · line 3234
Quoted 10 lines
drivers/nvme/host/pci.c +10
-0+ +pcie_capability_read_word (pdev,PCI_EXP_DEVCTL2 , &word); + ndev->restore_ltr = word &PCI_EXP_DEVCTL2_LTR_EN ; +pcie_capability_clear_word (pdev,PCI_EXP_DEVCTL2 , +PCI_EXP_DEVCTL2_LTR_EN ); + }else if (ndev->restore_ltr) { +pcie_capability_set_word (pdev,PCI_EXP_DEVCTL2 , +PCI_EXP_DEVCTL2_LTR_EN ); + } +}
The calling conventions of this function are rather strange by mixing up two very different things.
I think two PCI-level helpers to disable LTR and return the status it ways in and to enable LTR would be really nice to have here.
drivers/nvme/host/pci.c static int nvme_suspend(struct device *dev) · line 3262
Quoted 8 lines
drivers/nvme/host/pci.c +1
-0if (ndev->last_ps ==U32_MAX ||nvme_set_power_state (ctrl, ndev->last_ps) !=0 ) goto reset;@@ -3239,6 +3259,11 @@ static int nvme_suspend(struct device *dev) ndev->last_ps =U32_MAX ; +/* If using s2idle with simple suspend, disable LTR to avoid problems. */
Overly long line here.
[Public]
Quoted 16 lines
-----Original Message-----
From: Christoph Hellwig <[email protected]>
Sent: Tuesday, March 15, 2022 02:23
To: Limonciello, Mario <[email protected]>
Cc: Keith Busch <[email protected]>; Jens Axboe <[email protected]>; Christoph Hellwig <[email protected]>; Sagi Grimberg <[email protected]>; open list:NVM EXPRESS DRIVER <[email protected]>; open list <[email protected]>; Huang, Patrick <[email protected]>; [email protected]
Subject: Re: [PATCH] nvme-pci: Disable LTR for simple suspendQuoted 4 lines · Mario Limonciello
Some drives from SSSTC are showing stability problems after s0i3 entry when the Linux kernel is in s2idle loop if LTR has been enabled. This leads to failures to resume.
Quoted 7 lines
Quoted 3 lines
This appears to be a firmware issue specific to SSSTC SSDs, but to avoid this class of problem, disable LTR when going into s2idle and simple suspend has been set.
This seems like a giant hammer to do this for all NVMe devices, why not quirk the specific ones?
The thought process was to be defensive against any other drives that have this firmware deficiency as well, but point taken.
Will rework it as a quirk.
Quoted 22 lines
drivers/nvme/host/pci.c static int nvme_set_power_state(struct nvme_ctrl *ctrl, u32 ps)
Quoted 9 lines
drivers/nvme/host/pci.c +9
-0+static void nvme_suspend_ltr (struct device *dev,bool disable) +{ +struct pci_dev *pdev =to_pci_dev (dev); +struct nvme_dev *ndev =pci_get_drvdata (pdev); + +if (disable) { +u16 word; + + pcie_capability_read_word(pdev, PCI_EXP_DEVCTL2,&word);
drivers/nvme/host/pci.c static int nvme_set_power_state(struct nvme_ctrl *ctrl, u32 ps) · line 3234
Quoted 8 lines
drivers/nvme/host/pci.c +8
-0+ ndev->restore_ltr = word &PCI_EXP_DEVCTL2_LTR_EN ; +pcie_capability_clear_word (pdev,PCI_EXP_DEVCTL2 , +PCI_EXP_DEVCTL2_LTR_EN ); + }else if (ndev->restore_ltr) { +pcie_capability_set_word (pdev,PCI_EXP_DEVCTL2 , +PCI_EXP_DEVCTL2_LTR_EN ); + } +}The calling conventions of this function are rather strange by mixing up two very different things.
Quoted 2 lines
I think two PCI-level helpers to disable LTR and return the status it ways in and to enable LTR would be really nice to have here.
If adding helper functions to PCI for this, it actually begs the argument of whether this should just be a PCI quirk. The LTR behavior is tied to how it behaves in D3, not based on anything that the NVME driver has done.
Unless you feel otherwise, I'll rework it as a PCI quirk.
Quoted 12 lines
drivers/nvme/host/pci.c static int nvme_suspend(struct device *dev) · line 3262
Quoted 9 lines
drivers/nvme/host/pci.c +1
-0if (ndev->last_ps ==U32_MAX ||nvme_set_power_state (ctrl, ndev->last_ps) !=0 ) goto reset;@@ -3239,6 +3259,11 @@ static int nvme_suspend(struct device *dev) ndev->last_ps =U32_MAX ; +/* If using s2idle with simple suspend, disable LTR to avoid problems. */
Overly long line here.