linux-arm-msm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] bus: mhi: pci-generic: Fix hibernation
@ 2021-06-01 18:17 Loic Poulain
  2021-06-06 15:23 ` Manivannan Sadhasivam
  2021-06-06 15:26 ` Manivannan Sadhasivam
  0 siblings, 2 replies; 3+ messages in thread
From: Loic Poulain @ 2021-06-01 18:17 UTC (permalink / raw)
  To: mani, hemantk; +Cc: linux-arm-msm, Loic Poulain

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>
---
 drivers/bus/mhi/pci_generic.c | 36 +++++++++++++++++++++++++++++++++++-
 1 file changed, 35 insertions(+), 1 deletion(-)

diff --git a/drivers/bus/mhi/pci_generic.c b/drivers/bus/mhi/pci_generic.c
index aa8f8d5..afa8763 100644
--- a/drivers/bus/mhi/pci_generic.c
+++ b/drivers/bus/mhi/pci_generic.c
@@ -888,9 +888,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 = {
-- 
2.7.4


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

* Re: [PATCH] bus: mhi: pci-generic: Fix hibernation
  2021-06-01 18:17 [PATCH] bus: mhi: pci-generic: Fix hibernation Loic Poulain
@ 2021-06-06 15:23 ` Manivannan Sadhasivam
  2021-06-06 15:26 ` Manivannan Sadhasivam
  1 sibling, 0 replies; 3+ messages in thread
From: Manivannan Sadhasivam @ 2021-06-06 15:23 UTC (permalink / raw)
  To: Loic Poulain; +Cc: hemantk, linux-arm-msm

On Tue, Jun 01, 2021 at 08:17:25PM +0200, Loic Poulain wrote:
> 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>

Thanks,
Mani

> ---
>  drivers/bus/mhi/pci_generic.c | 36 +++++++++++++++++++++++++++++++++++-
>  1 file changed, 35 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/bus/mhi/pci_generic.c b/drivers/bus/mhi/pci_generic.c
> index aa8f8d5..afa8763 100644
> --- a/drivers/bus/mhi/pci_generic.c
> +++ b/drivers/bus/mhi/pci_generic.c
> @@ -888,9 +888,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 = {
> -- 
> 2.7.4
> 

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

* Re: [PATCH] bus: mhi: pci-generic: Fix hibernation
  2021-06-01 18:17 [PATCH] bus: mhi: pci-generic: Fix hibernation Loic Poulain
  2021-06-06 15:23 ` Manivannan Sadhasivam
@ 2021-06-06 15:26 ` Manivannan Sadhasivam
  1 sibling, 0 replies; 3+ messages in thread
From: Manivannan Sadhasivam @ 2021-06-06 15:26 UTC (permalink / raw)
  To: Loic Poulain; +Cc: hemantk, linux-arm-msm

On Tue, Jun 01, 2021 at 08:17:25PM +0200, Loic Poulain wrote:
> 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>

Applied to mhi-fixes!

Thanks,
Mani

> ---
>  drivers/bus/mhi/pci_generic.c | 36 +++++++++++++++++++++++++++++++++++-
>  1 file changed, 35 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/bus/mhi/pci_generic.c b/drivers/bus/mhi/pci_generic.c
> index aa8f8d5..afa8763 100644
> --- a/drivers/bus/mhi/pci_generic.c
> +++ b/drivers/bus/mhi/pci_generic.c
> @@ -888,9 +888,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 = {
> -- 
> 2.7.4
> 

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

end of thread, other threads:[~2021-06-06 15:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-01 18:17 [PATCH] bus: mhi: pci-generic: Fix hibernation Loic Poulain
2021-06-06 15:23 ` Manivannan Sadhasivam
2021-06-06 15:26 ` Manivannan Sadhasivam

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).