Skip to content

Commit 5f0c2ee

Browse files
Loic Poulaingregkh
authored andcommitted
bus: mhi: pci-generic: Fix hibernation
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. Link: https://lore.kernel.org/r/[email protected] Reported-by: Shujun Wang <[email protected]> Cc: stable <[email protected]> Reviewed-by: Manivannan Sadhasivam <[email protected]> Signed-off-by: Loic Poulain <[email protected]> Signed-off-by: Manivannan Sadhasivam <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 0b67808 commit 5f0c2ee

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

drivers/bus/mhi/pci_generic.c

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -935,9 +935,43 @@ static int __maybe_unused mhi_pci_resume(struct device *dev)
935935
return ret;
936936
}
937937

938+
static int __maybe_unused mhi_pci_freeze(struct device *dev)
939+
{
940+
struct mhi_pci_device *mhi_pdev = dev_get_drvdata(dev);
941+
struct mhi_controller *mhi_cntrl = &mhi_pdev->mhi_cntrl;
942+
943+
/* We want to stop all operations, hibernation does not guarantee that
944+
* device will be in the same state as before freezing, especially if
945+
* the intermediate restore kernel reinitializes MHI device with new
946+
* context.
947+
*/
948+
if (test_and_clear_bit(MHI_PCI_DEV_STARTED, &mhi_pdev->status)) {
949+
mhi_power_down(mhi_cntrl, false);
950+
mhi_unprepare_after_power_down(mhi_cntrl);
951+
}
952+
953+
return 0;
954+
}
955+
956+
static int __maybe_unused mhi_pci_restore(struct device *dev)
957+
{
958+
struct mhi_pci_device *mhi_pdev = dev_get_drvdata(dev);
959+
960+
/* Reinitialize the device */
961+
queue_work(system_long_wq, &mhi_pdev->recovery_work);
962+
963+
return 0;
964+
}
965+
938966
static const struct dev_pm_ops mhi_pci_pm_ops = {
939967
SET_RUNTIME_PM_OPS(mhi_pci_runtime_suspend, mhi_pci_runtime_resume, NULL)
940-
SET_SYSTEM_SLEEP_PM_OPS(mhi_pci_suspend, mhi_pci_resume)
968+
#ifdef CONFIG_PM_SLEEP
969+
.suspend = mhi_pci_suspend,
970+
.resume = mhi_pci_resume,
971+
.freeze = mhi_pci_freeze,
972+
.thaw = mhi_pci_restore,
973+
.restore = mhi_pci_restore,
974+
#endif
941975
};
942976

943977
static struct pci_driver mhi_pci_driver = {

0 commit comments

Comments
 (0)