media: qcom: iris: handle runtime PM resume failure in core deinit
Subsystems (4)
PATCH v2 1/1 media: qcom: iris: handle runtime PM resume failure in core deinit
Check the return value of pm_runtime_resume_and_get() in iris_core_deinit().
If runtime PM resume fails, skip hardware power-off operations but still perform software teardown and state transition. Also skip the corresponding pm_runtime_put_sync() call to avoid unbalanced runtime PM references.
---
Changes in v2:
- Keep software teardown and state transition when runtime PM resume fails
- Skip only hardware power-off operations and pm_runtime_put_sync()
drivers/media/platform/qcom/iris/iris_core.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/media/platform/qcom/iris/iris_core.c +9 -3
@@ -12,18 +12,24 @@void iris_core_deinit (struct iris_core *core) { -pm_runtime_resume_and_get (core->dev); +int ret; + + ret =pm_runtime_resume_and_get (core->dev);mutex_lock (&core->lock);if (core->state !=IRIS_CORE_DEINIT ) {iris_fw_unload (core); -iris_vpu_power_off (core); + +if (!ret) +iris_vpu_power_off (core); +iris_hfi_queues_deinit (core); core->state =IRIS_CORE_DEINIT ; }mutex_unlock (&core->lock); -pm_runtime_put_sync (core->dev); +if (!ret) +pm_runtime_put_sync (core->dev); }static int iris_wait_for_system_response (struct iris_core *core)
Signature · 1 line
2.34.1
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
Pre-existing issues:
- [Critical] V4L2 file descriptors outlive the devm-allocated iris_core, leading to a Use-After-Free and use of a destroyed mutex during device unbind.
- [High] The delayed work core->sys_error_handler is not cancelled before the driver is removed and its memory is freed, leading to a Use-After-Free.
- [High] The threaded IRQ handler accesses hardware registers without verifying the device's PM runtime state, causing a synchronous external abort.
- [High] Manual hardware power-on bypasses the PM runtime framework, leading to state desynchronization and a double-enable bug. --
commit c7ce3ea6452bd787828d7a9a38e6b47c68475a5e
Author: Hungyu Lin <[email protected]>
media: qcom: iris: handle runtime PM resume failure in core deinit
This commit checks the return value of pm_runtime_resume_and_get() in iris_core_deinit(). If runtime PM resume fails, it skips hardware power-off operations but still performs software teardown. It also skips the corresponding pm_runtime_put_sync() call to avoid unbalanced references.
Quoted 22 lines
drivers/media/platform/qcom/iris/iris_core.c +7
-2@@ -12,18 +12,24 @@void iris_core_deinit (struct iris_core *core) { -pm_runtime_resume_and_get (core->dev); +int ret; + + ret =pm_runtime_resume_and_get (core->dev);mutex_lock (&core->lock);if (core->state !=IRIS_CORE_DEINIT ) {iris_fw_unload (core); -iris_vpu_power_off (core); + +if (!ret) +iris_vpu_power_off (core); +iris_hfi_queues_deinit (core);
drivers/media/platform/qcom/iris/iris_core.c line 35
Quoted 10 lines
drivers/media/platform/qcom/iris/iris_core.c +2
-1core->state =IRIS_CORE_DEINIT ; }mutex_unlock (&core->lock); -pm_runtime_put_sync (core->dev); +if (!ret) +pm_runtime_put_sync (core->dev); }static int iris_wait_for_system_response (struct iris_core *core)
[Severity: High]
This is a pre-existing issue, but is the delayed work core->sys_error_handler cancelled before the driver is removed?
In iris_probe(), core->sys_error_handler is initialized as a delayed work item. During driver teardown in iris_remove(), there appears to be no call to cancel_delayed_work_sync(&core->sys_error_handler):
iris_remove() {
...
struct iris_core *core;
...
}Because core is allocated using devm_kzalloc, the memory will be automatically freed by devres immediately after iris_remove() returns.
If the delayed work is pending or executing concurrently, could it access freed memory?
[Severity: Critical]
This is a pre-existing issue, but are V4L2 file descriptors outliving the devm-allocated iris_core?
In iris_remove(), video_unregister_device() is called:
iris_remove() {
...
video_unregister_device(core->vdev_dec);
video_unregister_device(core->vdev_enc);
...
}This removes the device node but leaves existing open file descriptors valid. Devres frees core when iris_remove() returns.
When userspace later closes a lingering open file descriptor, iris_close() invokes iris_remove_session(), which accesses the freed inst->core pointer and attempts to acquire the destroyed mutex:
iris_remove_session() {
...
mutex_lock(&core->lock);
...
}Could this lead to a use-after-free and use of a destroyed mutex during device unbind? Also, does the teardown order in iris_remove() introduce a race where an open() call can pass the registration check just before the core structure is freed?
[Severity: High]
This is a pre-existing issue, but might the threaded IRQ handler access hardware registers without verifying the device PM runtime state?
In iris_hfi_isr_handler(), the threaded IRQ handler accesses VPU registers without calling pm_runtime_get_if_active():
iris_hfi_isr_handler() {
...
mutex_lock(&core->lock);
pm_runtime_mark_last_busy(core->dev);
iris_vpu_clear_interrupt(core);
mutex_unlock(&core->lock);
...
}Concurrently, iris_pm_suspend() acquires core->lock, powers off the VPU, disables the IRQ using disable_irq_nosync(), and then unlocks the mutex.
Because disable_irq_nosync() does not wait for a currently executing threaded handler to finish, the handler (which was blocked waiting for core->lock) might resume execution immediately after PM suspend releases the lock.
Could the handler then access the registers of a powered-down device and cause a synchronous external abort?
[Severity: High]
This is a pre-existing issue, but does manual hardware power-on bypass the PM runtime framework?
When iris_sys_error_handler() runs asynchronously, it calls iris_core_deinit() and then iris_core_init(). iris_core_init() manually invokes iris_vpu_power_on() without acquiring a PM runtime reference:
iris_core_init() {
...
ret = iris_vpu_power_on(core);
if (ret)
goto error_queue_deinit;
...
}The PM framework therefore still considers the device suspended. Later, when the PM framework transitions the device state, it triggers iris_pm_resume(), which calls iris_vpu_power_on() a second time:
iris_hfi_pm_resume() {
...
ret = iris_vpu_power_on(core);
if (ret)
goto error;
...
}Could this double power-on leak clock and regulator reference counts and trigger an unbalanced enable warning for the IRQ?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
drivers/media/platform/qcom/iris/iris_core.c
Quoted 22 lines · Hungyu Lin
Check the return value of
pm_runtime_resume_and_get()iniris_core_deinit().If runtime PM resume fails, skip hardware power-off operations but still perform software teardown and state transition. Also skip the corresponding
pm_runtime_put_sync()call to avoid unbalanced runtime PM references.Fixes bb8a95aa038e ("media: iris: implement power management")Signed-off-by Hungyu Lin <[email protected]>---
Changes in v2:
- Keep software teardown and state transition when runtime PM resume fails
- Skip only hardware power-off operations andpm_runtime_put_sync()drivers/media/platform/qcom/iris/iris_core.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)drivers/media/platform/qcom/iris/iris_core.c +0
-0