* [PATCH] soc: qcom: rpmh-rsc: Write the sleep and wake sets again after hibernation
@ 2026-11-20 15:08 Abel Vesa
2026-11-26 14:39 ` Konrad Dybcio
2026-11-30 5:19 ` Maulik Shah
0 siblings, 2 replies; 3+ messages in thread
From: Abel Vesa @ 2026-11-20 15:08 UTC (permalink / raw)
To: Bjorn Andersson, Konrad Dybcio, Abel Vesa
Cc: Maulik Shah, linux-arm-msm, linux-kernel, Abel Vesa
The sleep and wake TCSes are written by rpmh_flush() right before the
last CPU of the RSC power domain goes down, but only when the cached
votes changed since the last flush. A hibernation image is restored by
another kernel, which used the TCSes for its own votes. The cache of the
restored kernel still says the TCSes hold its votes, so it never writes
them again and every power collapse after the restore applies the sleep
and wake votes of the kernel that loaded the image, until one of the
cached votes happens to change.
Mark the cache dirty when restoring from hibernation, so that the next
power collapse writes the sleep and wake sets of the restored kernel.
Signed-off-by: Abel Vesa <abel.vesa@oss.qualcomm.com>
---
drivers/soc/qcom/rpmh-rsc.c | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/drivers/soc/qcom/rpmh-rsc.c b/drivers/soc/qcom/rpmh-rsc.c
index 02b74c510c3f..3f89857d9d22 100644
--- a/drivers/soc/qcom/rpmh-rsc.c
+++ b/drivers/soc/qcom/rpmh-rsc.c
@@ -1169,12 +1169,35 @@ static const struct of_device_id rpmh_drv_match[] = {
};
MODULE_DEVICE_TABLE(of, rpmh_drv_match);
+/*
+ * A hibernation image is restored by another kernel, which filled the sleep
+ * and wake TCSes with its own votes. Our cache still says they hold ours, so
+ * rpmh_flush() would never write them again and the next power collapse would
+ * use what the other kernel left behind. Write them again before that.
+ */
+static int rpmh_rsc_restore_early(struct device *dev)
+{
+ struct rsc_drv *drv = dev_get_drvdata(dev);
+ unsigned long flags;
+
+ spin_lock_irqsave(&drv->client.cache_lock, flags);
+ drv->client.dirty = true;
+ spin_unlock_irqrestore(&drv->client.cache_lock, flags);
+
+ return 0;
+}
+
+static const struct dev_pm_ops rpmh_rsc_pm_ops = {
+ .restore_early = pm_sleep_ptr(rpmh_rsc_restore_early),
+};
+
static struct platform_driver rpmh_driver = {
.probe = rpmh_rsc_probe,
.driver = {
.name = "rpmh",
.of_match_table = rpmh_drv_match,
.suppress_bind_attrs = true,
+ .pm = pm_sleep_ptr(&rpmh_rsc_pm_ops),
},
};
---
base-commit: adcad7f4e6332cff3d6d7165f41584899f598534
change-id: 20261120-soc-qcom-rpmh-rsc-restore-hibernation-e536287de56c
Best regards,
--
Abel
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] soc: qcom: rpmh-rsc: Write the sleep and wake sets again after hibernation
2026-11-20 15:08 [PATCH] soc: qcom: rpmh-rsc: Write the sleep and wake sets again after hibernation Abel Vesa
@ 2026-11-26 14:39 ` Konrad Dybcio
2026-11-30 5:19 ` Maulik Shah
1 sibling, 0 replies; 3+ messages in thread
From: Konrad Dybcio @ 2026-11-26 14:39 UTC (permalink / raw)
To: Abel Vesa, Bjorn Andersson, Konrad Dybcio, Abel Vesa
Cc: Maulik Shah, linux-arm-msm, linux-kernel
On 11/20/26 4:08 PM, Abel Vesa wrote:
> The sleep and wake TCSes are written by rpmh_flush() right before the
> last CPU of the RSC power domain goes down, but only when the cached
> votes changed since the last flush. A hibernation image is restored by
> another kernel, which used the TCSes for its own votes. The cache of the
> restored kernel still says the TCSes hold its votes, so it never writes
> them again and every power collapse after the restore applies the sleep
> and wake votes of the kernel that loaded the image, until one of the
> cached votes happens to change.
>
> Mark the cache dirty when restoring from hibernation, so that the next
> power collapse writes the sleep and wake sets of the restored kernel.
>
> Signed-off-by: Abel Vesa <abel.vesa@oss.qualcomm.com>
> ---
> drivers/soc/qcom/rpmh-rsc.c | 23 +++++++++++++++++++++++
> 1 file changed, 23 insertions(+)
>
> diff --git a/drivers/soc/qcom/rpmh-rsc.c b/drivers/soc/qcom/rpmh-rsc.c
> index 02b74c510c3f..3f89857d9d22 100644
> --- a/drivers/soc/qcom/rpmh-rsc.c
> +++ b/drivers/soc/qcom/rpmh-rsc.c
> @@ -1169,12 +1169,35 @@ static const struct of_device_id rpmh_drv_match[] = {
> };
> MODULE_DEVICE_TABLE(of, rpmh_drv_match);
>
> +/*
> + * A hibernation image is restored by another kernel, which filled the sleep
> + * and wake TCSes with its own votes. Our cache still says they hold ours, so
> + * rpmh_flush() would never write them again and the next power collapse would
> + * use what the other kernel left behind. Write them again before that.
Should we fully drop that cache as we go towards hibernation?
(perhaps at a point when we're sure it isn't going to fail..)
IIUC we're going to have some votes that have been cast by drivers
that need them and then some leftover ones
Konrad
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] soc: qcom: rpmh-rsc: Write the sleep and wake sets again after hibernation
2026-11-20 15:08 [PATCH] soc: qcom: rpmh-rsc: Write the sleep and wake sets again after hibernation Abel Vesa
2026-11-26 14:39 ` Konrad Dybcio
@ 2026-11-30 5:19 ` Maulik Shah
1 sibling, 0 replies; 3+ messages in thread
From: Maulik Shah @ 2026-11-30 5:19 UTC (permalink / raw)
To: Abel Vesa, Bjorn Andersson, Konrad Dybcio, Abel Vesa
Cc: linux-arm-msm, linux-kernel
On 20-11-2026 20:38, Abel Vesa wrote:
> +/*
> + * A hibernation image is restored by another kernel, which filled the sleep
> + * and wake TCSes with its own votes. Our cache still says they hold ours, so
> + * rpmh_flush() would never write them again and the next power collapse would
> + * use what the other kernel left behind. Write them again before that.
> + */
> +static int rpmh_rsc_restore_early(struct device *dev)
> +{
> + struct rsc_drv *drv = dev_get_drvdata(dev);
> + unsigned long flags;
> +
> + spin_lock_irqsave(&drv->client.cache_lock, flags);
> + drv->client.dirty = true;
> + spin_unlock_irqrestore(&drv->client.cache_lock, flags);
> +
> + return 0;
> +}
> +
> +static const struct dev_pm_ops rpmh_rsc_pm_ops = {
> + .restore_early = pm_sleep_ptr(rpmh_rsc_restore_early),
> +};
Its very likely that client would have already send a new/updated vote before the restore_early phase,
for example, PCIe maps its .restore_noirq same as .resume_noirq,
qcom_pcie_resume_noirq() → icc_enable() → qcom_icc_set() → qcom_icc_bcm_voter_commit() → rpmh_invalidate()
would have updated dirty cache flag. So this callback be needed to be moved to .restore_noirq stage or even before actual voting re-starts
or the idle low power mode happens.
For the RSCs using the CPU PM notifier fallback (not using power-domains property), When the saved image resumes
cpuidle gets enabled in syscore stage.
syscore_resume() => pm_sleep_enable_secondary_cpus() => cpuidle_resume(),
If all CPUs enter idle while device restoration is pending, the last CPU can therefore reach rpmh_rsc_cpu_pm_callback()
and rpmh_flush() while the restored dirty flag is still false.
so need to re-set this dirty flag in the syscore ops, resume callback.
Thanks,
Maulik
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-30 5:19 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-20 15:08 [PATCH] soc: qcom: rpmh-rsc: Write the sleep and wake sets again after hibernation Abel Vesa
2026-11-26 14:39 ` Konrad Dybcio
2026-11-30 5:19 ` Maulik Shah
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®