diff mbox series

[3/3] bus: mhi: pci-generic: Fix hibernation

Message ID 20210606153741.20725-4-manivannan.sadhasivam@linaro.org
State New
Headers show
Series MHI fixes for v5.13 | expand

Commit Message

Manivannan Sadhasivam June 6, 2021, 3:37 p.m. UTC
From: Loic Poulain <loic.poulain@linaro.org>


This patch fixes crash after resuming from hibernation. The issue
occurs when mhi stack is builtin and so part of the 'restore-kernel',
causing the device to be resumed from 'restored kernel' with a no
more valid context (memory mappings etc...) and leading to spurious
crashes.

This patch fixes the issue by implementing proper freeze/restore
callbacks.

Reported-by: Shujun Wang <wsj20369@163.com>
Signed-off-by: Loic Poulain <loic.poulain@linaro.org>

Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>

Link: https://lore.kernel.org/r/1622571445-4505-1-git-send-email-loic.poulain@linaro.org
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>

---
 drivers/bus/mhi/pci_generic.c | 36 ++++++++++++++++++++++++++++++++++-
 1 file changed, 35 insertions(+), 1 deletion(-)

-- 
2.25.1

Comments

Greg KH June 9, 2021, 5:04 p.m. UTC | #1
On Sun, Jun 06, 2021 at 09:07:41PM +0530, Manivannan Sadhasivam wrote:
> From: Loic Poulain <loic.poulain@linaro.org>

> 

> This patch fixes crash after resuming from hibernation. The issue

> occurs when mhi stack is builtin and so part of the 'restore-kernel',

> causing the device to be resumed from 'restored kernel' with a no

> more valid context (memory mappings etc...) and leading to spurious

> crashes.

> 

> This patch fixes the issue by implementing proper freeze/restore

> callbacks.

> 

> Reported-by: Shujun Wang <wsj20369@163.com>

> Signed-off-by: Loic Poulain <loic.poulain@linaro.org>

> Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>

> Link: https://lore.kernel.org/r/1622571445-4505-1-git-send-email-loic.poulain@linaro.org

> Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>

> ---

>  drivers/bus/mhi/pci_generic.c | 36 ++++++++++++++++++++++++++++++++++-

>  1 file changed, 35 insertions(+), 1 deletion(-)


Also needs a stable link, right?  I'll go add it by hand.  Please be
more careful next time...

greg k-h
Manivannan Sadhasivam June 9, 2021, 5:44 p.m. UTC | #2
On Wed, Jun 09, 2021 at 07:04:35PM +0200, Greg KH wrote:
> On Sun, Jun 06, 2021 at 09:07:41PM +0530, Manivannan Sadhasivam wrote:

> > From: Loic Poulain <loic.poulain@linaro.org>

> > 

> > This patch fixes crash after resuming from hibernation. The issue

> > occurs when mhi stack is builtin and so part of the 'restore-kernel',

> > causing the device to be resumed from 'restored kernel' with a no

> > more valid context (memory mappings etc...) and leading to spurious

> > crashes.

> > 

> > This patch fixes the issue by implementing proper freeze/restore

> > callbacks.

> > 

> > Reported-by: Shujun Wang <wsj20369@163.com>

> > Signed-off-by: Loic Poulain <loic.poulain@linaro.org>

> > Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>

> > Link: https://lore.kernel.org/r/1622571445-4505-1-git-send-email-loic.poulain@linaro.org

> > Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>

> > ---

> >  drivers/bus/mhi/pci_generic.c | 36 ++++++++++++++++++++++++++++++++++-

> >  1 file changed, 35 insertions(+), 1 deletion(-)

> 

> Also needs a stable link, right?  I'll go add it by hand.  Please be

> more careful next time...

> 


Oops... yes, sorry.

Thanks,
Mani

> greg k-h
diff mbox series

Patch

diff --git a/drivers/bus/mhi/pci_generic.c b/drivers/bus/mhi/pci_generic.c
index 0a6619ad292c..b3357a8a2fdb 100644
--- a/drivers/bus/mhi/pci_generic.c
+++ b/drivers/bus/mhi/pci_generic.c
@@ -935,9 +935,43 @@  static int __maybe_unused mhi_pci_resume(struct device *dev)
 	return ret;
 }
 
+static int __maybe_unused mhi_pci_freeze(struct device *dev)
+{
+	struct mhi_pci_device *mhi_pdev = dev_get_drvdata(dev);
+	struct mhi_controller *mhi_cntrl = &mhi_pdev->mhi_cntrl;
+
+	/* We want to stop all operations, hibernation does not guarantee that
+	 * device will be in the same state as before freezing, especially if
+	 * the intermediate restore kernel reinitializes MHI device with new
+	 * context.
+	 */
+	if (test_and_clear_bit(MHI_PCI_DEV_STARTED, &mhi_pdev->status)) {
+		mhi_power_down(mhi_cntrl, false);
+		mhi_unprepare_after_power_down(mhi_cntrl);
+	}
+
+	return 0;
+}
+
+static int __maybe_unused mhi_pci_restore(struct device *dev)
+{
+	struct mhi_pci_device *mhi_pdev = dev_get_drvdata(dev);
+
+	/* Reinitialize the device */
+	queue_work(system_long_wq, &mhi_pdev->recovery_work);
+
+	return 0;
+}
+
 static const struct dev_pm_ops mhi_pci_pm_ops = {
 	SET_RUNTIME_PM_OPS(mhi_pci_runtime_suspend, mhi_pci_runtime_resume, NULL)
-	SET_SYSTEM_SLEEP_PM_OPS(mhi_pci_suspend, mhi_pci_resume)
+#ifdef CONFIG_PM_SLEEP
+	.suspend = mhi_pci_suspend,
+	.resume = mhi_pci_resume,
+	.freeze = mhi_pci_freeze,
+	.thaw = mhi_pci_restore,
+	.restore = mhi_pci_restore,
+#endif
 };
 
 static struct pci_driver mhi_pci_driver = {