media: venus: fix HFI teardown races
Subsystems (5)
v5 cover media: venus: fix HFI teardown races
This issue was identified as part of our ongoing research while reviewing kernel code.
Synchronize IRQ handlers before freeing HFI state, and disable recovery work at the start of remove to prevent it from racing with teardown.
Changes in v5:
- Patch 1: no code changes; carry Bryan's Reviewed-by.
- Patch 2: drop the duplicate work disable from venus_hfi_destroy(), keeping it only in venus_remove(), as requested by Bryan.
- Rebase onto media-committers.git next.
Compilation test completed.
v4: https://lore.kernel.org/all/[email protected]/
Myeonghun Pak (2):
media: venus: hfi: disable IRQ before freeing HFI device
media: venus: disable recovery work before HFI teardown
drivers/media/platform/qcom/venus/core.c | 2 +- drivers/media/platform/qcom/venus/hfi_venus.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
base-commit: d7e7bca7169873b46e857c025c10f3336c1258d8
Signature · 1 line
2.53.0
PATCH v5 1/2 media: venus: hfi: disable IRQ before freeing HFI device
venus_hfi_destroy() frees hdev and its interface queues before disabling the IRQ. A handler that already loaded core->priv can therefore access freed state even after core->priv is cleared.
Move disable_irq() before clearing core->priv and releasing HFI state so both the hard and threaded handlers have completed before teardown.
--- drivers/media/platform/qcom/venus/hfi_venus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/platform/qcom/venus/hfi_venus.c +1 -1
@@ -1689,11 +1689,11 @@ void venus_hfi_destroy(struct venus_core *core) {struct venus_hfi_device *hdev =to_hfi_priv (core); +disable_irq (core->irq); core->priv =NULL ;venus_interface_queues_release (hdev);mutex_destroy (&hdev->lock);kfree (hdev); -disable_irq (core->irq); core->ops =NULL ; }
Signature · 1 line
2.53.0
Re: [PATCH v5 1/2] media: venus: hfi: disable IRQ before freeing HFI device
Quoted 8 lines · Myeonghun Pak
venus_hfi_destroy()frees hdev and its interface queues before disabling the IRQ. A handler that already loadedcore->privcan therefore access freed state even aftercore->privis cleared.Move
disable_irq()before clearingcore->privand releasing HFI state so both the hard and threaded handlers have completed before teardown.Fixes d96d3f30c0f2 ("[media] media: venus: hfi: add Venus HFI files")
No need to resend, I'll fix this tag too.
Quoted 33 lines
Reported-by Sashiko <[email protected]>Assisted-by LLMCo-developed-by Ijae Kim <[email protected]>Signed-off-by Ijae Kim <[email protected]>Signed-off-by Myeonghun Pak <[email protected]>Reviewed-by Bryan O'Donoghue <[email protected]>--- drivers/media/platform/qcom/venus/hfi_venus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/media/platform/qcom/venus/hfi_venus.c +1
-1@@ -1689,11 +1689,11 @@ void venus_hfi_destroy(struct venus_core *core) {struct venus_hfi_device *hdev =to_hfi_priv (core); +disable_irq (core->irq); core->priv =NULL ;venus_interface_queues_release (hdev);mutex_destroy (&hdev->lock);kfree (hdev); -disable_irq (core->irq); core->ops =NULL ; }Signature · 1 line
2.53.0
---
bod
Re: [PATCH v5 1/2] media: venus: hfi: disable IRQ before freeing HFI device
In reply to Myeonghun PakQuoted 4 lines · Myeonghun Pak
venus_hfi_destroy()frees hdev and its interface queues before disabling the IRQ. A handler that already loadedcore->privcan therefore access freed state even aftercore->privis cleared.
Quoted 8 lines
Move
disable_irq()before clearingcore->privand releasing HFI state so both the hard and threaded handlers have completed before teardown.Fixes d96d3f30c0f2 ("[media] media: venus: hfi: add Venus HFI files")Reported-by Sashiko <[email protected]>Assisted-by LLM
Checkpatch reports an error for the Assisted-by: LLM tag:
WARNING: Non-standard signature: Assisted-by:
#18:
ERROR: Unrecognized email address: 'LLM'
#18:
total: 1 errors, 1 warnings, 0 checks, 12 lines checked
Quoted 25 lines
Co-developed-by Ijae Kim <[email protected]>Signed-off-by Ijae Kim <[email protected]>Signed-off-by Myeonghun Pak <[email protected]>Reviewed-by Bryan O'Donoghue <[email protected]>--- drivers/media/platform/qcom/venus/hfi_venus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/media/platform/qcom/venus/hfi_venus.c +1
-1@@ -1689,11 +1689,11 @@ void venus_hfi_destroy(struct venus_core *core) {struct venus_hfi_device *hdev =to_hfi_priv (core); +disable_irq (core->irq); core->priv =NULL ;venus_interface_queues_release (hdev);mutex_destroy (&hdev->lock);kfree (hdev); -disable_irq (core->irq); core->ops =NULL ; }
PATCH v5 2/2 media: venus: disable recovery work before HFI teardown
In reply to Myeonghun Pakvenus_remove() cancels core->work while the IRQ can still schedule it. A later IRQ can requeue recovery work, which may access HFI state after it has been freed.
Use disable_delayed_work_sync() at the start of remove to drain recovery and prevent further IRQ or worker requeues. Drain the work before disabling the IRQ so recovery can finish completion waits that depend on IRQs.
--- drivers/media/platform/qcom/venus/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/platform/qcom/venus/core.c +1 -1
@@ -596,7 +596,7 @@ static void venus_remove(struct platform_device *pdev)struct device *dev = core->dev;int ret; -cancel_delayed_work_sync (&core->work); +disable_delayed_work_sync (&core->work); ret =pm_runtime_get_sync (dev);WARN_ON (ret <0 );
Signature · 1 line
2.53.0
Re: [PATCH v5 2/2] media: venus: disable recovery work before HFI teardown
Quoted 10 lines · Myeonghun Pak
venus_remove()cancelscore->workwhile the IRQ can still schedule it. A later IRQ can requeue recovery work, which may access HFI state after it has been freed.Use
disable_delayed_work_sync()at the start of remove to drain recovery and prevent further IRQ or worker requeues. Drain the work before disabling the IRQ so recovery can finish completion waits that depend on IRQs.Fixes af2c3834c8ca ("[media] media: venus: adding core part and helper functions")
Don't resend I'll fix the tag for you.
Quoted 29 lines
Reported-by Sashiko <[email protected]>Assisted-by LLMCo-developed-by Ijae Kim <[email protected]>Signed-off-by Ijae Kim <[email protected]>Signed-off-by Myeonghun Pak <[email protected]>--- drivers/media/platform/qcom/venus/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/media/platform/qcom/venus/core.c +1
-1@@ -596,7 +596,7 @@ static void venus_remove(struct platform_device *pdev)struct device *dev = core->dev;int ret; -cancel_delayed_work_sync (&core->work); +disable_delayed_work_sync (&core->work); ret =pm_runtime_get_sync (dev);WARN_ON (ret <0 );Signature · 1 line
2.53.0
---
bod