mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] media: iris: Unload the firmware before hibernation
@ 2026-10-26 13:39 Abel Vesa
  2026-11-17 12:42 ` bod
  2026-12-01 20:37 ` Kaylin Aurora
  0 siblings, 2 replies; 3+ messages in thread
From: Abel Vesa @ 2026-10-26 13:39 UTC (permalink / raw)
  To: Vikash Garodia, Dikshita Agarwal, Abhinav Kumar,
	Bryan O'Donoghue, Mauro Carvalho Chehab
  Cc: linux-media, linux-arm-msm, linux-kernel, Abel Vesa

A hibernation image is restored after a power cycle, by a kernel that
may have loaded the firmware itself. Neither the firmware, which lives
in memory the image does not hold, nor its authentication by the
TrustZone survive that, so resuming the core from the restored kernel
fails:

  qcom-iris aa00000.video-codec: failed to resume

Make sure the image does not hold an initialized core. Unload the
firmware before the image is created, and before the kernel that loads
the image jumps into it, so that the next session loads it again. Keep
the system error handler disabled meanwhile, so that it cannot load the
firmware again behind our back.

Refuse to hibernate while the device is open, as its sessions cannot
survive this. Failing them the way a system error does would let
hibernation go on, but would break every open file handle on each
hibernation, without userspace having a chance to tear the session
down cleanly.

Signed-off-by: Abel Vesa <abel.vesa@oss.qualcomm.com>
---
Prepared with help from an LLM-based assistant.
---
 drivers/media/platform/qcom/iris/iris_probe.c | 44 +++++++++++++++++++++++++--
 1 file changed, 42 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/qcom/iris/iris_probe.c b/drivers/media/platform/qcom/iris/iris_probe.c
index 41dec90f3e2b..ea77c573b333 100644
--- a/drivers/media/platform/qcom/iris/iris_probe.c
+++ b/drivers/media/platform/qcom/iris/iris_probe.c
@@ -411,9 +411,49 @@ static int __maybe_unused iris_pm_resume(struct device *dev)
 	return ret;
 }
 
+/*
+ * Neither the firmware nor its TrustZone authentication survive hibernation,
+ * so do not let the image hold an initialized core.
+ */
+static int iris_pm_freeze(struct device *dev)
+{
+	struct iris_core *core = dev_get_drvdata(dev);
+	int ret;
+
+	scoped_guard(mutex, &core->lock) {
+		if (!list_empty(&core->instances)) {
+			dev_err(dev, "cannot hibernate while the device is open\n");
+			return -EBUSY;
+		}
+	}
+
+	/* Keep a system error from loading the firmware again */
+	disable_delayed_work_sync(&core->sys_error_handler);
+	iris_core_deinit(core);
+
+	ret = pm_runtime_force_suspend(dev);
+	if (ret)
+		enable_delayed_work(&core->sys_error_handler);
+
+	return ret;
+}
+
+static int iris_pm_thaw(struct device *dev)
+{
+	struct iris_core *core = dev_get_drvdata(dev);
+
+	enable_delayed_work(&core->sys_error_handler);
+
+	return pm_runtime_force_resume(dev);
+}
+
 static const struct dev_pm_ops iris_pm_ops = {
-	SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
-				pm_runtime_force_resume)
+	.suspend = pm_sleep_ptr(pm_runtime_force_suspend),
+	.resume = pm_sleep_ptr(pm_runtime_force_resume),
+	.freeze = pm_sleep_ptr(iris_pm_freeze),
+	.thaw = pm_sleep_ptr(iris_pm_thaw),
+	.poweroff = pm_sleep_ptr(pm_runtime_force_suspend),
+	.restore = pm_sleep_ptr(iris_pm_thaw),
 	SET_RUNTIME_PM_OPS(iris_pm_suspend, iris_pm_resume, NULL)
 };
 

---
base-commit: 20a33c6b6cbe7e4805dfb6cd68816937443aa148
change-id: 20261023-b4-media-iris-unload-firmware-hibernation-930a88ecbe08

Best regards,
--  
Abel Vesa <abel.vesa@oss.qualcomm.com>


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

* Re: [PATCH] media: iris: Unload the firmware before hibernation
  2026-10-26 13:39 [PATCH] media: iris: Unload the firmware before hibernation Abel Vesa
@ 2026-11-17 12:42 ` bod
  2026-12-01 20:37 ` Kaylin Aurora
  1 sibling, 0 replies; 3+ messages in thread
From: bod @ 2026-11-17 12:42 UTC (permalink / raw)
  To: Abel Vesa
  Cc: Vikash Garodia, Dikshita Agarwal, Abhinav Kumar,
	Bryan O'Donoghue, Mauro Carvalho Chehab, linux-media,
	linux-arm-msm, linux-kernel

On 2026-10-26 15:39 +0200, Abel Vesa wrote:
> A hibernation image is restored after a power cycle, by a kernel that
> may have loaded the firmware itself. Neither the firmware, which lives
> in memory the image does not hold, nor its authentication by the
> TrustZone survive that, so resuming the core from the restored kernel
> fails:
> 
>   qcom-iris aa00000.video-codec: failed to resume
> 
> Make sure the image does not hold an initialized core. Unload the
> firmware before the image is created, and before the kernel that loads
> the image jumps into it, so that the next session loads it again. Keep
> the system error handler disabled meanwhile, so that it cannot load the
> firmware again behind our back.
> 
> Refuse to hibernate while the device is open, as its sessions cannot
> survive this. Failing them the way a system error does would let
> hibernation go on, but would break every open file handle on each
> hibernation, without userspace having a chance to tear the session
> down cleanly.
> 
> Signed-off-by: Abel Vesa <abel.vesa@oss.qualcomm.com>
> ---
> Prepared with help from an LLM-based assistant.
> ---
>  drivers/media/platform/qcom/iris/iris_probe.c | 44 +++++++++++++++++++++++++--
>  1 file changed, 42 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/media/platform/qcom/iris/iris_probe.c b/drivers/media/platform/qcom/iris/iris_probe.c
> index 41dec90f3e2b..ea77c573b333 100644
> --- a/drivers/media/platform/qcom/iris/iris_probe.c
> +++ b/drivers/media/platform/qcom/iris/iris_probe.c
> @@ -411,9 +411,49 @@ static int __maybe_unused iris_pm_resume(struct device *dev)
>  	return ret;
>  }
>  
> +/*
> + * Neither the firmware nor its TrustZone authentication survive hibernation,
> + * so do not let the image hold an initialized core.
> + */


> +static int iris_pm_freeze(struct device *dev)
> +{
> +	struct iris_core *core = dev_get_drvdata(dev);
> +	int ret;
> +
> +	scoped_guard(mutex, &core->lock) {
> +		if (!list_empty(&core->instances)) {
> +			dev_err(dev, "cannot hibernate while the device is open\n");
> +			return -EBUSY;
> +		}
> +	}
> +
> +	/* Keep a system error from loading the firmware again */
> +	disable_delayed_work_sync(&core->sys_error_handler);
> +	iris_core_deinit(core);

I think the logic here is generally good. One thing though - we appear to
have cancel_delayed_work_sync() + iris_core_deinit() in iris_remove() and
now here disable_delayed_work_sync() + iris_core_deinit().

I think the iris_remove() should be disable_delayed_work_sync() it seems to
be the same error as this:

https://lore.kernel.org/linux-media/20261023223635.3c895c4752c4-3-mhun512@gmail.com

So perhaps a patch before this patch which Fixes: the
cancel_delayed_work_sync() in iris_remove() and then you can use a helper
function 

abels_super_cool_teardown() {

- disable_delayed_work_sync();
- iris_core_deinit();

}

in both iris_remove() and iris_pm_freeze()

> +
> +	ret = pm_runtime_force_suspend(dev);
> +	if (ret)
> +		enable_delayed_work(&core->sys_error_handler);
> +
> +	return ret;
> +}
> +
> +static int iris_pm_thaw(struct device *dev)
> +{
> +	struct iris_core *core = dev_get_drvdata(dev);
> +
> +	enable_delayed_work(&core->sys_error_handler);

I was going to ask about when the firmware gets loaded but its done in
iris_open() so I think this is fine.
---
bod


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

* Re: [PATCH] media: iris: Unload the firmware before hibernation
  2026-10-26 13:39 [PATCH] media: iris: Unload the firmware before hibernation Abel Vesa
  2026-11-17 12:42 ` bod
@ 2026-12-01 20:37 ` Kaylin Aurora
  1 sibling, 0 replies; 3+ messages in thread
From: Kaylin Aurora @ 2026-12-01 20:37 UTC (permalink / raw)
  To: abel.vesa
  Cc: Vikash Garodia, Dikshita Agarwal, Abhinav Kumar,
	Bryan O'Donoghue, Mauro Carvalho Chehab, linux-media,
	linux-arm-msm, linux-kernel

On Mon, Oct 26, 2026 at 03:39PM +0200, Abel Vesa wrote:
> Make sure the image does not hold an initialized core. Unload the
> firmware before the image is created, and before the kernel that loads
> the image jumps into it, so that the next session loads it again.

Hi Abel,

I tested this on an ASUS Zenbook 14 UX3480QA (X1P42100), on v7.3.6
rather than your base; it applies there with a 4 line offset. The
firmware was loaded (a decode had run) before each sleep, and each
check decodes a short H.264 clip with h264_v4l2m2m and compares the
frames against a software decode.

Without the patch, every resume after a hibernation fails with
"failed to resume" until qcom_iris is reloaded. With it:

  - hibernation and restore: decode afterwards is bit-exact, no errors
  - hibernation with the decoder open: refused with "cannot hibernate
    while the device is open" (-EBUSY), and the decoder works afterwards
  - deep suspend: no change, decode afterwards is bit-exact

One problem though. With the patch, hibernation aborted after the
device freeze phase hangs the machine hard: black screen, keyboard
backlight off, only a forced power off recovers. Reproduced twice:

  # echo devices > /sys/power/pm_test
  # systemctl hibernate

The same sequence with the unpatched driver (firmware also loaded)
comes back after the 5 second wait as expected. Nothing reaches the
log after "PM: hibernation: hibernation entry", and this machine has no
pstore backend, so I don't know where it stops.

As far as I can tell, pm_test=devices only adds the 5 second wait to
the path a real failure takes: when a device fails .freeze after
iris_pm_freeze() has run, create_image() is skipped as well, and
devices go back through .restore without the late and noirq phases.
So I would expect a failed hibernation to hang the same way, though
perhaps less often given the shorter window.

I'm happy to test a v2 or a debug patch on this machine.

Testing done with the help of Claude Opus 5.5.

Kaylin Aurora

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

end of thread, other threads:[~2026-12-01 20:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-26 13:39 [PATCH] media: iris: Unload the firmware before hibernation Abel Vesa
2026-11-17 12:42 ` bod
2026-12-01 20:37 ` Kaylin Aurora

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®