media: tegra-vde: fix mutex ownership across decode completion
PATCH 1/1 media: tegra-vde: fix mutex ownership across decode completion
VDE starts a mem2mem decode while holding vde->lock in the job callback, but tegra_decode_complete() runs in a workqueue and releases it through tegra_vde_decode_abort(). Unlocking a mutex from a different task violates mutex ownership and triggers a DEBUG_MUTEXES warning.
Use a binary semaphore for decode and system-sleep serialization so the completion worker can release it. Return the semaphore if forced runtime suspend fails, allowing later decode or suspend operations to proceed.
--- drivers/media/platform/nvidia/tegra-vde/h264.c | 6 +++--- drivers/media/platform/nvidia/tegra-vde/vde.c | 10 ++++++---- drivers/media/platform/nvidia/tegra-vde/vde.h | 3 ++- 3 files changed, 11 insertions(+), 8 deletions(-)
Build-tested for ARM with W=1 against media-committers/next. On ASUS SL101 with DEBUG_MUTEXES, the baseline and patched v7.4-rc4 kernels each completed 3/3 60-frame H.264 decodes with identical output hashes. The baseline logged the cross-task mutex warning; the patched kernel did not.
The patched kernel also completed one LP1 suspend/resume cycle; all three post-resume decodes matched the baseline hashes.
Thanks for taking a look.
drivers/media/platform/nvidia/tegra-vde/h264.c +3 -3
@@ -539,7 +539,7 @@ static int tegra_vde_decode_begin(struct tegra_vde *vde,unsigned int macroblocks_nb;int err; - err =mutex_lock_interruptible (&vde->lock); + err =down_interruptible (&vde->lock);if (err)return err;
@@ -588,7 +588,7 @@ static int tegra_vde_decode_begin(struct tegra_vde *vde,pm_runtime_put_autosuspend (dev); unlock: -mutex_unlock (&vde->lock); +up (&vde->lock);return err; }
@@ -613,7 +613,7 @@ static void tegra_vde_decode_abort(struct tegra_vde *vde)pm_runtime_put_autosuspend (dev); -mutex_unlock (&vde->lock); +up (&vde->lock); }static int tegra_vde_decode_end (struct tegra_vde *vde)
drivers/media/platform/nvidia/tegra-vde/vde.c +6 -4
@@ -333,7 +333,7 @@ static int tegra_vde_probe(struct platform_device *pdev)INIT_LIST_HEAD (&vde->map_list);mutex_init (&vde->map_lock); -mutex_init (&vde->lock); +sema_init (&vde->lock,1 );init_completion (&vde->decode_completion); err =tegra_vde_iommu_init (vde);
@@ -431,11 +431,13 @@ static __maybe_unused int tegra_vde_pm_suspend(struct device *dev)struct tegra_vde *vde =dev_get_drvdata (dev);int err; -mutex_lock (&vde->lock); +down (&vde->lock); err =pm_runtime_force_suspend (dev); -if (err <0 ) +if (err <0 ) { +up (&vde->lock);return err; + }return 0 ; }
@@ -449,7 +451,7 @@ static __maybe_unused int tegra_vde_pm_resume(struct device *dev)if (err <0 )return err; -mutex_unlock (&vde->lock); +up (&vde->lock);return 0 ; }
drivers/media/platform/nvidia/tegra-vde/vde.h +2 -1
@@ -13,6 +13,7 @@#include <linux/iova.h> #include <linux/list.h> #include <linux/mutex.h> +#include <linux/semaphore.h> #include <linux/types.h> #include <linux/workqueue.h>
@@ -102,7 +103,7 @@ struct tegra_vde {void __iomem *vdma;void __iomem *frameid;struct device *dev; -struct mutex lock; +struct semaphore lock;struct mutex map_lock;struct list_head map_list;struct reset_control *rst;
base-commit: fb8b2c10a588f1384b98280b1c32307da9db4747